Support calling update while syncing scenegraph.
authorGunnar Sletta <gunnar.sletta@nokia.com>
Thu, 9 Jun 2011 07:14:54 +0000 (09:14 +0200)
committerGunnar Sletta <gunnar.sletta@nokia.com>
Thu, 9 Jun 2011 07:19:34 +0000 (09:19 +0200)
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
src/declarative/items/qsgcanvas_p.h

index 240088c..e10c57d 100644 (file)
@@ -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();
index 9ea11f5..7538b3d 100644 (file)
@@ -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;