Android: Fix orientation change on Android 4.3

In Android 4.3, we will get a new native window pointer for the
same surface (the old surface has not been destroyed), whereas
before we would get the same pointer, thus hitting the
"sameNativeWindow" branch. This revealed some bugs in the
surfaceChanged code path when the old surface had not been
destroyed. This path is now taken both when there's no old surface
(the app has been suspended in the mean time) and when the
orientation changes.

To handle the second case, we need to make sure:
1. We update the static pointer
2. We update the pointers in the platform windows
3. We don't add a second reference to the static data for
windows
4. We schedule an update of the window size

Task-number: QTBUG-32878
Change-Id: I47257615f9ba820315fc98d7a804e52223f430bf
Reviewed-by: Christian Stromme <christian.stromme@digia.com>
Reviewed-by: Frederik Gladhorn <frederik.gladhorn@digia.com>
This commit is contained in:
Eskil Abrahamsen Blomfeldt 2013-08-15 10:45:51 +02:00 committed by The Qt Project
parent 07502898e9
commit 05ddae12d1
4 changed files with 41 additions and 19 deletions

View File

@ -555,33 +555,37 @@ static void setSurface(JNIEnv *env, jobject /*thiz*/, jobject jSurface)
m_nativeWindow = nativeWindow;
if (m_waitForWindow)
m_waitForWindowSemaphore.release();
if (m_androidPlatformIntegration && !sameNativeWindow) {
m_surfaceMutex.unlock();
m_androidPlatformIntegration->surfaceChanged();
} else if (m_androidPlatformIntegration && sameNativeWindow) {
QPlatformScreen *screen = m_androidPlatformIntegration->screen();
if (m_androidPlatformIntegration) {
QSize size = QtAndroid::nativeWindowSize();
QPlatformScreen *screen = m_androidPlatformIntegration->screen();
QRect geometry(QPoint(0, 0), size);
QWindowSystemInterface::handleScreenAvailableGeometryChange(screen->screen(), geometry);
QWindowSystemInterface::handleScreenGeometryChange(screen->screen(), geometry);
// Resize all top level windows, since they share the same surface
foreach (QWindow *w, QGuiApplication::topLevelWindows()) {
QAndroidOpenGLPlatformWindow *window =
static_cast<QAndroidOpenGLPlatformWindow *>(w->handle());
if (!sameNativeWindow) {
m_surfaceMutex.unlock();
m_androidPlatformIntegration->surfaceChanged();
} else {
// Resize all top level windows, since they share the same surface
foreach (QWindow *w, QGuiApplication::topLevelWindows()) {
QAndroidOpenGLPlatformWindow *window =
static_cast<QAndroidOpenGLPlatformWindow *>(w->handle());
if (window != 0) {
window->lock();
window->scheduleResize(size);
if (window != 0) {
window->lock();
window->scheduleResize(size);
QWindowSystemInterface::handleExposeEvent(window->window(),
QRegion(window->window()->geometry()));
window->unlock();
QWindowSystemInterface::handleExposeEvent(window->window(),
QRegion(window->window()->geometry()));
window->unlock();
}
}
m_surfaceMutex.unlock();
}
m_surfaceMutex.unlock();
} else {
m_surfaceMutex.unlock();
}

View File

@ -85,9 +85,19 @@ void QAndroidOpenGLPlatformWindow::invalidateSurface()
}
}
void QAndroidOpenGLPlatformWindow::updateStaticNativeWindow()
{
QWriteLocker locker(&m_staticSurfaceLock);
m_staticNativeWindow = QtAndroid::nativeWindow(false);
}
void QAndroidOpenGLPlatformWindow::resetSurface()
{
m_referenceCount.ref();
// Only add a reference if we're not already holding one, otherwise we're just updating
// the native window pointer
if (m_window == 0)
m_referenceCount.ref();
if (m_staticSurface == 0) {
QWriteLocker locker(&m_staticSurfaceLock);
QEglFSWindow::resetSurface();
@ -95,12 +105,17 @@ void QAndroidOpenGLPlatformWindow::resetSurface()
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
{
lock();
scheduleResize(QtAndroid::nativeWindowSize());
QWindowSystemInterface::handleExposeEvent(window(), QRegion(geometry())); // Expose event
unlock();
}
QWindowSystemInterface::flushWindowSystemEvents();
}

View File

@ -71,6 +71,8 @@ public:
void destroy();
static void updateStaticNativeWindow();
private:
QSize m_scheduledResize;
QMutex m_lock;

View File

@ -162,6 +162,7 @@ void QAndroidPlatformIntegration::invalidateNativeSurface()
void QAndroidPlatformIntegration::surfaceChanged()
{
QAndroidOpenGLPlatformWindow::updateStaticNativeWindow();
foreach (QWindow *w, QGuiApplication::topLevelWindows()) {
QAndroidOpenGLPlatformWindow *window =
static_cast<QAndroidOpenGLPlatformWindow *>(w->handle());