Commit 63258ab0 authored by Kai Uwe Broulik's avatar Kai Uwe Broulik Committed by Kai Uwe Broulik
Browse files

kcmkwin/kwintabbox: Remove API not supported by KWin core



WindowThumbnailItem in scripting doesn't support any of the
'brightness', 'saturation', 'clipTo' anymore, so it makes
no sense to support it in the KCM's preview.

Signed-off-by: default avatarVictoria Fischer <victoria.fischer@mbition.io>
parent 354c0e35
Pipeline #228791 passed with stage
in 14 minutes and 38 seconds
......@@ -19,19 +19,6 @@ 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
NOHLSL
NOMSL
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;
}
......@@ -9,136 +9,14 @@
#include "thumbnailitem.h"
// Qt
#include <QDebug>
#include <QQuickWindow>
#include <QSGSimpleTextureNode>
#include <QSGImageNode>
#include <QStandardPaths>
namespace KWin
{
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
BrightnessSaturationShader::BrightnessSaturationShader()
: QSGMaterialShader()
, m_id_matrix(0)
, m_id_opacity(0)
, m_id_saturation(0)
, m_id_brightness(0)
{
}
const char *BrightnessSaturationShader::vertexShader() const
{
return "attribute highp vec4 vertex; \n"
"attribute highp vec2 texCoord; \n"
"uniform highp mat4 u_matrix; \n"
"varying highp vec2 v_coord; \n"
"void main() { \n"
" v_coord = texCoord; \n"
" gl_Position = u_matrix * vertex; \n"
"}";
}
const char *BrightnessSaturationShader::fragmentShader() const
{
return "uniform sampler2D qt_Texture; \n"
"uniform lowp float u_opacity; \n"
"uniform highp float u_saturation; \n"
"uniform highp float u_brightness; \n"
"varying highp vec2 v_coord; \n"
"void main() { \n"
" lowp vec4 tex = texture2D(qt_Texture, v_coord); \n"
" if (u_saturation != 1.0) { \n"
" tex.rgb = mix(vec3(dot( vec3( 0.30, 0.59, 0.11 ), tex.rgb )), tex.rgb, u_saturation); \n"
" } \n"
" tex.rgb = tex.rgb * u_brightness; \n"
" gl_FragColor = tex * u_opacity; \n"
"}";
}
const char *const *BrightnessSaturationShader::attributeNames() const
{
static char const *const names[] = {"vertex", "texCoord", nullptr};
return names;
}
void BrightnessSaturationShader::updateState(const QSGMaterialShader::RenderState &state, QSGMaterial *newMaterial, QSGMaterial *oldMaterial)
{
Q_ASSERT(program()->isLinked());
if (state.isMatrixDirty()) {
program()->setUniformValue(m_id_matrix, state.combinedMatrix());
}
if (state.isOpacityDirty()) {
program()->setUniformValue(m_id_opacity, state.opacity());
}
auto *tx = static_cast<BrightnessSaturationMaterial *>(newMaterial);
auto *oldTx = static_cast<BrightnessSaturationMaterial *>(oldMaterial);
QSGTexture *t = tx->texture();
t->setFiltering(QSGTexture::Linear);
if (!oldTx || oldTx->texture()->textureId() != t->textureId()) {
t->bind();
} else {
t->updateBindOptions();
}
program()->setUniformValue(m_id_saturation, static_cast<float>(tx->saturation));
program()->setUniformValue(m_id_brightness, static_cast<float>(tx->brightness));
}
void BrightnessSaturationShader::initialize()
{
QSGMaterialShader::initialize();
m_id_matrix = program()->uniformLocation("u_matrix");
m_id_opacity = program()->uniformLocation("u_opacity");
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)
, m_wId(0)
......@@ -164,11 +42,8 @@ void WindowThumbnailItem::setWId(qulonglong wId)
void WindowThumbnailItem::setClipTo(QQuickItem *clip)
{
if (m_clipToItem == clip) {
return;
}
m_clipToItem = clip;
Q_EMIT clipToChanged();
Q_UNUSED(clip)
qWarning() << "ThumbnailItem.clipTo is removed and it has no replacements";
}
void WindowThumbnailItem::findImage()
......@@ -209,24 +84,22 @@ void WindowThumbnailItem::findImage()
QSGNode *WindowThumbnailItem::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *updatePaintNodeData)
{
Q_UNUSED(updatePaintNodeData)
QSGGeometryNode *node = static_cast<QSGGeometryNode *>(oldNode);
auto *node = static_cast<QSGImageNode *>(oldNode);
if (!node) {
node = new QSGGeometryNode();
auto *material = new BrightnessSaturationMaterial;
material->setFlag(QSGMaterial::Blending);
material->setTexture(window()->createTextureFromImage(m_image));
node->setMaterial(material);
QSGGeometry *geometry = new QSGGeometry(QSGGeometry::defaultAttributes_TexturedPoint2D(), 4);
node->setGeometry(geometry);
node = window()->createImageNode();
node->setOwnsTexture(true);
qsgnode_set_description(node, QStringLiteral("windowthumbnail"));
node->setFiltering(QSGTexture::Linear);
}
auto *material = static_cast<BrightnessSaturationMaterial *>(node->material());
const QSize size(material->texture()->textureSize().scaled(boundingRect().size().toSize(), Qt::KeepAspectRatio));
node->setTexture(window()->createTextureFromImage(m_image));
const QSize size(m_image.size().scaled(boundingRect().size().toSize(), Qt::KeepAspectRatio));
const qreal x = boundingRect().x() + (boundingRect().width() - size.width()) / 2;
const qreal y = boundingRect().y() + (boundingRect().height() - size.height()) / 2;
QSGGeometry::updateTexturedRectGeometry(node->geometry(), QRectF(QPointF(x, y), size), QRectF(0.0, 0.0, 1.0, 1.0));
material->brightness = m_brightness;
material->saturation = m_saturation;
node->markDirty(QSGNode::DirtyGeometry | QSGNode::DirtyMaterial);
node->setRect(QRectF(QPointF(x, y), size));
return node;
}
......@@ -247,22 +120,14 @@ QSize WindowThumbnailItem::sourceSize() const
void WindowThumbnailItem::setBrightness(qreal brightness)
{
if (m_brightness == brightness) {
return;
}
m_brightness = brightness;
update();
Q_EMIT brightnessChanged();
Q_UNUSED(brightness)
qWarning() << "ThumbnailItem.brightness is removed. Use a shader effect to change brightness";
}
void WindowThumbnailItem::setSaturation(qreal saturation)
{
if (m_saturation == saturation) {
return;
}
m_saturation = saturation;
update();
Q_EMIT saturationChanged();
Q_UNUSED(saturation)
qWarning() << "ThumbnailItem.saturation is removed. Use a shader effect to change saturation";
}
void WindowThumbnailItem::setSourceSize(const QSize &size)
......
......@@ -12,59 +12,28 @@
#include <QImage>
#include <QQuickItem>
#include <QSGTextureMaterial>
namespace KWin
{
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;
void updateState(const RenderState &state, QSGMaterial *newMaterial, QSGMaterial *oldMaterial) override;
void initialize() override;
private:
int m_id_matrix;
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;
}
QSGMaterialType *type() const override
{
static QSGMaterialType type;
return &type;
}
qreal brightness;
qreal saturation;
};
class WindowThumbnailItem : public QQuickItem
{
Q_OBJECT
Q_PROPERTY(qulonglong wId READ wId WRITE setWId NOTIFY wIdChanged SCRIPTABLE true)
/**
* TODO Plasma 6: Remove.
* @deprecated clipTo has no replacement
*/
Q_PROPERTY(QQuickItem *clipTo READ clipTo WRITE setClipTo NOTIFY clipToChanged)
/**
* TODO Plasma 6: Remove.
* @deprecated use a shader effect to change the brightness
*/
Q_PROPERTY(qreal brightness READ brightness WRITE setBrightness NOTIFY brightnessChanged)
/**
* TODO Plasma 6: Remove.
* @deprecated use a shader effect to change color saturation
*/
Q_PROPERTY(qreal saturation READ saturation WRITE setSaturation NOTIFY saturationChanged)
Q_PROPERTY(QSize sourceSize READ sourceSize WRITE setSourceSize NOTIFY sourceSizeChanged)
public:
......
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