1 | // Copyright (C) 2016 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 QSGRENDERLOOP_P_H |
5 | #define QSGRENDERLOOP_P_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 <QtGui/qimage.h> |
19 | #include <QtGui/qsurface.h> |
20 | #include <private/qtquickglobal_p.h> |
21 | #include <QtCore/qset.h> |
22 | #include <QtCore/qobject.h> |
23 | #include <QtCore/qcoreevent.h> |
24 | |
25 | QT_BEGIN_NAMESPACE |
26 | |
27 | class QQuickWindow; |
28 | class QSGContext; |
29 | class QSGRenderContext; |
30 | class QAnimationDriver; |
31 | class QRunnable; |
32 | |
33 | class Q_QUICK_PRIVATE_EXPORT QSGRenderLoop : public QObject |
34 | { |
35 | Q_OBJECT |
36 | |
37 | public: |
38 | enum RenderLoopFlags { |
39 | SupportsGrabWithoutExpose = 0x01 |
40 | }; |
41 | |
42 | virtual ~QSGRenderLoop(); |
43 | |
44 | virtual void show(QQuickWindow *window) = 0; |
45 | virtual void hide(QQuickWindow *window) = 0; |
46 | virtual void resize(QQuickWindow *) {}; |
47 | |
48 | virtual void windowDestroyed(QQuickWindow *window) = 0; |
49 | |
50 | virtual void exposureChanged(QQuickWindow *window) = 0; |
51 | virtual QImage grab(QQuickWindow *window) = 0; |
52 | |
53 | virtual void update(QQuickWindow *window) = 0; |
54 | virtual void maybeUpdate(QQuickWindow *window) = 0; |
55 | virtual void handleUpdateRequest(QQuickWindow *) { } |
56 | |
57 | virtual QAnimationDriver *animationDriver() const = 0; |
58 | |
59 | virtual QSGContext *sceneGraphContext() const = 0; |
60 | virtual QSGRenderContext *createRenderContext(QSGContext *) const = 0; |
61 | |
62 | virtual void releaseResources(QQuickWindow *window) = 0; |
63 | virtual void postJob(QQuickWindow *window, QRunnable *job); |
64 | |
65 | void addWindow(QQuickWindow *win) { m_windows.insert(value: win); } |
66 | void removeWindow(QQuickWindow *win) { m_windows.remove(value: win); } |
67 | QSet<QQuickWindow *> windows() const { return m_windows; } |
68 | |
69 | virtual QSurface::SurfaceType windowSurfaceType() const; |
70 | |
71 | // ### make this less of a singleton |
72 | static QSGRenderLoop *instance(); |
73 | static void setInstance(QSGRenderLoop *instance); |
74 | |
75 | virtual bool interleaveIncubation() const { return false; } |
76 | |
77 | virtual int flags() const { return 0; } |
78 | |
79 | static void cleanup(); |
80 | |
81 | void handleContextCreationFailure(QQuickWindow *window); |
82 | |
83 | Q_SIGNALS: |
84 | void timeToIncubate(); |
85 | |
86 | private: |
87 | static QSGRenderLoop *s_instance; |
88 | |
89 | QSet<QQuickWindow *> m_windows; |
90 | }; |
91 | |
92 | enum QSGRenderLoopType |
93 | { |
94 | BasicRenderLoop, |
95 | ThreadedRenderLoop |
96 | }; |
97 | |
98 | enum QSGCustomEvents { |
99 | |
100 | // Passed from the RL to the RT when a window is removed obscured and |
101 | // should be removed from the render loop. |
102 | WM_Obscure = QEvent::User + 1, |
103 | |
104 | // Passed from the RL to RT when GUI has been locked, waiting for sync |
105 | // (updatePaintNode()) |
106 | WM_RequestSync = QEvent::User + 2, |
107 | |
108 | // Passed by the RL to the RT to free up maybe release SG and GL contexts |
109 | // if no windows are rendering. |
110 | WM_TryRelease = QEvent::User + 4, |
111 | |
112 | // Passed by the RL to the RT when a QQuickWindow::grabWindow() is |
113 | // called. |
114 | WM_Grab = QEvent::User + 5, |
115 | |
116 | // Passed by the window when there is a render job to run |
117 | WM_PostJob = QEvent::User + 6, |
118 | |
119 | // When using the QRhi this is sent upon PlatformSurfaceAboutToBeDestroyed from |
120 | // the event filter installed on the QQuickWindow. |
121 | WM_ReleaseSwapchain = QEvent::User + 7, |
122 | |
123 | }; |
124 | |
125 | QT_END_NAMESPACE |
126 | |
127 | #endif // QSGRENDERLOOP_P_H |
128 | |