Fix flicker when showing QQuickWidget
authorLaszlo Agocs <laszlo.agocs@digia.com>
Thu, 14 Aug 2014 10:58:55 +0000 (12:58 +0200)
committerLaszlo Agocs <laszlo.agocs@digia.com>
Thu, 14 Aug 2014 13:58:45 +0000 (15:58 +0200)
This also reintroduces the change from commit 14b4747b17d522fe57f3a5f21738c5a89323b5e2.
Due to some bizarre merge issue that change has disappeared from qquickwidget.cpp
and its history. It is there in the main log, though.

The new fix depends on this older one, so the combined one fixes the following
three issues:

1. Polish and sync cannot be skipped when we are rendering for the first time.

2. Recreating the fbo twice when the widget is shown. Calling
createFramebufferObject() is not necessary in this case since createContext()
will trigger this anyhow due to scenegraphInitialized().

3. Avoid recreating the fbo when the size is the same as before. Some platforms
are keen on sending resize events with the same size. These should be ignored.
What's worse, some platforms (cocoa) generate a resize on exitting (Cmd-Q)
and not ignoring the resize at that stage is dangerous since the scenegraph
is already invalidated.

Task-number: QTBUG-40710
Task-number: QTBUG-40505
Change-Id: I2e897acc68fa68233563a1db63ffb6c5d0baad73
Reviewed-by: Gunnar Sletta <gunnar.sletta@jollamobile.com>
src/quickwidgets/qquickwidget.cpp

index 446ed1c..b89c894 100644 (file)
@@ -891,8 +891,23 @@ void QQuickWidget::resizeEvent(QResizeEvent *e)
         d->renderControl->sync();
     }
 
-    d->createContext();
-    createFramebufferObject();
+    bool newFbo = false;
+    if (d->context) {
+        // Bail out in the special case of receiving a resize after
+        // scenegraph invalidation during application exit.
+        if (!d->fbo && !d->offscreenWindow->openglContext())
+            return;
+        if (!d->fbo || d->fbo->size() != size() * devicePixelRatio()) {
+            newFbo = true;
+            createFramebufferObject();
+        }
+    } else {
+        // This will result in a scenegraphInitialized() signal which
+        // is connected to createFramebufferObject().
+        newFbo = true;
+        d->createContext();
+    }
+
     QCoreApplication::sendEvent(d->offscreenWindow, e);
     d->offscreenWindow->setGeometry(0, 0, e->size().width(), e->size().height());
 
@@ -904,10 +919,13 @@ void QQuickWidget::resizeEvent(QResizeEvent *e)
 
     context->makeCurrent(d->offscreenSurface);
 
-    if (d->fakeHidden) {
-        d->fakeHidden = false;
+    if (newFbo) {
+        d->renderControl->polishItems();
+        d->renderControl->sync();
+    } else if (d->fakeHidden) {
         d->renderControl->sync();
     }
+    d->fakeHidden = false;
 
     d->renderControl->render();
     context->functions()->glFlush();