diff --git a/plugins/scenes/opengl/scene_opengl.h b/plugins/scenes/opengl/scene_opengl.h --- a/plugins/scenes/opengl/scene_opengl.h +++ b/plugins/scenes/opengl/scene_opengl.h @@ -43,7 +43,6 @@ Q_OBJECT public: class EffectFrame; - class Window; ~SceneOpenGL() override; bool initFailed() const override; bool hasPendingFlush() const override; @@ -143,34 +142,9 @@ GLuint vao; }; -class SceneOpenGL::Window - : public Scene::Window -{ -public: - ~Window() override; - bool beginRenderWindow(int mask, const QRegion ®ion, WindowPaintData &data); - void performPaint(int mask, QRegion region, WindowPaintData data) override = 0; - void endRenderWindow(); - bool bindTexture(); - void setScene(SceneOpenGL *scene) { - m_scene = scene; - } - -protected: - WindowPixmap* createWindowPixmap() override; - Window(Toplevel* c); - - QMatrix4x4 transformation(int mask, const WindowPaintData &data) const; - GLTexture *getDecorationTexture() const; - -protected: - SceneOpenGL *m_scene; - bool m_hardwareClipping; -}; - class OpenGLWindowPixmap; -class SceneOpenGL2Window : public SceneOpenGL::Window +class OpenGLWindow final : public Scene::Window { public: enum Leaf { ShadowLeaf = 0, DecorationLeaf, ContentLeaf, PreviousContentLeaf, LeafCount }; @@ -195,22 +169,28 @@ TextureCoordinateType coordinateType; }; - explicit SceneOpenGL2Window(Toplevel *c); - ~SceneOpenGL2Window() override; + OpenGLWindow(Toplevel *toplevel, SceneOpenGL *scene); + ~OpenGLWindow() override; -protected: + WindowPixmap *createWindowPixmap() override; + void performPaint(int mask, QRegion region, WindowPaintData data) override; + +private: + QMatrix4x4 transformation(int mask, const WindowPaintData &data) const; + GLTexture *getDecorationTexture() const; QMatrix4x4 modelViewProjectionMatrix(int mask, const WindowPaintData &data) const; QVector4D modulate(float opacity, float brightness) const; void setBlendEnabled(bool enabled); void setupLeafNodes(LeafNode *nodes, const WindowQuadList *quads, const WindowPaintData &data); - void performPaint(int mask, QRegion region, WindowPaintData data) override; + void renderSubSurface(GLShader *shader, const QMatrix4x4 &mvp, const QMatrix4x4 &windowMatrix, + OpenGLWindowPixmap *pixmap, const QRegion ®ion, bool hardwareClipping); + bool beginRenderWindow(int mask, const QRegion ®ion, WindowPaintData &data); + void endRenderWindow(); + bool bindTexture(); -private: - void renderSubSurface(GLShader *shader, const QMatrix4x4 &mvp, const QMatrix4x4 &windowMatrix, OpenGLWindowPixmap *pixmap, const QRegion ®ion, bool hardwareClipping); - /** - * Whether prepareStates enabled blending and restore states should disable again. - */ - bool m_blendingEnabled; + SceneOpenGL *m_scene; + bool m_hardwareClipping = false; + bool m_blendingEnabled = false; }; class OpenGLWindowPixmap : public WindowPixmap diff --git a/plugins/scenes/opengl/scene_opengl.cpp b/plugins/scenes/opengl/scene_opengl.cpp --- a/plugins/scenes/opengl/scene_opengl.cpp +++ b/plugins/scenes/opengl/scene_opengl.cpp @@ -1026,9 +1026,7 @@ Scene::Window *SceneOpenGL2::createWindow(Toplevel *t) { - SceneOpenGL2Window *w = new SceneOpenGL2Window(t); - w->setScene(this); - return w; + return new OpenGLWindow(t, this); } void SceneOpenGL2::finalDrawWindow(EffectWindowImpl* w, int mask, QRegion region, WindowPaintData& data) @@ -1058,22 +1056,22 @@ } //**************************************** -// SceneOpenGL::Window +// OpenGLWindow //**************************************** -SceneOpenGL::Window::Window(Toplevel* c) - : Scene::Window(c) - , m_scene(nullptr) +OpenGLWindow::OpenGLWindow(Toplevel *toplevel, SceneOpenGL *scene) + : Scene::Window(toplevel) + , m_scene(scene) { } -SceneOpenGL::Window::~Window() +OpenGLWindow::~OpenGLWindow() { } static SceneOpenGLTexture *s_frameTexture = nullptr; // Bind the window pixmap to an OpenGL texture. -bool SceneOpenGL::Window::bindTexture() +bool OpenGLWindow::bindTexture() { s_frameTexture = nullptr; OpenGLWindowPixmap *pixmap = windowPixmap(); @@ -1091,12 +1089,12 @@ return pixmap->bind(); } -QMatrix4x4 SceneOpenGL::Window::transformation(int mask, const WindowPaintData &data) const +QMatrix4x4 OpenGLWindow::transformation(int mask, const WindowPaintData &data) const { QMatrix4x4 matrix; matrix.translate(x(), y()); - if (!(mask & PAINT_WINDOW_TRANSFORMED)) + if (!(mask & Scene::PAINT_WINDOW_TRANSFORMED)) return matrix; matrix.translate(data.translation()); @@ -1115,12 +1113,12 @@ return matrix; } -bool SceneOpenGL::Window::beginRenderWindow(int mask, const QRegion ®ion, WindowPaintData &data) +bool OpenGLWindow::beginRenderWindow(int mask, const QRegion ®ion, WindowPaintData &data) { if (region.isEmpty()) return false; - m_hardwareClipping = region != infiniteRegion() && (mask & PAINT_WINDOW_TRANSFORMED) && !(mask & PAINT_SCREEN_TRANSFORMED); + m_hardwareClipping = region != infiniteRegion() && (mask & Scene::PAINT_WINDOW_TRANSFORMED) && !(mask & Scene::PAINT_SCREEN_TRANSFORMED); if (region != infiniteRegion() && !m_hardwareClipping) { WindowQuadList quads; quads.reserve(data.quads.count()); @@ -1159,16 +1157,16 @@ // Update the texture filter if (waylandServer()) { - filter = ImageFilterGood; + filter = Scene::ImageFilterGood; s_frameTexture->setFilter(GL_LINEAR); } else { if (options->glSmoothScale() != 0 && - (mask & (PAINT_WINDOW_TRANSFORMED | PAINT_SCREEN_TRANSFORMED))) - filter = ImageFilterGood; + (mask & (Scene::PAINT_WINDOW_TRANSFORMED | Scene::PAINT_SCREEN_TRANSFORMED))) + filter = Scene::ImageFilterGood; else - filter = ImageFilterFast; + filter = Scene::ImageFilterFast; - s_frameTexture->setFilter(filter == ImageFilterGood ? GL_LINEAR : GL_NEAREST); + s_frameTexture->setFilter(filter == Scene::ImageFilterGood ? GL_LINEAR : GL_NEAREST); } const GLVertexAttrib attribs[] = { @@ -1183,14 +1181,14 @@ return true; } -void SceneOpenGL::Window::endRenderWindow() +void OpenGLWindow::endRenderWindow() { if (m_hardwareClipping) { glDisable(GL_SCISSOR_TEST); } } -GLTexture *SceneOpenGL::Window::getDecorationTexture() const +GLTexture *OpenGLWindow::getDecorationTexture() const { if (AbstractClient *client = dynamic_cast(toplevel)) { if (client->noBorder()) { @@ -1216,33 +1214,20 @@ return nullptr; } -WindowPixmap* SceneOpenGL::Window::createWindowPixmap() +WindowPixmap *OpenGLWindow::createWindowPixmap() { return new OpenGLWindowPixmap(this, m_scene); } -//*************************************** -// SceneOpenGL2Window -//*************************************** -SceneOpenGL2Window::SceneOpenGL2Window(Toplevel *c) - : SceneOpenGL::Window(c) - , m_blendingEnabled(false) -{ -} - -SceneOpenGL2Window::~SceneOpenGL2Window() -{ -} - -QVector4D SceneOpenGL2Window::modulate(float opacity, float brightness) const +QVector4D OpenGLWindow::modulate(float opacity, float brightness) const { const float a = opacity; const float rgb = opacity * brightness; return QVector4D(rgb, rgb, rgb, a); } -void SceneOpenGL2Window::setBlendEnabled(bool enabled) +void OpenGLWindow::setBlendEnabled(bool enabled) { if (enabled && !m_blendingEnabled) glEnable(GL_BLEND); @@ -1252,7 +1237,7 @@ m_blendingEnabled = enabled; } -void SceneOpenGL2Window::setupLeafNodes(LeafNode *nodes, const WindowQuadList *quads, const WindowPaintData &data) +void OpenGLWindow::setupLeafNodes(LeafNode *nodes, const WindowQuadList *quads, const WindowPaintData &data) { if (!quads[ShadowLeaf].isEmpty()) { nodes[ShadowLeaf].texture = static_cast(m_shadow)->shadowTexture(); @@ -1289,7 +1274,7 @@ } } -QMatrix4x4 SceneOpenGL2Window::modelViewProjectionMatrix(int mask, const WindowPaintData &data) const +QMatrix4x4 OpenGLWindow::modelViewProjectionMatrix(int mask, const WindowPaintData &data) const { SceneOpenGL2 *scene = static_cast(m_scene); @@ -1313,7 +1298,7 @@ return scene->projectionMatrix() * mvMatrix; } -void SceneOpenGL2Window::renderSubSurface(GLShader *shader, const QMatrix4x4 &mvp, const QMatrix4x4 &windowMatrix, OpenGLWindowPixmap *pixmap, const QRegion ®ion, bool hardwareClipping) +void OpenGLWindow::renderSubSurface(GLShader *shader, const QMatrix4x4 &mvp, const QMatrix4x4 &windowMatrix, OpenGLWindowPixmap *pixmap, const QRegion ®ion, bool hardwareClipping) { QMatrix4x4 newWindowMatrix = windowMatrix; newWindowMatrix.translate(pixmap->subSurface()->position().x(), pixmap->subSurface()->position().y()); @@ -1342,7 +1327,7 @@ } } -void SceneOpenGL2Window::performPaint(int mask, QRegion region, WindowPaintData data) +void OpenGLWindow::performPaint(int mask, QRegion region, WindowPaintData data) { if (!beginRenderWindow(mask, region, data)) return;