File indexing completed on 2024-05-19 16:34:48
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 "openglbackend.h" 0014 0015 #include "scene/decorationitem.h" 0016 #include "scene/workspacescene.h" 0017 #include "shadow.h" 0018 0019 #include "kwinglutils.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 std::unique_ptr<Shadow> createShadow(Window *window) override; 0034 bool makeOpenGLContextCurrent() override; 0035 void doneOpenGLContextCurrent() override; 0036 bool supportsNativeFence() const override; 0037 DecorationRenderer *createDecorationRenderer(Decoration::DecoratedClientImpl *impl) override; 0038 bool animationsSupported() const override; 0039 0040 OpenGLBackend *backend() const 0041 { 0042 return m_backend; 0043 } 0044 0045 std::shared_ptr<GLTexture> 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 SceneOpenGLShadow 0059 : public Shadow 0060 { 0061 public: 0062 explicit SceneOpenGLShadow(Window *window); 0063 ~SceneOpenGLShadow() override; 0064 0065 GLTexture *shadowTexture() 0066 { 0067 return m_texture.get(); 0068 } 0069 0070 protected: 0071 bool prepareBackend() override; 0072 0073 private: 0074 std::shared_ptr<GLTexture> m_texture; 0075 }; 0076 0077 class SceneOpenGLDecorationRenderer : public DecorationRenderer 0078 { 0079 Q_OBJECT 0080 public: 0081 enum class DecorationPart : int { 0082 Left, 0083 Top, 0084 Right, 0085 Bottom, 0086 Count 0087 }; 0088 explicit SceneOpenGLDecorationRenderer(Decoration::DecoratedClientImpl *client); 0089 ~SceneOpenGLDecorationRenderer() override; 0090 0091 void render(const QRegion ®ion) override; 0092 0093 GLTexture *texture() 0094 { 0095 return m_texture.get(); 0096 } 0097 GLTexture *texture() const 0098 { 0099 return m_texture.get(); 0100 } 0101 0102 private: 0103 void renderPart(const QRect &rect, const QRect &partRect, const QPoint &textureOffset, qreal devicePixelRatio, bool rotated = false); 0104 static const QMargins texturePadForPart(const QRect &rect, const QRect &partRect); 0105 void resizeTexture(); 0106 int toNativeSize(int size) const; 0107 std::unique_ptr<GLTexture> m_texture; 0108 }; 0109 0110 } // namespace