From f445a99a746bf0d5a14924b0ab34c92ec8a6942d Mon Sep 17 00:00:00 2001 From: David Edmundson Date: Mon, 6 Mar 2017 00:39:12 +0000 Subject: [PATCH] Support scaling in BackgroundContrast effect Summary: Background contrast reads pixels from the framebuffer we need to convert from compositor to framebuffer co-ordinates when an output is scaled Test Plan: Ran the manual test in kwindowsystem. Moved window over dolphin. Visually checked output Reviewers: #plasma Subscribers: plasma-devel, kwin, #kwin Tags: #kwin Differential Revision: https://phabricator.kde.org/D4949 --- effects/backgroundcontrast/contrast.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/effects/backgroundcontrast/contrast.cpp b/effects/backgroundcontrast/contrast.cpp index 51308166cd..9f371c424c 100644 --- a/effects/backgroundcontrast/contrast.cpp +++ b/effects/backgroundcontrast/contrast.cpp @@ -417,6 +417,8 @@ void ContrastEffect::doContrast(EffectWindow *w, const QRegion& shape, const QRe const QRegion actualShape = shape & screen; const QRect r = actualShape.boundingRect(); + qreal scale = GLRenderTarget::virtualScreenScale(); + // Upload geometry for the horizontal and vertical passes GLVertexBuffer *vbo = GLVertexBuffer::streamingBuffer(); uploadGeometry(vbo, actualShape); @@ -424,14 +426,14 @@ void ContrastEffect::doContrast(EffectWindow *w, const QRegion& shape, const QRe // Create a scratch texture and copy the area in the back buffer that we're // going to blur into it - GLTexture scratch(GL_RGBA8, r.width(), r.height()); + GLTexture scratch(GL_RGBA8, r.width() * scale, r.height() * scale); scratch.setFilter(GL_LINEAR); scratch.setWrapMode(GL_CLAMP_TO_EDGE); scratch.bind(); const QRect sg = GLRenderTarget::virtualScreenGeometry(); - glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, r.x() - sg.x(), sg.height() - sg.y() - r.y() - r.height(), - r.width(), r.height()); + glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, (r.x() - sg.x()) * scale, (sg.height() - sg.y() - r.y() - r.height()) * scale, + scratch.width(), scratch.height()); // Draw the texture on the offscreen framebuffer object, while blurring it horizontally @@ -443,8 +445,8 @@ void ContrastEffect::doContrast(EffectWindow *w, const QRegion& shape, const QRe // Set up the texture matrix to transform from screen coordinates // to texture coordinates. QMatrix4x4 textureMatrix; - textureMatrix.scale(1.0 / scratch.width(), -1.0 / scratch.height(), 1); - textureMatrix.translate(-r.x(), -scratch.height() - r.y(), 0); + textureMatrix.scale(1.0 / r.width(), -1.0 / r.height(), 1); + textureMatrix.translate(-r.x(), -r.height() - r.y(), 0); shader->setTextureMatrix(textureMatrix); shader->setModelViewProjectionMatrix(screenProjection);