From ba201ce8131511505528624bba5ede7772a521cd Mon Sep 17 00:00:00 2001 From: taj-ny <79316397+taj-ny@users.noreply.github.com> Date: Thu, 2 Jan 2025 16:42:39 +0100 Subject: [PATCH] rename fake blur to static blur --- README.md | 2 +- docs/configuration.md | 8 ++--- src/blur.cpp | 80 +++++++++++++++++++++--------------------- src/blur.h | 16 ++++----- src/kcm/blur_config.ui | 8 ++--- src/settings.cpp | 12 +++---- src/settings.h | 8 ++--- 7 files changed, 67 insertions(+), 67 deletions(-) diff --git a/README.md b/README.md index 8f8b69c08..f5deb21e3 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ Better Blur (formerly kwin-effects-forceblur) is a fork the KWin Blur effect for - X11 and Wayland support - Force blur - Rounded corners with optional anti-aliasing -- Optional blur texture caching for much lower GPU usage, works best with tiling +- Static blur for much lower GPU usage ### Bug fixes Fixes for blur-related Plasma bugs that haven't been patched yet. diff --git a/docs/configuration.md b/docs/configuration.md index 98126a8ee..ef265d2de 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -17,11 +17,11 @@ This option will override the blur region specified by the decoration. ### Paint windows as non-opaque Fixes transparency for some applications by marking their windows as transparent. This will only be done for force-blurred windows. -# Fake blur +# Static blur When enabled, the blur texture will be cached and reused. The blurred areas of the window will be marked as opaque, resulting in KWin not painting anything behind them. Only one image per screen is cached at a time. -Fake blur is mainly intended for laptop users who want longer battery life while still having blur everywhere. +Static blur is mainly intended for laptop users who want longer battery life while still having blur everywhere. ### Use real blur for windows that are in front of other windows By default, when two windows overlap, you won't be able to see the window behind. @@ -32,11 +32,11 @@ If this option is enabled, the effect will automatically switch to real blur whe https://github.com/taj-ny/kwin-effects-forceblur/assets/79316397/7bae6a16-6c78-4889-8df1-feb24005dabc ### Image source -The image to use for fake blur. +The image to use for static blur. - Desktop wallpaper - A screenshot of the desktop is taken for every screen. Icons and widgets will be included. The cached texture is invalidated when the entire desktop is repainted, which can happen when the wallpaper changes, icons are interacted with or when widgets update. - Custom - The specified image is scaled for every screen without respecting the aspect ratio. Supported formats are JPEG and PNG. ### Blur image -Whether to blur the image used for fake blur. This is only done once. +Whether to blur the image used for static blur. This is only done once. diff --git a/src/blur.cpp b/src/blur.cpp index 76ce6902d..02a2f5874 100644 --- a/src/blur.cpp +++ b/src/blur.cpp @@ -239,7 +239,7 @@ void BlurEffect::reconfigure(ReconfigureFlags flags) m_iterationCount = blurStrengthValues[m_settings.general.blurStrength].iteration; m_offset = blurStrengthValues[m_settings.general.blurStrength].offset; m_expandSize = blurOffsets[m_iterationCount - 1].expandSize; - m_fakeBlurTextures.clear(); + m_staticBlurTextures.clear(); m_colorMatrix = colorMatrix(m_settings.general.brightness, m_settings.general.saturation, m_settings.general.contrast); for (EffectWindow *w : effects->stackingOrder()) { @@ -319,13 +319,13 @@ void BlurEffect::updateBlurRegion(EffectWindow *w, bool geometryChanged) } } -bool BlurEffect::hasFakeBlur(EffectWindow *w) +bool BlurEffect::hasStaticBlur(EffectWindow *w) { - if (!m_settings.fakeBlur.enable) { + if (!m_settings.staticBlur.enable) { return false; } - if (m_settings.fakeBlur.disableWhenWindowBehind) { + if (m_settings.staticBlur.disableWhenWindowBehind) { if (auto it = m_windows.find(w); it != m_windows.end()) { return !it->second.hasWindowBehind; } @@ -352,7 +352,7 @@ void BlurEffect::slotWindowAdded(EffectWindow *w) } if (w->isDesktop() && !effects->waylandDisplay()) { - m_fakeBlurTextures.erase(nullptr); + m_staticBlurTextures.erase(nullptr); return; } @@ -397,11 +397,11 @@ void BlurEffect::slotWindowDeleted(EffectWindow *w) void BlurEffect::slotScreenAdded(KWin::Output *screen) { screenChangedConnections[screen] = connect(screen, &Output::changed, this, [this, screen]() { - if (!m_settings.fakeBlur.enable) { + if (!m_settings.staticBlur.enable) { return; } - m_fakeBlurTextures.erase(screen); + m_staticBlurTextures.erase(screen); effects->addRepaintFull(); }); } @@ -536,8 +536,8 @@ void BlurEffect::prePaintWindow(EffectWindow *w, WindowPrePaintData &data, std:: // in case this window has regions to be blurred const QRegion blurArea = blurRegion(w).translated(w->pos().toPoint()); - bool fakeBlur = hasFakeBlur(w) && m_fakeBlurTextures.contains(m_currentScreen) && !blurArea.isEmpty(); - if (fakeBlur) { + bool staticBlur = hasStaticBlur(w) && m_staticBlurTextures.contains(m_currentScreen) && !blurArea.isEmpty(); + if (staticBlur) { data.opaque += blurArea; int topCornerRadius; @@ -560,8 +560,8 @@ void BlurEffect::prePaintWindow(EffectWindow *w, WindowPrePaintData &data, std:: } } - if (m_settings.fakeBlur.enable) { - if (m_settings.fakeBlur.disableWhenWindowBehind) { + if (m_settings.staticBlur.enable) { + if (m_settings.staticBlur.disableWhenWindowBehind) { if (auto it = m_windows.find(w); it != m_windows.end()) { const bool hadWindowBehind = it->second.hasWindowBehind; it->second.hasWindowBehind = false; @@ -588,18 +588,18 @@ void BlurEffect::prePaintWindow(EffectWindow *w, WindowPrePaintData &data, std:: } } - if (m_settings.fakeBlur.imageSource == FakeBlurImageSource::DesktopWallpaper && w->isDesktop() && w->frameGeometry() == data.paint.boundingRect()) { - m_fakeBlurTextures.erase(m_currentScreen); + if (m_settings.staticBlur.imageSource == StaticBlurImageSource::DesktopWallpaper && w->isDesktop() && w->frameGeometry() == data.paint.boundingRect()) { + m_staticBlurTextures.erase(m_currentScreen); } } - if (m_settings.forceBlur.markWindowAsTranslucent && !fakeBlur && shouldForceBlur(w)) { + if (m_settings.forceBlur.markWindowAsTranslucent && !staticBlur && shouldForceBlur(w)) { data.setTranslucent(); } effects->prePaintWindow(w, data, presentTime); - if (!fakeBlur) { + if (!staticBlur) { const QRegion oldOpaque = data.opaque; if (data.opaque.intersects(m_currentBlur)) { // to blur an area partially we have to shrink the opaque area of a window @@ -692,10 +692,10 @@ void BlurEffect::drawWindow(const RenderTarget &renderTarget, const RenderViewpo effects->drawWindow(renderTarget, viewport, w, mask, region, data); } -GLTexture *BlurEffect::ensureFakeBlurTexture(const Output *output, const RenderTarget &renderTarget) +GLTexture *BlurEffect::ensureStaticBlurTexture(const Output *output, const RenderTarget &renderTarget) { - if (m_fakeBlurTextures.contains(output)) { - return m_fakeBlurTextures[output].get(); + if (m_staticBlurTextures.contains(output)) { + return m_staticBlurTextures[output].get(); } if (effects->waylandDisplay() && !output) { @@ -707,13 +707,13 @@ GLTexture *BlurEffect::ensureFakeBlurTexture(const Output *output, const RenderT textureFormat = renderTarget.texture()->internalFormat(); } GLTexture *texture = effects->waylandDisplay() - ? createFakeBlurTextureWayland(output, renderTarget, textureFormat) - : createFakeBlurTextureX11(textureFormat); + ? createStaticBlurTextureWayland(output, renderTarget, textureFormat) + : createStaticBlurTextureX11(textureFormat); if (!texture) { return nullptr; } - return (m_fakeBlurTextures[output] = std::unique_ptr(texture)).get(); + return (m_staticBlurTextures[output] = std::unique_ptr(texture)).get(); } GLTexture *BlurEffect::ensureNoiseTexture() @@ -826,16 +826,16 @@ void BlurEffect::blur(BlurRenderData &renderInfo, const RenderTarget &renderTarg // Since the VBO is shared, the texture needs to be blurred before the geometry is uploaded, otherwise it will be // reset. - GLTexture *fakeBlurTexture = nullptr; - if (w && hasFakeBlur(w)) { - fakeBlurTexture = ensureFakeBlurTexture(m_currentScreen, renderTarget); - if (fakeBlurTexture) { + GLTexture *staticBlurTexture = nullptr; + if (w && hasStaticBlur(w)) { + staticBlurTexture = ensureStaticBlurTexture(m_currentScreen, renderTarget); + if (staticBlurTexture) { renderInfo.textures.clear(); renderInfo.framebuffers.clear(); } } - if (!fakeBlurTexture + if (!staticBlurTexture && (renderInfo.framebuffers.size() != (m_iterationCount + 1) || renderInfo.textures[0]->size() != backgroundRect.size() || renderInfo.textures[0]->internalFormat() != textureFormat)) { @@ -862,7 +862,7 @@ void BlurEffect::blur(BlurRenderData &renderInfo, const RenderTarget &renderTarg } // Fetch the pixels behind the shape that is going to be blurred. - if (!fakeBlurTexture) { + if (!staticBlurTexture) { const QRegion dirtyRegion = region & backgroundRect; for (const QRect &dirtyRect: dirtyRegion) { renderInfo.framebuffers[0]->blitFromRenderTarget(renderTarget, viewport, dirtyRect, dirtyRect.translated(-backgroundRect.topLeft())); @@ -973,7 +973,7 @@ void BlurEffect::blur(BlurRenderData &renderInfo, const RenderTarget &renderTarg vbo->bindArrays(); - if (fakeBlurTexture) { + if (staticBlurTexture) { ShaderManager::instance()->pushShader(m_texture.shader.get()); QMatrix4x4 projectionMatrix; @@ -986,7 +986,7 @@ void BlurEffect::blur(BlurRenderData &renderInfo, const RenderTarget &renderTarg } m_texture.shader->setUniform(m_texture.mvpMatrixLocation, projectionMatrix); - m_texture.shader->setUniform(m_texture.textureSizeLocation, QVector2D(fakeBlurTexture->size().width(), fakeBlurTexture->size().height())); + m_texture.shader->setUniform(m_texture.textureSizeLocation, QVector2D(staticBlurTexture->size().width(), staticBlurTexture->size().height())); m_texture.shader->setUniform(m_texture.texStartPosLocation, QVector2D(backgroundRect.x() - screenGeometry.x(), backgroundRect.y() - screenGeometry.y())); m_texture.shader->setUniform(m_texture.blurSizeLocation, QVector2D(backgroundRect.width(), backgroundRect.height())); m_texture.shader->setUniform(m_texture.scaleLocation, (float)viewport.scale()); @@ -995,7 +995,7 @@ void BlurEffect::blur(BlurRenderData &renderInfo, const RenderTarget &renderTarg m_texture.shader->setUniform(m_texture.antialiasingLocation, m_settings.roundedCorners.antialiasing); m_texture.shader->setUniform(m_texture.opacityLocation, static_cast(opacity)); - fakeBlurTexture->bind(); + staticBlurTexture->bind(); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); @@ -1155,7 +1155,7 @@ GLTexture *BlurEffect::wallpaper(EffectWindow *desktop, const qreal &scale, cons return texture.release(); } -GLTexture *BlurEffect::createFakeBlurTextureWayland(const Output *output, const RenderTarget &renderTarget, const GLenum &textureFormat) +GLTexture *BlurEffect::createStaticBlurTextureWayland(const Output *output, const RenderTarget &renderTarget, const GLenum &textureFormat) { EffectWindow *desktop = nullptr; for (EffectWindow *w : effects->stackingOrder()) { @@ -1169,10 +1169,10 @@ GLTexture *BlurEffect::createFakeBlurTextureWayland(const Output *output, const } std::unique_ptr texture; - if (m_settings.fakeBlur.imageSource == FakeBlurImageSource::DesktopWallpaper) { + if (m_settings.staticBlur.imageSource == StaticBlurImageSource::DesktopWallpaper) { texture.reset(wallpaper(desktop, output->scale(), textureFormat)); - } else if (m_settings.fakeBlur.imageSource == FakeBlurImageSource::Custom) { - texture = GLTexture::upload(m_settings.fakeBlur.customImage.scaled(output->pixelSize(), Qt::AspectRatioMode::IgnoreAspectRatio, Qt::TransformationMode::SmoothTransformation)); + } else if (m_settings.staticBlur.imageSource == StaticBlurImageSource::Custom) { + texture = GLTexture::upload(m_settings.staticBlur.customImage.scaled(output->pixelSize(), Qt::AspectRatioMode::IgnoreAspectRatio, Qt::TransformationMode::SmoothTransformation)); } if (!texture) { return nullptr; @@ -1207,14 +1207,14 @@ GLTexture *BlurEffect::createFakeBlurTextureWayland(const Output *output, const GLFramebuffer::popFramebuffer(); ShaderManager::instance()->popShader(); - if (m_settings.fakeBlur.blurCustomImage) { + if (m_settings.staticBlur.blurCustomImage) { blur(texture.get()); } return texture.release(); } -GLTexture *BlurEffect::createFakeBlurTextureX11(const GLenum &textureFormat) +GLTexture *BlurEffect::createStaticBlurTextureX11(const GLenum &textureFormat) { std::vector desktops; QRegion desktopGeometries; @@ -1241,16 +1241,16 @@ GLTexture *BlurEffect::createFakeBlurTextureX11(const GLenum &textureFormat) const auto geometry = desktop->frameGeometry(); std::unique_ptr texture; - if (m_settings.fakeBlur.imageSource == FakeBlurImageSource::DesktopWallpaper) { + if (m_settings.staticBlur.imageSource == StaticBlurImageSource::DesktopWallpaper) { texture.reset(wallpaper(desktop, 1, textureFormat)); - } else if (m_settings.fakeBlur.imageSource == FakeBlurImageSource::Custom) { - texture = GLTexture::upload(m_settings.fakeBlur.customImage.scaled(geometry.width(), geometry.height(), Qt::AspectRatioMode::IgnoreAspectRatio, Qt::TransformationMode::SmoothTransformation)); + } else if (m_settings.staticBlur.imageSource == StaticBlurImageSource::Custom) { + texture = GLTexture::upload(m_settings.staticBlur.customImage.scaled(geometry.width(), geometry.height(), Qt::AspectRatioMode::IgnoreAspectRatio, Qt::TransformationMode::SmoothTransformation)); } if (!texture) { return nullptr; } - if (m_settings.fakeBlur.blurCustomImage) { + if (m_settings.staticBlur.blurCustomImage) { blur(texture.get()); } diff --git a/src/blur.h b/src/blur.h index 6f426b5cb..bc3251179 100644 --- a/src/blur.h +++ b/src/blur.h @@ -96,7 +96,7 @@ public Q_SLOTS: bool shouldBlur(const EffectWindow *w, int mask, const WindowPaintData &data); bool shouldForceBlur(const EffectWindow *w) const; void updateBlurRegion(EffectWindow *w, bool geometryChanged = false); - bool hasFakeBlur(EffectWindow *w); + bool hasStaticBlur(EffectWindow *w); QMatrix4x4 colorMatrix(const float &brightness, const float &saturation, const float &contrast) const; /* @@ -108,9 +108,9 @@ public Q_SLOTS: /** * @param output Can be nullptr. * @remark This method shall not be called outside of BlurEffect::blur. - * @return The cached fake blur texture. The texture will be created if it doesn't exist. + * @return The cached static blur texture. The texture will be created if it doesn't exist. */ - GLTexture *ensureFakeBlurTexture(const Output *output, const RenderTarget &renderTarget); + GLTexture *ensureStaticBlurTexture(const Output *output, const RenderTarget &renderTarget); GLTexture *ensureNoiseTexture(); /** @@ -121,17 +121,17 @@ public Q_SLOTS: GLTexture *wallpaper(EffectWindow *desktop, const qreal &scale, const GLenum &textureFormat); /** - * Creates a fake blur texture for the specified screen. + * Creates a static blur texture for the specified screen. * @remark This method shall not be called outside of BlurEffect::blur. * @return A pointer to the texture, or nullptr if an error occurred. */ - GLTexture *createFakeBlurTextureWayland(const Output *output, const RenderTarget &renderTarget, const GLenum &textureFormat); + GLTexture *createStaticBlurTextureWayland(const Output *output, const RenderTarget &renderTarget, const GLenum &textureFormat); /** - * Creates a composite fake blur texture containing images for all screens. + * Creates a composite static blur texture containing images for all screens. * @return A pointer to the texture, or nullptr if an error occurred. */ - GLTexture *createFakeBlurTextureX11(const GLenum &textureFormat); + GLTexture *createStaticBlurTextureX11(const GLenum &textureFormat); private: struct @@ -211,7 +211,7 @@ public Q_SLOTS: QList blurStrengthValues; - std::unordered_map> m_fakeBlurTextures; + std::unordered_map> m_staticBlurTextures; // Windows to blur even when transformed. QList m_blurWhenTransformed; diff --git a/src/kcm/blur_config.ui b/src/kcm/blur_config.ui index 5cd765f34..502e0294f 100644 --- a/src/kcm/blur_config.ui +++ b/src/kcm/blur_config.ui @@ -467,14 +467,14 @@ - Fake Blur + Static blur - When enabled, the blur texture will be cached and reused, resulting in much lower GPU usage. -Works best with tiling. + When enabled, a cached texture will be painted behind windows instead of actually blurring +the background, resulting in much lower GPU usage. @@ -501,7 +501,7 @@ Works best with tiling. - Use real blur for windows that are in front of other windows + Use dynamic blur for windows with other windows behind diff --git a/src/settings.cpp b/src/settings.cpp index a38307e44..5cbfda97d 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -29,15 +29,15 @@ void BlurSettings::read() roundedCorners.antialiasing = BlurConfig::roundedCornersAntialiasing(); roundedCorners.roundMaximized = BlurConfig::roundCornersOfMaximizedWindows(); - fakeBlur.enable = BlurConfig::fakeBlur(); - fakeBlur.disableWhenWindowBehind = BlurConfig::fakeBlurDisableWhenWindowBehind(); - fakeBlur.customImage = QImage(BlurConfig::fakeBlurImage()); + staticBlur.enable = BlurConfig::fakeBlur(); + staticBlur.disableWhenWindowBehind = BlurConfig::fakeBlurDisableWhenWindowBehind(); + staticBlur.customImage = QImage(BlurConfig::fakeBlurImage()); if (BlurConfig::fakeBlurImageSourceDesktopWallpaper()) { - fakeBlur.imageSource = FakeBlurImageSource::DesktopWallpaper; + staticBlur.imageSource = StaticBlurImageSource::DesktopWallpaper; } else { - fakeBlur.imageSource = FakeBlurImageSource::Custom; + staticBlur.imageSource = StaticBlurImageSource::Custom; } - fakeBlur.blurCustomImage = BlurConfig::fakeBlurCustomImageBlur(); + staticBlur.blurCustomImage = BlurConfig::fakeBlurCustomImageBlur(); } } \ No newline at end of file diff --git a/src/settings.h b/src/settings.h index 7d97fd39e..fa047780e 100644 --- a/src/settings.h +++ b/src/settings.h @@ -6,7 +6,7 @@ namespace KWin { -enum class FakeBlurImageSource +enum class StaticBlurImageSource { Custom, DesktopWallpaper @@ -49,11 +49,11 @@ struct RoundedCornersSettings bool roundMaximized; }; -struct FakeBlurSettings +struct StaticBlurSettings { bool enable; bool disableWhenWindowBehind; - FakeBlurImageSource imageSource; + StaticBlurImageSource imageSource; QImage customImage; bool blurCustomImage; }; @@ -64,7 +64,7 @@ class BlurSettings GeneralSettings general{}; ForceBlurSettings forceBlur{}; RoundedCornersSettings roundedCorners{}; - FakeBlurSettings fakeBlur{}; + StaticBlurSettings staticBlur{}; void read(); };