summaryrefslogtreecommitdiff
path: root/platform/ios
diff options
context:
space:
mode:
authorMinh Nguyễn <mxn@1ec5.org>2016-05-06 08:47:18 -0700
committerMinh Nguyễn <mxn@1ec5.org>2016-05-06 08:47:18 -0700
commitd28b6f37190dc1c9cbb1e3973f8a4534b507865c (patch)
tree90cdfe6c0629b1cb88f4dc3b11d59db31e389622 /platform/ios
parent8a7087af68ffb6c85dfbaa8374e463503addf1b6 (diff)
downloadqtlocation-mapboxgl-d28b6f37190dc1c9cbb1e3973f8a4534b507865c.tar.gz
[ios, osx] Avoid recomputing tile cache size on every redraw
The tile cache size is only recomputed when an input changes. Fixes #4026.
Diffstat (limited to 'platform/ios')
-rw-r--r--platform/ios/src/MGLMapView.mm40
1 files changed, 28 insertions, 12 deletions
diff --git a/platform/ios/src/MGLMapView.mm b/platform/ios/src/MGLMapView.mm
index eecc71ad27..8a3faa6a2e 100644
--- a/platform/ios/src/MGLMapView.mm
+++ b/platform/ios/src/MGLMapView.mm
@@ -381,6 +381,7 @@ mbgl::Duration MGLDurationInSeconds(NSTimeInterval duration)
// setup mbgl map
mbgl::DefaultFileSource *mbglFileSource = [MGLOfflineStorage sharedOfflineStorage].mbglFileSource;
_mbglMap = new mbgl::Map(*_mbglView, *mbglFileSource, mbgl::MapMode::Continuous, mbgl::GLContextMode::Unique, mbgl::ConstrainMode::None);
+ [self validateTileCacheSize];
// start paused if in IB
if (_isTargetingInterfaceBuilder || background) {
@@ -646,15 +647,37 @@ mbgl::Duration MGLDurationInSeconds(NSTimeInterval duration)
- (void)setFrame:(CGRect)frame
{
[super setFrame:frame];
-
- [self setNeedsLayout];
+ if ( ! CGRectEqualToRect(frame, self.frame))
+ {
+ [self validateTileCacheSize];
+ }
}
- (void)setBounds:(CGRect)bounds
{
[super setBounds:bounds];
+ if ( ! CGRectEqualToRect(bounds, self.bounds))
+ {
+ [self validateTileCacheSize];
+ }
+}
- [self setNeedsLayout];
+- (void)validateTileCacheSize
+{
+ if ( ! _mbglMap)
+ {
+ return;
+ }
+
+ CGFloat zoomFactor = self.maximumZoomLevel - self.minimumZoomLevel + 1;
+ CGFloat cpuFactor = [NSProcessInfo processInfo].processorCount;
+ CGFloat memoryFactor = (CGFloat)[NSProcessInfo processInfo].physicalMemory / 1000 / 1000 / 1000;
+ CGFloat sizeFactor = (CGRectGetWidth(self.bounds) / mbgl::util::tileSize) *
+ (CGRectGetHeight(self.bounds) / mbgl::util::tileSize);
+
+ NSUInteger cacheSize = zoomFactor * cpuFactor * memoryFactor * sizeFactor * 0.5;
+
+ _mbglMap->setSourceTileCacheSize(cacheSize);
}
+ (BOOL)requiresConstraintBasedLayout
@@ -830,15 +853,6 @@ mbgl::Duration MGLDurationInSeconds(NSTimeInterval duration)
{
if ( ! self.dormant)
{
- CGFloat zoomFactor = _mbglMap->getMaxZoom() - _mbglMap->getMinZoom() + 1;
- CGFloat cpuFactor = (CGFloat)[[NSProcessInfo processInfo] processorCount];
- CGFloat memoryFactor = (CGFloat)[[NSProcessInfo processInfo] physicalMemory] / 1000 / 1000 / 1000;
- CGFloat sizeFactor = ((CGFloat)_mbglMap->getWidth() / mbgl::util::tileSize) *
- ((CGFloat)_mbglMap->getHeight() / mbgl::util::tileSize);
-
- NSUInteger cacheSize = zoomFactor * cpuFactor * memoryFactor * sizeFactor * 0.5;
-
- _mbglMap->setSourceTileCacheSize(cacheSize);
_mbglMap->render();
[self updateUserLocationAnnotationView];
@@ -2175,6 +2189,7 @@ mbgl::Duration MGLDurationInSeconds(NSTimeInterval duration)
- (void)setMinimumZoomLevel:(double)minimumZoomLevel
{
_mbglMap->setMinZoom(minimumZoomLevel);
+ [self validateTileCacheSize];
}
- (double)minimumZoomLevel
@@ -2185,6 +2200,7 @@ mbgl::Duration MGLDurationInSeconds(NSTimeInterval duration)
- (void)setMaximumZoomLevel:(double)maximumZoomLevel
{
_mbglMap->setMaxZoom(maximumZoomLevel);
+ [self validateTileCacheSize];
}
- (double)maximumZoomLevel