diff --git a/CMakeLists.txt b/CMakeLists.txt index 8f036b59b6..956393cfb0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) diff --git a/src/kcmkwin/kwintabbox/CMakeLists.txt b/src/kcmkwin/kwintabbox/CMakeLists.txt index 62d09a7b1e..5a632275ae 100644 --- a/src/kcmkwin/kwintabbox/CMakeLists.txt +++ b/src/kcmkwin/kwintabbox/CMakeLists.txt @@ -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 diff --git a/src/kcmkwin/kwintabbox/brightnesssaturation.frag b/src/kcmkwin/kwintabbox/brightnesssaturation.frag new file mode 100644 index 0000000000..722c15f0dc --- /dev/null +++ b/src/kcmkwin/kwintabbox/brightnesssaturation.frag @@ -0,0 +1,27 @@ +/* + * SPDX-FileCopyrightText: 2011, 2014 Martin Gräßlin + * 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; +} diff --git a/src/kcmkwin/kwintabbox/brightnesssaturation.vert b/src/kcmkwin/kwintabbox/brightnesssaturation.vert new file mode 100644 index 0000000000..361f915755 --- /dev/null +++ b/src/kcmkwin/kwintabbox/brightnesssaturation.vert @@ -0,0 +1,22 @@ +/* + * SPDX-FileCopyrightText: 2011, 2014 Martin Gräßlin + * 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; +} diff --git a/src/kcmkwin/kwintabbox/thumbnailitem.cpp b/src/kcmkwin/kwintabbox/thumbnailitem.cpp index a29b9fb559..663f580c71 100644 --- a/src/kcmkwin/kwintabbox/thumbnailitem.cpp +++ b/src/kcmkwin/kwintabbox/thumbnailitem.cpp @@ -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(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(newMaterial)->texture(); + } +} +#endif WindowThumbnailItem::WindowThumbnailItem(QQuickItem *parent) : QQuickItem(parent) diff --git a/src/kcmkwin/kwintabbox/thumbnailitem.h b/src/kcmkwin/kwintabbox/thumbnailitem.h index bc20ad308d..fbc4e37de6 100644 --- a/src/kcmkwin/kwintabbox/thumbnailitem.h +++ b/src/kcmkwin/kwintabbox/thumbnailitem.h @@ -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; }