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
25QT_BEGIN_NAMESPACE
26
27class QOpenGLContext;
28class QOpenGLFramebufferObject;
29class QWindow;
30class QPlatformTextureList;
31
32class QOpenGLCompositorWindow
33{
34public:
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
42class Q_OPENGL_EXPORT QOpenGLCompositor : public QObject
43{
44 Q_OBJECT
45
46public:
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
65signals:
66 void topWindowChanged(QOpenGLCompositorWindow *window);
67
68private slots:
69 void handleRenderAllRequest();
70
71private:
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
89QT_END_NAMESPACE
90
91#endif // QOPENGLCOMPOSITOR_H
92

source code of qtbase/src/opengl/qopenglcompositor_p.h