From 0b9967d0f16652b0c77d454923bb7a1423792658 Mon Sep 17 00:00:00 2001
From: Paul Olav Tvete <paul.tvete@theqtcompany.com>
Date: Wed, 2 Mar 2016 15:51:00 +0100
Subject: [PATCH] Workaround for i.MX6 Wayland client crash

There is a bug in some versions of the Vivante driver, causing clients
to crash when a window is closed. This patch avoids a crash on startup,
confirmed with GL version "OpenGL ES 3.0 V5.0.11.p4.25762". The crash
happens with both Weston and Qt-based compositors.

Since we do not yet know exactly which versions are affected, we
avoid destroying the temporary surface for all Vivante versions.

Change-Id: I4b5b0ebb04b8441559aebb54a6ec3eb534c5c8e0
Reviewed-by: Jan Arne Petersen <jan.petersen@kdab.com>
Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@theqtcompany.com>
---
 .../client/wayland-egl/qwaylandglcontext.cpp                 | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/src/hardwareintegration/client/wayland-egl/qwaylandglcontext.cpp b/src/hardwareintegration/client/wayland-egl/qwaylandglcontext.cpp
index faaa6aef..5889a1e3 100644
--- a/src/hardwareintegration/client/wayland-egl/qwaylandglcontext.cpp
+++ b/src/hardwareintegration/client/wayland-egl/qwaylandglcontext.cpp
@@ -308,6 +308,8 @@ void QWaylandGLContext::updateGLFormat()
     wl_egl_window *eglWindow = wl_egl_window_create(wlSurface, 1, 1);
     EGLSurface eglSurface = eglCreateWindowSurface(m_eglDisplay, m_config, eglWindow, 0);
 
+    static bool vivanteEglWorkaround = strstr(eglQueryString(m_eglDisplay, EGL_VENDOR), "Vivante Corporation") != 0;
+
     if (eglMakeCurrent(m_eglDisplay, eglSurface, eglSurface, m_context)) {
         if (m_format.renderableType() == QSurfaceFormat::OpenGL
             || m_format.renderableType() == QSurfaceFormat::OpenGLES) {
@@ -347,7 +349,8 @@ void QWaylandGLContext::updateGLFormat()
         eglMakeCurrent(prevDisplay, prevSurfaceDraw, prevSurfaceRead, prevContext);
     }
     eglDestroySurface(m_eglDisplay, eglSurface);
-    wl_egl_window_destroy(eglWindow);
+    if (!vivanteEglWorkaround)
+        wl_egl_window_destroy(eglWindow);
     wl_surface_destroy(wlSurface);
 }
 
-- 
GitLab