[android] remove tile cache size customization

This commit is contained in:
Ivo van Dongen
2017-06-26 10:36:26 -07:00
committed by Ivo van Dongen
parent de37ae9628
commit a35b268606
3 changed files with 5 additions and 52 deletions

View File

@@ -1,11 +1,9 @@
package com.mapbox.mapboxsdk.maps;
import android.app.ActivityManager;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.PointF;
import android.graphics.RectF;
import android.os.Build;
import android.support.annotation.IntRange;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
@@ -78,27 +76,11 @@ final class NativeMapView {
fileSource = FileSource.getInstance(context);
pixelRatio = context.getResources().getDisplayMetrics().density;
int availableProcessors = Runtime.getRuntime().availableProcessors();
ActivityManager.MemoryInfo memoryInfo = new ActivityManager.MemoryInfo();
ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
activityManager.getMemoryInfo(memoryInfo);
long totalMemory = memoryInfo.availMem;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
totalMemory = memoryInfo.totalMem;
}
if (availableProcessors < 0) {
throw new IllegalArgumentException("availableProcessors cannot be negative.");
}
if (totalMemory < 0) {
throw new IllegalArgumentException("totalMemory cannot be negative.");
}
onMapChangedListeners = new CopyOnWriteArrayList<>();
this.mapView = mapView;
String programCacheDir = context.getCacheDir().getAbsolutePath();
nativeInitialize(this, fileSource, pixelRatio, programCacheDir, availableProcessors, totalMemory);
nativeInitialize(this, fileSource, pixelRatio, programCacheDir);
}
//
@@ -941,9 +923,7 @@ final class NativeMapView {
private native void nativeInitialize(NativeMapView nativeMapView,
FileSource fileSource,
float pixelRatio,
String programCacheDir,
int availableProcessors,
long totalMemory);
String programCacheDir);
private native void nativeDestroy();

View File

@@ -56,13 +56,9 @@ NativeMapView::NativeMapView(jni::JNIEnv& _env,
jni::Object<NativeMapView> _obj,
jni::Object<FileSource> jFileSource,
jni::jfloat _pixelRatio,
jni::String _programCacheDir,
jni::jint _availableProcessors,
jni::jlong _totalMemory)
jni::String _programCacheDir)
: javaPeer(_obj.NewWeakGlobalRef(_env)),
pixelRatio(_pixelRatio),
availableProcessors(_availableProcessors),
totalMemory(_totalMemory),
threadPool(sharedThreadPool()) {
// Get a reference to the JavaVM for callbacks
@@ -77,19 +73,6 @@ NativeMapView::NativeMapView(jni::JNIEnv& _env,
pixelRatio, mbgl::android::FileSource::getDefaultFileSource(_env, jFileSource), *threadPool,
MapMode::Continuous, GLContextMode::Unique, ConstrainMode::HeightOnly,
ViewportMode::Default, jni::Make<std::string>(_env, _programCacheDir));
recalculateSourceTileCacheSize();
}
void NativeMapView::recalculateSourceTileCacheSize() {
//Calculate a fitting cache size based on device parameters
float zoomFactor = map->getMaxZoom() - map->getMinZoom() + 1;
float cpuFactor = availableProcessors;
float memoryFactor = static_cast<float>(totalMemory) / 1000.0f / 1000.0f / 1000.0f;
float sizeFactor = (static_cast<float>(map->getSize().width) / mbgl::util::tileSize) *
(static_cast<float>(map->getSize().height) / mbgl::util::tileSize);
map->setSourceTileCacheSize(zoomFactor * cpuFactor * memoryFactor * sizeFactor * 0.5f);
}
/**
@@ -333,7 +316,6 @@ void NativeMapView::resizeView(jni::JNIEnv&, int w, int h) {
width = util::max(64, w);
height = util::max(64, h);
map->setSize({ static_cast<uint32_t>(width), static_cast<uint32_t>(height) });
recalculateSourceTileCacheSize();
}
void NativeMapView::resizeFramebuffer(jni::JNIEnv&, int w, int h) {
@@ -488,7 +470,6 @@ void NativeMapView::resetZoom(jni::JNIEnv&) {
void NativeMapView::setMinZoom(jni::JNIEnv&, jni::jdouble zoom) {
map->setMinZoom(zoom);
recalculateSourceTileCacheSize();
}
jni::jdouble NativeMapView::getMinZoom(jni::JNIEnv&) {
@@ -497,7 +478,6 @@ jni::jdouble NativeMapView::getMinZoom(jni::JNIEnv&) {
void NativeMapView::setMaxZoom(jni::JNIEnv&, jni::jdouble zoom) {
map->setMaxZoom(zoom);
recalculateSourceTileCacheSize();
}
jni::jdouble NativeMapView::getMaxZoom(jni::JNIEnv&) {
@@ -1473,7 +1453,7 @@ void NativeMapView::registerNative(jni::JNIEnv& env) {
// Register the peer
jni::RegisterNativePeer<NativeMapView>(env, NativeMapView::javaClass, "nativePtr",
std::make_unique<NativeMapView, JNIEnv&, jni::Object<NativeMapView>, jni::Object<FileSource>, jni::jfloat, jni::String, jni::jint, jni::jlong>,
std::make_unique<NativeMapView, JNIEnv&, jni::Object<NativeMapView>, jni::Object<FileSource>, jni::jfloat, jni::String>,
"nativeInitialize",
"nativeDestroy",
METHOD(&NativeMapView::render, "nativeRender"),

View File

@@ -49,9 +49,7 @@ public:
jni::Object<NativeMapView>,
jni::Object<FileSource>,
jni::jfloat pixelRatio,
jni::String programCacheDir,
jni::jint availableProcessors,
jni::jlong totalMemory);
jni::String programCacheDir);
virtual ~NativeMapView();
@@ -290,8 +288,6 @@ private:
void updateFps();
private:
void recalculateSourceTileCacheSize();
JavaVM *vm = nullptr;
jni::UniqueWeakObject<NativeMapView> javaPeer;
@@ -327,9 +323,6 @@ private:
bool framebufferSizeChanged = true;
int availableProcessors = 0;
size_t totalMemory = 0;
// Ensure these are initialised last
std::shared_ptr<mbgl::ThreadPool> threadPool;
std::unique_ptr<mbgl::Map> map;