From 51b5a2df5c2fd7668713fadb1f728f857b6a2872 Mon Sep 17 00:00:00 2001 From: Themaister Date: Sun, 17 Mar 2013 22:05:15 +0100 Subject: [PATCH] Refactor aspect_ratio member. Mutate in g_extern.system.aspect_ratio to avoid getting wrong aspect ratio on reentrancy. --- driver.c | 12 +++++++----- general.h | 1 + gfx/d3d9/d3d9.cpp | 2 +- gfx/gl.c | 6 +++--- gfx/vg.c | 2 +- gfx/xvideo.c | 4 ++-- gx/gx_video.c | 4 ++-- retroarch.c | 8 ++++---- settings.c | 2 +- 9 files changed, 22 insertions(+), 19 deletions(-) diff --git a/driver.c b/driver.c index 91b3e90fb1..d9460e9f37 100644 --- a/driver.c +++ b/driver.c @@ -787,14 +787,16 @@ void init_video_input(void) if (g_extern.filter.active) scale = g_extern.filter.scale; - if (g_settings.video.aspect_ratio < 0.0f) + g_extern.system.aspect_ratio = g_settings.video.aspect_ratio; + + if (g_extern.system.aspect_ratio < 0.0f) { if (geom->aspect_ratio > 0.0f && g_settings.video.aspect_ratio_auto) - g_settings.video.aspect_ratio = geom->aspect_ratio; + g_extern.system.aspect_ratio = geom->aspect_ratio; else - g_settings.video.aspect_ratio = (float)geom->base_width / geom->base_height; // 1:1 PAR. + g_extern.system.aspect_ratio = (float)geom->base_width / geom->base_height; // 1:1 PAR. - RARCH_LOG("Adjusting aspect ratio to %.2f\n", g_settings.video.aspect_ratio); + RARCH_LOG("Adjusting aspect ratio to %.2f\n", g_extern.system.aspect_ratio); } unsigned width; @@ -808,7 +810,7 @@ void init_video_input(void) { if (g_settings.video.force_aspect) { - width = roundf(geom->base_height * g_settings.video.xscale * g_settings.video.aspect_ratio); + width = roundf(geom->base_height * g_settings.video.xscale * g_extern.system.aspect_ratio); height = roundf(geom->base_height * g_settings.video.yscale); } else diff --git a/general.h b/general.h index 4902856d0d..ae8f9eac6c 100644 --- a/general.h +++ b/general.h @@ -374,6 +374,7 @@ struct global { struct retro_system_info info; struct retro_system_av_info av_info; + float aspect_ratio; char *environment; char *environment_split; diff --git a/gfx/d3d9/d3d9.cpp b/gfx/d3d9/d3d9.cpp index c182325a23..ecd8cd515f 100644 --- a/gfx/d3d9/d3d9.cpp +++ b/gfx/d3d9/d3d9.cpp @@ -193,7 +193,7 @@ void D3DVideo::init(const video_info_t &info) } } - calculate_rect(screen_width, screen_height, info.force_aspect, g_settings.video.aspect_ratio); + calculate_rect(screen_width, screen_height, info.force_aspect, g_extern.system.aspect_ratio); #ifdef HAVE_CG if (!init_cg()) diff --git a/gfx/gl.c b/gfx/gl.c index e36121ea3b..1471887e2c 100644 --- a/gfx/gl.c +++ b/gfx/gl.c @@ -711,11 +711,11 @@ void gl_set_viewport(void *data, unsigned width, unsigned height, bool force_ful if (g_settings.video.scale_integer && !force_full) { - gfx_scale_integer(&gl->vp, width, height, g_settings.video.aspect_ratio, gl->keep_aspect); + gfx_scale_integer(&gl->vp, width, height, g_extern.system.aspect_ratio, gl->keep_aspect); } else if (gl->keep_aspect && !force_full) { - float desired_aspect = g_settings.video.aspect_ratio; + float desired_aspect = g_extern.system.aspect_ratio; float delta; #ifdef HAVE_RGUI @@ -2293,7 +2293,7 @@ static void gl_set_aspect_ratio(void *data, unsigned aspectratio_index) else if (g_settings.video.aspect_ratio_idx == ASPECT_RATIO_CORE) gfx_set_core_viewport(); - g_settings.video.aspect_ratio = aspectratio_lut[g_settings.video.aspect_ratio_idx].value; + g_extern.system.aspect_ratio = aspectratio_lut[g_settings.video.aspect_ratio_idx].value; g_settings.video.force_aspect = false; gl->keep_aspect = true; diff --git a/gfx/vg.c b/gfx/vg.c index 811bb2c03e..c5b92e0d0c 100644 --- a/gfx/vg.c +++ b/gfx/vg.c @@ -279,7 +279,7 @@ static void vg_calculate_quad(vg_t *vg) // set viewport for aspect ratio, taken from the OpenGL driver if (vg->mKeepAspect) { - float desired_aspect = g_settings.video.aspect_ratio; + float desired_aspect = g_extern.system.aspect_ratio; // If the aspect ratios of screen and desired aspect ratio are sufficiently equal (floating point stuff), // assume they are actually equal. diff --git a/gfx/xvideo.c b/gfx/xvideo.c index ded1a37cd7..99fda76791 100644 --- a/gfx/xvideo.c +++ b/gfx/xvideo.c @@ -538,7 +538,7 @@ static void calc_out_rect(bool keep_aspect, struct rarch_viewport *vp, unsigned if (g_settings.video.scale_integer) { - gfx_scale_integer(vp, vp_width, vp_height, g_settings.video.aspect_ratio, keep_aspect); + gfx_scale_integer(vp, vp_width, vp_height, g_extern.system.aspect_ratio, keep_aspect); } else if (!keep_aspect) { @@ -548,7 +548,7 @@ static void calc_out_rect(bool keep_aspect, struct rarch_viewport *vp, unsigned } else { - float desired_aspect = g_settings.video.aspect_ratio; + float desired_aspect = g_extern.system.aspect_ratio; float device_aspect = (float)vp_width / vp_height; // If the aspect ratios of screen and desired aspect ratio are sufficiently equal (floating point stuff), diff --git a/gx/gx_video.c b/gx/gx_video.c index 677af60ab6..3769fc55e3 100644 --- a/gx/gx_video.c +++ b/gx/gx_video.c @@ -279,7 +279,7 @@ static void gx_set_aspect_ratio(void *data, unsigned aspectratio_idx) else if(g_settings.video.aspect_ratio_idx == ASPECT_RATIO_CORE) gfx_set_core_viewport(); - g_settings.video.aspect_ratio = aspectratio_lut[g_settings.video.aspect_ratio_idx].value; + g_extern.system.aspect_ratio = aspectratio_lut[g_settings.video.aspect_ratio_idx].value; g_settings.video.force_aspect = false; gx->keep_aspect = true; gx->should_resize = true; @@ -700,7 +700,7 @@ static void gx_resize(void *data) if (gx->keep_aspect && gx_mode.efbHeight >= 480) // ingore this for custom resolutions { - float desired_aspect = g_settings.video.aspect_ratio; + float desired_aspect = g_extern.system.aspect_ratio; if (desired_aspect == 0.0) desired_aspect = 1.0; #ifdef HW_RVL diff --git a/retroarch.c b/retroarch.c index 5331b6d158..8fa83c4942 100644 --- a/retroarch.c +++ b/retroarch.c @@ -1326,8 +1326,8 @@ static void init_recording(void) params.fb_width = next_pow2(vp.width); params.fb_height = next_pow2(vp.height); - if (g_settings.video.force_aspect && (g_settings.video.aspect_ratio > 0.0f)) - params.aspect_ratio = g_settings.video.aspect_ratio; + if (g_settings.video.force_aspect && (g_extern.system.aspect_ratio > 0.0f)) + params.aspect_ratio = g_extern.system.aspect_ratio; else params.aspect_ratio = (float)vp.width / vp.height; @@ -1354,8 +1354,8 @@ static void init_recording(void) params.out_height = g_extern.record_height; } - if (g_settings.video.force_aspect && (g_settings.video.aspect_ratio > 0.0f)) - params.aspect_ratio = g_settings.video.aspect_ratio; + if (g_settings.video.force_aspect && (g_extern.system.aspect_ratio > 0.0f)) + params.aspect_ratio = g_extern.system.aspect_ratio; else params.aspect_ratio = (float)params.out_width / params.out_height; diff --git a/settings.c b/settings.c index a3bd9275cc..cdfb3df81e 100644 --- a/settings.c +++ b/settings.c @@ -1196,7 +1196,7 @@ bool config_save_file(const char *path) config_set_bool(conf, "rewind_enable", g_settings.rewind_enable); config_set_int(conf, "rewind_granularity", g_settings.rewind_granularity); config_set_string(conf, "video_cg_shader", g_settings.video.cg_shader_path); - config_set_float(conf, "video_aspect_ratio", g_settings.video.aspect_ratio); + config_set_float(conf, "video_aspect_ratio", g_extern.system.aspect_ratio); #ifdef HAVE_FBO config_set_float(conf, "video_fbo_scale_x", g_settings.video.fbo.scale_x); config_set_float(conf, "video_fbo_scale_y", g_settings.video.fbo.scale_y);