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).
This commit is contained in:
JosJuice
2018-06-01 09:36:29 +02:00
parent daee5a4b43
commit 1c027bc148
43 changed files with 976 additions and 1574 deletions

View File

@ -0,0 +1,26 @@
// Copyright 2018 Dolphin Emulator Project
// Licensed under GPLv2+
// Refer to the license.txt file included.
#include "jni/AndroidCommon/AndroidCommon.h"
#include <string>
#include <jni.h>
std::string GetJString(JNIEnv* env, jstring jstr)
{
std::string result = "";
if (!jstr)
return result;
const char* s = env->GetStringUTFChars(jstr, nullptr);
result = s;
env->ReleaseStringUTFChars(jstr, s);
return result;
}
jstring ToJString(JNIEnv* env, const std::string& str)
{
return env->NewStringUTF(str.c_str());
}

View File

@ -0,0 +1,12 @@
// Copyright 2018 Dolphin Emulator Project
// Licensed under GPLv2+
// Refer to the license.txt file included.
#pragma once
#include <string>
#include <jni.h>
std::string GetJString(JNIEnv* env, jstring jstr);
jstring ToJString(JNIEnv* env, const std::string& str);

View File

@ -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 <jni.h>
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<void**>(&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<jclass>(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<jclass>(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, "<init>", "(J)V");
const jclass game_file_cache_class =
env->FindClass("org/dolphinemu/dolphinemu/model/GameFileCache");
s_game_file_cache_class = reinterpret_cast<jclass>(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<void**>(&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

View File

@ -0,0 +1,23 @@
// Copyright 2018 Dolphin Emulator Project
// Licensed under GPLv2+
// Refer to the license.txt file included.
#pragma once
#include <jni.h>
namespace IDCache
{
JavaVM* GetJavaVM();
jclass GetNativeLibraryClass();
jmethodID GetDisplayAlertMsg();
jclass GetGameFileClass();
jfieldID GetGameFilePointer();
jmethodID GetGameFileConstructor();
jclass GetGameFileCacheClass();
jfieldID GetGameFileCachePointer();
} // namespace IDCache

View File

@ -1,4 +1,8 @@
add_library(main SHARED
AndroidCommon/AndroidCommon.cpp
AndroidCommon/IDCache.cpp
GameList/GameFile.cpp
GameList/GameFileCache.cpp
ButtonManager.cpp
MainAndroid.cpp
)

View File

@ -0,0 +1,140 @@
// Copyright 2018 Dolphin Emulator Project
// Licensed under GPLv2+
// Refer to the license.txt file included.
#include "jni/GameList/GameFile.h"
#include <memory>
#include <utility>
#include <vector>
#include <jni.h>
#include "DiscIO/Enums.h"
#include "UICommon/GameFile.h"
#include "jni/AndroidCommon/AndroidCommon.h"
#include "jni/AndroidCommon/IDCache.h"
static std::shared_ptr<const UICommon::GameFile>* GetPointer(JNIEnv* env, jobject obj)
{
return reinterpret_cast<std::shared_ptr<const UICommon::GameFile>*>(
env->GetLongField(obj, IDCache::GetGameFilePointer()));
}
static std::shared_ptr<const UICommon::GameFile>& GetRef(JNIEnv* env, jobject obj)
{
return *GetPointer(env, obj);
}
jobject GameFileToJava(JNIEnv* env, std::shared_ptr<const UICommon::GameFile> game_file)
{
if (!game_file)
return nullptr;
return env->NewObject(
IDCache::GetGameFileClass(), IDCache::GetGameFileConstructor(),
reinterpret_cast<jlong>(new std::shared_ptr<const UICommon::GameFile>(std::move(game_file))));
}
#ifdef __cplusplus
extern "C" {
#endif
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_model_GameFile_finalize(JNIEnv* env,
jobject obj);
JNIEXPORT jint JNICALL Java_org_dolphinemu_dolphinemu_model_GameFile_getPlatform(JNIEnv* env,
jobject obj);
JNIEXPORT jstring JNICALL Java_org_dolphinemu_dolphinemu_model_GameFile_getTitle(JNIEnv* env,
jobject obj);
JNIEXPORT jstring JNICALL Java_org_dolphinemu_dolphinemu_model_GameFile_getDescription(JNIEnv* env,
jobject obj);
JNIEXPORT jstring JNICALL Java_org_dolphinemu_dolphinemu_model_GameFile_getCompany(JNIEnv* env,
jobject obj);
JNIEXPORT jint JNICALL Java_org_dolphinemu_dolphinemu_model_GameFile_getCountry(JNIEnv* env,
jobject obj);
JNIEXPORT jstring JNICALL Java_org_dolphinemu_dolphinemu_model_GameFile_getPath(JNIEnv* env,
jobject obj);
JNIEXPORT jstring JNICALL Java_org_dolphinemu_dolphinemu_model_GameFile_getGameId(JNIEnv* env,
jobject obj);
JNIEXPORT jintArray JNICALL Java_org_dolphinemu_dolphinemu_model_GameFile_getBanner(JNIEnv* env,
jobject obj);
JNIEXPORT jint JNICALL Java_org_dolphinemu_dolphinemu_model_GameFile_getBannerWidth(JNIEnv* env,
jobject obj);
JNIEXPORT jint JNICALL Java_org_dolphinemu_dolphinemu_model_GameFile_getBannerHeight(JNIEnv* env,
jobject obj);
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_model_GameFile_finalize(JNIEnv* env,
jobject obj)
{
delete GetPointer(env, obj);
}
JNIEXPORT jint JNICALL Java_org_dolphinemu_dolphinemu_model_GameFile_getPlatform(JNIEnv* env,
jobject obj)
{
return static_cast<jint>(GetRef(env, obj)->GetPlatform());
}
JNIEXPORT jstring JNICALL Java_org_dolphinemu_dolphinemu_model_GameFile_getTitle(JNIEnv* env,
jobject obj)
{
return ToJString(env, GetRef(env, obj)->GetName());
}
JNIEXPORT jstring JNICALL Java_org_dolphinemu_dolphinemu_model_GameFile_getDescription(JNIEnv* env,
jobject obj)
{
return ToJString(env, GetRef(env, obj)->GetDescription());
}
JNIEXPORT jstring JNICALL Java_org_dolphinemu_dolphinemu_model_GameFile_getCompany(JNIEnv* env,
jobject obj)
{
return ToJString(env, DiscIO::GetCompanyFromID(GetRef(env, obj)->GetMakerID()));
}
JNIEXPORT jint JNICALL Java_org_dolphinemu_dolphinemu_model_GameFile_getCountry(JNIEnv* env,
jobject obj)
{
return static_cast<jint>(GetRef(env, obj)->GetCountry());
}
JNIEXPORT jstring JNICALL Java_org_dolphinemu_dolphinemu_model_GameFile_getPath(JNIEnv* env,
jobject obj)
{
return ToJString(env, GetRef(env, obj)->GetFilePath());
}
JNIEXPORT jstring JNICALL Java_org_dolphinemu_dolphinemu_model_GameFile_getGameId(JNIEnv* env,
jobject obj)
{
return ToJString(env, GetRef(env, obj)->GetGameID());
}
JNIEXPORT jintArray JNICALL Java_org_dolphinemu_dolphinemu_model_GameFile_getBanner(JNIEnv* env,
jobject obj)
{
const std::vector<u32>& buffer = GetRef(env, obj)->GetBannerImage().buffer;
const jsize size = static_cast<jsize>(buffer.size());
const jintArray out_array = env->NewIntArray(size);
if (!out_array)
return nullptr;
env->SetIntArrayRegion(out_array, 0, size, reinterpret_cast<const jint*>(buffer.data()));
return out_array;
}
JNIEXPORT jint JNICALL Java_org_dolphinemu_dolphinemu_model_GameFile_getBannerWidth(JNIEnv* env,
jobject obj)
{
return static_cast<jint>(GetRef(env, obj)->GetBannerImage().width);
}
JNIEXPORT jint JNICALL Java_org_dolphinemu_dolphinemu_model_GameFile_getBannerHeight(JNIEnv* env,
jobject obj)
{
return static_cast<jint>(GetRef(env, obj)->GetBannerImage().height);
}
#ifdef __cplusplus
}
#endif

View File

@ -0,0 +1,17 @@
// Copyright 2018 Dolphin Emulator Project
// Licensed under GPLv2+
// Refer to the license.txt file included.
#pragma once
#include <memory>
#include <string>
#include <jni.h>
namespace UICommon
{
class GameFile;
}
jobject GameFileToJava(JNIEnv* env, std::shared_ptr<const UICommon::GameFile> game_file);

View File

@ -0,0 +1,121 @@
// Copyright 2018 Dolphin Emulator Project
// Licensed under GPLv2+
// Refer to the license.txt file included.
#include <memory>
#include <vector>
#include <jni.h>
#include "UICommon/GameFileCache.h"
#include "jni/AndroidCommon/AndroidCommon.h"
#include "jni/AndroidCommon/IDCache.h"
#include "jni/GameList/GameFile.h"
namespace UICommon
{
class GameFile;
}
static UICommon::GameFileCache* GetPointer(JNIEnv* env, jobject obj)
{
return reinterpret_cast<UICommon::GameFileCache*>(
env->GetLongField(obj, IDCache::GetGameFileCachePointer()));
}
#ifdef __cplusplus
extern "C" {
#endif
JNIEXPORT jlong JNICALL Java_org_dolphinemu_dolphinemu_model_GameFileCache_newGameFileCache(
JNIEnv* env, jobject obj, jstring path);
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_model_GameFileCache_finalize(JNIEnv* env,
jobject obj);
JNIEXPORT jobjectArray JNICALL
Java_org_dolphinemu_dolphinemu_model_GameFileCache_getAllGames(JNIEnv* env, jobject obj);
JNIEXPORT jobject JNICALL Java_org_dolphinemu_dolphinemu_model_GameFileCache_addOrGet(JNIEnv* env,
jobject obj,
jstring path);
JNIEXPORT jboolean JNICALL Java_org_dolphinemu_dolphinemu_model_GameFileCache_update(
JNIEnv* env, jobject obj, jobjectArray folder_paths);
JNIEXPORT jboolean JNICALL
Java_org_dolphinemu_dolphinemu_model_GameFileCache_updateAdditionalMetadata(JNIEnv* env,
jobject obj);
JNIEXPORT jboolean JNICALL Java_org_dolphinemu_dolphinemu_model_GameFileCache_load(JNIEnv* env,
jobject obj);
JNIEXPORT jboolean JNICALL Java_org_dolphinemu_dolphinemu_model_GameFileCache_save(JNIEnv* env,
jobject obj);
JNIEXPORT jlong JNICALL Java_org_dolphinemu_dolphinemu_model_GameFileCache_newGameFileCache(
JNIEnv* env, jobject obj, jstring path)
{
return reinterpret_cast<jlong>(new UICommon::GameFileCache(GetJString(env, path)));
}
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_model_GameFileCache_finalize(JNIEnv* env,
jobject obj)
{
delete GetPointer(env, obj);
}
JNIEXPORT jobjectArray JNICALL
Java_org_dolphinemu_dolphinemu_model_GameFileCache_getAllGames(JNIEnv* env, jobject obj)
{
const UICommon::GameFileCache* ptr = GetPointer(env, obj);
const jobjectArray array =
env->NewObjectArray(static_cast<jsize>(ptr->GetSize()), IDCache::GetGameFileClass(), nullptr);
jsize i = 0;
GetPointer(env, obj)->ForEach([env, array, &i](const auto& game_file) {
env->SetObjectArrayElement(array, i++, GameFileToJava(env, game_file));
});
return array;
}
JNIEXPORT jobject JNICALL Java_org_dolphinemu_dolphinemu_model_GameFileCache_addOrGet(JNIEnv* env,
jobject obj,
jstring path)
{
bool cache_changed = false;
return GameFileToJava(env, GetPointer(env, obj)->AddOrGet(GetJString(env, path), &cache_changed));
}
JNIEXPORT jboolean JNICALL Java_org_dolphinemu_dolphinemu_model_GameFileCache_update(
JNIEnv* env, jobject obj, jobjectArray folder_paths)
{
jsize size = env->GetArrayLength(folder_paths);
std::vector<std::string> folder_paths_vector;
folder_paths_vector.reserve(size);
for (jsize i = 0; i < size; ++i)
{
const jstring path = reinterpret_cast<jstring>(env->GetObjectArrayElement(folder_paths, i));
folder_paths_vector.push_back(GetJString(env, path));
env->DeleteLocalRef(path);
}
return GetPointer(env, obj)->Update(UICommon::FindAllGamePaths(folder_paths_vector, false));
}
JNIEXPORT jboolean JNICALL
Java_org_dolphinemu_dolphinemu_model_GameFileCache_updateAdditionalMetadata(JNIEnv* env,
jobject obj)
{
return GetPointer(env, obj)->UpdateAdditionalMetadata();
}
JNIEXPORT jboolean JNICALL Java_org_dolphinemu_dolphinemu_model_GameFileCache_load(JNIEnv* env,
jobject obj)
{
return GetPointer(env, obj)->Load();
}
JNIEXPORT jboolean JNICALL Java_org_dolphinemu_dolphinemu_model_GameFileCache_save(JNIEnv* env,
jobject obj)
{
return GetPointer(env, obj)->Save();
}
#ifdef __cplusplus
}
#endif

View File

@ -16,8 +16,6 @@
#include <thread>
#include <utility>
#include "ButtonManager.h"
#include "Common/CPUDetect.h"
#include "Common/CommonPaths.h"
#include "Common/CommonTypes.h"
@ -51,16 +49,15 @@
#include "VideoCommon/RenderBase.h"
#include "VideoCommon/VideoBackendBase.h"
#define DOLPHIN_TAG "DolphinEmuNative"
JavaVM* g_java_vm;
#include "jni/AndroidCommon/AndroidCommon.h"
#include "jni/AndroidCommon/IDCache.h"
#include "jni/ButtonManager.h"
namespace
{
ANativeWindow* s_surf;
static constexpr char DOLPHIN_TAG[] = "DolphinEmuNative";
jclass s_jni_class;
jmethodID s_jni_method_alert;
ANativeWindow* s_surf;
// The Core only supports using a single Host thread.
// If multiple threads want to call host functions then they need to queue
@ -70,16 +67,6 @@ Common::Event s_update_main_frame_event;
bool s_have_wm_user_stop = false;
} // Anonymous namespace
/*
* Cache the JavaVM so that we can call into it later.
*/
jint JNI_OnLoad(JavaVM* vm, void* reserved)
{
g_java_vm = vm;
return JNI_VERSION_1_6;
}
void Host_NotifyMapLoaded()
{
}
@ -156,229 +143,19 @@ static bool MsgAlert(const char* caption, const char* text, bool yes_no, MsgType
// Associate the current Thread with the Java VM.
JNIEnv* env;
g_java_vm->AttachCurrentThread(&env, NULL);
IDCache::GetJavaVM()->AttachCurrentThread(&env, nullptr);
// Execute the Java method.
jboolean result =
env->CallStaticBooleanMethod(s_jni_class, s_jni_method_alert, env->NewStringUTF(caption),
env->NewStringUTF(text), yes_no ? JNI_TRUE : JNI_FALSE);
jboolean result = env->CallStaticBooleanMethod(
IDCache::GetNativeLibraryClass(), IDCache::GetDisplayAlertMsg(), ToJString(env, caption),
ToJString(env, text), yes_no ? JNI_TRUE : JNI_FALSE);
// Must be called before the current thread exits; might as well do it here.
g_java_vm->DetachCurrentThread();
IDCache::GetJavaVM()->DetachCurrentThread();
return result != JNI_FALSE;
}
#define DVD_BANNER_WIDTH 96
#define DVD_BANNER_HEIGHT 32
static inline u32 Average32(u32 a, u32 b)
{
return ((a >> 1) & 0x7f7f7f7f) + ((b >> 1) & 0x7f7f7f7f);
}
static inline u32 GetPixel(u32* buffer, unsigned int x, unsigned int y)
{
// thanks to unsignedness, these also check for <0 automatically.
if (x > 191)
return 0;
if (y > 63)
return 0;
return buffer[y * 192 + x];
}
static bool LoadBanner(std::string filename, u32* Banner)
{
std::unique_ptr<DiscIO::Volume> pVolume(DiscIO::CreateVolumeFromFilename(filename));
if (pVolume != nullptr)
{
u32 Width, Height;
std::vector<u32> BannerVec = pVolume->GetBanner(&Width, &Height);
// This code (along with above inlines) is moved from
// elsewhere. Someone who knows anything about Android
// please get rid of it and use proper high-resolution
// images.
if (Height == 64 && Width == 192)
{
u32* Buffer = &BannerVec[0];
for (int y = 0; y < 32; y++)
{
for (int x = 0; x < 96; x++)
{
// simplified plus-shaped "gaussian"
u32 surround = Average32(
Average32(GetPixel(Buffer, x * 2 - 1, y * 2), GetPixel(Buffer, x * 2 + 1, y * 2)),
Average32(GetPixel(Buffer, x * 2, y * 2 - 1), GetPixel(Buffer, x * 2, y * 2 + 1)));
Banner[y * 96 + x] = Average32(GetPixel(Buffer, x * 2, y * 2), surround);
}
}
return true;
}
else if (Height == 32 && Width == 96)
{
memcpy(Banner, &BannerVec[0], 96 * 32 * 4);
return true;
}
}
return false;
}
static int GetCountry(std::string filename)
{
std::unique_ptr<DiscIO::Volume> pVolume(DiscIO::CreateVolumeFromFilename(filename));
if (pVolume != nullptr)
{
int country = static_cast<int>(pVolume->GetCountry());
__android_log_print(ANDROID_LOG_INFO, DOLPHIN_TAG, "Country Code: %i", country);
return country;
}
return static_cast<int>(DiscIO::Country::Unknown);
}
static int GetPlatform(std::string filename)
{
std::unique_ptr<DiscIO::Volume> pVolume(DiscIO::CreateVolumeFromFilename(filename));
if (pVolume != nullptr)
{
switch (pVolume->GetVolumeType())
{
case DiscIO::Platform::GameCubeDisc:
__android_log_print(ANDROID_LOG_INFO, DOLPHIN_TAG, "Volume is a GameCube disc.");
return 0;
case DiscIO::Platform::WiiDisc:
__android_log_print(ANDROID_LOG_INFO, DOLPHIN_TAG, "Volume is a Wii disc.");
return 1;
case DiscIO::Platform::WiiWAD:
__android_log_print(ANDROID_LOG_INFO, DOLPHIN_TAG, "Volume is a Wii WAD.");
return 2;
}
}
return -1;
}
static std::string GetTitle(std::string filename)
{
__android_log_print(ANDROID_LOG_WARN, DOLPHIN_TAG, "Getting Title for file: %s",
filename.c_str());
std::unique_ptr<DiscIO::Volume> pVolume(DiscIO::CreateVolumeFromFilename(filename));
if (pVolume != nullptr)
{
std::map<DiscIO::Language, std::string> titles = pVolume->GetLongNames();
if (titles.empty())
titles = pVolume->GetShortNames();
auto end = titles.end();
// English tends to be a good fallback when the requested language isn't available
// if (language != DiscIO::Language::English) {
auto it = titles.find(DiscIO::Language::English);
if (it != end)
return it->second;
//}
// If English isn't available either, just pick something
if (!titles.empty())
return titles.cbegin()->second;
// No usable name, return filename (better than nothing)
std::string name;
SplitPath(filename, nullptr, &name, nullptr);
return name;
}
return std::string("");
}
static std::string GetDescription(std::string filename)
{
__android_log_print(ANDROID_LOG_WARN, DOLPHIN_TAG, "Getting Description for file: %s",
filename.c_str());
std::unique_ptr<DiscIO::Volume> volume(DiscIO::CreateVolumeFromFilename(filename));
if (volume != nullptr)
{
std::map<DiscIO::Language, std::string> descriptions = volume->GetDescriptions();
auto end = descriptions.end();
// English tends to be a good fallback when the requested language isn't available
// if (language != DiscIO::Language::English) {
auto it = descriptions.find(DiscIO::Language::English);
if (it != end)
return it->second;
//}
// If English isn't available either, just pick something
if (!descriptions.empty())
return descriptions.cbegin()->second;
}
return std::string();
}
static std::string GetGameId(std::string filename)
{
__android_log_print(ANDROID_LOG_WARN, DOLPHIN_TAG, "Getting ID for file: %s", filename.c_str());
std::unique_ptr<DiscIO::Volume> volume(DiscIO::CreateVolumeFromFilename(filename));
if (volume == nullptr)
return std::string();
std::string id = volume->GetGameID();
__android_log_print(ANDROID_LOG_INFO, DOLPHIN_TAG, "Game ID: %s", id.c_str());
return id;
}
static std::string GetCompany(std::string filename)
{
__android_log_print(ANDROID_LOG_WARN, DOLPHIN_TAG, "Getting Company for file: %s",
filename.c_str());
std::unique_ptr<DiscIO::Volume> volume(DiscIO::CreateVolumeFromFilename(filename));
if (volume == nullptr)
return std::string();
std::string company = DiscIO::GetCompanyFromID(volume->GetMakerID());
__android_log_print(ANDROID_LOG_INFO, DOLPHIN_TAG, "Company: %s", company.c_str());
return company;
}
static u64 GetFileSize(std::string filename)
{
__android_log_print(ANDROID_LOG_WARN, DOLPHIN_TAG, "Getting size of file: %s", filename.c_str());
std::unique_ptr<DiscIO::Volume> volume(DiscIO::CreateVolumeFromFilename(filename));
if (volume == nullptr)
return -1;
u64 size = volume->GetSize();
__android_log_print(ANDROID_LOG_INFO, DOLPHIN_TAG, "Size: %" PRIu64, size);
return size;
}
static std::string GetJString(JNIEnv* env, jstring jstr)
{
std::string result = "";
if (!jstr)
return result;
const char* s = env->GetStringUTFChars(jstr, nullptr);
result = s;
env->ReleaseStringUTFChars(jstr, s);
return result;
}
#ifdef __cplusplus
extern "C" {
#endif
@ -395,28 +172,6 @@ JNIEXPORT jboolean JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_onGamePa
JNIEnv* env, jobject obj, jstring jDevice, jint Button, jint Action);
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_onGamePadMoveEvent(
JNIEnv* env, jobject obj, jstring jDevice, jint Axis, jfloat Value);
JNIEXPORT jintArray JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_GetBanner(JNIEnv* env,
jobject obj,
jstring jFile);
JNIEXPORT jstring JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_GetTitle(JNIEnv* env,
jobject obj,
jstring jFilename);
JNIEXPORT jstring JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_GetDescription(
JNIEnv* env, jobject obj, jstring jFilename);
JNIEXPORT jstring JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_GetGameId(JNIEnv* env,
jobject obj,
jstring jFilename);
JNIEXPORT jint JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_GetCountry(JNIEnv* env,
jobject obj,
jstring jFilename);
JNIEXPORT jstring JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_GetCompany(
JNIEnv* env, jobject obj, jstring jFilename);
JNIEXPORT jlong JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_GetFilesize(JNIEnv* env,
jobject obj,
jstring jFilename);
JNIEXPORT jint JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_GetPlatform(JNIEnv* env,
jobject obj,
jstring jFilename);
JNIEXPORT jstring JNICALL
Java_org_dolphinemu_dolphinemu_NativeLibrary_GetVersionString(JNIEnv* env, jobject obj);
JNIEXPORT jstring JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_GetGitRevision(JNIEnv* env,
@ -461,8 +216,6 @@ JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_SetProfiling
jboolean enable);
JNIEXPORT void JNICALL
Java_org_dolphinemu_dolphinemu_NativeLibrary_WriteProfileResults(JNIEnv* env, jobject obj);
JNIEXPORT void JNICALL
Java_org_dolphinemu_dolphinemu_NativeLibrary_CacheClassesAndMethods(JNIEnv* env, jobject obj);
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_Run__Ljava_lang_String_2(
JNIEnv* env, jobject obj, jstring jFile);
JNIEXPORT void JNICALL
@ -518,93 +271,16 @@ JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_onGamePadMov
ButtonManager::GamepadAxisEvent(GetJString(env, jDevice), Axis, Value);
}
JNIEXPORT jintArray JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_GetBanner(JNIEnv* env,
jobject obj,
jstring jFile)
{
std::string file = GetJString(env, jFile);
u32 uBanner[DVD_BANNER_WIDTH * DVD_BANNER_HEIGHT];
jintArray Banner = env->NewIntArray(DVD_BANNER_WIDTH * DVD_BANNER_HEIGHT);
if (LoadBanner(file, uBanner))
{
env->SetIntArrayRegion(Banner, 0, DVD_BANNER_WIDTH * DVD_BANNER_HEIGHT, (jint*)uBanner);
}
return Banner;
}
JNIEXPORT jstring JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_GetTitle(JNIEnv* env,
jobject obj,
jstring jFilename)
{
std::string filename = GetJString(env, jFilename);
std::string name = GetTitle(filename);
return env->NewStringUTF(name.c_str());
}
JNIEXPORT jstring JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_GetDescription(
JNIEnv* env, jobject obj, jstring jFilename)
{
std::string filename = GetJString(env, jFilename);
std::string description = GetDescription(filename);
return env->NewStringUTF(description.c_str());
}
JNIEXPORT jstring JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_GetGameId(JNIEnv* env,
jobject obj,
jstring jFilename)
{
std::string filename = GetJString(env, jFilename);
std::string id = GetGameId(filename);
return env->NewStringUTF(id.c_str());
}
JNIEXPORT jstring JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_GetCompany(JNIEnv* env,
jobject obj,
jstring jFilename)
{
std::string filename = GetJString(env, jFilename);
std::string company = GetCompany(filename);
return env->NewStringUTF(company.c_str());
}
JNIEXPORT jint JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_GetCountry(JNIEnv* env,
jobject obj,
jstring jFilename)
{
std::string filename = GetJString(env, jFilename);
int country = GetCountry(filename);
return country;
}
JNIEXPORT jlong JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_GetFilesize(JNIEnv* env,
jobject obj,
jstring jFilename)
{
std::string filename = GetJString(env, jFilename);
u64 size = GetFileSize(filename);
return size;
}
JNIEXPORT jint JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_GetPlatform(JNIEnv* env,
jobject obj,
jstring jFilename)
{
std::string filename = GetJString(env, jFilename);
int platform = GetPlatform(filename);
return platform;
}
JNIEXPORT jstring JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_GetVersionString(JNIEnv* env,
jobject obj)
{
return env->NewStringUTF(Common::scm_rev_str.c_str());
return ToJString(env, Common::scm_rev_str.c_str());
}
JNIEXPORT jstring JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_GetGitRevision(JNIEnv* env,
jobject obj)
{
return env->NewStringUTF(Common::scm_rev_git_str.c_str());
return ToJString(env, Common::scm_rev_git_str.c_str());
}
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_SaveScreenShot(JNIEnv* env,
@ -646,7 +322,7 @@ JNIEXPORT jstring JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_GetUserSe
ini.GetOrCreateSection(section)->Get(key, &value, "-1");
return env->NewStringUTF(value.c_str());
return ToJString(env, value.c_str());
}
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_SetUserSetting(
@ -686,8 +362,9 @@ JNIEXPORT jstring JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_GetConfig
ini.GetOrCreateSection(section)->Get(key, &value, defaultValue);
return env->NewStringUTF(value.c_str());
return ToJString(env, value.c_str());
}
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_SetConfig(
JNIEnv* env, jobject obj, jstring jFile, jstring jSection, jstring jKey, jstring jValue)
{
@ -762,7 +439,7 @@ JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_SetUserDirec
JNIEXPORT jstring JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_GetUserDirectory(JNIEnv* env,
jobject obj)
{
return env->NewStringUTF(File::GetUserPath(D_USER_IDX).c_str());
return ToJString(env, File::GetUserPath(D_USER_IDX).c_str());
}
JNIEXPORT jint JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_DefaultCPUCore(JNIEnv* env,
@ -791,25 +468,6 @@ JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_WriteProfile
JitInterface::WriteProfileResults(filename);
}
JNIEXPORT void JNICALL
Java_org_dolphinemu_dolphinemu_NativeLibrary_CacheClassesAndMethods(JNIEnv* env, jobject obj)
{
// This class reference is only valid for the lifetime of this method.
jclass localClass = env->FindClass("org/dolphinemu/dolphinemu/NativeLibrary");
// This reference, however, is valid until we delete it.
s_jni_class = reinterpret_cast<jclass>(env->NewGlobalRef(localClass));
// TODO Find a place for this.
// So we don't leak a reference to NativeLibrary.class.
// env->DeleteGlobalRef(s_jni_class);
// Method signature taken from javap -s
// Source/Android/app/build/intermediates/classes/arm/debug/org/dolphinemu/dolphinemu/NativeLibrary.class
s_jni_method_alert = env->GetStaticMethodID(s_jni_class, "displayAlertMsg",
"(Ljava/lang/String;Ljava/lang/String;Z)Z");
}
// Surface Handling
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_SurfaceChanged(JNIEnv* env,
jobject obj,