summaryrefslogtreecommitdiffstats
path: root/src/plugins
diff options
context:
space:
mode:
authorTor Arne Vestbø <tor.arne.vestbo@qt.io>2017-11-30 16:46:41 +0100
committerTor Arne Vestbø <tor.arne.vestbo@qt.io>2017-12-06 20:47:05 +0000
commit933497bace2ddfd9920100ccf155658cd2030c7c (patch)
tree47ee45f0795a0267782e98ab5153aefdcc209892 /src/plugins
parente37c9d5d5f4ba9874808a4e565c36b2953eb96da (diff)
iOS: Ignore view layouts while in the background
Despite the OpenGL ES Programming Guide telling us to avoid all use of OpenGL while in the background, iOS will perform its view snapshotting for the app switcher after the application has been backgrounded; once for each orientation. Presumably the expectation is that no rendering needs to be done to provide an alternate orientation snapshot, just relayouting of views. But in our case, or any non-stretchable content case such as a OpenGL based game, this is not true. Instead of continuing layout, which will send potentially expensive geometry changes (with isExposed false, since we're in the background), we short-circuit the snapshotting. iOS will still use the latest rendered frame to create the application switcher thumbnail, but it will be based on the last active orientation of the application. To ensure that we pick up the right geometry when rotating the device while the app is in the background, we treat applicationWillEnterForeground as Qt::ApplicationInactive, which matches the recommendations of the OpenGL ES Programming Guide to "re-create any objects and restart your animation timers". Change-Id: Ia9c27f85f996ecf30284c825b43447aa7099224e Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
Diffstat (limited to 'src/plugins')
-rw-r--r--src/plugins/platforms/ios/qiosapplicationstate.mm1
-rw-r--r--src/plugins/platforms/ios/qiosviewcontroller.mm20
2 files changed, 21 insertions, 0 deletions
diff --git a/src/plugins/platforms/ios/qiosapplicationstate.mm b/src/plugins/platforms/ios/qiosapplicationstate.mm
index fed09999b5..3407aebf8f 100644
--- a/src/plugins/platforms/ios/qiosapplicationstate.mm
+++ b/src/plugins/platforms/ios/qiosapplicationstate.mm
@@ -58,6 +58,7 @@ static void qRegisterApplicationStateNotifications()
// there's no separate notification for moving to UIApplicationStateInactive,
// so we use UIApplicationWillResignActiveNotification as an intermediate.
static QMap<NSNotificationName, UIApplicationState> notifications {
+ { UIApplicationWillEnterForegroundNotification, UIApplicationStateInactive },
{ UIApplicationDidBecomeActiveNotification, UIApplicationStateActive },
{ UIApplicationWillResignActiveNotification, UIApplicationStateInactive },
{ UIApplicationDidEnterBackgroundNotification, UIApplicationStateBackground },
diff --git a/src/plugins/platforms/ios/qiosviewcontroller.mm b/src/plugins/platforms/ios/qiosviewcontroller.mm
index c47b6d68b1..a9fdfaf9f1 100644
--- a/src/plugins/platforms/ios/qiosviewcontroller.mm
+++ b/src/plugins/platforms/ios/qiosviewcontroller.mm
@@ -157,6 +157,26 @@
- (void)layoutSubviews
{
+ if (QGuiApplication::applicationState() == Qt::ApplicationSuspended) {
+ // Despite the OpenGL ES Programming Guide telling us to avoid all
+ // use of OpenGL while in the background, iOS will perform its view
+ // snapshotting for the app switcher after the application has been
+ // backgrounded; once for each orientation. Presumably the expectation
+ // is that no rendering needs to be done to provide an alternate
+ // orientation snapshot, just relayouting of views. But in our case,
+ // or any non-stretchable content case such as a OpenGL based game,
+ // this is not true. Instead of continuing layout, which will send
+ // potentially expensive geometry changes (with isExposed false,
+ // since we're in the background), we short-circuit the snapshotting
+ // here. iOS will still use the latest rendered frame to create the
+ // application switcher thumbnail, but it will be based on the last
+ // active orientation of the application.
+ QIOSScreen *screen = self.qtViewController->m_screen;
+ qCDebug(lcQpaWindow) << "ignoring layout of subviews while suspended,"
+ << "likely system snapshot of" << screen->screen()->primaryOrientation();
+ return;
+ }
+
for (int i = int(self.subviews.count) - 1; i >= 0; --i) {
UIView *view = static_cast<UIView *>([self.subviews objectAtIndex:i]);
if (![view isKindOfClass:[QUIView class]])