From c97a53510166db7227d58ebab7411b0ba58e2e97 Mon Sep 17 00:00:00 2001 From: taj-ny <79316397+taj-ny@users.noreply.github.com> Date: Wed, 26 Jun 2024 10:49:23 +0200 Subject: [PATCH 1/3] blur/rounded-corners: cache textures used for anti-aliasing Fixes #86 --- src/blur.cpp | 18 ++++++++++-------- src/blur.h | 4 ++++ 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/blur.cpp b/src/blur.cpp index 645c86506..a57db9eb0 100644 --- a/src/blur.cpp +++ b/src/blur.cpp @@ -1051,10 +1051,12 @@ void BlurEffect::blur(const RenderTarget &renderTarget, const RenderViewport &vi * Since only a fragment of the window may be painted, the shader allows to toggle rounding for each corner. */ - const auto finalBlurTexture = GLTexture::allocate(textureFormat, backgroundRect.size()); - finalBlurTexture->setFilter(GL_LINEAR); - finalBlurTexture->setWrapMode(GL_CLAMP_TO_EDGE); - const auto finalBlurFramebuffer = std::make_unique(finalBlurTexture.get()); + if (hasAntialiasedRoundedCorners && (!renderInfo.blurTexture || renderInfo.blurTexture->size() != backgroundRect.size())) { + renderInfo.blurTexture = GLTexture::allocate(textureFormat, backgroundRect.size()); + renderInfo.blurTexture->setFilter(GL_LINEAR); + renderInfo.blurTexture->setWrapMode(GL_CLAMP_TO_EDGE); + renderInfo.blurFramebuffer = std::make_unique(renderInfo.blurTexture.get()); + } if (m_fakeBlur && m_hasValidFakeBlurTexture) { ShaderManager::instance()->pushShader(m_texturePass.shader.get()); @@ -1062,7 +1064,7 @@ void BlurEffect::blur(const RenderTarget &renderTarget, const RenderViewport &vi QMatrix4x4 projectionMatrix; if (hasAntialiasedRoundedCorners) { projectionMatrix.ortho(QRectF(0.0, 0.0, backgroundRect.width(), backgroundRect.height())); - GLFramebuffer::pushFramebuffer(finalBlurFramebuffer.get()); + GLFramebuffer::pushFramebuffer(renderInfo.blurFramebuffer.get()); } else { projectionMatrix = viewport.projectionMatrix(); projectionMatrix.translate(deviceBackgroundRect.x(), deviceBackgroundRect.y()); @@ -1148,7 +1150,7 @@ void BlurEffect::blur(const RenderTarget &renderTarget, const RenderViewport &vi const auto &read = renderInfo.framebuffers[1]; if (hasAntialiasedRoundedCorners) { - GLFramebuffer::pushFramebuffer(finalBlurFramebuffer.get()); + GLFramebuffer::pushFramebuffer(renderInfo.blurFramebuffer.get()); projectionMatrix = QMatrix4x4(); projectionMatrix.ortho(QRectF(0.0, 0.0, backgroundRect.width(), backgroundRect.height())); } else { @@ -1244,7 +1246,7 @@ void BlurEffect::blur(const RenderTarget &renderTarget, const RenderViewport &vi glUniform1i(m_roundedCorners.afterBlurTextureLocation, 1); glActiveTexture(GL_TEXTURE1); - glBindTexture(GL_TEXTURE_2D, finalBlurTexture->texture()); + glBindTexture(GL_TEXTURE_2D, renderInfo.blurTexture->texture()); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); @@ -1260,7 +1262,7 @@ void BlurEffect::blur(const RenderTarget &renderTarget, const RenderViewport &vi glDisable(GL_BLEND); glActiveTexture(GL_TEXTURE0); renderInfo.textures[0]->unbind(); - finalBlurTexture->unbind(); + renderInfo.blurTexture->unbind(); ShaderManager::instance()->popShader(); } diff --git a/src/blur.h b/src/blur.h index fde304191..d21349398 100644 --- a/src/blur.h +++ b/src/blur.h @@ -26,6 +26,10 @@ struct BlurRenderData /// contains not blurred background behind the window, it's cached. std::vector> textures; std::vector> framebuffers; + + // Contains the blurred background behind the window. Used for corner anti-aliasing. + std::unique_ptr blurTexture; + std::unique_ptr blurFramebuffer; }; struct BlurEffectData From 3ad9829c93f6829cd5488f0ef7dd0a2a000c54a1 Mon Sep 17 00:00:00 2001 From: taj-ny <79316397+taj-ny@users.noreply.github.com> Date: Wed, 26 Jun 2024 09:49:59 +0200 Subject: [PATCH 2/3] blur/force-blur: never set blur region for desktops Fixes #85 --- src/blur.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/blur.cpp b/src/blur.cpp index a57db9eb0..093b41c9a 100644 --- a/src/blur.cpp +++ b/src/blur.cpp @@ -737,7 +737,7 @@ bool BlurEffect::shouldBlur(const EffectWindow *w, int mask, const WindowPaintDa bool BlurEffect::shouldForceBlur(const EffectWindow *w) const { - if ((!m_blurDocks && w->isDock()) || (!m_blurMenus && isMenu(w))) { + if (w->isDesktop() || (!m_blurDocks && w->isDock()) || (!m_blurMenus && isMenu(w))) { return false; } From 938666681ac4451df20b2de2f27d9bb307d5b705 Mon Sep 17 00:00:00 2001 From: taj-ny <79316397+taj-ny@users.noreply.github.com> Date: Tue, 16 Jul 2024 19:25:19 +0200 Subject: [PATCH 3/3] bump version --- CMakeLists.txt | 2 +- package.nix | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index dc2203b8e..8e73239f8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,7 @@ cmake_minimum_required(VERSION 3.16.0) project(forceblur) -set(PROJECT_VERSION "1.3.0") +set(PROJECT_VERSION "1.3.1") set(PROJECT_VERSION_MAJOR 0) set(KF_MIN_VERSION "5.240.0") diff --git a/package.nix b/package.nix index 8e92c706c..108ff643d 100644 --- a/package.nix +++ b/package.nix @@ -9,7 +9,7 @@ stdenv.mkDerivation rec { pname = "kwin-effects-forceblur"; - version = "1.3.0"; + version = "1.3.1"; src = ./.;