fixes #1157, #1255: cache parsed tiles in memory

This commit is contained in:
Justin R. Miller
2015-04-16 01:15:41 -07:00
parent c574acd64d
commit 190709c6b1
9 changed files with 191 additions and 7 deletions

View File

@@ -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