Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qsgthreadedrenderloop.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// Copyright (C) 2016 Jolla Ltd, author: <gunnar.sletta@jollamobile.com>
3// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
4// Qt-Security score:significant reason:default
5
6
7#include <QtCore/QMutex>
8#include <QtCore/QWaitCondition>
9#include <QtCore/QAnimationDriver>
10#include <QtCore/QQueue>
11#include <QtCore/QTimer>
12
13#include <QtGui/QGuiApplication>
14#include <QtGui/QScreen>
15#include <QtGui/QOffscreenSurface>
16
17#include <qpa/qwindowsysteminterface.h>
18
19#include <QtQuick/QQuickWindow>
20#include <private/qquickwindow_p.h>
21#include <private/qquickitem_p.h>
22#include <QtGui/qpa/qplatformwindow_p.h>
23
24#include <QtQuick/private/qsgrenderer_p.h>
25
28#include <private/qquickanimatorcontroller_p.h>
29
30#include <private/qquickprofiler_p.h>
31#include <private/qqmldebugserviceinterfaces_p.h>
32#include <private/qqmldebugconnector_p.h>
33
34#include <private/qsgrhishadereffectnode_p.h>
35#include <private/qsgdefaultrendercontext_p.h>
36
37#include <qtquick_tracepoints_p.h>
38
39#ifdef Q_OS_DARWIN
40#include <QtCore/private/qcore_mac_p.h>
41#endif
42
43/*
44 Overall design:
45
46 There are two classes here. QSGThreadedRenderLoop and
47 QSGRenderThread. All communication between the two is based on
48 event passing and we have a number of custom events.
49
50 In this implementation, the render thread is never blocked and the
51 GUI thread will initiate a polishAndSync which will block and wait
52 for the render thread to pick it up and release the block only
53 after the render thread is done syncing. The reason for this
54 is:
55
56 1. Clear blocking paradigm. We only have one real "block" point
57 (polishAndSync()) and all blocking is initiated by GUI and picked
58 up by Render at specific times based on events. This makes the
59 execution deterministic.
60
61 2. Render does not have to interact with GUI. This is done so that
62 the render thread can run its own animation system which stays
63 alive even when the GUI thread is blocked doing i/o, object
64 instantiation, QPainter-painting or any other non-trivial task.
65
66 ---
67
68 There is one thread per window and one QRhi instance per thread.
69
70 ---
71
72 The render thread has affinity to the GUI thread until a window
73 is shown. From that moment and until the window is destroyed, it
74 will have affinity to the render thread. (moved back at the end
75 of run for cleanup).
76
77 ---
78
79 The render loop is active while any window is exposed. All visible
80 windows are tracked, but only exposed windows are actually added to
81 the render thread and rendered. That means that if all windows are
82 obscured, we might end up cleaning up the SG and GL context (if all
83 windows have disabled persistency). Especially for multiprocess,
84 low-end systems, this should be quite important.
85
86 */
87
89
90Q_TRACE_POINT(qtquick, QSG_polishAndSync_entry)
91Q_TRACE_POINT(qtquick, QSG_polishAndSync_exit)
92Q_TRACE_POINT(qtquick, QSG_wait_entry)
93Q_TRACE_POINT(qtquick, QSG_wait_exit)
94Q_TRACE_POINT(qtquick, QSG_syncAndRender_entry)
95Q_TRACE_POINT(qtquick, QSG_syncAndRender_exit)
96Q_TRACE_POINT(qtquick, QSG_animations_entry)
97Q_TRACE_POINT(qtquick, QSG_animations_exit)
98
99#define QSG_RT_PAD " (RT) %s"
100
101extern Q_GUI_EXPORT QImage qt_gl_read_framebuffer(const QSize &size, bool alpha_format, bool include_alpha);
102
103// RL: Render Loop
104// RT: Render Thread
105
106
107QSGThreadedRenderLoop::Window *QSGThreadedRenderLoop::windowFor(QQuickWindow *window)
108{
109 for (const auto &t : std::as_const(m_windows)) {
110 if (t.window == window)
111 return const_cast<Window *>(&t);
112 }
113 return nullptr;
114}
115
116class WMWindowEvent : public QEvent
117{
118public:
119 WMWindowEvent(QQuickWindow *c, QEvent::Type type) : QEvent(type), window(c) { }
120 QQuickWindow *window;
121};
122
124{
125public:
126 WMTryReleaseEvent(QQuickWindow *win, bool destroy, bool needsFallbackSurface)
128 , inDestructor(destroy)
129 , needsFallback(needsFallbackSurface)
130 {}
131
134};
135
137{
138public:
139 WMSyncEvent(QQuickWindow *c, bool inExpose, bool force, const QRhiSwapChainProxyData &scProxyData)
141 , size(c->size())
142 , dpr(float(c->effectiveDevicePixelRatio()))
143 , syncInExpose(inExpose)
144 , forceRenderPass(force)
145 , scProxyData(scProxyData)
146 {}
148 float dpr;
152};
153
154
156{
157public:
158 WMGrabEvent(QQuickWindow *c, QImage *result) :
161};
162
164{
165public:
166 WMJobEvent(QQuickWindow *c, QRunnable *postedJob)
167 : WMWindowEvent(c, QEvent::Type(WM_PostJob)), job(postedJob) {}
168 ~WMJobEvent() { delete job; }
169 QRunnable *job;
170};
171
173{
174public:
177};
178
180{
181public:
183 : waiting(false)
184 {
185 }
186
187 void addEvent(QEvent *e) {
188 mutex.lock();
189 enqueue(e);
190 if (waiting)
191 condition.wakeOne();
192 mutex.unlock();
193 }
194
195 QEvent *takeEvent(bool wait) {
196 mutex.lock();
197 if (size() == 0 && wait) {
198 waiting = true;
199 condition.wait(&mutex);
200 waiting = false;
201 }
202 QEvent *e = dequeue();
203 mutex.unlock();
204 return e;
205 }
206
208 mutex.lock();
209 bool has = !isEmpty();
210 mutex.unlock();
211 return has;
212 }
213
214private:
215 QMutex mutex;
216 QWaitCondition condition;
217 bool waiting;
218};
219
220
222{
224public:
226 : wm(w)
227 , rhi(nullptr)
228 , ownRhi(true)
229 , offscreenSurface(nullptr)
230 , animatorDriver(nullptr)
231 , pendingUpdate(0)
232 , sleeping(false)
233 , active(false)
234 , window(nullptr)
235 , stopEventProcessing(false)
236 {
238#if defined(Q_OS_QNX) || defined(Q_OS_INTEGRITY)
239 // The render thread requires a larger stack than the default (256k).
240 setStackSize(1024 * 1024);
241#endif
242 }
243
245 {
246 delete sgrc;
247 delete offscreenSurface;
248 }
249
251
252 bool event(QEvent *) override;
253 void run() override;
254
256 void sync(bool inExpose);
257
259 {
260 if (sleeping)
261 stopEventProcessing = true;
262 if (window)
263 pendingUpdate |= RepaintRequest;
264 }
265
268 void postEvent(QEvent *e);
269
270public:
271 enum {
275 };
276
277 void ensureRhi();
280
282 QRhi *rhi;
283 bool ownRhi;
284 QSGDefaultRenderContext *sgrc;
285 QOffscreenSurface *offscreenSurface;
286
287 QAnimationDriver *animatorDriver;
288
291
292 volatile bool active;
293
296
298
299 QQuickWindow *window; // Will be 0 when window is not exposed
301 float dpr = 1;
304 bool rhiDeviceLost = false;
305 bool rhiDoomed = false;
308 bool swapchainOutOfDate = false;
309
310 // Local event queue stuff...
313};
314
315bool QSGRenderThread::event(QEvent *e)
316{
317 switch ((int) e->type()) {
318
319 case WM_Obscure: {
320 qCDebug(QSG_LOG_RENDERLOOP, QSG_RT_PAD, "WM_Obscure");
321
322 Q_ASSERT(!window || window == static_cast<WMWindowEvent *>(e)->window);
323
324 mutex.lock();
325 if (window) {
326 QQuickWindowPrivate::get(window)->fireAboutToStop();
327 qCDebug(QSG_LOG_RENDERLOOP, QSG_RT_PAD, "- window removed");
328 window = nullptr;
329 }
330 waitCondition.wakeOne();
331 mutex.unlock();
332
333 return true; }
334
335
336 case WM_Exposed: {
337 qCDebug(QSG_LOG_RENDERLOOP, QSG_RT_PAD, "WM_Exposed");
338
339 mutex.lock();
340 window = static_cast<WMWindowEvent *>(e)->window;
341 waitCondition.wakeOne();
342 mutex.unlock();
343
344 return true; }
345
346 case WM_RequestSync: {
347 qCDebug(QSG_LOG_RENDERLOOP, QSG_RT_PAD, "WM_RequestSync");
348 WMSyncEvent *se = static_cast<WMSyncEvent *>(e);
349 if (sleeping)
350 stopEventProcessing = true;
351 window = se->window;
352 windowSize = se->size;
353 dpr = se->dpr;
355
356 pendingUpdate |= SyncRequest;
357 if (se->syncInExpose) {
358 qCDebug(QSG_LOG_RENDERLOOP, QSG_RT_PAD, "- triggered from expose");
359 pendingUpdate |= ExposeRequest;
360 }
361 if (se->forceRenderPass) {
362 qCDebug(QSG_LOG_RENDERLOOP, QSG_RT_PAD, "- repaint regardless");
363 pendingUpdate |= RepaintRequest;
364 }
365 return true; }
366
367 case WM_TryRelease: {
368 qCDebug(QSG_LOG_RENDERLOOP, QSG_RT_PAD, "WM_TryRelease");
369 mutex.lock();
370 wm->m_lockedForSync = true;
371 WMTryReleaseEvent *wme = static_cast<WMTryReleaseEvent *>(e);
372 if (!window || wme->inDestructor) {
373 qCDebug(QSG_LOG_RENDERLOOP, QSG_RT_PAD, "- setting exit flag and invalidating");
374 invalidateGraphics(wme->window, wme->inDestructor);
375 active = rhi != nullptr;
376 Q_ASSERT_X(!wme->inDestructor || !active, "QSGRenderThread::invalidateGraphics()", "Thread's active state is not set to false when shutting down");
377 if (sleeping)
378 stopEventProcessing = true;
379 } else {
380 qCDebug(QSG_LOG_RENDERLOOP, QSG_RT_PAD, "- not releasing because window is still active");
381 if (window) {
382 QQuickWindowPrivate *d = QQuickWindowPrivate::get(window);
383 qCDebug(QSG_LOG_RENDERLOOP, QSG_RT_PAD, "- requesting external renderers such as Quick 3D to release cached resources");
384 emit d->context->releaseCachedResourcesRequested();
385 if (d->renderer) {
386 qCDebug(QSG_LOG_RENDERLOOP, QSG_RT_PAD, "- requesting renderer to release cached resources");
387 d->renderer->releaseCachedResources();
388 }
389#if QT_CONFIG(quick_shadereffect)
390 QSGRhiShaderEffectNode::garbageCollectMaterialTypeCache(window);
391#endif
392 }
393 }
394 waitCondition.wakeOne();
395 wm->m_lockedForSync = false;
396 mutex.unlock();
397 return true;
398 }
399
400 case WM_Grab: {
401 qCDebug(QSG_LOG_RENDERLOOP, QSG_RT_PAD, "WM_Grab");
402 WMGrabEvent *ce = static_cast<WMGrabEvent *>(e);
403 Q_ASSERT(ce->window);
404 Q_ASSERT(ce->window == window || !window);
405 mutex.lock();
406 if (ce->window) {
407 if (rhi) {
408 QQuickWindowPrivate *cd = QQuickWindowPrivate::get(ce->window);
409 // The assumption is that the swapchain is usable, because on
410 // expose the thread starts up and renders a frame so one cannot
411 // get here without having done at least one on-screen frame.
412 cd->rhi->beginFrame(cd->swapchain);
413 cd->rhi->makeThreadLocalNativeContextCurrent(); // for custom GL rendering before/during/after sync
414 cd->syncSceneGraph();
415 sgrc->endSync();
416 cd->renderSceneGraph();
417 *ce->image = QSGRhiSupport::instance()->grabAndBlockInCurrentFrame(rhi, cd->swapchain->currentFrameCommandBuffer());
418 cd->rhi->endFrame(cd->swapchain, QRhi::SkipPresent);
419 }
420 ce->image->setDevicePixelRatio(ce->window->effectiveDevicePixelRatio());
421 }
422 qCDebug(QSG_LOG_RENDERLOOP, QSG_RT_PAD, "- waking gui to handle result");
423 waitCondition.wakeOne();
424 mutex.unlock();
425 return true;
426 }
427
428 case WM_PostJob: {
429 qCDebug(QSG_LOG_RENDERLOOP, QSG_RT_PAD, "WM_PostJob");
430 WMJobEvent *ce = static_cast<WMJobEvent *>(e);
431 Q_ASSERT(ce->window == window);
432 if (window) {
433 if (rhi)
434 rhi->makeThreadLocalNativeContextCurrent();
435 ce->job->run();
436 delete ce->job;
437 ce->job = nullptr;
438 qCDebug(QSG_LOG_RENDERLOOP, QSG_RT_PAD, "- job done");
439 }
440 return true;
441 }
442
443 case WM_ReleaseSwapchain: {
444 qCDebug(QSG_LOG_RENDERLOOP, QSG_RT_PAD, "WM_ReleaseSwapchain");
445 WMReleaseSwapchainEvent *ce = static_cast<WMReleaseSwapchainEvent *>(e);
446 // forget about 'window' here that may be null when already unexposed
447 Q_ASSERT(ce->window);
448 mutex.lock();
449 if (ce->window) {
450 wm->releaseSwapchain(ce->window);
451 qCDebug(QSG_LOG_RENDERLOOP, QSG_RT_PAD, "- swapchain released");
452 }
453 waitCondition.wakeOne();
454 mutex.unlock();
455 return true;
456 }
457
458 default:
459 break;
460 }
461 return QThread::event(e);
462}
463
464void QSGRenderThread::invalidateGraphics(QQuickWindow *window, bool inDestructor)
465{
466 qCDebug(QSG_LOG_RENDERLOOP, QSG_RT_PAD, "invalidateGraphics()");
467
468 if (!rhi)
469 return;
470
471 if (!window) {
472 qCWarning(QSG_LOG_RENDERLOOP, "QSGThreadedRenderLoop:QSGRenderThread: no window to make current...");
473 return;
474 }
475
476 bool wipeSG = inDestructor || !window->isPersistentSceneGraph();
477 bool wipeGraphics = inDestructor || (wipeSG && !window->isPersistentGraphics());
478
479 rhi->makeThreadLocalNativeContextCurrent();
480
481 QQuickWindowPrivate *dd = QQuickWindowPrivate::get(window);
482
483 // The canvas nodes must be cleaned up regardless if we are in the destructor..
484 if (wipeSG) {
485 dd->cleanupNodesOnShutdown();
486#if QT_CONFIG(quick_shadereffect)
487 QSGRhiShaderEffectNode::resetMaterialTypeCache(window);
488#endif
489 } else {
490 qCDebug(QSG_LOG_RENDERLOOP, QSG_RT_PAD, "- persistent SG, avoiding cleanup");
491 return;
492 }
493
494 sgrc->invalidate();
495 QCoreApplication::processEvents();
496 QCoreApplication::sendPostedEvents(nullptr, QEvent::DeferredDelete);
497 if (inDestructor)
498 dd->animationController.reset();
499
500 qCDebug(QSG_LOG_RENDERLOOP, QSG_RT_PAD, "- invalidating scene graph");
501
502 if (wipeGraphics) {
503 if (dd->swapchain) {
504 if (window->handle()) {
505 // We get here when exiting via QCoreApplication::quit() instead of
506 // through QWindow::close().
507 wm->releaseSwapchain(window);
508 } else {
509 qWarning("QSGThreadedRenderLoop cleanup with QQuickWindow %p swapchain %p still alive, this should not happen.",
510 window, dd->swapchain);
511 }
512 }
513 if (ownRhi)
514 QSGRhiSupport::instance()->destroyRhi(rhi, dd->graphicsConfig);
515 rhi = nullptr;
516 dd->rhi = nullptr;
517 qCDebug(QSG_LOG_RENDERLOOP, QSG_RT_PAD, "- QRhi destroyed");
518 } else {
519 qCDebug(QSG_LOG_RENDERLOOP, QSG_RT_PAD, "- persistent GL, avoiding cleanup");
520 }
521}
522
523/*
524 Enters the mutex lock to make sure GUI is blocking and performs
525 sync, then wakes GUI.
526 */
527void QSGRenderThread::sync(bool inExpose)
528{
529 qCDebug(QSG_LOG_RENDERLOOP, QSG_RT_PAD, "sync()");
530 mutex.lock();
531
532 Q_ASSERT_X(wm->m_lockedForSync, "QSGRenderThread::sync()", "sync triggered on bad terms as gui is not already locked...");
533
534 bool canSync = true;
535 if (rhi) {
536 if (windowSize.width() > 0 && windowSize.height() > 0) {
537 // With the rhi making the (OpenGL) context current serves only one
538 // purpose: to enable external OpenGL rendering connected to one of
539 // the QQuickWindow signals (beforeSynchronizing, beforeRendering,
540 // etc.) to function like it did on the direct OpenGL path. For our
541 // own rendering this call would not be necessary.
542 rhi->makeThreadLocalNativeContextCurrent();
543 } else {
544 // Zero size windows do not initialize a swapchain and
545 // rendercontext. So no sync or render can be done then.
546 canSync = false;
547 }
548 } else {
549 canSync = false;
550 }
551 if (canSync) {
552 QQuickWindowPrivate *d = QQuickWindowPrivate::get(window);
553 // If the scene graph was touched since the last sync() make sure it sends the
554 // changed signal.
555 if (d->renderer)
556 d->renderer->clearChangedFlag();
557 d->syncSceneGraph();
558 sgrc->endSync();
559
560 // Process deferred deletes now, directly after the sync as
561 // deleteLater on the GUI must now also have resulted in SG changes
562 // and the delete is a safe operation.
563 QCoreApplication::sendPostedEvents(nullptr, QEvent::DeferredDelete);
564 } else {
565 qCDebug(QSG_LOG_RENDERLOOP, QSG_RT_PAD, "- window has bad size, sync aborted");
566 }
567
568 // Two special cases: For grabs we do not care about blocking the gui
569 // (main) thread. When this is from an expose, we will keep locked until
570 // the frame is rendered (submitted), so in that case waking happens later
571 // in syncAndRender(). Otherwise, wake now and let the main thread go on
572 // while we render.
573 if (!inExpose) {
574 qCDebug(QSG_LOG_RENDERLOOP, QSG_RT_PAD, "- sync complete, waking Gui");
575 waitCondition.wakeOne();
576 mutex.unlock();
577 }
578}
579
581{
582 QQuickWindowPrivate *wd = QQuickWindowPrivate::get(window);
583 wd->cleanupNodesOnShutdown();
584 sgrc->invalidate();
585 wm->releaseSwapchain(window);
586 if (ownRhi)
587 QSGRhiSupport::instance()->destroyRhi(rhi, {});
588 rhi = nullptr;
589 wd->rhi = nullptr;
590}
591
593{
594 if (!rhi || !rhi->isDeviceLost())
595 return;
596
597 qWarning("Graphics device lost, cleaning up scenegraph and releasing RHI");
599 rhiDeviceLost = true;
600}
601
603{
604 const bool profileFrames = QSG_LOG_TIME_RENDERLOOP().isDebugEnabled();
605 QElapsedTimer threadTimer;
606 qint64 syncTime = 0, renderTime = 0;
607 if (profileFrames)
608 threadTimer.start();
609 Q_TRACE_SCOPE(QSG_syncAndRender);
610 Q_QUICK_SG_PROFILE_START(QQuickProfiler::SceneGraphRenderLoopFrame);
611 Q_TRACE(QSG_sync_entry);
612
613 qCDebug(QSG_LOG_RENDERLOOP, QSG_RT_PAD, "syncAndRender()");
614
615 if (profileFrames) {
616 const qint64 elapsedSinceLastMs = m_threadTimeBetweenRenders.restart();
617 qCDebug(QSG_LOG_TIME_RENDERLOOP, "[window %p][render thread %p] syncAndRender: start, elapsed since last call: %d ms",
618 window,
619 QThread::currentThread(),
620 int(elapsedSinceLastMs));
621 }
622
623 QQuickWindowPrivate *d = QQuickWindowPrivate::get(window);
624
625 const bool syncRequested = (pendingUpdate & SyncRequest);
626 const bool exposeRequested = (pendingUpdate & ExposeRequest) == ExposeRequest;
627 pendingUpdate = 0;
628
629 QQuickWindowPrivate *cd = QQuickWindowPrivate::get(window);
630 QSGRhiSupport *rhiSupport = QSGRhiSupport::instance();
631 // Begin the frame before syncing -> sync is where we may invoke
632 // updatePaintNode() on the items and they may want to do resource updates.
633 // Also relevant for applications that connect to the before/afterSynchronizing
634 // signals and want to do graphics stuff already there.
635 const bool hasValidSwapChain = (cd->swapchain && windowSize.width() > 0 && windowSize.height() > 0);
636 if (hasValidSwapChain) {
637 cd->swapchain->setProxyData(scProxyData);
638 // always prefer what the surface tells us, not the QWindow
639 const QSize effectiveOutputSize = cd->swapchain->surfacePixelSize();
640 // An update request could still be delivered right before we get an
641 // unexpose. With Vulkan on Windows for example attempting to render
642 // leads to failures at this stage since the surface size is already 0.
643 if (effectiveOutputSize.isEmpty()) {
644 if (syncRequested) {
645 mutex.lock();
646 waitCondition.wakeOne();
647 mutex.unlock();
648 }
649 return;
650 }
651
652 const QSize previousOutputSize = cd->swapchain->currentPixelSize();
653 if (!cd->hasActiveSwapchain || previousOutputSize != effectiveOutputSize || cd->swapchainJustBecameRenderable || swapchainOutOfDate) {
654 if (cd->swapchainJustBecameRenderable)
655 qCDebug(QSG_LOG_RENDERLOOP, QSG_RT_PAD, "just became exposed");
657 qCDebug(QSG_LOG_RENDERLOOP, QSG_RT_PAD, "swapchain out of date");
658
659 cd->hasActiveSwapchain = cd->swapchain->createOrResize();
660 if (!cd->hasActiveSwapchain) {
661 cd->hasRenderableSwapchain = false;
662 bool bailOut = false;
663 if (rhi->isDeviceLost()) {
665 bailOut = true;
666 } else if (previousOutputSize.isEmpty() && !swRastFallbackDueToSwapchainFailure && rhiSupport->attemptReinitWithSwRastUponFail()) {
667 qWarning("Failed to create swapchain."
668 " Retrying by requesting a software rasterizer, if applicable for the 3D API implementation.");
671 bailOut = true;
672 }
673 if (bailOut)
674 QCoreApplication::postEvent(window, new QEvent(QEvent::Type(QQuickWindowPrivate::FullUpdateRequest)));
675 else
676 qWarning("Failed to build or resize swapchain");
677 if (syncRequested) {
678 // Lock like sync() would do. Note that exposeRequested always includes syncRequested.
679 qCDebug(QSG_LOG_RENDERLOOP, QSG_RT_PAD, "- bailing out due to failed swapchain init, wake Gui");
680 mutex.lock();
681 waitCondition.wakeOne();
682 mutex.unlock();
683 }
684 return;
685 }
686
687 cd->swapchainJustBecameRenderable = false;
688 swapchainOutOfDate = false;
689 cd->hasRenderableSwapchain = cd->hasActiveSwapchain;
690
691 qCDebug(QSG_LOG_RENDERLOOP) << "rhi swapchain size" << cd->swapchain->currentPixelSize();
692 }
693
694 emit window->beforeFrameBegin();
695
696 Q_ASSERT(rhi == cd->rhi);
697 QRhi::FrameOpResult frameResult = rhi->beginFrame(cd->swapchain);
698 if (frameResult != QRhi::FrameOpSuccess) {
699 if (frameResult == QRhi::FrameOpDeviceLost)
701 else if (frameResult == QRhi::FrameOpError)
702 qWarning("Failed to start frame");
703 else if (frameResult == QRhi::FrameOpSwapChainOutOfDate)
704 swapchainOutOfDate = true;
705 // try again later
706 if (frameResult == QRhi::FrameOpDeviceLost || frameResult == QRhi::FrameOpSwapChainOutOfDate)
707 QCoreApplication::postEvent(window, new QEvent(QEvent::Type(QQuickWindowPrivate::FullUpdateRequest)));
708 // Before returning we need to ensure the same wake up logic that
709 // would have happened if beginFrame() had suceeded.
710 if (syncRequested) {
711 // Lock like sync() would do. Note that exposeRequested always includes syncRequested.
712 qCDebug(QSG_LOG_RENDERLOOP, QSG_RT_PAD, "- bailing out due to failed beginFrame, wake Gui");
713 mutex.lock();
714 // Go ahead with waking because we will return right after this.
715 waitCondition.wakeOne();
716 mutex.unlock();
717 }
718 emit window->afterFrameEnd();
719 return;
720 }
721 }
722
723 if (syncRequested) {
724 qCDebug(QSG_LOG_RENDERLOOP, QSG_RT_PAD, "- updatePending, doing sync");
725 sync(exposeRequested);
726 }
727#ifndef QSG_NO_RENDER_TIMING
728 if (profileFrames)
729 syncTime = threadTimer.nsecsElapsed();
730#endif
731 Q_TRACE(QSG_sync_exit);
732 Q_QUICK_SG_PROFILE_RECORD(QQuickProfiler::SceneGraphRenderLoopFrame,
733 QQuickProfiler::SceneGraphRenderLoopSync);
734
735 // In Qt 6 this function always completes and presents a frame. This is
736 // more compatible with what the basic render loop (or a custom loop with
737 // QQuickRenderControl) would do, is more accurate due to not having to do
738 // an msleep() with an inaccurate interval, and avoids misunderstandings
739 // for signals like frameSwapped(). (in Qt 5 a continuously "updating"
740 // window is continuously presenting frames with the basic loop, but not
741 // with threaded due to aborting when sync() finds there are no relevant
742 // visual changes in the scene graph; this system proved to be simply too
743 // confusing in practice)
744
745 qCDebug(QSG_LOG_RENDERLOOP, QSG_RT_PAD, "- rendering started");
746
747 Q_TRACE(QSG_render_entry);
748
749 // RepaintRequest may have been set in pendingUpdate in an
750 // updatePaintNode() invoked from sync(). We are about to do a repaint
751 // right now, so reset the flag. (bits other than RepaintRequest cannot
752 // be set in pendingUpdate at this point)
753 pendingUpdate = 0;
754
755 // Advance render thread animations (from the QQuickAnimator subclasses).
756 if (animatorDriver->isRunning()) {
757 d->animationController->lock();
758 animatorDriver->advance();
759 d->animationController->unlock();
760 }
761
762 // Zero size windows do not initialize a swapchain and
763 // rendercontext. So no sync or render can be done then.
764 const bool canRender = d->renderer && hasValidSwapChain;
765 double lastCompletedGpuTime = 0;
766 if (canRender) {
767 if (!syncRequested) // else this was already done in sync()
768 rhi->makeThreadLocalNativeContextCurrent();
769
770 d->renderSceneGraph();
771
772 if (profileFrames)
773 renderTime = threadTimer.nsecsElapsed();
774 Q_TRACE(QSG_render_exit);
775 Q_QUICK_SG_PROFILE_RECORD(QQuickProfiler::SceneGraphRenderLoopFrame,
776 QQuickProfiler::SceneGraphRenderLoopRender);
777 Q_TRACE(QSG_swap_entry);
778
779 QRhi::FrameOpResult frameResult = rhi->endFrame(cd->swapchain);
780 if (frameResult != QRhi::FrameOpSuccess) {
781 if (frameResult == QRhi::FrameOpDeviceLost)
783 else if (frameResult == QRhi::FrameOpError)
784 qWarning("Failed to end frame");
785 else if (frameResult == QRhi::FrameOpSwapChainOutOfDate)
786 swapchainOutOfDate = true;
787 if (frameResult == QRhi::FrameOpDeviceLost || frameResult == QRhi::FrameOpSwapChainOutOfDate)
788 QCoreApplication::postEvent(window, new QEvent(QEvent::Type(QQuickWindowPrivate::FullUpdateRequest)));
789 } else {
790 lastCompletedGpuTime = cd->swapchain->currentFrameCommandBuffer()->lastCompletedGpuTime();
791 }
792 d->fireFrameSwapped();
793 } else {
794 Q_TRACE(QSG_render_exit);
795 Q_QUICK_SG_PROFILE_SKIP(QQuickProfiler::SceneGraphRenderLoopFrame,
796 QQuickProfiler::SceneGraphRenderLoopSync, 1);
797 Q_TRACE(QSG_swap_entry);
798 qCDebug(QSG_LOG_RENDERLOOP, QSG_RT_PAD, "- window not ready, skipping render");
799 // Make sure a beginFrame() always gets an endFrame(). We could have
800 // started a frame but then not have a valid renderer (if there was no
801 // sync). So gracefully handle that.
802 if (cd->swapchain && rhi->isRecordingFrame())
803 rhi->endFrame(cd->swapchain, QRhi::SkipPresent);
804 }
805
806 qCDebug(QSG_LOG_RENDERLOOP, QSG_RT_PAD, "- rendering done");
807
808 // beforeFrameBegin - afterFrameEnd must always come in pairs; if there was
809 // no before due to 0 size then there shouldn't be an after either
810 if (hasValidSwapChain)
811 emit window->afterFrameEnd();
812
813 // Though it would be more correct to put this block directly after
814 // fireFrameSwapped in the if (current) branch above, we don't do
815 // that to avoid blocking the GUI thread in the case where it
816 // has started rendering with a bad window, causing makeCurrent to
817 // fail or if the window has a bad size.
818 if (exposeRequested) {
819 // With expose sync() did not wake gui, do it now.
820 qCDebug(QSG_LOG_RENDERLOOP, QSG_RT_PAD, "- wake Gui after expose");
821 waitCondition.wakeOne();
822 mutex.unlock();
823 }
824
825 if (profileFrames) {
826 // Beware that there is no guarantee the graphics stack always
827 // blocks for a full vsync in beginFrame() or endFrame(). (because
828 // e.g. there is no guarantee that OpenGL blocks in swapBuffers(),
829 // it may block elsewhere; also strategies may change once there
830 // are multiple windows) So process the results printed here with
831 // caution and pay attention to the elapsed-since-last-call time
832 // printed at the beginning of the function too.
833 qCDebug(QSG_LOG_TIME_RENDERLOOP,
834 "[window %p][render thread %p] syncAndRender: frame rendered in %dms, sync=%d, render=%d, swap=%d",
835 window,
836 QThread::currentThread(),
837 int(threadTimer.elapsed()),
838 int((syncTime/1000000)),
839 int((renderTime - syncTime) / 1000000),
840 int((threadTimer.nsecsElapsed() - renderTime) / 1000000));
841 if (!qFuzzyIsNull(lastCompletedGpuTime) && cd->graphicsConfig.timestampsEnabled()) {
842 qCDebug(QSG_LOG_TIME_RENDERLOOP, "[window %p][render thread %p] syncAndRender: last retrieved GPU frame time was %.4f ms",
843 window,
844 QThread::currentThread(),
845 lastCompletedGpuTime * 1000.0);
846 }
847 }
848
849 Q_TRACE(QSG_swap_exit);
850 Q_QUICK_SG_PROFILE_END(QQuickProfiler::SceneGraphRenderLoopFrame,
851 QQuickProfiler::SceneGraphRenderLoopSwap);
852}
853
854
855
857{
858 eventQueue.addEvent(e);
859}
860
861
862
864{
865 qCDebug(QSG_LOG_RENDERLOOP, QSG_RT_PAD, "--- begin processEvents()");
866 while (eventQueue.hasMoreEvents()) {
867 QEvent *e = eventQueue.takeEvent(false);
868 event(e);
869 delete e;
870 }
871 qCDebug(QSG_LOG_RENDERLOOP, QSG_RT_PAD, "--- done processEvents()");
872}
873
875{
876 qCDebug(QSG_LOG_RENDERLOOP, QSG_RT_PAD, "--- begin processEventsAndWaitForMore()");
877 stopEventProcessing = false;
878 while (!stopEventProcessing) {
879 QEvent *e = eventQueue.takeEvent(true);
880 event(e);
881 delete e;
882 }
883 qCDebug(QSG_LOG_RENDERLOOP, QSG_RT_PAD, "--- done processEventsAndWaitForMore()");
884}
885
887{
888 if (!rhi) {
889 if (rhiDoomed) // no repeated attempts if the initial attempt failed
890 return;
891 QSGRhiSupport *rhiSupport = QSGRhiSupport::instance();
892 const bool forcePreferSwRenderer = swRastFallbackDueToSwapchainFailure;
893 QSGRhiSupport::RhiCreateResult rhiResult = rhiSupport->createRhi(window, offscreenSurface, forcePreferSwRenderer);
894 rhi = rhiResult.rhi;
895 ownRhi = rhiResult.own;
896 if (rhi) {
897 rhiDeviceLost = false;
898 rhiSampleCount = rhiSupport->chooseSampleCountForWindowWithRhi(window, rhi);
899 } else {
900 if (!rhiDeviceLost) {
901 rhiDoomed = true;
902 qWarning("Failed to create QRhi on the render thread; scenegraph is not functional");
903 }
904 // otherwise no error, will retry on a subsequent rendering attempt
905 return;
906 }
907 }
908 if (!sgrc->rhi() && windowSize.width() > 0 && windowSize.height() > 0) {
909 // We need to guarantee that sceneGraphInitialized is emitted
910 // with a context current, if running with OpenGL.
911 rhi->makeThreadLocalNativeContextCurrent();
912 QSGDefaultRenderContext::InitParams rcParams;
913 rcParams.rhi = rhi;
914 rcParams.sampleCount = rhiSampleCount;
915 rcParams.initialSurfacePixelSize = windowSize * qreal(dpr);
916 rcParams.maybeSurface = window;
917 sgrc->initialize(&rcParams);
918 }
919 QQuickWindowPrivate *cd = QQuickWindowPrivate::get(window);
920 if (rhi && !cd->swapchain) {
921 cd->rhi = rhi;
922 QRhiSwapChain::Flags flags = QRhiSwapChain::UsedAsTransferSource; // may be used in a grab
923 const QSurfaceFormat requestedFormat = window->requestedFormat();
924
925 // QQ is always premul alpha. Decide based on alphaBufferSize in
926 // requestedFormat(). (the platform plugin can override format() but
927 // what matters here is what the application wanted, hence using the
928 // requested one)
929 const bool alpha = requestedFormat.alphaBufferSize() > 0;
930 if (alpha)
931 flags |= QRhiSwapChain::SurfaceHasPreMulAlpha;
932
933 // Request NoVSync if swap interval was set to 0 (either by the app or
934 // by QSG_NO_VSYNC). What this means in practice is another question,
935 // but at least we tried.
936 if (requestedFormat.swapInterval() == 0) {
937 qCDebug(QSG_LOG_INFO, "Swap interval is 0, attempting to disable vsync when presenting.");
938 flags |= QRhiSwapChain::NoVSync;
939 }
940
941 cd->swapchain = rhi->newSwapChain();
942 static bool depthBufferEnabled = qEnvironmentVariableIsEmpty("QSG_NO_DEPTH_BUFFER");
943 if (depthBufferEnabled) {
944 cd->depthStencilForSwapchain = rhi->newRenderBuffer(QRhiRenderBuffer::DepthStencil,
945 QSize(),
947 QRhiRenderBuffer::UsedWithSwapChainOnly
948 | QSGRhiSupport::depthStencilBufferFlags());
949 cd->swapchain->setDepthStencil(cd->depthStencilForSwapchain);
950 }
951 cd->swapchain->setWindow(window);
952 cd->swapchain->setProxyData(scProxyData);
953 QSGRhiSupport::instance()->applySwapChainFormat(cd->swapchain, window);
954 qCDebug(QSG_LOG_INFO, "MSAA sample count for the swapchain is %d. Alpha channel requested = %s.",
955 rhiSampleCount, alpha ? "yes" : "no");
956 cd->swapchain->setSampleCount(rhiSampleCount);
957 cd->swapchain->setFlags(flags);
958 cd->rpDescForSwapchain = cd->swapchain->newCompatibleRenderPassDescriptor();
959 cd->swapchain->setRenderPassDescriptor(cd->rpDescForSwapchain);
960 }
961}
962
964{
965 qCDebug(QSG_LOG_RENDERLOOP, QSG_RT_PAD, "run()");
966 animatorDriver = sgrc->sceneGraphContext()->createAnimationDriver(nullptr);
967 animatorDriver->install();
968 if (QQmlDebugConnector::service<QQmlProfilerService>())
969 QQuickProfiler::registerAnimationCallback();
970
971 m_threadTimeBetweenRenders.start();
972
973 while (active) {
974#ifdef Q_OS_DARWIN
975 QMacAutoReleasePool frameReleasePool;
976#endif
977
978 if (window) {
980
981 // We absolutely have to syncAndRender() here, even when QRhi
982 // failed to initialize otherwise the gui thread will be left
983 // in a blocked state. It is up to syncAndRender() to
984 // gracefully skip all graphics stuff when rhi is null.
985
987
988 // Now we can do something about rhi init failures. (reinit
989 // failure after device reset does not count)
992 QEvent *e = new QEvent(QEvent::Type(QQuickWindowPrivate::TriggerContextCreationFailure));
993 QCoreApplication::postEvent(window, e);
994 }
995 }
996
998 QCoreApplication::processEvents();
999
1000 if (active && (pendingUpdate == 0 || !window)) {
1001 qCDebug(QSG_LOG_RENDERLOOP, QSG_RT_PAD, "done drawing, sleep...");
1002 sleeping = true;
1004 sleeping = false;
1005 }
1006 }
1007
1008 Q_ASSERT_X(!rhi, "QSGRenderThread::run()", "The graphics context should be cleaned up before exiting the render thread...");
1009
1010 qCDebug(QSG_LOG_RENDERLOOP, QSG_RT_PAD, "run() completed");
1011
1012 delete animatorDriver;
1013 animatorDriver = nullptr;
1014
1015 sgrc->moveToThread(wm->thread());
1016 moveToThread(wm->thread());
1017}
1018
1019QSGThreadedRenderLoop::QSGThreadedRenderLoop()
1020 : sg(QSGContext::createDefaultContext())
1021 , m_animation_timer(0)
1022{
1023 m_animation_driver = sg->createAnimationDriver(this);
1024
1025 connect(m_animation_driver, SIGNAL(started()), this, SLOT(animationStarted()));
1026 connect(m_animation_driver, SIGNAL(stopped()), this, SLOT(animationStopped()));
1027
1028 m_animation_driver->install();
1029}
1030
1032{
1033 qDeleteAll(pendingRenderContexts);
1034 delete sg;
1035}
1036
1037QSGRenderContext *QSGThreadedRenderLoop::createRenderContext(QSGContext *sg) const
1038{
1039 auto context = sg->createRenderContext();
1040 pendingRenderContexts.insert(context);
1041 return context;
1042}
1043
1044void QSGThreadedRenderLoop::postUpdateRequest(Window *w)
1045{
1046 w->window->requestUpdate();
1047}
1048
1049QAnimationDriver *QSGThreadedRenderLoop::animationDriver() const
1050{
1051 return m_animation_driver;
1052}
1053
1055{
1056 return sg;
1057}
1058
1059bool QSGThreadedRenderLoop::anyoneShowing() const
1060{
1061 for (int i=0; i<m_windows.size(); ++i) {
1062 QQuickWindow *c = m_windows.at(i).window;
1063 if (c->isVisible() && c->isExposed())
1064 return true;
1065 }
1066 return false;
1067}
1068
1070{
1071 return m_animation_driver->isRunning() && anyoneShowing();
1072}
1073
1074void QSGThreadedRenderLoop::animationStarted()
1075{
1076 qCDebug(QSG_LOG_RENDERLOOP, "- animationStarted()");
1077 startOrStopAnimationTimer();
1078
1079 for (int i=0; i<m_windows.size(); ++i)
1080 postUpdateRequest(const_cast<Window *>(&m_windows.at(i)));
1081}
1082
1084{
1085 qCDebug(QSG_LOG_RENDERLOOP, "- animationStopped()");
1086 startOrStopAnimationTimer();
1087}
1088
1089
1090void QSGThreadedRenderLoop::startOrStopAnimationTimer()
1091{
1092 if (!sg->isVSyncDependent(m_animation_driver))
1093 return;
1094
1095 int exposedWindows = 0;
1096 int unthrottledWindows = 0;
1097 int badVSync = 0;
1098 const Window *theOne = nullptr;
1099 for (int i=0; i<m_windows.size(); ++i) {
1100 const Window &w = m_windows.at(i);
1101 if (w.window->isVisible() && w.window->isExposed()) {
1102 ++exposedWindows;
1103 theOne = &w;
1104 if (w.actualWindowFormat.swapInterval() == 0)
1105 ++unthrottledWindows;
1106 if (w.badVSync)
1107 ++badVSync;
1108 }
1109 }
1110
1111 // Best case: with 1 exposed windows we can advance regular animations in
1112 // polishAndSync() and rely on being throttled to vsync. (no normal system
1113 // timer needed)
1114 //
1115 // Special case: with no windows exposed (e.g. on Windows: all of them are
1116 // minimized) run a normal system timer to make non-visual animation
1117 // functional still.
1118 //
1119 // Not so ideal case: with more than one window exposed we have to use the
1120 // same path as the no-windows case since polishAndSync() is now called
1121 // potentially for multiple windows over time so it cannot take care of
1122 // advancing the animation driver anymore.
1123 //
1124 // On top, another case: a window with vsync disabled should disable all the
1125 // good stuff and go with the system timer.
1126 //
1127 // Similarly, if there is at least one window where we determined that
1128 // vsync based blocking is not working as expected, that should make us
1129 // choose the timer based way.
1130
1131 const bool canUseVSyncBasedAnimation = exposedWindows == 1 && unthrottledWindows == 0 && badVSync == 0;
1132
1133 if (m_animation_timer != 0 && (canUseVSyncBasedAnimation || !m_animation_driver->isRunning())) {
1134 qCDebug(QSG_LOG_RENDERLOOP, "*** Stopping system (not vsync-based) animation timer (exposedWindows=%d unthrottledWindows=%d badVSync=%d)",
1135 exposedWindows, unthrottledWindows, badVSync);
1136 killTimer(m_animation_timer);
1137 m_animation_timer = 0;
1138 // If animations are running, make sure we keep on animating
1139 if (m_animation_driver->isRunning())
1140 postUpdateRequest(const_cast<Window *>(theOne));
1141 } else if (m_animation_timer == 0 && !canUseVSyncBasedAnimation && m_animation_driver->isRunning()) {
1142 qCDebug(QSG_LOG_RENDERLOOP, "*** Starting system (not vsync-based) animation timer (exposedWindows=%d unthrottledWindows=%d badVSync=%d)",
1143 exposedWindows, unthrottledWindows, badVSync);
1144 m_animation_timer = startTimer(int(sg->vsyncIntervalForAnimationDriver(m_animation_driver)));
1145 }
1146}
1147
1148/*
1149 Removes this window from the list of tracked windowes in this
1150 window manager. hide() will trigger obscure, which in turn will
1151 stop rendering.
1152
1153 This function will be called during QWindow::close() which will
1154 also destroy the QPlatformWindow so it is important that this
1155 triggers handleObscurity() and that rendering for that window
1156 is fully done and over with by the time this function exits.
1157 */
1158
1159void QSGThreadedRenderLoop::hide(QQuickWindow *window)
1160{
1161 qCDebug(QSG_LOG_RENDERLOOP) << "hide()" << window;
1162
1163 if (window->isExposed())
1164 handleObscurity(windowFor(window));
1165
1166 releaseResources(window);
1167}
1168
1169void QSGThreadedRenderLoop::resize(QQuickWindow *window)
1170{
1171 qCDebug(QSG_LOG_RENDERLOOP) << "resize()" << window;
1172
1173 Window *w = windowFor(window);
1174 if (!w)
1175 return;
1176
1177 w->psTimeAccumulator = 0.0f;
1178 w->psTimeSampleCount = 0;
1179}
1180
1181/*
1182 If the window is first hide it, then perform a complete cleanup
1183 with releaseResources which will take down the GL context and
1184 exit the rendering thread.
1185 */
1186void QSGThreadedRenderLoop::windowDestroyed(QQuickWindow *window)
1187{
1188 qCDebug(QSG_LOG_RENDERLOOP) << "begin windowDestroyed()" << window;
1189
1190 Window *w = windowFor(window);
1191 if (!w)
1192 return;
1193
1194 handleObscurity(w);
1195 releaseResources(w, true);
1196
1197 QSGRenderThread *thread = w->thread;
1198 while (thread->isRunning())
1199 QThread::yieldCurrentThread();
1200 Q_ASSERT(thread->thread() == QThread::currentThread());
1201 delete thread;
1202
1203 for (int i=0; i<m_windows.size(); ++i) {
1204 if (m_windows.at(i).window == window) {
1205 m_windows.removeAt(i);
1206 break;
1207 }
1208 }
1209
1210 // Now that we altered the window list, we may need to stop the animation
1211 // timer even if we didn't via handleObscurity. This covers the case where
1212 // we destroy a visible & exposed QQuickWindow.
1213 startOrStopAnimationTimer();
1214
1215 qCDebug(QSG_LOG_RENDERLOOP) << "done windowDestroyed()" << window;
1216}
1217
1218void QSGThreadedRenderLoop::releaseSwapchain(QQuickWindow *window)
1219{
1220 QQuickWindowPrivate *wd = QQuickWindowPrivate::get(window);
1221 delete wd->rpDescForSwapchain;
1222 wd->rpDescForSwapchain = nullptr;
1223 delete wd->swapchain;
1224 wd->swapchain = nullptr;
1225 delete wd->depthStencilForSwapchain;
1226 wd->depthStencilForSwapchain = nullptr;
1227 wd->hasActiveSwapchain = wd->hasRenderableSwapchain = wd->swapchainJustBecameRenderable = false;
1228}
1229
1230void QSGThreadedRenderLoop::exposureChanged(QQuickWindow *window)
1231{
1232 qCDebug(QSG_LOG_RENDERLOOP) << "exposureChanged()" << window;
1233
1234 // This is tricker than used to be. We want to detect having an empty
1235 // surface size (which may be the case even when window->size() is
1236 // non-empty, on some platforms with some graphics APIs!) as well as the
1237 // case when the window just became "newly exposed" (e.g. after a
1238 // minimize-restore on Windows, or when switching between fully obscured -
1239 // not fully obscured on macOS)
1240 QQuickWindowPrivate *wd = QQuickWindowPrivate::get(window);
1241 if (!window->isExposed())
1242 wd->hasRenderableSwapchain = false;
1243
1244 bool skipThisExpose = false;
1245 if (window->isExposed() && wd->hasActiveSwapchain && wd->swapchain->surfacePixelSize().isEmpty()) {
1246 wd->hasRenderableSwapchain = false;
1247 skipThisExpose = true;
1248 }
1249
1250 if (window->isExposed() && !wd->hasRenderableSwapchain && wd->hasActiveSwapchain
1251 && !wd->swapchain->surfacePixelSize().isEmpty())
1252 {
1253 wd->hasRenderableSwapchain = true;
1254 wd->swapchainJustBecameRenderable = true;
1255 }
1256
1257 if (window->isExposed()) {
1258 if (!skipThisExpose)
1259 handleExposure(window);
1260 } else {
1261 Window *w = windowFor(window);
1262 if (w)
1263 handleObscurity(w);
1264 }
1265}
1266
1267/*
1268 Will post an event to the render thread that this window should
1269 start to render.
1270 */
1271void QSGThreadedRenderLoop::handleExposure(QQuickWindow *window)
1272{
1273 qCDebug(QSG_LOG_RENDERLOOP) << "handleExposure()" << window;
1274
1275 Window *w = windowFor(window);
1276 if (!w) {
1277 qCDebug(QSG_LOG_RENDERLOOP, "- adding window to list");
1278 Window win;
1279 win.window = window;
1280 win.actualWindowFormat = window->format();
1281 auto renderContext = QQuickWindowPrivate::get(window)->context;
1282 // The thread assumes ownership, so we don't need to delete it later.
1283 pendingRenderContexts.remove(renderContext);
1284 win.thread = new QSGRenderThread(this, renderContext);
1285 win.updateDuringSync = false;
1286 win.forceRenderPass = true; // also covered by polishAndSync(inExpose=true), but doesn't hurt
1287 win.badVSync = false;
1288 win.timeBetweenPolishAndSyncs.start();
1289 win.psTimeAccumulator = 0.0f;
1290 win.psTimeSampleCount = 0;
1291 m_windows << win;
1292 w = &m_windows.last();
1293 } else {
1294 if (!QQuickWindowPrivate::get(window)->updatesEnabled) {
1295 qCDebug(QSG_LOG_RENDERLOOP, "- updatesEnabled is false, abort");
1296 return;
1297 }
1298 }
1299
1300#ifndef QT_NO_DEBUG
1301 if (w->window->width() <= 0 || w->window->height() <= 0
1302 || (w->window->isTopLevel() && !w->window->geometry().intersects(w->window->screen()->availableGeometry()))) {
1303 qWarning().noquote().nospace() << "QSGThreadedRenderLoop: expose event received for window "
1304 << w->window << " with invalid geometry: " << w->window->geometry()
1305 << " on " << w->window->screen();
1306 }
1307#endif
1308
1309 // Because we are going to bind a GL context to it, make sure it
1310 // is created.
1311 if (!w->window->handle())
1312 w->window->create();
1313
1314 // Start render thread if it is not running
1315 if (!w->thread->isRunning()) {
1316 qCDebug(QSG_LOG_RENDERLOOP, "- starting render thread");
1317
1318 // set this early as we'll be rendering shortly anyway and this avoids
1319 // specialcasing exposure in polishAndSync.
1320 w->thread->window = window;
1321
1322 if (!w->thread->rhi) {
1323 QSGRhiSupport *rhiSupport = QSGRhiSupport::instance();
1324 if (!w->thread->offscreenSurface)
1325 w->thread->offscreenSurface = rhiSupport->maybeCreateOffscreenSurface(window);
1326 w->thread->scProxyData = QRhi::updateSwapChainProxyData(rhiSupport->rhiBackend(), window);
1327 window->installEventFilter(this);
1328 }
1329
1330 QQuickAnimatorController *controller
1331 = QQuickWindowPrivate::get(w->window)->animationController.get();
1332 if (controller->thread() != w->thread)
1333 controller->moveToThread(w->thread);
1334
1335 w->thread->active = true;
1336 if (w->thread->thread() == QThread::currentThread()) {
1337 w->thread->sgrc->moveToThread(w->thread);
1338 w->thread->moveToThread(w->thread);
1339 }
1340 w->thread->start();
1341 if (!w->thread->isRunning())
1342 qFatal("Render thread failed to start, aborting application.");
1343
1344 } else {
1345 qCDebug(QSG_LOG_RENDERLOOP, "- render thread already running");
1346
1347 // set w->thread->window here too, but using an event so it's thread-safe
1348 w->thread->mutex.lock();
1349 w->thread->postEvent(new WMWindowEvent(w->window, QEvent::Type(WM_Exposed)));
1350 w->thread->waitCondition.wait(&w->thread->mutex);
1351 w->thread->mutex.unlock();
1352 }
1353
1354 polishAndSync(w, true);
1355 qCDebug(QSG_LOG_RENDERLOOP, "- done with handleExposure()");
1356
1357 startOrStopAnimationTimer();
1358}
1359
1360/*
1361 This function posts an event to the render thread to remove the window
1362 from the list of windowses to render.
1363
1364 It also starts up the non-vsync animation tick if no more windows
1365 are showing.
1366 */
1367void QSGThreadedRenderLoop::handleObscurity(Window *w)
1368{
1369 if (!w)
1370 return;
1371
1372 qCDebug(QSG_LOG_RENDERLOOP) << "handleObscurity()" << w->window;
1373 if (w->thread->isRunning()) {
1374 if (!QQuickWindowPrivate::get(w->window)->updatesEnabled) {
1375 qCDebug(QSG_LOG_RENDERLOOP, "- updatesEnabled is false, abort");
1376 return;
1377 }
1378 w->thread->mutex.lock();
1379 w->thread->postEvent(new WMWindowEvent(w->window, QEvent::Type(WM_Obscure)));
1380 w->thread->waitCondition.wait(&w->thread->mutex);
1381 w->thread->mutex.unlock();
1382 }
1383 startOrStopAnimationTimer();
1384}
1385
1386bool QSGThreadedRenderLoop::eventFilter(QObject *watched, QEvent *event)
1387{
1388 switch (event->type()) {
1389 case QEvent::PlatformSurface:
1390 // this is the proper time to tear down the swapchain (while the native window and surface are still around)
1391 if (static_cast<QPlatformSurfaceEvent *>(event)->surfaceEventType() == QPlatformSurfaceEvent::SurfaceAboutToBeDestroyed) {
1392 QQuickWindow *window = qobject_cast<QQuickWindow *>(watched);
1393 if (window) {
1394 Window *w = windowFor(window);
1395 if (w && w->thread->isRunning()) {
1396 w->thread->mutex.lock();
1397 w->thread->postEvent(new WMReleaseSwapchainEvent(window));
1398 w->thread->waitCondition.wait(&w->thread->mutex);
1399 w->thread->mutex.unlock();
1400 }
1401 }
1402 // keep this filter on the window - needed for uncommon but valid
1403 // sequences of calls like window->destroy(); window->show();
1404 }
1405 break;
1406 default:
1407 break;
1408 }
1409 return QObject::eventFilter(watched, event);
1410}
1411
1413{
1414 qCDebug(QSG_LOG_RENDERLOOP) << "- update request" << window;
1415 if (!QQuickWindowPrivate::get(window)->updatesEnabled) {
1416 qCDebug(QSG_LOG_RENDERLOOP, "- updatesEnabled is false, abort");
1417 return;
1418 }
1419 Window *w = windowFor(window);
1420 if (w)
1421 polishAndSync(w);
1422}
1423
1424void QSGThreadedRenderLoop::maybeUpdate(QQuickWindow *window)
1425{
1426 Window *w = windowFor(window);
1427 if (w)
1428 maybeUpdate(w);
1429}
1430
1431/*
1432 Called whenever the QML scene has changed. Will post an event to
1433 ourselves that a sync is needed.
1434 */
1435void QSGThreadedRenderLoop::maybeUpdate(Window *w)
1436{
1437 if (!QCoreApplication::instance())
1438 return;
1439
1440 if (!w || !w->thread->isRunning())
1441 return;
1442
1443 QThread *current = QThread::currentThread();
1444 if (current == w->thread && w->thread->rhi && w->thread->rhi->isDeviceLost())
1445 return;
1446 if (current != QCoreApplication::instance()->thread() && (current != w->thread || !m_lockedForSync)) {
1447 qWarning() << "Updates can only be scheduled from GUI thread or from QQuickItem::updatePaintNode()";
1448 return;
1449 }
1450
1451 qCDebug(QSG_LOG_RENDERLOOP) << "update from item" << w->window;
1452
1453 // Call this function from the Gui thread later as startTimer cannot be
1454 // called from the render thread.
1455 if (current == w->thread) {
1456 qCDebug(QSG_LOG_RENDERLOOP, "- on render thread");
1457 w->updateDuringSync = true;
1458 return;
1459 }
1460
1461 // An updatePolish() implementation may call update() to get the QQuickItem
1462 // dirtied. That's fine but it also leads to calling this function.
1463 // Requesting another update is a waste then since the updatePolish() call
1464 // will be followed up with a round of sync and render.
1465 if (m_inPolish)
1466 return;
1467
1468 postUpdateRequest(w);
1469}
1470
1471/*
1472 Called when the QQuickWindow should be explicitly repainted. This function
1473 can also be called on the render thread when the GUI thread is blocked to
1474 keep render thread animations alive.
1475 */
1476void QSGThreadedRenderLoop::update(QQuickWindow *window)
1477{
1478 Window *w = windowFor(window);
1479 if (!w)
1480 return;
1481
1482 const bool isRenderThread = QThread::currentThread() == w->thread;
1483
1484 if (QPlatformWindow *platformWindow = window->handle()) {
1485 // If the window is being resized we don't want to schedule unthrottled
1486 // updates on the render thread, as this will starve the main thread
1487 // from getting drawables for displaying the updated window size.
1488 if (isRenderThread && !platformWindow->allowsIndependentThreadedRendering()) {
1489 // In most cases the window will already have update requested
1490 // due to the animator triggering a sync, but just in case we
1491 // schedule an update request on the main thread explicitly.
1492 qCDebug(QSG_LOG_RENDERLOOP) << "window is resizing. update on window" << w->window;
1493 QTimer::singleShot(0, window, &QWindow::requestUpdate);
1494 return;
1495 }
1496 }
1497
1498 if (isRenderThread) {
1499 qCDebug(QSG_LOG_RENDERLOOP) << "update on window - on render thread" << w->window;
1500 w->thread->requestRepaint();
1501 return;
1502 }
1503
1504 qCDebug(QSG_LOG_RENDERLOOP) << "update on window" << w->window;
1505 // We set forceRenderPass because we want to make sure the QQuickWindow
1506 // actually does a full render pass after the next sync.
1507 w->forceRenderPass = true;
1508 maybeUpdate(w);
1509}
1510
1511
1512void QSGThreadedRenderLoop::releaseResources(QQuickWindow *window)
1513{
1514 Window *w = windowFor(window);
1515 if (w)
1516 releaseResources(w, false);
1517}
1518
1519/*
1520 * Release resources will post an event to the render thread to
1521 * free up the SG and GL resources and exists the render thread.
1522 */
1523void QSGThreadedRenderLoop::releaseResources(Window *w, bool inDestructor)
1524{
1525 qCDebug(QSG_LOG_RENDERLOOP) << "releaseResources()" << (inDestructor ? "in destructor" : "in api-call") << w->window;
1526
1527 w->thread->mutex.lock();
1528 if (w->thread->isRunning() && w->thread->active) {
1529 QQuickWindow *window = w->window;
1530
1531 // The platform window might have been destroyed before
1532 // hide/release/windowDestroyed is called, so we may need to have a
1533 // fallback surface to perform the cleanup of the scene graph and the
1534 // RHI resources.
1535
1536 qCDebug(QSG_LOG_RENDERLOOP, "- posting release request to render thread");
1537 w->thread->postEvent(new WMTryReleaseEvent(window, inDestructor, window->handle() == nullptr));
1538 w->thread->waitCondition.wait(&w->thread->mutex);
1539
1540 // Avoid a shutdown race condition.
1541 // If SG is invalidated and 'active' becomes false, the thread's run()
1542 // method will exit. handleExposure() relies on QThread::isRunning() (because it
1543 // potentially needs to start the thread again) and our mutex cannot be used to
1544 // track the thread stopping, so we wait a few nanoseconds extra so the thread
1545 // can exit properly.
1546 if (!w->thread->active) {
1547 qCDebug(QSG_LOG_RENDERLOOP) << " - waiting for render thread to exit" << w->window;
1548 w->thread->wait();
1549 qCDebug(QSG_LOG_RENDERLOOP) << " - render thread finished" << w->window;
1550 }
1551 }
1552 w->thread->mutex.unlock();
1553}
1554
1555
1556/* Calls polish on all items, then requests synchronization with the render thread
1557 * and blocks until that is complete. Returns false if it aborted; otherwise true.
1558 */
1559void QSGThreadedRenderLoop::polishAndSync(Window *w, bool inExpose)
1560{
1561 qCDebug(QSG_LOG_RENDERLOOP) << "polishAndSync" << (inExpose ? "(in expose)" : "(normal)") << w->window;
1562
1563 QQuickWindow *window = w->window;
1564 if (!w->thread || !w->thread->window) {
1565 qCDebug(QSG_LOG_RENDERLOOP, "- not exposed, abort");
1566 return;
1567 }
1568
1569 // Flush pending touch events.
1570 QQuickWindowPrivate::get(window)->deliveryAgentPrivate()->flushFrameSynchronousEvents(window);
1571 // The delivery of the event might have caused the window to stop rendering
1572 w = windowFor(window);
1573 if (!w || !w->thread || !w->thread->window) {
1574 qCDebug(QSG_LOG_RENDERLOOP, "- removed after event flushing, abort");
1575 return;
1576 }
1577
1578 Q_TRACE_SCOPE(QSG_polishAndSync);
1579 QElapsedTimer timer;
1580 qint64 polishTime = 0;
1581 qint64 waitTime = 0;
1582 qint64 syncTime = 0;
1583
1584 const qint64 elapsedSinceLastMs = w->timeBetweenPolishAndSyncs.restart();
1585
1586 if (w->actualWindowFormat.swapInterval() != 0 && sg->isVSyncDependent(m_animation_driver)) {
1587 w->psTimeAccumulator += elapsedSinceLastMs;
1588 w->psTimeSampleCount += 1;
1589 // cannot be too high because we'd then delay recognition of broken vsync at start
1590 static const int PS_TIME_SAMPLE_LENGTH = 20;
1591 if (w->psTimeSampleCount > PS_TIME_SAMPLE_LENGTH) {
1592 const float t = w->psTimeAccumulator / w->psTimeSampleCount;
1593 const float vsyncRate = sg->vsyncIntervalForAnimationDriver(m_animation_driver);
1594
1595 // What this means is that the last PS_TIME_SAMPLE_LENGTH frames
1596 // average to an elapsed time of t milliseconds, whereas the animation
1597 // driver (assuming a single window, vsync-based advancing) assumes a
1598 // vsyncRate milliseconds for a frame. If now we see that the elapsed
1599 // time is way too low (less than half of the approx. expected value),
1600 // then we assume that something is wrong with vsync.
1601 //
1602 // This will not capture everything. Consider a 144 Hz screen with 6.9
1603 // ms vsync rate, the half of that is below the default 5 ms timer of
1604 // QWindow::requestUpdate(), so this will not trigger even if the
1605 // graphics stack does not throttle. But then the whole workaround is
1606 // not that important because the animations advance anyway closer to
1607 // what's expected (e.g. advancing as if 6-7 ms passed after ca. 5 ms),
1608 // the gap is a lot smaller than with the 60 Hz case (animations
1609 // advancing as if 16 ms passed after just ca. 5 ms) The workaround
1610 // here is present mainly for virtual machines and other broken
1611 // environments, most of which will persumably report a 60 Hz screen.
1612
1613 const float threshold = vsyncRate * 0.5f;
1614 const bool badVSync = t < threshold;
1615 if (badVSync && !w->badVSync) {
1616 // Once we determine something is wrong with the frame rate, set
1617 // the flag for the rest of the lifetime of the window. This is
1618 // saner and more deterministic than allowing it to be turned on
1619 // and off. (a window resize can take up time, leading to higher
1620 // elapsed times, thus unnecessarily starting to switch modes,
1621 // while some platforms seem to have advanced logic (and adaptive
1622 // refresh rates an whatnot) that can eventually start throttling
1623 // an unthrottled window, potentially leading to a continuous
1624 // switching of modes back and forth which is not desirable.
1625 w->badVSync = true;
1626 qCDebug(QSG_LOG_INFO, "Window %p is determined to have broken vsync throttling (%f < %f) "
1627 "switching to system timer to drive gui thread animations to remedy this "
1628 "(however, render thread animators will likely advance at an incorrect rate).",
1629 w->window, t, threshold);
1630 startOrStopAnimationTimer();
1631 }
1632
1633 w->psTimeAccumulator = 0.0f;
1634 w->psTimeSampleCount = 0;
1635 }
1636 }
1637
1638 const bool profileFrames = QSG_LOG_TIME_RENDERLOOP().isDebugEnabled();
1639 if (profileFrames) {
1640 timer.start();
1641 qCDebug(QSG_LOG_TIME_RENDERLOOP, "[window %p][gui thread] polishAndSync: start, elapsed since last call: %d ms",
1642 window,
1643 int(elapsedSinceLastMs));
1644 }
1645 Q_QUICK_SG_PROFILE_START(QQuickProfiler::SceneGraphPolishAndSync);
1646 Q_TRACE(QSG_polishItems_entry);
1647
1648 QQuickWindowPrivate *d = QQuickWindowPrivate::get(window);
1649 m_inPolish = true;
1650 d->polishItems();
1651 m_inPolish = false;
1652
1653 if (profileFrames)
1654 polishTime = timer.nsecsElapsed();
1655 Q_TRACE(QSG_polishItems_exit);
1656 Q_QUICK_SG_PROFILE_RECORD(QQuickProfiler::SceneGraphPolishAndSync,
1657 QQuickProfiler::SceneGraphPolishAndSyncPolish);
1658
1659 w = windowFor(window);
1660 if (!w || !w->thread || !w->thread->window) {
1661 qCDebug(QSG_LOG_RENDERLOOP, "- removed after polishing, abort");
1662 return;
1663 }
1664
1665 Q_TRACE(QSG_wait_entry);
1666 w->updateDuringSync = false;
1667
1668 emit window->afterAnimating();
1669
1670 const QRhiSwapChainProxyData scProxyData =
1671 QRhi::updateSwapChainProxyData(QSGRhiSupport::instance()->rhiBackend(), window);
1672
1673 qCDebug(QSG_LOG_RENDERLOOP, "- lock for sync");
1674 w->thread->mutex.lock();
1675 m_lockedForSync = true;
1676 w->thread->postEvent(new WMSyncEvent(window, inExpose, w->forceRenderPass, scProxyData));
1677 w->forceRenderPass = false;
1678
1679 qCDebug(QSG_LOG_RENDERLOOP, "- wait for sync");
1680 if (profileFrames)
1681 waitTime = timer.nsecsElapsed();
1682 Q_TRACE(QSG_wait_exit);
1683 Q_QUICK_SG_PROFILE_RECORD(QQuickProfiler::SceneGraphPolishAndSync,
1684 QQuickProfiler::SceneGraphPolishAndSyncWait);
1685 Q_TRACE(QSG_sync_entry);
1686
1687 w->thread->waitCondition.wait(&w->thread->mutex);
1688 m_lockedForSync = false;
1689 w->thread->mutex.unlock();
1690 qCDebug(QSG_LOG_RENDERLOOP, "- unlock after sync");
1691
1692 if (profileFrames)
1693 syncTime = timer.nsecsElapsed();
1694 Q_TRACE(QSG_sync_exit);
1695 Q_QUICK_SG_PROFILE_RECORD(QQuickProfiler::SceneGraphPolishAndSync,
1696 QQuickProfiler::SceneGraphPolishAndSyncSync);
1697 Q_TRACE(QSG_animations_entry);
1698
1699 // Now is the time to advance the regular animations (as we are throttled
1700 // to vsync due to the wait above), but this is only relevant when there is
1701 // one single window. With multiple windows m_animation_timer is active,
1702 // and advance() happens instead in response to a good old timer event, not
1703 // here. (the above applies only when the QSGAnimationDriver reports
1704 // isVSyncDependent() == true, if not then we always use the driver and
1705 // just advance here)
1706 if (m_animation_timer == 0 && m_animation_driver->isRunning()) {
1707 auto advanceAnimations = [this, window=QPointer(window)] {
1708 qCDebug(QSG_LOG_RENDERLOOP, "- advancing animations");
1709 m_animation_driver->advance();
1710 qCDebug(QSG_LOG_RENDERLOOP, "- animations done..");
1711
1712 // We need to trigger another update round to keep all animations
1713 // running correctly. For animations that lead to a visual change (a
1714 // property change in some item leading to dirtying the item and so
1715 // ending up in maybeUpdate()) this would not be needed, but other
1716 // animations would then stop functioning since there is nothing
1717 // advancing the animation system if we do not call postUpdateRequest()
1718 // here and nothing else leads to it either. This has an unfortunate
1719 // side effect in multi window cases: one can end up in a situation
1720 // where a non-animating window gets updates continuously because there
1721 // is an animation running in some other window that is non-exposed or
1722 // even closed already (if it was exposed we would not hit this branch,
1723 // however). Sadly, there is nothing that can be done about it.
1724 if (window)
1725 window->requestUpdate();
1726
1727 emit timeToIncubate();
1728 };
1729
1730#if defined(Q_OS_APPLE)
1731 if (inExpose) {
1732 // If we are handling an expose event the system is expecting us to
1733 // produce a frame that it can present on screen to the user. Advancing
1734 // animations at this point might result in changing properties of the
1735 // window in a way that invalidates the current frame, resulting in the
1736 // discarding of the current frame before the user ever sees it. To give
1737 // the system a chance to present the current frame we defer the advance
1738 // of the animations until the start of the next event loop pass, which
1739 // should still give plenty of time to compute the new render state before
1740 // the next expose event or update request.
1741 QMetaObject::invokeMethod(this, advanceAnimations, Qt::QueuedConnection);
1742 } else
1743#endif // Q_OS_APPLE
1744 {
1745 // For regular update requests we assume we can advance here synchronously
1746 advanceAnimations();
1747 }
1748 } else if (w->updateDuringSync) {
1749 postUpdateRequest(w);
1750 }
1751
1752 if (profileFrames) {
1753 qCDebug(QSG_LOG_TIME_RENDERLOOP, "[window %p][gui thread] Frame prepared, polish=%d ms, lock=%d ms, blockedForSync=%d ms, animations=%d ms",
1754 window,
1755 int(polishTime / 1000000),
1756 int((waitTime - polishTime) / 1000000),
1757 int((syncTime - waitTime) / 1000000),
1758 int((timer.nsecsElapsed() - syncTime) / 1000000));
1759 }
1760
1761 Q_TRACE(QSG_animations_exit);
1762 Q_QUICK_SG_PROFILE_END(QQuickProfiler::SceneGraphPolishAndSync,
1763 QQuickProfiler::SceneGraphPolishAndSyncAnimations);
1764}
1765
1767{
1768 switch ((int) e->type()) {
1769
1770 case QEvent::Timer: {
1771 Q_ASSERT(sg->isVSyncDependent(m_animation_driver));
1772 QTimerEvent *te = static_cast<QTimerEvent *>(e);
1773 if (te->timerId() == m_animation_timer) {
1774 qCDebug(QSG_LOG_RENDERLOOP, "- ticking non-render thread timer");
1775 m_animation_driver->advance();
1776 emit timeToIncubate();
1777 return true;
1778 }
1779 break;
1780 }
1781
1782 default:
1783 break;
1784 }
1785
1786 return QObject::event(e);
1787}
1788
1789
1790
1791/*
1792 Locks down GUI and performs a grab the scene graph, then returns the result.
1793
1794 Since the QML scene could have changed since the last time it was rendered,
1795 we need to polish and sync the scene graph. This might seem superfluous, but
1796 - QML changes could have triggered deleteLater() which could have removed
1797 textures or other objects from the scene graph, causing render to crash.
1798 - Autotests rely on grab(), setProperty(), grab(), compare behavior.
1799 */
1800
1801QImage QSGThreadedRenderLoop::grab(QQuickWindow *window)
1802{
1803 qCDebug(QSG_LOG_RENDERLOOP) << "grab()" << window;
1804
1805 Window *w = windowFor(window);
1806 Q_ASSERT(w);
1807
1808 if (!w->thread->isRunning())
1809 return QImage();
1810
1811 if (!window->handle())
1812 window->create();
1813
1814 qCDebug(QSG_LOG_RENDERLOOP, "- polishing items");
1815 QQuickWindowPrivate *d = QQuickWindowPrivate::get(window);
1816 m_inPolish = true;
1817 d->polishItems();
1818 m_inPolish = false;
1819
1820 QImage result;
1821 w->thread->mutex.lock();
1822 m_lockedForSync = true;
1823 qCDebug(QSG_LOG_RENDERLOOP, "- posting grab event");
1824 w->thread->postEvent(new WMGrabEvent(window, &result));
1825 w->thread->waitCondition.wait(&w->thread->mutex);
1826 m_lockedForSync = false;
1827 w->thread->mutex.unlock();
1828
1829 qCDebug(QSG_LOG_RENDERLOOP, "- grab complete");
1830
1831 return result;
1832}
1833
1834/*
1835 * Posts a new job event to the render thread.
1836 * Returns true if posting succeeded.
1837 */
1838void QSGThreadedRenderLoop::postJob(QQuickWindow *window, QRunnable *job)
1839{
1840 Window *w = windowFor(window);
1841 if (w && w->thread && w->thread->window)
1842 w->thread->postEvent(new WMJobEvent(window, job));
1843 else
1844 delete job;
1845}
1846
1847QT_END_NAMESPACE
1848
1849#include "qsgthreadedrenderloop.moc"
1850#include "moc_qsgthreadedrenderloop_p.cpp"
\inmodule QtGui
Definition qimage.h:38
QElapsedTimer m_threadTimeBetweenRenders
QOffscreenSurface * offscreenSurface
QSGRenderThreadEventQueue eventQueue
bool event(QEvent *) override
This virtual function receives events to an object and should return true if the event e was recogniz...
QSGDefaultRenderContext * sgrc
void sync(bool inExpose)
QRhiSwapChainProxyData scProxyData
QSGThreadedRenderLoop * wm
QAnimationDriver * animatorDriver
bool interleaveIncubation() const override
bool event(QEvent *) override
This virtual function receives events to an object and should return true if the event e was recogniz...
QImage grab(QQuickWindow *) override
QSGRenderContext * createRenderContext(QSGContext *) const override
bool eventFilter(QObject *watched, QEvent *event) override
Filters events if this object has been installed as an event filter for the watched object.
void postJob(QQuickWindow *window, QRunnable *job) override
QSGContext * sceneGraphContext() const override
void resize(QQuickWindow *window) override
void update(QQuickWindow *window) override
void handleUpdateRequest(QQuickWindow *window) override
QAnimationDriver * animationDriver() const override
void maybeUpdate(QQuickWindow *window) override
void exposureChanged(QQuickWindow *window) override
void releaseResources(QQuickWindow *window) override
void hide(QQuickWindow *) override
void windowDestroyed(QQuickWindow *window) override
WMGrabEvent(QQuickWindow *c, QImage *result)
WMJobEvent(QQuickWindow *c, QRunnable *postedJob)
WMSyncEvent(QQuickWindow *c, bool inExpose, bool force, const QRhiSwapChainProxyData &scProxyData)
QRhiSwapChainProxyData scProxyData
WMTryReleaseEvent(QQuickWindow *win, bool destroy, bool needsFallbackSurface)
WMWindowEvent(QQuickWindow *c, QEvent::Type type)
Combined button and popup list for selecting options.
@ WM_Exposed
@ WM_Obscure
@ WM_Grab
@ WM_PostJob
@ WM_TryRelease
@ WM_ReleaseSwapchain
@ WM_RequestSync
#define QSG_RT_PAD
\inmodule QtGuiPrivate \inheaderfile rhi/qrhi.h
Definition qrhi.h:1649