From 190709c6b1fd9326d0eef5ffc8eb36070e5ad5c7 Mon Sep 17 00:00:00 2001 From: "Justin R. Miller" Date: Thu, 16 Apr 2015 01:15:41 -0700 Subject: fixes #1157, #1255: cache parsed tiles in memory --- platform/ios/MGLMapView.mm | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) (limited to 'platform') diff --git a/platform/ios/MGLMapView.mm b/platform/ios/MGLMapView.mm index 0395114825..8721b2a4d6 100644 --- a/platform/ios/MGLMapView.mm +++ b/platform/ios/MGLMapView.mm @@ -367,6 +367,7 @@ mbgl::DefaultFileSource *mbglFileSource = nullptr; // [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(appDidBackground:) name:UIApplicationDidEnterBackgroundNotification object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(appWillForeground:) name:UIApplicationWillEnterForegroundNotification object:nil]; + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didReceiveMemoryWarning) name:UIApplicationDidReceiveMemoryWarningNotification object:nil]; // set initial position // @@ -574,6 +575,17 @@ mbgl::DefaultFileSource *mbglFileSource = nullptr; else { mbglView->resize(rect.size.width, rect.size.height, view.contentScaleFactor, view.drawableWidth, view.drawableHeight); + + 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->getState().getWidth() / mbgl::util::tileSize) * + ((CGFloat)mbglMap->getState().getHeight() / mbgl::util::tileSize); + + NSUInteger cacheSize = zoomFactor * cpuFactor * memoryFactor * sizeFactor * 0.5; + + mbglMap->setSourceTileCacheSize(cacheSize); + mbglMap->renderSync(); } } @@ -1166,6 +1178,11 @@ mbgl::DefaultFileSource *mbglFileSource = nullptr; mbglMap->toggleDebug(); } +- (void)emptyMemoryCache +{ + mbglMap->onLowMemory(); +} + #pragma mark - Geography - + (NSSet *)keyPathsForValuesAffectingCenterCoordinate @@ -2450,7 +2467,8 @@ class MBGLView : public mbgl::View [EAGLContext setCurrentContext:nil]; } - void resize(uint16_t width, uint16_t height, float ratio, uint16_t fbWidth, uint16_t fbHeight) { + void resize(uint16_t width, uint16_t height, float ratio, uint16_t fbWidth, uint16_t fbHeight) + { View::resize(width, height, ratio, fbWidth, fbHeight); } @@ -2566,4 +2584,9 @@ class MBGLView : public mbgl::View self.rotateEnabled = allowsRotating; } +- (void)didReceiveMemoryWarning +{ + mbglMap->onLowMemory(); +} + @end -- cgit v1.2.1