winrt: store egldisplay globally

The QWinRTEGLContext must not store the display, as it might get
destroyed while other objects still need it, for instance QWinRTWindow
to delete the surface. Rather create a global static for creating the
display once and delete it when application lifecycle ends.

Change-Id: Id176b6934e1d1327f5bb70ad0d258de91f675041
Reviewed-by: Andrew Knight <andrew.knight@intopalo.com>
bb10
Maurice Kalinowski 2015-10-30 08:27:30 +01:00
parent 5814cd9d27
commit ccbb1b4409
1 changed files with 29 additions and 16 deletions

View File

@ -51,11 +51,26 @@
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);
}
EGLDisplay eglDisplay;
};
Q_GLOBAL_STATIC(WinRTEGLDisplay, g)
class QWinRTEGLContextPrivate
{
public:
QSurfaceFormat format;
EGLDisplay eglDisplay;
EGLConfig eglConfig;
EGLContext eglContext;
};
@ -72,9 +87,7 @@ QWinRTEGLContext::~QWinRTEGLContext()
{
Q_D(QWinRTEGLContext);
if (d->eglContext != EGL_NO_CONTEXT)
eglDestroyContext(d->eglDisplay, d->eglContext);
if (d->eglDisplay != EGL_NO_DISPLAY)
eglTerminate(d->eglDisplay);
eglDestroyContext(g->eglDisplay, d->eglContext);
}
void QWinRTEGLContext::initialize()
@ -89,20 +102,21 @@ void QWinRTEGLContext::initialize()
: EGL_PLATFORM_ANGLE_DEVICE_TYPE_WARP_ANGLE;
eglBindAPI(EGL_OPENGL_ES_API);
const EGLint displayAttributes[] = {
EGL_PLATFORM_ANGLE_TYPE_ANGLE, EGL_PLATFORM_ANGLE_TYPE_D3D11_ANGLE,
EGL_PLATFORM_ANGLE_DEVICE_TYPE_ANGLE, deviceType,
EGL_PLATFORM_ANGLE_ENABLE_AUTOMATIC_TRIM_ANGLE, true,
EGL_NONE,
};
d->eglDisplay = eglGetPlatformDisplayEXT(EGL_PLATFORM_ANGLE_ANGLE, EGL_DEFAULT_DISPLAY, displayAttributes);
if (d->eglDisplay == EGL_NO_DISPLAY)
g->eglDisplay = eglGetPlatformDisplayEXT(EGL_PLATFORM_ANGLE_ANGLE, EGL_DEFAULT_DISPLAY, displayAttributes);
if (g->eglDisplay == EGL_NO_DISPLAY)
qCritical("Failed to initialize EGL display: 0x%x", eglGetError());
if (!eglInitialize(d->eglDisplay, nullptr, nullptr))
if (!eglInitialize(g->eglDisplay, nullptr, nullptr))
qCritical("Failed to initialize EGL: 0x%x", eglGetError());
d->eglConfig = q_configFromGLFormat(d->eglDisplay, d->format);
d->eglConfig = q_configFromGLFormat(g->eglDisplay, d->format);
const EGLint flags = d->format.testOption(QSurfaceFormat::DebugContext)
? EGL_CONTEXT_OPENGL_DEBUG_BIT_KHR : 0;
@ -112,7 +126,7 @@ void QWinRTEGLContext::initialize()
EGL_CONTEXT_FLAGS_KHR, flags,
EGL_NONE
};
d->eglContext = eglCreateContext(d->eglDisplay, d->eglConfig, nullptr, attributes);
d->eglContext = eglCreateContext(g->eglDisplay, d->eglConfig, nullptr, attributes);
if (d->eglContext == EGL_NO_CONTEXT) {
qWarning("QEGLPlatformContext: Failed to create context: %x", eglGetError());
return;
@ -126,37 +140,36 @@ bool QWinRTEGLContext::makeCurrent(QPlatformSurface *windowSurface)
QWinRTWindow *window = static_cast<QWinRTWindow *>(windowSurface);
if (window->eglSurface() == EGL_NO_SURFACE)
window->createEglSurface(d->eglDisplay, d->eglConfig);
window->createEglSurface(g->eglDisplay, d->eglConfig);
EGLSurface surface = window->eglSurface();
if (surface == EGL_NO_SURFACE)
return false;
const bool ok = eglMakeCurrent(d->eglDisplay, surface, surface, d->eglContext);
const bool ok = eglMakeCurrent(g->eglDisplay, surface, surface, d->eglContext);
if (!ok) {
qWarning("QEGLPlatformContext: eglMakeCurrent failed: %x", eglGetError());
return false;
}
eglSwapInterval(d->eglDisplay, d->format.swapInterval());
eglSwapInterval(g->eglDisplay, d->format.swapInterval());
return true;
}
void QWinRTEGLContext::doneCurrent()
{
Q_D(const QWinRTEGLContext);
const bool ok = eglMakeCurrent(d->eglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
const bool ok = eglMakeCurrent(g->eglDisplay, EGL_NO_SURFACE,
EGL_NO_SURFACE, EGL_NO_CONTEXT);
if (!ok)
qWarning("QEGLPlatformContext: eglMakeCurrent failed: %x", eglGetError());
}
void QWinRTEGLContext::swapBuffers(QPlatformSurface *windowSurface)
{
Q_D(QWinRTEGLContext);
Q_ASSERT(windowSurface->surface()->surfaceType() == QSurface::OpenGLSurface);
const QWinRTWindow *window = static_cast<QWinRTWindow *>(windowSurface);
eglSwapBuffers(d->eglDisplay, window->eglSurface());
eglSwapBuffers(g->eglDisplay, window->eglSurface());
}
QSurfaceFormat QWinRTEGLContext::format() const