From c82351488e99d061f2cb361e780a80b03b7afb5e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fredrik=20H=C3=B6glund?= Date: Fri, 12 Mar 2010 15:56:19 +0000 Subject: [PATCH] Make sure that both the render target and the shader are valid before using them. svn path=/trunk/KDE/kdebase/workspace/; revision=1102465 --- effects/blur/blur.cpp | 3 ++- effects/blur/blurshader.cpp | 27 +++++++++++++++++++++------ effects/blur/blurshader.h | 4 ++++ 3 files changed, 27 insertions(+), 7 deletions(-) diff --git a/effects/blur/blur.cpp b/effects/blur/blur.cpp index badf69a82b..354319795a 100644 --- a/effects/blur/blur.cpp +++ b/effects/blur/blur.cpp @@ -162,12 +162,13 @@ void BlurEffect::drawWindow(EffectWindow *w, int mask, QRegion region, WindowPai bool translated = data.xTranslate || data.yTranslate; bool transformed = scaled || translated; bool hasAlpha = w->hasAlpha() || (w->hasDecoration() && effects->decorationsHaveAlpha()); + bool valid = target->valid() && shader->isValid(); QRegion shape; if (!effects->activeFullScreenEffect() && hasAlpha && !w->isDesktop() && !transformed) shape = blurRegion(w).translated(w->geometry().topLeft()) & screen; - if (!shape.isEmpty() && region.intersects(shape.boundingRect())) + if (valid && !shape.isEmpty() && region.intersects(shape.boundingRect())) { const QRect r = expand(shape.boundingRect()) & screen; const QPoint offset = -shape.boundingRect().topLeft() + diff --git a/effects/blur/blurshader.cpp b/effects/blur/blurshader.cpp index 2220697a8a..581ef28917 100644 --- a/effects/blur/blurshader.cpp +++ b/effects/blur/blurshader.cpp @@ -29,7 +29,7 @@ using namespace KWin; BlurShader::BlurShader() - : mRadius(12) + : mRadius(0), mValid(false) { } @@ -52,6 +52,7 @@ void BlurShader::setRadius(int radius) if (mRadius != r) { mRadius = r; reset(); + init(); } } @@ -117,10 +118,15 @@ void GLSLBlurShader::reset() glDeleteProgram(program); program = 0; } + + setIsValid(false); } void GLSLBlurShader::setPixelDistance(float val) { + if (!isValid()) + return; + float pixelSize[2] = { 0.0, 0.0 }; if (direction() == Qt::Horizontal) @@ -133,14 +139,17 @@ void GLSLBlurShader::setPixelDistance(float val) void GLSLBlurShader::setOpacity(float val) { + if (!isValid()) + return; + const float opacity[4] = { val, val, val, val }; glUniform4fv(uOpacity, 1, opacity); } void GLSLBlurShader::bind() { - if (!program) - init(); + if (!isValid()) + return; glUseProgram(program); glUniform1i(uTexUnit, 0); @@ -284,6 +293,8 @@ void GLSLBlurShader::init() uPixelSize = glGetUniformLocation(program, "pixelSize"); uOpacity = glGetUniformLocation(program, "opacity"); } + + setIsValid(program != 0); } @@ -308,6 +319,8 @@ void ARBBlurShader::reset() glDeleteProgramsARB(1, &program); program = 0; } + + setIsValid(false); } void ARBBlurShader::setPixelDistance(float val) @@ -331,8 +344,8 @@ void ARBBlurShader::setOpacity(float val) void ARBBlurShader::bind() { - if (!program) - init(); + if (!isValid()) + return; glEnable(GL_FRAGMENT_PROGRAM_ARB); glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, program); @@ -413,7 +426,9 @@ void ARBBlurShader::init() if (glGetError()) { const char *error = (const char*)glGetString(GL_PROGRAM_ERROR_STRING_ARB); kError() << "Failed to compile fragment program:" << error; - } + setIsValid(false); + } else + setIsValid(true); glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, 0); } diff --git a/effects/blur/blurshader.h b/effects/blur/blurshader.h index 9340700c78..b42e6f6ce6 100644 --- a/effects/blur/blurshader.h +++ b/effects/blur/blurshader.h @@ -33,6 +33,8 @@ public: static BlurShader *create(); + bool isValid() const { return mValid; } + // Sets the radius in pixels void setRadius(int radius); int radius() const { return mRadius; } @@ -53,6 +55,7 @@ public: protected: float gaussian(float x, float sigma) const; QVector gaussianKernel() const; + void setIsValid(bool value) { mValid = value; } virtual void init() = 0; virtual void reset() = 0; virtual int maxKernelSize() const = 0; @@ -60,6 +63,7 @@ protected: private: int mRadius; Qt::Orientation mDirection; + bool mValid; };