From 6960cb13f7d3d6564de90f5a25884003c33a4c4f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Minh=20Nguye=CC=82=CC=83n?= Date: Wed, 9 Jan 2019 23:24:40 -0800 Subject: [ios] Prevent map view on external display from sleeping in background MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When the application enters background mode, only put the map view to sleep if it’s installed on the main screen or hasn’t been added to any window. Otherwise, if it’s targeting an external display, such as via AirPlay or CarPlay, allow the map view to continue rendering. --- platform/ios/CHANGELOG.md | 2 +- platform/ios/src/MGLMapView.mm | 12 +++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/platform/ios/CHANGELOG.md b/platform/ios/CHANGELOG.md index bcd54800c8..58413b3184 100644 --- a/platform/ios/CHANGELOG.md +++ b/platform/ios/CHANGELOG.md @@ -9,7 +9,7 @@ Mapbox welcomes participation and contributions from everyone. Please read [CONT * Fixed a bug where the `animated` parameter to `-[MGLMapView selectAnnotation:animated:]` was being ignored. ([#13689](https://github.com/mapbox/mapbox-gl-native/pull/13689)) * Reinstates version 11 as the default Mapbox Streets style (as introduced in 4.7.0). ([#13690](https://github.com/mapbox/mapbox-gl-native/pull/13690)) * Added the `-[MGLShapeSource leavesOfCluster:offset:limit:]`, `-[MGLShapeSource childrenOfCluster:]`, `-[MGLShapeSource zoomLevelForExpandingCluster:]` methods for inspecting a cluster in an `MGLShapeSource`s created with the `MGLShapeSourceOptionClustered` option. Feature querying now returns clusters represented by `MGLPointFeatureCluster` objects (that conform to the `MGLCluster` protocol). ([#12952](https://github.com/mapbox/mapbox-gl-native/pull/12952) - +* `MGLMapView` no longer freezes on external displays connected through AirPlay or CarPlay when the main device’s screen goes to sleep or the user manually locks the screen. ([#13701](https://github.com/mapbox/mapbox-gl-native/pull/13701)) ## 4.7.1 - December 21, 2018 diff --git a/platform/ios/src/MGLMapView.mm b/platform/ios/src/MGLMapView.mm index 4d4bf39123..d188ffb91f 100644 --- a/platform/ios/src/MGLMapView.mm +++ b/platform/ios/src/MGLMapView.mm @@ -1222,7 +1222,7 @@ public: self.mbglMap.setConstrainMode(mbgl::ConstrainMode::HeightOnly); } - _displayLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(updateFromDisplayLink)]; + _displayLink = [self.window.screen displayLinkWithTarget:self selector:@selector(updateFromDisplayLink)]; [self updateDisplayLinkPreferredFramesPerSecond]; [_displayLink addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSRunLoopCommonModes]; _needsDisplayRefresh = YES; @@ -1301,6 +1301,16 @@ public: - (void)sleepGL:(__unused NSNotification *)notification { + // If this view targets an external display, such as AirPlay or CarPlay, we + // can safely continue to render OpenGL content without tripping + // gpus_ReturnNotPermittedKillClient in libGPUSupportMercury, because the + // external connection keeps the application from truly receding to the + // background. + if (self.window.screen != [UIScreen mainScreen]) + { + return; + } + MGLLogInfo(@"Entering background."); MGLAssertIsMainThread(); -- cgit v1.2.1