diff options
| author | 2024-02-05 06:07:29 -0500 | |
|---|---|---|
| committer | 2024-02-08 13:45:26 -0500 | |
| commit | e7c4c8b993ce27a50b7a56f90247056048d20f7d (patch) | |
| tree | b87c275f4ea92092f7c8b6cdcb0f50d32819490f /src/common/android/id_cache.h | |
| parent | Merge pull request #12892 from liamwhite/serialization-stuff (diff) | |
| download | yuzu-e7c4c8b993ce27a50b7a56f90247056048d20f7d.tar.gz yuzu-e7c4c8b993ce27a50b7a56f90247056048d20f7d.tar.xz yuzu-e7c4c8b993ce27a50b7a56f90247056048d20f7d.zip | |
android: Move JNI setup and helpers to common
Diffstat (limited to '')
| -rw-r--r-- | src/common/android/id_cache.h (renamed from src/android/app/src/main/jni/id_cache.h) | 26 |
1 files changed, 23 insertions, 3 deletions
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 @@ | |||
| 3 | 3 | ||
| 4 | #pragma once | 4 | #pragma once |
| 5 | 5 | ||
| 6 | #include <future> | ||
| 6 | #include <jni.h> | 7 | #include <jni.h> |
| 7 | 8 | ||
| 8 | #include "video_core/rasterizer_interface.h" | 9 | #include "video_core/rasterizer_interface.h" |
| 9 | 10 | ||
| 10 | namespace IDCache { | 11 | namespace Common::Android { |
| 11 | 12 | ||
| 12 | JNIEnv* GetEnvForThread(); | 13 | JNIEnv* GetEnvForThread(); |
| 14 | |||
| 15 | /** | ||
| 16 | * Starts a new thread to run JNI. Intended to be used when you must run JNI from a fiber. | ||
| 17 | * @tparam T Typename of the return value for the work param | ||
| 18 | * @param work Lambda that runs JNI code. This function will take care of attaching this thread to | ||
| 19 | * the JVM | ||
| 20 | * @return The result from the work lambda param | ||
| 21 | */ | ||
| 22 | template <typename T = void> | ||
| 23 | T RunJNIOnFiber(const std::function<T(JNIEnv*)>& work) { | ||
| 24 | std::future<T> j_result = std::async(std::launch::async, [&] { | ||
| 25 | auto env = GetEnvForThread(); | ||
| 26 | return work(env); | ||
| 27 | }); | ||
| 28 | return j_result.get(); | ||
| 29 | } | ||
| 30 | |||
| 13 | jclass GetNativeLibraryClass(); | 31 | jclass GetNativeLibraryClass(); |
| 32 | |||
| 14 | jclass GetDiskCacheProgressClass(); | 33 | jclass GetDiskCacheProgressClass(); |
| 15 | jclass GetDiskCacheLoadCallbackStageClass(); | 34 | jclass GetDiskCacheLoadCallbackStageClass(); |
| 16 | jclass GetGameDirClass(); | 35 | jclass GetGameDirClass(); |
| 17 | jmethodID GetGameDirConstructor(); | 36 | jmethodID GetGameDirConstructor(); |
| 18 | jmethodID GetExitEmulationActivity(); | ||
| 19 | jmethodID GetDiskCacheLoadProgress(); | 37 | jmethodID GetDiskCacheLoadProgress(); |
| 38 | |||
| 39 | jmethodID GetExitEmulationActivity(); | ||
| 20 | jmethodID GetOnEmulationStarted(); | 40 | jmethodID GetOnEmulationStarted(); |
| 21 | jmethodID GetOnEmulationStopped(); | 41 | jmethodID GetOnEmulationStopped(); |
| 22 | jmethodID GetOnProgramChanged(); | 42 | jmethodID GetOnProgramChanged(); |
| @@ -65,4 +85,4 @@ jclass GetBooleanClass(); | |||
| 65 | jmethodID GetBooleanConstructor(); | 85 | jmethodID GetBooleanConstructor(); |
| 66 | jfieldID GetBooleanValueField(); | 86 | jfieldID GetBooleanValueField(); |
| 67 | 87 | ||
| 68 | } // namespace IDCache | 88 | } // namespace Common::Android |