File libqt5-avoid-dynamic-switching-backingstore-composition-paths.patch of Package libqt5-qtbase.1959

From 5d63e325faa44cf1345d6f7b5cb39ec874527675 Mon Sep 17 00:00:00 2001
From: Laszlo Agocs <laszlo.agocs@theqtcompany.com>
Date: Mon, 30 Nov 2015 11:31:43 +0100
Subject: [PATCH] Avoid dynamic switching between backingstore composition
 paths

Make it opt-in because doing a normal backingstore flush does not seem to
work on Cocoa once we use OpenGL on the window. Windows and Linux should
be able to cope with this.

This means that platforms outside Windows and Linux will continue to have
the problem of having GL-based compositing enabled for ever after having a
QOpenGL/QuickWidget shown in the window once, but the issue is most
prevalent on Windows anyway, OS X machines can deal with OpenGL better
in general.

Task-number: QTBUG-49172
Change-Id: I30fd2efa95cc4f6eed9cf7f7613d0750355c775c
Reviewed-by: Lars Knoll <lars.knoll@theqtcompany.com>
Reviewed-by: Eike Ziller <eike.ziller@theqtcompany.com>
Reviewed-by: Paul Olav Tvete <paul.tvete@theqtcompany.com>
---
 src/gui/kernel/qplatformintegration.h                 |  3 ++-
 src/plugins/platforms/windows/qwindowsintegration.cpp |  2 ++
 src/plugins/platforms/xcb/qxcbintegration.cpp         |  1 +
 src/widgets/kernel/qwidgetbackingstore.cpp            | 17 ++++++++++++++++-
 4 files changed, 21 insertions(+), 2 deletions(-)

diff --git a/src/gui/kernel/qplatformintegration.h b/src/gui/kernel/qplatformintegration.h
index 00c50a9..af89a73 100644
--- a/src/gui/kernel/qplatformintegration.h
+++ b/src/gui/kernel/qplatformintegration.h
@@ -91,7 +91,8 @@ public:
         SyncState,
         RasterGLSurface,
         AllGLFunctionsQueryable,
-        ApplicationIcon
+        ApplicationIcon,
+        SwitchableWidgetComposition
     };
 
     virtual ~QPlatformIntegration() { }
diff --git a/src/plugins/platforms/windows/qwindowsintegration.cpp b/src/plugins/platforms/windows/qwindowsintegration.cpp
index 6b50ebe..55e6d55 100644
--- a/src/plugins/platforms/windows/qwindowsintegration.cpp
+++ b/src/plugins/platforms/windows/qwindowsintegration.cpp
@@ -282,6 +282,8 @@ bool QWindowsIntegration::hasCapability(QPlatformIntegration::Capability cap) co
         return true;
     case AllGLFunctionsQueryable:
         return true;
+    case SwitchableWidgetComposition:
+        return true;
     default:
         return QPlatformIntegration::hasCapability(cap);
     }
diff --git a/src/plugins/platforms/xcb/qxcbintegration.cpp b/src/plugins/platforms/xcb/qxcbintegration.cpp
index 9cedfa7..19e8b1d 100644
--- a/src/plugins/platforms/xcb/qxcbintegration.cpp
+++ b/src/plugins/platforms/xcb/qxcbintegration.cpp
@@ -252,6 +252,7 @@ bool QXcbIntegration::hasCapability(QPlatformIntegration::Capability cap) const
     case ForeignWindows: return true;
     case SyncState: return true;
     case RasterGLSurface: return true;
+    case SwitchableWidgetComposition: return true;
     default: return QPlatformIntegration::hasCapability(cap);
     }
 }
diff --git a/src/widgets/kernel/qwidgetbackingstore.cpp b/src/widgets/kernel/qwidgetbackingstore.cpp
index 6d43adc..b86c376 100644
--- a/src/widgets/kernel/qwidgetbackingstore.cpp
+++ b/src/widgets/kernel/qwidgetbackingstore.cpp
@@ -104,7 +104,6 @@ void QWidgetBackingStore::qt_flush(QWidget *widget, const QRegion &region, QBack
 
 #ifndef QT_NO_OPENGL
     if (widgetTextures) {
-        Q_ASSERT(!widgetTextures->isEmpty());
         qt_window_private(tlw->windowHandle())->compositing = true;
         widget->window()->d_func()->sendComposeStatus(widget->window(), false);
         // A window may have alpha even when the app did not request
@@ -955,6 +954,8 @@ static void findAllTextureWidgetsRecursively(QWidget *tlw, QWidget *widget)
     }
 }
 
+Q_GLOBAL_STATIC(QPlatformTextureList, qt_dummy_platformTextureList)
+
 static QPlatformTextureList *widgetTexturesFor(QWidget *tlw, QWidget *widget)
 {
     foreach (QPlatformTextureList *tl, QWidgetPrivate::get(tlw)->topData()->widgetTextures) {
@@ -965,6 +966,20 @@ static QPlatformTextureList *widgetTexturesFor(QWidget *tlw, QWidget *widget)
                 return tl;
         }
     }
+
+    if (QWidgetPrivate::get(tlw)->textureChildSeen) {
+        // No render-to-texture widgets in the (sub-)tree due to hidden or native
+        // children. Returning null results in using the normal backingstore flush path
+        // without OpenGL-based compositing. This is very desirable normally. However,
+        // some platforms cannot handle switching between the non-GL and GL paths for
+        // their windows so it has to be opt-in.
+        static bool switchableWidgetComposition =
+            QGuiApplicationPrivate::instance()->platformIntegration()
+                ->hasCapability(QPlatformIntegration::SwitchableWidgetComposition);
+        if (!switchableWidgetComposition)
+            return qt_dummy_platformTextureList();
+    }
+
     return 0;
 }
 
-- 
2.6.2