diff options
author | Leith Bade <leith@mapbox.com> | 2015-07-28 14:34:16 +1000 |
---|---|---|
committer | Leith Bade <leith@mapbox.com> | 2015-07-29 12:17:42 +1000 |
commit | d57a02f3a9274d331ddaa7a82d062e36fdc09251 (patch) | |
tree | 0e42e6378763c775e701fa3b3c15b2385aad707f /android/cpp | |
parent | 3f2f9d26c80aeb62c22832799345a56c3ef1506c (diff) | |
download | qtlocation-mapboxgl-d57a02f3a9274d331ddaa7a82d062e36fdc09251.tar.gz |
First pass at updating JNI bindings
Hook up collisionDebug, isFullyLoaded, onLowMemory in Android
Rename class to styleClass in Java to match iOS
Fixed some formatting
Fixes #1905
Fixes #1946
Fixes #1263
Diffstat (limited to 'android/cpp')
-rw-r--r-- | android/cpp/jni.cpp | 68 | ||||
-rw-r--r-- | android/cpp/native_map_view.cpp | 15 |
2 files changed, 65 insertions, 18 deletions
diff --git a/android/cpp/jni.cpp b/android/cpp/jni.cpp index 0521e07ad0..85022dbc0d 100644 --- a/android/cpp/jni.cpp +++ b/android/cpp/jni.cpp @@ -272,6 +272,7 @@ jlongArray std_vector_uint_to_jobject(JNIEnv *env, std::vector<uint32_t> vector) return jarray; } + } } @@ -279,13 +280,12 @@ namespace { using namespace mbgl::android; -jlong JNICALL -nativeCreate(JNIEnv *env, jobject obj, jstring cachePath_, jstring dataPath_, jstring apkPath_, jfloat pixelRatio) { +jlong JNICALL nativeCreate(JNIEnv *env, jobject obj, jstring cachePath_, jstring dataPath_, jstring apkPath_, jfloat pixelRatio, jint availableProcessors, jlong totalMemory) { mbgl::Log::Debug(mbgl::Event::JNI, "nativeCreate"); cachePath = std_string_from_jstring(env, cachePath_); dataPath = std_string_from_jstring(env, dataPath_); apkPath = std_string_from_jstring(env, apkPath_); - NativeMapView *nativeMapView = new NativeMapView(env, obj, pixelRatio); + NativeMapView *nativeMapView = new NativeMapView(env, obj, pixelRatio, availableProcessors, totalMemory); jlong mapViewPtr = reinterpret_cast<jlong>(nativeMapView); return mapViewPtr; } @@ -337,8 +337,7 @@ void JNICALL nativeTerminateContext(JNIEnv *env, jobject obj, jlong nativeMapVie nativeMapView->terminateContext(); } -void JNICALL -nativeCreateSurface(JNIEnv *env, jobject obj, jlong nativeMapViewPtr, jobject surface) { +void JNICALL nativeCreateSurface(JNIEnv *env, jobject obj, jlong nativeMapViewPtr, jobject surface) { mbgl::Log::Debug(mbgl::Event::JNI, "nativeCreateSurface"); assert(nativeMapViewPtr != 0); NativeMapView *nativeMapView = reinterpret_cast<NativeMapView *>(nativeMapViewPtr); @@ -428,8 +427,7 @@ void JNICALL nativeAddClass(JNIEnv *env, jobject obj, jlong nativeMapViewPtr, js nativeMapView->getMap().addClass(std_string_from_jstring(env, clazz)); } -void JNICALL -nativeSetClasses(JNIEnv *env, jobject obj, jlong nativeMapViewPtr, jobject classes) { +void JNICALL nativeSetClasses(JNIEnv *env, jobject obj, jlong nativeMapViewPtr, jobject classes) { mbgl::Log::Debug(mbgl::Event::JNI, "nativeSetClasses"); assert(nativeMapViewPtr != 0); NativeMapView *nativeMapView = reinterpret_cast<NativeMapView *>(nativeMapViewPtr); @@ -482,8 +480,7 @@ jstring JNICALL nativeGetStyleJSON(JNIEnv *env, jobject obj, jlong nativeMapView return std_string_to_jstring(env, nativeMapView->getMap().getStyleJSON()); } -void JNICALL -nativeSetAccessToken(JNIEnv *env, jobject obj, jlong nativeMapViewPtr, jstring accessToken) { +void JNICALL nativeSetAccessToken(JNIEnv *env, jobject obj, jlong nativeMapViewPtr, jstring accessToken) { mbgl::Log::Debug(mbgl::Event::JNI, "nativeSetAccessToken"); assert(nativeMapViewPtr != 0); NativeMapView *nativeMapView = reinterpret_cast<NativeMapView *>(nativeMapViewPtr); @@ -691,7 +688,6 @@ std::pair<mbgl::AnnotationSegment, mbgl::StyleProperties> readPolygon(JNIEnv *en return std::make_pair(segment, shapeProperties); } - jlong JNICALL nativeAddPolygon(JNIEnv *env, jobject obj, jlong nativeMapViewPtr, jobject polygon) { mbgl::Log::Debug(mbgl::Event::JNI, "nativeAddPolygon"); assert(nativeMapViewPtr != 0); @@ -760,7 +756,6 @@ jlongArray JNICALL nativeAddPolygons(JNIEnv *env, jobject obj, jlong nativeMapVi return std_vector_uint_to_jobject(env, shapeAnnotationIDs); } - void JNICALL nativeRemoveAnnotation(JNIEnv *env, jobject obj, jlong nativeMapViewPtr, jlong annotationId) { mbgl::Log::Debug(mbgl::Event::JNI, "nativeRemoveAnnotation"); assert(nativeMapViewPtr != 0); @@ -845,8 +840,7 @@ jdouble JNICALL nativeGetScale(JNIEnv *env, jobject obj, jlong nativeMapViewPtr) return nativeMapView->getMap().getScale(); } -void JNICALL -nativeSetZoom(JNIEnv *env, jobject obj, jlong nativeMapViewPtr, jdouble zoom, jlong duration) { +void JNICALL nativeSetZoom(JNIEnv *env, jobject obj, jlong nativeMapViewPtr, jdouble zoom, jlong duration) { mbgl::Log::Debug(mbgl::Event::JNI, "nativeSetZoom"); assert(nativeMapViewPtr != 0); NativeMapView *nativeMapView = reinterpret_cast<NativeMapView *>(nativeMapViewPtr); @@ -962,6 +956,13 @@ void JNICALL nativeResetNorth(JNIEnv *env, jobject obj, jlong nativeMapViewPtr) nativeMapView->getMap().resetNorth(); } +void JNICALL nativeOnLowMemory(JNIEnv *env, jobject obj, jlong nativeMapViewPtr) { + mbgl::Log::Debug(mbgl::Event::JNI, "nativeOnLowMemory"); + assert(nativeMapViewPtr != 0); + NativeMapView *nativeMapView = reinterpret_cast<NativeMapView *>(nativeMapViewPtr); + nativeMapView->getMap().onLowMemory(); +} + void JNICALL nativeSetDebug(JNIEnv *env, jobject obj, jlong nativeMapViewPtr, jboolean debug) { mbgl::Log::Debug(mbgl::Event::JNI, "nativeSetDebug"); assert(nativeMapViewPtr != 0); @@ -985,8 +986,35 @@ jboolean JNICALL nativeGetDebug(JNIEnv *env, jobject obj, jlong nativeMapViewPtr return nativeMapView->getMap().getDebug(); } -void JNICALL -nativeSetReachability(JNIEnv *env, jobject obj, jlong nativeMapViewPtr, jboolean status) { +void JNICALL nativeSetCollisionDebug(JNIEnv *env, jobject obj, jlong nativeMapViewPtr, jboolean debug) { + mbgl::Log::Debug(mbgl::Event::JNI, "nativeSetCollisionDebug"); + assert(nativeMapViewPtr != 0); + NativeMapView *nativeMapView = reinterpret_cast<NativeMapView *>(nativeMapViewPtr); + nativeMapView->getMap().setCollisionDebug(debug); +} + +void JNICALL nativeToggleCollisionDebug(JNIEnv *env, jobject obj, jlong nativeMapViewPtr) { + mbgl::Log::Debug(mbgl::Event::JNI, "nativeToggleCollisionDebug"); + assert(nativeMapViewPtr != 0); + NativeMapView *nativeMapView = reinterpret_cast<NativeMapView *>(nativeMapViewPtr); + nativeMapView->getMap().toggleCollisionDebug(); +} + +jboolean JNICALL nativeGetCollisionDebug(JNIEnv *env, jobject obj, jlong nativeMapViewPtr) { + mbgl::Log::Debug(mbgl::Event::JNI, "nativeGetCollisionDebug"); + assert(nativeMapViewPtr != 0); + NativeMapView *nativeMapView = reinterpret_cast<NativeMapView *>(nativeMapViewPtr); + return nativeMapView->getMap().getCollisionDebug(); +} + +jboolean JNICALL nativeIsFullyLoaded(JNIEnv *env, jobject obj, jlong nativeMapViewPtr) { + mbgl::Log::Debug(mbgl::Event::JNI, "nativeIsFullyLoaded"); + assert(nativeMapViewPtr != 0); + NativeMapView *nativeMapView = reinterpret_cast<NativeMapView *>(nativeMapViewPtr); + return nativeMapView->getMap().isFullyLoaded(); +} + +void JNICALL nativeSetReachability(JNIEnv *env, jobject obj, jlong nativeMapViewPtr, jboolean status) { mbgl::Log::Debug(mbgl::Event::JNI, "nativeSetReachability"); assert(nativeMapViewPtr != 0); if (status) { @@ -1112,6 +1140,7 @@ jobject JNICALL nativeLatLngForPixel(JNIEnv *env, jobject obj, jlong nativeMapVi return ret; } + } extern "C" { @@ -1167,7 +1196,7 @@ extern "C" JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) { env->ExceptionDescribe(); return JNI_ERR; } - + markerSpriteId = env->GetFieldID(markerClass, "sprite", "Ljava/lang/String;"); if (markerSpriteId == nullptr) { env->ExceptionDescribe(); @@ -1415,7 +1444,7 @@ extern "C" JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) { } const std::vector<JNINativeMethod> methods = { - {"nativeCreate", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;F)J", + {"nativeCreate", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;FIJ)J", reinterpret_cast<void *>(&nativeCreate)}, {"nativeDestroy", "(J)V", reinterpret_cast<void *>(&nativeDestroy)}, {"nativeInitializeDisplay", "(J)V", reinterpret_cast<void *>(&nativeInitializeDisplay)}, @@ -1500,9 +1529,14 @@ extern "C" JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) { &nativeSetBearing))}, {"nativeGetBearing", "(J)D", reinterpret_cast<void *>(&nativeGetBearing)}, {"nativeResetNorth", "(J)V", reinterpret_cast<void *>(&nativeResetNorth)}, + {"nativeOnLowMemory", "(J)V", reinterpret_cast<void *>(&nativeOnLowMemory)}, {"nativeSetDebug", "(JZ)V", reinterpret_cast<void *>(&nativeSetDebug)}, {"nativeToggleDebug", "(J)V", reinterpret_cast<void *>(&nativeToggleDebug)}, {"nativeGetDebug", "(J)Z", reinterpret_cast<void *>(&nativeGetDebug)}, + {"nativeSetCollisionDebug", "(JZ)V", reinterpret_cast<void *>(&nativeSetCollisionDebug)}, + {"nativeToggleCollisionDebug", "(J)V", reinterpret_cast<void *>(&nativeToggleCollisionDebug)}, + {"nativeGetCollisionDebug", "(J)Z", reinterpret_cast<void *>(&nativeGetCollisionDebug)}, + {"nativeIsFullyLoaded", "(J)Z", reinterpret_cast<void *>(&nativeIsFullyLoaded)}, {"nativeSetReachability", "(JZ)V", reinterpret_cast<void *>(&nativeSetReachability)}, //{"nativeGetWorldBoundsMeters", "(J)V", reinterpret_cast<void *>(&nativeGetWorldBoundsMeters)}, //{"nativeGetWorldBoundsLatLng", "(J)V", reinterpret_cast<void *>(&nativeGetWorldBoundsLatLng)}, diff --git a/android/cpp/native_map_view.cpp b/android/cpp/native_map_view.cpp index 9c7a3efde7..351833a07d 100644 --- a/android/cpp/native_map_view.cpp +++ b/android/cpp/native_map_view.cpp @@ -15,6 +15,7 @@ #include <mbgl/platform/event.hpp> #include <mbgl/platform/log.hpp> #include <mbgl/platform/gl.hpp> +#include <mbgl/util/constants.hpp> namespace mbgl { namespace android { @@ -52,9 +53,11 @@ void log_gl_string(GLenum name, const char *label) { } } -NativeMapView::NativeMapView(JNIEnv *env, jobject obj_, float pixelRatio_) +NativeMapView::NativeMapView(JNIEnv *env, jobject obj_, float pixelRatio_, int availableProcessors_, size_t totalMemory_) : mbgl::View(*this), pixelRatio(pixelRatio_), + availableProcessors(availableProcessors_), + totalMemory(totalMemory_), fileCache(mbgl::android::cachePath + "/mbgl-cache.db"), fileSource(&fileCache), map(*this, fileSource, MapMode::Continuous) { @@ -763,6 +766,16 @@ void NativeMapView::onInvalidate(bool inProgress) { const bool dirty = !clean.test_and_set(); if (dirty) { + 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.getWidth()) / mbgl::util::tileSize) * + (static_cast<float>(map.getHeight()) / mbgl::util::tileSize); + + size_t cacheSize = zoomFactor * cpuFactor * memoryFactor * sizeFactor * 0.5f; + + map.setSourceTileCacheSize(cacheSize); + const bool needsRerender = map.renderSync(); if (!inProgress) { map.nudgeTransitions(needsRerender); |