From 1c027bc148574cf0b05cd04f8ce15132e8115170 Mon Sep 17 00:00:00 2001 From: JosJuice Date: Fri, 1 Jun 2018 09:36:29 +0200 Subject: Use UICommon's game list code on Android Deduplicates code, and gets rid of some problems the old code had (such as: bad performance when calling native functions, only one disc showing up for multi-disc games, Wii banners being low-res, unnecessarily much effort being needed for adding more metadata). --- Source/Android/jni/AndroidCommon/IDCache.cpp | 110 +++++++++++++++++++++++++++ 1 file changed, 110 insertions(+) create mode 100644 Source/Android/jni/AndroidCommon/IDCache.cpp (limited to 'Source/Android/jni/AndroidCommon/IDCache.cpp') diff --git a/Source/Android/jni/AndroidCommon/IDCache.cpp b/Source/Android/jni/AndroidCommon/IDCache.cpp new file mode 100644 index 0000000000..2c457d6c9d --- /dev/null +++ b/Source/Android/jni/AndroidCommon/IDCache.cpp @@ -0,0 +1,110 @@ +// Copyright 2018 Dolphin Emulator Project +// Licensed under GPLv2+ +// Refer to the license.txt file included. + +#include "jni/AndroidCommon/IDCache.h" + +#include + +static constexpr jint JNI_VERSION = JNI_VERSION_1_6; + +static JavaVM* s_java_vm; + +static jclass s_native_library_class; +static jmethodID s_display_alert_msg; + +static jclass s_game_file_class; +static jfieldID s_game_file_pointer; +static jmethodID s_game_file_constructor; + +static jclass s_game_file_cache_class; +static jfieldID s_game_file_cache_pointer; + +namespace IDCache +{ +JavaVM* GetJavaVM() +{ + return s_java_vm; +} + +jclass GetNativeLibraryClass() +{ + return s_native_library_class; +} + +jmethodID GetDisplayAlertMsg() +{ + return s_display_alert_msg; +} + +jclass GetGameFileClass() +{ + return s_game_file_class; +} + +jfieldID GetGameFilePointer() +{ + return s_game_file_pointer; +} + +jmethodID GetGameFileConstructor() +{ + return s_game_file_constructor; +} + +jclass GetGameFileCacheClass() +{ + return s_game_file_cache_class; +} + +jfieldID GetGameFileCachePointer() +{ + return s_game_file_cache_pointer; +} + +} // namespace IDCache + +#ifdef __cplusplus +extern "C" { +#endif + +jint JNI_OnLoad(JavaVM* vm, void* reserved) +{ + s_java_vm = vm; + + JNIEnv* env; + if (vm->GetEnv(reinterpret_cast(&env), JNI_VERSION) != JNI_OK) + return JNI_ERR; + + const jclass native_library_class = env->FindClass("org/dolphinemu/dolphinemu/NativeLibrary"); + 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"); + + const jclass game_file_class = env->FindClass("org/dolphinemu/dolphinemu/model/GameFile"); + s_game_file_class = reinterpret_cast(env->NewGlobalRef(game_file_class)); + s_game_file_pointer = env->GetFieldID(game_file_class, "mPointer", "J"); + s_game_file_constructor = env->GetMethodID(game_file_class, "", "(J)V"); + + const jclass game_file_cache_class = + env->FindClass("org/dolphinemu/dolphinemu/model/GameFileCache"); + s_game_file_cache_class = reinterpret_cast(env->NewGlobalRef(game_file_cache_class)); + s_game_file_cache_pointer = env->GetFieldID(game_file_cache_class, "mPointer", "J"); + + return JNI_VERSION; +} + +void JNI_OnUnload(JavaVM* vm, void* reserved) +{ + JNIEnv* env; + if (vm->GetEnv(reinterpret_cast(&env), JNI_VERSION) != JNI_OK) + return; + + env->DeleteGlobalRef(s_native_library_class); + env->DeleteGlobalRef(s_game_file_class); + env->DeleteGlobalRef(s_game_file_cache_class); +} + +#ifdef __cplusplus +} +#endif -- cgit v1.2.3