summaryrefslogtreecommitdiffstats
path: root/src/plugins/platforms/winrt/qwinrteglcontext.cpp
diff options
context:
space:
mode:
authorSamuel Nevala <samuel.nevala@intopalo.com>2015-09-10 13:14:57 +0300
committerAndrew Knight <andrew.knight@intopalo.com>2015-09-14 19:20:02 +0000
commitf3fd7b3d961ffed480e5851e594f6981f558f486 (patch)
tree8acc33a2a5d706a48d893c78d3be35e8a5303955 /src/plugins/platforms/winrt/qwinrteglcontext.cpp
parentfe1ba879610c73075b10f274bba338af53a6bd43 (diff)
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 <andrew.knight@intopalo.com>
Diffstat (limited to 'src/plugins/platforms/winrt/qwinrteglcontext.cpp')
-rw-r--r--src/plugins/platforms/winrt/qwinrteglcontext.cpp30
1 files changed, 9 insertions, 21 deletions
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<QPlatformSurface *, EGLSurface> 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<QWinRTWindow *>(windowSurface);
- HRESULT hr = QEventDispatcherWinRT::runOnXamlThread([this, d, window, &surface]() {
- surface = eglCreateWindowSurface(d->eglDisplay, d->eglConfig,
- reinterpret_cast<EGLNativeWindowType>(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<QWinRTWindow *>(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<QWinRTWindow *>(windowSurface);
+ eglSwapBuffers(d->eglDisplay, window->eglSurface());
}
QSurfaceFormat QWinRTEGLContext::format() const