diff options
author | Tobrun <tobrun.van.nuland@gmail.com> | 2016-06-20 12:32:20 +0200 |
---|---|---|
committer | Tobrun <tobrun.van.nuland@gmail.com> | 2016-07-05 15:43:19 +0200 |
commit | 2bf4e20052e827a4f69dd718ba659f66edccc6df (patch) | |
tree | 5bf07287a206c982f9407c8b5608ab05a8221511 | |
parent | a40953dd71ca4a3c00ff125ca508948bfc1ec4c5 (diff) | |
download | qtlocation-mapboxgl-2bf4e20052e827a4f69dd718ba659f66edccc6df.tar.gz |
[android] #5104 - make nativePixelForLatLng faster (74ms to 57ms)
[android] #5104 - make nativeLatLngForPix faster (52ms - 45ms).
[andriod] #5104 - make nativeSetLatLng faster (117ms to 105ms)
[android] #5104 - make nativeFlyTo faster (106ms to 97ms)
[android] #5104 - make nativeEaseTo faster (103 to 94ms)
[android] #5104 - make nativeJumpTo faster (94 to 86ms)
[android] #5104 - make nativeProjectedMetersForLatLng faster (32 to 30ms)
[android] #5104 - make nativeLatLngForProjectedMeters faster (32 to 30ms)
-rwxr-xr-x | platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/NativeMapView.java | 38 | ||||
-rwxr-xr-x | platform/android/src/jni.cpp | 60 |
2 files changed, 34 insertions, 64 deletions
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/NativeMapView.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/NativeMapView.java index 9cf464b926..5a1cfa7a6f 100755 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/NativeMapView.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/NativeMapView.java @@ -231,7 +231,7 @@ final class NativeMapView { } public void setLatLng(LatLng latLng, long duration) { - nativeSetLatLng(mNativeMapViewPtr, latLng, duration); + nativeSetLatLng(mNativeMapViewPtr, latLng.getLatitude(), latLng.getLongitude(), duration); } public LatLng getLatLng() { @@ -344,7 +344,7 @@ final class NativeMapView { } public long addMarker(Marker marker) { - Marker[] markers = { marker }; + Marker[] markers = {marker}; return nativeAddMarkers(mNativeMapViewPtr, markers)[0]; } @@ -353,7 +353,7 @@ final class NativeMapView { } public long addPolyline(Polyline polyline) { - Polyline[] polylines = { polyline }; + Polyline[] polylines = {polyline}; return nativeAddPolylines(mNativeMapViewPtr, polylines)[0]; } @@ -362,7 +362,7 @@ final class NativeMapView { } public long addPolygon(Polygon polygon) { - Polygon[] polygons = { polygon }; + Polygon[] polygons = {polygon}; return nativeAddPolygons(mNativeMapViewPtr, polygons)[0]; } @@ -377,7 +377,7 @@ final class NativeMapView { } public void removeAnnotation(long id) { - long[] ids = { id }; + long[] ids = {id}; removeAnnotations(ids); } @@ -426,15 +426,15 @@ final class NativeMapView { } public ProjectedMeters projectedMetersForLatLng(LatLng latLng) { - return nativeProjectedMetersForLatLng(mNativeMapViewPtr, latLng); + return nativeProjectedMetersForLatLng(mNativeMapViewPtr, latLng.getLatitude(), latLng.getLongitude()); } public LatLng latLngForProjectedMeters(ProjectedMeters projectedMeters) { - return nativeLatLngForProjectedMeters(mNativeMapViewPtr, projectedMeters); + return nativeLatLngForProjectedMeters(mNativeMapViewPtr, projectedMeters.getNorthing(), projectedMeters.getEasting()); } public PointF pixelForLatLng(LatLng latLng) { - return nativePixelForLatLng(mNativeMapViewPtr, latLng); + return nativePixelForLatLng(mNativeMapViewPtr, latLng.getLatitude(), latLng.getLongitude()); } public LatLng latLngForPixel(PointF pixel) { @@ -446,15 +446,15 @@ final class NativeMapView { } public void jumpTo(double angle, LatLng center, double pitch, double zoom) { - nativeJumpTo(mNativeMapViewPtr, angle, center, pitch, zoom); + nativeJumpTo(mNativeMapViewPtr, angle, center.getLatitude(), center.getLongitude(), pitch, zoom); } public void easeTo(double angle, LatLng center, long duration, double pitch, double zoom, boolean easingInterpolator) { - nativeEaseTo(mNativeMapViewPtr, angle, center, duration, pitch, zoom, easingInterpolator); + nativeEaseTo(mNativeMapViewPtr, angle, center.getLatitude(), center.getLongitude(), duration, pitch, zoom, easingInterpolator); } public void flyTo(double angle, LatLng center, long duration, double pitch, double zoom) { - nativeFlyTo(mNativeMapViewPtr, angle, center, duration, pitch, zoom); + nativeFlyTo(mNativeMapViewPtr, angle, center.getLatitude(), center.getLongitude(), duration, pitch, zoom); } public void addCustomLayer(CustomLayer customLayer, String before) { @@ -542,7 +542,7 @@ final class NativeMapView { private native void nativeMoveBy(long nativeMapViewPtr, double dx, double dy, long duration); - private native void nativeSetLatLng(long nativeMapViewPtr, LatLng latLng, + private native void nativeSetLatLng(long nativeMapViewPtr, double latitude, double longitude, long duration); private native LatLng nativeGetLatLng(long nativeMapViewPtr); @@ -623,21 +623,21 @@ final class NativeMapView { private native double nativeGetMetersPerPixelAtLatitude(long nativeMapViewPtr, double lat, double zoom); - private native ProjectedMeters nativeProjectedMetersForLatLng(long nativeMapViewPtr, LatLng latLng); + private native ProjectedMeters nativeProjectedMetersForLatLng(long nativeMapViewPtr, double latitude, double longitude); - private native LatLng nativeLatLngForProjectedMeters(long nativeMapViewPtr, ProjectedMeters projectedMeters); + private native LatLng nativeLatLngForProjectedMeters(long nativeMapViewPtr, double northing, double easting); - private native PointF nativePixelForLatLng(long nativeMapViewPtr, LatLng latLng); + private native PointF nativePixelForLatLng(long nativeMapViewPtr, double lat, double lon); private native LatLng nativeLatLngForPixel(long nativeMapViewPtr, PointF pixel); private native double nativeGetTopOffsetPixelsForAnnotationSymbol(long nativeMapViewPtr, String symbolName); + + private native void nativeJumpTo(long nativeMapViewPtr, double angle, double latitude, double longitude, double pitch, double zoom); - private native void nativeJumpTo(long nativeMapViewPtr, double angle, LatLng center, double pitch, double zoom); + private native void nativeEaseTo(long nativeMapViewPtr, double angle, double latitude, double longitude, long duration, double pitch, double zoom, boolean easingInterpolator); - private native void nativeEaseTo(long nativeMapViewPtr, double angle, LatLng center, long duration, double pitch, double zoom, boolean easingInterpolator); - - private native void nativeFlyTo(long nativeMapViewPtr, double angle, LatLng center, long duration, double pitch, double zoom); + private native void nativeFlyTo(long nativeMapViewPtr, double angle, double latitude, double longitude, long duration, double pitch, double zoom); private native void nativeAddCustomLayer(long nativeMapViewPtr, CustomLayer customLayer, String before); diff --git a/platform/android/src/jni.cpp b/platform/android/src/jni.cpp index 17695582e3..311f97b3d9 100755 --- a/platform/android/src/jni.cpp +++ b/platform/android/src/jni.cpp @@ -478,15 +478,10 @@ void nativeMoveBy(JNIEnv *env, jni::jobject* obj, jlong nativeMapViewPtr, jdoubl nativeMapView->getMap().moveBy(center, mbgl::Milliseconds(duration)); } -void nativeSetLatLng(JNIEnv *env, jni::jobject* obj, jlong nativeMapViewPtr, jni::jobject* latLng, - jlong duration) { +void nativeSetLatLng(JNIEnv *env, jni::jobject* obj, jlong nativeMapViewPtr, jdouble latitude, jdouble longitude, jlong duration) { mbgl::Log::Debug(mbgl::Event::JNI, "nativeSetLatLng"); assert(nativeMapViewPtr != 0); NativeMapView *nativeMapView = reinterpret_cast<NativeMapView *>(nativeMapViewPtr); - - jdouble latitude = jni::GetField<jdouble>(*env, latLng, *latLngLatitudeId); - jdouble longitude = jni::GetField<jdouble>(*env, latLng, *latLngLongitudeId); - nativeMapView->getMap().setLatLng(mbgl::LatLng(latitude, longitude), nativeMapView->getInsets(), mbgl::Duration(duration)); } @@ -952,50 +947,34 @@ jdouble nativeGetMetersPerPixelAtLatitude(JNIEnv *env, jni::jobject* obj, jlong return nativeMapView->getMap().getMetersPerPixelAtLatitude(lat, zoom); } -jni::jobject* nativeProjectedMetersForLatLng(JNIEnv *env, jni::jobject* obj, jlong nativeMapViewPtr, jni::jobject* latLng) { +jni::jobject* nativeProjectedMetersForLatLng(JNIEnv *env, jni::jobject* obj, jlong nativeMapViewPtr, jdouble latitude, jdouble longitude) { mbgl::Log::Debug(mbgl::Event::JNI, "nativeProjectedMetersForLatLng"); assert(nativeMapViewPtr != 0); NativeMapView *nativeMapView = reinterpret_cast<NativeMapView *>(nativeMapViewPtr); - - jdouble latitude = jni::GetField<jdouble>(*env, latLng, *latLngLatitudeId); - jdouble longitude = jni::GetField<jdouble>(*env, latLng, *latLngLongitudeId); - mbgl::ProjectedMeters projectedMeters = nativeMapView->getMap().projectedMetersForLatLng(mbgl::LatLng(latitude, longitude)); return &jni::NewObject(*env, *projectedMetersClass, *projectedMetersConstructorId, projectedMeters.northing, projectedMeters.easting); } -jni::jobject* nativeLatLngForProjectedMeters(JNIEnv *env, jni::jobject* obj, jlong nativeMapViewPtr, jni::jobject* projectedMeters) { +jni::jobject* nativeLatLngForProjectedMeters(JNIEnv *env, jni::jobject* obj, jlong nativeMapViewPtr, jdouble northing, jdouble easting) { mbgl::Log::Debug(mbgl::Event::JNI, "nativeLatLngForProjectedMeters"); assert(nativeMapViewPtr != 0); NativeMapView *nativeMapView = reinterpret_cast<NativeMapView *>(nativeMapViewPtr); - - jdouble northing = jni::GetField<jdouble>(*env, projectedMeters, *projectedMetersNorthingId); - jdouble easting = jni::GetField<jdouble>(*env, projectedMeters, *projectedMetersEastingId); - mbgl::LatLng latLng = nativeMapView->getMap().latLngForProjectedMeters(mbgl::ProjectedMeters(northing, easting)); return &jni::NewObject(*env, *latLngClass, *latLngConstructorId, latLng.latitude, latLng.longitude); } -jni::jobject* nativePixelForLatLng(JNIEnv *env, jni::jobject* obj, jlong nativeMapViewPtr, jni::jobject* latLng) { +jni::jobject* nativePixelForLatLng(JNIEnv *env, jni::jobject* obj, jlong nativeMapViewPtr, jdouble latitude, jdouble longitude) { mbgl::Log::Debug(mbgl::Event::JNI, "nativePixelForLatLng"); assert(nativeMapViewPtr != 0); NativeMapView *nativeMapView = reinterpret_cast<NativeMapView *>(nativeMapViewPtr); - - jdouble latitude = jni::GetField<jdouble>(*env, latLng, *latLngLatitudeId); - jdouble longitude = jni::GetField<jdouble>(*env, latLng, *latLngLongitudeId); - mbgl::ScreenCoordinate pixel = nativeMapView->getMap().pixelForLatLng(mbgl::LatLng(latitude, longitude)); return &jni::NewObject(*env, *pointFClass, *pointFConstructorId, static_cast<jfloat>(pixel.x), static_cast<jfloat>(pixel.y)); } -jni::jobject* nativeLatLngForPixel(JNIEnv *env, jni::jobject* obj, jlong nativeMapViewPtr, jni::jobject* pixel) { +jni::jobject* nativeLatLngForPixel(JNIEnv *env, jni::jobject* obj, jlong nativeMapViewPtr, jfloat x, jfloat y) { mbgl::Log::Debug(mbgl::Event::JNI, "nativeLatLngForPixel"); assert(nativeMapViewPtr != 0); NativeMapView *nativeMapView = reinterpret_cast<NativeMapView *>(nativeMapViewPtr); - - jfloat x = jni::GetField<jfloat>(*env, pixel, *pointFXId); - jfloat y = jni::GetField<jfloat>(*env, pixel, *pointFYId); - mbgl::LatLng latLng = nativeMapView->getMap().latLngForPixel(mbgl::ScreenCoordinate(x, y)); return &jni::NewObject(*env, *latLngClass, *latLngConstructorId, latLng.latitude, latLng.longitude); } @@ -1007,14 +986,11 @@ jdouble nativeGetTopOffsetPixelsForAnnotationSymbol(JNIEnv *env, jni::jobject* o return nativeMapView->getMap().getTopOffsetPixelsForAnnotationIcon(std_string_from_jstring(env, symbolName)); } -void nativeJumpTo(JNIEnv *env, jni::jobject* obj, jlong nativeMapViewPtr, jdouble angle, jni::jobject* centerLatLng, jdouble pitch, jdouble zoom) { +void nativeJumpTo(JNIEnv *env, jni::jobject* obj, jlong nativeMapViewPtr, jdouble angle, jdouble latitude, jdouble longitude, jdouble pitch, jdouble zoom) { mbgl::Log::Debug(mbgl::Event::JNI, "nativeJumpTo"); assert(nativeMapViewPtr != 0); NativeMapView *nativeMapView = reinterpret_cast<NativeMapView *>(nativeMapViewPtr); - jdouble latitude = jni::GetField<jdouble>(*env, centerLatLng, *latLngLatitudeId); - jdouble longitude = jni::GetField<jdouble>(*env, centerLatLng, *latLngLongitudeId); - mbgl::CameraOptions options; if (angle != -1) { options.angle = angle; @@ -1031,14 +1007,11 @@ void nativeJumpTo(JNIEnv *env, jni::jobject* obj, jlong nativeMapViewPtr, jdoubl nativeMapView->getMap().jumpTo(options); } -void nativeEaseTo(JNIEnv *env, jni::jobject* obj, jlong nativeMapViewPtr, jdouble angle, jni::jobject* centerLatLng, jlong duration, jdouble pitch, jdouble zoom, jboolean easing) { +void nativeEaseTo(JNIEnv *env, jni::jobject* obj, jlong nativeMapViewPtr, jdouble angle, jdouble latitude, jdouble longitude, jlong duration, jdouble pitch, jdouble zoom, jboolean easing) { mbgl::Log::Debug(mbgl::Event::JNI, "nativeEaseTo"); assert(nativeMapViewPtr != 0); NativeMapView *nativeMapView = reinterpret_cast<NativeMapView *>(nativeMapViewPtr); - jdouble latitude = jni::GetField<jdouble>(*env, centerLatLng, *latLngLatitudeId); - jdouble longitude = jni::GetField<jdouble>(*env, centerLatLng, *latLngLongitudeId); - mbgl::CameraOptions cameraOptions; if (angle != -1) { cameraOptions.angle = angle; @@ -1069,14 +1042,11 @@ void nativeSetContentPadding(JNIEnv *env, jni::jobject* obj,long nativeMapViewPt nativeMapView->setInsets({top, left, bottom, right}); } -void nativeFlyTo(JNIEnv *env, jni::jobject* obj, jlong nativeMapViewPtr, jdouble angle, jni::jobject* centerLatLng, jlong duration, jdouble pitch, jdouble zoom) { +void nativeFlyTo(JNIEnv *env, jni::jobject* obj, jlong nativeMapViewPtr, jdouble angle, jdouble latitude, jdouble longitude, jlong duration, jdouble pitch, jdouble zoom) { mbgl::Log::Debug(mbgl::Event::JNI, "nativeFlyTo"); assert(nativeMapViewPtr != 0); NativeMapView *nativeMapView = reinterpret_cast<NativeMapView *>(nativeMapViewPtr); - jdouble latitude = jni::GetField<jdouble>(*env, centerLatLng, *latLngLatitudeId); - jdouble longitude = jni::GetField<jdouble>(*env, centerLatLng, *latLngLongitudeId); - mbgl::CameraOptions cameraOptions; if (angle != -1) { cameraOptions.angle = angle; @@ -1680,7 +1650,7 @@ extern "C" JNIEXPORT jint JNI_OnLoad(JavaVM *vm, void *reserved) { MAKE_NATIVE_METHOD(nativeCancelTransitions, "(J)V"), MAKE_NATIVE_METHOD(nativeSetGestureInProgress, "(JZ)V"), MAKE_NATIVE_METHOD(nativeMoveBy, "(JDDJ)V"), - MAKE_NATIVE_METHOD(nativeSetLatLng, "(JLcom/mapbox/mapboxsdk/geometry/LatLng;J)V"), + MAKE_NATIVE_METHOD(nativeSetLatLng, "(JDDJ)V"), MAKE_NATIVE_METHOD(nativeGetLatLng, "(J)Lcom/mapbox/mapboxsdk/geometry/LatLng;"), MAKE_NATIVE_METHOD(nativeResetPosition, "(J)V"), MAKE_NATIVE_METHOD(nativeGetCameraValues, "(J)[D"), @@ -1716,14 +1686,14 @@ extern "C" JNIEXPORT jint JNI_OnLoad(JavaVM *vm, void *reserved) { MAKE_NATIVE_METHOD(nativeIsFullyLoaded, "(J)Z"), MAKE_NATIVE_METHOD(nativeSetReachability, "(JZ)V"), MAKE_NATIVE_METHOD(nativeGetMetersPerPixelAtLatitude, "(JDD)D"), - MAKE_NATIVE_METHOD(nativeProjectedMetersForLatLng, "(JLcom/mapbox/mapboxsdk/geometry/LatLng;)Lcom/mapbox/mapboxsdk/geometry/ProjectedMeters;"), - MAKE_NATIVE_METHOD(nativeLatLngForProjectedMeters, "(JLcom/mapbox/mapboxsdk/geometry/ProjectedMeters;)Lcom/mapbox/mapboxsdk/geometry/LatLng;"), - MAKE_NATIVE_METHOD(nativePixelForLatLng, "(JLcom/mapbox/mapboxsdk/geometry/LatLng;)Landroid/graphics/PointF;"), + MAKE_NATIVE_METHOD(nativeProjectedMetersForLatLng, "(JDD)Lcom/mapbox/mapboxsdk/geometry/ProjectedMeters;"), + MAKE_NATIVE_METHOD(nativeLatLngForProjectedMeters, "(JDD)Lcom/mapbox/mapboxsdk/geometry/LatLng;"), + MAKE_NATIVE_METHOD(nativePixelForLatLng, "(JDD)Landroid/graphics/PointF;"), MAKE_NATIVE_METHOD(nativeLatLngForPixel, "(JLandroid/graphics/PointF;)Lcom/mapbox/mapboxsdk/geometry/LatLng;"), MAKE_NATIVE_METHOD(nativeGetTopOffsetPixelsForAnnotationSymbol, "(JLjava/lang/String;)D"), - MAKE_NATIVE_METHOD(nativeJumpTo, "(JDLcom/mapbox/mapboxsdk/geometry/LatLng;DD)V"), - MAKE_NATIVE_METHOD(nativeEaseTo, "(JDLcom/mapbox/mapboxsdk/geometry/LatLng;JDDZ)V"), - MAKE_NATIVE_METHOD(nativeFlyTo, "(JDLcom/mapbox/mapboxsdk/geometry/LatLng;JDD)V"), + MAKE_NATIVE_METHOD(nativeJumpTo, "(JDDDDD)V"), + MAKE_NATIVE_METHOD(nativeEaseTo, "(JDDDJDDZ)V"), + MAKE_NATIVE_METHOD(nativeFlyTo, "(JDDDJDD)V"), MAKE_NATIVE_METHOD(nativeAddCustomLayer, "(JLcom/mapbox/mapboxsdk/layers/CustomLayer;Ljava/lang/String;)V"), MAKE_NATIVE_METHOD(nativeRemoveCustomLayer, "(JLjava/lang/String;)V"), MAKE_NATIVE_METHOD(nativeSetContentPadding, "(JDDDD)V") |