no subclass for the shader

* get rid of the strength property
* this effect doesn't have config
icc-effect-5.14.5
Marco Martin 2014-01-05 17:20:50 +01:00
parent 4036f179fc
commit 4f2d2e469d
3 changed files with 26 additions and 83 deletions

View File

@ -74,11 +74,6 @@ void ContrastEffect::reconfigure(ReconfigureFlags flags)
{ {
Q_UNUSED(flags) Q_UNUSED(flags)
ContrastConfig::self()->readConfig();
int strength = 4;
if (shader)
shader->setStrength(strength);
if (!shader || !shader->isValid()) if (!shader || !shader->isValid())
XDeleteProperty(display(), rootWindow(), net_wm_contrast_region); XDeleteProperty(display(), rootWindow(), net_wm_contrast_region);
} }
@ -136,7 +131,7 @@ bool ContrastEffect::enabledByDefault()
bool ContrastEffect::supported() bool ContrastEffect::supported()
{ {
bool supported = GLRenderTarget::supported() && GLTexture::NPOTTextureSupported() && GLSLContrastShader::supported(); bool supported = GLRenderTarget::supported() && GLTexture::NPOTTextureSupported() && ContrastShader::supported();
if (supported) { if (supported) {
int maxTexSize; int maxTexSize;

View File

@ -34,48 +34,28 @@ using namespace KWin;
ContrastShader::ContrastShader() ContrastShader::ContrastShader()
: mStrength(0), mValid(false) : shader(NULL), mValid(false)
{ {
} }
ContrastShader::~ContrastShader() ContrastShader::~ContrastShader()
{ {
reset();
} }
ContrastShader *ContrastShader::create() ContrastShader *ContrastShader::create()
{ {
if (GLSLContrastShader::supported()) if (ContrastShader::supported()) {
return new GLSLContrastShader(); ContrastShader *s = new ContrastShader();
s->reset();
s->init();
return s;
}
return NULL; return NULL;
} }
void ContrastShader::setStrength(int radius) void ContrastShader::reset()
{
const int r = qMax(radius, 2);
if (mStrength != r) {
mStrength = r;
reset();
init();
}
}
// ----------------------------------------------------------------------------
GLSLContrastShader::GLSLContrastShader()
: ContrastShader(), shader(NULL)
{
}
GLSLContrastShader::~GLSLContrastShader()
{
reset();
}
void GLSLContrastShader::reset()
{ {
delete shader; delete shader;
shader = NULL; shader = NULL;
@ -83,7 +63,7 @@ void GLSLContrastShader::reset()
setIsValid(false); setIsValid(false);
} }
bool GLSLContrastShader::supported() bool ContrastShader::supported()
{ {
if (!GLPlatform::instance()->supports(GLSL)) if (!GLPlatform::instance()->supports(GLSL))
return false; return false;
@ -115,7 +95,7 @@ bool GLSLContrastShader::supported()
return true; return true;
} }
void GLSLContrastShader::setColorMatrix(const QMatrix4x4 &matrix) void ContrastShader::setColorMatrix(const QMatrix4x4 &matrix)
{ {
if (!isValid()) if (!isValid())
return; return;
@ -125,7 +105,7 @@ void GLSLContrastShader::setColorMatrix(const QMatrix4x4 &matrix)
ShaderManager::instance()->popShader(); ShaderManager::instance()->popShader();
} }
void GLSLContrastShader::setTextureMatrix(const QMatrix4x4 &matrix) void ContrastShader::setTextureMatrix(const QMatrix4x4 &matrix)
{ {
if (!isValid()) if (!isValid())
return; return;
@ -133,7 +113,7 @@ void GLSLContrastShader::setTextureMatrix(const QMatrix4x4 &matrix)
shader->setUniform(textureMatrixLocation, matrix); shader->setUniform(textureMatrixLocation, matrix);
} }
void GLSLContrastShader::setModelViewProjectionMatrix(const QMatrix4x4 &matrix) void ContrastShader::setModelViewProjectionMatrix(const QMatrix4x4 &matrix)
{ {
if (!isValid()) if (!isValid())
return; return;
@ -141,7 +121,7 @@ void GLSLContrastShader::setModelViewProjectionMatrix(const QMatrix4x4 &matrix)
shader->setUniform(mvpMatrixLocation, matrix); shader->setUniform(mvpMatrixLocation, matrix);
} }
void GLSLContrastShader::bind() void ContrastShader::bind()
{ {
if (!isValid()) if (!isValid())
return; return;
@ -149,12 +129,12 @@ void GLSLContrastShader::bind()
ShaderManager::instance()->pushShader(shader); ShaderManager::instance()->pushShader(shader);
} }
void GLSLContrastShader::unbind() void ContrastShader::unbind()
{ {
ShaderManager::instance()->popShader(); ShaderManager::instance()->popShader();
} }
void GLSLContrastShader::init() void ContrastShader::init()
{ {

View File

@ -39,57 +39,25 @@ public:
return mValid; return mValid;
} }
// Sets the radius in pixels void setColorMatrix(const QMatrix4x4 &matrix);
void setStrength(int strength);
int strength() const {
return mStrength;
}
virtual void setColorMatrix(const QMatrix4x4 &matrix) = 0;
virtual void setTextureMatrix(const QMatrix4x4 &matrix) = 0; void setTextureMatrix(const QMatrix4x4 &matrix);
virtual void setModelViewProjectionMatrix(const QMatrix4x4 &matrix) = 0; void setModelViewProjectionMatrix(const QMatrix4x4 &matrix);
virtual void bind() = 0;
virtual void unbind() = 0;
protected:
float gaussian(float x, float sigma) const;
void setIsValid(bool value) {
mValid = value;
}
virtual void init() = 0;
virtual void reset() = 0;
private:
int mStrength;
bool mValid;
};
// ----------------------------------------------------------------------------
class GLSLContrastShader : public ContrastShader
{
public:
GLSLContrastShader();
~GLSLContrastShader();
void bind(); void bind();
void unbind(); void unbind();
void setColorMatrix(const QMatrix4x4 &matrix);
void setTextureMatrix(const QMatrix4x4 &matrix);
void setModelViewProjectionMatrix(const QMatrix4x4 &matrix);
static bool supported(); static bool supported();
protected: protected:
void init(); void setIsValid(bool value) {
void reset(); mValid = value;
}
virtual void init();
virtual void reset();
private: private:
bool mValid;
GLShader *shader; GLShader *shader;
int mvpMatrixLocation; int mvpMatrixLocation;
int textureMatrixLocation; int textureMatrixLocation;