diff --git a/composite.cpp b/composite.cpp
index 57e0df5090..c65716b5ca 100644
--- a/composite.cpp
+++ b/composite.cpp
@@ -55,8 +55,6 @@ along with this program. If not, see .
#include "compositingprefs.h"
#include "notifications.h"
-#include
-
#include
#include
@@ -142,10 +140,6 @@ void Workspace::slotCompositingOptionsInitialized()
}
#endif
- kDebug(1212) << "Color correction:" << options->isColorCorrected();
- ColorCorrection::instance()->setEnabled(options->isColorCorrected());
- connect(ColorCorrection::instance(), SIGNAL(changed()), this, SLOT(addRepaintFull()));
-
scene = new SceneOpenGL(this);
// TODO: Add 30 second delay to protect against screen freezes as well
@@ -210,7 +204,6 @@ void Workspace::finishCompositing()
if (scene == NULL)
return;
m_finishingCompositing = true;
- ColorCorrection::cleanup();
delete cm_selection;
foreach (Client * c, clients)
scene->windowClosed(c, NULL);
diff --git a/libkwineffects/kwinglcolorcorrection.cpp b/libkwineffects/kwinglcolorcorrection.cpp
index a274827172..a3b6a0e3ff 100644
--- a/libkwineffects/kwinglcolorcorrection.cpp
+++ b/libkwineffects/kwinglcolorcorrection.cpp
@@ -221,23 +221,8 @@ static const char s_ccAlteration[] =
* Color Correction
*/
-ColorCorrection *ColorCorrection::s_colorCorrection = NULL;
-
-ColorCorrection *ColorCorrection::instance()
-{
- if (!s_colorCorrection)
- s_colorCorrection = new ColorCorrection;
- return s_colorCorrection;
-}
-
-void ColorCorrection::cleanup()
-{
- delete s_colorCorrection;
- s_colorCorrection = NULL;
-}
-
-ColorCorrection::ColorCorrection()
- : QObject()
+ColorCorrection::ColorCorrection(QObject *parent)
+ : QObject(parent)
, d_ptr(new ColorCorrectionPrivate(this))
{
@@ -305,6 +290,7 @@ void ColorCorrection::setEnabled(bool enabled)
#endif
d->m_enabled = enabled;
+ GLShader::sColorCorrect = enabled;
kDebug(1212) << enabled;
}
@@ -357,11 +343,6 @@ void ColorCorrection::reset()
QByteArray ColorCorrection::prepareFragmentShader(const QByteArray &sourceCode)
{
- Q_D(ColorCorrection);
-
- if (!d->m_enabled)
- return sourceCode;
-
bool sourceIsValid = true;
/*
diff --git a/libkwineffects/kwinglcolorcorrection.h b/libkwineffects/kwinglcolorcorrection.h
index 0c7e66b01f..ec080c0239 100644
--- a/libkwineffects/kwinglcolorcorrection.h
+++ b/libkwineffects/kwinglcolorcorrection.h
@@ -48,8 +48,8 @@ class KWIN_EXPORT ColorCorrection : public QObject
Q_OBJECT
public:
- static ColorCorrection *instance();
- static void cleanup();
+ explicit ColorCorrection(QObject *parent = 0);
+ virtual ~ColorCorrection();
/**
* Prepares color correction for the output number \param screen.
@@ -65,14 +65,11 @@ public:
void reset();
/**
- * When color correction is disabled, it does nothing and returns
- * \param sourceCode.
- *
- * Else, it modifies \param sourceCode, making it suitable for performing
+ * Modifies \param sourceCode, making it suitable for performing
* color correction. This is done by inserting a 3d texture lookup operation
* just before the output fragment color is returned.
*/
- QByteArray prepareFragmentShader(const QByteArray &sourceCode);
+ static QByteArray prepareFragmentShader(const QByteArray &sourceCode);
public slots:
/**
@@ -88,14 +85,9 @@ signals:
*/
void changed();
-private:
- ColorCorrection();
- virtual ~ColorCorrection();
-
private:
ColorCorrectionPrivate * const d_ptr;
Q_DECLARE_PRIVATE(ColorCorrection)
- static ColorCorrection *s_colorCorrection;
};
} // KWin namespace
diff --git a/libkwineffects/kwinglutils.cpp b/libkwineffects/kwinglutils.cpp
index edddc0d6a1..b4495c5dac 100644
--- a/libkwineffects/kwinglutils.cpp
+++ b/libkwineffects/kwinglutils.cpp
@@ -264,6 +264,8 @@ void popMatrix()
// GLShader
//****************************************
+bool GLShader::sColorCorrect = false;
+
GLShader::GLShader()
: mProgram(0)
, mValid(false)
@@ -318,8 +320,8 @@ const QByteArray GLShader::prepareSource(GLenum shaderType, const QByteArray &so
ba.append(source);
// Inject color correction code for fragment shaders, if possible
- if (shaderType == GL_FRAGMENT_SHADER)
- ba = ColorCorrection::instance()->prepareFragmentShader(ba);
+ if (shaderType == GL_FRAGMENT_SHADER && sColorCorrect)
+ ba = ColorCorrection::prepareFragmentShader(ba);
return ba;
}
diff --git a/libkwineffects/kwinglutils.h b/libkwineffects/kwinglutils.h
index 7f092a5772..42120d775b 100644
--- a/libkwineffects/kwinglutils.h
+++ b/libkwineffects/kwinglutils.h
@@ -220,6 +220,9 @@ private:
int mFloatLocation[FloatUniformCount];
int mIntLocation[IntUniformCount];
+ static bool sColorCorrect;
+
+ friend class ColorCorrection;
friend class ShaderManager;
};
diff --git a/scene_opengl.cpp b/scene_opengl.cpp
index ce4806b2f1..8682c0f8f0 100644
--- a/scene_opengl.cpp
+++ b/scene_opengl.cpp
@@ -122,6 +122,18 @@ bool SceneOpenGL::initFailed() const
return !init_ok;
}
+ColorCorrection* SceneOpenGL::colorCorrection()
+{
+ return m_colorCorrection;
+}
+
+void SceneOpenGL::initColorCorrection()
+{
+ kDebug(1212) << "Color correction:" << options->isColorCorrected();
+ m_colorCorrection->setEnabled(options->isColorCorrected());
+ connect(m_colorCorrection, SIGNAL(changed()), wspace, SLOT(addRepaintFull()));
+}
+
bool SceneOpenGL::selectMode()
{
if (!initDrawableConfigs())
@@ -243,7 +255,7 @@ void SceneOpenGL::performPaintWindow(EffectWindowImpl* w, int mask, QRegion regi
void SceneOpenGL::windowAdded(Toplevel* c)
{
assert(!windows.contains(c));
- windows[ c ] = new Window(c);
+ windows[ c ] = new Window(c, this);
connect(c, SIGNAL(opacityChanged(KWin::Toplevel*,qreal)), SLOT(windowOpacityChanged(KWin::Toplevel*)));
connect(c, SIGNAL(geometryShapeChanged(KWin::Toplevel*,QRect)), SLOT(windowGeometryShapeChanged(KWin::Toplevel*)));
connect(c, SIGNAL(windowClosed(KWin::Toplevel*,KWin::Deleted*)), SLOT(windowClosed(KWin::Toplevel*,KWin::Deleted*)));
@@ -375,7 +387,7 @@ bool SceneOpenGL::Texture::load(const QPixmap& pixmap, GLenum target)
// SceneOpenGL::Window
//****************************************
-SceneOpenGL::Window::Window(Toplevel* c)
+SceneOpenGL::Window::Window(Toplevel* c, SceneOpenGL* scene)
: Scene::Window(c)
, texture()
, topTexture()
@@ -383,6 +395,7 @@ SceneOpenGL::Window::Window(Toplevel* c)
, rightTexture()
, bottomTexture()
{
+ m_scene = scene;
}
SceneOpenGL::Window::~Window()
@@ -524,8 +537,7 @@ void SceneOpenGL::Window::performPaint(int mask, QRegion region, WindowPaintData
data.shader = ShaderManager::instance()->pushShader(ShaderManager::SimpleShader);
data.shader->setUniform(GLShader::Offset, QVector2D(x(), y()));
}
- if (options->isColorCorrected())
- ColorCorrection::instance()->setupForOutput(data.screen());
+ m_scene->colorCorrection()->setupForOutput(data.screen());
sceneShader = true;
}
@@ -883,8 +895,7 @@ void SceneOpenGL::Window::prepareShaderRenderStates(TextureType type, double opa
shader->setUniform(GLShader::Saturation, saturation);
shader->setUniform(GLShader::AlphaToOne, opaque ? 1 : 0);
- if (options->isColorCorrected())
- ColorCorrection::instance()->setupForOutput(screen);
+ m_scene->colorCorrection()->setupForOutput(screen);
}
void SceneOpenGL::Window::prepareRenderStates(TextureType type, double opacity, double brightness, double saturation, int screen, GLTexture *tex)
diff --git a/scene_opengl.h b/scene_opengl.h
index 45e5e29507..e482269baa 100644
--- a/scene_opengl.h
+++ b/scene_opengl.h
@@ -31,6 +31,7 @@ along with this program. If not, see .
namespace KWin
{
+class ColorCorrection;
class LanczosFilter;
class SceneOpenGL
@@ -55,6 +56,8 @@ public:
void idle();
+ ColorCorrection *colorCorrection();
+
protected:
virtual void paintGenericScreen(int mask, ScreenPaintData data);
virtual void paintBackground(QRegion region);
@@ -71,6 +74,7 @@ private:
bool initRenderingContext();
bool initBufferConfigs();
bool initDrawableConfigs();
+ void initColorCorrection();
void waitSync();
#ifndef KWIN_HAVE_OPENGLES
void setupModelViewProjectionMatrix();
@@ -111,6 +115,7 @@ private:
QRegion m_lastDamage;
int m_lastMask;
QWeakPointer m_lanczosFilter;
+ ColorCorrection *m_colorCorrection;
};
class SceneOpenGL::TexturePrivate
@@ -166,7 +171,7 @@ class SceneOpenGL::Window
: public Scene::Window
{
public:
- Window(Toplevel* c);
+ Window(Toplevel* c, SceneOpenGL* scene);
virtual ~Window();
virtual void performPaint(int mask, QRegion region, WindowPaintData data);
virtual void pixmapDiscarded();
@@ -204,6 +209,7 @@ private:
Texture leftTexture;
Texture rightTexture;
Texture bottomTexture;
+ SceneOpenGL *m_scene;
};
class SceneOpenGL::EffectFrame
diff --git a/scene_opengl_egl.cpp b/scene_opengl_egl.cpp
index 33e8960413..2803c5f519 100644
--- a/scene_opengl_egl.cpp
+++ b/scene_opengl_egl.cpp
@@ -31,6 +31,7 @@ int surfaceHasSubPost;
SceneOpenGL::SceneOpenGL(Workspace* ws)
: Scene(ws)
, init_ok(false)
+ , m_colorCorrection(new ColorCorrection(this))
{
if (!initRenderingContext())
return;
@@ -51,6 +52,7 @@ SceneOpenGL::SceneOpenGL(Workspace* ws)
return;
}
debug = qstrcmp(qgetenv("KWIN_GL_DEBUG"), "1") == 0;
+ initColorCorrection();
if (!ShaderManager::instance()->isValid()) {
kError(1212) << "Shaders not valid, ES compositing not possible";
return;
diff --git a/scene_opengl_glx.cpp b/scene_opengl_glx.cpp
index e0654b5861..0b774360e8 100644
--- a/scene_opengl_glx.cpp
+++ b/scene_opengl_glx.cpp
@@ -39,6 +39,7 @@ SceneOpenGL::SceneOpenGL(Workspace* ws)
: Scene(ws)
, m_resetModelViewProjectionMatrix(true)
, init_ok(false)
+ , m_colorCorrection(new ColorCorrection(this))
{
initGLX();
// check for FBConfig support
@@ -102,6 +103,8 @@ SceneOpenGL::SceneOpenGL(Workspace* ws)
debug = qstrcmp(qgetenv("KWIN_GL_DEBUG"), "1") == 0;
+ initColorCorrection();
+
// scene shader setup
if (GLPlatform::instance()->supports(GLSL)) {
if (!ShaderManager::instance()->isValid()) {