summaryrefslogtreecommitdiffstats
path: root/src/plugins/platforms/android/qandroidplatformopenglcontext.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins/platforms/android/qandroidplatformopenglcontext.cpp')
-rw-r--r--src/plugins/platforms/android/qandroidplatformopenglcontext.cpp30
1 files changed, 26 insertions, 4 deletions
diff --git a/src/plugins/platforms/android/qandroidplatformopenglcontext.cpp b/src/plugins/platforms/android/qandroidplatformopenglcontext.cpp
index faccf8b1173..fbfbb625dd2 100644
--- a/src/plugins/platforms/android/qandroidplatformopenglcontext.cpp
+++ b/src/plugins/platforms/android/qandroidplatformopenglcontext.cpp
@@ -22,19 +22,41 @@ QAndroidPlatformOpenGLContext::QAndroidPlatformOpenGLContext(const QSurfaceForma
void QAndroidPlatformOpenGLContext::swapBuffers(QPlatformSurface *surface)
{
- if (surface->surface()->surfaceClass() == QSurface::Window &&
- static_cast<QAndroidPlatformOpenGLWindow *>(surface)->checkNativeSurface(eglConfig())) {
- QEGLPlatformContext::makeCurrent(surface);
+ if (surface->surface()->surfaceClass() != QSurface::Window) {
+ QEGLPlatformContext::swapBuffers(surface);
+ return;
}
+ QAndroidPlatformOpenGLWindow *window = static_cast<QAndroidPlatformOpenGLWindow *>(surface);
+ // Since QEGLPlatformContext::makeCurrent() and QEGLPlatformContext::swapBuffers()
+ // will be using the eglSurface of the window, which wraps the Android Surface, we
+ // need to lock here to make sure we don't end up using a Surface already destroyed
+ // by Android
+ window->lockSurface();
+
+ if (window->checkNativeSurface(eglConfig())) {
+ // Call base class implementation directly since we are already locked
+ QEGLPlatformContext::makeCurrent(surface);
+ }
QEGLPlatformContext::swapBuffers(surface);
+
+ window->unlockSurface();
}
bool QAndroidPlatformOpenGLContext::makeCurrent(QPlatformSurface *surface)
{
- return QEGLPlatformContext::makeCurrent(surface);
+ if (surface->surface()->surfaceClass() != QSurface::Window)
+ return QEGLPlatformContext::makeCurrent(surface);
+
+ QAndroidPlatformOpenGLWindow *window = static_cast<QAndroidPlatformOpenGLWindow *>(surface);
+ window->lockSurface();
+ const bool ok = QEGLPlatformContext::makeCurrent(surface);
+ window->unlockSurface();
+ return ok;
}
+// Called from inside QEGLPlatformContext::swapBuffers() and QEGLPlatformContext::makeCurrent(),
+// already locked
EGLSurface QAndroidPlatformOpenGLContext::eglSurfaceForPlatformSurface(QPlatformSurface *surface)
{
if (surface->surface()->surfaceClass() == QSurface::Window) {