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>bb10
parent
e37c9d5d5f
commit
933497bace
|
|
@ -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 },
|
||||
|
|
|
|||
|
|
@ -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]])
|
||||
|
|
|
|||
Loading…
Reference in New Issue