From 44a6050e839dc6311132010056ec5218680aea50 Mon Sep 17 00:00:00 2001 From: David Edmundson Date: Mon, 6 Mar 2017 14:34:36 +0000 Subject: [PATCH] Add scaling support into BlurEffect::doBlur Summary: This patch caputres from the framebuffer using the framebuffer's geometry, factoring in scale. We then keep the current normal DPI framebuffer causing it to downsample there. This is good because: - it keeps the code very simple - it's a performance optimisation. Blurring on 4k is naturally more expensive than at regular DPI. Downsampling keeps it the same - and you can't see a difference given it's high DPI and you're going to blur it anwyay. - it keeps kernel sizes somewhat resolution independent so it will look just as blurry across multiple screens. ::doCachedBlur still needs doing. Test Plan: Ran an app Ran the kwindowsystem blur test Observed the right part of the window being blurred Reviewers: #plasma Subscribers: plasma-devel Tags: #plasma Differential Revision: https://phabricator.kde.org/D4963 --- effects/blur/blur.cpp | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/effects/blur/blur.cpp b/effects/blur/blur.cpp index ea68fcba3b..0ed1535bbd 100644 --- a/effects/blur/blur.cpp +++ b/effects/blur/blur.cpp @@ -522,16 +522,20 @@ void BlurEffect::doBlur(const QRegion& shape, const QRect& screen, const float o uploadGeometry(vbo, expanded, shape); vbo->bindArrays(); + const qreal scale = GLRenderTarget::virtualScreenScale(); + // 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()); + // for HIGH DPI scratch is captured in native resolution, it is then implicitly downsampled + // when rendering into tex + 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 target->attachTexture(tex); @@ -548,8 +552,8 @@ void BlurEffect::doBlur(const QRegion& shape, const QRect& screen, const float o // 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); vbo->draw(GL_TRIANGLES, 0, expanded.rectCount() * 6);