Fix resizing canvas with renderStrategy == Cooperative
authorGunnar Sletta <gunnar.sletta@digia.com>
Wed, 12 Jun 2013 14:30:05 +0000 (16:30 +0200)
committerThe Qt Project <gerrit-noreply@qt-project.org>
Thu, 13 Jun 2013 08:00:56 +0000 (10:00 +0200)
updatePolish() called prepare() which would use a queued
metaInvoke() to change the size of the texture. However,
there is no guaranteed event processing on the render thread
between polish on the GUI thread and sync on the render
thread, we would very often get to updatePaintNode() before
the queued invoke landed, resulting the drawing being done
to a texture of the wrong size.

Fix this by calling prepare from updatePaintNode when
in CooperativeMode so that the autoconnection becomes
a direct one and we get prepare and flush processed in
the right order.

Change-Id: I0fa4687a94ada4bdaddca19133e686bca0bc745c
Reviewed-by: Alan Alpert <aalpert@blackberry.com>
src/quick/items/context2d/qquickcanvasitem.cpp

index 4144256..3b1b6d5 100644 (file)
@@ -645,7 +645,7 @@ void QQuickCanvasItem::updatePolish()
 
     Q_D(QQuickCanvasItem);
 
-    if (d->context)
+    if (d->context && d->renderStrategy != QQuickCanvasItem::Cooperative)
         d->context->prepare(d->canvasSize.toSize(), d->tileSize, d->canvasWindow.toRect(), d->dirtyRect.toRect(), d->smooth, d->antialiasing);
 
     if (d->animationCallbacks.size() > 0 && isVisible()) {
@@ -697,8 +697,10 @@ QSGNode *QQuickCanvasItem::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData
     else
         node->setFiltering(QSGTexture::Nearest);
 
-    if (d->renderStrategy == QQuickCanvasItem::Cooperative)
+    if (d->renderStrategy == QQuickCanvasItem::Cooperative) {
+        d->context->prepare(d->canvasSize.toSize(), d->tileSize, d->canvasWindow.toRect(), d->dirtyRect.toRect(), d->smooth, d->antialiasing);
         d->context->flush();
+    }
 
     node->setTexture(d->context->texture());
     node->markDirty(QSGNode::DirtyMaterial);