From 2bc038adc905497891294019007fcf0bf85f5638 Mon Sep 17 00:00:00 2001 From: Laszlo Agocs Date: Mon, 12 Jan 2015 16:52:05 +0100 Subject: Expose context loss On platforms like Windows (and presumably on mobile devices too) the loss of the context (e.g. the underlying D3D device in case of ANGLE) is an event that can happen randomly and needs sufficient handling. Enhance QOpenGLContext::isValid() with the purpose of indicating context loss. Currently only the Windows EGL backend (ANGLE) has support for it. Other platforms may be added later. Task-number: QTBUG-43263 Change-Id: I8177694c1ee7cebbd5d330e34757fd94c563e6d6 Reviewed-by: Friedemann Kleint --- src/plugins/platforms/windows/qwindowseglcontext.cpp | 12 +++++++++++- src/plugins/platforms/windows/qwindowswindow.cpp | 8 ++++++++ src/plugins/platforms/windows/qwindowswindow.h | 1 + 3 files changed, 20 insertions(+), 1 deletion(-) (limited to 'src/plugins') diff --git a/src/plugins/platforms/windows/qwindowseglcontext.cpp b/src/plugins/platforms/windows/qwindowseglcontext.cpp index c0d0c1f77c..0872741e47 100644 --- a/src/plugins/platforms/windows/qwindowseglcontext.cpp +++ b/src/plugins/platforms/windows/qwindowseglcontext.cpp @@ -592,7 +592,17 @@ bool QWindowsEGLContext::makeCurrent(QPlatformSurface *surface) QWindowsEGLStaticContext::libEGL.eglSwapInterval(m_staticContext->display(), m_swapInterval); } } else { - qWarning("QWindowsEGLContext::makeCurrent: eglError: %x, this: %p \n", QWindowsEGLStaticContext::libEGL.eglGetError(), this); + int err = QWindowsEGLStaticContext::libEGL.eglGetError(); + // EGL_CONTEXT_LOST (loss of the D3D device) is not necessarily fatal. + // Qt Quick is able to recover for example. + if (err == EGL_CONTEXT_LOST) { + m_eglContext = EGL_NO_CONTEXT; + qCDebug(lcQpaGl) << "Got EGL context lost in makeCurrent() for context" << this; + // Drop the surface. Will recreate on the next makeCurrent. + window->invalidateSurface(); + } else { + qWarning("QWindowsEGLContext::makeCurrent: eglError: %x, this: %p \n", err, this); + } } return ok; diff --git a/src/plugins/platforms/windows/qwindowswindow.cpp b/src/plugins/platforms/windows/qwindowswindow.cpp index 5d94ec3c38..5dfc48df99 100644 --- a/src/plugins/platforms/windows/qwindowswindow.cpp +++ b/src/plugins/platforms/windows/qwindowswindow.cpp @@ -2294,6 +2294,14 @@ void *QWindowsWindow::surface(void *nativeConfig) #endif } +void QWindowsWindow::invalidateSurface() +{ + if (m_surface) { + m_data.staticOpenGLContext->destroyWindowSurface(m_surface); + m_surface = 0; + } +} + void QWindowsWindow::setTouchWindowTouchTypeStatic(QWindow *window, QWindowsWindowFunctions::TouchWindowTouchTypes touchTypes) { if (!window->handle()) diff --git a/src/plugins/platforms/windows/qwindowswindow.h b/src/plugins/platforms/windows/qwindowswindow.h index 66102511e0..3e2f488f46 100644 --- a/src/plugins/platforms/windows/qwindowswindow.h +++ b/src/plugins/platforms/windows/qwindowswindow.h @@ -254,6 +254,7 @@ public: void setWindowIcon(const QIcon &icon); void *surface(void *nativeConfig); + void invalidateSurface() Q_DECL_OVERRIDE; #ifndef Q_OS_WINCE void setAlertState(bool enabled); -- cgit v1.2.3