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 QOpenGLCompositorWindow |
33 | { |
34 | public: |
35 | virtual ~QOpenGLCompositorWindow() { } |
36 | virtual QWindow *sourceWindow() const = 0; |
37 | virtual const QPlatformTextureList *textures() const = 0; |
38 | virtual void beginCompositing() { } |
39 | virtual void endCompositing() { } |
40 | }; |
41 | |
42 | class Q_OPENGL_EXPORT QOpenGLCompositor : public QObject |
43 | { |
44 | Q_OBJECT |
45 | |
46 | public: |
47 | static QOpenGLCompositor *instance(); |
48 | static void destroy(); |
49 | |
50 | void setTargetWindow(QWindow *window, const QRect &nativeTargetGeometry); |
51 | void setTargetContext(QOpenGLContext *context); |
52 | void setRotation(int degrees); |
53 | QOpenGLContext *context() const { return m_context; } |
54 | QWindow *targetWindow() const { return m_targetWindow; } |
55 | |
56 | void update(); |
57 | QImage grab(); |
58 | |
59 | QList<QOpenGLCompositorWindow *> windows() const { return m_windows; } |
60 | void addWindow(QOpenGLCompositorWindow *window); |
61 | void removeWindow(QOpenGLCompositorWindow *window); |
62 | void moveToTop(QOpenGLCompositorWindow *window); |
63 | void changeWindowIndex(QOpenGLCompositorWindow *window, int newIdx); |
64 | |
65 | signals: |
66 | void topWindowChanged(QOpenGLCompositorWindow *window); |
67 | |
68 | private slots: |
69 | void handleRenderAllRequest(); |
70 | |
71 | private: |
72 | QOpenGLCompositor(); |
73 | ~QOpenGLCompositor(); |
74 | |
75 | void renderAll(QOpenGLFramebufferObject *fbo); |
76 | void render(QOpenGLCompositorWindow *window); |
77 | void ensureCorrectZOrder(); |
78 | |
79 | QOpenGLContext *m_context; |
80 | QWindow *m_targetWindow; |
81 | QRect m_nativeTargetGeometry; |
82 | int m_rotation; |
83 | QMatrix4x4 m_rotationMatrix; |
84 | QTimer m_updateTimer; |
85 | QOpenGLTextureBlitter m_blitter; |
86 | QList<QOpenGLCompositorWindow *> m_windows; |
87 | }; |
88 | |
89 | QT_END_NAMESPACE |
90 | |
91 | #endif // QOPENGLCOMPOSITOR_H |
92 |