From 2b1f01426c1ee47474b4b8e4e53799d992d0711c Mon Sep 17 00:00:00 2001 From: Maurice Kalinowski Date: Thu, 7 Jan 2016 13:20:08 +0100 Subject: WinRT: Fix application shutdown Do not create a dummy eglDisplay when the global static is constructed. This causes ANGLE to wrongly set some internals, which breaks usage of EGL_PLATFORM_ANGLE_ENABLE_AUTOMATIC_TRIM_ANGLE as the attribute map might be empty after calling eglGetPlatformDisplayEXT. Furthermore initialize() assigns a new display to it without terminating the old one. This way, the internal suspend handler in ANGLE (Trim11.cpp) will be added to the application. The suspend handler is not invoked when an application suspends though. Reason being that the handler needs to be added from inside the Xaml thread. As we cannot control this inside ANGLE, we will call eglInitialize inside the Xaml thread and hence get the suspend event properly. Task-number: QTBUG-50337 Task-number: QTBUG-50292 Change-Id: I3867377254c37084bf24f18e78af467f6237db57 Reviewed-by: Oliver Wolff --- src/plugins/platforms/winrt/qwinrteglcontext.cpp | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) (limited to 'src/plugins/platforms') diff --git a/src/plugins/platforms/winrt/qwinrteglcontext.cpp b/src/plugins/platforms/winrt/qwinrteglcontext.cpp index 3fd0278360..ebd15d7184 100644 --- a/src/plugins/platforms/winrt/qwinrteglcontext.cpp +++ b/src/plugins/platforms/winrt/qwinrteglcontext.cpp @@ -54,9 +54,6 @@ QT_BEGIN_NAMESPACE struct WinRTEGLDisplay { WinRTEGLDisplay() { - eglDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY); - if (eglDisplay == EGL_NO_DISPLAY) - qCritical("Failed to initialize EGL display: 0x%x", eglGetError()); } ~WinRTEGLDisplay() { eglTerminate(eglDisplay); @@ -117,9 +114,17 @@ void QWinRTEGLContext::initialize() if (g->eglDisplay == EGL_NO_DISPLAY) qCritical("Failed to initialize EGL display: 0x%x", eglGetError()); - if (!eglInitialize(g->eglDisplay, nullptr, nullptr)) - qCritical("Failed to initialize EGL: 0x%x", eglGetError()); - + // eglInitialize checks for EGL_PLATFORM_ANGLE_ENABLE_AUTOMATIC_TRIM_ANGLE + // which adds a suspending handler. This needs to be added from the Xaml + // thread itself, otherwise it will not be invoked. add_Suspending does + // not return an error unfortunately, so it silently fails and causes + // applications to not quit when the system wants to terminate the app + // after suspend. + hr = QEventDispatcherWinRT::runOnXamlThread([]() { + if (!eglInitialize(g->eglDisplay, nullptr, nullptr)) + qCritical("Failed to initialize EGL: 0x%x", eglGetError()); + return S_OK; + }); d->eglConfig = q_configFromGLFormat(g->eglDisplay, d->format); const EGLint flags = d->format.testOption(QSurfaceFormat::DebugContext) -- cgit v1.2.3