fade out the effect if the window opacity is < 1

This commit is contained in:
Marco Martin 2014-01-23 14:33:19 +01:00
parent 65c3c4c1b4
commit b7ded05596
3 changed files with 34 additions and 2 deletions

View file

@ -384,6 +384,8 @@ void ContrastEffect::doContrast(const QRegion& shape, const QRect& screen, const
shader->bind();
shader->setOpacity(opacity);
// Set up the texture matrix to transform from screen coordinates
// to texture coordinates.
#ifdef KWIN_HAVE_OPENGL_1

View file

@ -35,7 +35,7 @@ using namespace KWin;
ContrastShader::ContrastShader()
: mValid(false), shader(NULL)
: mValid(false), shader(NULL), m_opacity(1)
{
}
@ -93,6 +93,20 @@ bool ContrastShader::supported()
return true;
}
void ContrastShader::setOpacity(float opacity)
{
m_opacity = opacity;
ShaderManager::instance()->pushShader(shader);
shader->setUniform(opacityLocation, opacity);
ShaderManager::instance()->popShader();
}
float ContrastShader::opacity() const
{
return m_opacity;
}
void ContrastShader::setColorMatrix(const QMatrix4x4 &matrix)
{
if (!isValid())
@ -181,6 +195,7 @@ void ContrastShader::init()
stream2 << "uniform mat4 colorMatrix;\n";
stream2 << "uniform sampler2D sampler;\n";
stream2 << "uniform float opacity;\n";
stream2 << "in vec4 varyingTexCoords;\n";
if (glsl_140)
@ -189,8 +204,16 @@ void ContrastShader::init()
stream2 << "void main(void)\n";
stream2 << "{\n";
stream2 << " vec4 tex = " << texture2D << "(sampler, varyingTexCoords.st);\n";
stream2 << " mat4 identity = mat4(1.0, 0.0, 0.0, 0.0,\n";
stream2 << " 0.0, 1.0, 0.0, 0.0,\n";
stream2 << " 0.0, 0.0, 1.0, 0.0,\n";
stream2 << " 0.0, 0.0, 0.0, 1.0);\n";
stream2 << " " << fragColor << " = tex * colorMatrix;\n";
stream2 << " if (opacity >= 1.0) {\n";
stream2 << " " << fragColor << " = tex * colorMatrix;\n";
stream2 << " } else {\n";
stream2 << " " << fragColor << " = tex * (opacity * colorMatrix + (1-opacity) * identity);\n";
stream2 << " }\n";
stream2 << "}\n";
stream2.flush();
@ -201,6 +224,7 @@ void ContrastShader::init()
colorMatrixLocation = shader->uniformLocation("colorMatrix");
textureMatrixLocation = shader->uniformLocation("textureMatrix");
mvpMatrixLocation = shader->uniformLocation("modelViewProjectionMatrix");
opacityLocation = shader->uniformLocation("opacity");
QMatrix4x4 modelViewProjection;
modelViewProjection.ortho(0, displayWidth(), displayHeight(), 0, 0, 65535);
@ -208,6 +232,7 @@ void ContrastShader::init()
shader->setUniform(colorMatrixLocation, QMatrix4x4());
shader->setUniform(textureMatrixLocation, QMatrix4x4());
shader->setUniform(mvpMatrixLocation, modelViewProjection);
shader->setUniform(opacityLocation, (float)1.0);
ShaderManager::instance()->popShader();
}

View file

@ -52,6 +52,9 @@ public:
static bool supported();
void setOpacity(float opacity);
float opacity() const;
protected:
void setIsValid(bool value) {
mValid = value;
@ -65,6 +68,8 @@ private:
int textureMatrixLocation;
int colorMatrixLocation;
int pixelSizeLocation;
int opacityLocation;
float m_opacity;
};