From f968ee6527df84e71543be869210ffb5d30551b5 Mon Sep 17 00:00:00 2001 From: Themaister Date: Sun, 14 Apr 2013 00:53:05 +0200 Subject: [PATCH] Refactor nonblock states. Preserve nonblock state better across reinits, etc. Try to keep vsync in RGUI. --- driver.c | 28 +++++++++++++++++++++++++++- driver.h | 2 ++ frontend/frontend.c | 3 +++ retroarch.c | 26 ++++++-------------------- 4 files changed, 38 insertions(+), 21 deletions(-) diff --git a/driver.c b/driver.c index 3b58ea8216..42a5620e6e 100644 --- a/driver.c +++ b/driver.c @@ -255,7 +255,12 @@ static void adjust_system_rates(void) RARCH_LOG("Set audio input rate to: %.2f Hz.\n", g_settings.audio.in_rate); if (driver.video_data) - video_set_nonblock_state_func(!g_settings.video.vsync || g_extern.system.force_nonblock); + { + if (g_extern.system.force_nonblock) + video_set_nonblock_state_func(true); + else + driver_set_nonblock_state(driver.nonblock_state); + } } void driver_set_monitor_refresh_rate(float hz) @@ -267,7 +272,24 @@ void driver_set_monitor_refresh_rate(float hz) g_extern.audio_data.orig_src_ratio = g_extern.audio_data.src_ratio = (double)g_settings.audio.out_rate / g_settings.audio.in_rate; +} +void driver_set_nonblock_state(bool nonblock) +{ + // Only apply non-block-state for video if we're using vsync. + if (g_extern.video_active) + { + bool video_nb = nonblock; + if (!g_settings.video.vsync || !g_extern.system.force_nonblock) + video_nb = true; + video_set_nonblock_state_func(video_nb); + } + + if (g_extern.audio_active) + audio_set_nonblock_state_func(g_settings.audio.sync ? nonblock : true); + + g_extern.audio_data.chunk_size = nonblock ? + g_extern.audio_data.nonblock_chunk_size : g_extern.audio_data.block_chunk_size; } uintptr_t driver_get_current_framebuffer(void) @@ -347,6 +369,10 @@ void init_drivers(void) g_extern.system.hw_render_callback.context_reset(); init_audio(); + + // Keep non-throttled state as good as possible. + if (driver.nonblock_state) + driver_set_nonblock_state(driver.nonblock_state); } void uninit_drivers(void) diff --git a/driver.h b/driver.h index fd0c69ef7a..39a85d7214 100644 --- a/driver.h +++ b/driver.h @@ -416,6 +416,7 @@ typedef struct driver #endif bool stdin_claimed; bool block_hotkey; + bool nonblock_state; // Opaque handles to currently running window. // Used by e.g. input drivers which bind to a window. @@ -460,6 +461,7 @@ void init_audio(void); void uninit_audio(void); void driver_set_monitor_refresh_rate(float hz); +void driver_set_nonblock_state(bool nonblock); // Used by RETRO_ENVIRONMENT_SET_HW_RENDER. uintptr_t driver_get_current_framebuffer(void); diff --git a/frontend/frontend.c b/frontend/frontend.c index 1cfb3d5e2a..d8756d171d 100644 --- a/frontend/frontend.c +++ b/frontend/frontend.c @@ -83,7 +83,10 @@ int main(int argc, char *argv[]) else if (g_extern.lifecycle_mode_state & (1ULL << MODE_MENU)) { g_extern.lifecycle_mode_state |= 1ULL << MODE_MENU_PREINIT; + // Menu should always run with vsync on. + video_set_nonblock_state_func(false); while (menu_iterate()); + driver_set_nonblock_state(driver.nonblock_state); g_extern.lifecycle_mode_state &= ~(1ULL << MODE_MENU); } else diff --git a/retroarch.c b/retroarch.c index 46d1b95357..5aa4fbb46c 100644 --- a/retroarch.c +++ b/retroarch.c @@ -49,38 +49,24 @@ #define RARCH_PERFORMANCE_MODE #endif -// To avoid continous switching if we hold the button down, we require that the button must go from pressed, unpressed back to pressed to be able to toggle between then. +// To avoid continous switching if we hold the button down, we require that the button must go from pressed, +// unpressed back to pressed to be able to toggle between then. static void check_fast_forward_button(void) { bool new_button_state = input_key_pressed_func(RARCH_FAST_FORWARD_KEY); bool new_hold_button_state = input_key_pressed_func(RARCH_FAST_FORWARD_HOLD_KEY); - bool update_sync = false; static bool old_button_state = false; static bool old_hold_button_state = false; - static bool syncing_state = false; if (new_button_state && !old_button_state) { - syncing_state = !syncing_state; - update_sync = true; + driver.nonblock_state = !driver.nonblock_state; + driver_set_nonblock_state(driver.nonblock_state); } else if (old_hold_button_state != new_hold_button_state) { - syncing_state = new_hold_button_state; - update_sync = true; - } - - if (update_sync) - { - // Only apply non-block-state for video if we're using vsync. - if (g_extern.video_active && g_settings.video.vsync && !g_extern.system.force_nonblock) - video_set_nonblock_state_func(syncing_state); - - if (g_extern.audio_active) - audio_set_nonblock_state_func(g_settings.audio.sync ? syncing_state : true); - - g_extern.audio_data.chunk_size = - syncing_state ? g_extern.audio_data.nonblock_chunk_size : g_extern.audio_data.block_chunk_size; + driver.nonblock_state = new_hold_button_state; + driver_set_nonblock_state(driver.nonblock_state); } old_button_state = new_button_state;