Create contexts and pbuffers with the correct screen in QQuickWidget
authorLaszlo Agocs <laszlo.agocs@theqtcompany.com>
Thu, 7 May 2015 17:09:39 +0000 (19:09 +0200)
committerLaszlo Agocs <laszlo.agocs@theqtcompany.com>
Tue, 12 May 2015 08:59:08 +0000 (08:59 +0000)
Change-Id: I8e9db998eee0af5f62c1384f2dcb2028254cc642
Reviewed-by: Gunnar Sletta <gunnar@sletta.org>
src/quickwidgets/qquickwidget.cpp

index 38dde80..f0a2a31 100644 (file)
@@ -691,8 +691,10 @@ void QQuickWidgetPrivate::createContext()
         context = new QOpenGLContext;
         context->setFormat(offscreenWindow->requestedFormat());
 
-        if (qt_gl_global_share_context())
+        if (qt_gl_global_share_context()) {
             context->setShareContext(qt_gl_global_share_context());
+            context->setScreen(context->shareContext()->screen());
+        }
 
         if (!context->create()) {
             const bool isEs = context->isOpenGLES();
@@ -707,6 +709,7 @@ void QQuickWidgetPrivate::createContext()
         // 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->setScreen(context->screen());
         offscreenSurface->create();
     }
 
@@ -742,7 +745,14 @@ void QQuickWidget::createFramebufferObject()
 
     if (context->shareContext() != QWidgetPrivate::get(window())->shareContext()) {
         context->setShareContext(QWidgetPrivate::get(window())->shareContext());
-        context->create();
+        context->setScreen(context->shareContext()->screen());
+        if (!context->create())
+            qWarning("QQuickWidget: Failed to recreate context");
+        // The screen may be different so we must recreate the offscreen surface too.
+        // Unlike QOpenGLContext, QOffscreenSurface's create() does not recreate so have to destroy() first.
+        d->offscreenSurface->destroy();
+        d->offscreenSurface->setScreen(context->screen());
+        d->offscreenSurface->create();
     }
 
     context->makeCurrent(d->offscreenSurface);