From eb95685556143eb71323742bfcdaa20541b01375 Mon Sep 17 00:00:00 2001 From: Eskil Abrahamsen Blomfeldt Date: Mon, 15 Apr 2013 11:23:04 +0200 Subject: Android: Don't crash when displaying multiple top-levels While the raster platform plugin supports multiple top level windows, this is not supported on the GL plugin, so if you use GL or QtQuick2 in your app and use several top levels, the app would crash with an error message. A problem is that the top-level SurfaceView is a special overlay View and does not support being stacked in a layout. So instead, we let all windows share the same GL surface and draw on top of each other. This works fine for simple use cases. We implement a new platform capability to make sure no top level windows (even combobox popups and dialogs) get non-fullscreen geometries. That has never worked properly with the eglfs plugin. Task-number: QTBUG-30473 Change-Id: Ia1438019638fc739cc93ffe79b46b81631254df2 Reviewed-by: Paul Olav Tvete --- .../src/opengl/qandroidopenglplatformwindow.cpp | 58 +++++++++++++++++++++- 1 file changed, 57 insertions(+), 1 deletion(-) (limited to 'src/plugins/platforms/android/src/opengl/qandroidopenglplatformwindow.cpp') diff --git a/src/plugins/platforms/android/src/opengl/qandroidopenglplatformwindow.cpp b/src/plugins/platforms/android/src/opengl/qandroidopenglplatformwindow.cpp index 15c6559157..5362906e0e 100644 --- a/src/plugins/platforms/android/src/opengl/qandroidopenglplatformwindow.cpp +++ b/src/plugins/platforms/android/src/opengl/qandroidopenglplatformwindow.cpp @@ -45,11 +45,21 @@ QT_BEGIN_NAMESPACE +EGLSurface QAndroidOpenGLPlatformWindow::m_staticSurface = 0; +EGLNativeWindowType QAndroidOpenGLPlatformWindow::m_staticNativeWindow = 0; +QReadWriteLock QAndroidOpenGLPlatformWindow::m_staticSurfaceLock; +QBasicAtomicInt QAndroidOpenGLPlatformWindow::m_referenceCount = Q_BASIC_ATOMIC_INITIALIZER(0); + QAndroidOpenGLPlatformWindow::QAndroidOpenGLPlatformWindow(QWindow *window) : QEglFSWindow(window) { } +QAndroidOpenGLPlatformWindow::~QAndroidOpenGLPlatformWindow() +{ + destroy(); +} + bool QAndroidOpenGLPlatformWindow::isExposed() const { return QtAndroid::nativeWindow(false) != 0 && QEglFSWindow::isExposed(); @@ -60,11 +70,57 @@ void QAndroidOpenGLPlatformWindow::invalidateSurface() QWindowSystemInterface::handleExposeEvent(window(), QRegion()); // Obscure event QWindowSystemInterface::flushWindowSystemEvents(); QEglFSWindow::invalidateSurface(); + + m_window = 0; + m_surface = 0; + + if (!m_referenceCount.deref()){ + QWriteLocker locker(&m_staticSurfaceLock); + + EGLDisplay display = (static_cast(window()->screen()->handle()))->display(); + eglDestroySurface(display, m_staticSurface); + + m_staticSurface = 0; + m_staticNativeWindow = 0; + } } void QAndroidOpenGLPlatformWindow::resetSurface() { - QEglFSWindow::resetSurface(); + m_referenceCount.ref(); + if (m_staticSurface == 0) { + QWriteLocker locker(&m_staticSurfaceLock); + QEglFSWindow::resetSurface(); + m_staticSurface = m_surface; + m_staticNativeWindow = m_window; + } else { + QReadLocker locker(&m_staticSurfaceLock); + Q_ASSERT(m_staticSurface != m_surface); + m_window = m_staticNativeWindow; + m_surface = m_staticSurface; + } + + QWindowSystemInterface::handleExposeEvent(window(), QRegion(geometry())); // Expose event + QWindowSystemInterface::flushWindowSystemEvents(); +} + +void QAndroidOpenGLPlatformWindow::destroy() +{ + if (!m_referenceCount.deref()) { + QEglFSWindow::destroy(); + } else { + m_window = 0; + m_surface = 0; + } +} + +void QAndroidOpenGLPlatformWindow::raise() +{ +} + +void QAndroidOpenGLPlatformWindow::setVisible(bool visible) +{ + QEglFSWindow::setVisible(visible); QWindowSystemInterface::handleExposeEvent(window(), QRegion(geometry())); // Expose event QWindowSystemInterface::flushWindowSystemEvents(); } -- cgit v1.2.3