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 <oliver.wolff@theqtcompany.com>
This commit is contained in:
Maurice Kalinowski 2016-01-07 13:20:08 +01:00
parent 558f69a18b
commit 2b1f01426c

View File

@ -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)