Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/ios performances #44

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@
/cmake-build-debug
/platform/android/build
/platform/android/MapboxGLAndroidSDK/src/main/assets/sdk_versions/com.mapbox.mapboxsdk
/platform/ios/platform/ios/Mapbox.playground/build/
*.code-workspace

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does Mapbox.playground allow for adding files to Git ignore?

That is, is it possible to remove the Playground binary build files by adding the following?

platform/ios/platform/ios/Mapbox.playground/build/

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be fine now

.DS_Store
/build
**/.idea
/platform/android/MapboxGLAndroidSDKTestApp/local.properties
Expand Down
Binary file added .gitignore.swp
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1120"
LastUpgradeVersion = "1240"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand All @@ -15,7 +15,7 @@
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "DA1DC9491CB6C1C2006E619F"
BuildableName = "Mapbox GL.app"
BuildableName = "MapLibre GL.app"
BlueprintName = "iosapp"
ReferencedContainer = "container:ios.xcodeproj">
</BuildableReference>
Expand All @@ -31,7 +31,7 @@
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "DA1DC9491CB6C1C2006E619F"
BuildableName = "Mapbox GL.app"
BuildableName = "MapLibre GL.app"
BlueprintName = "iosapp"
ReferencedContainer = "container:ios.xcodeproj">
</BuildableReference>
Expand All @@ -54,7 +54,7 @@
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "DA1DC9491CB6C1C2006E619F"
BuildableName = "Mapbox GL.app"
BuildableName = "MapLibre GL.app"
BlueprintName = "iosapp"
ReferencedContainer = "container:ios.xcodeproj">
</BuildableReference>
Expand All @@ -78,7 +78,7 @@
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "DA1DC9491CB6C1C2006E619F"
BuildableName = "Mapbox GL.app"
BuildableName = "MapLibre GL.app"
BlueprintName = "iosapp"
ReferencedContainer = "container:ios.xcodeproj">
</BuildableReference>
Expand Down
128 changes: 92 additions & 36 deletions platform/ios/platform/ios/src/MGLMapView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,12 @@ typedef NS_ENUM(NSUInteger, MGLUserTrackingState) {
/// The threshold used to consider when a tilt gesture should start.
const CLLocationDegrees MGLHorizontalTiltToleranceDegrees = 45.0;

/// The time between background snapshot attempts.
const NSTimeInterval MGLBackgroundSnapshotImageInterval = 60.0;

/// The delay after the map has idled before a background snapshot is attempted.
const NSTimeInterval MGLBackgroundSnapshotImageIdleDelay = 3.0;

/// Mapping from an annotation tag to metadata about that annotation, including
/// the annotation itself.
typedef std::unordered_map<MGLAnnotationTag, MGLAnnotationContext> MGLAnnotationTagContextMap;
Expand Down Expand Up @@ -1552,23 +1558,27 @@ - (void)pauseRendering:(__unused NSNotification *)notification
_displayLink.paused = YES;
[self processPendingBlocks];

if ( ! self.glSnapshotView)
if (self.lastSnapshotImage)
{
self.glSnapshotView = [[UIImageView alloc] initWithFrame: _mbglView->getView().frame];
self.glSnapshotView.autoresizingMask = _mbglView->getView().autoresizingMask;
self.glSnapshotView.contentMode = UIViewContentModeCenter;
[self insertSubview:self.glSnapshotView aboveSubview:_mbglView->getView()];
}

self.glSnapshotView.image = self.lastSnapshotImage;
self.glSnapshotView.hidden = NO;
if ( ! self.glSnapshotView)
{
self.glSnapshotView = [[UIImageView alloc] initWithFrame: _mbglView->getView().frame];
self.glSnapshotView.autoresizingMask = _mbglView->getView().autoresizingMask;
self.glSnapshotView.contentMode = UIViewContentModeCenter;
[self insertSubview:self.glSnapshotView aboveSubview:_mbglView->getView()];
}

self.glSnapshotView.image = self.lastSnapshotImage;
self.glSnapshotView.hidden = NO;
self.glSnapshotView.alpha = 1;

if (self.debugMask && [self.glSnapshotView.subviews count] == 0)
{
UIView *snapshotTint = [[UIView alloc] initWithFrame:self.glSnapshotView.bounds];
snapshotTint.autoresizingMask = self.glSnapshotView.autoresizingMask;
snapshotTint.backgroundColor = [[UIColor redColor] colorWithAlphaComponent:0.25];
[self.glSnapshotView addSubview:snapshotTint];
if (self.debugMask && [self.glSnapshotView.subviews count] == 0)
{
UIView *snapshotTint = [[UIView alloc] initWithFrame:self.glSnapshotView.bounds];
snapshotTint.autoresizingMask = self.glSnapshotView.autoresizingMask;
snapshotTint.backgroundColor = [[UIColor redColor] colorWithAlphaComponent:0.25];
[self.glSnapshotView addSubview:snapshotTint];
}
}

_mbglView->deleteView();
Expand All @@ -1586,9 +1596,15 @@ - (void)resumeRendering:(__unused NSNotification *)notification

_mbglView->createView();

self.glSnapshotView.hidden = YES;

[self.glSnapshotView.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
[UIView transitionWithView:self
duration:0.25
options:UIViewAnimationOptionTransitionCrossDissolve
animations:^{
self.glSnapshotView.hidden = YES;
}
completion:^(BOOL finished) {
[self.glSnapshotView.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
}];

_displayLink.paused = NO;

Expand Down Expand Up @@ -5946,29 +5962,32 @@ - (void)dismissHeadingCalibrationDisplay:(id<MGLLocationManager>)manager

- (void)locationManager:(__unused id<MGLLocationManager>)manager didUpdateHeading:(CLHeading *)newHeading
{
if ( ! _showsUserLocation || self.pan.state == UIGestureRecognizerStateBegan || newHeading.headingAccuracy < 0) return;
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^(void) {
if ( ! self->_showsUserLocation || self.pan.state == UIGestureRecognizerStateBegan || newHeading.headingAccuracy < 0) return;

self.userLocation.heading = newHeading;
self.userLocation.heading = newHeading;

if (self.showsUserHeadingIndicator || self.userTrackingMode == MGLUserTrackingModeFollowWithHeading)
{
[self updateUserLocationAnnotationView];
}
if (self.showsUserHeadingIndicator || self.userTrackingMode == MGLUserTrackingModeFollowWithHeading)
{
[self updateUserLocationAnnotationView];
}

if ([self.delegate respondsToSelector:@selector(mapView:didUpdateUserLocation:)])
{
[self.delegate mapView:self didUpdateUserLocation:self.userLocation];
if ([self.delegate respondsToSelector:@selector(mapView:didUpdateUserLocation:)])
{
[self.delegate mapView:self didUpdateUserLocation:self.userLocation];

if ( ! _showsUserLocation) return;
}
if (!self->_showsUserLocation) return;
}

CLLocationDirection headingDirection = (newHeading.trueHeading >= 0 ? newHeading.trueHeading : newHeading.magneticHeading);
CLLocationDirection headingDirection = (newHeading.trueHeading >= 0 ? newHeading.trueHeading : newHeading.magneticHeading);

if (headingDirection >= 0 && self.userTrackingMode == MGLUserTrackingModeFollowWithHeading
&& self.userTrackingState != MGLUserTrackingStateBegan)
{
[self _setDirection:headingDirection animated:YES];
}
if (headingDirection >= 0 && self.userTrackingMode == MGLUserTrackingModeFollowWithHeading
&& self.userTrackingState != MGLUserTrackingStateBegan)
{
[self _setDirection:headingDirection animated:YES];
[self updateUserLocationAnnotationView];
}
});
}

- (void)locationManager:(__unused id<MGLLocationManager>)manager didFailWithError:(NSError *)error
Expand Down Expand Up @@ -6353,6 +6372,8 @@ - (void)mapViewDidFailLoadingMapWithError:(NSError *)error {
}

- (void)mapViewWillStartRenderingFrame {
[self cancelBackgroundSnapshot];

if (!_mbglMap)
{
return;
Expand Down Expand Up @@ -6412,7 +6433,9 @@ - (void)mapViewDidBecomeIdle {
if (!_mbglMap) {
return;
}


[self queueBackgroundSnapshot];

if ([self.delegate respondsToSelector:@selector(mapViewDidBecomeIdle:)]) {
[self.delegate mapViewDidBecomeIdle:self];
}
Expand Down Expand Up @@ -6891,6 +6914,39 @@ - (void)prepareForInterfaceBuilder
return _annotationViewReuseQueueByIdentifier[identifier];
}

#pragma mark - Snapshot image -

- (void)attemptBackgroundSnapshot {
static NSTimeInterval lastSnapshotTime = 0.0;

if ([UIApplication sharedApplication].applicationState != UIApplicationStateActive) {
return;
}

NSTimeInterval now = CACurrentMediaTime();

if (lastSnapshotTime == 0.0 || (now - lastSnapshotTime > MGLBackgroundSnapshotImageInterval)) {
self.lastSnapshotImage = _mbglView->snapshot();
lastSnapshotTime = now;
}
}

- (void)cancelBackgroundSnapshot
{
[NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(attemptBackgroundSnapshot) object:nil];
}

- (void)queueBackgroundSnapshot {
if ([UIApplication sharedApplication].applicationState != UIApplicationStateActive) {
return;
}

[self cancelBackgroundSnapshot];
[self performSelector:@selector(attemptBackgroundSnapshot)
withObject:nil
afterDelay:MGLBackgroundSnapshotImageIdleDelay];
}

@end

#pragma mark - IBAdditions methods
Expand Down