Add QQuickCanvas::update()
authorGunnar Sletta <gunnar.sletta@nokia.com>
Wed, 16 May 2012 18:16:07 +0000 (20:16 +0200)
committerQt by Nokia <qt-info@nokia.com>
Tue, 22 May 2012 18:04:28 +0000 (20:04 +0200)
We would like to make a distinction between QQuickItem::update()
which triggers updatePaintNode() to synchronize the scene
graph and requesting the toplevel QQuickCanvas to be repainted.

If we have this distinction in place it is possible for the
scene graph to detect that the scene is unchanged and avoid
rendering unless the user has explicitely asked for the
canvas to be repainted, which is often the case when hooking
into QQuickCanvas::beforeRender().

Change-Id: Ibe77f58423593deb217ef9f8082fa12009f45daf
Reviewed-by: Samuel Rødal <samuel.rodal@nokia.com>
src/quick/items/qquickcanvas.cpp
src/quick/items/qquickcanvas.h
src/quick/items/qquickitem.cpp
src/quick/items/qquickwindowmanager.cpp
src/quick/items/qquickwindowmanager_p.h

index 4fd3bf0..c3aecce 100644 (file)
@@ -255,6 +255,19 @@ void QQuickCanvasPrivate::setRenderWithoutShowing(bool render)
 }
 
 
+/*!
+ * Schedules the canvas to render another frame.
+ *
+ * Calling QQuickCanvas::update() differs from QQuickItem::update() in that
+ * it always triggers a repaint, regardless of changes in the underlying
+ * scene graph or not.
+ */
+void QQuickCanvas::update()
+{
+    Q_D(QQuickCanvas);
+    d->windowManager->update(this);
+}
+
 void forceUpdate(QQuickItem *item)
 {
     if (item->flags() & QQuickItem::ItemHasContents)
index 0e06202..c3a6e45 100644 (file)
@@ -130,6 +130,7 @@ Q_SIGNALS:
     void clearColorChanged(const QColor &);
 
 public Q_SLOTS:
+    void update();
     void releaseResources();
 
 protected:
index 879d6a4..b7e6f07 100644 (file)
@@ -3107,6 +3107,11 @@ void QQuickItem::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeo
     The main thread is blocked while this function is executed so it is safe to read
     values from the QQuickItem instance and other objects in the main thread.
 
+    If no call to QQuickItem::updatePaintNode() result in actual scene graph
+    changes, like QSGNode::markDirty() or adding and removing nodes, then
+    the underlying implementation may decide to not render the scene again as
+    the visual outcome is identical.
+
     \warning It is crucial that OpenGL operations and interaction with
     the scene graph happens exclusively on the rendering thread,
     primarily during the QQuickItem::updatePaintNode() call. The best
@@ -3114,7 +3119,7 @@ void QQuickItem::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeo
     the QQuickItem::updatePaintNode() function.
 
     \sa QSGMaterial, QSGSimpleMaterial, QSGGeometryNode, QSGGeometry,
-    QSGFlatColorMaterial, QSGTextureMaterial
+    QSGFlatColorMaterial, QSGTextureMaterial, QSGNode::markDirty()
  */
 
 QSGNode *QQuickItem::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *)
@@ -3401,6 +3406,16 @@ void QQuickItem::setBaselineOffset(qreal offset)
     emit baselineOffsetChanged(offset);
 }
 
+
+/*!
+ * Schedules a call to updatePaintNode() for this item.
+ *
+ * The call to QQuickItem::updatePaintNode() will always happen if the
+ * item is showing in a QQuickCanvas.
+ *
+ * Only items which specifies QQuickItem::ItemHasContents are allowed
+ * to call QQuickItem::update().
+ */
 void QQuickItem::update()
 {
     Q_D(QQuickItem);
index bef9081..f584209 100644 (file)
@@ -188,6 +188,7 @@ public:
     void resize(QQuickCanvas *canvas, const QSize &size);
     void handleDeferredUpdate();
     void maybeUpdate(QQuickCanvas *canvas);
+    void update(QQuickCanvas *canvas) { maybeUpdate(canvas); } // identical for this implementation
     void wakeup();
 
     void startRendering();
@@ -297,6 +298,7 @@ public:
     void wakeup();
 
     void maybeUpdate(QQuickCanvas *canvas);
+    void update(QQuickCanvas *canvas) { maybeUpdate(canvas); } // identical for this implementation.
 
     void releaseResources() { }
 
index 54b71f3..5535019 100644 (file)
@@ -64,6 +64,7 @@ public:
     virtual QImage grab(QQuickCanvas *canvas) = 0;
     virtual void resize(QQuickCanvas *canvas, const QSize &size) = 0;
 
+    virtual void update(QQuickCanvas *canvas) = 0;
     virtual void maybeUpdate(QQuickCanvas *canvas) = 0;
     virtual void wakeup() = 0;