From f3fd7b3d961ffed480e5851e594f6981f558f486 Mon Sep 17 00:00:00 2001 From: Samuel Nevala Date: Thu, 10 Sep 2015 13:14:57 +0300 Subject: winrt: Move EGL surface to window. Fixes GPU memory leak when window is created/deleted dynamically and repeatedly. EGL context used to own EGL surface, but the context outlives the surface if window is created/deleted dynamically. The EGL surface is now owned by the window and destroyed with it. Change-Id: Ib949261ef6e77217018e60aad3e36e4a6d2eaba0 Reviewed-by: Andrew Knight --- src/plugins/platforms/winrt/qwinrteglcontext.cpp | 30 +++++++----------------- 1 file changed, 9 insertions(+), 21 deletions(-) (limited to 'src/plugins/platforms/winrt/qwinrteglcontext.cpp') diff --git a/src/plugins/platforms/winrt/qwinrteglcontext.cpp b/src/plugins/platforms/winrt/qwinrteglcontext.cpp index 44aab266ca..9cb45336d6 100644 --- a/src/plugins/platforms/winrt/qwinrteglcontext.cpp +++ b/src/plugins/platforms/winrt/qwinrteglcontext.cpp @@ -56,7 +56,6 @@ public: EGLDisplay eglDisplay; EGLConfig eglConfig; EGLContext eglContext; - QHash surfaceForWindow; }; QWinRTEGLContext::QWinRTEGLContext(QOpenGLContext *context) @@ -70,8 +69,6 @@ QWinRTEGLContext::QWinRTEGLContext(QOpenGLContext *context) QWinRTEGLContext::~QWinRTEGLContext() { Q_D(QWinRTEGLContext); - foreach (const EGLSurface &surface, d->surfaceForWindow) - eglDestroySurface(d->eglDisplay, surface); if (d->eglContext != EGL_NO_CONTEXT) eglDestroyContext(d->eglDisplay, d->eglContext); if (d->eglDisplay != EGL_NO_DISPLAY) @@ -112,23 +109,13 @@ bool QWinRTEGLContext::makeCurrent(QPlatformSurface *windowSurface) Q_D(QWinRTEGLContext); Q_ASSERT(windowSurface->surface()->surfaceType() == QSurface::OpenGLSurface); - EGLSurface surface = d->surfaceForWindow.value(windowSurface); - if (surface == EGL_NO_SURFACE) { - QWinRTWindow *window = static_cast(windowSurface); - HRESULT hr = QEventDispatcherWinRT::runOnXamlThread([this, d, window, &surface]() { - surface = eglCreateWindowSurface(d->eglDisplay, d->eglConfig, - reinterpret_cast(window->winId()), - nullptr); - if (surface == EGL_NO_SURFACE) { - qCritical("Failed to create EGL window surface: 0x%x", eglGetError()); - return E_FAIL; - } - return S_OK; - }); - if (FAILED(hr)) - return false; - d->surfaceForWindow.insert(windowSurface, surface); - } + QWinRTWindow *window = static_cast(windowSurface); + if (window->eglSurface() == EGL_NO_SURFACE) + window->createEglSurface(d->eglDisplay, d->eglConfig); + + EGLSurface surface = window->eglSurface(); + if (surface == EGL_NO_SURFACE) + return false; const bool ok = eglMakeCurrent(d->eglDisplay, surface, surface, d->eglContext); if (!ok) { @@ -153,7 +140,8 @@ void QWinRTEGLContext::swapBuffers(QPlatformSurface *windowSurface) Q_D(QWinRTEGLContext); Q_ASSERT(windowSurface->surface()->surfaceType() == QSurface::OpenGLSurface); - eglSwapBuffers(d->eglDisplay, d->surfaceForWindow.value(windowSurface)); + const QWinRTWindow *window = static_cast(windowSurface); + eglSwapBuffers(d->eglDisplay, window->eglSurface()); } QSurfaceFormat QWinRTEGLContext::format() const -- cgit v1.2.3