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 "notifications.h"
|
||||
|
||||
#include <kwinglcolorcorrection.h>
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include <QtCore/QtConcurrentRun>
|
||||
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
||||
/*
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -220,6 +220,9 @@ private:
|
|||
int mFloatLocation[FloatUniformCount];
|
||||
int mIntLocation[IntUniformCount];
|
||||
|
||||
static bool sColorCorrect;
|
||||
|
||||
friend class ColorCorrection;
|
||||
friend class ShaderManager;
|
||||
};
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -31,6 +31,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
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<LanczosFilter> 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
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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()) {
|
||||
|
|
Loading…
Reference in a new issue