From e3897c8641a9b6bb5b35e98388d83aee5ca0f8e5 Mon Sep 17 00:00:00 2001 From: twinaphex Date: Sun, 18 Jan 2015 19:01:13 +0100 Subject: [PATCH] Less dependencies on driver.h --- audio/audio_monitor.c | 2 -- driver.c | 23 +++++++++++++++++++++++ driver.h | 10 ++++++++++ gfx/drivers/gx_gfx.c | 9 ++++----- gfx/video_monitor.c | 38 +++++++++++++------------------------- settings_data.c | 5 ++--- 6 files changed, 52 insertions(+), 35 deletions(-) diff --git a/audio/audio_monitor.c b/audio/audio_monitor.c index 5a6cffbda7..2c5977f213 100644 --- a/audio/audio_monitor.c +++ b/audio/audio_monitor.c @@ -15,9 +15,7 @@ */ #include "audio_monitor.h" -#include "../driver.h" #include "../general.h" -#include "../retroarch.h" void audio_monitor_adjust_system_rates(void) { diff --git a/driver.c b/driver.c index 94c4cd7293..a5883179e3 100644 --- a/driver.c +++ b/driver.c @@ -208,6 +208,29 @@ void driver_adjust_system_rates(void) { audio_monitor_adjust_system_rates(); video_monitor_adjust_system_rates(); + + if (!driver.video_data) + return; + + if (g_extern.system.force_nonblock) + rarch_main_command(RARCH_CMD_VIDEO_SET_NONBLOCKING_STATE); + else + driver_set_nonblock_state(driver.nonblock_state); +} + +/** + * driver_set_refresh_rate: + * @hz : New refresh rate for monitor. + * + * Sets monitor refresh rate to new value by calling + * video_monitor_set_refresh_rate(). Subsequently + * calls audio_monitor_set_refresh_rate(). + **/ +void driver_set_refresh_rate(float hz) +{ + video_monitor_set_refresh_rate(hz); + driver_adjust_system_rates(); + audio_monitor_set_refresh_rate(); } /** diff --git a/driver.h b/driver.h index f11a0dfb08..c84385b401 100644 --- a/driver.h +++ b/driver.h @@ -360,6 +360,16 @@ void driver_set_nonblock_state(bool enable); void driver_adjust_system_rates(void); +/** + * driver_set_refresh_rate: + * @hz : New refresh rate for monitor. + * + * Sets monitor refresh rate to new value by calling + * video_monitor_set_refresh_rate(). Subsequently + * calls audio_monitor_set_refresh_rate(). + **/ +void driver_set_refresh_rate(float hz); + /** * driver_get_current_framebuffer: * diff --git a/gfx/drivers/gx_gfx.c b/gfx/drivers/gx_gfx.c index 51fa7f2f4a..86539c0258 100644 --- a/gfx/drivers/gx_gfx.c +++ b/gfx/drivers/gx_gfx.c @@ -20,7 +20,6 @@ #include "../drivers_font_renderer/bitmap.h" #include "../../menu/menu.h" #include "../gfx_common.h" -#include "../video_monitor.h" #ifdef HW_RVL #include "../../wii/mem2_manager.h" @@ -293,16 +292,16 @@ void gx_set_video_mode(void *data, unsigned fbWidth, unsigned lines) if (tvmode == VI_PAL) { if (modetype == VI_NON_INTERLACE) - video_monitor_set_refresh_rate(50.0801f); + driver_set_refresh_rate(50.0801f); else - video_monitor_set_refresh_rate(50.0f); + driver_set_refresh_rate(50.0f); } else { if (modetype == VI_NON_INTERLACE) - video_monitor_set_refresh_rate(59.8261f); + driver_set_refresh_rate(59.8261f); else - video_monitor_set_refresh_rate(59.94f); + driver_set_refresh_rate(59.94f); } /* Don't spam the queue when scrolling through resolutions. */ diff --git a/gfx/video_monitor.c b/gfx/video_monitor.c index a11fce4832..74d644131f 100644 --- a/gfx/video_monitor.c +++ b/gfx/video_monitor.c @@ -15,8 +15,6 @@ */ #include "video_monitor.h" -#include "../audio/audio_monitor.h" -#include "../driver.h" #include "../general.h" #include "../retroarch.h" @@ -33,29 +31,21 @@ void video_monitor_adjust_system_rates(void) timing_skew = fabs(1.0f - info->fps / g_settings.video.refresh_rate); - if (timing_skew > g_settings.audio.max_timing_skew) - { - /* We don't want to adjust pitch too much. If we have extreme cases, - * just don't readjust at all. */ - RARCH_LOG("Timings deviate too much. Will not adjust. (Display = %.2f Hz, Game = %.2f Hz)\n", - g_settings.video.refresh_rate, - (float)info->fps); - - /* We won't be able to do VSync reliably as game FPS > monitor FPS. */ - if (info->fps > g_settings.video.refresh_rate) - { - g_extern.system.force_nonblock = true; - RARCH_LOG("Game FPS > Monitor FPS. Cannot rely on VSync.\n"); - } - } - - if (!driver.video_data) + /* We don't want to adjust pitch too much. If we have extreme cases, + * just don't readjust at all. */ + if (timing_skew <= g_settings.audio.max_timing_skew) return; - if (g_extern.system.force_nonblock) - rarch_main_command(RARCH_CMD_VIDEO_SET_NONBLOCKING_STATE); - else - driver_set_nonblock_state(driver.nonblock_state); + RARCH_LOG("Timings deviate too much. Will not adjust. (Display = %.2f Hz, Game = %.2f Hz)\n", + g_settings.video.refresh_rate, + (float)info->fps); + + /* We won't be able to do VSync reliably when game FPS > monitor FPS. */ + if (info->fps <= g_settings.video.refresh_rate) + return; + + g_extern.system.force_nonblock = true; + RARCH_LOG("Game FPS > Monitor FPS. Cannot rely on VSync.\n"); } /** @@ -72,8 +62,6 @@ void video_monitor_set_refresh_rate(float hz) RARCH_LOG("%s\n", msg); g_settings.video.refresh_rate = hz; - driver_adjust_system_rates(); - audio_monitor_set_refresh_rate(); } /** diff --git a/settings_data.c b/settings_data.c index ea8afff648..7e3f7d00e4 100644 --- a/settings_data.c +++ b/settings_data.c @@ -19,7 +19,6 @@ #include "settings_data.h" #include "dynamic.h" #include -#include "gfx/video_monitor.h" #include "input/input_autodetect.h" #include "input/input_common.h" #include "config.def.h" @@ -1013,7 +1012,7 @@ static int setting_data_action_ok_video_refresh_rate_auto( if (video_monitor_fps_statistics(&video_refresh_rate, &deviation, &sample_points)) { - video_monitor_set_refresh_rate(video_refresh_rate); + driver_set_refresh_rate(video_refresh_rate); /* Incase refresh rate update forced non-block video. */ rarch_main_command(RARCH_CMD_VIDEO_SET_BLOCKING_STATE); } @@ -3099,7 +3098,7 @@ static void general_write_handler(void *data) { if (driver.video && driver.video_data) { - video_monitor_set_refresh_rate(*setting->value.fraction); + driver_set_refresh_rate(*setting->value.fraction); /* In case refresh rate update forced non-block video. */ rarch_cmd = RARCH_CMD_VIDEO_SET_BLOCKING_STATE;