From d356a263f627b55424a9750163a00dffc6faebcf Mon Sep 17 00:00:00 2001 From: Gunnar Sletta Date: Thu, 9 Jun 2011 09:14:54 +0200 Subject: Support calling update while syncing scenegraph. The variable inSync is written from the scene graph thread and read from the GUI thread, but this is safe as it is only written to during the sync phase, during which the GUI thread is already blocked. --- src/declarative/items/qsgcanvas.cpp | 11 ++++++++++- src/declarative/items/qsgcanvas_p.h | 2 ++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/declarative/items/qsgcanvas.cpp b/src/declarative/items/qsgcanvas.cpp index 240088cf23..e10c57d015 100644 --- a/src/declarative/items/qsgcanvas.cpp +++ b/src/declarative/items/qsgcanvas.cpp @@ -1792,7 +1792,14 @@ void QSGCanvas::maybeUpdate() Q_D(QSGCanvas); if (d->threadedRendering && d->thread && d->thread->isRunning()) { - if (!d->renderThreadAwakened) { + Q_ASSERT_X(QThread::currentThread() == QApplication::instance()->thread() || d->thread->inSync, + "QSGCanvas::update", + "Function can only be called from GUI thread or during QSGItem::updatePaintNode()"); + + if (d->thread->inSync) { + d->thread->isExternalUpdatePending = true; + + } else if (!d->renderThreadAwakened) { #ifdef THREAD_DEBUG printf("GUI: doing update...\n"); #endif @@ -1899,7 +1906,9 @@ void QSGCanvasRenderThread::run() #ifdef THREAD_DEBUG printf(" RenderThread: Doing locked sync\n"); #endif + inSync = true; d->syncSceneGraph(); + inSync = false; // Wake GUI after sync to let it continue animating and event processing. wake(); diff --git a/src/declarative/items/qsgcanvas_p.h b/src/declarative/items/qsgcanvas_p.h index 9ea11f5892..7538b3d7c1 100644 --- a/src/declarative/items/qsgcanvas_p.h +++ b/src/declarative/items/qsgcanvas_p.h @@ -180,6 +180,7 @@ public: , isRenderBlocked(false) , isExternalUpdatePending(false) , syncAlreadyHappened(false) + , inSync(false) , doGrab(false) , shouldExit(false) , hasExited(false) @@ -222,6 +223,7 @@ public: uint isRenderBlocked : 1; uint isExternalUpdatePending : 1; uint syncAlreadyHappened : 1; + uint inSync : 1; uint doGrab : 1; uint shouldExit : 1; -- cgit v1.2.3