From 40044f21e1b05335bdf043a5362798027e1bbbfd Mon Sep 17 00:00:00 2001 From: Vlad Zahorodnii Date: Fri, 29 Jul 2022 11:08:59 +0000 Subject: [PATCH] effects: Honor transforms in OffscreenEffect This ensures that transforms are honored with effects such as wobbly windows. --- src/libkwineffects/kwineffects.cpp | 20 +++++++++++++++ src/libkwineffects/kwineffects.h | 5 ++++ src/libkwineffects/kwinoffscreeneffect.cpp | 3 ++- src/scenes/opengl/scene_opengl.cpp | 29 +--------------------- 4 files changed, 28 insertions(+), 29 deletions(-) diff --git a/src/libkwineffects/kwineffects.cpp b/src/libkwineffects/kwineffects.cpp index 648a01c7d0..56299aea9a 100644 --- a/src/libkwineffects/kwineffects.cpp +++ b/src/libkwineffects/kwineffects.cpp @@ -204,6 +204,26 @@ void PaintData::setRotationOrigin(const QVector3D &origin) d->rotationOrigin = origin; } +QMatrix4x4 PaintData::toMatrix() const +{ + QMatrix4x4 ret; + if (d->translation != QVector3D(0, 0, 0)) { + ret.translate(d->translation); + } + if (d->scale != QVector3D(1, 1, 1)) { + ret.scale(d->scale); + } + + if (d->rotationAngle != 0) { + ret.translate(d->rotationOrigin); + const QVector3D axis = d->rotationAxis; + ret.rotate(d->rotationAngle, axis.x(), axis.y(), axis.z()); + ret.translate(-d->rotationOrigin); + } + + return ret; +} + class WindowPaintDataPrivate { public: diff --git a/src/libkwineffects/kwineffects.h b/src/libkwineffects/kwineffects.h index 7e75870123..0d3dc19349 100644 --- a/src/libkwineffects/kwineffects.h +++ b/src/libkwineffects/kwineffects.h @@ -3092,6 +3092,11 @@ public: */ QVector3D rotationAxis() const; + /** + * Returns the corresponding transform matrix. + */ + QMatrix4x4 toMatrix() const; + protected: PaintData(); PaintData(const PaintData &other); diff --git a/src/libkwineffects/kwinoffscreeneffect.cpp b/src/libkwineffects/kwinoffscreeneffect.cpp index 5cf564e65e..731ebea58c 100644 --- a/src/libkwineffects/kwinoffscreeneffect.cpp +++ b/src/libkwineffects/kwinoffscreeneffect.cpp @@ -160,7 +160,8 @@ void OffscreenEffectPrivate::paint(EffectWindow *window, GLTexture *texture, con QMatrix4x4 mvp = data.screenProjectionMatrix(); mvp.translate(window->x(), window->y()); - shader->setUniform(GLShader::ModelViewProjectionMatrix, mvp); + + shader->setUniform(GLShader::ModelViewProjectionMatrix, mvp * data.toMatrix()); shader->setUniform(GLShader::ModulationConstant, QVector4D(rgb, rgb, rgb, a)); shader->setUniform(GLShader::Saturation, data.saturation()); shader->setUniform(GLShader::TextureWidth, texture->width()); diff --git a/src/scenes/opengl/scene_opengl.cpp b/src/scenes/opengl/scene_opengl.cpp index f3d71222cd..d8cae6a000 100644 --- a/src/scenes/opengl/scene_opengl.cpp +++ b/src/scenes/opengl/scene_opengl.cpp @@ -409,33 +409,6 @@ QMatrix4x4 SceneOpenGL::modelViewProjectionMatrix(const WindowPaintData &data) c } } -static QMatrix4x4 transformForPaintData(int mask, const WindowPaintData &data) -{ - // TODO: Switch to QTransform. - QMatrix4x4 matrix; - - if (!(mask & Scene::PAINT_WINDOW_TRANSFORMED)) { - return matrix; - } - - matrix.translate(data.translation()); - const QVector3D scale = data.scale(); - matrix.scale(scale.x(), scale.y(), scale.z()); - - if (data.rotationAngle() == 0.0) { - return matrix; - } - - // Apply the rotation - // cannot use data.rotation.applyTo(&matrix) as QGraphicsRotation uses projectedRotate to map back to 2D - matrix.translate(data.rotationOrigin()); - const QVector3D axis = data.rotationAxis(); - matrix.rotate(data.rotationAngle(), axis.x(), axis.y(), axis.z()); - matrix.translate(-data.rotationOrigin()); - - return matrix; -} - void SceneOpenGL::render(Item *item, int mask, const QRegion ®ion, const WindowPaintData &data) { if (region.isEmpty()) { @@ -450,7 +423,7 @@ void SceneOpenGL::render(Item *item, int mask, const QRegion ®ion, const Wind renderContext.transformStack.push(QMatrix4x4()); renderContext.opacityStack.push(data.opacity()); - item->setTransform(transformForPaintData(mask, data)); + item->setTransform(data.toMatrix()); createRenderNode(item, &renderContext);