From af758abf0fb45b93326ce274fa60e14d9973de38 Mon Sep 17 00:00:00 2001 From: "Justin R. Miller" Date: Wed, 4 Nov 2015 09:56:19 -0800 Subject: [PATCH] cleanups - We don't need a mutex as everything is ensured on main thread. - Move internal-only properties to ivars. - Avoid API collision with needsDisplay. - Move code to lifecycle section. --- platform/ios/MGLMapView.mm | 57 +++++++++++++++++++------------------- 1 file changed, 28 insertions(+), 29 deletions(-) diff --git a/platform/ios/MGLMapView.mm b/platform/ios/MGLMapView.mm index 347b3a70c..7c5b6aa40 100644 --- a/platform/ios/MGLMapView.mm +++ b/platform/ios/MGLMapView.mm @@ -40,7 +40,6 @@ #import #import #import -#include class MBGLView; @@ -109,9 +108,6 @@ 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 @@ -128,8 +124,9 @@ mbgl::util::UnitBezier MGLUnitBezierForMediaTimingFunction(CAMediaTimingFunction CLLocationDegrees _pendingLatitude; CLLocationDegrees _pendingLongitude; - - std::mutex needsDisplayMutex; + + CADisplayLink *_displayLink; + BOOL _needsDisplayRefresh; } #pragma mark - Setup & Teardown - @@ -232,6 +229,12 @@ std::chrono::steady_clock::duration secondsAsDuration(float duration) // setup mbgl map _mbglMap = new mbgl::Map(*_mbglView, *_mbglFileSource, mbgl::MapMode::Continuous); + // setup refresh driver + _displayLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(updateFromDisplayLink)]; + _displayLink.frameInterval = 2; + [_displayLink addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode]; + _needsDisplayRefresh = YES; + // start paused if in IB if (_isTargetingInterfaceBuilder || background) { self.dormant = YES; @@ -377,10 +380,6 @@ 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 @@ -744,6 +743,25 @@ std::chrono::steady_clock::duration secondsAsDuration(float duration) #pragma mark - Life Cycle - +- (void)updateFromDisplayLink +{ + MGLAssertIsMainThread(); + + if (_needsDisplayRefresh) + { + _needsDisplayRefresh = NO; + + [self.glView display]; + } +} + +- (void)invalidate +{ + MGLAssertIsMainThread(); + + _needsDisplayRefresh = YES; +} + - (void)willTerminate { MGLAssertIsMainThread(); @@ -3114,25 +3132,6 @@ CLLocationCoordinate2D MGLLocationCoordinate2DFromLatLng(mbgl::LatLng latLng) return path; } -- (void)updateFromDisplayLink -{ - std::unique_lock lock(needsDisplayMutex); - if (_needsDisplay) { - _needsDisplay = NO; - lock.unlock(); - [self.glView display]; - } else { - lock.unlock(); - } -} - -- (void)invalidate -{ - std::lock_guard lock(needsDisplayMutex); - MGLAssertIsMainThread(); - _needsDisplay = YES; -} - - (BOOL)isFullyLoaded { return _mbglMap->isFullyLoaded();