From 933497bace2ddfd9920100ccf155658cd2030c7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Thu, 30 Nov 2017 16:46:41 +0100 Subject: 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 --- src/plugins/platforms/ios/qiosapplicationstate.mm | 1 + src/plugins/platforms/ios/qiosviewcontroller.mm | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+) (limited to 'src/plugins') 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 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([self.subviews objectAtIndex:i]); if (![view isKindOfClass:[QUIView class]]) -- cgit v1.2.3