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/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/source.cpp')
-rw-r--r-- | platform/android/src/style/sources/source.cpp | 25 |
1 files changed, 13 insertions, 12 deletions
diff --git a/platform/android/src/style/sources/source.cpp b/platform/android/src/style/sources/source.cpp index c7968786ec..e13f55aff1 100644 --- a/platform/android/src/style/sources/source.cpp +++ b/platform/android/src/style/sources/source.cpp @@ -1,5 +1,6 @@ #include "source.hpp" #include "../android_conversion.hpp" +#include "../../attach_env.hpp" #include <jni/jni.hpp> @@ -47,16 +48,16 @@ namespace android { } } - jni::Object<Source> Source::peerForCoreSource(jni::JNIEnv& env, mbgl::style::Source& coreSource, AndroidRendererFrontend& frontend) { + const jni::Object<Source>& Source::peerForCoreSource(jni::JNIEnv& env, mbgl::style::Source& coreSource, AndroidRendererFrontend& frontend) { if (!coreSource.peer.has_value()) { coreSource.peer = createSourcePeer(env, coreSource, frontend); } - return *coreSource.peer.get<std::unique_ptr<Source>>()->javaPeer; + return coreSource.peer.get<std::unique_ptr<Source>>()->javaPeer; } - Source::Source(jni::JNIEnv& env, mbgl::style::Source& coreSource, jni::Object<Source> obj, AndroidRendererFrontend& frontend) + Source::Source(jni::JNIEnv& env, mbgl::style::Source& coreSource, const jni::Object<Source>& obj, AndroidRendererFrontend& frontend) : source(coreSource) - , javaPeer(obj.NewGlobalRef(env)) + , javaPeer(jni::NewGlobal(env, obj)) , rendererFrontend(&frontend) { } @@ -76,23 +77,23 @@ 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& javaClass = jni::Class<Source>::Singleton(*env); static auto nativePtrField = javaClass.GetField<jlong>(*env, "nativePtr"); - javaPeer->Set(*env, nativePtrField, (jlong) 0); + javaPeer.Set(*env, nativePtrField, (jlong) 0); javaPeer.reset(); } } - jni::String Source::getId(jni::JNIEnv& env) { + jni::Local<jni::String> Source::getId(jni::JNIEnv& env) { return jni::Make<jni::String>(env, source.getID()); } - jni::String Source::getAttribution(jni::JNIEnv& env) { + jni::Local<jni::String> Source::getAttribution(jni::JNIEnv& env) { auto attribution = source.getAttribution(); return attribution ? jni::Make<jni::String>(env, attribution.value()) : jni::Make<jni::String>(env,""); } - void Source::addToMap(JNIEnv& env, jni::Object<Source> obj, mbgl::Map& map, AndroidRendererFrontend& frontend) { + void Source::addToMap(JNIEnv& env, const jni::Object<Source>& obj, mbgl::Map& map, AndroidRendererFrontend& frontend) { // Check to see if we own the source first if (!ownedSource) { throw std::runtime_error("Cannot add source twice"); @@ -105,12 +106,12 @@ namespace android { source.peer = std::unique_ptr<Source>(this); // Add strong reference to java source - javaPeer = obj.NewGlobalRef(env); + javaPeer = jni::NewGlobal(env, obj); rendererFrontend = &frontend; } - bool Source::removeFromMap(JNIEnv&, jni::Object<Source>, mbgl::Map& map) { + bool Source::removeFromMap(JNIEnv&, const jni::Object<Source>&, mbgl::Map& map) { // Cannot remove if not attached yet if (ownedSource) { throw std::runtime_error("Cannot remove detached source"); @@ -143,7 +144,7 @@ namespace android { void Source::registerNative(jni::JNIEnv& env) { // Lookup the class - static auto javaClass = jni::Class<Source>::Singleton(env); + static auto& javaClass = jni::Class<Source>::Singleton(env); #define METHOD(MethodPtr, name) jni::MakeNativePeerMethod<decltype(MethodPtr), (MethodPtr)>(name) |