File xcb-avoid-triggering-OpenGL-initialization-for-RasterSurface.patch of Package libqt5-qtbase.1959

From 5d5e0a4e976622bc3db8b1f7f70041ff71e45085 Mon Sep 17 00:00:00 2001
From: John Lindgren <john.lindgren@aol.com>
Date: Sat, 29 Aug 2015 15:21:43 -0400
Subject: [PATCH] Avoid triggering OpenGL initialization for RasterSurface

Application that do not require OpenGL need a way to opt-out of
GLX/EGL calls completely. The initialization can be expensive and what
is more, some systems may not have functional GLX at all (some VMs are
known to crash when trying to get FBConfigs for the window).

QApplication already has AA_ForceRasterWidgets, which causes the use
of plain RasterSurface everywhere instead of RasterGLSurface. Combined
with a trivial check in the xcb backend to skip all the Xlib+GLX/EGL
path, the attribute will allow apps to ensure that no GLX/EGL calls
are ever made.

This however implies a change in QWindowContainer: the embedded window
must use the same initialization path as the parent otherwise we will
end up with a BadMatch. QWindowContainer can do this transparently to
the applications, unless the QWindow is already created.

Change-Id: I846af7edb8b92b9836cdbd93c6a5eec5a6147a49
Task-number: QTBUG-46765
Reviewed-by: Paul Olav Tvete <paul.tvete@theqtcompany.com>
---
 src/plugins/platforms/xcb/qxcbwindow.cpp | 3 ++-
 src/widgets/kernel/qwindowcontainer.cpp  | 9 +++++++++
 2 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/src/plugins/platforms/xcb/qxcbwindow.cpp b/src/plugins/platforms/xcb/qxcbwindow.cpp
index e7f5bbf..bde8826 100644
--- a/src/plugins/platforms/xcb/qxcbwindow.cpp
+++ b/src/plugins/platforms/xcb/qxcbwindow.cpp
@@ -389,7 +389,8 @@ void QXcbWindow::create()
     resolveFormat();
 
 #ifdef XCB_USE_XLIB
-    if (QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::OpenGL)) {
+    if (window()->surfaceType() != QSurface::RasterSurface
+     && QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::OpenGL)) {
         XVisualInfo *visualInfo = Q_NULLPTR;
         if (connection()->hasDefaultVisualId())
             visualInfo = CREATE_VISUALINFO_FROM_DEFAULT_VISUALID(this);
diff --git a/src/widgets/kernel/qwindowcontainer.cpp b/src/widgets/kernel/qwindowcontainer.cpp
index 9d3a4ef..3885431 100644
--- a/src/widgets/kernel/qwindowcontainer.cpp
+++ b/src/widgets/kernel/qwindowcontainer.cpp
@@ -34,6 +34,8 @@
 #include "qwindowcontainer_p.h"
 #include "qwidget_p.h"
 #include <QtGui/qwindow.h>
+#include <QtGui/private/qguiapplication_p.h>
+#include <qpa/qplatformintegration.h>
 #include <QDebug>
 
 #include <QMdiSubWindow>
@@ -196,6 +198,13 @@ QWindowContainer::QWindowContainer(QWindow *embeddedWindow, QWidget *parent, Qt:
         return;
     }
 
+    // The embedded QWindow must use the same logic as QWidget when it comes to the surface type.
+    // Otherwise we may end up with BadMatch failures on X11.
+    if (embeddedWindow->surfaceType() == QSurface::RasterSurface
+        && QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::RasterGLSurface)
+        && !QApplication::testAttribute(Qt::AA_ForceRasterWidgets))
+        embeddedWindow->setSurfaceType(QSurface::RasterGLSurface);
+
     d->window = embeddedWindow;
     d->window->setParent(&d->fakeParent);
     setAcceptDrops(true);
-- 
2.6.3