File indexing completed on 2024-05-19 05:32:22

0001 /*
0002     KWin - the KDE window manager
0003     This file is part of the KDE project.
0004 
0005     SPDX-FileCopyrightText: 2006 Lubos Lunak <l.lunak@kde.org>
0006     SPDX-FileCopyrightText: 2009, 2010, 2011 Martin Gräßlin <mgraesslin@kde.org>
0007 
0008     SPDX-License-Identifier: GPL-2.0-or-later
0009 */
0010 
0011 #pragma once
0012 
0013 #include "platformsupport/scenes/opengl/openglbackend.h"
0014 
0015 #include "scene/decorationitem.h"
0016 #include "scene/shadowitem.h"
0017 #include "scene/workspacescene.h"
0018 
0019 #include "opengl/glutils.h"
0020 
0021 namespace KWin
0022 {
0023 class OpenGLBackend;
0024 
0025 class KWIN_EXPORT WorkspaceSceneOpenGL : public WorkspaceScene
0026 {
0027     Q_OBJECT
0028 
0029 public:
0030     explicit WorkspaceSceneOpenGL(OpenGLBackend *backend);
0031     ~WorkspaceSceneOpenGL() override;
0032 
0033     bool makeOpenGLContextCurrent() override;
0034     void doneOpenGLContextCurrent() override;
0035     bool supportsNativeFence() const override;
0036     std::unique_ptr<DecorationRenderer> createDecorationRenderer(Decoration::DecoratedClientImpl *impl) override;
0037     std::unique_ptr<ShadowTextureProvider> createShadowTextureProvider(Shadow *shadow) override;
0038     bool animationsSupported() const override;
0039 
0040     OpenGLBackend *backend() const
0041     {
0042         return m_backend;
0043     }
0044 
0045     std::pair<std::shared_ptr<GLTexture>, ColorDescription> textureForOutput(Output *output) const override;
0046 
0047 private:
0048     OpenGLBackend *m_backend;
0049     GLuint vao = 0;
0050 };
0051 
0052 /**
0053  * @short OpenGL implementation of Shadow.
0054  *
0055  * This class extends Shadow by the Elements required for OpenGL rendering.
0056  * @author Martin Gräßlin <mgraesslin@kde.org>
0057  */
0058 class OpenGLShadowTextureProvider : public ShadowTextureProvider
0059 {
0060 public:
0061     explicit OpenGLShadowTextureProvider(Shadow *shadow);
0062     ~OpenGLShadowTextureProvider() override;
0063 
0064     GLTexture *shadowTexture()
0065     {
0066         return m_texture.get();
0067     }
0068 
0069     void update() override;
0070 
0071 private:
0072     std::shared_ptr<GLTexture> m_texture;
0073 };
0074 
0075 class SceneOpenGLDecorationRenderer : public DecorationRenderer
0076 {
0077     Q_OBJECT
0078 public:
0079     enum class DecorationPart : int {
0080         Left,
0081         Top,
0082         Right,
0083         Bottom,
0084         Count
0085     };
0086     explicit SceneOpenGLDecorationRenderer(Decoration::DecoratedClientImpl *client);
0087     ~SceneOpenGLDecorationRenderer() override;
0088 
0089     void render(const QRegion &region) override;
0090 
0091     GLTexture *texture()
0092     {
0093         return m_texture.get();
0094     }
0095     GLTexture *texture() const
0096     {
0097         return m_texture.get();
0098     }
0099 
0100 private:
0101     void renderPart(const QRect &rect, const QRect &partRect, const QPoint &textureOffset, qreal devicePixelRatio, bool rotated = false);
0102     static const QMargins texturePadForPart(const QRect &rect, const QRect &partRect);
0103     void resizeTexture();
0104     int toNativeSize(int size) const;
0105     std::unique_ptr<GLTexture> m_texture;
0106 };
0107 
0108 } // namespace