diff options
author | John Firebaugh <john.firebaugh@gmail.com> | 2018-08-22 12:27:43 -0700 |
---|---|---|
committer | John Firebaugh <john.firebaugh@gmail.com> | 2018-09-07 09:44:12 -0700 |
commit | 79bf0e8af6bf9ec829a352d56b8e70ccc8f4fa41 (patch) | |
tree | 2b646523d45f0fa9917612ed80de12bbd35d5b1e /platform/android/src/style/sources/custom_geometry_source.cpp | |
parent | 5911e3b13f2f2b6741e26db3e41513ed21cc95b4 (diff) | |
download | qtlocation-mapboxgl-79bf0e8af6bf9ec829a352d56b8e70ccc8f4fa41.tar.gz |
[android] jni.hpp 4.0.0
Diffstat (limited to 'platform/android/src/style/sources/custom_geometry_source.cpp')
-rw-r--r-- | platform/android/src/style/sources/custom_geometry_source.cpp | 56 |
1 files changed, 28 insertions, 28 deletions
diff --git a/platform/android/src/style/sources/custom_geometry_source.cpp b/platform/android/src/style/sources/custom_geometry_source.cpp index 9012948b0b..057f5c99ba 100644 --- a/platform/android/src/style/sources/custom_geometry_source.cpp +++ b/platform/android/src/style/sources/custom_geometry_source.cpp @@ -1,4 +1,5 @@ #include "custom_geometry_source.hpp" +#include "../../attach_env.hpp" #include <mbgl/renderer/query.hpp> @@ -21,7 +22,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::Local<jni::Object<>> options, + const jni::Object<>& options, style::TileFunction fetchFn, style::TileFunction cancelFn) { using namespace mbgl::style::conversion; @@ -29,7 +30,7 @@ namespace android { return style::CustomGeometrySource::Options(); } Error error; - optional<style::CustomGeometrySource::Options> result = convert<style::CustomGeometrySource::Options>(Value(env, std::move(options)), error); + optional<style::CustomGeometrySource::Options> result = convert<style::CustomGeometrySource::Options>(Value(env, options), error); if (!result) { throw std::logic_error(error.message); } @@ -39,11 +40,11 @@ namespace android { } CustomGeometrySource::CustomGeometrySource(jni::JNIEnv& env, - jni::String sourceId, - jni::Object<> options) + const jni::String& sourceId, + const jni::Object<>& options) : Source(env, std::make_unique<mbgl::style::CustomGeometrySource>( jni::Make<std::string>(env, sourceId), - convertCustomGeometrySourceOptions(env, jni::SeizeLocal(env, std::move(options)), + convertCustomGeometrySourceOptions(env, options, std::bind(&CustomGeometrySource::fetchTile, this, std::placeholders::_1), std::bind(&CustomGeometrySource::cancelTile, this, std::placeholders::_1)))) { } @@ -61,48 +62,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& 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, javaClass, *javaPeer); + 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& 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, javaClass, *javaPeer); + 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& javaClass = jni::Class<CustomGeometrySource>::Singleton(*_env); static auto startThreads = javaClass.GetMethod<void ()>(*_env, "startThreads"); assert(javaPeer); - auto peer = jni::Cast(*_env, javaClass, *javaPeer); + 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& javaClass = jni::Class<CustomGeometrySource>::Singleton(*_env); static auto releaseThreads = javaClass.GetMethod<void ()>(*_env, "releaseThreads"); assert(javaPeer); - auto peer = jni::Cast(*_env, javaClass, *javaPeer); + auto peer = jni::Cast(*_env, javaClass, javaPeer); peer.Call(*_env, releaseThreads); }; @@ -111,12 +112,12 @@ namespace android { jni::jint y) { android::UniqueEnv _env = android::AttachEnv(); - static auto javaClass = jni::Class<CustomGeometrySource>::Singleton(*_env); + 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, javaClass, *javaPeer); + auto peer = jni::Cast(*_env, javaClass, javaPeer); return peer.Call(*_env, isCancelled, z, x, y); }; @@ -124,7 +125,7 @@ namespace android { jni::jint z, jni::jint x, jni::jint y, - jni::Object<geojson::FeatureCollection> jFeatures) { + const jni::Object<geojson::FeatureCollection>& jFeatures) { using namespace mbgl::android::geojson; // Convert the jni object @@ -140,36 +141,35 @@ namespace android { source.as<mbgl::style::CustomGeometrySource>()->CustomGeometrySource::invalidateTile(CanonicalTileID(z, x, y)); } - void CustomGeometrySource::invalidateBounds(jni::JNIEnv& env, jni::Object<LatLngBounds> jBounds) { + void CustomGeometrySource::invalidateBounds(jni::JNIEnv& env, const jni::Object<LatLngBounds>& jBounds) { auto bounds = LatLngBounds::getLatLngBounds(env, jBounds); source.as<mbgl::style::CustomGeometrySource>()->CustomGeometrySource::invalidateRegion(bounds); } - jni::Array<jni::Object<geojson::Feature>> CustomGeometrySource::querySourceFeatures(jni::JNIEnv& env, - jni::Array<jni::Object<>> jfilter) { + jni::Local<jni::Array<jni::Object<geojson::Feature>>> CustomGeometrySource::querySourceFeatures(jni::JNIEnv& env, + const jni::Array<jni::Object<>>& jfilter) { using namespace mbgl::android::conversion; using namespace mbgl::android::geojson; std::vector<mbgl::Feature> features; if (rendererFrontend) { - features = rendererFrontend->querySourceFeatures(source.getID(), - { {}, toFilter(env, jni::SeizeLocal(env, std::move(jfilter))) }); + features = rendererFrontend->querySourceFeatures(source.getID(), { {}, toFilter(env, jfilter) }); } return Feature::convert(env, features); } - jni::Object<Source> CustomGeometrySource::createJavaPeer(jni::JNIEnv& env) { - static auto javaClass = jni::Class<CustomGeometrySource>::Singleton(env); + jni::Local<jni::Object<Source>> CustomGeometrySource::createJavaPeer(jni::JNIEnv& env) { + 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()); + return javaClass.New(env, constructor, reinterpret_cast<jni::jlong>(this)); } - void CustomGeometrySource::addToMap(JNIEnv& env, jni::Object<Source> obj, mbgl::Map& map, AndroidRendererFrontend& frontend) { + void CustomGeometrySource::addToMap(JNIEnv& env, const jni::Object<Source>& obj, mbgl::Map& map, AndroidRendererFrontend& frontend) { Source::addToMap(env, obj, map, frontend); startThreads(); } - bool CustomGeometrySource::removeFromMap(JNIEnv& env, jni::Object<Source> source, mbgl::Map& map) { + bool CustomGeometrySource::removeFromMap(JNIEnv& env, const jni::Object<Source>& source, mbgl::Map& map) { bool successfullyRemoved = Source::removeFromMap(env, source, map); if (successfullyRemoved) { releaseThreads(); @@ -179,14 +179,14 @@ namespace android { void CustomGeometrySource::registerNative(jni::JNIEnv& env) { // Lookup the class - static auto javaClass = jni::Class<CustomGeometrySource>::Singleton(env); + 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, javaClass, "nativePtr", - std::make_unique<CustomGeometrySource, JNIEnv&, jni::String, jni::Object<>>, + jni::MakePeer<CustomGeometrySource, const jni::String&, const jni::Object<>&>, "initialize", "finalize", METHOD(&CustomGeometrySource::querySourceFeatures, "querySourceFeatures"), |