diff options
| author | JosJuice <josjuice@gmail.com> | 2018-06-01 09:36:29 +0200 |
|---|---|---|
| committer | JosJuice <josjuice@gmail.com> | 2018-06-06 17:34:07 +0200 |
| commit | 1c027bc148574cf0b05cd04f8ce15132e8115170 (patch) | |
| tree | cf7d352f8cc68bc26b37168f86c8314d448903a7 /Source/Android/jni/GameList/GameFile.cpp | |
| parent | daee5a4b43e95f50a1b024348a19d7f2bb48bdbc (diff) | |
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).
Diffstat (limited to 'Source/Android/jni/GameList/GameFile.cpp')
| -rw-r--r-- | Source/Android/jni/GameList/GameFile.cpp | 140 |
1 files changed, 140 insertions, 0 deletions
diff --git a/Source/Android/jni/GameList/GameFile.cpp b/Source/Android/jni/GameList/GameFile.cpp new file mode 100644 index 0000000000..b2cf26cd52 --- /dev/null +++ b/Source/Android/jni/GameList/GameFile.cpp @@ -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
|
