File indexing completed on 2025-03-16 11:20:43
0001 /* 0002 KWin - the KDE window manager 0003 This file is part of the KDE project. 0004 0005 SPDX-FileCopyrightText: 2015 Martin Gräßlin <mgraesslin@kde.org> 0006 0007 SPDX-License-Identifier: GPL-2.0-or-later 0008 */ 0009 0010 #pragma once 0011 0012 #include <epoxy/egl.h> 0013 #include <kwin_export.h> 0014 #include <kwinglobals.h> 0015 0016 #include <QObject> 0017 0018 #include <memory> 0019 #include <optional> 0020 0021 namespace KWin 0022 { 0023 0024 class Output; 0025 class DmaBufTexture; 0026 class InputBackend; 0027 class OpenGLBackend; 0028 class QPainterBackend; 0029 class OutputConfiguration; 0030 struct DmaBufParams; 0031 0032 class KWIN_EXPORT Outputs : public QVector<Output *> 0033 { 0034 public: 0035 Outputs(){}; 0036 template<typename T> 0037 Outputs(const QVector<T> &other) 0038 { 0039 resize(other.size()); 0040 std::copy(other.constBegin(), other.constEnd(), begin()); 0041 } 0042 }; 0043 0044 class KWIN_EXPORT OutputBackend : public QObject 0045 { 0046 Q_OBJECT 0047 public: 0048 ~OutputBackend() override; 0049 0050 virtual bool initialize() = 0; 0051 virtual std::unique_ptr<InputBackend> createInputBackend(); 0052 virtual std::unique_ptr<OpenGLBackend> createOpenGLBackend(); 0053 virtual std::unique_ptr<QPainterBackend> createQPainterBackend(); 0054 virtual std::optional<DmaBufParams> testCreateDmaBuf(const QSize &size, quint32 format, const QVector<uint64_t> &modifiers); 0055 virtual std::shared_ptr<DmaBufTexture> createDmaBufTexture(const QSize &size, quint32 format, const uint64_t modifier); 0056 std::shared_ptr<DmaBufTexture> createDmaBufTexture(const DmaBufParams &attributes); 0057 0058 /** 0059 * The EGLDisplay used by the compositing scene. 0060 */ 0061 EGLDisplay sceneEglDisplay() const; 0062 void setSceneEglDisplay(EGLDisplay display); 0063 /** 0064 * Returns the compositor-wide shared EGL context. This function may return EGL_NO_CONTEXT 0065 * if the underlying rendering backend does not use EGL. 0066 * 0067 * Note that the returned context should never be made current. Instead, create a context 0068 * that shares with this one and make the new context current. 0069 */ 0070 EGLContext sceneEglGlobalShareContext() const; 0071 /** 0072 * Sets the global share context to @a context. This function is intended to be called only 0073 * by rendering backends. 0074 */ 0075 void setSceneEglGlobalShareContext(EGLContext context); 0076 0077 /** 0078 * The CompositingTypes supported by the Platform. 0079 * The first item should be the most preferred one. 0080 * @since 5.11 0081 */ 0082 virtual QVector<CompositingType> supportedCompositors() const = 0; 0083 0084 virtual Outputs outputs() const = 0; 0085 Output *findOutput(const QString &name) const; 0086 0087 /** 0088 * A string of information to include in kwin debug output 0089 * It should not be translated. 0090 * 0091 * The base implementation prints the name. 0092 * @since 5.12 0093 */ 0094 virtual QString supportInformation() const; 0095 0096 virtual Output *createVirtualOutput(const QString &name, const QSize &size, qreal scale); 0097 virtual void removeVirtualOutput(Output *output); 0098 0099 /** 0100 * Applies the output changes. Default implementation only sets values common between platforms 0101 */ 0102 virtual bool applyOutputChanges(const OutputConfiguration &config); 0103 0104 public Q_SLOTS: 0105 virtual void sceneInitialized(){}; 0106 0107 Q_SIGNALS: 0108 void outputsQueried(); 0109 /** 0110 * This signal is emitted when an output has been connected. The @a output is not ready 0111 * for compositing yet. 0112 */ 0113 void outputAdded(Output *output); 0114 /** 0115 * This signal is emitted when an output has been disconnected. 0116 */ 0117 void outputRemoved(Output *output); 0118 0119 protected: 0120 explicit OutputBackend(QObject *parent = nullptr); 0121 0122 private: 0123 EGLDisplay m_eglDisplay; 0124 EGLContext m_globalShareContext = EGL_NO_CONTEXT; 0125 }; 0126 0127 } // namespace KWin