File indexing completed on 2024-05-19 05:31:57
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 #pragma once 0011 0012 #include "core/renderbackend.h" 0013 0014 #include <QRegion> 0015 #include <memory> 0016 0017 namespace KWin 0018 { 0019 class Output; 0020 class OpenGLBackend; 0021 class GLTexture; 0022 0023 /** 0024 * @brief The OpenGLBackend creates and holds the OpenGL context and is responsible for Texture from Pixmap. 0025 * 0026 * The OpenGLBackend is an abstract base class used by the SceneOpenGL to abstract away the differences 0027 * between various OpenGL windowing systems such as GLX and EGL. 0028 * 0029 * A concrete implementation has to create and release the OpenGL context in a way so that the 0030 * SceneOpenGL does not have to care about it. 0031 * 0032 * In addition a major task for this class is to generate the SceneOpenGLTexturePrivate which is 0033 * able to perform the texture from pixmap operation in the given backend. 0034 * 0035 * @author Martin Gräßlin <mgraesslin@kde.org> 0036 */ 0037 class KWIN_EXPORT OpenGLBackend : public RenderBackend 0038 { 0039 Q_OBJECT 0040 0041 public: 0042 OpenGLBackend(); 0043 virtual ~OpenGLBackend(); 0044 0045 virtual void init() = 0; 0046 CompositingType compositingType() const override final; 0047 bool checkGraphicsReset() override final; 0048 0049 virtual bool makeCurrent() = 0; 0050 virtual void doneCurrent() = 0; 0051 0052 /** 0053 * @brief Whether the creation of the Backend failed. 0054 * 0055 * The SceneOpenGL should test whether the Backend got constructed correctly. If this method 0056 * returns @c true, the SceneOpenGL should not try to start the rendering. 0057 * 0058 * @return bool @c true if the creation of the Backend failed, @c false otherwise. 0059 */ 0060 bool isFailed() const 0061 { 0062 return m_failed; 0063 } 0064 0065 bool supportsBufferAge() const 0066 { 0067 return m_haveBufferAge; 0068 } 0069 0070 bool supportsNativeFence() const 0071 { 0072 return m_haveNativeFence; 0073 } 0074 0075 /** 0076 * The backend specific extensions (e.g. EGL/GLX extensions). 0077 * 0078 * Not the OpenGL (ES) extension! 0079 */ 0080 QList<QByteArray> extensions() const 0081 { 0082 return m_extensions; 0083 } 0084 0085 /** 0086 * @returns whether the backend specific extensions contains @p extension. 0087 */ 0088 bool hasExtension(const QByteArray &extension) const 0089 { 0090 return m_extensions.contains(extension); 0091 } 0092 0093 /** 0094 * Copy a region of pixels from the current read to the current draw buffer 0095 */ 0096 void copyPixels(const QRegion ®ion, const QSize &screenSize); 0097 0098 virtual std::pair<std::shared_ptr<GLTexture>, ColorDescription> textureForOutput(Output *output) const; 0099 0100 protected: 0101 /** 0102 * @brief Sets the backend initialization to failed. 0103 * 0104 * This method should be called by the concrete subclass in case the initialization failed. 0105 * The given @p reason is logged as a warning. 0106 * 0107 * @param reason The reason why the initialization failed. 0108 */ 0109 void setFailed(const QString &reason); 0110 0111 void setSupportsBufferAge(bool value) 0112 { 0113 m_haveBufferAge = value; 0114 } 0115 0116 void setSupportsNativeFence(bool value) 0117 { 0118 m_haveNativeFence = value; 0119 } 0120 0121 /** 0122 * Sets the platform-specific @p extensions. 0123 * 0124 * These are the EGL/GLX extensions, not the OpenGL extensions 0125 */ 0126 void setExtensions(const QList<QByteArray> &extensions) 0127 { 0128 m_extensions = extensions; 0129 } 0130 0131 private: 0132 /** 0133 * @brief Whether the backend supports GLX_EXT_buffer_age / EGL_EXT_buffer_age. 0134 */ 0135 bool m_haveBufferAge; 0136 /** 0137 * @brief Whether the backend supports EGL_ANDROID_native_fence_sync. 0138 */ 0139 bool m_haveNativeFence = false; 0140 /** 0141 * @brief Whether the initialization failed, of course default to @c false. 0142 */ 0143 bool m_failed; 0144 QList<QByteArray> m_extensions; 0145 }; 0146 0147 }