diff options
author | Adam Hunter <adam@mapbox.com> | 2015-11-03 16:47:40 -0800 |
---|---|---|
committer | Justin R. Miller <incanus@codesorcery.net> | 2015-11-04 10:33:30 -0800 |
commit | 36d90ea97d947dcacc5257bcb33cba139dad46bb (patch) | |
tree | a11b289d2971b817531d4e4499ccab2a776ad2aa /platform | |
parent | dfb36d62317d99482e6a16b772e8d370464d1cce (diff) | |
download | qtlocation-mapboxgl-36d90ea97d947dcacc5257bcb33cba139dad46bb.tar.gz |
Fix #1975 - improve animation fluidity and response
Diffstat (limited to 'platform')
-rw-r--r-- | platform/ios/MGLMapView.mm | 27 |
1 files changed, 25 insertions, 2 deletions
diff --git a/platform/ios/MGLMapView.mm b/platform/ios/MGLMapView.mm index 54cc3e879f..347b3a70cb 100644 --- a/platform/ios/MGLMapView.mm +++ b/platform/ios/MGLMapView.mm @@ -40,6 +40,7 @@ #import <algorithm> #import <cstdlib> #import <unordered_set> +#include <mutex> class MBGLView; @@ -108,6 +109,9 @@ mbgl::util::UnitBezier MGLUnitBezierForMediaTimingFunction(CAMediaTimingFunction @property (nonatomic, getter=isAnimatingGesture) BOOL animatingGesture; @property (nonatomic, readonly, getter=isRotationAllowed) BOOL rotationAllowed; +@property (nonatomic) CADisplayLink *displayLink; +@property (nonatomic) BOOL needsDisplay; + @end @implementation MGLMapView @@ -124,6 +128,8 @@ mbgl::util::UnitBezier MGLUnitBezierForMediaTimingFunction(CAMediaTimingFunction CLLocationDegrees _pendingLatitude; CLLocationDegrees _pendingLongitude; + + std::mutex needsDisplayMutex; } #pragma mark - Setup & Teardown - @@ -371,6 +377,10 @@ std::chrono::steady_clock::duration secondsAsDuration(float duration) MGLEventKeyZoomLevel: @(zoom), MGLEventKeyPushEnabled: @([MGLMapboxEvents checkPushEnabled]) }]; + self.displayLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(updateFromDisplayLink)]; + self.displayLink.frameInterval = 2; + [self.displayLink addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode]; + _needsDisplay = YES; } - (void)createGLView @@ -386,7 +396,7 @@ std::chrono::steady_clock::duration secondsAsDuration(float duration) // _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]; @@ -3104,10 +3114,23 @@ CLLocationCoordinate2D MGLLocationCoordinate2DFromLatLng(mbgl::LatLng latLng) return path; } +- (void)updateFromDisplayLink +{ + std::unique_lock<std::mutex> lock(needsDisplayMutex); + if (_needsDisplay) { + _needsDisplay = NO; + lock.unlock(); + [self.glView display]; + } else { + lock.unlock(); + } +} + - (void)invalidate { + std::lock_guard<std::mutex> lock(needsDisplayMutex); MGLAssertIsMainThread(); - [self.glView setNeedsDisplay]; + _needsDisplay = YES; } - (BOOL)isFullyLoaded |