2020-08-02 22:22:19 +00:00
|
|
|
/*
|
|
|
|
KWin - the KDE window manager
|
|
|
|
This file is part of the KDE project.
|
2017-09-08 20:30:18 +00:00
|
|
|
|
2020-08-02 22:22:19 +00:00
|
|
|
SPDX-FileCopyrightText: 2006 Lubos Lunak <l.lunak@kde.org>
|
|
|
|
SPDX-FileCopyrightText: 2009, 2010, 2011 Martin Gräßlin <mgraesslin@kde.org>
|
2017-09-08 20:30:18 +00:00
|
|
|
|
2020-08-02 22:22:19 +00:00
|
|
|
SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
*/
|
2017-09-08 20:30:18 +00:00
|
|
|
#ifndef KWIN_SCENE_OPENGL_BACKEND_H
|
|
|
|
#define KWIN_SCENE_OPENGL_BACKEND_H
|
|
|
|
|
|
|
|
#include <QRegion>
|
|
|
|
|
|
|
|
#include <kwin_export.h>
|
|
|
|
|
|
|
|
namespace KWin
|
|
|
|
{
|
2020-07-22 17:22:36 +00:00
|
|
|
class AbstractOutput;
|
2017-09-08 20:30:18 +00:00
|
|
|
class OpenGLBackend;
|
|
|
|
class OverlayWindow;
|
|
|
|
class SceneOpenGL;
|
|
|
|
class SceneOpenGLTexture;
|
|
|
|
class SceneOpenGLTexturePrivate;
|
|
|
|
class WindowPixmap;
|
2020-07-22 17:22:36 +00:00
|
|
|
class GLTexture;
|
2017-09-08 20:30:18 +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 SceneOpenGLTexturePrivate which is
|
|
|
|
* able to perform the texture from pixmap operation in the given backend.
|
|
|
|
*
|
|
|
|
* @author Martin Gräßlin <mgraesslin@kde.org>
|
2019-07-29 18:58:33 +00:00
|
|
|
*/
|
2017-09-08 20:30:18 +00:00
|
|
|
class KWIN_EXPORT OpenGLBackend
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
OpenGLBackend();
|
|
|
|
virtual ~OpenGLBackend();
|
|
|
|
|
|
|
|
virtual void init() = 0;
|
2020-11-09 14:10:03 +00:00
|
|
|
|
2017-09-08 20:30:18 +00:00
|
|
|
virtual void screenGeometryChanged(const QSize &size) = 0;
|
|
|
|
virtual SceneOpenGLTexturePrivate *createBackendTexture(SceneOpenGLTexture *texture) = 0;
|
|
|
|
|
2020-04-24 17:11:41 +00:00
|
|
|
/**
|
|
|
|
* Notifies about starting to paint.
|
|
|
|
*
|
|
|
|
* @p damage contains the reported damage as suggested by windows and effects on prepaint calls.
|
|
|
|
*/
|
2020-10-30 07:39:17 +00:00
|
|
|
virtual void aboutToStartPainting(int screenId, const QRegion &damage);
|
2017-09-08 20:30:18 +00:00
|
|
|
virtual void endRenderingFrameForScreen(int screenId, const QRegion &damage, const QRegion &damagedRegion);
|
|
|
|
virtual bool makeCurrent() = 0;
|
|
|
|
virtual void doneCurrent() = 0;
|
|
|
|
virtual bool usesOverlayWindow() const = 0;
|
|
|
|
/**
|
|
|
|
* Whether the rendering needs to be split per screen.
|
|
|
|
* Default implementation returns @c false.
|
2019-07-29 18:58:33 +00:00
|
|
|
*/
|
2017-09-08 20:30:18 +00:00
|
|
|
virtual bool perScreenRendering() const;
|
|
|
|
virtual QRegion prepareRenderingForScreen(int screenId);
|
|
|
|
/**
|
|
|
|
* @brief Compositor is going into idle mode, flushes any pending paints.
|
2019-07-29 18:58:33 +00:00
|
|
|
*/
|
2017-09-08 20:30:18 +00:00
|
|
|
void idle();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return bool Whether the scene needs to flush a frame.
|
2019-07-29 18:58:33 +00:00
|
|
|
*/
|
2017-09-08 20:30:18 +00:00
|
|
|
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*
|
2019-07-29 18:58:33 +00:00
|
|
|
*/
|
2019-08-07 17:33:20 +00:00
|
|
|
virtual OverlayWindow *overlayWindow() const;
|
2017-09-08 20:30:18 +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.
|
2019-07-29 18:58:33 +00:00
|
|
|
*/
|
2017-09-08 20:30:18 +00:00
|
|
|
bool isFailed() const {
|
|
|
|
return m_failed;
|
|
|
|
}
|
2020-01-09 17:18:22 +00:00
|
|
|
/**
|
|
|
|
* @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
|
|
|
|
*/
|
|
|
|
bool syncsToVBlank() const {
|
|
|
|
return m_syncsToVBlank;
|
|
|
|
}
|
2020-01-09 17:06:14 +00:00
|
|
|
/**
|
|
|
|
* @brief Whether VSync blocks execution until the screen is in the retrace
|
|
|
|
*
|
2020-01-09 17:18:27 +00:00
|
|
|
* Case for waitVideoSync and non triple buffering buffer swaps
|
2020-01-09 17:06:14 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
bool blocksForRetrace() const {
|
|
|
|
return m_blocksForRetrace;
|
|
|
|
}
|
2017-09-08 20:30:18 +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
|
2019-07-29 18:58:33 +00:00
|
|
|
*/
|
2017-09-08 20:30:18 +00:00
|
|
|
bool isDirectRendering() const {
|
|
|
|
return m_directRendering;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool supportsBufferAge() const {
|
|
|
|
return m_haveBufferAge;
|
|
|
|
}
|
|
|
|
|
2020-04-24 17:11:41 +00:00
|
|
|
bool supportsPartialUpdate() const
|
|
|
|
{
|
|
|
|
return m_havePartialUpdate;
|
|
|
|
}
|
|
|
|
bool supportsSwapBuffersWithDamage() const
|
|
|
|
{
|
|
|
|
return m_haveSwapBuffersWithDamage;
|
|
|
|
}
|
|
|
|
|
2020-10-12 06:45:05 +00:00
|
|
|
bool supportsSurfacelessContext() const
|
|
|
|
{
|
|
|
|
return m_haveSurfacelessContext;
|
2017-09-08 20:30:18 +00:00
|
|
|
}
|
2020-10-15 09:27:00 +00:00
|
|
|
bool supportsNativeFence() const
|
|
|
|
{
|
|
|
|
return m_haveNativeFence;
|
|
|
|
}
|
2017-09-08 20:30:18 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the damage that has accumulated since a buffer of the given age was presented.
|
2019-07-29 18:58:33 +00:00
|
|
|
*/
|
2017-09-08 20:30:18 +00:00
|
|
|
QRegion accumulatedDamageHistory(int bufferAge) const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Saves the given region to damage history.
|
2019-07-29 18:58:33 +00:00
|
|
|
*/
|
2017-09-08 20:30:18 +00:00
|
|
|
void addToDamageHistory(const QRegion ®ion);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The backend specific extensions (e.g. EGL/GLX extensions).
|
|
|
|
*
|
|
|
|
* Not the OpenGL (ES) extension!
|
2019-07-29 18:58:33 +00:00
|
|
|
*/
|
2017-09-08 20:30:18 +00:00
|
|
|
QList<QByteArray> extensions() const {
|
|
|
|
return m_extensions;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @returns whether the backend specific extensions contains @p extension.
|
2019-07-29 18:58:33 +00:00
|
|
|
*/
|
2017-09-08 20:30:18 +00:00
|
|
|
bool hasExtension(const QByteArray &extension) const {
|
|
|
|
return m_extensions.contains(extension);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Copy a region of pixels from the current read to the current draw buffer
|
2019-07-29 18:58:33 +00:00
|
|
|
*/
|
2017-09-08 20:30:18 +00:00
|
|
|
void copyPixels(const QRegion ®ion);
|
|
|
|
|
2020-07-22 17:22:36 +00:00
|
|
|
virtual QSharedPointer<GLTexture> textureForOutput(AbstractOutput *output) const;
|
|
|
|
|
2017-09-08 20:30:18 +00:00
|
|
|
protected:
|
|
|
|
/**
|
|
|
|
* @brief Backend specific flushing of frame to screen.
|
2019-07-29 18:58:33 +00:00
|
|
|
*/
|
2017-09-08 20:30:18 +00:00
|
|
|
virtual void present() = 0;
|
|
|
|
/**
|
|
|
|
* @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.
|
2019-07-29 18:58:33 +00:00
|
|
|
*/
|
2017-09-08 20:30:18 +00:00
|
|
|
void setFailed(const QString &reason);
|
2020-01-09 17:18:22 +00:00
|
|
|
/**
|
|
|
|
* @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.
|
|
|
|
*/
|
|
|
|
void setSyncsToVBlank(bool enabled) {
|
|
|
|
m_syncsToVBlank = enabled;
|
|
|
|
}
|
2020-01-09 17:06:14 +00:00
|
|
|
/**
|
|
|
|
* @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;
|
|
|
|
}
|
2017-09-08 20:30:18 +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
|
2019-07-29 18:58:33 +00:00
|
|
|
*/
|
2017-09-08 20:30:18 +00:00
|
|
|
void setIsDirectRendering(bool direct) {
|
|
|
|
m_directRendering = direct;
|
|
|
|
}
|
|
|
|
|
|
|
|
void setSupportsBufferAge(bool value) {
|
|
|
|
m_haveBufferAge = value;
|
|
|
|
}
|
|
|
|
|
2020-04-24 17:11:41 +00:00
|
|
|
void setSupportsPartialUpdate(bool value)
|
|
|
|
{
|
|
|
|
m_havePartialUpdate = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
void setSupportsSwapBuffersWithDamage(bool value)
|
|
|
|
{
|
|
|
|
m_haveSwapBuffersWithDamage = value;
|
|
|
|
}
|
|
|
|
|
2020-10-12 06:45:05 +00:00
|
|
|
void setSupportsSurfacelessContext(bool value)
|
|
|
|
{
|
|
|
|
m_haveSurfacelessContext = value;
|
|
|
|
}
|
|
|
|
|
2020-10-15 09:27:00 +00:00
|
|
|
void setSupportsNativeFence(bool value)
|
|
|
|
{
|
|
|
|
m_haveNativeFence = value;
|
|
|
|
}
|
|
|
|
|
2017-09-08 20:30:18 +00:00
|
|
|
/**
|
|
|
|
* @return const QRegion& Damage of previously rendered frame
|
2019-07-29 18:58:33 +00:00
|
|
|
*/
|
2017-09-08 20:30:18 +00:00
|
|
|
const QRegion &lastDamage() const {
|
|
|
|
return m_lastDamage;
|
|
|
|
}
|
|
|
|
void setLastDamage(const QRegion &damage) {
|
|
|
|
m_lastDamage = damage;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the platform-specific @p extensions.
|
|
|
|
*
|
|
|
|
* These are the EGL/GLX extensions, not the OpenGL extensions
|
2019-07-29 18:58:33 +00:00
|
|
|
*/
|
2017-09-08 20:30:18 +00:00
|
|
|
void setExtensions(const QList<QByteArray> &extensions) {
|
|
|
|
m_extensions = extensions;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2020-01-09 17:18:22 +00:00
|
|
|
/**
|
|
|
|
* @brief Whether VSync is available and used, defaults to @c false.
|
|
|
|
*/
|
|
|
|
bool m_syncsToVBlank;
|
2020-01-09 17:06:14 +00:00
|
|
|
/**
|
|
|
|
* @brief Whether present() will block execution until the next vertical retrace @c false.
|
|
|
|
*/
|
|
|
|
bool m_blocksForRetrace;
|
2017-09-08 20:30:18 +00:00
|
|
|
/**
|
|
|
|
* @brief Whether direct rendering is used, defaults to @c false.
|
2019-07-29 18:58:33 +00:00
|
|
|
*/
|
2017-09-08 20:30:18 +00:00
|
|
|
bool m_directRendering;
|
|
|
|
/**
|
|
|
|
* @brief Whether the backend supports GLX_EXT_buffer_age / EGL_EXT_buffer_age.
|
2019-07-29 18:58:33 +00:00
|
|
|
*/
|
2017-09-08 20:30:18 +00:00
|
|
|
bool m_haveBufferAge;
|
2020-04-24 17:11:41 +00:00
|
|
|
/**
|
|
|
|
* @brief Whether the backend supports EGL_KHR_partial_update
|
|
|
|
*/
|
|
|
|
bool m_havePartialUpdate;
|
|
|
|
bool m_haveSwapBuffersWithDamage = false;
|
2020-10-12 06:45:05 +00:00
|
|
|
/**
|
|
|
|
* @brief Whether the backend supports EGL_KHR_surfaceless_context.
|
|
|
|
*/
|
|
|
|
bool m_haveSurfacelessContext = false;
|
2020-10-15 09:27:00 +00:00
|
|
|
/**
|
|
|
|
* @brief Whether the backend supports EGL_ANDROID_native_fence_sync.
|
|
|
|
*/
|
|
|
|
bool m_haveNativeFence = false;
|
2017-09-08 20:30:18 +00:00
|
|
|
/**
|
|
|
|
* @brief Whether the initialization failed, of course default to @c false.
|
2019-07-29 18:58:33 +00:00
|
|
|
*/
|
2017-09-08 20:30:18 +00:00
|
|
|
bool m_failed;
|
|
|
|
/**
|
|
|
|
* @brief Damaged region of previously rendered frame.
|
2019-07-29 18:58:33 +00:00
|
|
|
*/
|
2017-09-08 20:30:18 +00:00
|
|
|
QRegion m_lastDamage;
|
|
|
|
/**
|
|
|
|
* @brief The damage history for the past 10 frames.
|
2019-07-29 18:58:33 +00:00
|
|
|
*/
|
2017-09-08 20:30:18 +00:00
|
|
|
QList<QRegion> m_damageHistory;
|
|
|
|
QList<QByteArray> m_extensions;
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|