diff options
author | Justin R. Miller <incanus@codesorcery.net> | 2015-11-04 09:56:19 -0800 |
---|---|---|
committer | Justin R. Miller <incanus@codesorcery.net> | 2015-11-04 10:33:30 -0800 |
commit | af758abf0fb45b93326ce274fa60e14d9973de38 (patch) | |
tree | 6df19f1e057ba0dac04220ba3254d5ce137dd7a7 | |
parent | 36d90ea97d947dcacc5257bcb33cba139dad46bb (diff) | |
download | qtlocation-mapboxgl-af758abf0fb45b93326ce274fa60e14d9973de38.tar.gz |
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.
-rw-r--r-- | platform/ios/MGLMapView.mm | 57 |
1 files changed, 28 insertions, 29 deletions
diff --git a/platform/ios/MGLMapView.mm b/platform/ios/MGLMapView.mm index 347b3a70cb..7c5b6aa409 100644 --- a/platform/ios/MGLMapView.mm +++ b/platform/ios/MGLMapView.mm @@ -40,7 +40,6 @@ #import <algorithm> #import <cstdlib> #import <unordered_set> -#include <mutex> 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<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(); - _needsDisplay = YES; -} - - (BOOL)isFullyLoaded { return _mbglMap->isFullyLoaded(); |