From 98544d28064de7936b9fd777a2c3fb37de06b74b Mon Sep 17 00:00:00 2001 From: izzy2lost Date: Mon, 2 Mar 2026 02:46:03 -0500 Subject: [PATCH] minor improvements --- android/app/src/main/cpp/CMakeLists.txt | 8 +++- .../app/src/main/cpp/xemu_snapshots_stub.c | 41 ++++++++++++++++++- .../java/com/izzy2lost/x1box/MainActivity.kt | 6 +++ 3 files changed, 52 insertions(+), 3 deletions(-) diff --git a/android/app/src/main/cpp/CMakeLists.txt b/android/app/src/main/cpp/CMakeLists.txt index 8c70eb21a3..910b5754e8 100644 --- a/android/app/src/main/cpp/CMakeLists.txt +++ b/android/app/src/main/cpp/CMakeLists.txt @@ -844,7 +844,7 @@ target_compile_definitions(xemu_core PRIVATE target_compile_options(xemu_core PRIVATE -g0 $<$,$,$>:-UNDEBUG> - $<$:-O3 -march=armv8.2-a -ffunction-sections -fdata-sections> + $<$,$>:-O3 -march=armv8.2-a -ffunction-sections -fdata-sections> ) target_include_directories(xemu_core PRIVATE @@ -914,7 +914,11 @@ endif() target_compile_options(xemu PRIVATE -fexceptions -frtti -g0 $<$,$,$>:-UNDEBUG> - $<$:-O3 -march=armv8.2-a -ffunction-sections -fdata-sections> + $<$,$>:-O3 -march=armv8.2-a -ffunction-sections -fdata-sections> +) + +target_link_options(xemu PRIVATE + $<$,$,$>:-Wl,--gc-sections> ) target_include_directories(xemu PRIVATE diff --git a/android/app/src/main/cpp/xemu_snapshots_stub.c b/android/app/src/main/cpp/xemu_snapshots_stub.c index a0914e4d86..aff02f59ff 100644 --- a/android/app/src/main/cpp/xemu_snapshots_stub.c +++ b/android/app/src/main/cpp/xemu_snapshots_stub.c @@ -7,6 +7,7 @@ #include "xemu-xbe.h" #include +#include #include #include #include @@ -21,6 +22,8 @@ const char **g_snapshot_shortcut_index_key_map[] = { NULL }; static bool xemu_snapshots_dirty = true; static GLuint g_snapshot_display_tex = 0; static bool g_snapshot_display_flip = false; +static SDL_atomic_t g_snapshot_pending = { 0 }; +static SDL_atomic_t g_fps_counter_enabled = { 0 }; #define SNAPSHOT_PREVIEW_WIDTH 320 #define SNAPSHOT_PREVIEW_HEIGHT 240 @@ -397,6 +400,20 @@ static struct { .lock = PTHREAD_MUTEX_INITIALIZER, }; +static void set_fps_counter_enabled(bool enabled) +{ + SDL_AtomicSet(&g_fps_counter_enabled, enabled ? 1 : 0); + + if (!enabled) { + pthread_mutex_lock(&g_fps_state.lock); + g_fps_state.window_start_ms = 0; + g_fps_state.last_frame_ms = 0; + g_fps_state.frame_count = 0; + g_fps_state.fps = 0.0f; + pthread_mutex_unlock(&g_fps_state.lock); + } +} + static void update_android_fps_counter(void) { const uint64_t now_ms = (uint64_t)SDL_GetTicks64(); @@ -423,13 +440,20 @@ static void update_android_fps_counter(void) void xemu_android_process_snapshot_request(void) { - update_android_fps_counter(); + if (SDL_AtomicGet(&g_fps_counter_enabled) != 0) { + update_android_fps_counter(); + } + + if (SDL_AtomicGet(&g_snapshot_pending) == 0) { + return; + } if (pthread_mutex_trylock(&g_snap_req.lock) != 0) { return; } if (!g_snap_req.pending) { + SDL_AtomicSet(&g_snapshot_pending, 0); pthread_mutex_unlock(&g_snap_req.lock); return; } @@ -454,6 +478,7 @@ void xemu_android_process_snapshot_request(void) } g_snap_req.pending = false; + SDL_AtomicSet(&g_snapshot_pending, 0); g_snap_req.done = true; pthread_cond_signal(&g_snap_req.cond); pthread_mutex_unlock(&g_snap_req.lock); @@ -466,6 +491,7 @@ static jboolean dispatch_snapshot(JNIEnv *env, jstring jname, SnapOpType type) pthread_mutex_lock(&g_snap_req.lock); g_snap_req.type = type; g_snap_req.pending = true; + SDL_AtomicSet(&g_snapshot_pending, 1); g_snap_req.done = false; strncpy(g_snap_req.name, name, sizeof(g_snap_req.name) - 1); g_snap_req.name[sizeof(g_snap_req.name) - 1] = '\0'; @@ -501,6 +527,10 @@ JNIEXPORT jfloat JNICALL Java_com_izzy2lost_x1box_MainActivity_nativeGetFps( JNIEnv *env, jobject obj) { + if (SDL_AtomicGet(&g_fps_counter_enabled) == 0) { + return 0.0f; + } + float fps = 0.0f; const uint64_t now_ms = (uint64_t)SDL_GetTicks64(); (void)env; @@ -520,3 +550,12 @@ Java_com_izzy2lost_x1box_MainActivity_nativeGetFps( return (jfloat)fps; } + +JNIEXPORT void JNICALL +Java_com_izzy2lost_x1box_MainActivity_nativeSetFpsCounterEnabled( + JNIEnv *env, jobject obj, jboolean enabled) +{ + (void)env; + (void)obj; + set_fps_counter_enabled(enabled == JNI_TRUE); +} diff --git a/android/app/src/main/java/com/izzy2lost/x1box/MainActivity.kt b/android/app/src/main/java/com/izzy2lost/x1box/MainActivity.kt index 84a2b04e55..91b0f00e80 100644 --- a/android/app/src/main/java/com/izzy2lost/x1box/MainActivity.kt +++ b/android/app/src/main/java/com/izzy2lost/x1box/MainActivity.kt @@ -79,6 +79,7 @@ class MainActivity : SDLActivity(), InputManager.InputDeviceListener { startupSnapshotSlot = requestedSlot } showFpsCounter = isFpsCounterEnabled() + nativeSetFpsCounterEnabled(showFpsCounter) setupOnScreenController() if (showFpsCounter) { setupFpsCounter() @@ -179,6 +180,7 @@ class MainActivity : SDLActivity(), InputManager.InputDeviceListener { if (showFpsCounter && fpsCounterView == null) { setupFpsCounter() } + nativeSetFpsCounterEnabled(showFpsCounter) return } @@ -193,6 +195,7 @@ class MainActivity : SDLActivity(), InputManager.InputDeviceListener { } fpsCounterView = null } + nativeSetFpsCounterEnabled(showFpsCounter) } private fun setupFpsCounter() { @@ -285,6 +288,7 @@ class MainActivity : SDLActivity(), InputManager.InputDeviceListener { override fun onPause() { stopFpsUpdates() + nativeSetFpsCounterEnabled(false) super.onPause() } @@ -408,6 +412,7 @@ class MainActivity : SDLActivity(), InputManager.InputDeviceListener { inputManager?.unregisterInputDeviceListener(this) fpsCounterView = null + nativeSetFpsCounterEnabled(false) super.onDestroy() } @@ -484,6 +489,7 @@ class MainActivity : SDLActivity(), InputManager.InputDeviceListener { private external fun nativeSaveSnapshot(name: String): Boolean private external fun nativeLoadSnapshot(name: String): Boolean private external fun nativeGetFps(): Float + private external fun nativeSetFpsCounterEnabled(enabled: Boolean) private fun slotName(slot: Int) = "android_slot_$slot"