Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Fix #1975 - improve animation fluidity and response #2922

Merged
merged 4 commits into from
Nov 4, 2015
Merged
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
37 changes: 30 additions & 7 deletions platform/ios/MGLMapView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
const CGFloat MGLMaximumPitch = 60;
const CLLocationDegrees MGLAngularFieldOfView = M_PI / 6.;
const std::string spritePrefix = "com.mapbox.sprites.";
const NSUInteger MGLTargetFrameInterval = 2; //Target FPS will be 60 divided by this value

NSString *const MGLAnnotationIDKey = @"MGLAnnotationIDKey";
NSString *const MGLAnnotationSymbolKey = @"MGLAnnotationSymbolKey";
Expand Down Expand Up @@ -124,6 +125,9 @@ @implementation MGLMapView

CLLocationDegrees _pendingLatitude;
CLLocationDegrees _pendingLongitude;

CADisplayLink *_displayLink;
BOOL _needsDisplayRefresh;
}

#pragma mark - Setup & Teardown -
Expand Down Expand Up @@ -226,6 +230,12 @@ - (void)commonInit
// setup mbgl map
_mbglMap = new mbgl::Map(*_mbglView, *_mbglFileSource, mbgl::MapMode::Continuous);

// setup refresh driver
_displayLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(updateFromDisplayLink)];
_displayLink.frameInterval = MGLTargetFrameInterval;
[_displayLink addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
_needsDisplayRefresh = YES;

// start paused if in IB
if (_isTargetingInterfaceBuilder || background) {
self.dormant = YES;
Expand Down Expand Up @@ -386,7 +396,7 @@ - (void)createGLView
//
_glView = [[GLKView alloc] initWithFrame:self.bounds context:_context];
_glView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
_glView.enableSetNeedsDisplay = YES;
_glView.enableSetNeedsDisplay = NO;
_glView.drawableStencilFormat = GLKViewDrawableStencilFormat8;
_glView.drawableDepthFormat = GLKViewDrawableDepthFormat16;
_glView.contentScaleFactor = [UIScreen instancesRespondToSelector:@selector(nativeScale)] ? [[UIScreen mainScreen] nativeScale] : [[UIScreen mainScreen] scale];
Expand Down Expand Up @@ -734,6 +744,25 @@ - (void)layoutSubviews

#pragma mark - Life Cycle -

- (void)updateFromDisplayLink
{
MGLAssertIsMainThread();

if (_needsDisplayRefresh)
{
_needsDisplayRefresh = NO;

[self.glView display];
}
}

- (void)invalidate
{
MGLAssertIsMainThread();

_needsDisplayRefresh = YES;
}

- (void)willTerminate
{
MGLAssertIsMainThread();
Expand Down Expand Up @@ -3104,12 +3133,6 @@ + (NSString *)pathForBundleResourceNamed:(NSString *)name ofType:(NSString *)ext
return path;
}

- (void)invalidate
{
MGLAssertIsMainThread();
[self.glView setNeedsDisplay];
}

- (BOOL)isFullyLoaded
{
return _mbglMap->isFullyLoaded();
Expand Down