Commit 192a57e2 authored by Volker Krause's avatar Volker Krause Committed by Vlad Zahorodnii
Browse files

Port thumbnail item to use Qt Shader Tools for Qt 6

parent 1b5814c0
Pipeline #227896 passed with stage
in 15 minutes and 59 seconds
......@@ -41,7 +41,7 @@ if (QT_MAJOR_VERSION EQUAL "5")
find_package(Qt5 ${QT_MIN_VERSION} CONFIG REQUIRED COMPONENTS X11Extras)
find_package(Qt5XkbCommonSupport REQUIRED)
else()
find_package(Qt6 ${QT_MIN_VERSION} CONFIG REQUIRED COMPONENTS WaylandClient)
find_package(Qt6 ${QT_MIN_VERSION} CONFIG REQUIRED COMPONENTS WaylandClient ShaderTools)
endif()
find_package(Qt${QT_MAJOR_VERSION}Test ${QT_MIN_VERSION} CONFIG QUIET)
......
......@@ -19,6 +19,17 @@ qt_add_dbus_interface(kcm_kwintabbox_PART_SRCS ${KWin_SOURCE_DIR}/src/org.kde.kw
kconfig_add_kcfg_files(kcm_kwintabbox_PART_SRCS kwintabboxsettings.kcfgc kwinswitcheffectsettings.kcfgc kwinpluginssettings.kcfgc)
kcoreaddons_add_plugin(kcm_kwintabbox SOURCES ${kcm_kwintabbox_PART_SRCS} INSTALL_NAMESPACE "plasma/kcms/systemsettings_qwidgets")
if (QT_MAJOR_VERSION EQUAL "6")
qt6_add_shaders(kcm_kwintabbox "shaders"
BATCHABLE
PRECOMPILE
OPTIMIZED
PREFIX "/org/kde/kwin/tabbox/shaders/"
FILES
brightnesssaturation.vert
brightnesssaturation.frag
)
endif()
kcmutils_generate_desktop_file(kcm_kwintabbox)
target_link_libraries(kcm_kwintabbox
......
/*
* SPDX-FileCopyrightText: 2011, 2014 Martin Gräßlin <mgraesslin@kde.org>
* SPDX-License-Identifier: GPL-2.0-or-later
*/
#version 440
layout (std140, binding = 0) uniform buf {
highp mat4 u_matrix;
lowp float u_opacity; // offset 64
highp float u_saturation; // offset 68
highp float u_brightness; // offset 72
} ubuf; // size 76
layout (binding = 1) uniform sampler2D qt_Texture;
layout (location = 0) in highp vec2 v_coord;
layout (location = 0) out highp vec4 fragColor;
void main() {
lowp vec4 tex = texture(qt_Texture, v_coord);
if (ubuf.u_saturation != 1.0) {
tex.rgb = mix(vec3(dot( vec3( 0.30, 0.59, 0.11 ), tex.rgb )), tex.rgb, ubuf.u_saturation);
}
tex.rgb = tex.rgb * ubuf.u_brightness;
fragColor = tex * ubuf.u_opacity;
}
/*
* SPDX-FileCopyrightText: 2011, 2014 Martin Gräßlin <mgraesslin@kde.org>
* SPDX-License-Identifier: GPL-2.0-or-later
*/
#version 440
layout (std140, binding = 0) uniform buf {
highp mat4 u_matrix;
lowp float u_opacity;
highp float u_saturation;
highp float u_brightness;
} ubuf;
layout (location = 0) in highp vec4 vertex;
layout (location = 1) in highp vec2 texCoord;
layout (location = 0) out highp vec2 v_coord;
void main() {
v_coord = texCoord;
gl_Position = ubuf.u_matrix * vertex;
}
......@@ -16,6 +16,7 @@
namespace KWin
{
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
BrightnessSaturationShader::BrightnessSaturationShader()
: QSGMaterialShader()
, m_id_matrix(0)
......@@ -93,6 +94,50 @@ void BrightnessSaturationShader::initialize()
m_id_saturation = program()->uniformLocation("u_saturation");
m_id_brightness = program()->uniformLocation("u_brightness");
}
#else
BrightnessSaturationShader::BrightnessSaturationShader()
{
setShaderFileName(QSGMaterialShader::VertexStage, QStringLiteral(":/org/kde/kwin/tabbox/shaders/brightnesssaturation.vert.qsb"));
setShaderFileName(QSGMaterialShader::FragmentStage, QStringLiteral(":/org/kde/kwin/tabbox/shaders/brightnesssaturation.frag.qsb"));
}
bool BrightnessSaturationShader::updateUniformData(QSGMaterialShader::RenderState &state, QSGMaterial *newMaterial, QSGMaterial *oldMaterial)
{
bool changed = false;
QByteArray *buf = state.uniformData();
Q_ASSERT(buf->size() >= 76);
if (state.isMatrixDirty()) {
const QMatrix4x4 m = state.combinedMatrix();
memcpy(buf->data(), m.constData(), 64);
changed = true;
}
if (state.isOpacityDirty()) {
const float opacity = state.opacity();
memcpy(buf->data() + 64, &opacity, 4);
changed = true;
}
if (!oldMaterial || newMaterial->compare(oldMaterial) != 0) {
const auto material = static_cast<BrightnessSaturationMaterial *>(newMaterial);
memcpy(buf->data() + 68, &material->saturation, 4);
memcpy(buf->data() + 72, &material->brightness, 4);
changed = true;
}
return changed;
}
void BrightnessSaturationShader::updateSampledImage(QSGMaterialShader::RenderState &state, int binding, QSGTexture **texture, QSGMaterial *newMaterial, QSGMaterial *oldMaterial)
{
Q_UNUSED(state);
Q_UNUSED(oldMaterial);
if (binding == 1) {
*texture = static_cast<BrightnessSaturationMaterial *>(newMaterial)->texture();
}
}
#endif
WindowThumbnailItem::WindowThumbnailItem(QQuickItem *parent)
: QQuickItem(parent)
......
......@@ -21,6 +21,7 @@ class BrightnessSaturationShader : public QSGMaterialShader
{
public:
BrightnessSaturationShader();
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
const char *vertexShader() const override;
const char *fragmentShader() const override;
const char *const *attributeNames() const override;
......@@ -32,12 +33,20 @@ private:
int m_id_opacity;
int m_id_saturation;
int m_id_brightness;
#else
bool updateUniformData(QSGMaterialShader::RenderState &state, QSGMaterial *newMaterial, QSGMaterial *oldMaterial) override;
void updateSampledImage(QSGMaterialShader::RenderState &state, int binding, QSGTexture **texture, QSGMaterial *newMaterial, QSGMaterial *oldMaterial) override;
#endif
};
class BrightnessSaturationMaterial : public QSGTextureMaterial
{
public:
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
QSGMaterialShader *createShader() const override
#else
QSGMaterialShader *createShader(QSGRendererInterface::RenderMode) const override
#endif
{
return new BrightnessSaturationShader;
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment