summaryrefslogtreecommitdiff
path: root/platform/android/src/map/image.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'platform/android/src/map/image.cpp')
-rw-r--r--platform/android/src/map/image.cpp33
1 files changed, 13 insertions, 20 deletions
diff --git a/platform/android/src/map/image.cpp b/platform/android/src/map/image.cpp
index ce89e22d7a..ee3c7012a7 100644
--- a/platform/android/src/map/image.cpp
+++ b/platform/android/src/map/image.cpp
@@ -6,43 +6,36 @@ namespace mbgl {
namespace android {
mbgl::style::Image Image::getImage(jni::JNIEnv& env, jni::Object<Image> image) {
- static auto widthField = Image::javaClass.GetField<jni::jint>(env, "width");
- static auto heightField = Image::javaClass.GetField<jni::jint>(env, "height");
- static auto pixelRatioField = Image::javaClass.GetField<jni::jfloat>(env, "pixelRatio");
- static auto bufferField = Image::javaClass.GetField<jni::Array<jbyte>>(env, "buffer");
- static auto nameField = Image::javaClass.GetField<jni::String>(env, "name");
- static auto sdfField = Image::javaClass.GetField<jni::jboolean>(env, "sdf");
+ static auto javaClass = jni::Class<Image>::Singleton(env);
+ static auto widthField = javaClass.GetField<jni::jint>(env, "width");
+ static auto heightField = javaClass.GetField<jni::jint>(env, "height");
+ static auto pixelRatioField = javaClass.GetField<jni::jfloat>(env, "pixelRatio");
+ static auto bufferField = javaClass.GetField<jni::Array<jbyte>>(env, "buffer");
+ static auto nameField = javaClass.GetField<jni::String>(env, "name");
+ static auto sdfField = javaClass.GetField<jni::jboolean>(env, "sdf");
auto height = image.Get(env, heightField);
auto width = image.Get(env, widthField);
auto pixelRatio = image.Get(env, pixelRatioField);
- auto pixels = image.Get(env, bufferField);
- auto jName = image.Get(env, nameField);
- auto name = jni::Make<std::string>(env, jName);
+ auto pixels = jni::SeizeLocal(env, image.Get(env, bufferField));
+ auto name = jni::Make<std::string>(env, *jni::SeizeLocal(env, image.Get(env, nameField)));
auto sdf = (bool) image.Get(env, sdfField);
- jni::DeleteLocalRef(env, jName);
- jni::NullCheck(env, &pixels);
- std::size_t size = pixels.Length(env);
+ jni::NullCheck(env, pixels->Get());
+ std::size_t size = pixels->Length(env);
mbgl::PremultipliedImage premultipliedImage({ static_cast<uint32_t>(width), static_cast<uint32_t>(height) });
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()));
- jni::DeleteLocalRef(env, pixels);
+ jni::GetArrayRegion(env, **pixels, 0, size, reinterpret_cast<jbyte*>(premultipliedImage.data.get()));
return mbgl::style::Image {name, std::move(premultipliedImage), pixelRatio, sdf};
}
void Image::registerNative(jni::JNIEnv &env) {
- // Lookup the class
- Image::javaClass = *jni::Class<Image>::Find(env).NewGlobalRef(env).release();
+ jni::Class<Image>::Singleton(env);
}
-jni::Class<Image> Image::javaClass;
-
-
} // namespace android
} // namespace mb
-