From 7b3c61f6198cd36b1cc08f26d9a3d8e748a49a99 Mon Sep 17 00:00:00 2001 From: "Thiago Marcos P. Santos" Date: Wed, 13 Apr 2016 19:53:29 +0300 Subject: [PATCH] [android] Do not attach/detach to threads Not needed as everything is now running on the same thread. --- platform/android/src/native_map_view.cpp | 36 ++++-------------------- platform/android/src/native_map_view.hpp | 4 +-- 2 files changed, 7 insertions(+), 33 deletions(-) diff --git a/platform/android/src/native_map_view.cpp b/platform/android/src/native_map_view.cpp index 6b1d4ff32..0607dd1cc 100755 --- a/platform/android/src/native_map_view.cpp +++ b/platform/android/src/native_map_view.cpp @@ -54,14 +54,15 @@ void log_gl_string(GLenum name, const char *label) { } } -NativeMapView::NativeMapView(JNIEnv *env, jobject obj_, float pixelRatio_, int availableProcessors_, size_t totalMemory_) +NativeMapView::NativeMapView(JNIEnv *env_, jobject obj_, float pixelRatio_, int availableProcessors_, size_t totalMemory_) : mbgl::View(*this), + env(env_), pixelRatio(pixelRatio_), availableProcessors(availableProcessors_), totalMemory(totalMemory_) { mbgl::Log::Debug(mbgl::Event::Android, "NativeMapView::NativeMapView"); - assert(env != nullptr); + assert(env_ != nullptr); assert(obj_ != nullptr); if (env->GetJavaVM(&vm) < 0) { @@ -104,16 +105,10 @@ NativeMapView::~NativeMapView() { map.reset(); fileSource.reset(); - jint ret; - JNIEnv *env = nullptr; - ret = vm->GetEnv(reinterpret_cast(&env), JNI_VERSION_1_6); - if (ret == JNI_OK) { - env->DeleteWeakGlobalRef(obj); - } else { - mbgl::Log::Error(mbgl::Event::JNI, "GetEnv() failed with %i", ret); - throw std::runtime_error("GetEnv() failed"); - } + env->DeleteWeakGlobalRef(obj); + obj = nullptr; + env = nullptr; vm = nullptr; } @@ -134,8 +129,6 @@ void NativeMapView::activate() { assert(vm != nullptr); - renderDetach = attach_jni_thread(vm, &renderEnv, "Map Thread"); - if ((display != EGL_NO_DISPLAY) && (surface != EGL_NO_SURFACE) && (context != EGL_NO_CONTEXT)) { if (!eglMakeCurrent(display, surface, surface, context)) { mbgl::Log::Error(mbgl::Event::OpenGL, "eglMakeCurrent() returned error %d", @@ -166,8 +159,6 @@ void NativeMapView::deactivate() { } else { mbgl::Log::Info(mbgl::Event::Android, "Not deactivating as we are not ready"); } - - detach_jni_thread(vm, &renderEnv, renderDetach); } void NativeMapView::invalidate() { @@ -176,15 +167,10 @@ void NativeMapView::invalidate() { assert(vm != nullptr); assert(obj != nullptr); - JNIEnv *env = nullptr; - bool detach = attach_jni_thread(vm, &env, "NativeMapView::invalidate()"); - env->CallVoidMethod(obj, onInvalidateId); if (env->ExceptionCheck()) { env->ExceptionDescribe(); } - - detach_jni_thread(vm, &env, detach); } void NativeMapView::render() { @@ -661,15 +647,10 @@ void NativeMapView::notifyMapChange(mbgl::MapChange change) { assert(vm != nullptr); assert(obj != nullptr); - JNIEnv *env = nullptr; - bool detach = attach_jni_thread(vm, &env, "NativeMapView::notifyMapChange()"); - env->CallVoidMethod(obj, onMapChangedId, change); if (env->ExceptionCheck()) { env->ExceptionDescribe(); } - - detach_jni_thread(vm, &env, detach); } void NativeMapView::enableFps(bool enable) { @@ -703,15 +684,10 @@ void NativeMapView::updateFps() { assert(vm != nullptr); assert(obj != nullptr); - JNIEnv *env = nullptr; - bool detach = attach_jni_thread(vm, &env, "NativeMapView::updateFps()"); - env->CallVoidMethod(obj, onFpsChangedId, fps); if (env->ExceptionCheck()) { env->ExceptionDescribe(); } - - detach_jni_thread(vm, &env, detach); } void NativeMapView::resizeView(int w, int h) { diff --git a/platform/android/src/native_map_view.hpp b/platform/android/src/native_map_view.hpp index b0142adb1..0c29c2fe5 100755 --- a/platform/android/src/native_map_view.hpp +++ b/platform/android/src/native_map_view.hpp @@ -57,6 +57,7 @@ private: private: JavaVM *vm = nullptr; + JNIEnv *env = nullptr; jweak obj = nullptr; ANativeWindow *window = nullptr; @@ -84,9 +85,6 @@ private: int availableProcessors = 0; size_t totalMemory = 0; - jboolean renderDetach = false; - JNIEnv *renderEnv = nullptr; - // Ensure these are initialised last std::unique_ptr fileSource; std::unique_ptr map;