diff options
author | John Firebaugh <john.firebaugh@gmail.com> | 2018-08-17 13:43:07 -0700 |
---|---|---|
committer | John Firebaugh <john.firebaugh@gmail.com> | 2018-09-07 09:44:12 -0700 |
commit | 53c3c327f0ebea276d977f58a59cdb9449165518 (patch) | |
tree | 1315a80a1c24f24dd1cbd4e00cf85083be16ce45 /platform/android/src/snapshotter | |
parent | 6806ba5b52129050c0944bd7c8b1fe285baeeddc (diff) | |
download | qtlocation-mapboxgl-53c3c327f0ebea276d977f58a59cdb9449165518.tar.gz |
[android] Upgrade to latest jni.hpp
Diffstat (limited to 'platform/android/src/snapshotter')
4 files changed, 10 insertions, 17 deletions
diff --git a/platform/android/src/snapshotter/map_snapshot.cpp b/platform/android/src/snapshotter/map_snapshot.cpp index 379ac89d52..d626ae68b7 100644 --- a/platform/android/src/snapshotter/map_snapshot.cpp +++ b/platform/android/src/snapshotter/map_snapshot.cpp @@ -38,21 +38,20 @@ jni::Object<MapSnapshot> MapSnapshot::New(JNIEnv& env, auto bitmap = Bitmap::CreateBitmap(env, std::move(image)); // Create the Mapsnapshot peers + static auto javaClass = jni::Class<MapSnapshot>::Singleton(env); static auto constructor = javaClass.GetConstructor<jni::jlong, jni::Object<Bitmap>, jni::Array<jni::String>, jni::jboolean>(env); auto nativePeer = std::make_unique<MapSnapshot>(pixelRatio, pointForFn, latLngForFn); return javaClass.New(env, constructor, reinterpret_cast<jlong>(nativePeer.release()), bitmap, conversion::toArray(env, attributions), (jni::jboolean) showLogo); } -jni::Class<MapSnapshot> MapSnapshot::javaClass; - void MapSnapshot::registerNative(jni::JNIEnv& env) { // Lookup the class - MapSnapshot::javaClass = *jni::Class<MapSnapshot>::Find(env).NewGlobalRef(env).release(); + static auto javaClass = jni::Class<MapSnapshot>::Singleton(env); #define METHOD(MethodPtr, name) jni::MakeNativePeerMethod<decltype(MethodPtr), (MethodPtr)>(name) // Register the peer - jni::RegisterNativePeer<MapSnapshot>(env, MapSnapshot::javaClass, + jni::RegisterNativePeer<MapSnapshot>(env, javaClass, "nativePtr", std::make_unique<MapSnapshot, JNIEnv&>, "initialize", diff --git a/platform/android/src/snapshotter/map_snapshot.hpp b/platform/android/src/snapshotter/map_snapshot.hpp index f168be85b4..3cd293b621 100644 --- a/platform/android/src/snapshotter/map_snapshot.hpp +++ b/platform/android/src/snapshotter/map_snapshot.hpp @@ -39,8 +39,6 @@ public: jni::Object<LatLng> latLngForPixel(jni::JNIEnv&, jni::Object<PointF>); private: - static jni::Class<MapSnapshot> javaClass; - float pixelRatio; mbgl::MapSnapshotter::PointForFn pointForFn; mbgl::MapSnapshotter::LatLngForFn latLngForFn; diff --git a/platform/android/src/snapshotter/map_snapshotter.cpp b/platform/android/src/snapshotter/map_snapshotter.cpp index a93404dbfb..4df0749aa0 100644 --- a/platform/android/src/snapshotter/map_snapshotter.cpp +++ b/platform/android/src/snapshotter/map_snapshotter.cpp @@ -25,7 +25,7 @@ MapSnapshotter::MapSnapshotter(jni::JNIEnv& _env, jni::Object<CameraPosition> position, jni::jboolean _showLogo, jni::String _programCacheDir) - : javaPeer(SeizeGenericWeakRef(_env, jni::Object<MapSnapshotter>(jni::NewWeakGlobalRef(_env, _obj.Get()).release()))) + : javaPeer(SeizeGenericWeak(_obj.NewWeakGlobalRef(_env).release())) , pixelRatio(_pixelRatio) , threadPool(sharedThreadPool()) { @@ -80,13 +80,13 @@ void MapSnapshotter::start(JNIEnv& env) { [this](std::exception_ptr err, PremultipliedImage image, std::vector<std::string> attributions, mbgl::MapSnapshotter::PointForFn pointForFn, mbgl::MapSnapshotter::LatLngForFn latLngForFn) { MBGL_VERIFY_THREAD(tid); android::UniqueEnv _env = android::AttachEnv(); + static auto javaClass = jni::Class<MapSnapshotter>::Singleton(*_env); if (err) { // error handler callback static auto onSnapshotFailed = javaClass.GetMethod<void (jni::String)>(*_env, "onSnapshotFailed"); - auto message = jni::Make<jni::String>(*_env, util::toString(err)); - javaPeer->Call(*_env, onSnapshotFailed, message); - jni::DeleteLocalRef(*_env, message); + javaPeer->Call(*_env, onSnapshotFailed, + *jni::SeizeLocal(*_env, jni::Make<jni::String>(*_env, util::toString(err)))); } else { // Create the wrapper auto mapSnapshot = android::MapSnapshot::New(*_env, std::move(image), pixelRatio, attributions, showLogo, pointForFn, latLngForFn); @@ -149,16 +149,14 @@ void MapSnapshotter::deactivateFilesource(JNIEnv& env) { // Static methods // -jni::Class<MapSnapshotter> MapSnapshotter::javaClass; - void MapSnapshotter::registerNative(jni::JNIEnv& env) { // Lookup the class - MapSnapshotter::javaClass = *jni::Class<MapSnapshotter>::Find(env).NewGlobalRef(env).release(); + static auto javaClass = jni::Class<MapSnapshotter>::Singleton(env); #define METHOD(MethodPtr, name) jni::MakeNativePeerMethod<decltype(MethodPtr), (MethodPtr)>(name) // Register the peer - jni::RegisterNativePeer<MapSnapshotter>(env, MapSnapshotter::javaClass, "nativePtr", + jni::RegisterNativePeer<MapSnapshotter>(env, javaClass, "nativePtr", std::make_unique<MapSnapshotter, JNIEnv&, jni::Object<MapSnapshotter>, jni::Object<FileSource>, jni::jfloat, jni::jint, jni::jint, jni::String, jni::String, jni::Object<LatLngBounds>, jni::Object<CameraPosition>, jni::jboolean, jni::String>, "nativeInitialize", "finalize", diff --git a/platform/android/src/snapshotter/map_snapshotter.hpp b/platform/android/src/snapshotter/map_snapshotter.hpp index 7b72452c45..05a27256aa 100644 --- a/platform/android/src/snapshotter/map_snapshotter.hpp +++ b/platform/android/src/snapshotter/map_snapshotter.hpp @@ -23,8 +23,6 @@ public: static constexpr auto Name() { return "com/mapbox/mapboxsdk/snapshotter/MapSnapshotter"; }; - static jni::Class<MapSnapshotter> javaClass; - static void registerNative(jni::JNIEnv&); MapSnapshotter(jni::JNIEnv&, @@ -60,7 +58,7 @@ private: MBGL_STORE_THREAD(tid); JavaVM *vm = nullptr; - GenericUniqueWeakObject<MapSnapshotter> javaPeer; + GenericWeak<jni::Object<MapSnapshotter>> javaPeer; float pixelRatio; bool showLogo; |