summaryrefslogtreecommitdiffstats
path: root/src/common
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/common/CMakeLists.txt8
-rw-r--r--src/common/android/android_common.cpp (renamed from src/android/app/src/main/jni/android_common/android_common.cpp)23
-rw-r--r--src/common/android/android_common.h (renamed from src/android/app/src/main/jni/android_common/android_common.h)4
-rw-r--r--src/common/android/applets/software_keyboard.cpp (renamed from src/android/app/src/main/jni/applets/software_keyboard.cpp)24
-rw-r--r--src/common/android/applets/software_keyboard.h (renamed from src/android/app/src/main/jni/applets/software_keyboard.h)4
-rw-r--r--src/common/android/id_cache.cpp (renamed from src/android/app/src/main/jni/id_cache.cpp)12
-rw-r--r--src/common/android/id_cache.h (renamed from src/android/app/src/main/jni/id_cache.h)26
7 files changed, 68 insertions, 33 deletions
diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt
index 85926fc8f..8ff1326f2 100644
--- a/src/common/CMakeLists.txt
+++ b/src/common/CMakeLists.txt
@@ -179,9 +179,15 @@ endif()
if(ANDROID)
target_sources(common
- PRIVATE
+ PUBLIC
fs/fs_android.cpp
fs/fs_android.h
+ android/android_common.cpp
+ android/android_common.h
+ android/id_cache.cpp
+ android/id_cache.h
+ android/applets/software_keyboard.cpp
+ android/applets/software_keyboard.h
)
endif()
diff --git a/src/android/app/src/main/jni/android_common/android_common.cpp b/src/common/android/android_common.cpp
index 7018a52af..e79005658 100644
--- a/src/android/app/src/main/jni/android_common/android_common.cpp
+++ b/src/common/android/android_common.cpp
@@ -1,15 +1,17 @@
// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
-#include "jni/android_common/android_common.h"
+#include "android_common.h"
#include <string>
#include <string_view>
#include <jni.h>
+#include "common/android/id_cache.h"
#include "common/string_util.h"
-#include "jni/id_cache.h"
+
+namespace Common::Android {
std::string GetJString(JNIEnv* env, jstring jstr) {
if (!jstr) {
@@ -18,7 +20,8 @@ std::string GetJString(JNIEnv* env, jstring jstr) {
const jchar* jchars = env->GetStringChars(jstr, nullptr);
const jsize length = env->GetStringLength(jstr);
- const std::u16string_view string_view(reinterpret_cast<const char16_t*>(jchars), length);
+ const std::u16string_view string_view(reinterpret_cast<const char16_t*>(jchars),
+ static_cast<u32>(length));
const std::string converted_string = Common::UTF16ToUTF8(string_view);
env->ReleaseStringChars(jstr, jchars);
@@ -36,25 +39,27 @@ jstring ToJString(JNIEnv* env, std::u16string_view str) {
}
double GetJDouble(JNIEnv* env, jobject jdouble) {
- return env->GetDoubleField(jdouble, IDCache::GetDoubleValueField());
+ return env->GetDoubleField(jdouble, GetDoubleValueField());
}
jobject ToJDouble(JNIEnv* env, double value) {
- return env->NewObject(IDCache::GetDoubleClass(), IDCache::GetDoubleConstructor(), value);
+ return env->NewObject(GetDoubleClass(), GetDoubleConstructor(), value);
}
s32 GetJInteger(JNIEnv* env, jobject jinteger) {
- return env->GetIntField(jinteger, IDCache::GetIntegerValueField());
+ return env->GetIntField(jinteger, GetIntegerValueField());
}
jobject ToJInteger(JNIEnv* env, s32 value) {
- return env->NewObject(IDCache::GetIntegerClass(), IDCache::GetIntegerConstructor(), value);
+ return env->NewObject(GetIntegerClass(), GetIntegerConstructor(), value);
}
bool GetJBoolean(JNIEnv* env, jobject jboolean) {
- return env->GetBooleanField(jboolean, IDCache::GetBooleanValueField());
+ return env->GetBooleanField(jboolean, GetBooleanValueField());
}
jobject ToJBoolean(JNIEnv* env, bool value) {
- return env->NewObject(IDCache::GetBooleanClass(), IDCache::GetBooleanConstructor(), value);
+ return env->NewObject(GetBooleanClass(), GetBooleanConstructor(), value);
}
+
+} // namespace Common::Android
diff --git a/src/android/app/src/main/jni/android_common/android_common.h b/src/common/android/android_common.h
index 29a338c0a..d0ccb4ec2 100644
--- a/src/android/app/src/main/jni/android_common/android_common.h
+++ b/src/common/android/android_common.h
@@ -8,6 +8,8 @@
#include <jni.h>
#include "common/common_types.h"
+namespace Common::Android {
+
std::string GetJString(JNIEnv* env, jstring jstr);
jstring ToJString(JNIEnv* env, std::string_view str);
jstring ToJString(JNIEnv* env, std::u16string_view str);
@@ -20,3 +22,5 @@ jobject ToJInteger(JNIEnv* env, s32 value);
bool GetJBoolean(JNIEnv* env, jobject jboolean);
jobject ToJBoolean(JNIEnv* env, bool value);
+
+} // namespace Common::Android
diff --git a/src/android/app/src/main/jni/applets/software_keyboard.cpp b/src/common/android/applets/software_keyboard.cpp
index 9943483e8..477e62b16 100644
--- a/src/android/app/src/main/jni/applets/software_keyboard.cpp
+++ b/src/common/android/applets/software_keyboard.cpp
@@ -6,12 +6,12 @@
#include <jni.h>
+#include "common/android/android_common.h"
+#include "common/android/applets/software_keyboard.h"
+#include "common/android/id_cache.h"
#include "common/logging/log.h"
#include "common/string_util.h"
#include "core/core.h"
-#include "jni/android_common/android_common.h"
-#include "jni/applets/software_keyboard.h"
-#include "jni/id_cache.h"
static jclass s_software_keyboard_class;
static jclass s_keyboard_config_class;
@@ -19,10 +19,10 @@ static jclass s_keyboard_data_class;
static jmethodID s_swkbd_execute_normal;
static jmethodID s_swkbd_execute_inline;
-namespace SoftwareKeyboard {
+namespace Common::Android::SoftwareKeyboard {
static jobject ToJKeyboardParams(const Core::Frontend::KeyboardInitializeParameters& config) {
- JNIEnv* env = IDCache::GetEnvForThread();
+ JNIEnv* env = GetEnvForThread();
jobject object = env->AllocObject(s_keyboard_config_class);
env->SetObjectField(object,
@@ -78,7 +78,7 @@ static jobject ToJKeyboardParams(const Core::Frontend::KeyboardInitializeParamet
}
AndroidKeyboard::ResultData AndroidKeyboard::ResultData::CreateFromFrontend(jobject object) {
- JNIEnv* env = IDCache::GetEnvForThread();
+ JNIEnv* env = GetEnvForThread();
const jstring string = reinterpret_cast<jstring>(env->GetObjectField(
object, env->GetFieldID(s_keyboard_data_class, "text", "Ljava/lang/String;")));
return ResultData{GetJString(env, string),
@@ -141,7 +141,7 @@ void AndroidKeyboard::ShowNormalKeyboard() const {
// Pivot to a new thread, as we cannot call GetEnvForThread() from a Fiber.
std::thread([&] {
- data = ResultData::CreateFromFrontend(IDCache::GetEnvForThread()->CallStaticObjectMethod(
+ data = ResultData::CreateFromFrontend(GetEnvForThread()->CallStaticObjectMethod(
s_software_keyboard_class, s_swkbd_execute_normal, ToJKeyboardParams(parameters)));
}).join();
@@ -183,8 +183,8 @@ void AndroidKeyboard::ShowInlineKeyboard(
// Pivot to a new thread, as we cannot call GetEnvForThread() from a Fiber.
m_is_inline_active = true;
std::thread([&] {
- IDCache::GetEnvForThread()->CallStaticVoidMethod(
- s_software_keyboard_class, s_swkbd_execute_inline, ToJKeyboardParams(parameters));
+ GetEnvForThread()->CallStaticVoidMethod(s_software_keyboard_class, s_swkbd_execute_inline,
+ ToJKeyboardParams(parameters));
}).join();
}
@@ -220,7 +220,7 @@ void AndroidKeyboard::SubmitInlineKeyboardText(std::u16string submitted_text) {
m_current_text += submitted_text;
submit_inline_callback(Service::AM::Frontend::SwkbdReplyType::ChangedString, m_current_text,
- m_current_text.size());
+ static_cast<int>(m_current_text.size()));
}
void AndroidKeyboard::SubmitInlineKeyboardInput(int key_code) {
@@ -242,7 +242,7 @@ void AndroidKeyboard::SubmitInlineKeyboardInput(int key_code) {
case KEYCODE_DEL:
m_current_text.pop_back();
submit_inline_callback(Service::AM::Frontend::SwkbdReplyType::ChangedString, m_current_text,
- m_current_text.size());
+ static_cast<int>(m_current_text.size()));
break;
}
}
@@ -274,4 +274,4 @@ void CleanupJNI(JNIEnv* env) {
env->DeleteGlobalRef(s_keyboard_data_class);
}
-} // namespace SoftwareKeyboard
+} // namespace Common::Android::SoftwareKeyboard
diff --git a/src/android/app/src/main/jni/applets/software_keyboard.h b/src/common/android/applets/software_keyboard.h
index 2affc01f6..9fd09d27c 100644
--- a/src/android/app/src/main/jni/applets/software_keyboard.h
+++ b/src/common/android/applets/software_keyboard.h
@@ -7,7 +7,7 @@
#include "core/frontend/applets/software_keyboard.h"
-namespace SoftwareKeyboard {
+namespace Common::Android::SoftwareKeyboard {
class AndroidKeyboard final : public Core::Frontend::SoftwareKeyboardApplet {
public:
@@ -66,7 +66,7 @@ void InitJNI(JNIEnv* env);
// Should be called in JNI_Unload
void CleanupJNI(JNIEnv* env);
-} // namespace SoftwareKeyboard
+} // namespace Common::Android::SoftwareKeyboard
// Native function calls
extern "C" {
diff --git a/src/android/app/src/main/jni/id_cache.cpp b/src/common/android/id_cache.cpp
index f30100bd8..f39262db9 100644
--- a/src/android/app/src/main/jni/id_cache.cpp
+++ b/src/common/android/id_cache.cpp
@@ -3,10 +3,10 @@
#include <jni.h>
+#include "applets/software_keyboard.h"
+#include "common/android/id_cache.h"
#include "common/assert.h"
#include "common/fs/fs_android.h"
-#include "jni/applets/software_keyboard.h"
-#include "jni/id_cache.h"
#include "video_core/rasterizer_interface.h"
static JavaVM* s_java_vm;
@@ -67,7 +67,7 @@ static jfieldID s_boolean_value_field;
static constexpr jint JNI_VERSION = JNI_VERSION_1_6;
-namespace IDCache {
+namespace Common::Android {
JNIEnv* GetEnvForThread() {
thread_local static struct OwnedEnv {
@@ -276,8 +276,6 @@ jfieldID GetBooleanValueField() {
return s_boolean_value_field;
}
-} // namespace IDCache
-
#ifdef __cplusplus
extern "C" {
#endif
@@ -393,7 +391,7 @@ jint JNI_OnLoad(JavaVM* vm, void* reserved) {
Common::FS::Android::RegisterCallbacks(env, s_native_library_class);
// Initialize applets
- SoftwareKeyboard::InitJNI(env);
+ Common::Android::SoftwareKeyboard::InitJNI(env);
return JNI_VERSION;
}
@@ -426,3 +424,5 @@ void JNI_OnUnload(JavaVM* vm, void* reserved) {
#ifdef __cplusplus
}
#endif
+
+} // namespace Common::Android
diff --git a/src/android/app/src/main/jni/id_cache.h b/src/common/android/id_cache.h
index 00e48afc0..47802f96c 100644
--- a/src/android/app/src/main/jni/id_cache.h
+++ b/src/common/android/id_cache.h
@@ -3,20 +3,40 @@
#pragma once
+#include <future>
#include <jni.h>
#include "video_core/rasterizer_interface.h"
-namespace IDCache {
+namespace Common::Android {
JNIEnv* GetEnvForThread();
+
+/**
+ * Starts a new thread to run JNI. Intended to be used when you must run JNI from a fiber.
+ * @tparam T Typename of the return value for the work param
+ * @param work Lambda that runs JNI code. This function will take care of attaching this thread to
+ * the JVM
+ * @return The result from the work lambda param
+ */
+template <typename T = void>
+T RunJNIOnFiber(const std::function<T(JNIEnv*)>& work) {
+ std::future<T> j_result = std::async(std::launch::async, [&] {
+ auto env = GetEnvForThread();
+ return work(env);
+ });
+ return j_result.get();
+}
+
jclass GetNativeLibraryClass();
+
jclass GetDiskCacheProgressClass();
jclass GetDiskCacheLoadCallbackStageClass();
jclass GetGameDirClass();
jmethodID GetGameDirConstructor();
-jmethodID GetExitEmulationActivity();
jmethodID GetDiskCacheLoadProgress();
+
+jmethodID GetExitEmulationActivity();
jmethodID GetOnEmulationStarted();
jmethodID GetOnEmulationStopped();
jmethodID GetOnProgramChanged();
@@ -65,4 +85,4 @@ jclass GetBooleanClass();
jmethodID GetBooleanConstructor();
jfieldID GetBooleanValueField();
-} // namespace IDCache
+} // namespace Common::Android