Skip to content

Commit

Permalink
Merge pull request #154 from taj-ny/static-blur-rename
Browse files Browse the repository at this point in the history
rename fake blur to static blur
  • Loading branch information
taj-ny authored Jan 2, 2025
2 parents 2052564 + ba201ce commit 9d068fd
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 67 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
8 changes: 4 additions & 4 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
80 changes: 40 additions & 40 deletions src/blur.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down Expand Up @@ -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;
}
Expand All @@ -352,7 +352,7 @@ void BlurEffect::slotWindowAdded(EffectWindow *w)
}

if (w->isDesktop() && !effects->waylandDisplay()) {
m_fakeBlurTextures.erase(nullptr);
m_staticBlurTextures.erase(nullptr);
return;
}

Expand Down Expand Up @@ -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();
});
}
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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) {
Expand All @@ -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<GLTexture>(texture)).get();
return (m_staticBlurTextures[output] = std::unique_ptr<GLTexture>(texture)).get();
}

GLTexture *BlurEffect::ensureNoiseTexture()
Expand Down Expand Up @@ -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)) {
Expand All @@ -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()));
Expand Down Expand Up @@ -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;
Expand All @@ -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());
Expand All @@ -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<float>(opacity));

fakeBlurTexture->bind();
staticBlurTexture->bind();
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

Expand Down Expand Up @@ -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()) {
Expand All @@ -1169,10 +1169,10 @@ GLTexture *BlurEffect::createFakeBlurTextureWayland(const Output *output, const
}

std::unique_ptr<GLTexture> 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;
Expand Down Expand Up @@ -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<EffectWindow *> desktops;
QRegion desktopGeometries;
Expand All @@ -1241,16 +1241,16 @@ GLTexture *BlurEffect::createFakeBlurTextureX11(const GLenum &textureFormat)
const auto geometry = desktop->frameGeometry();

std::unique_ptr<GLTexture> 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());
}

Expand Down
16 changes: 8 additions & 8 deletions src/blur.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/*
Expand All @@ -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();

/**
Expand All @@ -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
Expand Down Expand Up @@ -211,7 +211,7 @@ public Q_SLOTS:

QList<BlurValuesStruct> blurStrengthValues;

std::unordered_map<const Output*, std::unique_ptr<GLTexture>> m_fakeBlurTextures;
std::unordered_map<const Output*, std::unique_ptr<GLTexture>> m_staticBlurTextures;

// Windows to blur even when transformed.
QList<const EffectWindow*> m_blurWhenTransformed;
Expand Down
8 changes: 4 additions & 4 deletions src/kcm/blur_config.ui
Original file line number Diff line number Diff line change
Expand Up @@ -467,14 +467,14 @@
</widget>
<widget class="QWidget">
<attribute name="title">
<string>Fake Blur</string>
<string>Static blur</string>
</attribute>
<layout class="QVBoxLayout">
<item>
<widget class="QLabel">
<property name="text">
<string>When enabled, the blur texture will be cached and reused, resulting in much lower GPU usage.
Works best with tiling.</string>
<string>When enabled, a cached texture will be painted behind windows instead of actually blurring
the background, resulting in much lower GPU usage.</string>
</property>
</widget>
</item>
Expand All @@ -501,7 +501,7 @@ Works best with tiling.</string>
<item>
<widget class="QCheckBox" name="kcfg_FakeBlurDisableWhenWindowBehind">
<property name="text">
<string>Use real blur for windows that are in front of other windows</string>
<string>Use dynamic blur for windows with other windows behind</string>
</property>
</widget>
</item>
Expand Down
12 changes: 6 additions & 6 deletions src/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

}
Loading

0 comments on commit 9d068fd

Please sign in to comment.