| 1 | // Copyright (C) 2020 The Qt Company Ltd. |
|---|---|
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
| 3 | |
| 4 | #ifndef QOPENGLCOMPOSITOR_H |
| 5 | #define QOPENGLCOMPOSITOR_H |
| 6 | |
| 7 | // |
| 8 | // W A R N I N G |
| 9 | // ------------- |
| 10 | // |
| 11 | // This file is not part of the Qt API. It exists purely as an |
| 12 | // implementation detail. This header file may change from version to |
| 13 | // version without notice, or even be removed. |
| 14 | // |
| 15 | // We mean it. |
| 16 | // |
| 17 | |
| 18 | #include <QtOpenGL/qtopenglglobal.h> |
| 19 | |
| 20 | #include <QtCore/QTimer> |
| 21 | #include <QtOpenGL/QOpenGLTextureBlitter> |
| 22 | #include <QtGui/QMatrix4x4> |
| 23 | #include <QtCore/private/qglobal_p.h> |
| 24 | |
| 25 | QT_BEGIN_NAMESPACE |
| 26 | |
| 27 | class QOpenGLContext; |
| 28 | class QOpenGLFramebufferObject; |
| 29 | class QWindow; |
| 30 | class QPlatformTextureList; |
| 31 | |
| 32 | class QOpenGLCompositorBackingStore; |
| 33 | class QOpenGLCompositorWindow |
| 34 | { |
| 35 | public: |
| 36 | virtual ~QOpenGLCompositorWindow() { } |
| 37 | virtual QWindow *sourceWindow() const = 0; |
| 38 | virtual const QPlatformTextureList *textures() const = 0; |
| 39 | virtual void beginCompositing() { } |
| 40 | virtual void endCompositing() { } |
| 41 | virtual void setBackingStore(QOpenGLCompositorBackingStore *backingStore) = 0; |
| 42 | virtual QOpenGLCompositorBackingStore *backingStore() const = 0; |
| 43 | }; |
| 44 | |
| 45 | class Q_OPENGL_EXPORT QOpenGLCompositor : public QObject |
| 46 | { |
| 47 | Q_OBJECT |
| 48 | |
| 49 | public: |
| 50 | enum GrabOrientation { |
| 51 | Flipped, |
| 52 | NotFlipped, |
| 53 | }; |
| 54 | |
| 55 | static QOpenGLCompositor *instance(); |
| 56 | static void destroy(); |
| 57 | |
| 58 | void setTargetWindow(QWindow *window, const QRect &nativeTargetGeometry); |
| 59 | void setTargetContext(QOpenGLContext *context); |
| 60 | void setRotation(int degrees); |
| 61 | QOpenGLContext *context() const { return m_context; } |
| 62 | QWindow *targetWindow() const { return m_targetWindow; } |
| 63 | QRect nativeTargetGeometry() const { return m_nativeTargetGeometry; } |
| 64 | |
| 65 | void update(); |
| 66 | QImage grab(); |
| 67 | |
| 68 | bool grabToFrameBufferObject(QOpenGLFramebufferObject *fbo, GrabOrientation orientation = Flipped); |
| 69 | |
| 70 | QList<QOpenGLCompositorWindow *> windows() const { return m_windows; } |
| 71 | void addWindow(QOpenGLCompositorWindow *window); |
| 72 | void removeWindow(QOpenGLCompositorWindow *window); |
| 73 | void moveToTop(QOpenGLCompositorWindow *window); |
| 74 | void changeWindowIndex(QOpenGLCompositorWindow *window, int newIdx); |
| 75 | |
| 76 | signals: |
| 77 | void topWindowChanged(QOpenGLCompositorWindow *window); |
| 78 | |
| 79 | private slots: |
| 80 | void handleRenderAllRequest(); |
| 81 | |
| 82 | private: |
| 83 | QOpenGLCompositor(); |
| 84 | ~QOpenGLCompositor(); |
| 85 | |
| 86 | void renderAll(QOpenGLFramebufferObject *fbo, |
| 87 | QOpenGLTextureBlitter::Origin origin = QOpenGLTextureBlitter::OriginTopLeft); |
| 88 | void render(QOpenGLCompositorWindow *window, |
| 89 | QOpenGLTextureBlitter::Origin origin = QOpenGLTextureBlitter::OriginTopLeft); |
| 90 | void ensureCorrectZOrder(); |
| 91 | |
| 92 | QOpenGLContext *m_context; |
| 93 | QWindow *m_targetWindow; |
| 94 | QRect m_nativeTargetGeometry; |
| 95 | int m_rotation; |
| 96 | QMatrix4x4 m_rotationMatrix; |
| 97 | QTimer m_updateTimer; |
| 98 | QOpenGLTextureBlitter m_blitter; |
| 99 | QList<QOpenGLCompositorWindow *> m_windows; |
| 100 | }; |
| 101 | |
| 102 | QT_END_NAMESPACE |
| 103 | |
| 104 | #endif // QOPENGLCOMPOSITOR_H |
| 105 |
