Skip to content

Commit

Permalink
Merge pull request #90 from taj-ny/performance-fixes
Browse files Browse the repository at this point in the history
v1.3.1
  • Loading branch information
taj-ny authored Jul 16, 2024
2 parents b9dd76a + 9386666 commit bcf1cba
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 11 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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")
Expand Down
2 changes: 1 addition & 1 deletion package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

stdenv.mkDerivation rec {
pname = "kwin-effects-forceblur";
version = "1.3.0";
version = "1.3.1";

src = ./.;

Expand Down
20 changes: 11 additions & 9 deletions src/blur.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -1051,18 +1051,20 @@ 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<GLFramebuffer>(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<GLFramebuffer>(renderInfo.blurTexture.get());
}

if (m_fakeBlur && m_hasValidFakeBlurTexture) {
ShaderManager::instance()->pushShader(m_texturePass.shader.get());

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());
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
Expand All @@ -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();
}

Expand Down
4 changes: 4 additions & 0 deletions src/blur.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ struct BlurRenderData
/// contains not blurred background behind the window, it's cached.
std::vector<std::unique_ptr<GLTexture>> textures;
std::vector<std::unique_ptr<GLFramebuffer>> framebuffers;

// Contains the blurred background behind the window. Used for corner anti-aliasing.
std::unique_ptr<GLTexture> blurTexture;
std::unique_ptr<GLFramebuffer> blurFramebuffer;
};

struct BlurEffectData
Expand Down

0 comments on commit bcf1cba

Please sign in to comment.