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