[android] Reuse Java Source objects by holding on to a strong reference in the C++ peer.

This commit is contained in:
Asheem Mamoowala
2017-11-13 16:06:26 -08:00
parent 3067b77c65
commit f06ebcc967
21 changed files with 187 additions and 197 deletions

View File

@@ -30,8 +30,10 @@ namespace android {
) {
}
VectorSource::VectorSource(mbgl::style::VectorSource& coreSource)
: Source(coreSource) {
VectorSource::VectorSource(jni::JNIEnv& env,
mbgl::style::Source& coreSource,
AndroidRendererFrontend& frontend)
: Source(env, coreSource, createJavaPeer(env), frontend) {
}
VectorSource::~VectorSource() = default;
@@ -56,9 +58,9 @@ namespace android {
jni::Class<VectorSource> VectorSource::javaClass;
jni::jobject* VectorSource::createJavaPeer(jni::JNIEnv& env) {
jni::Object<Source> VectorSource::createJavaPeer(jni::JNIEnv& env) {
static auto constructor = VectorSource::javaClass.template GetConstructor<jni::jlong>(env);
return VectorSource::javaClass.New(env, constructor, reinterpret_cast<jni::jlong>(this));
return jni::Object<Source>(VectorSource::javaClass.New(env, constructor, reinterpret_cast<jni::jlong>(this)).Get());
}
void VectorSource::registerNative(jni::JNIEnv& env) {