From 4979220cf0103d81023c32498870ecfd35ef473b Mon Sep 17 00:00:00 2001 From: zackhow Date: Mon, 21 Jan 2019 19:11:11 -0500 Subject: [PATCH] Android: Optimize rumble call Moved rumble call to IDCache since GetMethodID is expensive --- Source/Android/jni/AndroidCommon/IDCache.cpp | 10 +++++++++- Source/Android/jni/AndroidCommon/IDCache.h | 1 + .../ControllerInterface/Android/Android.cpp | 4 +--- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/Source/Android/jni/AndroidCommon/IDCache.cpp b/Source/Android/jni/AndroidCommon/IDCache.cpp index 9841506fab..71e2ae9d59 100644 --- a/Source/Android/jni/AndroidCommon/IDCache.cpp +++ b/Source/Android/jni/AndroidCommon/IDCache.cpp @@ -25,6 +25,8 @@ static jclass s_analytics_class; static jmethodID s_send_analytics_report; static jmethodID s_get_analytics_value; +static jmethodID s_do_rumble; + namespace IDCache { JavaVM* GetJavaVM() @@ -86,6 +88,11 @@ jfieldID GetGameFileCachePointer() return s_game_file_cache_pointer; } +jmethodID GetDoRumble() +{ + return s_do_rumble; +} + } // namespace IDCache #ifdef __cplusplus @@ -104,8 +111,9 @@ jint JNI_OnLoad(JavaVM* vm, void* reserved) s_native_library_class = reinterpret_cast(env->NewGlobalRef(native_library_class)); s_display_alert_msg = env->GetStaticMethodID(s_native_library_class, "displayAlertMsg", "(Ljava/lang/String;Ljava/lang/String;Z)Z"); + s_do_rumble = env->GetStaticMethodID(s_native_library_class, "rumble", "(ID)V"); s_get_update_touch_pointer = - env->GetStaticMethodID(IDCache::GetNativeLibraryClass(), "updateTouchPointer", "()V"); + env->GetStaticMethodID(s_native_library_class, "updateTouchPointer", "()V"); const jclass game_file_class = env->FindClass("org/dolphinemu/dolphinemu/model/GameFile"); s_game_file_class = reinterpret_cast(env->NewGlobalRef(game_file_class)); diff --git a/Source/Android/jni/AndroidCommon/IDCache.h b/Source/Android/jni/AndroidCommon/IDCache.h index 26262ac8d7..0e71a6ca7a 100644 --- a/Source/Android/jni/AndroidCommon/IDCache.h +++ b/Source/Android/jni/AndroidCommon/IDCache.h @@ -14,6 +14,7 @@ JavaVM* GetJavaVM(); jclass GetNativeLibraryClass(); jmethodID GetDisplayAlertMsg(); +jmethodID GetDoRumble(); jmethodID GetUpdateTouchPointer(); jclass GetAnalyticsClass(); diff --git a/Source/Core/InputCommon/ControllerInterface/Android/Android.cpp b/Source/Core/InputCommon/ControllerInterface/Android/Android.cpp index 768bdef89c..44dcbf234a 100644 --- a/Source/Core/InputCommon/ControllerInterface/Android/Android.cpp +++ b/Source/Core/InputCommon/ControllerInterface/Android/Android.cpp @@ -239,9 +239,7 @@ void Touchscreen::Motor::Rumble(int padID, double state) { JNIEnv* env; IDCache::GetJavaVM()->AttachCurrentThread(&env, nullptr); - jmethodID rumbleMethod = - env->GetStaticMethodID(IDCache::GetNativeLibraryClass(), "rumble", "(ID)V"); - env->CallStaticVoidMethod(IDCache::GetNativeLibraryClass(), rumbleMethod, padID, state); + env->CallStaticVoidMethod(IDCache::GetNativeLibraryClass(), IDCache::GetDoRumble(), padID, state); IDCache::GetJavaVM()->DetachCurrentThread(); } }