diff options
Diffstat (limited to 'platform/android/src/style/sources')
16 files changed, 73 insertions, 105 deletions
diff --git a/platform/android/src/style/sources/custom_geometry_source.cpp b/platform/android/src/style/sources/custom_geometry_source.cpp index e9a530f75b..029824eae0 100644 --- a/platform/android/src/style/sources/custom_geometry_source.cpp +++ b/platform/android/src/style/sources/custom_geometry_source.cpp @@ -21,7 +21,7 @@ namespace android { // the value was originally a CustomGeometrySourceOptions object on the Java side. If it fails // to convert, it's a bug in our serialization or Java-side static typing. static style::CustomGeometrySource::Options convertCustomGeometrySourceOptions(jni::JNIEnv& env, - jni::Object<> options, + jni::Local<jni::Object<>> options, style::TileFunction fetchFn, style::TileFunction cancelFn) { using namespace mbgl::style::conversion; @@ -29,7 +29,7 @@ namespace android { return style::CustomGeometrySource::Options(); } Error error; - optional<style::CustomGeometrySource::Options> result = convert<style::CustomGeometrySource::Options>(Value(env, options), error); + optional<style::CustomGeometrySource::Options> result = convert<style::CustomGeometrySource::Options>(Value(env, std::move(options)), error); if (!result) { throw std::logic_error(error.message); } @@ -43,7 +43,7 @@ namespace android { jni::Object<> options) : Source(env, std::make_unique<mbgl::style::CustomGeometrySource>( jni::Make<std::string>(env, sourceId), - convertCustomGeometrySourceOptions(env, options, + convertCustomGeometrySourceOptions(env, jni::SeizeLocal(env, std::move(options)), std::bind(&CustomGeometrySource::fetchTile, this, std::placeholders::_1), std::bind(&CustomGeometrySource::cancelTile, this, std::placeholders::_1)))) { } @@ -61,44 +61,48 @@ namespace android { void CustomGeometrySource::fetchTile (const mbgl::CanonicalTileID& tileID) { android::UniqueEnv _env = android::AttachEnv(); + static auto javaClass = jni::Class<CustomGeometrySource>::Singleton(*_env); static auto fetchTile = javaClass.GetMethod<void (jni::jint, jni::jint, jni::jint)>(*_env, "fetchTile"); assert(javaPeer); - auto peer = jni::Cast(*_env, *javaPeer, javaClass); + auto peer = jni::Cast(*_env, javaClass, *javaPeer); peer.Call(*_env, fetchTile, (int)tileID.z, (int)tileID.x, (int)tileID.y); }; void CustomGeometrySource::cancelTile(const mbgl::CanonicalTileID& tileID) { android::UniqueEnv _env = android::AttachEnv(); + static auto javaClass = jni::Class<CustomGeometrySource>::Singleton(*_env); static auto cancelTile = javaClass.GetMethod<void (jni::jint, jni::jint, jni::jint)>(*_env, "cancelTile"); assert(javaPeer); - auto peer = jni::Cast(*_env, *javaPeer, javaClass); + auto peer = jni::Cast(*_env, javaClass, *javaPeer); peer.Call(*_env, cancelTile, (int)tileID.z, (int)tileID.x, (int)tileID.y); }; void CustomGeometrySource::startThreads() { android::UniqueEnv _env = android::AttachEnv(); + static auto javaClass = jni::Class<CustomGeometrySource>::Singleton(*_env); static auto startThreads = javaClass.GetMethod<void ()>(*_env, "startThreads"); assert(javaPeer); - auto peer = jni::Cast(*_env, *javaPeer, javaClass); + auto peer = jni::Cast(*_env, javaClass, *javaPeer); peer.Call(*_env, startThreads); } void CustomGeometrySource::releaseThreads() { android::UniqueEnv _env = android::AttachEnv(); + static auto javaClass = jni::Class<CustomGeometrySource>::Singleton(*_env); static auto releaseThreads = javaClass.GetMethod<void ()>(*_env, "releaseThreads"); assert(javaPeer); - auto peer = jni::Cast(*_env, *javaPeer, javaClass); + auto peer = jni::Cast(*_env, javaClass, *javaPeer); peer.Call(*_env, releaseThreads); }; @@ -107,11 +111,12 @@ namespace android { jni::jint y) { android::UniqueEnv _env = android::AttachEnv(); + static auto javaClass = jni::Class<CustomGeometrySource>::Singleton(*_env); static auto isCancelled = javaClass.GetMethod<jboolean (jni::jint, jni::jint, jni::jint)>(*_env, "isCancelled"); assert(javaPeer); - auto peer = jni::Cast(*_env, *javaPeer, javaClass); + auto peer = jni::Cast(*_env, javaClass, *javaPeer); return peer.Call(*_env, isCancelled, z, x, y); }; @@ -147,16 +152,16 @@ namespace android { std::vector<mbgl::Feature> features; if (rendererFrontend) { - features = rendererFrontend->querySourceFeatures(source.getID(), { {}, toFilter(env, jfilter) }); + features = rendererFrontend->querySourceFeatures(source.getID(), + { {}, toFilter(env, jni::SeizeLocal(env, std::move(jfilter))) }); } return *convert<jni::Array<jni::Object<Feature>>, std::vector<mbgl::Feature>>(env, features); } - jni::Class<CustomGeometrySource> CustomGeometrySource::javaClass; - jni::Object<Source> CustomGeometrySource::createJavaPeer(jni::JNIEnv& env) { - static auto constructor = CustomGeometrySource::javaClass.template GetConstructor<jni::jlong>(env); - return jni::Object<Source>(CustomGeometrySource::javaClass.New(env, constructor, reinterpret_cast<jni::jlong>(this)).Get()); + static auto javaClass = jni::Class<CustomGeometrySource>::Singleton(env); + static auto constructor = javaClass.GetConstructor<jni::jlong>(env); + return jni::Object<Source>(javaClass.New(env, constructor, reinterpret_cast<jni::jlong>(this)).Get()); } void CustomGeometrySource::addToMap(JNIEnv& env, jni::Object<Source> obj, mbgl::Map& map, AndroidRendererFrontend& frontend) { @@ -174,13 +179,13 @@ namespace android { void CustomGeometrySource::registerNative(jni::JNIEnv& env) { // Lookup the class - CustomGeometrySource::javaClass = *jni::Class<CustomGeometrySource>::Find(env).NewGlobalRef(env).release(); + static auto javaClass = jni::Class<CustomGeometrySource>::Singleton(env); #define METHOD(MethodPtr, name) jni::MakeNativePeerMethod<decltype(MethodPtr), (MethodPtr)>(name) // Register the peer jni::RegisterNativePeer<CustomGeometrySource>( - env, CustomGeometrySource::javaClass, "nativePtr", + env, javaClass, "nativePtr", std::make_unique<CustomGeometrySource, JNIEnv&, jni::String, jni::Object<>>, "initialize", "finalize", diff --git a/platform/android/src/style/sources/custom_geometry_source.hpp b/platform/android/src/style/sources/custom_geometry_source.hpp index 801f81b089..ecfadd659c 100644 --- a/platform/android/src/style/sources/custom_geometry_source.hpp +++ b/platform/android/src/style/sources/custom_geometry_source.hpp @@ -18,14 +18,10 @@ public: static constexpr auto Name() { return "com/mapbox/mapboxsdk/style/sources/CustomGeometrySource"; }; - static jni::Class<CustomGeometrySource> javaClass; - static void registerNative(jni::JNIEnv&); CustomGeometrySource(jni::JNIEnv&, jni::String, jni::Object<>); - CustomGeometrySource(jni::JNIEnv&, mbgl::style::Source&, AndroidRendererFrontend&); - ~CustomGeometrySource(); bool removeFromMap(JNIEnv&, jni::Object<Source>, mbgl::Map&) override; @@ -36,6 +32,8 @@ public: bool isCancelled(jni::jint z, jni::jint x, jni::jint y); void startThreads(); void releaseThreads(); + +private: void setTileData(jni::JNIEnv& env, jni::jint z, jni::jint x, jni::jint y, jni::Object<geojson::FeatureCollection> jf); void invalidateTile(jni::JNIEnv& env, jni::jint z, jni::jint x, jni::jint y); @@ -44,7 +42,6 @@ public: jni::Array<jni::Object<geojson::Feature>> querySourceFeatures(jni::JNIEnv&, jni::Array<jni::Object<>> ); -private: jni::Object<Source> createJavaPeer(jni::JNIEnv&); }; // class CustomGeometrySource diff --git a/platform/android/src/style/sources/geojson_source.cpp b/platform/android/src/style/sources/geojson_source.cpp index 9d6ca704eb..b9f3f73801 100644 --- a/platform/android/src/style/sources/geojson_source.cpp +++ b/platform/android/src/style/sources/geojson_source.cpp @@ -29,13 +29,14 @@ namespace android { // This conversion is expected not to fail because it's used only in contexts where // the value was originally a GeoJsonOptions object on the Java side. If it fails // to convert, it's a bug in our serialization or Java-side static typing. - static style::GeoJSONOptions convertGeoJSONOptions(jni::JNIEnv& env, jni::Object<> options) { + static style::GeoJSONOptions convertGeoJSONOptions(jni::JNIEnv& env, jni::Local<jni::Object<>> options) { using namespace mbgl::style::conversion; if (!options) { return style::GeoJSONOptions(); } Error error; - optional<style::GeoJSONOptions> result = convert<style::GeoJSONOptions>(mbgl::android::Value(env, options), error); + optional<style::GeoJSONOptions> result = convert<style::GeoJSONOptions>( + mbgl::android::Value(env, std::move(options)), error); if (!result) { throw std::logic_error(error.message); } @@ -45,7 +46,7 @@ namespace android { GeoJSONSource::GeoJSONSource(jni::JNIEnv& env, jni::String sourceId, jni::Object<> options) : Source(env, std::make_unique<mbgl::style::GeoJSONSource>( jni::Make<std::string>(env, sourceId), - convertGeoJSONOptions(env, options))) + convertGeoJSONOptions(env, jni::SeizeLocal(env, std::move(options))))) , threadPool(sharedThreadPool()) , converter(std::make_unique<Actor<FeatureConverter>>(*threadPool)) { } @@ -100,22 +101,22 @@ namespace android { std::vector<mbgl::Feature> features; if (rendererFrontend) { - features = rendererFrontend->querySourceFeatures(source.getID(), { {}, toFilter(env, jfilter) }); + features = rendererFrontend->querySourceFeatures(source.getID(), + { {}, toFilter(env, jni::SeizeLocal(env, std::move(jfilter))) }); } return *convert<jni::Array<jni::Object<Feature>>, std::vector<mbgl::Feature>>(env, features); } - jni::Class<GeoJSONSource> GeoJSONSource::javaClass; - jni::Object<Source> GeoJSONSource::createJavaPeer(jni::JNIEnv& env) { - static auto constructor = GeoJSONSource::javaClass.template GetConstructor<jni::jlong>(env); - return jni::Object<Source>(GeoJSONSource::javaClass.New(env, constructor, reinterpret_cast<jni::jlong>(this)).Get()); + static auto javaClass = jni::Class<GeoJSONSource>::Singleton(env); + static auto constructor = javaClass.GetConstructor<jni::jlong>(env); + return jni::Object<Source>(javaClass.New(env, constructor, reinterpret_cast<jni::jlong>(this)).Get()); } template <class JNIType> void GeoJSONSource::setCollectionAsync(jni::JNIEnv& env, jni::Object<JNIType> jObject) { - std::shared_ptr<jni::jobject> object = std::shared_ptr<jni::jobject>(jObject.NewGlobalRef(env).release()->Get(), GenericGlobalRefDeleter()); + std::shared_ptr<jni::jobject> object = std::shared_ptr<jni::jobject>(jObject.NewGlobalRef(env).release().Get(), GenericGlobalRefDeleter()); Update::Converter converterFn = [this, object](ActorRef<Callback> _callback) { converter->self().invoke(&FeatureConverter::convertObject<JNIType>, jni::Object<JNIType>(*object), _callback); @@ -158,13 +159,13 @@ namespace android { void GeoJSONSource::registerNative(jni::JNIEnv& env) { // Lookup the class - GeoJSONSource::javaClass = *jni::Class<GeoJSONSource>::Find(env).NewGlobalRef(env).release(); + static auto javaClass = jni::Class<GeoJSONSource>::Singleton(env); #define METHOD(MethodPtr, name) jni::MakeNativePeerMethod<decltype(MethodPtr), (MethodPtr)>(name) // Register the peer jni::RegisterNativePeer<GeoJSONSource>( - env, GeoJSONSource::javaClass, "nativePtr", + env, javaClass, "nativePtr", std::make_unique<GeoJSONSource, JNIEnv&, jni::String, jni::Object<>>, "initialize", "finalize", diff --git a/platform/android/src/style/sources/geojson_source.hpp b/platform/android/src/style/sources/geojson_source.hpp index 24ea3c73f8..eb28e2470b 100644 --- a/platform/android/src/style/sources/geojson_source.hpp +++ b/platform/android/src/style/sources/geojson_source.hpp @@ -30,35 +30,26 @@ struct Update { class GeoJSONSource : public Source { public: - static constexpr auto Name() { return "com/mapbox/mapboxsdk/style/sources/GeoJsonSource"; }; - static jni::Class<GeoJSONSource> javaClass; - static void registerNative(jni::JNIEnv&); GeoJSONSource(jni::JNIEnv&, jni::String, jni::Object<>); - GeoJSONSource(jni::JNIEnv&, mbgl::style::Source&, AndroidRendererFrontend&); - ~GeoJSONSource(); +private: void setGeoJSONString(jni::JNIEnv&, jni::String); - void setFeatureCollection(jni::JNIEnv&, jni::Object<geojson::FeatureCollection>); - void setFeature(jni::JNIEnv&, jni::Object<geojson::Feature>); - void setGeometry(jni::JNIEnv&, jni::Object<geojson::Geometry>); - void setURL(jni::JNIEnv&, jni::String); - jni::String getURL(jni::JNIEnv&); - jni::Array<jni::Object<geojson::Feature>> querySourceFeatures(jni::JNIEnv&, - jni::Array<jni::Object<>> jfilter); + jni::Array<jni::Object<>>); + + jni::String getURL(jni::JNIEnv&); -private: jni::Object<Source> createJavaPeer(jni::JNIEnv&); std::unique_ptr<Update> awaitingUpdate; std::unique_ptr<Update> update; diff --git a/platform/android/src/style/sources/image_source.cpp b/platform/android/src/style/sources/image_source.cpp index 278564485d..343b7439c8 100644 --- a/platform/android/src/style/sources/image_source.cpp +++ b/platform/android/src/style/sources/image_source.cpp @@ -50,22 +50,21 @@ namespace android { LatLngQuad::getLatLngArray(env, coordinatesObject)); } - jni::Class<ImageSource> ImageSource::javaClass; - jni::Object<Source> ImageSource::createJavaPeer(jni::JNIEnv& env) { - static auto constructor = ImageSource::javaClass.template GetConstructor<jni::jlong>(env); - return jni::Object<Source>(ImageSource::javaClass.New(env, constructor, reinterpret_cast<jni::jlong>(this)).Get()); + static auto javaClass = jni::Class<ImageSource>::Singleton(env); + static auto constructor = javaClass.GetConstructor<jni::jlong>(env); + return jni::Object<Source>(javaClass.New(env, constructor, reinterpret_cast<jni::jlong>(this)).Get()); } void ImageSource::registerNative(jni::JNIEnv& env) { // Lookup the class - ImageSource::javaClass = *jni::Class<ImageSource>::Find(env).NewGlobalRef(env).release(); + static auto javaClass = jni::Class<ImageSource>::Singleton(env); #define METHOD(MethodPtr, name) jni::MakeNativePeerMethod<decltype(MethodPtr), (MethodPtr)>(name) // Register the peer jni::RegisterNativePeer<ImageSource>( - env, ImageSource::javaClass, "nativePtr", + env, javaClass, "nativePtr", std::make_unique<ImageSource, JNIEnv&, jni::String, jni::Object<LatLngQuad>>, "initialize", "finalize", diff --git a/platform/android/src/style/sources/image_source.hpp b/platform/android/src/style/sources/image_source.hpp index 6021a03dc3..b09d4f8c95 100644 --- a/platform/android/src/style/sources/image_source.hpp +++ b/platform/android/src/style/sources/image_source.hpp @@ -15,8 +15,6 @@ public: static constexpr auto Name() { return "com/mapbox/mapboxsdk/style/sources/ImageSource"; }; - static jni::Class<ImageSource> javaClass; - static void registerNative(jni::JNIEnv&); ImageSource(jni::JNIEnv&, jni::String, jni::Object<LatLngQuad>); diff --git a/platform/android/src/style/sources/raster_dem_source.cpp b/platform/android/src/style/sources/raster_dem_source.cpp index 75e0159d7c..73d04f27c1 100644 --- a/platform/android/src/style/sources/raster_dem_source.cpp +++ b/platform/android/src/style/sources/raster_dem_source.cpp @@ -17,7 +17,7 @@ namespace android { env, std::make_unique<mbgl::style::RasterDEMSource>( jni::Make<std::string>(env, sourceId), - convertURLOrTileset(Value(env, urlOrTileSet)), + convertURLOrTileset(Value(env, jni::SeizeLocal(env, std::move(urlOrTileSet)))), tileSize ) ) { @@ -36,22 +36,21 @@ namespace android { return url ? jni::Make<jni::String>(env, *url) : jni::String(); } - jni::Class<RasterDEMSource> RasterDEMSource::javaClass; - jni::Object<Source> RasterDEMSource::createJavaPeer(jni::JNIEnv& env) { - static auto constructor = RasterDEMSource::javaClass.template GetConstructor<jni::jlong>(env); - return jni::Object<Source>(RasterDEMSource::javaClass.New(env, constructor, reinterpret_cast<jni::jlong>(this)).Get()); + static auto javaClass = jni::Class<RasterDEMSource>::Singleton(env); + static auto constructor = javaClass.GetConstructor<jni::jlong>(env); + return jni::Object<Source>(javaClass.New(env, constructor, reinterpret_cast<jni::jlong>(this)).Get()); } void RasterDEMSource::registerNative(jni::JNIEnv& env) { // Lookup the class - RasterDEMSource::javaClass = *jni::Class<RasterDEMSource>::Find(env).NewGlobalRef(env).release(); + static auto javaClass = jni::Class<RasterDEMSource>::Singleton(env); #define METHOD(MethodPtr, name) jni::MakeNativePeerMethod<decltype(MethodPtr), (MethodPtr)>(name) // Register the peer jni::RegisterNativePeer<RasterDEMSource>( - env, RasterDEMSource::javaClass, "nativePtr", + env, javaClass, "nativePtr", std::make_unique<RasterDEMSource, JNIEnv&, jni::String, jni::Object<>, jni::jint>, "initialize", "finalize", diff --git a/platform/android/src/style/sources/raster_dem_source.hpp b/platform/android/src/style/sources/raster_dem_source.hpp index 56924c1f8d..25d9fe90cd 100644 --- a/platform/android/src/style/sources/raster_dem_source.hpp +++ b/platform/android/src/style/sources/raster_dem_source.hpp @@ -9,17 +9,12 @@ namespace android { class RasterDEMSource : public Source { public: - static constexpr auto Name() { return "com/mapbox/mapboxsdk/style/sources/RasterDemSource"; }; - static jni::Class<RasterDEMSource> javaClass; - static void registerNative(jni::JNIEnv&); RasterDEMSource(jni::JNIEnv&, jni::String, jni::Object<>, jni::jint); - RasterDEMSource(jni::JNIEnv&, mbgl::style::Source&, AndroidRendererFrontend&); - ~RasterDEMSource(); jni::String getURL(jni::JNIEnv&); diff --git a/platform/android/src/style/sources/raster_source.cpp b/platform/android/src/style/sources/raster_source.cpp index 33223a5b69..4eef41c8b1 100644 --- a/platform/android/src/style/sources/raster_source.cpp +++ b/platform/android/src/style/sources/raster_source.cpp @@ -16,7 +16,7 @@ namespace android { env, std::make_unique<mbgl::style::RasterSource>( jni::Make<std::string>(env, sourceId), - convertURLOrTileset(Value(env, urlOrTileSet)), + convertURLOrTileset(Value(env, jni::SeizeLocal(env, std::move(urlOrTileSet)))), tileSize ) ) { @@ -35,22 +35,21 @@ namespace android { return url ? jni::Make<jni::String>(env, *url) : jni::String(); } - jni::Class<RasterSource> RasterSource::javaClass; - jni::Object<Source> RasterSource::createJavaPeer(jni::JNIEnv& env) { - static auto constructor = RasterSource::javaClass.template GetConstructor<jni::jlong>(env); - return jni::Object<Source>(RasterSource::javaClass.New(env, constructor, reinterpret_cast<jni::jlong>(this)).Get()); + static auto javaClass = jni::Class<RasterSource>::Singleton(env); + static auto constructor = javaClass.GetConstructor<jni::jlong>(env); + return jni::Object<Source>(javaClass.New(env, constructor, reinterpret_cast<jni::jlong>(this)).Get()); } void RasterSource::registerNative(jni::JNIEnv& env) { // Lookup the class - RasterSource::javaClass = *jni::Class<RasterSource>::Find(env).NewGlobalRef(env).release(); + static auto javaClass = jni::Class<RasterSource>::Singleton(env); #define METHOD(MethodPtr, name) jni::MakeNativePeerMethod<decltype(MethodPtr), (MethodPtr)>(name) // Register the peer jni::RegisterNativePeer<RasterSource>( - env, RasterSource::javaClass, "nativePtr", + env, javaClass, "nativePtr", std::make_unique<RasterSource, JNIEnv&, jni::String, jni::Object<>, jni::jint>, "initialize", "finalize", diff --git a/platform/android/src/style/sources/raster_source.hpp b/platform/android/src/style/sources/raster_source.hpp index a1da22f40d..888d9f601d 100644 --- a/platform/android/src/style/sources/raster_source.hpp +++ b/platform/android/src/style/sources/raster_source.hpp @@ -9,17 +9,12 @@ namespace android { class RasterSource : public Source { public: - static constexpr auto Name() { return "com/mapbox/mapboxsdk/style/sources/RasterSource"; }; - static jni::Class<RasterSource> javaClass; - static void registerNative(jni::JNIEnv&); RasterSource(jni::JNIEnv&, jni::String, jni::Object<>, jni::jint); - RasterSource(jni::JNIEnv&, mbgl::style::Source&, AndroidRendererFrontend&); - ~RasterSource(); jni::String getURL(jni::JNIEnv&); diff --git a/platform/android/src/style/sources/source.cpp b/platform/android/src/style/sources/source.cpp index d2e2426c0b..c7968786ec 100644 --- a/platform/android/src/style/sources/source.cpp +++ b/platform/android/src/style/sources/source.cpp @@ -76,6 +76,7 @@ namespace android { if (ownedSource.get() == nullptr && javaPeer.get() != nullptr) { // Manually clear the java peer android::UniqueEnv env = android::AttachEnv(); + static auto javaClass = jni::Class<Source>::Singleton(*env); static auto nativePtrField = javaClass.GetField<jlong>(*env, "nativePtr"); javaPeer->Set(*env, nativePtrField, (jlong) 0); javaPeer.reset(); @@ -140,16 +141,14 @@ namespace android { rendererFrontend = nullptr; } - jni::Class<Source> Source::javaClass; - void Source::registerNative(jni::JNIEnv& env) { // Lookup the class - Source::javaClass = *jni::Class<Source>::Find(env).NewGlobalRef(env).release(); + static auto javaClass = jni::Class<Source>::Singleton(env); #define METHOD(MethodPtr, name) jni::MakeNativePeerMethod<decltype(MethodPtr), (MethodPtr)>(name) // Register the peer - jni::RegisterNativePeer<Source>(env, Source::javaClass, "nativePtr", + jni::RegisterNativePeer<Source>(env, javaClass, "nativePtr", METHOD(&Source::getId, "nativeGetId"), METHOD(&Source::getAttribution, "nativeGetAttribution") ); diff --git a/platform/android/src/style/sources/source.hpp b/platform/android/src/style/sources/source.hpp index 6b906eb9c0..492be8dfec 100644 --- a/platform/android/src/style/sources/source.hpp +++ b/platform/android/src/style/sources/source.hpp @@ -17,8 +17,6 @@ public: static constexpr auto Name() { return "com/mapbox/mapboxsdk/style/sources/Source"; }; - static jni::Class<Source> javaClass; - static void registerNative(jni::JNIEnv&); static jni::Object<Source> peerForCoreSource(jni::JNIEnv&, mbgl::style::Source&, AndroidRendererFrontend&); @@ -53,7 +51,7 @@ protected: mbgl::style::Source& source; // Set when the source is added to a map. - jni::UniqueObject<Source> javaPeer; + jni::Global<jni::Object<Source>> javaPeer; // RendererFrontend pointer is valid only when added to the map. AndroidRendererFrontend* rendererFrontend { nullptr }; diff --git a/platform/android/src/style/sources/unknown_source.cpp b/platform/android/src/style/sources/unknown_source.cpp index 4b5510c1db..8e91798392 100644 --- a/platform/android/src/style/sources/unknown_source.cpp +++ b/platform/android/src/style/sources/unknown_source.cpp @@ -18,22 +18,21 @@ namespace android { : Source(env, coreSource, createJavaPeer(env), frontend) { } - jni::Class<UnknownSource> UnknownSource::javaClass; - jni::Object<Source> UnknownSource::createJavaPeer(jni::JNIEnv& env) { - static auto constructor = UnknownSource::javaClass.template GetConstructor<jni::jlong>(env); - return jni::Object<Source>(UnknownSource::javaClass.New(env, constructor, reinterpret_cast<jni::jlong>(this)).Get()); + static auto javaClass = jni::Class<UnknownSource>::Singleton(env); + static auto constructor = javaClass.GetConstructor<jni::jlong>(env); + return jni::Object<Source>(javaClass.New(env, constructor, reinterpret_cast<jni::jlong>(this)).Get()); } void UnknownSource::registerNative(jni::JNIEnv& env) { // Lookup the class - UnknownSource::javaClass = *jni::Class<UnknownSource>::Find(env).NewGlobalRef(env).release(); + static auto javaClass = jni::Class<UnknownSource>::Singleton(env); #define METHOD(MethodPtr, name) jni::MakeNativePeerMethod<decltype(MethodPtr), (MethodPtr)>(name) // Register the peer jni::RegisterNativePeer<UnknownSource>( - env, UnknownSource::javaClass, "nativePtr", + env, javaClass, "nativePtr", init, "initialize", "finalize" diff --git a/platform/android/src/style/sources/unknown_source.hpp b/platform/android/src/style/sources/unknown_source.hpp index 414d420c61..855aea7c63 100644 --- a/platform/android/src/style/sources/unknown_source.hpp +++ b/platform/android/src/style/sources/unknown_source.hpp @@ -12,8 +12,6 @@ public: static constexpr auto Name() { return "com/mapbox/mapboxsdk/style/sources/UnknownSource"; }; - static jni::Class<UnknownSource> javaClass; - static void registerNative(jni::JNIEnv&); UnknownSource(jni::JNIEnv&, mbgl::style::Source&, AndroidRendererFrontend&); diff --git a/platform/android/src/style/sources/vector_source.cpp b/platform/android/src/style/sources/vector_source.cpp index 9a9548d283..69052bd98c 100644 --- a/platform/android/src/style/sources/vector_source.cpp +++ b/platform/android/src/style/sources/vector_source.cpp @@ -25,7 +25,7 @@ namespace android { env, std::make_unique<mbgl::style::VectorSource>( jni::Make<std::string>(env, sourceId), - convertURLOrTileset(Value(env, urlOrTileSet)) + convertURLOrTileset(Value(env, jni::SeizeLocal(env, std::move(urlOrTileSet)))) ) ) { } @@ -51,27 +51,27 @@ namespace android { std::vector<mbgl::Feature> features; if (rendererFrontend) { - features = rendererFrontend->querySourceFeatures(source.getID(), { toVector(env, jSourceLayerIds), toFilter(env, jfilter) }); + features = rendererFrontend->querySourceFeatures(source.getID(), + { toVector(env, jSourceLayerIds), toFilter(env, jni::SeizeLocal(env, std::move(jfilter))) }); } return *convert<jni::Array<jni::Object<Feature>>, std::vector<mbgl::Feature>>(env, features); } - jni::Class<VectorSource> VectorSource::javaClass; - jni::Object<Source> VectorSource::createJavaPeer(jni::JNIEnv& env) { - static auto constructor = VectorSource::javaClass.template GetConstructor<jni::jlong>(env); - return jni::Object<Source>(VectorSource::javaClass.New(env, constructor, reinterpret_cast<jni::jlong>(this)).Get()); + static auto javaClass = jni::Class<VectorSource>::Singleton(env); + static auto constructor = javaClass.GetConstructor<jni::jlong>(env); + return jni::Object<Source>(javaClass.New(env, constructor, reinterpret_cast<jni::jlong>(this)).Get()); } void VectorSource::registerNative(jni::JNIEnv& env) { // Lookup the class - VectorSource::javaClass = *jni::Class<VectorSource>::Find(env).NewGlobalRef(env).release(); + static auto javaClass = jni::Class<VectorSource>::Singleton(env); #define METHOD(MethodPtr, name) jni::MakeNativePeerMethod<decltype(MethodPtr), (MethodPtr)>(name) // Register the peer jni::RegisterNativePeer<VectorSource>( - env, VectorSource::javaClass, "nativePtr", + env, javaClass, "nativePtr", std::make_unique<VectorSource, JNIEnv&, jni::String, jni::Object<>>, "initialize", "finalize", diff --git a/platform/android/src/style/sources/vector_source.hpp b/platform/android/src/style/sources/vector_source.hpp index 16049f5c77..587a4be208 100644 --- a/platform/android/src/style/sources/vector_source.hpp +++ b/platform/android/src/style/sources/vector_source.hpp @@ -10,25 +10,20 @@ namespace android { class VectorSource : public Source { public: - static constexpr auto Name() { return "com/mapbox/mapboxsdk/style/sources/VectorSource"; }; - static jni::Class<VectorSource> javaClass; - static void registerNative(jni::JNIEnv&); VectorSource(jni::JNIEnv&, jni::String, jni::Object<>); - VectorSource(jni::JNIEnv&, mbgl::style::Source&, AndroidRendererFrontend&); - ~VectorSource(); +private: jni::Array<jni::Object<geojson::Feature>> querySourceFeatures(jni::JNIEnv&, jni::Array<jni::String>, jni::Array<jni::Object<>> jfilter); jni::String getURL(jni::JNIEnv&); -private: jni::Object<Source> createJavaPeer(jni::JNIEnv&); }; // class VectorSource |