Fix fbo creation and resize logic in QQuickWidget
authorLaszlo Agocs <laszlo.agocs@digia.com>
Tue, 5 Aug 2014 15:16:56 +0000 (17:16 +0200)
committerLaszlo Agocs <laszlo.agocs@digia.com>
Wed, 6 Aug 2014 08:27:26 +0000 (10:27 +0200)
This corrects two issues:

1. 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().

2. 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-40505
Change-Id: I21ff418fde449aa15eef4d6593e7a518861fcde1
Reviewed-by: Gunnar Sletta <gunnar.sletta@jollamobile.com>
src/quickwidgets/qquickwidget.cpp

index 5e1502b..77d1622 100644 (file)
@@ -875,8 +875,19 @@ void QQuickWidget::resizeEvent(QResizeEvent *e)
         d->renderControl->sync();
     }
 
-    d->createContext();
-    createFramebufferObject();
+    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())
+            createFramebufferObject();
+    } else {
+        // This will result in a scenegraphInitialized() signal which
+        // is connected to createFramebufferObject().
+        d->createContext();
+    }
+
     d->offscreenWindow->resizeEvent(e);
     d->offscreenWindow->setGeometry(0, 0, e->size().width(), e->size().height());