summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/plugins/platforms/winrt/qwinrteglcontext.cpp30
-rw-r--r--src/plugins/platforms/winrt/qwinrtwindow.cpp31
-rw-r--r--src/plugins/platforms/winrt/qwinrtwindow.h4
3 files changed, 44 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
diff --git a/src/plugins/platforms/winrt/qwinrtwindow.cpp b/src/plugins/platforms/winrt/qwinrtwindow.cpp
index 5ff1c8bd19..c5b06a5d8a 100644
--- a/src/plugins/platforms/winrt/qwinrtwindow.cpp
+++ b/src/plugins/platforms/winrt/qwinrtwindow.cpp
@@ -88,6 +88,8 @@ public:
QSurfaceFormat surfaceFormat;
QString windowTitle;
Qt::WindowState state;
+ EGLDisplay display;
+ EGLSurface surface;
ComPtr<ISwapChainPanel> swapChainPanel;
ComPtr<ICanvasStatics> canvas;
@@ -100,6 +102,8 @@ QWinRTWindow::QWinRTWindow(QWindow *window)
{
Q_D(QWinRTWindow);
+ d->surface = EGL_NO_SURFACE;
+ d->display = EGL_NO_DISPLAY;
d->screen = static_cast<QWinRTScreen *>(screen());
setWindowFlags(window->flags());
setWindowState(window->windowState());
@@ -170,6 +174,11 @@ QWinRTWindow::~QWinRTWindow()
return S_OK;
});
RETURN_VOID_IF_FAILED("Failed to completely destroy window resources, likely because the application is shutting down");
+
+ EGLBoolean value = eglDestroySurface(d->display, d->surface);
+ d->surface = EGL_NO_SURFACE;
+ if (value == EGL_FALSE)
+ qCritical("Failed to destroy EGL window surface: 0x%x", eglGetError());
}
QSurfaceFormat QWinRTWindow::format() const
@@ -293,4 +302,26 @@ void QWinRTWindow::setWindowState(Qt::WindowState state)
d->state = state;
}
+EGLSurface QWinRTWindow::eglSurface() const
+{
+ Q_D(const QWinRTWindow);
+ return d->surface;
+}
+
+void QWinRTWindow::createEglSurface(EGLDisplay display, EGLConfig config)
+{
+ Q_D(QWinRTWindow);
+ if (d->surface == EGL_NO_SURFACE) {
+ d->display = display;
+ QEventDispatcherWinRT::runOnXamlThread([this, d, display, config]() {
+ d->surface = eglCreateWindowSurface(display, config,
+ reinterpret_cast<EGLNativeWindowType>(winId()),
+ nullptr);
+ if (d->surface == EGL_NO_SURFACE)
+ qCritical("Failed to create EGL window surface: 0x%x", eglGetError());
+ return S_OK;
+ });
+ }
+}
+
QT_END_NAMESPACE
diff --git a/src/plugins/platforms/winrt/qwinrtwindow.h b/src/plugins/platforms/winrt/qwinrtwindow.h
index 2957a7498b..9ac7adbf4d 100644
--- a/src/plugins/platforms/winrt/qwinrtwindow.h
+++ b/src/plugins/platforms/winrt/qwinrtwindow.h
@@ -39,6 +39,7 @@
#include <qpa/qplatformwindow.h>
#include <qpa/qwindowsysteminterface.h>
+#include <EGL/egl.h>
QT_BEGIN_NAMESPACE
@@ -63,6 +64,9 @@ public:
qreal devicePixelRatio() const Q_DECL_OVERRIDE;
void setWindowState(Qt::WindowState state) Q_DECL_OVERRIDE;
+ EGLSurface eglSurface() const;
+ void createEglSurface(EGLDisplay display, EGLConfig config);
+
private:
QScopedPointer<QWinRTWindowPrivate> d_ptr;
Q_DECLARE_PRIVATE(QWinRTWindow)