diff options
| author | Léo Lam <leo@leolam.fr> | 2021-09-22 11:07:19 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-09-22 11:07:19 +0200 |
| commit | 0d8ad5f53a213bd8fb9a201eff42e73e80b540dd (patch) | |
| tree | 88959d7775374194491830a530fc35e668856010 /Source/Android/jni/MainAndroid.cpp | |
| parent | cc84799c7f61eb7081d6393ee1c66bbda77f79c7 (diff) | |
| parent | 53d7d595e694eab21eae2e44f988242063518598 (diff) | |
Merge pull request #10008 from JosJuice/android-remove-emulationstate
Android: Remove the EmulationState class
Diffstat (limited to 'Source/Android/jni/MainAndroid.cpp')
| -rw-r--r-- | Source/Android/jni/MainAndroid.cpp | 43 |
1 files changed, 41 insertions, 2 deletions
diff --git a/Source/Android/jni/MainAndroid.cpp b/Source/Android/jni/MainAndroid.cpp index 765bab1bcb..53a87da1bc 100644 --- a/Source/Android/jni/MainAndroid.cpp +++ b/Source/Android/jni/MainAndroid.cpp @@ -23,6 +23,7 @@ #include "Common/CommonTypes.h" #include "Common/Event.h" #include "Common/FileUtil.h" +#include "Common/Flag.h" #include "Common/IniFile.h" #include "Common/Logging/LogManager.h" #include "Common/MsgHandler.h" @@ -81,6 +82,7 @@ Common::Event s_update_main_frame_event; std::mutex s_surface_lock; bool s_need_nonblocking_alert_msg; +Common::Flag s_is_booting; bool s_have_wm_user_stop = false; bool s_game_metadata_is_valid = false; } // Anonymous namespace @@ -247,9 +249,14 @@ JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_StopEmulatio s_update_main_frame_event.Set(); } +JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_SetIsBooting(JNIEnv*, jclass) +{ + s_is_booting.Set(); +} + JNIEXPORT jboolean JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_IsRunning(JNIEnv*, jclass) { - return static_cast<jboolean>(Core::IsRunning()); + return s_is_booting.IsSet() || static_cast<jboolean>(Core::IsRunning()); } JNIEXPORT jboolean JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_IsRunningAndStarted(JNIEnv*, @@ -258,6 +265,12 @@ JNIEXPORT jboolean JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_IsRunnin return static_cast<jboolean>(Core::IsRunningAndStarted()); } +JNIEXPORT jboolean JNICALL +Java_org_dolphinemu_dolphinemu_NativeLibrary_IsRunningAndUnpaused(JNIEnv*, jclass) +{ + return static_cast<jboolean>(Core::GetState() == Core::State::Running); +} + JNIEXPORT jboolean JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_onGamePadEvent( JNIEnv* env, jclass, jstring jDevice, jint Button, jint Action) { @@ -430,7 +443,25 @@ JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_SurfaceChang JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_SurfaceDestroyed(JNIEnv*, jclass) { - std::lock_guard<std::mutex> guard(s_surface_lock); + { + // If emulation continues running without a valid surface, we will probably crash, + // so pause emulation until we get a valid surface again. EmulationFragment handles resuming. + + std::unique_lock host_identity_guard(s_host_identity_lock); + + while (s_is_booting.IsSet()) + { + // Need to wait for boot to finish before we can pause + host_identity_guard.unlock(); + std::this_thread::sleep_for(std::chrono::milliseconds(1)); + host_identity_guard.lock(); + } + + if (Core::GetState() == Core::State::Running) + Core::SetState(Core::State::Paused); + } + + std::lock_guard surface_guard(s_surface_lock); if (g_renderer) g_renderer->ChangeSurface(nullptr); @@ -442,6 +473,13 @@ JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_SurfaceDestr } } +JNIEXPORT jboolean JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_HasSurface(JNIEnv*, jclass) +{ + std::lock_guard guard(s_surface_lock); + + return s_surf ? JNI_TRUE : JNI_FALSE; +} + JNIEXPORT jfloat JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_GetGameAspectRatio(JNIEnv*, jclass) { @@ -554,6 +592,7 @@ static void Run(JNIEnv* env, const std::vector<std::string>& paths, } } + s_is_booting.Clear(); s_need_nonblocking_alert_msg = false; surface_guard.unlock(); |
