From ddb134af9903512408b7e52455f1787e4b6b62ea Mon Sep 17 00:00:00 2001 From: Laszlo Agocs Date: Thu, 14 Aug 2014 12:58:55 +0200 Subject: Fix flicker when showing QQuickWidget 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 --- src/quickwidgets/qquickwidget.cpp | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) (limited to 'src/quickwidgets/qquickwidget.cpp') diff --git a/src/quickwidgets/qquickwidget.cpp b/src/quickwidgets/qquickwidget.cpp index 446ed1c84e..b89c894cb2 100644 --- a/src/quickwidgets/qquickwidget.cpp +++ b/src/quickwidgets/qquickwidget.cpp @@ -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(); -- cgit v1.2.3