diff options
Diffstat (limited to 'src/plugins/platforms/android/qandroidplatformopenglwindow.cpp')
-rw-r--r-- | src/plugins/platforms/android/qandroidplatformopenglwindow.cpp | 74 |
1 files changed, 62 insertions, 12 deletions
diff --git a/src/plugins/platforms/android/qandroidplatformopenglwindow.cpp b/src/plugins/platforms/android/qandroidplatformopenglwindow.cpp index f0c4a1de2a..d3fb22094a 100644 --- a/src/plugins/platforms/android/qandroidplatformopenglwindow.cpp +++ b/src/plugins/platforms/android/qandroidplatformopenglwindow.cpp @@ -42,9 +42,12 @@ #include "qandroidplatformopenglwindow.h" +#include "qandroidplatformscreen.h" #include "androidjnimain.h" +#include "qandroideventdispatcher.h" #include <QSurfaceFormat> +#include <QtGui/private/qwindow_p.h> #include <qpa/qwindowsysteminterface.h> #include <qpa/qplatformscreen.h> @@ -57,10 +60,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() @@ -73,30 +72,67 @@ QAndroidPlatformOpenGLWindow::~QAndroidPlatformOpenGLWindow() unlockSurface(); } +void QAndroidPlatformOpenGLWindow::repaint(const QRegion ®ion) +{ + // This is only for real raster top-level windows. Stop in all other cases. + if ((window()->surfaceType() == QSurface::RasterGLSurface && qt_window_private(window())->compositing) + || window()->surfaceType() == QSurface::OpenGLSurface + || QAndroidPlatformWindow::parent()) + return; + + QRect currentGeometry = geometry(); + + QRect dirtyClient = region.boundingRect(); + QRect dirtyRegion(currentGeometry.left() + dirtyClient.left(), + currentGeometry.top() + dirtyClient.top(), + dirtyClient.width(), + dirtyClient.height()); + QRect mOldGeometryLocal = m_oldGeometry; + m_oldGeometry = currentGeometry; + // If this is a move, redraw the previous location + if (mOldGeometryLocal != currentGeometry) + platformScreen()->setDirty(mOldGeometryLocal); + platformScreen()->setDirty(dirtyRegion); +} + void QAndroidPlatformOpenGLWindow::setGeometry(const QRect &rect) { if (rect == geometry()) return; - QRect oldGeometry = geometry(); + m_oldGeometry = geometry(); QAndroidPlatformWindow::setGeometry(rect); - QtAndroid::setSurfaceGeometry(m_nativeSurfaceId, rect); + if (m_nativeSurfaceId != -1) + QtAndroid::setSurfaceGeometry(m_nativeSurfaceId, rect); QRect availableGeometry = screen()->availableGeometry(); - if (oldGeometry.width() == 0 - && oldGeometry.height() == 0 + if (m_oldGeometry.width() == 0 + && m_oldGeometry.height() == 0 && rect.width() > 0 && rect.height() > 0 && availableGeometry.width() > 0 && availableGeometry.height() > 0) { - QWindowSystemInterface::handleExposeEvent(window(), QRegion(rect)); + QWindowSystemInterface::handleExposeEvent(window(), QRect(QPoint(0, 0), rect.size())); } + + if (rect.topLeft() != m_oldGeometry.topLeft()) + repaint(QRegion(rect)); } EGLSurface QAndroidPlatformOpenGLWindow::eglSurface(EGLConfig config) { + if (QAndroidEventDispatcherStopper::stopped()) + return m_eglSurface; + 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); @@ -117,7 +153,21 @@ void QAndroidPlatformOpenGLWindow::checkNativeSurface(EGLConfig config) // we've create another surface, the window should be repainted QRect availableGeometry = screen()->availableGeometry(); if (geometry().width() > 0 && geometry().height() > 0 && availableGeometry.width() > 0 && availableGeometry.height() > 0) - QWindowSystemInterface::handleExposeEvent(window(), QRegion(geometry())); + QWindowSystemInterface::handleExposeEvent(window(), QRegion(QRect(QPoint(), geometry().size()))); +} + +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) @@ -145,8 +195,8 @@ QSurfaceFormat QAndroidPlatformOpenGLWindow::format() const void QAndroidPlatformOpenGLWindow::clearEgl() { - eglMakeCurrent(m_eglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); if (m_eglSurface != EGL_NO_SURFACE) { + eglMakeCurrent(m_eglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); eglDestroySurface(m_eglDisplay, m_eglSurface); m_eglSurface = EGL_NO_SURFACE; } @@ -170,7 +220,7 @@ void QAndroidPlatformOpenGLWindow::surfaceChanged(JNIEnv *jniEnv, jobject surfac // repaint the window QRect availableGeometry = screen()->availableGeometry(); if (geometry().width() > 0 && geometry().height() > 0 && availableGeometry.width() > 0 && availableGeometry.height() > 0) - QWindowSystemInterface::handleExposeEvent(window(), QRegion(geometry())); + QWindowSystemInterface::handleExposeEvent(window(), QRegion(QRect(QPoint(), geometry().size()))); } QT_END_NAMESPACE |