From a7cb5b849148ed752bef5c724b92bb0748f7c201 Mon Sep 17 00:00:00 2001 From: twinaphex Date: Fri, 20 Nov 2015 20:47:47 +0100 Subject: [PATCH] Add RARCH_DISPLAY_CTL_MONITOR_ADJUST_SYSTEM_RATES --- driver.c | 2 +- gfx/video_driver.c | 80 ++++++++++++++++++++++++--------------------- gfx/video_driver.h | 1 + gfx/video_monitor.h | 2 -- 4 files changed, 44 insertions(+), 41 deletions(-) diff --git a/driver.c b/driver.c index e6dcdea132..f053ae2a37 100644 --- a/driver.c +++ b/driver.c @@ -235,7 +235,7 @@ static void driver_adjust_system_rates(void) driver_t *driver = driver_get_ptr(); audio_monitor_adjust_system_rates(); - video_monitor_adjust_system_rates(); + video_driver_ctl(RARCH_DISPLAY_CTL_MONITOR_ADJUST_SYSTEM_RATES, NULL); if (!driver->video_data) return; diff --git a/gfx/video_driver.c b/gfx/video_driver.c index c250929ded..9589a389ed 100644 --- a/gfx/video_driver.c +++ b/gfx/video_driver.c @@ -814,44 +814,6 @@ void video_driver_set_size_height(unsigned height) video_state.video_height = height; } -void video_monitor_adjust_system_rates(void) -{ - float timing_skew; - const struct retro_system_timing *info = NULL; - struct retro_system_av_info *av_info = - video_viewport_get_system_av_info(); - settings_t *settings = config_get_ptr(); - rarch_system_info_t *system = rarch_system_info_get_ptr(); - - if (!system) - return; - - system->force_nonblock = false; - - if (av_info) - info = (const struct retro_system_timing*)&av_info->timing; - - if (!info || info->fps <= 0.0) - return; - - timing_skew = fabs(1.0f - info->fps / settings->video.refresh_rate); - - /* We don't want to adjust pitch too much. If we have extreme cases, - * just don't readjust at all. */ - if (timing_skew <= settings->audio.max_timing_skew) - return; - - RARCH_LOG("Timings deviate too much. Will not adjust. (Display = %.2f Hz, Game = %.2f Hz)\n", - settings->video.refresh_rate, - (float)info->fps); - - if (info->fps <= settings->video.refresh_rate) - return; - - /* We won't be able to do VSync reliably when game FPS > monitor FPS. */ - system->force_nonblock = true; - RARCH_LOG("Game FPS > Monitor FPS. Cannot rely on VSync.\n"); -} /** * video_monitor_set_refresh_rate: @@ -1136,6 +1098,45 @@ static bool video_driver_cached_frame(driver_t *driver) return true; } +static void video_monitor_adjust_system_rates(void) +{ + float timing_skew; + const struct retro_system_timing *info = NULL; + struct retro_system_av_info *av_info = + video_viewport_get_system_av_info(); + settings_t *settings = config_get_ptr(); + rarch_system_info_t *system = rarch_system_info_get_ptr(); + + if (!system) + return; + + system->force_nonblock = false; + + if (av_info) + info = (const struct retro_system_timing*)&av_info->timing; + + if (!info || info->fps <= 0.0) + return; + + timing_skew = fabs(1.0f - info->fps / settings->video.refresh_rate); + + /* We don't want to adjust pitch too much. If we have extreme cases, + * just don't readjust at all. */ + if (timing_skew <= settings->audio.max_timing_skew) + return; + + RARCH_LOG("Timings deviate too much. Will not adjust. (Display = %.2f Hz, Game = %.2f Hz)\n", + settings->video.refresh_rate, + (float)info->fps); + + if (info->fps <= settings->video.refresh_rate) + return; + + /* We won't be able to do VSync reliably when game FPS > monitor FPS. */ + system->force_nonblock = true; + RARCH_LOG("Game FPS > Monitor FPS. Cannot rely on VSync.\n"); +} + bool video_driver_ctl(enum rarch_display_ctl_state state, void *data) { driver_t *driver = driver_get_ptr(); @@ -1152,6 +1153,9 @@ bool video_driver_ctl(enum rarch_display_ctl_state state, void *data) case RARCH_DISPLAY_CTL_MONITOR_RESET: video_state.frame_time_samples_count = 0; return true; + case RARCH_DISPLAY_CTL_MONITOR_ADJUST_SYSTEM_RATES: + video_monitor_adjust_system_rates(); + return true; case RARCH_DISPLAY_CTL_SET_ASPECT_RATIO: if (!poke || !poke->set_aspect_ratio) return false; diff --git a/gfx/video_driver.h b/gfx/video_driver.h index 9abc111269..3c0fae0c87 100644 --- a/gfx/video_driver.h +++ b/gfx/video_driver.h @@ -224,6 +224,7 @@ enum rarch_display_ctl_state RARCH_DISPLAY_CTL_INIT, RARCH_DISPLAY_CTL_DEINIT, RARCH_DISPLAY_CTL_MONITOR_RESET, + RARCH_DISPLAY_CTL_MONITOR_ADJUST_SYSTEM_RATES, RARCH_DISPLAY_CTL_APPLY_STATE_CHANGES, RARCH_DISPLAY_CTL_FIND_DRIVER, RARCH_DISPLAY_CTL_FRAME_FILTER_ALIVE, diff --git a/gfx/video_monitor.h b/gfx/video_monitor.h index 868a7f01fa..ac0815bcfa 100644 --- a/gfx/video_monitor.h +++ b/gfx/video_monitor.h @@ -24,8 +24,6 @@ extern "C" { #endif -void video_monitor_adjust_system_rates(void); - /** * video_monitor_set_refresh_rate: * @hz : New refresh rate for monitor.