diff options
author | Benjamin Jaeger <bjaeger@fb.com> | 2018-01-23 15:33:29 -0500 |
---|---|---|
committer | Tobrun <tobrun@mapbox.com> | 2018-02-12 15:56:58 +0100 |
commit | 0b27909b8b9959a14f9075d3b61c33c93ddd8c31 (patch) | |
tree | 368ac780ede1abc50d2fab2b6242bc7f2e51263c | |
parent | f3b32599061402316b0d1ab698301a8941c51ff5 (diff) | |
download | qtlocation-mapboxgl-0b27909b8b9959a14f9075d3b61c33c93ddd8c31.tar.gz |
NativeMapView.addImage without copying into Java
3 files changed, 6 insertions, 23 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 785b045779..c1e9053dfc 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 @@ -758,20 +758,11 @@ final class NativeMapView { return; } - // Check/correct config - if (image.getConfig() != Bitmap.Config.ARGB_8888) { - image = image.copy(Bitmap.Config.ARGB_8888, false); - } - - // Get pixels - ByteBuffer buffer = ByteBuffer.allocate(image.getByteCount()); - image.copyPixelsToBuffer(buffer); - // Determine pixel ratio float density = image.getDensity() == Bitmap.DENSITY_NONE ? Bitmap.DENSITY_NONE : image.getDensity(); float pixelRatio = density / DisplayMetrics.DENSITY_DEFAULT; - nativeAddImage(name, image.getWidth(), image.getHeight(), pixelRatio, buffer.array()); + nativeAddImage(name, image, pixelRatio); } public void addImages(@NonNull HashMap<String, Bitmap> bitmapHashMap) { @@ -1032,8 +1023,7 @@ final class NativeMapView { private native void nativeRemoveSource(Source source, long sourcePtr); - private native void nativeAddImage(String name, int width, int height, float pixelRatio, - byte[] array); + private native void nativeAddImage(String name, Bitmap bitmap, float pixelRatio); private native void nativeAddImages(Image[] images); diff --git a/platform/android/src/native_map_view.cpp b/platform/android/src/native_map_view.cpp index 36a73fee35..eefb578f39 100755 --- a/platform/android/src/native_map_view.cpp +++ b/platform/android/src/native_map_view.cpp @@ -893,16 +893,9 @@ void NativeMapView::removeSource(JNIEnv& env, jni::Object<Source> obj, jlong sou source->removeFromMap(env, obj, *map); } -void NativeMapView::addImage(JNIEnv& env, jni::String name, jni::jint w, jni::jint h, jni::jfloat scale, jni::Array<jbyte> pixels) { - jni::NullCheck(env, &pixels); - std::size_t size = pixels.Length(env); - - mbgl::PremultipliedImage premultipliedImage({ static_cast<uint32_t>(w), static_cast<uint32_t>(h) }); - if (premultipliedImage.bytes() != uint32_t(size)) { - throw mbgl::util::SpriteImageException("Sprite image pixel count mismatch"); - } - - jni::GetArrayRegion(env, *pixels, 0, size, reinterpret_cast<jbyte*>(premultipliedImage.data.get())); +void NativeMapView::addImage(JNIEnv& env, jni::String name, jni::Object<Bitmap> bitmap, jni::jfloat scale) { + jni::NullCheck(env, &bitmap); + mbgl::PremultipliedImage premultipliedImage = Bitmap::GetImage(env, bitmap); map->getStyle().addImage(std::make_unique<mbgl::style::Image>( jni::Make<std::string>(env, name), diff --git a/platform/android/src/native_map_view.hpp b/platform/android/src/native_map_view.hpp index 507d77ac5f..9ed333d2d5 100755 --- a/platform/android/src/native_map_view.hpp +++ b/platform/android/src/native_map_view.hpp @@ -236,7 +236,7 @@ public: void removeSource(JNIEnv&, jni::Object<Source>, jlong nativePtr); - void addImage(JNIEnv&, jni::String, jni::jint, jni::jint, jni::jfloat, jni::Array<jbyte>); + void addImage(JNIEnv&, jni::String, jni::Object<Bitmap> bitmap, jni::jfloat); void addImages(JNIEnv&, jni::Array<jni::Object<mbgl::android::Image>>); |