diff options
author | Wilhelm Berg <wb@BergWerk-GIS.at> | 2018-09-12 15:07:57 +0200 |
---|---|---|
committer | Wilhelm Berg <wb@BergWerk-GIS.at> | 2018-09-12 15:07:57 +0200 |
commit | 98b34cb0dbf5c50d7f319724c93021418140b15f (patch) | |
tree | 11cd51f86b5c672dda6bfe087f40f77df1553971 /platform/android/src/snapshotter | |
parent | ee17d79f9420eb859303d977955454dacc470db6 (diff) | |
parent | 079ba0209ed383c15123902f0810e658c2b0abf4 (diff) | |
download | qtlocation-mapboxgl-98b34cb0dbf5c50d7f319724c93021418140b15f.tar.gz |
Merge remote-tracking branch 'origin' into bwg-vs2017upstream/bwg-vs2017
# Conflicts:
# cmake/mason-dependencies.cmake
Diffstat (limited to 'platform/android/src/snapshotter')
4 files changed, 41 insertions, 50 deletions
diff --git a/platform/android/src/snapshotter/map_snapshot.cpp b/platform/android/src/snapshotter/map_snapshot.cpp index 42c1c16ca1..1650f72dc7 100644 --- a/platform/android/src/snapshotter/map_snapshot.cpp +++ b/platform/android/src/snapshotter/map_snapshot.cpp @@ -1,7 +1,7 @@ #include "map_snapshot.hpp" #include "../bitmap.hpp" -#include "../jni/collection.hpp" +#include "../conversion/collection.hpp" #include <memory> @@ -16,18 +16,18 @@ MapSnapshot::MapSnapshot(float pixelRatio_, MapSnapshot::PointForFn pointForFn_, MapSnapshot::~MapSnapshot() = default; -jni::Object<PointF> MapSnapshot::pixelForLatLng(jni::JNIEnv& env, jni::Object<LatLng> jLatLng) { +jni::Local<jni::Object<PointF>> MapSnapshot::pixelForLatLng(jni::JNIEnv& env, jni::Object<LatLng>& jLatLng) { ScreenCoordinate point = pointForFn(LatLng::getLatLng(env, jLatLng)); return PointF::New(env, point.x * pixelRatio, point.y * pixelRatio); } -jni::Object<LatLng> MapSnapshot::latLngForPixel(jni::JNIEnv& env, jni::Object<PointF>jPoint) { +jni::Local<jni::Object<LatLng>> MapSnapshot::latLngForPixel(jni::JNIEnv& env, jni::Object<PointF>& jPoint) { return LatLng::New(env, latLngForFn(PointF::getScreenCoordinate(env, jPoint))); } // Static methods // -jni::Object<MapSnapshot> MapSnapshot::New(JNIEnv& env, +jni::Local<jni::Object<MapSnapshot>> MapSnapshot::New(JNIEnv& env, PremultipliedImage&& image, float pixelRatio, std::vector<std::string> attributions, @@ -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, jni::Make<jni::Array<jni::String>>(env, attributions), (jni::jboolean) showLogo); + 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..6b82d02835 100644 --- a/platform/android/src/snapshotter/map_snapshot.hpp +++ b/platform/android/src/snapshotter/map_snapshot.hpp @@ -23,7 +23,7 @@ public: static void registerNative(jni::JNIEnv&); - static jni::Object<MapSnapshot> New(JNIEnv& env, + static jni::Local<jni::Object<MapSnapshot>> New(JNIEnv& env, PremultipliedImage&& image, float pixelRatio, std::vector<std::string> attributions, @@ -35,12 +35,10 @@ public: MapSnapshot(float pixelRatio, PointForFn, LatLngForFn); ~MapSnapshot(); - jni::Object<PointF> pixelForLatLng(jni::JNIEnv&, jni::Object<LatLng>); - jni::Object<LatLng> latLngForPixel(jni::JNIEnv&, jni::Object<PointF>); + jni::Local<jni::Object<PointF>> pixelForLatLng(jni::JNIEnv&, jni::Object<LatLng>&); + jni::Local<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..e2e01f4e38 100644 --- a/platform/android/src/snapshotter/map_snapshotter.cpp +++ b/platform/android/src/snapshotter/map_snapshotter.cpp @@ -14,18 +14,18 @@ namespace mbgl { namespace android { MapSnapshotter::MapSnapshotter(jni::JNIEnv& _env, - jni::Object<MapSnapshotter> _obj, - jni::Object<FileSource> _jFileSource, + const jni::Object<MapSnapshotter>& _obj, + const jni::Object<FileSource>& _jFileSource, jni::jfloat _pixelRatio, jni::jint width, jni::jint height, - jni::String styleURL, - jni::String styleJSON, - jni::Object<LatLngBounds> region, - jni::Object<CameraPosition> position, + const jni::String& styleURL, + const jni::String& styleJSON, + const jni::Object<LatLngBounds>& region, + const jni::Object<CameraPosition>& position, jni::jboolean _showLogo, - jni::String _programCacheDir) - : javaPeer(SeizeGenericWeakRef(_env, jni::Object<MapSnapshotter>(jni::NewWeakGlobalRef(_env, _obj.Get()).release()))) + const jni::String& _programCacheDir) + : javaPeer(_env, _obj) , pixelRatio(_pixelRatio) , threadPool(sharedThreadPool()) { @@ -80,20 +80,19 @@ 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.get(*_env).Call(*_env, onSnapshotFailed, 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); // invoke callback static auto onSnapshotReady = javaClass.GetMethod<void (jni::Object<MapSnapshot>)>(*_env, "onSnapshotReady"); - javaPeer->Call(*_env, onSnapshotReady, mapSnapshot); + javaPeer.get(*_env).Call(*_env, onSnapshotReady, mapSnapshot); } deactivateFilesource(*_env); @@ -108,11 +107,11 @@ void MapSnapshotter::cancel(JNIEnv& env) { deactivateFilesource(env); } -void MapSnapshotter::setStyleUrl(JNIEnv& env, jni::String styleURL) { +void MapSnapshotter::setStyleUrl(JNIEnv& env, const jni::String& styleURL) { snapshotter->setStyleURL(jni::Make<std::string>(env, styleURL)); } -void MapSnapshotter::setStyleJson(JNIEnv& env, jni::String styleJSON) { +void MapSnapshotter::setStyleJson(JNIEnv& env, const jni::String& styleJSON) { snapshotter->setStyleJSON(jni::Make<std::string>(env, styleJSON)); } @@ -121,12 +120,12 @@ void MapSnapshotter::setSize(JNIEnv&, jni::jint width, jni::jint height) { snapshotter->setSize(size); } -void MapSnapshotter::setCameraPosition(JNIEnv& env, jni::Object<CameraPosition> position) { +void MapSnapshotter::setCameraPosition(JNIEnv& env, const jni::Object<CameraPosition>& position) { auto options = CameraPosition::getCameraOptions(env, position); snapshotter->setCameraOptions(options); } -void MapSnapshotter::setRegion(JNIEnv& env, jni::Object<LatLngBounds> region) { +void MapSnapshotter::setRegion(JNIEnv& env, const jni::Object<LatLngBounds>& region) { snapshotter->setRegion(LatLngBounds::getLatLngBounds(env, region)); } @@ -149,17 +148,15 @@ 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", - 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>, + jni::RegisterNativePeer<MapSnapshotter>(env, javaClass, "nativePtr", + jni::MakePeer<MapSnapshotter, const jni::Object<MapSnapshotter>&, const jni::Object<FileSource>&, jni::jfloat, jni::jint, jni::jint, const jni::String&, const jni::String&, const jni::Object<LatLngBounds>&, const jni::Object<CameraPosition>&, jni::jboolean, const jni::String&>, "nativeInitialize", "finalize", METHOD(&MapSnapshotter::setStyleUrl, "setStyleUrl"), diff --git a/platform/android/src/snapshotter/map_snapshotter.hpp b/platform/android/src/snapshotter/map_snapshotter.hpp index 7b72452c45..e20acf4f1f 100644 --- a/platform/android/src/snapshotter/map_snapshotter.hpp +++ b/platform/android/src/snapshotter/map_snapshotter.hpp @@ -9,7 +9,6 @@ #include "../map/camera_position.hpp" #include <jni/jni.hpp> -#include "../jni/generic_global_ref_deleter.hpp" #include <memory> @@ -23,34 +22,32 @@ public: static constexpr auto Name() { return "com/mapbox/mapboxsdk/snapshotter/MapSnapshotter"; }; - static jni::Class<MapSnapshotter> javaClass; - static void registerNative(jni::JNIEnv&); MapSnapshotter(jni::JNIEnv&, - jni::Object<MapSnapshotter>, - jni::Object<FileSource>, + const jni::Object<MapSnapshotter>&, + const jni::Object<FileSource>&, jni::jfloat pixelRatio, jni::jint width, jni::jint height, - jni::String styleURL, - jni::String styleJSON, - jni::Object<LatLngBounds> region, - jni::Object<CameraPosition> position, + const jni::String& styleURL, + const jni::String& styleJSON, + const jni::Object<LatLngBounds>& region, + const jni::Object<CameraPosition>& position, jni::jboolean showLogo, - jni::String programCacheDir); + const jni::String& programCacheDir); ~MapSnapshotter(); - void setStyleUrl(JNIEnv&, jni::String styleURL); + void setStyleUrl(JNIEnv&, const jni::String& styleURL); - void setStyleJson(JNIEnv&, jni::String styleJSON); + void setStyleJson(JNIEnv&, const jni::String& styleJSON); void setSize(JNIEnv&, jni::jint width, jni::jint height); - void setCameraPosition(JNIEnv&, jni::Object<CameraPosition> position); + void setCameraPosition(JNIEnv&, const jni::Object<CameraPosition>& position); - void setRegion(JNIEnv&, jni::Object<LatLngBounds> region); + void setRegion(JNIEnv&, const jni::Object<LatLngBounds>& region); void start(JNIEnv&); @@ -60,7 +57,7 @@ private: MBGL_STORE_THREAD(tid); JavaVM *vm = nullptr; - GenericUniqueWeakObject<MapSnapshotter> javaPeer; + jni::WeakReference<jni::Object<MapSnapshotter>, jni::EnvAttachingDeleter> javaPeer; float pixelRatio; bool showLogo; |