2007-11-27 19:40:25 +00:00
|
|
|
/********************************************************************
|
2007-04-29 17:35:43 +00:00
|
|
|
KWin - the KDE window manager
|
|
|
|
This file is part of the KDE project.
|
|
|
|
|
|
|
|
Copyright (C) 2006 Lubos Lunak <l.lunak@kde.org>
|
2011-03-27 10:33:07 +00:00
|
|
|
Copyright (C) 2009, 2010, 2011 Martin Gräßlin <mgraesslin@kde.org>
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2007-11-27 19:40:25 +00:00
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*********************************************************************/
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
#ifndef KWIN_SCENE_OPENGL_H
|
|
|
|
#define KWIN_SCENE_OPENGL_H
|
|
|
|
|
|
|
|
#include "scene.h"
|
2011-03-27 10:33:07 +00:00
|
|
|
#include "shadow.h"
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
#include "kwinglutils.h"
|
2011-07-18 15:55:39 +00:00
|
|
|
#include "kwingltexture_p.h"
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2014-07-22 11:11:19 +00:00
|
|
|
#include "decorations/decorationrenderer.h"
|
|
|
|
|
2007-04-29 17:35:43 +00:00
|
|
|
namespace KWin
|
|
|
|
{
|
2012-11-13 20:41:02 +00:00
|
|
|
class ColorCorrection;
|
|
|
|
class LanczosFilter;
|
2012-08-26 15:14:23 +00:00
|
|
|
class OpenGLBackend;
|
2014-09-03 16:43:38 +00:00
|
|
|
class SyncManager;
|
|
|
|
class SyncObject;
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2016-04-12 13:03:07 +00:00
|
|
|
class KWIN_EXPORT SceneOpenGL
|
2007-04-29 17:35:43 +00:00
|
|
|
: public Scene
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2011-06-15 16:35:00 +00:00
|
|
|
Q_OBJECT
|
2011-01-30 14:34:42 +00:00
|
|
|
public:
|
|
|
|
class EffectFrame;
|
|
|
|
class Texture;
|
2011-07-18 15:55:39 +00:00
|
|
|
class TexturePrivate;
|
2011-01-30 14:34:42 +00:00
|
|
|
class Window;
|
|
|
|
virtual ~SceneOpenGL();
|
|
|
|
virtual bool initFailed() const;
|
2012-08-26 15:14:23 +00:00
|
|
|
virtual bool hasPendingFlush() const;
|
2013-03-28 20:53:25 +00:00
|
|
|
virtual qint64 paint(QRegion damage, ToplevelList windows);
|
2013-06-24 06:49:24 +00:00
|
|
|
virtual Scene::EffectFrame *createEffectFrame(EffectFrameImpl *frame);
|
2013-06-24 07:06:50 +00:00
|
|
|
virtual Shadow *createShadow(Toplevel *toplevel);
|
2011-11-26 15:15:46 +00:00
|
|
|
virtual void screenGeometryChanged(const QSize &size);
|
2012-08-26 15:14:23 +00:00
|
|
|
virtual OverlayWindow *overlayWindow();
|
2013-06-19 10:26:34 +00:00
|
|
|
virtual bool usesOverlayWindow() const;
|
2013-03-28 20:52:26 +00:00
|
|
|
virtual bool blocksForRetrace() const;
|
|
|
|
virtual bool syncsToVBlank() const;
|
Better handling for making the compositing OpenGL context current
With QtQuick2 it's possible that the scene graph rendering context either
lives in an own thread or uses the main GUI thread. In the latter case
it's the same thread as our compositing OpenGL context lives in. This
means our basic assumption that between two rendering passes the context
stays current does not hold.
The code already ensured that before we start a rendering pass the
context is made current, but there are many more possible cases. If we
use OpenGL in areas not triggered by the rendering loop but in response
to other events the context needs to be made current. This includes the
loading and unloading of effects (some effects use OpenGL in the static
effect check, in the ctor and dtor), background loading of texture data,
lazy loading after first usage invoked by shortcut, etc. etc.
To properly handle these cases new methods are added to EffectsHandler
to make the compositing OpenGL context current. These calls delegate down
into the scene. On non-OpenGL scenes they are noop, but on OpenGL they go
into the backend and make the context current. In addition they ensure
that Qt doesn't think that it's QOpenGLContext is current by calling
doneCurrent() on the QOpenGLContext::currentContext(). This unfortunately
causes an additional call to makeCurrent with a null context, but there
is no other way to tell Qt - it doesn't notice when a different context
is made current with low level API calls. In the multi-threaded
architecture this doesn't matter as ::currentContext() returns null.
A short evaluation showed that a transition to QOpenGLContext doesn't
seem feasible. Qt only supports either GLX or EGL while KWin supports
both and when entering the transition phase for Wayland, it would become
extremely tricky if our native platform is X11, but we want a Wayland
EGL context. A future solution might be to have a "KWin-QPA plugin" which
uses either xcb or Wayland and hides everything from Qt.
The API documentation is extended to describe when the effects-framework
ensures that an OpenGL context is current. The effects are changed to
make the context current in cases where it's not guaranteed. This has
been done by looking for creation or deletion of GLTextures and Shaders.
If there are other OpenGL usages outside the rendering loop, ctor/dtor
this needs to be changed, too.
2013-11-22 14:05:36 +00:00
|
|
|
virtual bool makeOpenGLContextCurrent() override;
|
|
|
|
virtual void doneOpenGLContextCurrent() override;
|
2014-07-22 11:11:19 +00:00
|
|
|
Decoration::Renderer *createDecorationRenderer(Decoration::DecoratedClientImpl *impl) override;
|
2014-09-03 16:43:38 +00:00
|
|
|
virtual void triggerFence() override;
|
2015-11-26 13:48:57 +00:00
|
|
|
virtual QMatrix4x4 projectionMatrix() const = 0;
|
2016-08-10 07:24:53 +00:00
|
|
|
bool animationsSupported() const override;
|
2014-09-03 16:43:38 +00:00
|
|
|
|
|
|
|
void insertWait();
|
2011-02-17 17:37:43 +00:00
|
|
|
|
2012-03-29 20:11:28 +00:00
|
|
|
void idle();
|
|
|
|
|
2013-03-17 11:58:36 +00:00
|
|
|
bool debug() const { return m_debug; }
|
2014-11-19 18:01:55 +00:00
|
|
|
void initDebugOutput();
|
2013-03-17 11:58:36 +00:00
|
|
|
|
2012-08-26 15:14:23 +00:00
|
|
|
/**
|
|
|
|
* @brief Factory method to create a backend specific texture.
|
|
|
|
*
|
|
|
|
* @return :SceneOpenGL::Texture*
|
|
|
|
**/
|
|
|
|
Texture *createTexture();
|
|
|
|
|
2015-08-17 09:40:01 +00:00
|
|
|
OpenGLBackend *backend() const {
|
|
|
|
return m_backend;
|
|
|
|
}
|
|
|
|
|
2013-03-22 11:17:58 +00:00
|
|
|
/**
|
|
|
|
* Copy a region of pixels from the current read to the current draw buffer
|
|
|
|
*/
|
|
|
|
static void copyPixels(const QRegion ®ion);
|
|
|
|
|
2015-02-23 13:41:45 +00:00
|
|
|
static SceneOpenGL *createScene(QObject *parent);
|
2012-09-06 15:13:22 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
protected:
|
2015-02-23 13:41:45 +00:00
|
|
|
SceneOpenGL(OpenGLBackend *backend, QObject *parent = nullptr);
|
2011-01-30 14:34:42 +00:00
|
|
|
virtual void paintBackground(QRegion region);
|
2013-02-18 22:17:46 +00:00
|
|
|
virtual void extendPaintRegion(QRegion ®ion, bool opaqueFullscreen);
|
2011-02-17 17:37:43 +00:00
|
|
|
QMatrix4x4 transformation(int mask, const ScreenPaintData &data) const;
|
2012-03-29 18:17:57 +00:00
|
|
|
virtual void paintDesktop(int desktop, int mask, const QRegion ®ion, ScreenPaintData &data);
|
2012-09-06 15:13:22 +00:00
|
|
|
|
2013-05-19 14:45:06 +00:00
|
|
|
void handleGraphicsReset(GLenum status);
|
|
|
|
|
2012-09-06 15:13:22 +00:00
|
|
|
virtual void doPaintBackground(const QVector<float> &vertices) = 0;
|
2015-11-26 13:48:57 +00:00
|
|
|
virtual void updateProjectionMatrix() = 0;
|
2013-05-19 14:45:06 +00:00
|
|
|
|
|
|
|
Q_SIGNALS:
|
|
|
|
void resetCompositing();
|
|
|
|
|
2012-09-06 15:13:22 +00:00
|
|
|
protected:
|
|
|
|
bool init_ok;
|
2012-10-16 20:41:21 +00:00
|
|
|
private:
|
|
|
|
bool viewportLimitsMatched(const QSize &size) const;
|
2011-01-30 14:34:42 +00:00
|
|
|
private:
|
2013-03-17 11:58:36 +00:00
|
|
|
bool m_debug;
|
2012-08-26 15:14:23 +00:00
|
|
|
OpenGLBackend *m_backend;
|
2014-09-03 16:43:38 +00:00
|
|
|
SyncManager *m_syncManager;
|
|
|
|
SyncObject *m_currentFence;
|
2011-01-30 14:34:42 +00:00
|
|
|
};
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2012-09-06 15:13:22 +00:00
|
|
|
class SceneOpenGL2 : public SceneOpenGL
|
|
|
|
{
|
2012-11-13 20:41:02 +00:00
|
|
|
Q_OBJECT
|
2012-09-06 15:13:22 +00:00
|
|
|
public:
|
2015-02-23 13:41:45 +00:00
|
|
|
explicit SceneOpenGL2(OpenGLBackend *backend, QObject *parent = nullptr);
|
2012-09-06 15:13:22 +00:00
|
|
|
virtual ~SceneOpenGL2();
|
2012-09-20 09:33:32 +00:00
|
|
|
virtual CompositingType compositingType() const {
|
|
|
|
return OpenGL2Compositing;
|
|
|
|
}
|
2012-09-06 15:13:22 +00:00
|
|
|
|
|
|
|
static bool supported(OpenGLBackend *backend);
|
|
|
|
|
2012-11-13 20:41:02 +00:00
|
|
|
ColorCorrection *colorCorrection();
|
2015-11-26 13:48:57 +00:00
|
|
|
QMatrix4x4 projectionMatrix() const override { return m_projectionMatrix; }
|
2015-11-30 13:35:12 +00:00
|
|
|
QMatrix4x4 screenProjectionMatrix() const override { return m_screenProjectionMatrix; }
|
2012-11-13 20:41:02 +00:00
|
|
|
|
2012-09-06 15:13:22 +00:00
|
|
|
protected:
|
2014-04-01 16:08:27 +00:00
|
|
|
virtual void paintSimpleScreen(int mask, QRegion region);
|
2012-09-06 15:13:22 +00:00
|
|
|
virtual void paintGenericScreen(int mask, ScreenPaintData data);
|
|
|
|
virtual void doPaintBackground(const QVector< float >& vertices);
|
2013-06-24 07:53:11 +00:00
|
|
|
virtual Scene::Window *createWindow(Toplevel *t);
|
2012-11-13 20:41:02 +00:00
|
|
|
virtual void finalDrawWindow(EffectWindowImpl* w, int mask, QRegion region, WindowPaintData& data);
|
2015-11-26 13:48:57 +00:00
|
|
|
virtual void updateProjectionMatrix() override;
|
2012-11-13 20:41:02 +00:00
|
|
|
|
|
|
|
private Q_SLOTS:
|
2013-09-04 12:42:45 +00:00
|
|
|
void slotColorCorrectedChanged(bool recreateShaders = true);
|
2013-02-08 11:12:51 +00:00
|
|
|
void resetLanczosFilter();
|
2012-11-13 20:41:02 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
void performPaintWindow(EffectWindowImpl* w, int mask, QRegion region, WindowPaintData& data);
|
2014-04-01 16:08:27 +00:00
|
|
|
QMatrix4x4 createProjectionMatrix() const;
|
2012-11-13 20:41:02 +00:00
|
|
|
|
|
|
|
private:
|
2013-02-08 11:12:51 +00:00
|
|
|
LanczosFilter *m_lanczosFilter;
|
2013-09-04 12:42:45 +00:00
|
|
|
QScopedPointer<ColorCorrection> m_colorCorrection;
|
2014-04-01 16:08:27 +00:00
|
|
|
QMatrix4x4 m_projectionMatrix;
|
|
|
|
QMatrix4x4 m_screenProjectionMatrix;
|
2013-03-13 16:03:30 +00:00
|
|
|
GLuint vao;
|
2012-09-06 15:13:22 +00:00
|
|
|
};
|
|
|
|
|
2011-07-18 15:55:39 +00:00
|
|
|
class SceneOpenGL::TexturePrivate
|
|
|
|
: public GLTexturePrivate
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
virtual ~TexturePrivate();
|
|
|
|
|
2015-02-11 10:00:12 +00:00
|
|
|
virtual bool loadTexture(WindowPixmap *pixmap) = 0;
|
|
|
|
virtual void updateTexture(WindowPixmap *pixmap);
|
2012-08-26 15:14:23 +00:00
|
|
|
virtual OpenGLBackend *backend() = 0;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
TexturePrivate();
|
2011-07-18 15:55:39 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
Q_DISABLE_COPY(TexturePrivate)
|
|
|
|
};
|
|
|
|
|
2007-04-29 17:35:43 +00:00
|
|
|
class SceneOpenGL::Texture
|
|
|
|
: public GLTexture
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
public:
|
2012-08-26 15:14:23 +00:00
|
|
|
Texture(OpenGLBackend *backend);
|
2011-01-30 14:34:42 +00:00
|
|
|
virtual ~Texture();
|
|
|
|
|
2011-07-18 15:55:39 +00:00
|
|
|
Texture & operator = (const Texture& tex);
|
|
|
|
|
2014-11-26 20:37:14 +00:00
|
|
|
void discard() override final;
|
2011-01-30 14:34:42 +00:00
|
|
|
|
|
|
|
protected:
|
2015-02-11 10:00:12 +00:00
|
|
|
bool load(WindowPixmap *pixmap);
|
|
|
|
void updateFromPixmap(WindowPixmap *pixmap);
|
2011-01-30 14:34:42 +00:00
|
|
|
|
2011-07-18 15:55:39 +00:00
|
|
|
Texture(TexturePrivate& dd);
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2011-07-18 15:55:39 +00:00
|
|
|
private:
|
2011-08-27 07:31:38 +00:00
|
|
|
Q_DECLARE_PRIVATE(Texture)
|
2011-05-12 16:52:38 +00:00
|
|
|
|
2013-05-10 10:07:56 +00:00
|
|
|
friend class OpenGLWindowPixmap;
|
2011-01-30 14:34:42 +00:00
|
|
|
};
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
class SceneOpenGL::Window
|
|
|
|
: public Scene::Window
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
virtual ~Window();
|
2013-03-17 12:34:26 +00:00
|
|
|
bool beginRenderWindow(int mask, const QRegion ®ion, WindowPaintData &data);
|
|
|
|
virtual void performPaint(int mask, QRegion region, WindowPaintData data) = 0;
|
|
|
|
void endRenderWindow();
|
2011-01-30 14:34:42 +00:00
|
|
|
bool bindTexture();
|
2012-08-16 19:19:54 +00:00
|
|
|
void setScene(SceneOpenGL *scene) {
|
|
|
|
m_scene = scene;
|
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
|
|
|
|
protected:
|
2013-05-10 10:07:56 +00:00
|
|
|
virtual WindowPixmap* createWindowPixmap();
|
2012-09-06 10:25:55 +00:00
|
|
|
Window(Toplevel* c);
|
2011-01-30 14:34:42 +00:00
|
|
|
enum TextureType {
|
|
|
|
Content,
|
2013-09-16 17:50:02 +00:00
|
|
|
Decoration,
|
2011-03-27 10:33:07 +00:00
|
|
|
Shadow
|
2007-04-29 17:35:43 +00:00
|
|
|
};
|
2011-02-15 17:10:54 +00:00
|
|
|
|
|
|
|
QMatrix4x4 transformation(int mask, const WindowPaintData &data) const;
|
2013-09-16 17:50:02 +00:00
|
|
|
GLTexture *getDecorationTexture() const;
|
2012-09-06 10:25:55 +00:00
|
|
|
|
2012-11-13 20:41:02 +00:00
|
|
|
protected:
|
|
|
|
SceneOpenGL *m_scene;
|
2013-03-17 10:50:47 +00:00
|
|
|
bool m_hardwareClipping;
|
2011-01-30 14:34:42 +00:00
|
|
|
};
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2012-09-06 10:25:55 +00:00
|
|
|
class SceneOpenGL2Window : public SceneOpenGL::Window
|
|
|
|
{
|
|
|
|
public:
|
2013-09-16 17:50:02 +00:00
|
|
|
enum Leaf { ShadowLeaf = 0, DecorationLeaf, ContentLeaf, PreviousContentLeaf, LeafCount };
|
2013-03-18 15:45:53 +00:00
|
|
|
|
|
|
|
struct LeafNode
|
|
|
|
{
|
|
|
|
LeafNode()
|
|
|
|
: texture(0),
|
|
|
|
firstVertex(0),
|
|
|
|
vertexCount(0),
|
|
|
|
opacity(1.0),
|
|
|
|
hasAlpha(false),
|
|
|
|
coordinateType(UnnormalizedCoordinates)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
GLTexture *texture;
|
|
|
|
int firstVertex;
|
|
|
|
int vertexCount;
|
|
|
|
float opacity;
|
|
|
|
bool hasAlpha;
|
|
|
|
TextureCoordinateType coordinateType;
|
|
|
|
};
|
|
|
|
|
2012-12-29 06:34:38 +00:00
|
|
|
explicit SceneOpenGL2Window(Toplevel *c);
|
2012-09-06 10:25:55 +00:00
|
|
|
virtual ~SceneOpenGL2Window();
|
|
|
|
|
|
|
|
protected:
|
2014-04-01 16:08:48 +00:00
|
|
|
QMatrix4x4 modelViewProjectionMatrix(int mask, const WindowPaintData &data) const;
|
2013-03-17 12:34:26 +00:00
|
|
|
QVector4D modulate(float opacity, float brightness) const;
|
|
|
|
void setBlendEnabled(bool enabled);
|
2013-03-18 15:45:53 +00:00
|
|
|
void setupLeafNodes(LeafNode *nodes, const WindowQuadList *quads, const WindowPaintData &data);
|
2013-03-17 12:34:26 +00:00
|
|
|
virtual void performPaint(int mask, QRegion region, WindowPaintData data);
|
2012-10-12 09:34:05 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
/**
|
|
|
|
* Whether prepareStates enabled blending and restore states should disable again.
|
|
|
|
**/
|
|
|
|
bool m_blendingEnabled;
|
2012-09-06 10:25:55 +00:00
|
|
|
};
|
|
|
|
|
2013-05-10 10:07:56 +00:00
|
|
|
class OpenGLWindowPixmap : public WindowPixmap
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
explicit OpenGLWindowPixmap(Scene::Window *window, SceneOpenGL *scene);
|
|
|
|
virtual ~OpenGLWindowPixmap();
|
|
|
|
SceneOpenGL::Texture *texture() const;
|
|
|
|
bool bind();
|
2016-09-09 07:41:05 +00:00
|
|
|
bool isValid() const override;
|
2016-03-31 08:22:14 +00:00
|
|
|
protected:
|
|
|
|
WindowPixmap *createChild(const QPointer<KWayland::Server::SubSurfaceInterface> &subSurface) override;
|
2013-05-10 10:07:56 +00:00
|
|
|
private:
|
2016-03-31 08:22:14 +00:00
|
|
|
explicit OpenGLWindowPixmap(const QPointer<KWayland::Server::SubSurfaceInterface> &subSurface, WindowPixmap *parent, SceneOpenGL *scene);
|
2013-05-10 10:07:56 +00:00
|
|
|
QScopedPointer<SceneOpenGL::Texture> m_texture;
|
2016-03-31 08:22:14 +00:00
|
|
|
SceneOpenGL *m_scene;
|
2013-05-10 10:07:56 +00:00
|
|
|
};
|
|
|
|
|
2010-07-18 16:32:37 +00:00
|
|
|
class SceneOpenGL::EffectFrame
|
|
|
|
: public Scene::EffectFrame
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
public:
|
2012-08-26 15:14:23 +00:00
|
|
|
EffectFrame(EffectFrameImpl* frame, SceneOpenGL *scene);
|
2011-01-30 14:34:42 +00:00
|
|
|
virtual ~EffectFrame();
|
|
|
|
|
|
|
|
virtual void free();
|
|
|
|
virtual void freeIconFrame();
|
|
|
|
virtual void freeTextFrame();
|
|
|
|
virtual void freeSelection();
|
|
|
|
|
|
|
|
virtual void render(QRegion region, double opacity, double frameOpacity);
|
|
|
|
|
|
|
|
virtual void crossFadeIcon();
|
|
|
|
virtual void crossFadeText();
|
|
|
|
|
|
|
|
static void cleanup();
|
|
|
|
|
|
|
|
private:
|
|
|
|
void updateTexture();
|
|
|
|
void updateTextTexture();
|
|
|
|
|
2014-11-23 13:33:19 +00:00
|
|
|
GLTexture *m_texture;
|
|
|
|
GLTexture *m_textTexture;
|
|
|
|
GLTexture *m_oldTextTexture;
|
|
|
|
QPixmap *m_textPixmap; // need to keep the pixmap around to workaround some driver problems
|
|
|
|
GLTexture *m_iconTexture;
|
|
|
|
GLTexture *m_oldIconTexture;
|
|
|
|
GLTexture *m_selectionTexture;
|
|
|
|
GLVertexBuffer *m_unstyledVBO;
|
2012-08-26 15:14:23 +00:00
|
|
|
SceneOpenGL *m_scene;
|
2011-01-30 14:34:42 +00:00
|
|
|
|
2012-08-26 15:14:23 +00:00
|
|
|
static GLTexture* m_unstyledTexture;
|
2011-01-30 14:34:42 +00:00
|
|
|
static QPixmap* m_unstyledPixmap; // need to keep the pixmap around to workaround some driver problems
|
|
|
|
static void updateUnstyledTexture(); // Update OpenGL unstyled frame texture
|
|
|
|
};
|
2010-07-18 16:32:37 +00:00
|
|
|
|
2011-03-27 10:33:07 +00:00
|
|
|
/**
|
|
|
|
* @short OpenGL implementation of Shadow.
|
|
|
|
*
|
|
|
|
* This class extends Shadow by the Elements required for OpenGL rendering.
|
|
|
|
* @author Martin Gräßlin <mgraesslin@kde.org>
|
|
|
|
**/
|
|
|
|
class SceneOpenGLShadow
|
|
|
|
: public Shadow
|
|
|
|
{
|
|
|
|
public:
|
2012-12-29 06:34:38 +00:00
|
|
|
explicit SceneOpenGLShadow(Toplevel *toplevel);
|
2011-03-27 10:33:07 +00:00
|
|
|
virtual ~SceneOpenGLShadow();
|
|
|
|
|
2011-06-23 17:06:12 +00:00
|
|
|
GLTexture *shadowTexture() {
|
2014-12-04 09:36:19 +00:00
|
|
|
return m_texture.data();
|
2011-06-23 17:06:12 +00:00
|
|
|
}
|
|
|
|
protected:
|
|
|
|
virtual void buildQuads();
|
|
|
|
virtual bool prepareBackend();
|
2011-03-27 10:33:07 +00:00
|
|
|
private:
|
2014-12-04 09:36:19 +00:00
|
|
|
QSharedPointer<GLTexture> m_texture;
|
2011-03-27 10:33:07 +00:00
|
|
|
};
|
|
|
|
|
2013-03-28 20:52:26 +00:00
|
|
|
/**
|
|
|
|
* @short Profiler to detect whether we have triple buffering
|
|
|
|
* The strategy is to start setBlocksForRetrace(false) but assume blocking and have the system prove that assumption wrong
|
|
|
|
**/
|
2016-04-12 13:03:07 +00:00
|
|
|
class KWIN_EXPORT SwapProfiler
|
2013-03-28 20:52:26 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
SwapProfiler();
|
|
|
|
void init();
|
|
|
|
void begin();
|
|
|
|
/**
|
|
|
|
* @return char being 'd' for double, 't' for triple (or more - but non-blocking) buffering and
|
|
|
|
* 0 (NOT '0') otherwise, so you can act on "if (char result = SwapProfiler::end()) { fooBar(); }
|
|
|
|
**/
|
|
|
|
char end();
|
|
|
|
private:
|
|
|
|
QElapsedTimer m_timer;
|
|
|
|
qint64 m_time;
|
|
|
|
int m_counter;
|
|
|
|
};
|
|
|
|
|
2012-08-26 15:14:23 +00:00
|
|
|
/**
|
|
|
|
* @brief The OpenGLBackend creates and holds the OpenGL context and is responsible for Texture from Pixmap.
|
|
|
|
*
|
|
|
|
* The OpenGLBackend is an abstract base class used by the SceneOpenGL to abstract away the differences
|
|
|
|
* between various OpenGL windowing systems such as GLX and EGL.
|
|
|
|
*
|
|
|
|
* A concrete implementation has to create and release the OpenGL context in a way so that the
|
|
|
|
* SceneOpenGL does not have to care about it.
|
|
|
|
*
|
|
|
|
* In addition a major task for this class is to generate the SceneOpenGL::TexturePrivate which is
|
|
|
|
* able to perform the texture from pixmap operation in the given backend.
|
|
|
|
*
|
|
|
|
* @author Martin Gräßlin <mgraesslin@kde.org>
|
|
|
|
**/
|
2015-05-05 15:58:09 +00:00
|
|
|
class KWIN_EXPORT OpenGLBackend
|
2012-08-26 15:14:23 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
OpenGLBackend();
|
|
|
|
virtual ~OpenGLBackend();
|
2015-11-25 12:09:28 +00:00
|
|
|
|
|
|
|
virtual void init() = 0;
|
2012-08-26 15:14:23 +00:00
|
|
|
/**
|
|
|
|
* @return Time passes since start of rendering current frame.
|
|
|
|
* @see startRenderTimer
|
|
|
|
**/
|
|
|
|
qint64 renderTime() {
|
2013-03-28 20:53:25 +00:00
|
|
|
return m_renderTimer.nsecsElapsed();
|
2012-08-26 15:14:23 +00:00
|
|
|
}
|
|
|
|
virtual void screenGeometryChanged(const QSize &size) = 0;
|
|
|
|
virtual SceneOpenGL::TexturePrivate *createBackendTexture(SceneOpenGL::Texture *texture) = 0;
|
2013-11-21 09:39:29 +00:00
|
|
|
|
2012-08-26 15:14:23 +00:00
|
|
|
/**
|
|
|
|
* @brief Backend specific code to prepare the rendering of a frame including flushing the
|
|
|
|
* previously rendered frame to the screen if the backend works this way.
|
2013-11-21 09:39:29 +00:00
|
|
|
*
|
|
|
|
* @return A region that if not empty will be repainted in addition to the damaged region
|
2012-08-26 15:14:23 +00:00
|
|
|
**/
|
2013-11-21 09:39:29 +00:00
|
|
|
virtual QRegion prepareRenderingFrame() = 0;
|
|
|
|
|
2012-08-26 15:14:23 +00:00
|
|
|
/**
|
|
|
|
* @brief Backend specific code to handle the end of rendering a frame.
|
|
|
|
*
|
2013-11-21 09:39:29 +00:00
|
|
|
* @param renderedRegion The possibly larger region that has been rendered
|
|
|
|
* @param damagedRegion The damaged region that should be posted
|
2012-08-26 15:14:23 +00:00
|
|
|
**/
|
2014-01-07 08:28:59 +00:00
|
|
|
virtual void endRenderingFrame(const QRegion &damage, const QRegion &damagedRegion) = 0;
|
2015-04-23 07:55:49 +00:00
|
|
|
virtual void endRenderingFrameForScreen(int screenId, const QRegion &damage, const QRegion &damagedRegion);
|
Better handling for making the compositing OpenGL context current
With QtQuick2 it's possible that the scene graph rendering context either
lives in an own thread or uses the main GUI thread. In the latter case
it's the same thread as our compositing OpenGL context lives in. This
means our basic assumption that between two rendering passes the context
stays current does not hold.
The code already ensured that before we start a rendering pass the
context is made current, but there are many more possible cases. If we
use OpenGL in areas not triggered by the rendering loop but in response
to other events the context needs to be made current. This includes the
loading and unloading of effects (some effects use OpenGL in the static
effect check, in the ctor and dtor), background loading of texture data,
lazy loading after first usage invoked by shortcut, etc. etc.
To properly handle these cases new methods are added to EffectsHandler
to make the compositing OpenGL context current. These calls delegate down
into the scene. On non-OpenGL scenes they are noop, but on OpenGL they go
into the backend and make the context current. In addition they ensure
that Qt doesn't think that it's QOpenGLContext is current by calling
doneCurrent() on the QOpenGLContext::currentContext(). This unfortunately
causes an additional call to makeCurrent with a null context, but there
is no other way to tell Qt - it doesn't notice when a different context
is made current with low level API calls. In the multi-threaded
architecture this doesn't matter as ::currentContext() returns null.
A short evaluation showed that a transition to QOpenGLContext doesn't
seem feasible. Qt only supports either GLX or EGL while KWin supports
both and when entering the transition phase for Wayland, it would become
extremely tricky if our native platform is X11, but we want a Wayland
EGL context. A future solution might be to have a "KWin-QPA plugin" which
uses either xcb or Wayland and hides everything from Qt.
The API documentation is extended to describe when the effects-framework
ensures that an OpenGL context is current. The effects are changed to
make the context current in cases where it's not guaranteed. This has
been done by looking for creation or deletion of GLTextures and Shaders.
If there are other OpenGL usages outside the rendering loop, ctor/dtor
this needs to be changed, too.
2013-11-22 14:05:36 +00:00
|
|
|
virtual bool makeCurrent() = 0;
|
|
|
|
virtual void doneCurrent() = 0;
|
2013-06-19 10:26:34 +00:00
|
|
|
virtual bool usesOverlayWindow() const = 0;
|
2015-04-17 13:48:55 +00:00
|
|
|
/**
|
|
|
|
* Whether the rendering needs to be split per screen.
|
|
|
|
* Default implementation returns @c false.
|
|
|
|
**/
|
|
|
|
virtual bool perScreenRendering() const;
|
2015-04-23 07:55:49 +00:00
|
|
|
virtual QRegion prepareRenderingForScreen(int screenId);
|
2012-08-26 15:14:23 +00:00
|
|
|
/**
|
|
|
|
* @brief Compositor is going into idle mode, flushes any pending paints.
|
|
|
|
**/
|
|
|
|
void idle();
|
2013-11-21 09:39:29 +00:00
|
|
|
|
2012-08-26 15:14:23 +00:00
|
|
|
/**
|
|
|
|
* @return bool Whether the scene needs to flush a frame.
|
|
|
|
**/
|
|
|
|
bool hasPendingFlush() const {
|
|
|
|
return !m_lastDamage.isEmpty();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Returns the OverlayWindow used by the backend.
|
|
|
|
*
|
|
|
|
* A backend does not have to use an OverlayWindow, this is mostly for the X world.
|
|
|
|
* In case the backend does not use an OverlayWindow it is allowed to return @c null.
|
|
|
|
* It's the task of the caller to check whether it is @c null.
|
|
|
|
*
|
|
|
|
* @return :OverlayWindow*
|
|
|
|
**/
|
2013-06-19 10:26:34 +00:00
|
|
|
virtual OverlayWindow *overlayWindow();
|
2012-08-26 15:14:23 +00:00
|
|
|
/**
|
|
|
|
* @brief Whether the creation of the Backend failed.
|
|
|
|
*
|
|
|
|
* The SceneOpenGL should test whether the Backend got constructed correctly. If this method
|
|
|
|
* returns @c true, the SceneOpenGL should not try to start the rendering.
|
|
|
|
*
|
|
|
|
* @return bool @c true if the creation of the Backend failed, @c false otherwise.
|
|
|
|
**/
|
|
|
|
bool isFailed() const {
|
|
|
|
return m_failed;
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* @brief Whether the Backend provides VSync.
|
|
|
|
*
|
|
|
|
* Currently only the GLX backend can provide VSync.
|
|
|
|
*
|
|
|
|
* @return bool @c true if VSync support is available, @c false otherwise
|
|
|
|
**/
|
2013-03-28 20:52:26 +00:00
|
|
|
bool syncsToVBlank() const {
|
|
|
|
return m_syncsToVBlank;
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* @brief Whether VSync blocks execution until the screen is in the retrace
|
|
|
|
*
|
|
|
|
* Case for waitVideoSync and non triple buffering buffer swaps
|
|
|
|
*
|
|
|
|
**/
|
|
|
|
bool blocksForRetrace() const {
|
|
|
|
return m_blocksForRetrace;
|
2012-08-26 15:14:23 +00:00
|
|
|
}
|
|
|
|
/**
|
|
|
|
* @brief Whether the backend uses direct rendering.
|
|
|
|
*
|
|
|
|
* Some OpenGLScene modes require direct rendering. E.g. the OpenGL 2 should not be used
|
|
|
|
* if direct rendering is not supported by the Scene.
|
|
|
|
*
|
|
|
|
* @return bool @c true if the GL context is direct, @c false if indirect
|
|
|
|
**/
|
|
|
|
bool isDirectRendering() const {
|
|
|
|
return m_directRendering;
|
|
|
|
}
|
2013-11-21 09:44:06 +00:00
|
|
|
|
|
|
|
bool supportsBufferAge() const {
|
|
|
|
return m_haveBufferAge;
|
|
|
|
}
|
|
|
|
|
2015-10-08 13:54:24 +00:00
|
|
|
/**
|
|
|
|
* @returns whether the context is surfaceless
|
|
|
|
**/
|
|
|
|
bool isSurfaceLessContext() const {
|
|
|
|
return m_surfaceLessContext;
|
|
|
|
}
|
|
|
|
|
2013-11-21 09:44:06 +00:00
|
|
|
/**
|
|
|
|
* Returns the damage that has accumulated since a buffer of the given age was presented.
|
|
|
|
*/
|
|
|
|
QRegion accumulatedDamageHistory(int bufferAge) const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Saves the given region to damage history.
|
|
|
|
*/
|
|
|
|
void addToDamageHistory(const QRegion ®ion);
|
|
|
|
|
2012-08-26 15:14:23 +00:00
|
|
|
protected:
|
|
|
|
/**
|
|
|
|
* @brief Backend specific flushing of frame to screen.
|
|
|
|
**/
|
2012-10-07 11:43:31 +00:00
|
|
|
virtual void present() = 0;
|
2012-08-26 15:14:23 +00:00
|
|
|
/**
|
|
|
|
* @brief Sets the backend initialization to failed.
|
|
|
|
*
|
|
|
|
* This method should be called by the concrete subclass in case the initialization failed.
|
|
|
|
* The given @p reason is logged as a warning.
|
|
|
|
*
|
|
|
|
* @param reason The reason why the initialization failed.
|
|
|
|
**/
|
|
|
|
void setFailed(const QString &reason);
|
|
|
|
/**
|
|
|
|
* @brief Sets whether the backend provides VSync.
|
|
|
|
*
|
|
|
|
* Should be called by the concrete subclass once it is determined whether VSync is supported.
|
|
|
|
* If the subclass does not call this method, the backend defaults to @c false.
|
|
|
|
* @param enabled @c true if VSync support available, @c false otherwise.
|
|
|
|
**/
|
2013-03-28 20:52:26 +00:00
|
|
|
void setSyncsToVBlank(bool enabled) {
|
|
|
|
m_syncsToVBlank = enabled;
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* @brief Sets whether the VSync iplementation blocks
|
|
|
|
*
|
|
|
|
* Should be called by the concrete subclass once it is determined how VSync works.
|
|
|
|
* If the subclass does not call this method, the backend defaults to @c false.
|
|
|
|
* @param enabled @c true if VSync blocks, @c false otherwise.
|
|
|
|
**/
|
|
|
|
void setBlocksForRetrace(bool enabled) {
|
|
|
|
m_blocksForRetrace = enabled;
|
2012-08-26 15:14:23 +00:00
|
|
|
}
|
|
|
|
/**
|
|
|
|
* @brief Sets whether the OpenGL context is direct.
|
|
|
|
*
|
|
|
|
* Should be called by the concrete subclass once it is determined whether the OpenGL context is
|
|
|
|
* direct or indirect.
|
|
|
|
* If the subclass does not call this method, the backend defaults to @c false.
|
|
|
|
*
|
|
|
|
* @param direct @c true if the OpenGL context is direct, @c false if indirect
|
|
|
|
**/
|
|
|
|
void setIsDirectRendering(bool direct) {
|
|
|
|
m_directRendering = direct;
|
|
|
|
}
|
2013-11-21 09:44:06 +00:00
|
|
|
|
|
|
|
void setSupportsBufferAge(bool value) {
|
|
|
|
m_haveBufferAge = value;
|
|
|
|
}
|
|
|
|
|
2012-08-26 15:14:23 +00:00
|
|
|
/**
|
|
|
|
* @return const QRegion& Damage of previously rendered frame
|
|
|
|
**/
|
|
|
|
const QRegion &lastDamage() const {
|
|
|
|
return m_lastDamage;
|
|
|
|
}
|
|
|
|
void setLastDamage(const QRegion &damage) {
|
|
|
|
m_lastDamage = damage;
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* @brief Starts the timer for how long it takes to render the frame.
|
|
|
|
*
|
|
|
|
* @see renderTime
|
|
|
|
**/
|
|
|
|
void startRenderTimer() {
|
|
|
|
m_renderTimer.start();
|
|
|
|
}
|
|
|
|
|
2015-10-08 13:54:24 +00:00
|
|
|
/**
|
|
|
|
* @param set whether the context is surface less
|
|
|
|
**/
|
|
|
|
void setSurfaceLessContext(bool set) {
|
|
|
|
m_surfaceLessContext = set;
|
|
|
|
}
|
|
|
|
|
2013-03-28 20:52:26 +00:00
|
|
|
SwapProfiler m_swapProfiler;
|
|
|
|
|
2012-08-26 15:14:23 +00:00
|
|
|
private:
|
|
|
|
/**
|
2013-03-28 20:52:26 +00:00
|
|
|
* @brief Whether VSync is available and used, defaults to @c false.
|
|
|
|
**/
|
|
|
|
bool m_syncsToVBlank;
|
|
|
|
/**
|
|
|
|
* @brief Whether present() will block execution until the next vertical retrace @c false.
|
2012-08-26 15:14:23 +00:00
|
|
|
**/
|
2013-03-28 20:52:26 +00:00
|
|
|
bool m_blocksForRetrace;
|
2012-08-26 15:14:23 +00:00
|
|
|
/**
|
|
|
|
* @brief Whether direct rendering is used, defaults to @c false.
|
|
|
|
**/
|
|
|
|
bool m_directRendering;
|
2013-11-21 09:44:06 +00:00
|
|
|
/**
|
|
|
|
* @brief Whether the backend supports GLX_EXT_buffer_age / EGL_EXT_buffer_age.
|
|
|
|
*/
|
|
|
|
bool m_haveBufferAge;
|
2012-08-26 15:14:23 +00:00
|
|
|
/**
|
|
|
|
* @brief Whether the initialization failed, of course default to @c false.
|
|
|
|
**/
|
|
|
|
bool m_failed;
|
|
|
|
/**
|
|
|
|
* @brief Damaged region of previously rendered frame.
|
|
|
|
**/
|
|
|
|
QRegion m_lastDamage;
|
2013-11-21 09:44:06 +00:00
|
|
|
/**
|
|
|
|
* @brief The damage history for the past 10 frames.
|
|
|
|
*/
|
|
|
|
QList<QRegion> m_damageHistory;
|
2012-08-26 15:14:23 +00:00
|
|
|
/**
|
|
|
|
* @brief Timer to measure how long a frame renders.
|
|
|
|
**/
|
|
|
|
QElapsedTimer m_renderTimer;
|
2015-10-08 13:54:24 +00:00
|
|
|
bool m_surfaceLessContext = false;
|
2012-08-26 15:14:23 +00:00
|
|
|
};
|
|
|
|
|
2014-07-22 11:11:19 +00:00
|
|
|
class SceneOpenGLDecorationRenderer : public Decoration::Renderer
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
enum class DecorationPart : int {
|
|
|
|
Left,
|
|
|
|
Top,
|
|
|
|
Right,
|
|
|
|
Bottom,
|
|
|
|
Count
|
|
|
|
};
|
|
|
|
explicit SceneOpenGLDecorationRenderer(Decoration::DecoratedClientImpl *client);
|
|
|
|
virtual ~SceneOpenGLDecorationRenderer();
|
|
|
|
|
|
|
|
void render() override;
|
2014-07-23 07:20:28 +00:00
|
|
|
void reparent(Deleted *deleted) override;
|
2014-07-22 11:11:19 +00:00
|
|
|
|
|
|
|
GLTexture *texture() {
|
|
|
|
return m_texture.data();
|
|
|
|
}
|
2014-07-23 07:20:28 +00:00
|
|
|
GLTexture *texture() const {
|
|
|
|
return m_texture.data();
|
|
|
|
}
|
2014-07-22 11:11:19 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
void resizeTexture();
|
|
|
|
QScopedPointer<GLTexture> m_texture;
|
|
|
|
};
|
|
|
|
|
2012-08-26 15:14:23 +00:00
|
|
|
inline bool SceneOpenGL::hasPendingFlush() const
|
|
|
|
{
|
|
|
|
return m_backend->hasPendingFlush();
|
|
|
|
}
|
|
|
|
|
2013-06-19 10:26:34 +00:00
|
|
|
inline bool SceneOpenGL::usesOverlayWindow() const
|
|
|
|
{
|
|
|
|
return m_backend->usesOverlayWindow();
|
|
|
|
}
|
|
|
|
|
2013-05-10 10:07:56 +00:00
|
|
|
inline SceneOpenGL::Texture* OpenGLWindowPixmap::texture() const
|
|
|
|
{
|
|
|
|
return m_texture.data();
|
|
|
|
}
|
|
|
|
|
2007-04-29 17:35:43 +00:00
|
|
|
} // namespace
|
|
|
|
|
|
|
|
#endif
|