diff options
author | BogDan Vatra <bogdan@kde.org> | 2014-07-21 17:09:31 +0300 |
---|---|---|
committer | BogDan Vatra <bogdan@kde.org> | 2014-07-31 19:20:42 +0200 |
commit | 96f0ff4f28c92b529a4d79afa669917734ec1192 (patch) | |
tree | 24dc77e2e40010374cb4b190b849414f04815e99 /src/plugins/platforms/android/qandroidplatformopenglwindow.cpp | |
parent | 734c1268269a71b16829d36179e4a090f76c785e (diff) |
Android: Release all windows when the application is suspended.
When an application is suspended on Android all its Gl surfaces
are destroyed and can't be used to render anymore, so we should
release them in order to give back to the system the memory used
by them.
[ChangeLog] [Android] Release all windows when the application is
suspended.
Task-number: QTBUG-29069
Change-Id: I038aaa2006da1f3188fccba943ec4ffb3e551cf0
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@digia.com>
Diffstat (limited to 'src/plugins/platforms/android/qandroidplatformopenglwindow.cpp')
-rw-r--r-- | src/plugins/platforms/android/qandroidplatformopenglwindow.cpp | 25 |
1 files changed, 21 insertions, 4 deletions
diff --git a/src/plugins/platforms/android/qandroidplatformopenglwindow.cpp b/src/plugins/platforms/android/qandroidplatformopenglwindow.cpp index f0c4a1de2a..d14426d595 100644 --- a/src/plugins/platforms/android/qandroidplatformopenglwindow.cpp +++ b/src/plugins/platforms/android/qandroidplatformopenglwindow.cpp @@ -57,10 +57,6 @@ QT_BEGIN_NAMESPACE QAndroidPlatformOpenGLWindow::QAndroidPlatformOpenGLWindow(QWindow *window, EGLDisplay display) :QAndroidPlatformWindow(window), m_eglDisplay(display) { - lockSurface(); - m_nativeSurfaceId = QtAndroid::createSurface(this, geometry(), bool(window->flags() & Qt::WindowStaysOnTopHint), 32); - m_surfaceWaitCondition.wait(&m_surfaceMutex); - unlockSurface(); } QAndroidPlatformOpenGLWindow::~QAndroidPlatformOpenGLWindow() @@ -97,6 +93,13 @@ void QAndroidPlatformOpenGLWindow::setGeometry(const QRect &rect) EGLSurface QAndroidPlatformOpenGLWindow::eglSurface(EGLConfig config) { QMutexLocker lock(&m_surfaceMutex); + + if (m_nativeSurfaceId == -1) { + const bool windowStaysOnTop = bool(window()->flags() & Qt::WindowStaysOnTopHint); + m_nativeSurfaceId = QtAndroid::createSurface(this, geometry(), windowStaysOnTop, 32); + m_surfaceWaitCondition.wait(&m_surfaceMutex); + } + if (m_eglSurface == EGL_NO_SURFACE) { m_surfaceMutex.unlock(); checkNativeSurface(config); @@ -120,6 +123,20 @@ void QAndroidPlatformOpenGLWindow::checkNativeSurface(EGLConfig config) QWindowSystemInterface::handleExposeEvent(window(), QRegion(geometry())); } +void QAndroidPlatformOpenGLWindow::applicationStateChanged(Qt::ApplicationState state) +{ + QAndroidPlatformWindow::applicationStateChanged(state); + if (state <= Qt::ApplicationHidden && QtAndroid::blockEventLoopsWhenSuspended()) { + lockSurface(); + if (m_nativeSurfaceId != -1) { + QtAndroid::destroySurface(m_nativeSurfaceId); + m_nativeSurfaceId = -1; + } + clearEgl(); + unlockSurface(); + } +} + void QAndroidPlatformOpenGLWindow::createEgl(EGLConfig config) { clearEgl(); |