From 3425c9c6d7f7915e6f7931da46105b36245e86ad Mon Sep 17 00:00:00 2001
From: David Edmundson <davidedmundson@kde.org>
Date: Thu, 29 Aug 2019 09:36:53 +0100
Subject: [PATCH] Handle context loss in QPlatformBackingStore

This powers a QQuickWidget and we also need to reset the context if we
get a context loss event.

Change-Id: Id8b7112606670985860069c2bb11cf141b3ac723
Reviewed-by: Laszlo Agocs <laszlo.agocs@qt.io>
---
 src/gui/painting/qplatformbackingstore.cpp | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/src/gui/painting/qplatformbackingstore.cpp b/src/gui/painting/qplatformbackingstore.cpp
index 601dc97be1..45e90bd99b 100644
--- a/src/gui/painting/qplatformbackingstore.cpp
+++ b/src/gui/painting/qplatformbackingstore.cpp
@@ -338,7 +338,16 @@ void QPlatformBackingStore::composeAndFlush(QWindow *window, const QRegion &regi
         }
     }
 
-    if (!d_ptr->context->makeCurrent(window)) {
+    bool current = d_ptr->context->makeCurrent(window);
+
+    if (!current && !d_ptr->context->isValid()) {
+        delete d_ptr->blitter;
+        d_ptr->blitter = nullptr;
+        d_ptr->textureId = 0;
+        current = d_ptr->context->create() && d_ptr->context->makeCurrent(window);
+    }
+
+    if (!current) {
         qCWarning(lcQpaBackingStore, "composeAndFlush: makeCurrent() failed");
         return;
     }