Invalidate the scenegraph properly in the rendercontrol
authorLaszlo Agocs <laszlo.agocs@digia.com>
Tue, 5 Aug 2014 12:53:34 +0000 (14:53 +0200)
committerLaszlo Agocs <laszlo.agocs@digia.com>
Fri, 8 Aug 2014 07:58:00 +0000 (09:58 +0200)
Taking the persistent flags from the QQuickWindow was a bad idea. These
are not applicable to the case when an application drives the scene via
QQuickRenderControl. Once stop() is called, all resources must be
released since the context itself will typically be destroyed afterwards.

This is a backport of 0b0bb319578bb2e2eced3a80ce3876a4408b72a7 in dev.

On top of this, stop() becomes invalidate() since the original
invalidate() function is never used by anyone. This naming is much cleaner
and is consistent with QSGContext and friends.

Task-number: QTBUG-40505
Task-number: QTBUG-40435
Change-Id: I398f1bda31f335c3508b238f0328305d3cd79ffd
Reviewed-by: Gunnar Sletta <gunnar.sletta@jollamobile.com>
src/quick/items/qquickrendercontrol.cpp
src/quick/items/qquickrendercontrol_p.h
src/quickwidgets/qquickwidget.cpp
src/quickwidgets/qquickwidget_p.h

index 2842d7e..e28669c 100644 (file)
@@ -123,12 +123,6 @@ void QQuickRenderControl::initialize(QOpenGLContext *gl)
     d->rc->initialize(gl);
 }
 
-void QQuickRenderControl::invalidate()
-{
-    Q_D(QQuickRenderControl);
-    d->rc->invalidate();
-}
-
 /*!
   This function should be called as late as possible before
   sync(). In a threaded scenario, rendering can happen in parallel with this function.
@@ -165,7 +159,7 @@ bool QQuickRenderControl::sync()
   Stop rendering and release resources. This function is typically
   called when the window is hidden. Requires a current context.
  */
-void QQuickRenderControl::stop()
+void QQuickRenderControl::invalidate()
 {
     Q_D(QQuickRenderControl);
     if (!d->window)
@@ -175,10 +169,11 @@ void QQuickRenderControl::stop()
     cd->fireAboutToStop();
     cd->cleanupNodesOnShutdown();
 
-    if (!cd->persistentSceneGraph) {
-        d->rc->invalidate();
-        QCoreApplication::sendPostedEvents(0, QEvent::DeferredDelete);
-    }
+    // We must invalidate since the context can potentially be destroyed by the
+    // application right after returning from this function. Invalidating is
+    // also essential to allow a subsequent initialize() to succeed.
+    d->rc->invalidate();
+    QCoreApplication::sendPostedEvents(0, QEvent::DeferredDelete);
 }
 
 /*!
index cc30e37..d8d5b09 100644 (file)
@@ -74,7 +74,6 @@ public:
     void polishItems();
     void render();
     bool sync();
-    void stop();
 
     QImage grab();
 
index 77d1622..8a61e37 100644 (file)
@@ -116,23 +116,23 @@ void QQuickWidgetPrivate::init(QQmlEngine* e)
     QObject::connect(renderControl, SIGNAL(sceneChanged()), q, SLOT(triggerUpdate()));
 }
 
-void QQuickWidgetPrivate::stopRenderControl()
+void QQuickWidgetPrivate::invalidateRenderControl()
 {
     if (!context) // this is not an error, could be called before creating the context, or multiple times
         return;
 
     bool success = context->makeCurrent(offscreenSurface);
     if (!success) {
-        qWarning("QQuickWidget::stopRenderControl could not make context current");
+        qWarning("QQuickWidget::invalidateRenderControl could not make context current");
         return;
     }
 
-    renderControl->stop();
+    renderControl->invalidate();
 }
 
 void QQuickWidgetPrivate::handleWindowChange()
 {
-    stopRenderControl();
+    invalidateRenderControl();
     destroyContext();
 }
 
@@ -158,7 +158,7 @@ QQuickWidgetPrivate::~QQuickWidgetPrivate()
     if (QQmlDebugService::isDebuggingEnabled())
         QQmlInspectorService::instance()->removeView(q_func());
 
-    stopRenderControl();
+    invalidateRenderControl();
 
     // context and offscreenSurface are current at this stage, if the context was created.
     Q_ASSERT(!context || (QOpenGLContext::currentContext() == context && context->surface() == offscreenSurface));
@@ -964,7 +964,7 @@ void QQuickWidget::showEvent(QShowEvent *)
 void QQuickWidget::hideEvent(QHideEvent *)
 {
     Q_D(QQuickWidget);
-    d->stopRenderControl();
+    d->invalidateRenderControl();
 }
 
 /*! \reimp */
index 356c34e..8a8d98f 100644 (file)
@@ -92,7 +92,7 @@ public:
 
     void init(QQmlEngine* e = 0);
     void handleWindowChange();
-    void stopRenderControl();
+    void invalidateRenderControl();
 
     QSize rootObjectSize() const;