diff options
author | Laszlo Agocs <laszlo.agocs@digia.com> | 2014-08-12 10:10:30 +0200 |
---|---|---|
committer | Laszlo Agocs <laszlo.agocs@digia.com> | 2014-08-14 11:02:37 +0200 |
commit | cbd5ed0e0dc459ece096aa43d775f64d6efd63b5 (patch) | |
tree | 989312d4181fe704387b072ef940604eb63e1a5e /src/quickwidgets | |
parent | dc4e537d4cfe16aaa88b6edd911571317241ab32 (diff) |
Reinitialize in QQuickWidget properly after hide and show
hide() followed by a show() results in totally broken QQuickWidgets due
to not initializing scenegraph again.
Task-number: QTBUG-40710
Change-Id: Id3cded2917d20c165b5885f3f2195d5c4566de89
Reviewed-by: Gunnar Sletta <gunnar.sletta@jollamobile.com>
Diffstat (limited to 'src/quickwidgets')
-rw-r--r-- | src/quickwidgets/qquickwidget.cpp | 51 |
1 files changed, 29 insertions, 22 deletions
diff --git a/src/quickwidgets/qquickwidget.cpp b/src/quickwidgets/qquickwidget.cpp index 0a521984e1..7aef165736 100644 --- a/src/quickwidgets/qquickwidget.cpp +++ b/src/quickwidgets/qquickwidget.cpp @@ -218,7 +218,7 @@ void QQuickWidgetPrivate::renderSceneGraph() QOpenGLContext *context = offscreenWindow->openglContext(); if (!context) { - qWarning("QQuickWidget: render scenegraph with no context"); + qWarning("QQuickWidget: Attempted to render scene with no context"); return; } @@ -634,33 +634,40 @@ void QQuickWidgetPrivate::handleContextCreationFailure(const QSurfaceFormat &for void QQuickWidgetPrivate::createContext() { - if (context) - return; - - context = new QOpenGLContext; - context->setFormat(offscreenWindow->requestedFormat()); + // On hide-show we invalidate() but our context is kept. + // We nonetheless need to initialize() again. + const bool reinit = context && !offscreenWindow->openglContext(); + + if (!reinit) { + if (context) + return; + + context = new QOpenGLContext; + context->setFormat(offscreenWindow->requestedFormat()); + + if (qt_gl_global_share_context()) + context->setShareContext(qt_gl_global_share_context()); + + if (!context->create()) { + const bool isEs = context->isOpenGLES(); + delete context; + context = 0; + handleContextCreationFailure(offscreenWindow->requestedFormat(), isEs); + return; + } - if (qt_gl_global_share_context()) - context->setShareContext(qt_gl_global_share_context()); - if (!context->create()) { - const bool isEs = context->isOpenGLES(); - delete context; - context = 0; - handleContextCreationFailure(offscreenWindow->requestedFormat(), isEs); - return; + offscreenSurface = new QOffscreenSurface; + // Pass the context's format(), which, now that the underlying platform context is created, + // contains a QSurfaceFormat representing the _actual_ format of the underlying + // configuration. This is essential to get a surface that is compatible with the context. + offscreenSurface->setFormat(context->format()); + offscreenSurface->create(); } - offscreenSurface = new QOffscreenSurface; - // Pass the context's format(), which, now that the underlying platform context is created, - // contains a QSurfaceFormat representing the _actual_ format of the underlying - // configuration. This is essential to get a surface that is compatible with the context. - offscreenSurface->setFormat(context->format()); - offscreenSurface->create(); - if (context->makeCurrent(offscreenSurface)) renderControl->initialize(context); else - qWarning("QQuickWidget: failed to make window surface current"); + qWarning("QQuickWidget: Failed to make context current"); } void QQuickWidgetPrivate::destroyContext() |