Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/qtdeclarative/src/qtdeclarative/src/quick/scenegraph/qsgthreadedrenderloop.cpp |
Source code | Switch to Preprocessed file |
Line | Source | Count | ||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | /**************************************************************************** | - | ||||||||||||||||||||||||
2 | ** | - | ||||||||||||||||||||||||
3 | ** Copyright (C) 2016 The Qt Company Ltd. | - | ||||||||||||||||||||||||
4 | ** Copyright (C) 2016 Jolla Ltd, author: <gunnar.sletta@jollamobile.com> | - | ||||||||||||||||||||||||
5 | ** Contact: https://www.qt.io/licensing/ | - | ||||||||||||||||||||||||
6 | ** | - | ||||||||||||||||||||||||
7 | ** This file is part of the QtQuick module of the Qt Toolkit. | - | ||||||||||||||||||||||||
8 | ** | - | ||||||||||||||||||||||||
9 | ** $QT_BEGIN_LICENSE:LGPL$ | - | ||||||||||||||||||||||||
10 | ** Commercial License Usage | - | ||||||||||||||||||||||||
11 | ** Licensees holding valid commercial Qt licenses may use this file in | - | ||||||||||||||||||||||||
12 | ** accordance with the commercial license agreement provided with the | - | ||||||||||||||||||||||||
13 | ** Software or, alternatively, in accordance with the terms contained in | - | ||||||||||||||||||||||||
14 | ** a written agreement between you and The Qt Company. For licensing terms | - | ||||||||||||||||||||||||
15 | ** and conditions see https://www.qt.io/terms-conditions. For further | - | ||||||||||||||||||||||||
16 | ** information use the contact form at https://www.qt.io/contact-us. | - | ||||||||||||||||||||||||
17 | ** | - | ||||||||||||||||||||||||
18 | ** GNU Lesser General Public License Usage | - | ||||||||||||||||||||||||
19 | ** Alternatively, this file may be used under the terms of the GNU Lesser | - | ||||||||||||||||||||||||
20 | ** General Public License version 3 as published by the Free Software | - | ||||||||||||||||||||||||
21 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the | - | ||||||||||||||||||||||||
22 | ** packaging of this file. Please review the following information to | - | ||||||||||||||||||||||||
23 | ** ensure the GNU Lesser General Public License version 3 requirements | - | ||||||||||||||||||||||||
24 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. | - | ||||||||||||||||||||||||
25 | ** | - | ||||||||||||||||||||||||
26 | ** GNU General Public License Usage | - | ||||||||||||||||||||||||
27 | ** Alternatively, this file may be used under the terms of the GNU | - | ||||||||||||||||||||||||
28 | ** General Public License version 2.0 or (at your option) the GNU General | - | ||||||||||||||||||||||||
29 | ** Public license version 3 or any later version approved by the KDE Free | - | ||||||||||||||||||||||||
30 | ** Qt Foundation. The licenses are as published by the Free Software | - | ||||||||||||||||||||||||
31 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 | - | ||||||||||||||||||||||||
32 | ** included in the packaging of this file. Please review the following | - | ||||||||||||||||||||||||
33 | ** information to ensure the GNU General Public License requirements will | - | ||||||||||||||||||||||||
34 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and | - | ||||||||||||||||||||||||
35 | ** https://www.gnu.org/licenses/gpl-3.0.html. | - | ||||||||||||||||||||||||
36 | ** | - | ||||||||||||||||||||||||
37 | ** $QT_END_LICENSE$ | - | ||||||||||||||||||||||||
38 | ** | - | ||||||||||||||||||||||||
39 | ****************************************************************************/ | - | ||||||||||||||||||||||||
40 | - | |||||||||||||||||||||||||
41 | - | |||||||||||||||||||||||||
42 | #include <QtCore/QMutex> | - | ||||||||||||||||||||||||
43 | #include <QtCore/QWaitCondition> | - | ||||||||||||||||||||||||
44 | #include <QtCore/QAnimationDriver> | - | ||||||||||||||||||||||||
45 | #include <QtCore/QQueue> | - | ||||||||||||||||||||||||
46 | #include <QtCore/QTime> | - | ||||||||||||||||||||||||
47 | - | |||||||||||||||||||||||||
48 | #include <QtGui/QGuiApplication> | - | ||||||||||||||||||||||||
49 | #include <QtGui/QScreen> | - | ||||||||||||||||||||||||
50 | #include <QtGui/QOffscreenSurface> | - | ||||||||||||||||||||||||
51 | - | |||||||||||||||||||||||||
52 | #include <qpa/qwindowsysteminterface.h> | - | ||||||||||||||||||||||||
53 | - | |||||||||||||||||||||||||
54 | #include <QtQuick/QQuickWindow> | - | ||||||||||||||||||||||||
55 | #include <private/qquickwindow_p.h> | - | ||||||||||||||||||||||||
56 | - | |||||||||||||||||||||||||
57 | #include <QtQuick/private/qsgrenderer_p.h> | - | ||||||||||||||||||||||||
58 | - | |||||||||||||||||||||||||
59 | #include "qsgthreadedrenderloop_p.h" | - | ||||||||||||||||||||||||
60 | #include <private/qquickanimatorcontroller_p.h> | - | ||||||||||||||||||||||||
61 | - | |||||||||||||||||||||||||
62 | #include <private/qquickprofiler_p.h> | - | ||||||||||||||||||||||||
63 | #include <private/qqmldebugserviceinterfaces_p.h> | - | ||||||||||||||||||||||||
64 | #include <private/qqmldebugconnector_p.h> | - | ||||||||||||||||||||||||
65 | - | |||||||||||||||||||||||||
66 | #if QT_CONFIG(quick_shadereffect) | - | ||||||||||||||||||||||||
67 | #include <private/qquickopenglshadereffectnode_p.h> | - | ||||||||||||||||||||||||
68 | #endif | - | ||||||||||||||||||||||||
69 | #include <private/qsgdefaultrendercontext_p.h> | - | ||||||||||||||||||||||||
70 | - | |||||||||||||||||||||||||
71 | /* | - | ||||||||||||||||||||||||
72 | Overall design: | - | ||||||||||||||||||||||||
73 | - | |||||||||||||||||||||||||
74 | There are two classes here. QSGThreadedRenderLoop and | - | ||||||||||||||||||||||||
75 | QSGRenderThread. All communication between the two is based on | - | ||||||||||||||||||||||||
76 | event passing and we have a number of custom events. | - | ||||||||||||||||||||||||
77 | - | |||||||||||||||||||||||||
78 | In this implementation, the render thread is never blocked and the | - | ||||||||||||||||||||||||
79 | GUI thread will initiate a polishAndSync which will block and wait | - | ||||||||||||||||||||||||
80 | for the render thread to pick it up and release the block only | - | ||||||||||||||||||||||||
81 | after the render thread is done syncing. The reason for this | - | ||||||||||||||||||||||||
82 | is: | - | ||||||||||||||||||||||||
83 | - | |||||||||||||||||||||||||
84 | 1. Clear blocking paradigm. We only have one real "block" point | - | ||||||||||||||||||||||||
85 | (polishAndSync()) and all blocking is initiated by GUI and picked | - | ||||||||||||||||||||||||
86 | up by Render at specific times based on events. This makes the | - | ||||||||||||||||||||||||
87 | execution deterministic. | - | ||||||||||||||||||||||||
88 | - | |||||||||||||||||||||||||
89 | 2. Render does not have to interact with GUI. This is done so that | - | ||||||||||||||||||||||||
90 | the render thread can run its own animation system which stays | - | ||||||||||||||||||||||||
91 | alive even when the GUI thread is blocked doing i/o, object | - | ||||||||||||||||||||||||
92 | instantiation, QPainter-painting or any other non-trivial task. | - | ||||||||||||||||||||||||
93 | - | |||||||||||||||||||||||||
94 | --- | - | ||||||||||||||||||||||||
95 | - | |||||||||||||||||||||||||
96 | There is one thread per window and one opengl context per thread. | - | ||||||||||||||||||||||||
97 | - | |||||||||||||||||||||||||
98 | --- | - | ||||||||||||||||||||||||
99 | - | |||||||||||||||||||||||||
100 | The render thread has affinity to the GUI thread until a window | - | ||||||||||||||||||||||||
101 | is shown. From that moment and until the window is destroyed, it | - | ||||||||||||||||||||||||
102 | will have affinity to the render thread. (moved back at the end | - | ||||||||||||||||||||||||
103 | of run for cleanup). | - | ||||||||||||||||||||||||
104 | - | |||||||||||||||||||||||||
105 | --- | - | ||||||||||||||||||||||||
106 | - | |||||||||||||||||||||||||
107 | The render loop is active while any window is exposed. All visible | - | ||||||||||||||||||||||||
108 | windows are tracked, but only exposed windows are actually added to | - | ||||||||||||||||||||||||
109 | the render thread and rendered. That means that if all windows are | - | ||||||||||||||||||||||||
110 | obscured, we might end up cleaning up the SG and GL context (if all | - | ||||||||||||||||||||||||
111 | windows have disabled persistency). Especially for multiprocess, | - | ||||||||||||||||||||||||
112 | low-end systems, this should be quite important. | - | ||||||||||||||||||||||||
113 | - | |||||||||||||||||||||||||
114 | */ | - | ||||||||||||||||||||||||
115 | - | |||||||||||||||||||||||||
116 | QT_BEGIN_NAMESPACE | - | ||||||||||||||||||||||||
117 | - | |||||||||||||||||||||||||
118 | #define QSG_RT_PAD " (RT) %s" | - | ||||||||||||||||||||||||
119 | - | |||||||||||||||||||||||||
120 | static inline int qsgrl_animation_interval() { | - | ||||||||||||||||||||||||
121 | qreal refreshRate = QGuiApplication::primaryScreen()->refreshRate(); | - | ||||||||||||||||||||||||
122 | // To work around that some platforms wrongfully return 0 or something | - | ||||||||||||||||||||||||
123 | // bogus for refreshrate | - | ||||||||||||||||||||||||
124 | if (refreshRate < 1)
| 0 | ||||||||||||||||||||||||
125 | return 16; never executed: return 16; | 0 | ||||||||||||||||||||||||
126 | return int(1000 / refreshRate); never executed: return int(1000 / refreshRate); | 0 | ||||||||||||||||||||||||
127 | } | - | ||||||||||||||||||||||||
128 | - | |||||||||||||||||||||||||
129 | - | |||||||||||||||||||||||||
130 | static QElapsedTimer threadTimer; | - | ||||||||||||||||||||||||
131 | static qint64 syncTime; | - | ||||||||||||||||||||||||
132 | static qint64 renderTime; | - | ||||||||||||||||||||||||
133 | static qint64 sinceLastTime; | - | ||||||||||||||||||||||||
134 | - | |||||||||||||||||||||||||
135 | extern Q_GUI_EXPORT QImage qt_gl_read_framebuffer(const QSize &size, bool alpha_format, bool include_alpha); | - | ||||||||||||||||||||||||
136 | - | |||||||||||||||||||||||||
137 | // RL: Render Loop | - | ||||||||||||||||||||||||
138 | // RT: Render Thread | - | ||||||||||||||||||||||||
139 | - | |||||||||||||||||||||||||
140 | // Passed from the RL to the RT when a window is removed obscured and | - | ||||||||||||||||||||||||
141 | // should be removed from the render loop. | - | ||||||||||||||||||||||||
142 | const QEvent::Type WM_Obscure = QEvent::Type(QEvent::User + 1); | - | ||||||||||||||||||||||||
143 | - | |||||||||||||||||||||||||
144 | // Passed from the RL to RT when GUI has been locked, waiting for sync | - | ||||||||||||||||||||||||
145 | // (updatePaintNode()) | - | ||||||||||||||||||||||||
146 | const QEvent::Type WM_RequestSync = QEvent::Type(QEvent::User + 2); | - | ||||||||||||||||||||||||
147 | - | |||||||||||||||||||||||||
148 | // Passed by the RT to itself to trigger another render pass. This is | - | ||||||||||||||||||||||||
149 | // typically a result of QQuickWindow::update(). | - | ||||||||||||||||||||||||
150 | const QEvent::Type WM_RequestRepaint = QEvent::Type(QEvent::User + 3); | - | ||||||||||||||||||||||||
151 | - | |||||||||||||||||||||||||
152 | // Passed by the RL to the RT to free up maybe release SG and GL contexts | - | ||||||||||||||||||||||||
153 | // if no windows are rendering. | - | ||||||||||||||||||||||||
154 | const QEvent::Type WM_TryRelease = QEvent::Type(QEvent::User + 4); | - | ||||||||||||||||||||||||
155 | - | |||||||||||||||||||||||||
156 | // Passed by the RL to the RT when a QQuickWindow::grabWindow() is | - | ||||||||||||||||||||||||
157 | // called. | - | ||||||||||||||||||||||||
158 | const QEvent::Type WM_Grab = QEvent::Type(QEvent::User + 5); | - | ||||||||||||||||||||||||
159 | - | |||||||||||||||||||||||||
160 | // Passed by the window when there is a render job to run | - | ||||||||||||||||||||||||
161 | const QEvent::Type WM_PostJob = QEvent::Type(QEvent::User + 6); | - | ||||||||||||||||||||||||
162 | - | |||||||||||||||||||||||||
163 | template <typename T> T *windowFor(const QList<T> &list, QQuickWindow *window) | - | ||||||||||||||||||||||||
164 | { | - | ||||||||||||||||||||||||
165 | for (int i=0; i<list.size(); ++i) {
| 0 | ||||||||||||||||||||||||
166 | const T &t = list.at(i); | - | ||||||||||||||||||||||||
167 | if (t.window == window)
| 0 | ||||||||||||||||||||||||
168 | return const_cast<T *>(&t); never executed: return const_cast<T *>(&t); | 0 | ||||||||||||||||||||||||
169 | } never executed: end of block | 0 | ||||||||||||||||||||||||
170 | return nullptr; never executed: return nullptr; | 0 | ||||||||||||||||||||||||
171 | } | - | ||||||||||||||||||||||||
172 | - | |||||||||||||||||||||||||
173 | - | |||||||||||||||||||||||||
174 | class WMWindowEvent : public QEvent | - | ||||||||||||||||||||||||
175 | { | - | ||||||||||||||||||||||||
176 | public: | - | ||||||||||||||||||||||||
177 | WMWindowEvent(QQuickWindow *c, QEvent::Type type) : QEvent(type), window(c) { } never executed: end of block | 0 | ||||||||||||||||||||||||
178 | QQuickWindow *window; | - | ||||||||||||||||||||||||
179 | }; | - | ||||||||||||||||||||||||
180 | - | |||||||||||||||||||||||||
181 | class WMTryReleaseEvent : public WMWindowEvent | - | ||||||||||||||||||||||||
182 | { | - | ||||||||||||||||||||||||
183 | public: | - | ||||||||||||||||||||||||
184 | WMTryReleaseEvent(QQuickWindow *win, bool destroy, QOffscreenSurface *fallback) | - | ||||||||||||||||||||||||
185 | : WMWindowEvent(win, WM_TryRelease) | - | ||||||||||||||||||||||||
186 | , inDestructor(destroy) | - | ||||||||||||||||||||||||
187 | , fallbackSurface(fallback) | - | ||||||||||||||||||||||||
188 | {} never executed: end of block | 0 | ||||||||||||||||||||||||
189 | - | |||||||||||||||||||||||||
190 | bool inDestructor; | - | ||||||||||||||||||||||||
191 | QOffscreenSurface *fallbackSurface; | - | ||||||||||||||||||||||||
192 | }; | - | ||||||||||||||||||||||||
193 | - | |||||||||||||||||||||||||
194 | class WMSyncEvent : public WMWindowEvent | - | ||||||||||||||||||||||||
195 | { | - | ||||||||||||||||||||||||
196 | public: | - | ||||||||||||||||||||||||
197 | WMSyncEvent(QQuickWindow *c, bool inExpose, bool force) | - | ||||||||||||||||||||||||
198 | : WMWindowEvent(c, WM_RequestSync) | - | ||||||||||||||||||||||||
199 | , size(c->size()) | - | ||||||||||||||||||||||||
200 | , syncInExpose(inExpose) | - | ||||||||||||||||||||||||
201 | , forceRenderPass(force) | - | ||||||||||||||||||||||||
202 | {} never executed: end of block | 0 | ||||||||||||||||||||||||
203 | QSize size; | - | ||||||||||||||||||||||||
204 | bool syncInExpose; | - | ||||||||||||||||||||||||
205 | bool forceRenderPass; | - | ||||||||||||||||||||||||
206 | }; | - | ||||||||||||||||||||||||
207 | - | |||||||||||||||||||||||||
208 | - | |||||||||||||||||||||||||
209 | class WMGrabEvent : public WMWindowEvent | - | ||||||||||||||||||||||||
210 | { | - | ||||||||||||||||||||||||
211 | public: | - | ||||||||||||||||||||||||
212 | WMGrabEvent(QQuickWindow *c, QImage *result) : WMWindowEvent(c, WM_Grab), image(result) {} never executed: end of block | 0 | ||||||||||||||||||||||||
213 | QImage *image; | - | ||||||||||||||||||||||||
214 | }; | - | ||||||||||||||||||||||||
215 | - | |||||||||||||||||||||||||
216 | class WMJobEvent : public WMWindowEvent | - | ||||||||||||||||||||||||
217 | { | - | ||||||||||||||||||||||||
218 | public: | - | ||||||||||||||||||||||||
219 | WMJobEvent(QQuickWindow *c, QRunnable *postedJob) | - | ||||||||||||||||||||||||
220 | : WMWindowEvent(c, WM_PostJob), job(postedJob) {} never executed: end of block | 0 | ||||||||||||||||||||||||
221 | ~WMJobEvent() { delete job; } never executed: end of block | 0 | ||||||||||||||||||||||||
222 | QRunnable *job; | - | ||||||||||||||||||||||||
223 | }; | - | ||||||||||||||||||||||||
224 | - | |||||||||||||||||||||||||
225 | class QSGRenderThreadEventQueue : public QQueue<QEvent *> | - | ||||||||||||||||||||||||
226 | { | - | ||||||||||||||||||||||||
227 | public: | - | ||||||||||||||||||||||||
228 | QSGRenderThreadEventQueue() | - | ||||||||||||||||||||||||
229 | : waiting(false) | - | ||||||||||||||||||||||||
230 | { | - | ||||||||||||||||||||||||
231 | } never executed: end of block | 0 | ||||||||||||||||||||||||
232 | - | |||||||||||||||||||||||||
233 | void addEvent(QEvent *e) { | - | ||||||||||||||||||||||||
234 | mutex.lock(); | - | ||||||||||||||||||||||||
235 | enqueue(e); | - | ||||||||||||||||||||||||
236 | if (waiting)
| 0 | ||||||||||||||||||||||||
237 | condition.wakeOne(); never executed: condition.wakeOne(); | 0 | ||||||||||||||||||||||||
238 | mutex.unlock(); | - | ||||||||||||||||||||||||
239 | } never executed: end of block | 0 | ||||||||||||||||||||||||
240 | - | |||||||||||||||||||||||||
241 | QEvent *takeEvent(bool wait) { | - | ||||||||||||||||||||||||
242 | mutex.lock(); | - | ||||||||||||||||||||||||
243 | if (size() == 0 && wait) {
| 0 | ||||||||||||||||||||||||
244 | waiting = true; | - | ||||||||||||||||||||||||
245 | condition.wait(&mutex); | - | ||||||||||||||||||||||||
246 | waiting = false; | - | ||||||||||||||||||||||||
247 | } never executed: end of block | 0 | ||||||||||||||||||||||||
248 | QEvent *e = dequeue(); | - | ||||||||||||||||||||||||
249 | mutex.unlock(); | - | ||||||||||||||||||||||||
250 | return e; never executed: return e; | 0 | ||||||||||||||||||||||||
251 | } | - | ||||||||||||||||||||||||
252 | - | |||||||||||||||||||||||||
253 | bool hasMoreEvents() { | - | ||||||||||||||||||||||||
254 | mutex.lock(); | - | ||||||||||||||||||||||||
255 | bool has = !isEmpty(); | - | ||||||||||||||||||||||||
256 | mutex.unlock(); | - | ||||||||||||||||||||||||
257 | return has; never executed: return has; | 0 | ||||||||||||||||||||||||
258 | } | - | ||||||||||||||||||||||||
259 | - | |||||||||||||||||||||||||
260 | private: | - | ||||||||||||||||||||||||
261 | QMutex mutex; | - | ||||||||||||||||||||||||
262 | QWaitCondition condition; | - | ||||||||||||||||||||||||
263 | bool waiting; | - | ||||||||||||||||||||||||
264 | }; | - | ||||||||||||||||||||||||
265 | - | |||||||||||||||||||||||||
266 | - | |||||||||||||||||||||||||
267 | class QSGRenderThread : public QThread | - | ||||||||||||||||||||||||
268 | { | - | ||||||||||||||||||||||||
269 | Q_OBJECT | - | ||||||||||||||||||||||||
270 | public: | - | ||||||||||||||||||||||||
271 | QSGRenderThread(QSGThreadedRenderLoop *w, QSGRenderContext *renderContext) | - | ||||||||||||||||||||||||
272 | : wm(w) | - | ||||||||||||||||||||||||
273 | , gl(nullptr) | - | ||||||||||||||||||||||||
274 | , animatorDriver(nullptr) | - | ||||||||||||||||||||||||
275 | , pendingUpdate(0) | - | ||||||||||||||||||||||||
276 | , sleeping(false) | - | ||||||||||||||||||||||||
277 | , syncResultedInChanges(false) | - | ||||||||||||||||||||||||
278 | , active(false) | - | ||||||||||||||||||||||||
279 | , window(nullptr) | - | ||||||||||||||||||||||||
280 | , stopEventProcessing(false) | - | ||||||||||||||||||||||||
281 | { | - | ||||||||||||||||||||||||
282 | sgrc = static_cast<QSGDefaultRenderContext *>(renderContext); | - | ||||||||||||||||||||||||
283 | #if defined(Q_OS_QNX) && defined(Q_PROCESSOR_X86) | - | ||||||||||||||||||||||||
284 | // The SDP 6.6.0 x86 MESA driver requires a larger stack than the default. | - | ||||||||||||||||||||||||
285 | setStackSize(1024 * 1024); | - | ||||||||||||||||||||||||
286 | #endif | - | ||||||||||||||||||||||||
287 | vsyncDelta = qsgrl_animation_interval(); | - | ||||||||||||||||||||||||
288 | } never executed: end of block | 0 | ||||||||||||||||||||||||
289 | - | |||||||||||||||||||||||||
290 | ~QSGRenderThread() | - | ||||||||||||||||||||||||
291 | { | - | ||||||||||||||||||||||||
292 | delete sgrc; | - | ||||||||||||||||||||||||
293 | } never executed: end of block | 0 | ||||||||||||||||||||||||
294 | - | |||||||||||||||||||||||||
295 | void invalidateOpenGL(QQuickWindow *window, bool inDestructor, QOffscreenSurface *backupSurface); | - | ||||||||||||||||||||||||
296 | void initializeOpenGL(); | - | ||||||||||||||||||||||||
297 | - | |||||||||||||||||||||||||
298 | bool event(QEvent *) override; | - | ||||||||||||||||||||||||
299 | void run() override; | - | ||||||||||||||||||||||||
300 | - | |||||||||||||||||||||||||
301 | void syncAndRender(); | - | ||||||||||||||||||||||||
302 | void sync(bool inExpose); | - | ||||||||||||||||||||||||
303 | - | |||||||||||||||||||||||||
304 | void requestRepaint() | - | ||||||||||||||||||||||||
305 | { | - | ||||||||||||||||||||||||
306 | if (sleeping)
| 0 | ||||||||||||||||||||||||
307 | stopEventProcessing = true; never executed: stopEventProcessing = true; | 0 | ||||||||||||||||||||||||
308 | if (window)
| 0 | ||||||||||||||||||||||||
309 | pendingUpdate |= RepaintRequest; never executed: pendingUpdate |= RepaintRequest; | 0 | ||||||||||||||||||||||||
310 | } never executed: end of block | 0 | ||||||||||||||||||||||||
311 | - | |||||||||||||||||||||||||
312 | void processEventsAndWaitForMore(); | - | ||||||||||||||||||||||||
313 | void processEvents(); | - | ||||||||||||||||||||||||
314 | void postEvent(QEvent *e); | - | ||||||||||||||||||||||||
315 | - | |||||||||||||||||||||||||
316 | public slots: | - | ||||||||||||||||||||||||
317 | void sceneGraphChanged() { | - | ||||||||||||||||||||||||
318 | qCDebug(QSG_LOG_RENDERLOOP, QSG_RT_PAD, "sceneGraphChanged"); never executed: QMessageLogger(__FILE__, 318, __PRETTY_FUNCTION__, QSG_LOG_RENDERLOOP().categoryName()).debug(" (RT) %s", "sceneGraphChanged");
| 0 | ||||||||||||||||||||||||
319 | syncResultedInChanges = true; | - | ||||||||||||||||||||||||
320 | } never executed: end of block | 0 | ||||||||||||||||||||||||
321 | - | |||||||||||||||||||||||||
322 | public: | - | ||||||||||||||||||||||||
323 | enum UpdateRequest { | - | ||||||||||||||||||||||||
324 | SyncRequest = 0x01, | - | ||||||||||||||||||||||||
325 | RepaintRequest = 0x02, | - | ||||||||||||||||||||||||
326 | ExposeRequest = 0x04 | RepaintRequest | SyncRequest | - | ||||||||||||||||||||||||
327 | }; | - | ||||||||||||||||||||||||
328 | - | |||||||||||||||||||||||||
329 | QSGThreadedRenderLoop *wm; | - | ||||||||||||||||||||||||
330 | QOpenGLContext *gl; | - | ||||||||||||||||||||||||
331 | QSGDefaultRenderContext *sgrc; | - | ||||||||||||||||||||||||
332 | - | |||||||||||||||||||||||||
333 | QAnimationDriver *animatorDriver; | - | ||||||||||||||||||||||||
334 | - | |||||||||||||||||||||||||
335 | uint pendingUpdate; | - | ||||||||||||||||||||||||
336 | bool sleeping; | - | ||||||||||||||||||||||||
337 | bool syncResultedInChanges; | - | ||||||||||||||||||||||||
338 | - | |||||||||||||||||||||||||
339 | volatile bool active; | - | ||||||||||||||||||||||||
340 | - | |||||||||||||||||||||||||
341 | float vsyncDelta; | - | ||||||||||||||||||||||||
342 | - | |||||||||||||||||||||||||
343 | QMutex mutex; | - | ||||||||||||||||||||||||
344 | QWaitCondition waitCondition; | - | ||||||||||||||||||||||||
345 | - | |||||||||||||||||||||||||
346 | QElapsedTimer m_timer; | - | ||||||||||||||||||||||||
347 | - | |||||||||||||||||||||||||
348 | QQuickWindow *window; // Will be 0 when window is not exposed | - | ||||||||||||||||||||||||
349 | QSize windowSize; | - | ||||||||||||||||||||||||
350 | - | |||||||||||||||||||||||||
351 | // Local event queue stuff... | - | ||||||||||||||||||||||||
352 | bool stopEventProcessing; | - | ||||||||||||||||||||||||
353 | QSGRenderThreadEventQueue eventQueue; | - | ||||||||||||||||||||||||
354 | }; | - | ||||||||||||||||||||||||
355 | - | |||||||||||||||||||||||||
356 | bool QSGRenderThread::event(QEvent *e) | - | ||||||||||||||||||||||||
357 | { | - | ||||||||||||||||||||||||
358 | switch ((int) e->type()) { | - | ||||||||||||||||||||||||
359 | - | |||||||||||||||||||||||||
360 | case WM_Obscure: { never executed: case WM_Obscure: | 0 | ||||||||||||||||||||||||
361 | qCDebug(QSG_LOG_RENDERLOOP, QSG_RT_PAD, "WM_Obscure"); never executed: QMessageLogger(__FILE__, 361, __PRETTY_FUNCTION__, QSG_LOG_RENDERLOOP().categoryName()).debug(" (RT) %s", "WM_Obscure");
| 0 | ||||||||||||||||||||||||
362 | - | |||||||||||||||||||||||||
363 | Q_ASSERT(!window || window == static_cast<WMWindowEvent *>(e)->window); | - | ||||||||||||||||||||||||
364 | - | |||||||||||||||||||||||||
365 | mutex.lock(); | - | ||||||||||||||||||||||||
366 | if (window) {
| 0 | ||||||||||||||||||||||||
367 | QQuickWindowPrivate::get(window)->fireAboutToStop(); | - | ||||||||||||||||||||||||
368 | qCDebug(QSG_LOG_RENDERLOOP, QSG_RT_PAD, "- window removed"); never executed: QMessageLogger(__FILE__, 368, __PRETTY_FUNCTION__, QSG_LOG_RENDERLOOP().categoryName()).debug(" (RT) %s", "- window removed");
| 0 | ||||||||||||||||||||||||
369 | window = nullptr; | - | ||||||||||||||||||||||||
370 | } never executed: end of block | 0 | ||||||||||||||||||||||||
371 | waitCondition.wakeOne(); | - | ||||||||||||||||||||||||
372 | mutex.unlock(); | - | ||||||||||||||||||||||||
373 | - | |||||||||||||||||||||||||
374 | return true; } never executed: return true; | 0 | ||||||||||||||||||||||||
375 | - | |||||||||||||||||||||||||
376 | case WM_RequestSync: { never executed: case WM_RequestSync: | 0 | ||||||||||||||||||||||||
377 | qCDebug(QSG_LOG_RENDERLOOP, QSG_RT_PAD, "WM_RequestSync"); never executed: QMessageLogger(__FILE__, 377, __PRETTY_FUNCTION__, QSG_LOG_RENDERLOOP().categoryName()).debug(" (RT) %s", "WM_RequestSync");
| 0 | ||||||||||||||||||||||||
378 | WMSyncEvent *se = static_cast<WMSyncEvent *>(e); | - | ||||||||||||||||||||||||
379 | if (sleeping)
| 0 | ||||||||||||||||||||||||
380 | stopEventProcessing = true; never executed: stopEventProcessing = true; | 0 | ||||||||||||||||||||||||
381 | window = se->window; | - | ||||||||||||||||||||||||
382 | windowSize = se->size; | - | ||||||||||||||||||||||||
383 | - | |||||||||||||||||||||||||
384 | pendingUpdate |= SyncRequest; | - | ||||||||||||||||||||||||
385 | if (se->syncInExpose) {
| 0 | ||||||||||||||||||||||||
386 | qCDebug(QSG_LOG_RENDERLOOP, QSG_RT_PAD, "- triggered from expose"); never executed: QMessageLogger(__FILE__, 386, __PRETTY_FUNCTION__, QSG_LOG_RENDERLOOP().categoryName()).debug(" (RT) %s", "- triggered from expose");
| 0 | ||||||||||||||||||||||||
387 | pendingUpdate |= ExposeRequest; | - | ||||||||||||||||||||||||
388 | } never executed: end of block | 0 | ||||||||||||||||||||||||
389 | if (se->forceRenderPass) {
| 0 | ||||||||||||||||||||||||
390 | qCDebug(QSG_LOG_RENDERLOOP, QSG_RT_PAD, "- repaint regardless"); never executed: QMessageLogger(__FILE__, 390, __PRETTY_FUNCTION__, QSG_LOG_RENDERLOOP().categoryName()).debug(" (RT) %s", "- repaint regardless");
| 0 | ||||||||||||||||||||||||
391 | pendingUpdate |= RepaintRequest; | - | ||||||||||||||||||||||||
392 | } never executed: end of block | 0 | ||||||||||||||||||||||||
393 | return true; } never executed: return true; | 0 | ||||||||||||||||||||||||
394 | - | |||||||||||||||||||||||||
395 | case WM_TryRelease: { never executed: case WM_TryRelease: | 0 | ||||||||||||||||||||||||
396 | qCDebug(QSG_LOG_RENDERLOOP, QSG_RT_PAD, "WM_TryRelease"); never executed: QMessageLogger(__FILE__, 396, __PRETTY_FUNCTION__, QSG_LOG_RENDERLOOP().categoryName()).debug(" (RT) %s", "WM_TryRelease");
| 0 | ||||||||||||||||||||||||
397 | mutex.lock(); | - | ||||||||||||||||||||||||
398 | wm->m_lockedForSync = true; | - | ||||||||||||||||||||||||
399 | WMTryReleaseEvent *wme = static_cast<WMTryReleaseEvent *>(e); | - | ||||||||||||||||||||||||
400 | if (!window || wme->inDestructor) {
| 0 | ||||||||||||||||||||||||
401 | qCDebug(QSG_LOG_RENDERLOOP, QSG_RT_PAD, "- setting exit flag and invalidating OpenGL"); never executed: QMessageLogger(__FILE__, 401, __PRETTY_FUNCTION__, QSG_LOG_RENDERLOOP().categoryName()).debug(" (RT) %s", "- setting exit flag and invalidating OpenGL");
| 0 | ||||||||||||||||||||||||
402 | invalidateOpenGL(wme->window, wme->inDestructor, wme->fallbackSurface); | - | ||||||||||||||||||||||||
403 | active = gl; | - | ||||||||||||||||||||||||
404 | Q_ASSERT_X(!wme->inDestructor || !active, "QSGRenderThread::invalidateOpenGL()", "Thread's active state is not set to false when shutting down"); | - | ||||||||||||||||||||||||
405 | if (sleeping)
| 0 | ||||||||||||||||||||||||
406 | stopEventProcessing = true; never executed: stopEventProcessing = true; | 0 | ||||||||||||||||||||||||
407 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
408 | qCDebug(QSG_LOG_RENDERLOOP, QSG_RT_PAD, "- not releasing because window is still active"); never executed: QMessageLogger(__FILE__, 408, __PRETTY_FUNCTION__, QSG_LOG_RENDERLOOP().categoryName()).debug(" (RT) %s", "- not releasing because window is still active");
| 0 | ||||||||||||||||||||||||
409 | if (window) {
| 0 | ||||||||||||||||||||||||
410 | QQuickWindowPrivate *d = QQuickWindowPrivate::get(window); | - | ||||||||||||||||||||||||
411 | if (d->renderer) {
| 0 | ||||||||||||||||||||||||
412 | qCDebug(QSG_LOG_RENDERLOOP, QSG_RT_PAD, "- requesting renderer to release cached resources"); never executed: QMessageLogger(__FILE__, 412, __PRETTY_FUNCTION__, QSG_LOG_RENDERLOOP().categoryName()).debug(" (RT) %s", "- requesting renderer to release cached resources");
| 0 | ||||||||||||||||||||||||
413 | d->renderer->releaseCachedResources(); | - | ||||||||||||||||||||||||
414 | } never executed: end of block | 0 | ||||||||||||||||||||||||
415 | } never executed: end of block | 0 | ||||||||||||||||||||||||
416 | } never executed: end of block | 0 | ||||||||||||||||||||||||
417 | waitCondition.wakeOne(); | - | ||||||||||||||||||||||||
418 | wm->m_lockedForSync = false; | - | ||||||||||||||||||||||||
419 | mutex.unlock(); | - | ||||||||||||||||||||||||
420 | return true; never executed: return true; | 0 | ||||||||||||||||||||||||
421 | } | - | ||||||||||||||||||||||||
422 | - | |||||||||||||||||||||||||
423 | case WM_Grab: { never executed: case WM_Grab: | 0 | ||||||||||||||||||||||||
424 | qCDebug(QSG_LOG_RENDERLOOP, QSG_RT_PAD, "WM_Grab"); never executed: QMessageLogger(__FILE__, 424, __PRETTY_FUNCTION__, QSG_LOG_RENDERLOOP().categoryName()).debug(" (RT) %s", "WM_Grab");
| 0 | ||||||||||||||||||||||||
425 | WMGrabEvent *ce = static_cast<WMGrabEvent *>(e); | - | ||||||||||||||||||||||||
426 | Q_ASSERT(ce->window); | - | ||||||||||||||||||||||||
427 | Q_ASSERT(ce->window == window || !window); | - | ||||||||||||||||||||||||
428 | mutex.lock(); | - | ||||||||||||||||||||||||
429 | if (ce->window) {
| 0 | ||||||||||||||||||||||||
430 | gl->makeCurrent(ce->window); | - | ||||||||||||||||||||||||
431 | - | |||||||||||||||||||||||||
432 | qCDebug(QSG_LOG_RENDERLOOP, QSG_RT_PAD, "- sync scene graph"); never executed: QMessageLogger(__FILE__, 432, __PRETTY_FUNCTION__, QSG_LOG_RENDERLOOP().categoryName()).debug(" (RT) %s", "- sync scene graph");
| 0 | ||||||||||||||||||||||||
433 | QQuickWindowPrivate *d = QQuickWindowPrivate::get(ce->window); | - | ||||||||||||||||||||||||
434 | d->syncSceneGraph(); | - | ||||||||||||||||||||||||
435 | sgrc->endSync(); | - | ||||||||||||||||||||||||
436 | - | |||||||||||||||||||||||||
437 | qCDebug(QSG_LOG_RENDERLOOP, QSG_RT_PAD, "- rendering scene graph"); never executed: QMessageLogger(__FILE__, 437, __PRETTY_FUNCTION__, QSG_LOG_RENDERLOOP().categoryName()).debug(" (RT) %s", "- rendering scene graph");
| 0 | ||||||||||||||||||||||||
438 | QQuickWindowPrivate::get(ce->window)->renderSceneGraph(ce->window->size()); | - | ||||||||||||||||||||||||
439 | - | |||||||||||||||||||||||||
440 | qCDebug(QSG_LOG_RENDERLOOP, QSG_RT_PAD, "- grabbing result"); never executed: QMessageLogger(__FILE__, 440, __PRETTY_FUNCTION__, QSG_LOG_RENDERLOOP().categoryName()).debug(" (RT) %s", "- grabbing result");
| 0 | ||||||||||||||||||||||||
441 | bool alpha = ce->window->format().alphaBufferSize() > 0 && ce->window->color().alpha() != 255;
| 0 | ||||||||||||||||||||||||
442 | *ce->image = qt_gl_read_framebuffer(windowSize * ce->window->effectiveDevicePixelRatio(), alpha, alpha); | - | ||||||||||||||||||||||||
443 | ce->image->setDevicePixelRatio(ce->window->effectiveDevicePixelRatio()); | - | ||||||||||||||||||||||||
444 | } never executed: end of block | 0 | ||||||||||||||||||||||||
445 | qCDebug(QSG_LOG_RENDERLOOP, QSG_RT_PAD, "- waking gui to handle result"); never executed: QMessageLogger(__FILE__, 445, __PRETTY_FUNCTION__, QSG_LOG_RENDERLOOP().categoryName()).debug(" (RT) %s", "- waking gui to handle result");
| 0 | ||||||||||||||||||||||||
446 | waitCondition.wakeOne(); | - | ||||||||||||||||||||||||
447 | mutex.unlock(); | - | ||||||||||||||||||||||||
448 | return true; never executed: return true; | 0 | ||||||||||||||||||||||||
449 | } | - | ||||||||||||||||||||||||
450 | - | |||||||||||||||||||||||||
451 | case WM_PostJob: { never executed: case WM_PostJob: | 0 | ||||||||||||||||||||||||
452 | qCDebug(QSG_LOG_RENDERLOOP, QSG_RT_PAD, "WM_PostJob"); never executed: QMessageLogger(__FILE__, 452, __PRETTY_FUNCTION__, QSG_LOG_RENDERLOOP().categoryName()).debug(" (RT) %s", "WM_PostJob");
| 0 | ||||||||||||||||||||||||
453 | WMJobEvent *ce = static_cast<WMJobEvent *>(e); | - | ||||||||||||||||||||||||
454 | Q_ASSERT(ce->window == window); | - | ||||||||||||||||||||||||
455 | if (window) {
| 0 | ||||||||||||||||||||||||
456 | gl->makeCurrent(window); | - | ||||||||||||||||||||||||
457 | ce->job->run(); | - | ||||||||||||||||||||||||
458 | delete ce->job; | - | ||||||||||||||||||||||||
459 | ce->job = nullptr; | - | ||||||||||||||||||||||||
460 | qCDebug(QSG_LOG_RENDERLOOP, QSG_RT_PAD, "- job done"); never executed: QMessageLogger(__FILE__, 460, __PRETTY_FUNCTION__, QSG_LOG_RENDERLOOP().categoryName()).debug(" (RT) %s", "- job done");
| 0 | ||||||||||||||||||||||||
461 | } never executed: end of block | 0 | ||||||||||||||||||||||||
462 | return true; never executed: return true; | 0 | ||||||||||||||||||||||||
463 | } | - | ||||||||||||||||||||||||
464 | - | |||||||||||||||||||||||||
465 | case WM_RequestRepaint: never executed: case WM_RequestRepaint: | 0 | ||||||||||||||||||||||||
466 | qCDebug(QSG_LOG_RENDERLOOP, QSG_RT_PAD, "WM_RequestPaint"); never executed: QMessageLogger(__FILE__, 466, __PRETTY_FUNCTION__, QSG_LOG_RENDERLOOP().categoryName()).debug(" (RT) %s", "WM_RequestPaint");
| 0 | ||||||||||||||||||||||||
467 | // When GUI posts this event, it is followed by a polishAndSync, so we mustn't | - | ||||||||||||||||||||||||
468 | // exit the event loop yet. | - | ||||||||||||||||||||||||
469 | pendingUpdate |= RepaintRequest; | - | ||||||||||||||||||||||||
470 | break; never executed: break; | 0 | ||||||||||||||||||||||||
471 | - | |||||||||||||||||||||||||
472 | default: never executed: default: | 0 | ||||||||||||||||||||||||
473 | break; never executed: break; | 0 | ||||||||||||||||||||||||
474 | } | - | ||||||||||||||||||||||||
475 | return QThread::event(e); never executed: return QThread::event(e); | 0 | ||||||||||||||||||||||||
476 | } | - | ||||||||||||||||||||||||
477 | - | |||||||||||||||||||||||||
478 | void QSGRenderThread::invalidateOpenGL(QQuickWindow *window, bool inDestructor, QOffscreenSurface *fallback) | - | ||||||||||||||||||||||||
479 | { | - | ||||||||||||||||||||||||
480 | qCDebug(QSG_LOG_RENDERLOOP, QSG_RT_PAD, "invalidateOpenGL()"); never executed: QMessageLogger(__FILE__, 480, __PRETTY_FUNCTION__, QSG_LOG_RENDERLOOP().categoryName()).debug(" (RT) %s", "invalidateOpenGL()");
| 0 | ||||||||||||||||||||||||
481 | - | |||||||||||||||||||||||||
482 | if (!gl)
| 0 | ||||||||||||||||||||||||
483 | return; never executed: return; | 0 | ||||||||||||||||||||||||
484 | - | |||||||||||||||||||||||||
485 | if (!window) {
| 0 | ||||||||||||||||||||||||
486 | qCWarning(QSG_LOG_RENDERLOOP, "QSGThreadedRenderLoop:QSGRenderThread: no window to make current..."); never executed: QMessageLogger(__FILE__, 486, __PRETTY_FUNCTION__, QSG_LOG_RENDERLOOP().categoryName()).warning("QSGThreadedRenderLoop:QSGRenderThread: no window to make current...");
| 0 | ||||||||||||||||||||||||
487 | return; never executed: return; | 0 | ||||||||||||||||||||||||
488 | } | - | ||||||||||||||||||||||||
489 | - | |||||||||||||||||||||||||
490 | - | |||||||||||||||||||||||||
491 | bool wipeSG = inDestructor || !window->isPersistentSceneGraph();
| 0 | ||||||||||||||||||||||||
492 | bool wipeGL = inDestructor || (wipeSG && !window->isPersistentOpenGLContext());
| 0 | ||||||||||||||||||||||||
493 | - | |||||||||||||||||||||||||
494 | bool current = gl->makeCurrent(fallback ? static_cast<QSurface *>(fallback) : static_cast<QSurface *>(window)); | - | ||||||||||||||||||||||||
495 | if (Q_UNLIKELY(!current)) {
| 0 | ||||||||||||||||||||||||
496 | qCDebug(QSG_LOG_RENDERLOOP, QSG_RT_PAD, "- cleanup without an OpenGL context"); never executed: QMessageLogger(__FILE__, 496, __PRETTY_FUNCTION__, QSG_LOG_RENDERLOOP().categoryName()).debug(" (RT) %s", "- cleanup without an OpenGL context");
| 0 | ||||||||||||||||||||||||
497 | } never executed: end of block | 0 | ||||||||||||||||||||||||
498 | - | |||||||||||||||||||||||||
499 | QQuickWindowPrivate *dd = QQuickWindowPrivate::get(window); | - | ||||||||||||||||||||||||
500 | - | |||||||||||||||||||||||||
501 | #if QT_CONFIG(quick_shadereffect) | - | ||||||||||||||||||||||||
502 | QQuickOpenGLShaderEffectMaterial::cleanupMaterialCache(); | - | ||||||||||||||||||||||||
503 | #endif | - | ||||||||||||||||||||||||
504 | - | |||||||||||||||||||||||||
505 | // The canvas nodes must be cleaned up regardless if we are in the destructor.. | - | ||||||||||||||||||||||||
506 | if (wipeSG) {
| 0 | ||||||||||||||||||||||||
507 | dd->cleanupNodesOnShutdown(); | - | ||||||||||||||||||||||||
508 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
509 | qCDebug(QSG_LOG_RENDERLOOP, QSG_RT_PAD, "- persistent SG, avoiding cleanup"); never executed: QMessageLogger(__FILE__, 509, __PRETTY_FUNCTION__, QSG_LOG_RENDERLOOP().categoryName()).debug(" (RT) %s", "- persistent SG, avoiding cleanup");
| 0 | ||||||||||||||||||||||||
510 | if (current)
| 0 | ||||||||||||||||||||||||
511 | gl->doneCurrent(); never executed: gl->doneCurrent(); | 0 | ||||||||||||||||||||||||
512 | return; never executed: return; | 0 | ||||||||||||||||||||||||
513 | } | - | ||||||||||||||||||||||||
514 | - | |||||||||||||||||||||||||
515 | sgrc->invalidate(); | - | ||||||||||||||||||||||||
516 | QCoreApplication::processEvents(); | - | ||||||||||||||||||||||||
517 | QCoreApplication::sendPostedEvents(nullptr, QEvent::DeferredDelete); | - | ||||||||||||||||||||||||
518 | if (inDestructor)
| 0 | ||||||||||||||||||||||||
519 | delete dd->animationController; never executed: delete dd->animationController; | 0 | ||||||||||||||||||||||||
520 | if (current)
| 0 | ||||||||||||||||||||||||
521 | gl->doneCurrent(); never executed: gl->doneCurrent(); | 0 | ||||||||||||||||||||||||
522 | qCDebug(QSG_LOG_RENDERLOOP, QSG_RT_PAD, "- invalidating scene graph"); never executed: QMessageLogger(__FILE__, 522, __PRETTY_FUNCTION__, QSG_LOG_RENDERLOOP().categoryName()).debug(" (RT) %s", "- invalidating scene graph");
| 0 | ||||||||||||||||||||||||
523 | - | |||||||||||||||||||||||||
524 | if (wipeGL) {
| 0 | ||||||||||||||||||||||||
525 | delete gl; | - | ||||||||||||||||||||||||
526 | gl = nullptr; | - | ||||||||||||||||||||||||
527 | qCDebug(QSG_LOG_RENDERLOOP, QSG_RT_PAD, "- invalidated OpenGL"); never executed: QMessageLogger(__FILE__, 527, __PRETTY_FUNCTION__, QSG_LOG_RENDERLOOP().categoryName()).debug(" (RT) %s", "- invalidated OpenGL");
| 0 | ||||||||||||||||||||||||
528 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
529 | qCDebug(QSG_LOG_RENDERLOOP, QSG_RT_PAD, "- persistent GL, avoiding cleanup"); never executed: QMessageLogger(__FILE__, 529, __PRETTY_FUNCTION__, QSG_LOG_RENDERLOOP().categoryName()).debug(" (RT) %s", "- persistent GL, avoiding cleanup");
| 0 | ||||||||||||||||||||||||
530 | } never executed: end of block | 0 | ||||||||||||||||||||||||
531 | } | - | ||||||||||||||||||||||||
532 | - | |||||||||||||||||||||||||
533 | /* | - | ||||||||||||||||||||||||
534 | Enters the mutex lock to make sure GUI is blocking and performs | - | ||||||||||||||||||||||||
535 | sync, then wakes GUI. | - | ||||||||||||||||||||||||
536 | */ | - | ||||||||||||||||||||||||
537 | void QSGRenderThread::sync(bool inExpose) | - | ||||||||||||||||||||||||
538 | { | - | ||||||||||||||||||||||||
539 | qCDebug(QSG_LOG_RENDERLOOP, QSG_RT_PAD, "sync()"); never executed: QMessageLogger(__FILE__, 539, __PRETTY_FUNCTION__, QSG_LOG_RENDERLOOP().categoryName()).debug(" (RT) %s", "sync()");
| 0 | ||||||||||||||||||||||||
540 | mutex.lock(); | - | ||||||||||||||||||||||||
541 | - | |||||||||||||||||||||||||
542 | Q_ASSERT_X(wm->m_lockedForSync, "QSGRenderThread::sync()", "sync triggered on bad terms as gui is not already locked..."); | - | ||||||||||||||||||||||||
543 | - | |||||||||||||||||||||||||
544 | bool current = false; | - | ||||||||||||||||||||||||
545 | if (windowSize.width() > 0 && windowSize.height() > 0)
| 0 | ||||||||||||||||||||||||
546 | current = gl->makeCurrent(window); never executed: current = gl->makeCurrent(window); | 0 | ||||||||||||||||||||||||
547 | // Check for context loss. | - | ||||||||||||||||||||||||
548 | if (!current && !gl->isValid()) {
| 0 | ||||||||||||||||||||||||
549 | QQuickWindowPrivate::get(window)->cleanupNodesOnShutdown(); | - | ||||||||||||||||||||||||
550 | sgrc->invalidate(); | - | ||||||||||||||||||||||||
551 | current = gl->create() && gl->makeCurrent(window);
| 0 | ||||||||||||||||||||||||
552 | if (current)
| 0 | ||||||||||||||||||||||||
553 | sgrc->initialize(gl); never executed: sgrc->initialize(gl); | 0 | ||||||||||||||||||||||||
554 | } never executed: end of block | 0 | ||||||||||||||||||||||||
555 | if (current) {
| 0 | ||||||||||||||||||||||||
556 | QQuickWindowPrivate *d = QQuickWindowPrivate::get(window); | - | ||||||||||||||||||||||||
557 | bool hadRenderer = d->renderer != nullptr; | - | ||||||||||||||||||||||||
558 | // If the scene graph was touched since the last sync() make sure it sends the | - | ||||||||||||||||||||||||
559 | // changed signal. | - | ||||||||||||||||||||||||
560 | if (d->renderer)
| 0 | ||||||||||||||||||||||||
561 | d->renderer->clearChangedFlag(); never executed: d->renderer->clearChangedFlag(); | 0 | ||||||||||||||||||||||||
562 | d->syncSceneGraph(); | - | ||||||||||||||||||||||||
563 | sgrc->endSync(); | - | ||||||||||||||||||||||||
564 | if (!hadRenderer && d->renderer) {
| 0 | ||||||||||||||||||||||||
565 | qCDebug(QSG_LOG_RENDERLOOP, QSG_RT_PAD, "- renderer was created"); never executed: QMessageLogger(__FILE__, 565, __PRETTY_FUNCTION__, QSG_LOG_RENDERLOOP().categoryName()).debug(" (RT) %s", "- renderer was created");
| 0 | ||||||||||||||||||||||||
566 | syncResultedInChanges = true; | - | ||||||||||||||||||||||||
567 | connect(d->renderer, SIGNAL(sceneGraphChanged()), this, SLOT(sceneGraphChanged()), Qt::DirectConnection); | - | ||||||||||||||||||||||||
568 | } never executed: end of block | 0 | ||||||||||||||||||||||||
569 | - | |||||||||||||||||||||||||
570 | // Process deferred deletes now, directly after the sync as | - | ||||||||||||||||||||||||
571 | // deleteLater on the GUI must now also have resulted in SG changes | - | ||||||||||||||||||||||||
572 | // and the delete is a safe operation. | - | ||||||||||||||||||||||||
573 | QCoreApplication::sendPostedEvents(nullptr, QEvent::DeferredDelete); | - | ||||||||||||||||||||||||
574 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
575 | qCDebug(QSG_LOG_RENDERLOOP, QSG_RT_PAD, "- window has bad size, sync aborted"); never executed: QMessageLogger(__FILE__, 575, __PRETTY_FUNCTION__, QSG_LOG_RENDERLOOP().categoryName()).debug(" (RT) %s", "- window has bad size, sync aborted");
| 0 | ||||||||||||||||||||||||
576 | } never executed: end of block | 0 | ||||||||||||||||||||||||
577 | - | |||||||||||||||||||||||||
578 | if (!inExpose) {
| 0 | ||||||||||||||||||||||||
579 | qCDebug(QSG_LOG_RENDERLOOP, QSG_RT_PAD, "- sync complete, waking Gui"); never executed: QMessageLogger(__FILE__, 579, __PRETTY_FUNCTION__, QSG_LOG_RENDERLOOP().categoryName()).debug(" (RT) %s", "- sync complete, waking Gui");
| 0 | ||||||||||||||||||||||||
580 | waitCondition.wakeOne(); | - | ||||||||||||||||||||||||
581 | mutex.unlock(); | - | ||||||||||||||||||||||||
582 | } never executed: end of block | 0 | ||||||||||||||||||||||||
583 | } never executed: end of block | 0 | ||||||||||||||||||||||||
584 | - | |||||||||||||||||||||||||
585 | void QSGRenderThread::syncAndRender() | - | ||||||||||||||||||||||||
586 | { | - | ||||||||||||||||||||||||
587 | bool profileFrames = QSG_LOG_TIME_RENDERLOOP().isDebugEnabled(); | - | ||||||||||||||||||||||||
588 | if (profileFrames) {
| 0 | ||||||||||||||||||||||||
589 | sinceLastTime = threadTimer.nsecsElapsed(); | - | ||||||||||||||||||||||||
590 | threadTimer.start(); | - | ||||||||||||||||||||||||
591 | } never executed: end of block | 0 | ||||||||||||||||||||||||
592 | Q_QUICK_SG_PROFILE_START(QQuickProfiler::SceneGraphRenderLoopFrame); never executed: end of block never executed: (void)0;
| 0 | ||||||||||||||||||||||||
593 | - | |||||||||||||||||||||||||
594 | QElapsedTimer waitTimer; | - | ||||||||||||||||||||||||
595 | waitTimer.start(); | - | ||||||||||||||||||||||||
596 | - | |||||||||||||||||||||||||
597 | qCDebug(QSG_LOG_RENDERLOOP, QSG_RT_PAD, "syncAndRender()"); never executed: QMessageLogger(__FILE__, 597, __PRETTY_FUNCTION__, QSG_LOG_RENDERLOOP().categoryName()).debug(" (RT) %s", "syncAndRender()");
| 0 | ||||||||||||||||||||||||
598 | - | |||||||||||||||||||||||||
599 | syncResultedInChanges = false; | - | ||||||||||||||||||||||||
600 | QQuickWindowPrivate *d = QQuickWindowPrivate::get(window); | - | ||||||||||||||||||||||||
601 | - | |||||||||||||||||||||||||
602 | bool repaintRequested = (pendingUpdate & RepaintRequest) || d->customRenderStage;
| 0 | ||||||||||||||||||||||||
603 | bool syncRequested = pendingUpdate & SyncRequest; | - | ||||||||||||||||||||||||
604 | bool exposeRequested = (pendingUpdate & ExposeRequest) == ExposeRequest; | - | ||||||||||||||||||||||||
605 | pendingUpdate = 0; | - | ||||||||||||||||||||||||
606 | - | |||||||||||||||||||||||||
607 | if (syncRequested) {
| 0 | ||||||||||||||||||||||||
608 | qCDebug(QSG_LOG_RENDERLOOP, QSG_RT_PAD, "- updatePending, doing sync"); never executed: QMessageLogger(__FILE__, 608, __PRETTY_FUNCTION__, QSG_LOG_RENDERLOOP().categoryName()).debug(" (RT) %s", "- updatePending, doing sync");
| 0 | ||||||||||||||||||||||||
609 | sync(exposeRequested); | - | ||||||||||||||||||||||||
610 | } never executed: end of block | 0 | ||||||||||||||||||||||||
611 | #ifndef QSG_NO_RENDER_TIMING | - | ||||||||||||||||||||||||
612 | if (profileFrames)
| 0 | ||||||||||||||||||||||||
613 | syncTime = threadTimer.nsecsElapsed(); never executed: syncTime = threadTimer.nsecsElapsed(); | 0 | ||||||||||||||||||||||||
614 | #endif | - | ||||||||||||||||||||||||
615 | Q_QUICK_SG_PROFILE_RECORD(QQuickProfiler::SceneGraphRenderLoopFrame, never executed: end of block never executed: (void)0 ;
| 0 | ||||||||||||||||||||||||
616 | QQuickProfiler::SceneGraphRenderLoopSync); never executed: (void)0 ; | 0 | ||||||||||||||||||||||||
617 | - | |||||||||||||||||||||||||
618 | if (!syncResultedInChanges && !repaintRequested && sgrc->isValid()) {
| 0 | ||||||||||||||||||||||||
619 | qCDebug(QSG_LOG_RENDERLOOP, QSG_RT_PAD, "- no changes, render aborted"); never executed: QMessageLogger(__FILE__, 619, __PRETTY_FUNCTION__, QSG_LOG_RENDERLOOP().categoryName()).debug(" (RT) %s", "- no changes, render aborted");
| 0 | ||||||||||||||||||||||||
620 | int waitTime = vsyncDelta - (int) waitTimer.elapsed(); | - | ||||||||||||||||||||||||
621 | if (waitTime > 0)
| 0 | ||||||||||||||||||||||||
622 | msleep(waitTime); never executed: msleep(waitTime); | 0 | ||||||||||||||||||||||||
623 | return; never executed: return; | 0 | ||||||||||||||||||||||||
624 | } | - | ||||||||||||||||||||||||
625 | - | |||||||||||||||||||||||||
626 | qCDebug(QSG_LOG_RENDERLOOP, QSG_RT_PAD, "- rendering started"); never executed: QMessageLogger(__FILE__, 626, __PRETTY_FUNCTION__, QSG_LOG_RENDERLOOP().categoryName()).debug(" (RT) %s", "- rendering started");
| 0 | ||||||||||||||||||||||||
627 | - | |||||||||||||||||||||||||
628 | - | |||||||||||||||||||||||||
629 | if (animatorDriver->isRunning()) {
| 0 | ||||||||||||||||||||||||
630 | d->animationController->lock(); | - | ||||||||||||||||||||||||
631 | animatorDriver->advance(); | - | ||||||||||||||||||||||||
632 | d->animationController->unlock(); | - | ||||||||||||||||||||||||
633 | } never executed: end of block | 0 | ||||||||||||||||||||||||
634 | - | |||||||||||||||||||||||||
635 | bool current = false; | - | ||||||||||||||||||||||||
636 | if (d->renderer && windowSize.width() > 0 && windowSize.height() > 0)
| 0 | ||||||||||||||||||||||||
637 | current = gl->makeCurrent(window); never executed: current = gl->makeCurrent(window); | 0 | ||||||||||||||||||||||||
638 | // Check for context loss. | - | ||||||||||||||||||||||||
639 | if (!current && !gl->isValid()) {
| 0 | ||||||||||||||||||||||||
640 | // Cannot do anything here because gui is not locked. Request a new | - | ||||||||||||||||||||||||
641 | // sync+render round on the gui thread and let the sync handle it. | - | ||||||||||||||||||||||||
642 | QCoreApplication::postEvent(window, new QEvent(QEvent::Type(QQuickWindowPrivate::FullUpdateRequest))); | - | ||||||||||||||||||||||||
643 | } never executed: end of block | 0 | ||||||||||||||||||||||||
644 | if (current) {
| 0 | ||||||||||||||||||||||||
645 | d->renderSceneGraph(windowSize); | - | ||||||||||||||||||||||||
646 | if (profileFrames)
| 0 | ||||||||||||||||||||||||
647 | renderTime = threadTimer.nsecsElapsed(); never executed: renderTime = threadTimer.nsecsElapsed(); | 0 | ||||||||||||||||||||||||
648 | Q_QUICK_SG_PROFILE_RECORD(QQuickProfiler::SceneGraphRenderLoopFrame, never executed: end of block never executed: (void)0 ;
| 0 | ||||||||||||||||||||||||
649 | QQuickProfiler::SceneGraphRenderLoopRender); never executed: (void)0 ; | 0 | ||||||||||||||||||||||||
650 | if (!d->customRenderStage || !d->customRenderStage->swap())
| 0 | ||||||||||||||||||||||||
651 | gl->swapBuffers(window); never executed: gl->swapBuffers(window); | 0 | ||||||||||||||||||||||||
652 | d->fireFrameSwapped(); | - | ||||||||||||||||||||||||
653 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
654 | Q_QUICK_SG_PROFILE_SKIP(QQuickProfiler::SceneGraphRenderLoopFrame, never executed: end of block never executed: (void)0 ;
| 0 | ||||||||||||||||||||||||
655 | QQuickProfiler::SceneGraphRenderLoopSync, 1); never executed: (void)0 ; | 0 | ||||||||||||||||||||||||
656 | qCDebug(QSG_LOG_RENDERLOOP, QSG_RT_PAD, "- window not ready, skipping render"); never executed: QMessageLogger(__FILE__, 656, __PRETTY_FUNCTION__, QSG_LOG_RENDERLOOP().categoryName()).debug(" (RT) %s", "- window not ready, skipping render");
| 0 | ||||||||||||||||||||||||
657 | } never executed: end of block | 0 | ||||||||||||||||||||||||
658 | - | |||||||||||||||||||||||||
659 | qCDebug(QSG_LOG_RENDERLOOP, QSG_RT_PAD, "- rendering done"); never executed: QMessageLogger(__FILE__, 659, __PRETTY_FUNCTION__, QSG_LOG_RENDERLOOP().categoryName()).debug(" (RT) %s", "- rendering done");
| 0 | ||||||||||||||||||||||||
660 | - | |||||||||||||||||||||||||
661 | // Though it would be more correct to put this block directly after | - | ||||||||||||||||||||||||
662 | // fireFrameSwapped in the if (current) branch above, we don't do | - | ||||||||||||||||||||||||
663 | // that to avoid blocking the GUI thread in the case where it | - | ||||||||||||||||||||||||
664 | // has started rendering with a bad window, causing makeCurrent to | - | ||||||||||||||||||||||||
665 | // fail or if the window has a bad size. | - | ||||||||||||||||||||||||
666 | if (exposeRequested) {
| 0 | ||||||||||||||||||||||||
667 | qCDebug(QSG_LOG_RENDERLOOP, QSG_RT_PAD, "- wake Gui after initial expose"); never executed: QMessageLogger(__FILE__, 667, __PRETTY_FUNCTION__, QSG_LOG_RENDERLOOP().categoryName()).debug(" (RT) %s", "- wake Gui after initial expose");
| 0 | ||||||||||||||||||||||||
668 | waitCondition.wakeOne(); | - | ||||||||||||||||||||||||
669 | mutex.unlock(); | - | ||||||||||||||||||||||||
670 | } never executed: end of block | 0 | ||||||||||||||||||||||||
671 | - | |||||||||||||||||||||||||
672 | qCDebug(QSG_LOG_TIME_RENDERLOOP, never executed: QMessageLogger( __FILE__ , 677 , __PRETTY_FUNCTION__, QSG_LOG_TIME_RENDERLOOP().categoryName()).debug("Frame rendered with 'threaded' renderloop in %dms, sync=%d, render=%d, swap=%d - (on render thread)", int(threadTimer.elapsed()), int((syncTime/1000000)), int((renderTime - syncTime) / 1000000), int(threadTimer.elapsed() - renderTime / 1000000)) ;
| 0 | ||||||||||||||||||||||||
673 | "Frame rendered with 'threaded' renderloop in %dms, sync=%d, render=%d, swap=%d - (on render thread)", never executed: QMessageLogger( __FILE__ , 677 , __PRETTY_FUNCTION__, QSG_LOG_TIME_RENDERLOOP().categoryName()).debug("Frame rendered with 'threaded' renderloop in %dms, sync=%d, render=%d, swap=%d - (on render thread)", int(threadTimer.elapsed()), int((syncTime/1000000)), int((renderTime - syncTime) / 1000000), int(threadTimer.elapsed() - renderTime / 1000000)) ; | 0 | ||||||||||||||||||||||||
674 | int(threadTimer.elapsed()), never executed: QMessageLogger( __FILE__ , 677 , __PRETTY_FUNCTION__, QSG_LOG_TIME_RENDERLOOP().categoryName()).debug("Frame rendered with 'threaded' renderloop in %dms, sync=%d, render=%d, swap=%d - (on render thread)", int(threadTimer.elapsed()), int((syncTime/1000000)), int((renderTime - syncTime) / 1000000), int(threadTimer.elapsed() - renderTime / 1000000)) ; | 0 | ||||||||||||||||||||||||
675 | int((syncTime/1000000)), never executed: QMessageLogger( __FILE__ , 677 , __PRETTY_FUNCTION__, QSG_LOG_TIME_RENDERLOOP().categoryName()).debug("Frame rendered with 'threaded' renderloop in %dms, sync=%d, render=%d, swap=%d - (on render thread)", int(threadTimer.elapsed()), int((syncTime/1000000)), int((renderTime - syncTime) / 1000000), int(threadTimer.elapsed() - renderTime / 1000000)) ; | 0 | ||||||||||||||||||||||||
676 | int((renderTime - syncTime) / 1000000), never executed: QMessageLogger( __FILE__ , 677 , __PRETTY_FUNCTION__, QSG_LOG_TIME_RENDERLOOP().categoryName()).debug("Frame rendered with 'threaded' renderloop in %dms, sync=%d, render=%d, swap=%d - (on render thread)", int(threadTimer.elapsed()), int((syncTime/1000000)), int((renderTime - syncTime) / 1000000), int(threadTimer.elapsed() - renderTime / 1000000)) ; | 0 | ||||||||||||||||||||||||
677 | int(threadTimer.elapsed() - renderTime / 1000000)); never executed: QMessageLogger( __FILE__ , 677 , __PRETTY_FUNCTION__, QSG_LOG_TIME_RENDERLOOP().categoryName()).debug("Frame rendered with 'threaded' renderloop in %dms, sync=%d, render=%d, swap=%d - (on render thread)", int(threadTimer.elapsed()), int((syncTime/1000000)), int((renderTime - syncTime) / 1000000), int(threadTimer.elapsed() - renderTime / 1000000)) ; | 0 | ||||||||||||||||||||||||
678 | - | |||||||||||||||||||||||||
679 | - | |||||||||||||||||||||||||
680 | Q_QUICK_SG_PROFILE_END(QQuickProfiler::SceneGraphRenderLoopFrame, never executed: end of block never executed: (void)0 ;
| 0 | ||||||||||||||||||||||||
681 | QQuickProfiler::SceneGraphRenderLoopSwap); never executed: (void)0 ; | 0 | ||||||||||||||||||||||||
682 | } | - | ||||||||||||||||||||||||
683 | - | |||||||||||||||||||||||||
684 | - | |||||||||||||||||||||||||
685 | - | |||||||||||||||||||||||||
686 | void QSGRenderThread::postEvent(QEvent *e) | - | ||||||||||||||||||||||||
687 | { | - | ||||||||||||||||||||||||
688 | eventQueue.addEvent(e); | - | ||||||||||||||||||||||||
689 | } never executed: end of block | 0 | ||||||||||||||||||||||||
690 | - | |||||||||||||||||||||||||
691 | - | |||||||||||||||||||||||||
692 | - | |||||||||||||||||||||||||
693 | void QSGRenderThread::processEvents() | - | ||||||||||||||||||||||||
694 | { | - | ||||||||||||||||||||||||
695 | qCDebug(QSG_LOG_RENDERLOOP, QSG_RT_PAD, "--- begin processEvents()"); never executed: QMessageLogger(__FILE__, 695, __PRETTY_FUNCTION__, QSG_LOG_RENDERLOOP().categoryName()).debug(" (RT) %s", "--- begin processEvents()");
| 0 | ||||||||||||||||||||||||
696 | while (eventQueue.hasMoreEvents()) {
| 0 | ||||||||||||||||||||||||
697 | QEvent *e = eventQueue.takeEvent(false); | - | ||||||||||||||||||||||||
698 | event(e); | - | ||||||||||||||||||||||||
699 | delete e; | - | ||||||||||||||||||||||||
700 | } never executed: end of block | 0 | ||||||||||||||||||||||||
701 | qCDebug(QSG_LOG_RENDERLOOP, QSG_RT_PAD, "--- done processEvents()"); never executed: QMessageLogger(__FILE__, 701, __PRETTY_FUNCTION__, QSG_LOG_RENDERLOOP().categoryName()).debug(" (RT) %s", "--- done processEvents()");
| 0 | ||||||||||||||||||||||||
702 | } never executed: end of block | 0 | ||||||||||||||||||||||||
703 | - | |||||||||||||||||||||||||
704 | void QSGRenderThread::processEventsAndWaitForMore() | - | ||||||||||||||||||||||||
705 | { | - | ||||||||||||||||||||||||
706 | qCDebug(QSG_LOG_RENDERLOOP, QSG_RT_PAD, "--- begin processEventsAndWaitForMore()"); never executed: QMessageLogger(__FILE__, 706, __PRETTY_FUNCTION__, QSG_LOG_RENDERLOOP().categoryName()).debug(" (RT) %s", "--- begin processEventsAndWaitForMore()");
| 0 | ||||||||||||||||||||||||
707 | stopEventProcessing = false; | - | ||||||||||||||||||||||||
708 | while (!stopEventProcessing) {
| 0 | ||||||||||||||||||||||||
709 | QEvent *e = eventQueue.takeEvent(true); | - | ||||||||||||||||||||||||
710 | event(e); | - | ||||||||||||||||||||||||
711 | delete e; | - | ||||||||||||||||||||||||
712 | } never executed: end of block | 0 | ||||||||||||||||||||||||
713 | qCDebug(QSG_LOG_RENDERLOOP, QSG_RT_PAD, "--- done processEventsAndWaitForMore()"); never executed: QMessageLogger(__FILE__, 713, __PRETTY_FUNCTION__, QSG_LOG_RENDERLOOP().categoryName()).debug(" (RT) %s", "--- done processEventsAndWaitForMore()");
| 0 | ||||||||||||||||||||||||
714 | } never executed: end of block | 0 | ||||||||||||||||||||||||
715 | - | |||||||||||||||||||||||||
716 | void QSGRenderThread::run() | - | ||||||||||||||||||||||||
717 | { | - | ||||||||||||||||||||||||
718 | qCDebug(QSG_LOG_RENDERLOOP, QSG_RT_PAD, "run()"); never executed: QMessageLogger(__FILE__, 718, __PRETTY_FUNCTION__, QSG_LOG_RENDERLOOP().categoryName()).debug(" (RT) %s", "run()");
| 0 | ||||||||||||||||||||||||
719 | animatorDriver = sgrc->sceneGraphContext()->createAnimationDriver(nullptr); | - | ||||||||||||||||||||||||
720 | animatorDriver->install(); | - | ||||||||||||||||||||||||
721 | if (QQmlDebugConnector::service<QQmlProfilerService>())
| 0 | ||||||||||||||||||||||||
722 | QQuickProfiler::registerAnimationCallback(); never executed: QQuickProfiler::registerAnimationCallback(); | 0 | ||||||||||||||||||||||||
723 | - | |||||||||||||||||||||||||
724 | while (active) {
| 0 | ||||||||||||||||||||||||
725 | - | |||||||||||||||||||||||||
726 | if (window) {
| 0 | ||||||||||||||||||||||||
727 | if (!sgrc->openglContext() && windowSize.width() > 0 && windowSize.height() > 0 && gl->makeCurrent(window))
| 0 | ||||||||||||||||||||||||
728 | sgrc->initialize(gl); never executed: sgrc->initialize(gl); | 0 | ||||||||||||||||||||||||
729 | syncAndRender(); | - | ||||||||||||||||||||||||
730 | } never executed: end of block | 0 | ||||||||||||||||||||||||
731 | - | |||||||||||||||||||||||||
732 | processEvents(); | - | ||||||||||||||||||||||||
733 | QCoreApplication::processEvents(); | - | ||||||||||||||||||||||||
734 | - | |||||||||||||||||||||||||
735 | if (active && (pendingUpdate == 0 || !window)) {
| 0 | ||||||||||||||||||||||||
736 | qCDebug(QSG_LOG_RENDERLOOP, QSG_RT_PAD, "done drawing, sleep..."); never executed: QMessageLogger(__FILE__, 736, __PRETTY_FUNCTION__, QSG_LOG_RENDERLOOP().categoryName()).debug(" (RT) %s", "done drawing, sleep...");
| 0 | ||||||||||||||||||||||||
737 | sleeping = true; | - | ||||||||||||||||||||||||
738 | processEventsAndWaitForMore(); | - | ||||||||||||||||||||||||
739 | sleeping = false; | - | ||||||||||||||||||||||||
740 | } never executed: end of block | 0 | ||||||||||||||||||||||||
741 | } never executed: end of block | 0 | ||||||||||||||||||||||||
742 | - | |||||||||||||||||||||||||
743 | Q_ASSERT_X(!gl, "QSGRenderThread::run()", "The OpenGL context should be cleaned up before exiting the render thread..."); | - | ||||||||||||||||||||||||
744 | - | |||||||||||||||||||||||||
745 | qCDebug(QSG_LOG_RENDERLOOP, QSG_RT_PAD, "run() completed"); never executed: QMessageLogger(__FILE__, 745, __PRETTY_FUNCTION__, QSG_LOG_RENDERLOOP().categoryName()).debug(" (RT) %s", "run() completed");
| 0 | ||||||||||||||||||||||||
746 | - | |||||||||||||||||||||||||
747 | delete animatorDriver; | - | ||||||||||||||||||||||||
748 | animatorDriver = nullptr; | - | ||||||||||||||||||||||||
749 | - | |||||||||||||||||||||||||
750 | sgrc->moveToThread(wm->thread()); | - | ||||||||||||||||||||||||
751 | moveToThread(wm->thread()); | - | ||||||||||||||||||||||||
752 | } never executed: end of block | 0 | ||||||||||||||||||||||||
753 | - | |||||||||||||||||||||||||
754 | QSGThreadedRenderLoop::QSGThreadedRenderLoop() | - | ||||||||||||||||||||||||
755 | : sg(QSGContext::createDefaultContext()) | - | ||||||||||||||||||||||||
756 | , m_animation_timer(0) | - | ||||||||||||||||||||||||
757 | { | - | ||||||||||||||||||||||||
758 | #if defined(QSG_RENDER_LOOP_DEBUG) | - | ||||||||||||||||||||||||
759 | qsgrl_timer.start(); | - | ||||||||||||||||||||||||
760 | #endif | - | ||||||||||||||||||||||||
761 | - | |||||||||||||||||||||||||
762 | m_animation_driver = sg->createAnimationDriver(this); | - | ||||||||||||||||||||||||
763 | - | |||||||||||||||||||||||||
764 | connect(m_animation_driver, SIGNAL(started()), this, SLOT(animationStarted())); | - | ||||||||||||||||||||||||
765 | connect(m_animation_driver, SIGNAL(stopped()), this, SLOT(animationStopped())); | - | ||||||||||||||||||||||||
766 | - | |||||||||||||||||||||||||
767 | m_animation_driver->install(); | - | ||||||||||||||||||||||||
768 | } never executed: end of block | 0 | ||||||||||||||||||||||||
769 | - | |||||||||||||||||||||||||
770 | QSGThreadedRenderLoop::~QSGThreadedRenderLoop() | - | ||||||||||||||||||||||||
771 | { | - | ||||||||||||||||||||||||
772 | delete sg; | - | ||||||||||||||||||||||||
773 | } never executed: end of block | 0 | ||||||||||||||||||||||||
774 | - | |||||||||||||||||||||||||
775 | QSGRenderContext *QSGThreadedRenderLoop::createRenderContext(QSGContext *sg) const | - | ||||||||||||||||||||||||
776 | { | - | ||||||||||||||||||||||||
777 | return sg->createRenderContext(); never executed: return sg->createRenderContext(); | 0 | ||||||||||||||||||||||||
778 | } | - | ||||||||||||||||||||||||
779 | - | |||||||||||||||||||||||||
780 | void QSGThreadedRenderLoop::maybePostPolishRequest(Window *w) | - | ||||||||||||||||||||||||
781 | { | - | ||||||||||||||||||||||||
782 | w->window->requestUpdate(); | - | ||||||||||||||||||||||||
783 | } never executed: end of block | 0 | ||||||||||||||||||||||||
784 | - | |||||||||||||||||||||||||
785 | QAnimationDriver *QSGThreadedRenderLoop::animationDriver() const | - | ||||||||||||||||||||||||
786 | { | - | ||||||||||||||||||||||||
787 | return m_animation_driver; never executed: return m_animation_driver; | 0 | ||||||||||||||||||||||||
788 | } | - | ||||||||||||||||||||||||
789 | - | |||||||||||||||||||||||||
790 | QSGContext *QSGThreadedRenderLoop::sceneGraphContext() const | - | ||||||||||||||||||||||||
791 | { | - | ||||||||||||||||||||||||
792 | return sg; never executed: return sg; | 0 | ||||||||||||||||||||||||
793 | } | - | ||||||||||||||||||||||||
794 | - | |||||||||||||||||||||||||
795 | bool QSGThreadedRenderLoop::anyoneShowing() const | - | ||||||||||||||||||||||||
796 | { | - | ||||||||||||||||||||||||
797 | for (int i=0; i<m_windows.size(); ++i) {
| 0 | ||||||||||||||||||||||||
798 | QQuickWindow *c = m_windows.at(i).window; | - | ||||||||||||||||||||||||
799 | if (c->isVisible() && c->isExposed())
| 0 | ||||||||||||||||||||||||
800 | return true; never executed: return true; | 0 | ||||||||||||||||||||||||
801 | } never executed: end of block | 0 | ||||||||||||||||||||||||
802 | return false; never executed: return false; | 0 | ||||||||||||||||||||||||
803 | } | - | ||||||||||||||||||||||||
804 | - | |||||||||||||||||||||||||
805 | bool QSGThreadedRenderLoop::interleaveIncubation() const | - | ||||||||||||||||||||||||
806 | { | - | ||||||||||||||||||||||||
807 | return m_animation_driver->isRunning() && anyoneShowing(); never executed: return m_animation_driver->isRunning() && anyoneShowing(); | 0 | ||||||||||||||||||||||||
808 | } | - | ||||||||||||||||||||||||
809 | - | |||||||||||||||||||||||||
810 | void QSGThreadedRenderLoop::animationStarted() | - | ||||||||||||||||||||||||
811 | { | - | ||||||||||||||||||||||||
812 | qCDebug(QSG_LOG_RENDERLOOP, "- animationStarted()"); never executed: QMessageLogger(__FILE__, 812, __PRETTY_FUNCTION__, QSG_LOG_RENDERLOOP().categoryName()).debug("- animationStarted()");
| 0 | ||||||||||||||||||||||||
813 | startOrStopAnimationTimer(); | - | ||||||||||||||||||||||||
814 | - | |||||||||||||||||||||||||
815 | for (int i=0; i<m_windows.size(); ++i)
| 0 | ||||||||||||||||||||||||
816 | maybePostPolishRequest(const_cast<Window *>(&m_windows.at(i))); never executed: maybePostPolishRequest(const_cast<Window *>(&m_windows.at(i))); | 0 | ||||||||||||||||||||||||
817 | } never executed: end of block | 0 | ||||||||||||||||||||||||
818 | - | |||||||||||||||||||||||||
819 | void QSGThreadedRenderLoop::animationStopped() | - | ||||||||||||||||||||||||
820 | { | - | ||||||||||||||||||||||||
821 | qCDebug(QSG_LOG_RENDERLOOP, "- animationStopped()"); never executed: QMessageLogger(__FILE__, 821, __PRETTY_FUNCTION__, QSG_LOG_RENDERLOOP().categoryName()).debug("- animationStopped()");
| 0 | ||||||||||||||||||||||||
822 | startOrStopAnimationTimer(); | - | ||||||||||||||||||||||||
823 | } never executed: end of block | 0 | ||||||||||||||||||||||||
824 | - | |||||||||||||||||||||||||
825 | - | |||||||||||||||||||||||||
826 | void QSGThreadedRenderLoop::startOrStopAnimationTimer() | - | ||||||||||||||||||||||||
827 | { | - | ||||||||||||||||||||||||
828 | int exposedWindows = 0; | - | ||||||||||||||||||||||||
829 | const Window *theOne = nullptr; | - | ||||||||||||||||||||||||
830 | for (int i=0; i<m_windows.size(); ++i) {
| 0 | ||||||||||||||||||||||||
831 | const Window &w = m_windows.at(i); | - | ||||||||||||||||||||||||
832 | if (w.window->isVisible() && w.window->isExposed()) {
| 0 | ||||||||||||||||||||||||
833 | ++exposedWindows; | - | ||||||||||||||||||||||||
834 | theOne = &w; | - | ||||||||||||||||||||||||
835 | } never executed: end of block | 0 | ||||||||||||||||||||||||
836 | } never executed: end of block | 0 | ||||||||||||||||||||||||
837 | - | |||||||||||||||||||||||||
838 | if (m_animation_timer != 0 && (exposedWindows == 1 || !m_animation_driver->isRunning())) {
| 0 | ||||||||||||||||||||||||
839 | qCDebug(QSG_LOG_RENDERLOOP, "*** Stopping animation timer"); never executed: QMessageLogger(__FILE__, 839, __PRETTY_FUNCTION__, QSG_LOG_RENDERLOOP().categoryName()).debug("*** Stopping animation timer");
| 0 | ||||||||||||||||||||||||
840 | killTimer(m_animation_timer); | - | ||||||||||||||||||||||||
841 | m_animation_timer = 0; | - | ||||||||||||||||||||||||
842 | // If animations are running, make sure we keep on animating | - | ||||||||||||||||||||||||
843 | if (m_animation_driver->isRunning())
| 0 | ||||||||||||||||||||||||
844 | maybePostPolishRequest(const_cast<Window *>(theOne)); never executed: maybePostPolishRequest(const_cast<Window *>(theOne)); | 0 | ||||||||||||||||||||||||
845 | } else if (m_animation_timer == 0 && exposedWindows != 1 && m_animation_driver->isRunning()) { never executed: end of block
| 0 | ||||||||||||||||||||||||
846 | qCDebug(QSG_LOG_RENDERLOOP, "*** Starting animation timer"); never executed: QMessageLogger(__FILE__, 846, __PRETTY_FUNCTION__, QSG_LOG_RENDERLOOP().categoryName()).debug("*** Starting animation timer");
| 0 | ||||||||||||||||||||||||
847 | m_animation_timer = startTimer(qsgrl_animation_interval()); | - | ||||||||||||||||||||||||
848 | } never executed: end of block | 0 | ||||||||||||||||||||||||
849 | } never executed: end of block | 0 | ||||||||||||||||||||||||
850 | - | |||||||||||||||||||||||||
851 | /* | - | ||||||||||||||||||||||||
852 | Removes this window from the list of tracked windowes in this | - | ||||||||||||||||||||||||
853 | window manager. hide() will trigger obscure, which in turn will | - | ||||||||||||||||||||||||
854 | stop rendering. | - | ||||||||||||||||||||||||
855 | - | |||||||||||||||||||||||||
856 | This function will be called during QWindow::close() which will | - | ||||||||||||||||||||||||
857 | also destroy the QPlatformWindow so it is important that this | - | ||||||||||||||||||||||||
858 | triggers handleObscurity() and that rendering for that window | - | ||||||||||||||||||||||||
859 | is fully done and over with by the time this function exits. | - | ||||||||||||||||||||||||
860 | */ | - | ||||||||||||||||||||||||
861 | - | |||||||||||||||||||||||||
862 | void QSGThreadedRenderLoop::hide(QQuickWindow *window) | - | ||||||||||||||||||||||||
863 | { | - | ||||||||||||||||||||||||
864 | qCDebug(QSG_LOG_RENDERLOOP) << "hide()" << window; never executed: QMessageLogger(__FILE__, 864, __PRETTY_FUNCTION__, QSG_LOG_RENDERLOOP().categoryName()).debug() << "hide()" << window;
| 0 | ||||||||||||||||||||||||
865 | - | |||||||||||||||||||||||||
866 | if (window->isExposed())
| 0 | ||||||||||||||||||||||||
867 | handleObscurity(windowFor(m_windows, window)); never executed: handleObscurity(windowFor(m_windows, window)); | 0 | ||||||||||||||||||||||||
868 | - | |||||||||||||||||||||||||
869 | releaseResources(window); | - | ||||||||||||||||||||||||
870 | } never executed: end of block | 0 | ||||||||||||||||||||||||
871 | - | |||||||||||||||||||||||||
872 | - | |||||||||||||||||||||||||
873 | /* | - | ||||||||||||||||||||||||
874 | If the window is first hide it, then perform a complete cleanup | - | ||||||||||||||||||||||||
875 | with releaseResources which will take down the GL context and | - | ||||||||||||||||||||||||
876 | exit the rendering thread. | - | ||||||||||||||||||||||||
877 | */ | - | ||||||||||||||||||||||||
878 | void QSGThreadedRenderLoop::windowDestroyed(QQuickWindow *window) | - | ||||||||||||||||||||||||
879 | { | - | ||||||||||||||||||||||||
880 | qCDebug(QSG_LOG_RENDERLOOP) << "begin windowDestroyed()" << window; never executed: QMessageLogger(__FILE__, 880, __PRETTY_FUNCTION__, QSG_LOG_RENDERLOOP().categoryName()).debug() << "begin windowDestroyed()" << window;
| 0 | ||||||||||||||||||||||||
881 | - | |||||||||||||||||||||||||
882 | Window *w = windowFor(m_windows, window); | - | ||||||||||||||||||||||||
883 | if (!w)
| 0 | ||||||||||||||||||||||||
884 | return; never executed: return; | 0 | ||||||||||||||||||||||||
885 | - | |||||||||||||||||||||||||
886 | handleObscurity(w); | - | ||||||||||||||||||||||||
887 | releaseResources(w, true); | - | ||||||||||||||||||||||||
888 | - | |||||||||||||||||||||||||
889 | QSGRenderThread *thread = w->thread; | - | ||||||||||||||||||||||||
890 | while (thread->isRunning())
| 0 | ||||||||||||||||||||||||
891 | QThread::yieldCurrentThread(); never executed: QThread::yieldCurrentThread(); | 0 | ||||||||||||||||||||||||
892 | Q_ASSERT(thread->thread() == QThread::currentThread()); | - | ||||||||||||||||||||||||
893 | delete thread; | - | ||||||||||||||||||||||||
894 | - | |||||||||||||||||||||||||
895 | for (int i=0; i<m_windows.size(); ++i) {
| 0 | ||||||||||||||||||||||||
896 | if (m_windows.at(i).window == window) {
| 0 | ||||||||||||||||||||||||
897 | m_windows.removeAt(i); | - | ||||||||||||||||||||||||
898 | break; never executed: break; | 0 | ||||||||||||||||||||||||
899 | } | - | ||||||||||||||||||||||||
900 | } never executed: end of block | 0 | ||||||||||||||||||||||||
901 | - | |||||||||||||||||||||||||
902 | // Now that we altered the window list, we may need to stop the animation | - | ||||||||||||||||||||||||
903 | // timer even if we didn't via handleObscurity. This covers the case where | - | ||||||||||||||||||||||||
904 | // we destroy a visible & exposed QQuickWindow. | - | ||||||||||||||||||||||||
905 | startOrStopAnimationTimer(); | - | ||||||||||||||||||||||||
906 | - | |||||||||||||||||||||||||
907 | qCDebug(QSG_LOG_RENDERLOOP) << "done windowDestroyed()" << window; never executed: QMessageLogger(__FILE__, 907, __PRETTY_FUNCTION__, QSG_LOG_RENDERLOOP().categoryName()).debug() << "done windowDestroyed()" << window;
| 0 | ||||||||||||||||||||||||
908 | } never executed: end of block | 0 | ||||||||||||||||||||||||
909 | - | |||||||||||||||||||||||||
910 | - | |||||||||||||||||||||||||
911 | void QSGThreadedRenderLoop::exposureChanged(QQuickWindow *window) | - | ||||||||||||||||||||||||
912 | { | - | ||||||||||||||||||||||||
913 | qCDebug(QSG_LOG_RENDERLOOP) << "exposureChanged()" << window; never executed: QMessageLogger(__FILE__, 913, __PRETTY_FUNCTION__, QSG_LOG_RENDERLOOP().categoryName()).debug() << "exposureChanged()" << window;
| 0 | ||||||||||||||||||||||||
914 | if (window->isExposed()) {
| 0 | ||||||||||||||||||||||||
915 | handleExposure(window); | - | ||||||||||||||||||||||||
916 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
917 | Window *w = windowFor(m_windows, window); | - | ||||||||||||||||||||||||
918 | if (w)
| 0 | ||||||||||||||||||||||||
919 | handleObscurity(w); never executed: handleObscurity(w); | 0 | ||||||||||||||||||||||||
920 | } never executed: end of block | 0 | ||||||||||||||||||||||||
921 | } | - | ||||||||||||||||||||||||
922 | - | |||||||||||||||||||||||||
923 | /* | - | ||||||||||||||||||||||||
924 | Will post an event to the render thread that this window should | - | ||||||||||||||||||||||||
925 | start to render. | - | ||||||||||||||||||||||||
926 | */ | - | ||||||||||||||||||||||||
927 | void QSGThreadedRenderLoop::handleExposure(QQuickWindow *window) | - | ||||||||||||||||||||||||
928 | { | - | ||||||||||||||||||||||||
929 | qCDebug(QSG_LOG_RENDERLOOP) << "handleExposure()" << window; never executed: QMessageLogger(__FILE__, 929, __PRETTY_FUNCTION__, QSG_LOG_RENDERLOOP().categoryName()).debug() << "handleExposure()" << window;
| 0 | ||||||||||||||||||||||||
930 | - | |||||||||||||||||||||||||
931 | Window *w = windowFor(m_windows, window); | - | ||||||||||||||||||||||||
932 | if (!w) {
| 0 | ||||||||||||||||||||||||
933 | qCDebug(QSG_LOG_RENDERLOOP, "- adding window to list"); never executed: QMessageLogger(__FILE__, 933, __PRETTY_FUNCTION__, QSG_LOG_RENDERLOOP().categoryName()).debug("- adding window to list");
| 0 | ||||||||||||||||||||||||
934 | Window win; | - | ||||||||||||||||||||||||
935 | win.window = window; | - | ||||||||||||||||||||||||
936 | win.actualWindowFormat = window->format(); | - | ||||||||||||||||||||||||
937 | win.thread = new QSGRenderThread(this, QQuickWindowPrivate::get(window)->context); | - | ||||||||||||||||||||||||
938 | win.updateDuringSync = false; | - | ||||||||||||||||||||||||
939 | win.forceRenderPass = true; // also covered by polishAndSync(inExpose=true), but doesn't hurt | - | ||||||||||||||||||||||||
940 | m_windows << win; | - | ||||||||||||||||||||||||
941 | w = &m_windows.last(); | - | ||||||||||||||||||||||||
942 | } never executed: end of block | 0 | ||||||||||||||||||||||||
943 | - | |||||||||||||||||||||||||
944 | // set this early as we'll be rendering shortly anyway and this avoids | - | ||||||||||||||||||||||||
945 | // specialcasing exposure in polishAndSync. | - | ||||||||||||||||||||||||
946 | w->thread->window = window; | - | ||||||||||||||||||||||||
947 | - | |||||||||||||||||||||||||
948 | if (w->window->width() <= 0 || w->window->height() <= 0
| 0 | ||||||||||||||||||||||||
949 | || (w->window->isTopLevel() && !w->window->geometry().intersects(w->window->screen()->availableGeometry()))) {
| 0 | ||||||||||||||||||||||||
950 | #ifndef QT_NO_DEBUG | - | ||||||||||||||||||||||||
951 | qWarning().noquote().nospace() << "QSGThreadedRenderLoop: expose event received for window " | - | ||||||||||||||||||||||||
952 | << w->window << " with invalid geometry: " << w->window->geometry() | - | ||||||||||||||||||||||||
953 | << " on " << w->window->screen(); | - | ||||||||||||||||||||||||
954 | #endif | - | ||||||||||||||||||||||||
955 | } never executed: end of block | 0 | ||||||||||||||||||||||||
956 | - | |||||||||||||||||||||||||
957 | // Because we are going to bind a GL context to it, make sure it | - | ||||||||||||||||||||||||
958 | // is created. | - | ||||||||||||||||||||||||
959 | if (!w->window->handle())
| 0 | ||||||||||||||||||||||||
960 | w->window->create(); never executed: w->window->create(); | 0 | ||||||||||||||||||||||||
961 | - | |||||||||||||||||||||||||
962 | // Start render thread if it is not running | - | ||||||||||||||||||||||||
963 | if (!w->thread->isRunning()) {
| 0 | ||||||||||||||||||||||||
964 | - | |||||||||||||||||||||||||
965 | qCDebug(QSG_LOG_RENDERLOOP, "- starting render thread"); never executed: QMessageLogger(__FILE__, 965, __PRETTY_FUNCTION__, QSG_LOG_RENDERLOOP().categoryName()).debug("- starting render thread");
| 0 | ||||||||||||||||||||||||
966 | - | |||||||||||||||||||||||||
967 | if (!w->thread->gl) {
| 0 | ||||||||||||||||||||||||
968 | w->thread->gl = new QOpenGLContext(); | - | ||||||||||||||||||||||||
969 | if (qt_gl_global_share_context())
| 0 | ||||||||||||||||||||||||
970 | w->thread->gl->setShareContext(qt_gl_global_share_context()); never executed: w->thread->gl->setShareContext(qt_gl_global_share_context()); | 0 | ||||||||||||||||||||||||
971 | w->thread->gl->setFormat(w->window->requestedFormat()); | - | ||||||||||||||||||||||||
972 | w->thread->gl->setScreen(w->window->screen()); | - | ||||||||||||||||||||||||
973 | if (!w->thread->gl->create()) {
| 0 | ||||||||||||||||||||||||
974 | const bool isEs = w->thread->gl->isOpenGLES(); | - | ||||||||||||||||||||||||
975 | delete w->thread->gl; | - | ||||||||||||||||||||||||
976 | w->thread->gl = nullptr; | - | ||||||||||||||||||||||||
977 | handleContextCreationFailure(w->window, isEs); | - | ||||||||||||||||||||||||
978 | return; never executed: return; | 0 | ||||||||||||||||||||||||
979 | } | - | ||||||||||||||||||||||||
980 | - | |||||||||||||||||||||||||
981 | QQuickWindowPrivate::get(w->window)->fireOpenGLContextCreated(w->thread->gl); | - | ||||||||||||||||||||||||
982 | - | |||||||||||||||||||||||||
983 | w->thread->gl->moveToThread(w->thread); | - | ||||||||||||||||||||||||
984 | qCDebug(QSG_LOG_RENDERLOOP, "- OpenGL context created"); never executed: QMessageLogger(__FILE__, 984, __PRETTY_FUNCTION__, QSG_LOG_RENDERLOOP().categoryName()).debug("- OpenGL context created");
| 0 | ||||||||||||||||||||||||
985 | } never executed: end of block | 0 | ||||||||||||||||||||||||
986 | - | |||||||||||||||||||||||||
987 | QQuickAnimatorController *controller = QQuickWindowPrivate::get(w->window)->animationController; | - | ||||||||||||||||||||||||
988 | if (controller->thread() != w->thread)
| 0 | ||||||||||||||||||||||||
989 | controller->moveToThread(w->thread); never executed: controller->moveToThread(w->thread); | 0 | ||||||||||||||||||||||||
990 | - | |||||||||||||||||||||||||
991 | w->thread->active = true; | - | ||||||||||||||||||||||||
992 | if (w->thread->thread() == QThread::currentThread()) {
| 0 | ||||||||||||||||||||||||
993 | w->thread->sgrc->moveToThread(w->thread); | - | ||||||||||||||||||||||||
994 | w->thread->moveToThread(w->thread); | - | ||||||||||||||||||||||||
995 | } never executed: end of block | 0 | ||||||||||||||||||||||||
996 | w->thread->start(); | - | ||||||||||||||||||||||||
997 | if (!w->thread->isRunning())
| 0 | ||||||||||||||||||||||||
998 | qFatal("Render thread failed to start, aborting application."); never executed: QMessageLogger(__FILE__, 998, __PRETTY_FUNCTION__).fatal("Render thread failed to start, aborting application."); | 0 | ||||||||||||||||||||||||
999 | - | |||||||||||||||||||||||||
1000 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
1001 | qCDebug(QSG_LOG_RENDERLOOP, "- render thread already running"); never executed: QMessageLogger(__FILE__, 1001, __PRETTY_FUNCTION__, QSG_LOG_RENDERLOOP().categoryName()).debug("- render thread already running");
| 0 | ||||||||||||||||||||||||
1002 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1003 | - | |||||||||||||||||||||||||
1004 | polishAndSync(w, true); | - | ||||||||||||||||||||||||
1005 | qCDebug(QSG_LOG_RENDERLOOP, "- done with handleExposure()"); never executed: QMessageLogger(__FILE__, 1005, __PRETTY_FUNCTION__, QSG_LOG_RENDERLOOP().categoryName()).debug("- done with handleExposure()");
| 0 | ||||||||||||||||||||||||
1006 | - | |||||||||||||||||||||||||
1007 | startOrStopAnimationTimer(); | - | ||||||||||||||||||||||||
1008 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1009 | - | |||||||||||||||||||||||||
1010 | /* | - | ||||||||||||||||||||||||
1011 | This function posts an event to the render thread to remove the window | - | ||||||||||||||||||||||||
1012 | from the list of windowses to render. | - | ||||||||||||||||||||||||
1013 | - | |||||||||||||||||||||||||
1014 | It also starts up the non-vsync animation tick if no more windows | - | ||||||||||||||||||||||||
1015 | are showing. | - | ||||||||||||||||||||||||
1016 | */ | - | ||||||||||||||||||||||||
1017 | void QSGThreadedRenderLoop::handleObscurity(Window *w) | - | ||||||||||||||||||||||||
1018 | { | - | ||||||||||||||||||||||||
1019 | qCDebug(QSG_LOG_RENDERLOOP) << "handleObscurity()" << w->window; never executed: QMessageLogger(__FILE__, 1019, __PRETTY_FUNCTION__, QSG_LOG_RENDERLOOP().categoryName()).debug() << "handleObscurity()" << w->window;
| 0 | ||||||||||||||||||||||||
1020 | if (w->thread->isRunning()) {
| 0 | ||||||||||||||||||||||||
1021 | w->thread->mutex.lock(); | - | ||||||||||||||||||||||||
1022 | w->thread->postEvent(new WMWindowEvent(w->window, WM_Obscure)); | - | ||||||||||||||||||||||||
1023 | w->thread->waitCondition.wait(&w->thread->mutex); | - | ||||||||||||||||||||||||
1024 | w->thread->mutex.unlock(); | - | ||||||||||||||||||||||||
1025 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1026 | startOrStopAnimationTimer(); | - | ||||||||||||||||||||||||
1027 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1028 | - | |||||||||||||||||||||||||
1029 | - | |||||||||||||||||||||||||
1030 | void QSGThreadedRenderLoop::handleUpdateRequest(QQuickWindow *window) | - | ||||||||||||||||||||||||
1031 | { | - | ||||||||||||||||||||||||
1032 | qCDebug(QSG_LOG_RENDERLOOP, "- polish and sync update request"); never executed: QMessageLogger(__FILE__, 1032, __PRETTY_FUNCTION__, QSG_LOG_RENDERLOOP().categoryName()).debug("- polish and sync update request");
| 0 | ||||||||||||||||||||||||
1033 | Window *w = windowFor(m_windows, window); | - | ||||||||||||||||||||||||
1034 | if (w)
| 0 | ||||||||||||||||||||||||
1035 | polishAndSync(w); never executed: polishAndSync(w); | 0 | ||||||||||||||||||||||||
1036 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1037 | - | |||||||||||||||||||||||||
1038 | void QSGThreadedRenderLoop::maybeUpdate(QQuickWindow *window) | - | ||||||||||||||||||||||||
1039 | { | - | ||||||||||||||||||||||||
1040 | Window *w = windowFor(m_windows, window); | - | ||||||||||||||||||||||||
1041 | if (w)
| 0 | ||||||||||||||||||||||||
1042 | maybeUpdate(w); never executed: maybeUpdate(w); | 0 | ||||||||||||||||||||||||
1043 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1044 | - | |||||||||||||||||||||||||
1045 | /* | - | ||||||||||||||||||||||||
1046 | Called whenever the QML scene has changed. Will post an event to | - | ||||||||||||||||||||||||
1047 | ourselves that a sync is needed. | - | ||||||||||||||||||||||||
1048 | */ | - | ||||||||||||||||||||||||
1049 | void QSGThreadedRenderLoop::maybeUpdate(Window *w) | - | ||||||||||||||||||||||||
1050 | { | - | ||||||||||||||||||||||||
1051 | if (!QCoreApplication::instance())
| 0 | ||||||||||||||||||||||||
1052 | return; never executed: return; | 0 | ||||||||||||||||||||||||
1053 | - | |||||||||||||||||||||||||
1054 | if (!w || !w->thread->isRunning())
| 0 | ||||||||||||||||||||||||
1055 | return; never executed: return; | 0 | ||||||||||||||||||||||||
1056 | - | |||||||||||||||||||||||||
1057 | QThread *current = QThread::currentThread(); | - | ||||||||||||||||||||||||
1058 | if (current != QCoreApplication::instance()->thread() && (current != w->thread || !m_lockedForSync)) {
| 0 | ||||||||||||||||||||||||
1059 | qWarning() << "Updates can only be scheduled from GUI thread or from QQuickItem::updatePaintNode()"; | - | ||||||||||||||||||||||||
1060 | return; never executed: return; | 0 | ||||||||||||||||||||||||
1061 | } | - | ||||||||||||||||||||||||
1062 | - | |||||||||||||||||||||||||
1063 | qCDebug(QSG_LOG_RENDERLOOP) << "update from item" << w->window; never executed: QMessageLogger(__FILE__, 1063, __PRETTY_FUNCTION__, QSG_LOG_RENDERLOOP().categoryName()).debug() << "update from item" << w->window;
| 0 | ||||||||||||||||||||||||
1064 | - | |||||||||||||||||||||||||
1065 | // Call this function from the Gui thread later as startTimer cannot be | - | ||||||||||||||||||||||||
1066 | // called from the render thread. | - | ||||||||||||||||||||||||
1067 | if (current == w->thread) {
| 0 | ||||||||||||||||||||||||
1068 | qCDebug(QSG_LOG_RENDERLOOP, "- on render thread"); never executed: QMessageLogger(__FILE__, 1068, __PRETTY_FUNCTION__, QSG_LOG_RENDERLOOP().categoryName()).debug("- on render thread");
| 0 | ||||||||||||||||||||||||
1069 | w->updateDuringSync = true; | - | ||||||||||||||||||||||||
1070 | return; never executed: return; | 0 | ||||||||||||||||||||||||
1071 | } | - | ||||||||||||||||||||||||
1072 | - | |||||||||||||||||||||||||
1073 | maybePostPolishRequest(w); | - | ||||||||||||||||||||||||
1074 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1075 | - | |||||||||||||||||||||||||
1076 | /* | - | ||||||||||||||||||||||||
1077 | Called when the QQuickWindow should be explicitly repainted. This function | - | ||||||||||||||||||||||||
1078 | can also be called on the render thread when the GUI thread is blocked to | - | ||||||||||||||||||||||||
1079 | keep render thread animations alive. | - | ||||||||||||||||||||||||
1080 | */ | - | ||||||||||||||||||||||||
1081 | void QSGThreadedRenderLoop::update(QQuickWindow *window) | - | ||||||||||||||||||||||||
1082 | { | - | ||||||||||||||||||||||||
1083 | Window *w = windowFor(m_windows, window); | - | ||||||||||||||||||||||||
1084 | if (!w)
| 0 | ||||||||||||||||||||||||
1085 | return; never executed: return; | 0 | ||||||||||||||||||||||||
1086 | - | |||||||||||||||||||||||||
1087 | if (w->thread == QThread::currentThread()) {
| 0 | ||||||||||||||||||||||||
1088 | qCDebug(QSG_LOG_RENDERLOOP) << "update on window - on render thread" << w->window; never executed: QMessageLogger(__FILE__, 1088, __PRETTY_FUNCTION__, QSG_LOG_RENDERLOOP().categoryName()).debug() << "update on window - on render thread" << w->window;
| 0 | ||||||||||||||||||||||||
1089 | w->thread->requestRepaint(); | - | ||||||||||||||||||||||||
1090 | return; never executed: return; | 0 | ||||||||||||||||||||||||
1091 | } | - | ||||||||||||||||||||||||
1092 | - | |||||||||||||||||||||||||
1093 | qCDebug(QSG_LOG_RENDERLOOP) << "update on window" << w->window; never executed: QMessageLogger(__FILE__, 1093, __PRETTY_FUNCTION__, QSG_LOG_RENDERLOOP().categoryName()).debug() << "update on window" << w->window;
| 0 | ||||||||||||||||||||||||
1094 | // We set forceRenderPass because we want to make sure the QQuickWindow | - | ||||||||||||||||||||||||
1095 | // actually does a full render pass after the next sync. | - | ||||||||||||||||||||||||
1096 | w->forceRenderPass = true; | - | ||||||||||||||||||||||||
1097 | maybeUpdate(w); | - | ||||||||||||||||||||||||
1098 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1099 | - | |||||||||||||||||||||||||
1100 | - | |||||||||||||||||||||||||
1101 | void QSGThreadedRenderLoop::releaseResources(QQuickWindow *window) | - | ||||||||||||||||||||||||
1102 | { | - | ||||||||||||||||||||||||
1103 | Window *w = windowFor(m_windows, window); | - | ||||||||||||||||||||||||
1104 | if (w)
| 0 | ||||||||||||||||||||||||
1105 | releaseResources(w, false); never executed: releaseResources(w, false); | 0 | ||||||||||||||||||||||||
1106 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1107 | - | |||||||||||||||||||||||||
1108 | /* | - | ||||||||||||||||||||||||
1109 | * Release resources will post an event to the render thread to | - | ||||||||||||||||||||||||
1110 | * free up the SG and GL resources and exists the render thread. | - | ||||||||||||||||||||||||
1111 | */ | - | ||||||||||||||||||||||||
1112 | void QSGThreadedRenderLoop::releaseResources(Window *w, bool inDestructor) | - | ||||||||||||||||||||||||
1113 | { | - | ||||||||||||||||||||||||
1114 | qCDebug(QSG_LOG_RENDERLOOP) << "releaseResources()" << (inDestructor ? "in destructor" : "in api-call") << w->window; never executed: QMessageLogger(__FILE__, 1114, __PRETTY_FUNCTION__, QSG_LOG_RENDERLOOP().categoryName()).debug() << "releaseResources()" << (inDestructor ? "in destructor" : "in api-call") << w->window;
| 0 | ||||||||||||||||||||||||
1115 | - | |||||||||||||||||||||||||
1116 | w->thread->mutex.lock(); | - | ||||||||||||||||||||||||
1117 | if (w->thread->isRunning() && w->thread->active) {
| 0 | ||||||||||||||||||||||||
1118 | QQuickWindow *window = w->window; | - | ||||||||||||||||||||||||
1119 | - | |||||||||||||||||||||||||
1120 | // The platform window might have been destroyed before | - | ||||||||||||||||||||||||
1121 | // hide/release/windowDestroyed is called, so we need to have a | - | ||||||||||||||||||||||||
1122 | // fallback surface to perform the cleanup of the scene graph | - | ||||||||||||||||||||||||
1123 | // and the OpenGL resources. | - | ||||||||||||||||||||||||
1124 | // QOffscreenSurface must be created on the GUI thread, so we | - | ||||||||||||||||||||||||
1125 | // create it here and pass it on to QSGRenderThread::invalidateGL() | - | ||||||||||||||||||||||||
1126 | QOffscreenSurface *fallback = nullptr; | - | ||||||||||||||||||||||||
1127 | if (!window->handle()) {
| 0 | ||||||||||||||||||||||||
1128 | qCDebug(QSG_LOG_RENDERLOOP, "- using fallback surface"); never executed: QMessageLogger(__FILE__, 1128, __PRETTY_FUNCTION__, QSG_LOG_RENDERLOOP().categoryName()).debug("- using fallback surface");
| 0 | ||||||||||||||||||||||||
1129 | fallback = new QOffscreenSurface(); | - | ||||||||||||||||||||||||
1130 | fallback->setFormat(w->actualWindowFormat); | - | ||||||||||||||||||||||||
1131 | fallback->create(); | - | ||||||||||||||||||||||||
1132 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1133 | - | |||||||||||||||||||||||||
1134 | qCDebug(QSG_LOG_RENDERLOOP, "- posting release request to render thread"); never executed: QMessageLogger(__FILE__, 1134, __PRETTY_FUNCTION__, QSG_LOG_RENDERLOOP().categoryName()).debug("- posting release request to render thread");
| 0 | ||||||||||||||||||||||||
1135 | w->thread->postEvent(new WMTryReleaseEvent(window, inDestructor, fallback)); | - | ||||||||||||||||||||||||
1136 | w->thread->waitCondition.wait(&w->thread->mutex); | - | ||||||||||||||||||||||||
1137 | delete fallback; | - | ||||||||||||||||||||||||
1138 | - | |||||||||||||||||||||||||
1139 | // Avoid a shutdown race condition. | - | ||||||||||||||||||||||||
1140 | // If SG is invalidated and 'active' becomes false, the thread's run() | - | ||||||||||||||||||||||||
1141 | // method will exit. handleExposure() relies on QThread::isRunning() (because it | - | ||||||||||||||||||||||||
1142 | // potentially needs to start the thread again) and our mutex cannot be used to | - | ||||||||||||||||||||||||
1143 | // track the thread stopping, so we wait a few nanoseconds extra so the thread | - | ||||||||||||||||||||||||
1144 | // can exit properly. | - | ||||||||||||||||||||||||
1145 | if (!w->thread->active) {
| 0 | ||||||||||||||||||||||||
1146 | qCDebug(QSG_LOG_RENDERLOOP) << " - waiting for render thread to exit" << w->window; never executed: QMessageLogger(__FILE__, 1146, __PRETTY_FUNCTION__, QSG_LOG_RENDERLOOP().categoryName()).debug() << " - waiting for render thread to exit" << w->window;
| 0 | ||||||||||||||||||||||||
1147 | w->thread->wait(); | - | ||||||||||||||||||||||||
1148 | qCDebug(QSG_LOG_RENDERLOOP) << " - render thread finished" << w->window; never executed: QMessageLogger(__FILE__, 1148, __PRETTY_FUNCTION__, QSG_LOG_RENDERLOOP().categoryName()).debug() << " - render thread finished" << w->window;
| 0 | ||||||||||||||||||||||||
1149 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1150 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1151 | w->thread->mutex.unlock(); | - | ||||||||||||||||||||||||
1152 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1153 | - | |||||||||||||||||||||||||
1154 | - | |||||||||||||||||||||||||
1155 | /* Calls polish on all items, then requests synchronization with the render thread | - | ||||||||||||||||||||||||
1156 | * and blocks until that is complete. Returns false if it aborted; otherwise true. | - | ||||||||||||||||||||||||
1157 | */ | - | ||||||||||||||||||||||||
1158 | void QSGThreadedRenderLoop::polishAndSync(Window *w, bool inExpose) | - | ||||||||||||||||||||||||
1159 | { | - | ||||||||||||||||||||||||
1160 | qCDebug(QSG_LOG_RENDERLOOP) << "polishAndSync" << (inExpose ? "(in expose)" : "(normal)") << w->window; never executed: QMessageLogger(__FILE__, 1160, __PRETTY_FUNCTION__, QSG_LOG_RENDERLOOP().categoryName()).debug() << "polishAndSync" << (inExpose ? "(in expose)" : "(normal)") << w->window;
| 0 | ||||||||||||||||||||||||
1161 | - | |||||||||||||||||||||||||
1162 | QQuickWindow *window = w->window; | - | ||||||||||||||||||||||||
1163 | if (!w->thread || !w->thread->window) {
| 0 | ||||||||||||||||||||||||
1164 | qCDebug(QSG_LOG_RENDERLOOP, "- not exposed, abort"); never executed: QMessageLogger(__FILE__, 1164, __PRETTY_FUNCTION__, QSG_LOG_RENDERLOOP().categoryName()).debug("- not exposed, abort");
| 0 | ||||||||||||||||||||||||
1165 | return; never executed: return; | 0 | ||||||||||||||||||||||||
1166 | } | - | ||||||||||||||||||||||||
1167 | - | |||||||||||||||||||||||||
1168 | // Flush pending touch events. | - | ||||||||||||||||||||||||
1169 | QQuickWindowPrivate::get(window)->flushFrameSynchronousEvents(); | - | ||||||||||||||||||||||||
1170 | // The delivery of the event might have caused the window to stop rendering | - | ||||||||||||||||||||||||
1171 | w = windowFor(m_windows, window); | - | ||||||||||||||||||||||||
1172 | if (!w || !w->thread || !w->thread->window) {
| 0 | ||||||||||||||||||||||||
1173 | qCDebug(QSG_LOG_RENDERLOOP, "- removed after event flushing, abort"); never executed: QMessageLogger(__FILE__, 1173, __PRETTY_FUNCTION__, QSG_LOG_RENDERLOOP().categoryName()).debug("- removed after event flushing, abort");
| 0 | ||||||||||||||||||||||||
1174 | return; never executed: return; | 0 | ||||||||||||||||||||||||
1175 | } | - | ||||||||||||||||||||||||
1176 | - | |||||||||||||||||||||||||
1177 | - | |||||||||||||||||||||||||
1178 | QElapsedTimer timer; | - | ||||||||||||||||||||||||
1179 | qint64 polishTime = 0; | - | ||||||||||||||||||||||||
1180 | qint64 waitTime = 0; | - | ||||||||||||||||||||||||
1181 | qint64 syncTime = 0; | - | ||||||||||||||||||||||||
1182 | bool profileFrames = QSG_LOG_TIME_RENDERLOOP().isDebugEnabled(); | - | ||||||||||||||||||||||||
1183 | if (profileFrames)
| 0 | ||||||||||||||||||||||||
1184 | timer.start(); never executed: timer.start(); | 0 | ||||||||||||||||||||||||
1185 | Q_QUICK_SG_PROFILE_START(QQuickProfiler::SceneGraphPolishAndSync); never executed: end of block never executed: (void)0;
| 0 | ||||||||||||||||||||||||
1186 | - | |||||||||||||||||||||||||
1187 | QQuickWindowPrivate *d = QQuickWindowPrivate::get(window); | - | ||||||||||||||||||||||||
1188 | d->polishItems(); | - | ||||||||||||||||||||||||
1189 | - | |||||||||||||||||||||||||
1190 | if (profileFrames)
| 0 | ||||||||||||||||||||||||
1191 | polishTime = timer.nsecsElapsed(); never executed: polishTime = timer.nsecsElapsed(); | 0 | ||||||||||||||||||||||||
1192 | Q_QUICK_SG_PROFILE_RECORD(QQuickProfiler::SceneGraphPolishAndSync, never executed: end of block never executed: (void)0 ;
| 0 | ||||||||||||||||||||||||
1193 | QQuickProfiler::SceneGraphPolishAndSyncPolish); never executed: (void)0 ; | 0 | ||||||||||||||||||||||||
1194 | - | |||||||||||||||||||||||||
1195 | w->updateDuringSync = false; | - | ||||||||||||||||||||||||
1196 | - | |||||||||||||||||||||||||
1197 | emit window->afterAnimating(); | - | ||||||||||||||||||||||||
1198 | - | |||||||||||||||||||||||||
1199 | qCDebug(QSG_LOG_RENDERLOOP, "- lock for sync"); never executed: QMessageLogger(__FILE__, 1199, __PRETTY_FUNCTION__, QSG_LOG_RENDERLOOP().categoryName()).debug("- lock for sync");
| 0 | ||||||||||||||||||||||||
1200 | w->thread->mutex.lock(); | - | ||||||||||||||||||||||||
1201 | m_lockedForSync = true; | - | ||||||||||||||||||||||||
1202 | w->thread->postEvent(new WMSyncEvent(window, inExpose, w->forceRenderPass)); | - | ||||||||||||||||||||||||
1203 | w->forceRenderPass = false; | - | ||||||||||||||||||||||||
1204 | - | |||||||||||||||||||||||||
1205 | qCDebug(QSG_LOG_RENDERLOOP, "- wait for sync"); never executed: QMessageLogger(__FILE__, 1205, __PRETTY_FUNCTION__, QSG_LOG_RENDERLOOP().categoryName()).debug("- wait for sync");
| 0 | ||||||||||||||||||||||||
1206 | if (profileFrames)
| 0 | ||||||||||||||||||||||||
1207 | waitTime = timer.nsecsElapsed(); never executed: waitTime = timer.nsecsElapsed(); | 0 | ||||||||||||||||||||||||
1208 | Q_QUICK_SG_PROFILE_RECORD(QQuickProfiler::SceneGraphPolishAndSync, never executed: end of block never executed: (void)0 ;
| 0 | ||||||||||||||||||||||||
1209 | QQuickProfiler::SceneGraphPolishAndSyncWait); never executed: (void)0 ; | 0 | ||||||||||||||||||||||||
1210 | w->thread->waitCondition.wait(&w->thread->mutex); | - | ||||||||||||||||||||||||
1211 | m_lockedForSync = false; | - | ||||||||||||||||||||||||
1212 | w->thread->mutex.unlock(); | - | ||||||||||||||||||||||||
1213 | qCDebug(QSG_LOG_RENDERLOOP, "- unlock after sync"); never executed: QMessageLogger(__FILE__, 1213, __PRETTY_FUNCTION__, QSG_LOG_RENDERLOOP().categoryName()).debug("- unlock after sync");
| 0 | ||||||||||||||||||||||||
1214 | - | |||||||||||||||||||||||||
1215 | if (profileFrames)
| 0 | ||||||||||||||||||||||||
1216 | syncTime = timer.nsecsElapsed(); never executed: syncTime = timer.nsecsElapsed(); | 0 | ||||||||||||||||||||||||
1217 | Q_QUICK_SG_PROFILE_RECORD(QQuickProfiler::SceneGraphPolishAndSync, never executed: end of block never executed: (void)0 ;
| 0 | ||||||||||||||||||||||||
1218 | QQuickProfiler::SceneGraphPolishAndSyncSync); never executed: (void)0 ; | 0 | ||||||||||||||||||||||||
1219 | - | |||||||||||||||||||||||||
1220 | if (m_animation_timer == 0 && m_animation_driver->isRunning()) {
| 0 | ||||||||||||||||||||||||
1221 | qCDebug(QSG_LOG_RENDERLOOP, "- advancing animations"); never executed: QMessageLogger(__FILE__, 1221, __PRETTY_FUNCTION__, QSG_LOG_RENDERLOOP().categoryName()).debug("- advancing animations");
| 0 | ||||||||||||||||||||||||
1222 | m_animation_driver->advance(); | - | ||||||||||||||||||||||||
1223 | qCDebug(QSG_LOG_RENDERLOOP, "- animations done.."); never executed: QMessageLogger(__FILE__, 1223, __PRETTY_FUNCTION__, QSG_LOG_RENDERLOOP().categoryName()).debug("- animations done..");
| 0 | ||||||||||||||||||||||||
1224 | // We need to trigger another sync to keep animations running... | - | ||||||||||||||||||||||||
1225 | maybePostPolishRequest(w); | - | ||||||||||||||||||||||||
1226 | emit timeToIncubate(); | - | ||||||||||||||||||||||||
1227 | } else if (w->updateDuringSync) { never executed: end of block
| 0 | ||||||||||||||||||||||||
1228 | maybePostPolishRequest(w); | - | ||||||||||||||||||||||||
1229 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1230 | - | |||||||||||||||||||||||||
1231 | qCDebug(QSG_LOG_TIME_RENDERLOOP()).nospace() never executed: QMessageLogger(__FILE__, 1231, __PRETTY_FUNCTION__, QSG_LOG_TIME_RENDERLOOP()().categoryName()).debug().nospace() << "Frame prepared with 'threaded' renderloop" << ", polish=" << (polishTime / 1000000) << ", lock=" << (waitTime - polishTime) / 1000000 << ", blockedForSync=" << (syncTime - waitTime) / 1000000 << ", animations=" << (timer.nsecsElapsed() - syncTime) / 1000000 << " - (on Gui thread) " << window;
| 0 | ||||||||||||||||||||||||
1232 | << "Frame prepared with 'threaded' renderloop" never executed: QMessageLogger(__FILE__, 1231, __PRETTY_FUNCTION__, QSG_LOG_TIME_RENDERLOOP()().categoryName()).debug().nospace() << "Frame prepared with 'threaded' renderloop" << ", polish=" << (polishTime / 1000000) << ", lock=" << (waitTime - polishTime) / 1000000 << ", blockedForSync=" << (syncTime - waitTime) / 1000000 << ", animations=" << (timer.nsecsElapsed() - syncTime) / 1000000 << " - (on Gui thread) " << window; | 0 | ||||||||||||||||||||||||
1233 | << ", polish=" << (polishTime / 1000000) never executed: QMessageLogger(__FILE__, 1231, __PRETTY_FUNCTION__, QSG_LOG_TIME_RENDERLOOP()().categoryName()).debug().nospace() << "Frame prepared with 'threaded' renderloop" << ", polish=" << (polishTime / 1000000) << ", lock=" << (waitTime - polishTime) / 1000000 << ", blockedForSync=" << (syncTime - waitTime) / 1000000 << ", animations=" << (timer.nsecsElapsed() - syncTime) / 1000000 << " - (on Gui thread) " << window; | 0 | ||||||||||||||||||||||||
1234 | << ", lock=" << (waitTime - polishTime) / 1000000 never executed: QMessageLogger(__FILE__, 1231, __PRETTY_FUNCTION__, QSG_LOG_TIME_RENDERLOOP()().categoryName()).debug().nospace() << "Frame prepared with 'threaded' renderloop" << ", polish=" << (polishTime / 1000000) << ", lock=" << (waitTime - polishTime) / 1000000 << ", blockedForSync=" << (syncTime - waitTime) / 1000000 << ", animations=" << (timer.nsecsElapsed() - syncTime) / 1000000 << " - (on Gui thread) " << window; | 0 | ||||||||||||||||||||||||
1235 | << ", blockedForSync=" << (syncTime - waitTime) / 1000000 never executed: QMessageLogger(__FILE__, 1231, __PRETTY_FUNCTION__, QSG_LOG_TIME_RENDERLOOP()().categoryName()).debug().nospace() << "Frame prepared with 'threaded' renderloop" << ", polish=" << (polishTime / 1000000) << ", lock=" << (waitTime - polishTime) / 1000000 << ", blockedForSync=" << (syncTime - waitTime) / 1000000 << ", animations=" << (timer.nsecsElapsed() - syncTime) / 1000000 << " - (on Gui thread) " << window; | 0 | ||||||||||||||||||||||||
1236 | << ", animations=" << (timer.nsecsElapsed() - syncTime) / 1000000 never executed: QMessageLogger(__FILE__, 1231, __PRETTY_FUNCTION__, QSG_LOG_TIME_RENDERLOOP()().categoryName()).debug().nospace() << "Frame prepared with 'threaded' renderloop" << ", polish=" << (polishTime / 1000000) << ", lock=" << (waitTime - polishTime) / 1000000 << ", blockedForSync=" << (syncTime - waitTime) / 1000000 << ", animations=" << (timer.nsecsElapsed() - syncTime) / 1000000 << " - (on Gui thread) " << window; | 0 | ||||||||||||||||||||||||
1237 | << " - (on Gui thread) " << window; never executed: QMessageLogger(__FILE__, 1231, __PRETTY_FUNCTION__, QSG_LOG_TIME_RENDERLOOP()().categoryName()).debug().nospace() << "Frame prepared with 'threaded' renderloop" << ", polish=" << (polishTime / 1000000) << ", lock=" << (waitTime - polishTime) / 1000000 << ", blockedForSync=" << (syncTime - waitTime) / 1000000 << ", animations=" << (timer.nsecsElapsed() - syncTime) / 1000000 << " - (on Gui thread) " << window; | 0 | ||||||||||||||||||||||||
1238 | - | |||||||||||||||||||||||||
1239 | Q_QUICK_SG_PROFILE_END(QQuickProfiler::SceneGraphPolishAndSync, never executed: end of block never executed: (void)0 ;
| 0 | ||||||||||||||||||||||||
1240 | QQuickProfiler::SceneGraphPolishAndSyncAnimations); never executed: (void)0 ; | 0 | ||||||||||||||||||||||||
1241 | } | - | ||||||||||||||||||||||||
1242 | - | |||||||||||||||||||||||||
1243 | bool QSGThreadedRenderLoop::event(QEvent *e) | - | ||||||||||||||||||||||||
1244 | { | - | ||||||||||||||||||||||||
1245 | switch ((int) e->type()) { | - | ||||||||||||||||||||||||
1246 | - | |||||||||||||||||||||||||
1247 | case QEvent::Timer: { never executed: case QEvent::Timer: | 0 | ||||||||||||||||||||||||
1248 | QTimerEvent *te = static_cast<QTimerEvent *>(e); | - | ||||||||||||||||||||||||
1249 | if (te->timerId() == m_animation_timer) {
| 0 | ||||||||||||||||||||||||
1250 | qCDebug(QSG_LOG_RENDERLOOP, "- ticking non-visual timer"); never executed: QMessageLogger(__FILE__, 1250, __PRETTY_FUNCTION__, QSG_LOG_RENDERLOOP().categoryName()).debug("- ticking non-visual timer");
| 0 | ||||||||||||||||||||||||
1251 | m_animation_driver->advance(); | - | ||||||||||||||||||||||||
1252 | emit timeToIncubate(); | - | ||||||||||||||||||||||||
1253 | return true; never executed: return true; | 0 | ||||||||||||||||||||||||
1254 | } | - | ||||||||||||||||||||||||
1255 | } | - | ||||||||||||||||||||||||
1256 | - | |||||||||||||||||||||||||
1257 | default: code before this statement never executed: default: never executed: default: | 0 | ||||||||||||||||||||||||
1258 | break; never executed: break; | 0 | ||||||||||||||||||||||||
1259 | } | - | ||||||||||||||||||||||||
1260 | - | |||||||||||||||||||||||||
1261 | return QObject::event(e); never executed: return QObject::event(e); | 0 | ||||||||||||||||||||||||
1262 | } | - | ||||||||||||||||||||||||
1263 | - | |||||||||||||||||||||||||
1264 | - | |||||||||||||||||||||||||
1265 | - | |||||||||||||||||||||||||
1266 | /* | - | ||||||||||||||||||||||||
1267 | Locks down GUI and performs a grab the scene graph, then returns the result. | - | ||||||||||||||||||||||||
1268 | - | |||||||||||||||||||||||||
1269 | Since the QML scene could have changed since the last time it was rendered, | - | ||||||||||||||||||||||||
1270 | we need to polish and sync the scene graph. This might seem superfluous, but | - | ||||||||||||||||||||||||
1271 | - QML changes could have triggered deleteLater() which could have removed | - | ||||||||||||||||||||||||
1272 | textures or other objects from the scene graph, causing render to crash. | - | ||||||||||||||||||||||||
1273 | - Autotests rely on grab(), setProperty(), grab(), compare behavior. | - | ||||||||||||||||||||||||
1274 | */ | - | ||||||||||||||||||||||||
1275 | - | |||||||||||||||||||||||||
1276 | QImage QSGThreadedRenderLoop::grab(QQuickWindow *window) | - | ||||||||||||||||||||||||
1277 | { | - | ||||||||||||||||||||||||
1278 | qCDebug(QSG_LOG_RENDERLOOP) << "grab()" << window; never executed: QMessageLogger(__FILE__, 1278, __PRETTY_FUNCTION__, QSG_LOG_RENDERLOOP().categoryName()).debug() << "grab()" << window;
| 0 | ||||||||||||||||||||||||
1279 | - | |||||||||||||||||||||||||
1280 | Window *w = windowFor(m_windows, window); | - | ||||||||||||||||||||||||
1281 | Q_ASSERT(w); | - | ||||||||||||||||||||||||
1282 | - | |||||||||||||||||||||||||
1283 | if (!w->thread->isRunning())
| 0 | ||||||||||||||||||||||||
1284 | return QImage(); never executed: return QImage(); | 0 | ||||||||||||||||||||||||
1285 | - | |||||||||||||||||||||||||
1286 | if (!window->handle())
| 0 | ||||||||||||||||||||||||
1287 | window->create(); never executed: window->create(); | 0 | ||||||||||||||||||||||||
1288 | - | |||||||||||||||||||||||||
1289 | qCDebug(QSG_LOG_RENDERLOOP, "- polishing items"); never executed: QMessageLogger(__FILE__, 1289, __PRETTY_FUNCTION__, QSG_LOG_RENDERLOOP().categoryName()).debug("- polishing items");
| 0 | ||||||||||||||||||||||||
1290 | QQuickWindowPrivate *d = QQuickWindowPrivate::get(window); | - | ||||||||||||||||||||||||
1291 | d->polishItems(); | - | ||||||||||||||||||||||||
1292 | - | |||||||||||||||||||||||||
1293 | QImage result; | - | ||||||||||||||||||||||||
1294 | w->thread->mutex.lock(); | - | ||||||||||||||||||||||||
1295 | m_lockedForSync = true; | - | ||||||||||||||||||||||||
1296 | qCDebug(QSG_LOG_RENDERLOOP, "- posting grab event"); never executed: QMessageLogger(__FILE__, 1296, __PRETTY_FUNCTION__, QSG_LOG_RENDERLOOP().categoryName()).debug("- posting grab event");
| 0 | ||||||||||||||||||||||||
1297 | w->thread->postEvent(new WMGrabEvent(window, &result)); | - | ||||||||||||||||||||||||
1298 | w->thread->waitCondition.wait(&w->thread->mutex); | - | ||||||||||||||||||||||||
1299 | m_lockedForSync = false; | - | ||||||||||||||||||||||||
1300 | w->thread->mutex.unlock(); | - | ||||||||||||||||||||||||
1301 | - | |||||||||||||||||||||||||
1302 | qCDebug(QSG_LOG_RENDERLOOP, "- grab complete"); never executed: QMessageLogger(__FILE__, 1302, __PRETTY_FUNCTION__, QSG_LOG_RENDERLOOP().categoryName()).debug("- grab complete");
| 0 | ||||||||||||||||||||||||
1303 | - | |||||||||||||||||||||||||
1304 | return result; never executed: return result; | 0 | ||||||||||||||||||||||||
1305 | } | - | ||||||||||||||||||||||||
1306 | - | |||||||||||||||||||||||||
1307 | /* | - | ||||||||||||||||||||||||
1308 | * Posts a new job event to the render thread. | - | ||||||||||||||||||||||||
1309 | * Returns true if posting succeeded. | - | ||||||||||||||||||||||||
1310 | */ | - | ||||||||||||||||||||||||
1311 | void QSGThreadedRenderLoop::postJob(QQuickWindow *window, QRunnable *job) | - | ||||||||||||||||||||||||
1312 | { | - | ||||||||||||||||||||||||
1313 | Window *w = windowFor(m_windows, window); | - | ||||||||||||||||||||||||
1314 | if (w && w->thread && w->thread->window)
| 0 | ||||||||||||||||||||||||
1315 | w->thread->postEvent(new WMJobEvent(window, job)); never executed: w->thread->postEvent(new WMJobEvent(window, job)); | 0 | ||||||||||||||||||||||||
1316 | else | - | ||||||||||||||||||||||||
1317 | delete job; never executed: delete job; | 0 | ||||||||||||||||||||||||
1318 | } | - | ||||||||||||||||||||||||
1319 | - | |||||||||||||||||||||||||
1320 | #include "qsgthreadedrenderloop.moc" | - | ||||||||||||||||||||||||
1321 | #include "moc_qsgthreadedrenderloop_p.cpp" | - | ||||||||||||||||||||||||
1322 | - | |||||||||||||||||||||||||
1323 | QT_END_NAMESPACE | - | ||||||||||||||||||||||||
Source code | Switch to Preprocessed file |