From b255b5a3253af4b346c68941a0be146179bc6fef Mon Sep 17 00:00:00 2001 From: twinaphex Date: Wed, 20 May 2015 18:24:45 +0200 Subject: [PATCH] Create video_driver_set_aspect_ratio_value and video_driver_get_aspect_ratio --- gfx/d3d/d3d.cpp | 6 +++--- gfx/drivers/exynos_gfx.c | 2 +- gfx/drivers/gl.c | 6 +++--- gfx/drivers/gx_gfx.c | 5 +++-- gfx/drivers/psp1_gfx.c | 6 +++--- gfx/drivers/sdl2_gfx.c | 7 ++++--- gfx/drivers/sdl_gfx.c | 2 +- gfx/drivers/vg.c | 6 +----- gfx/drivers/xvideo.c | 5 ++--- gfx/video_driver.c | 19 +++++++++++++++---- gfx/video_driver.h | 4 ++++ record/record_driver.c | 8 ++++---- runloop.h | 1 - 13 files changed, 44 insertions(+), 33 deletions(-) diff --git a/gfx/d3d/d3d.cpp b/gfx/d3d/d3d.cpp index 74a7173478..f55cf2b378 100644 --- a/gfx/d3d/d3d.cpp +++ b/gfx/d3d/d3d.cpp @@ -332,7 +332,7 @@ static bool d3d_initialize(d3d_video_t *d3d, const video_info_t *info) video_driver_get_size(&width, &height); d3d_calculate_rect(d3d, - width, height, info->force_aspect, global->system.aspect_ratio); + width, height, info->force_aspect, video_driver_get_aspect_ratio()); if (!d3d_init_chain(d3d, info)) { @@ -540,7 +540,7 @@ static void d3d_set_aspect_ratio(void *data, unsigned aspect_ratio_idx) break; } - global->system.aspect_ratio = aspectratio_lut[aspect_ratio_idx].value; + video_driver_set_aspect_ratio_value(aspectratio_lut[aspect_ratio_idx].value); if (!d3d) return; @@ -1663,7 +1663,7 @@ static bool d3d_frame(void *data, const void *frame, if (d3d->should_resize) { d3d_calculate_rect(d3d, width, width, d3d->video_info.force_aspect, - global->system.aspect_ratio); + video_driver_get_aspect_ratio()); d3d->renderchain_driver->set_final_viewport(d3d, d3d->renderchain_data, &d3d->final_viewport); diff --git a/gfx/drivers/exynos_gfx.c b/gfx/drivers/exynos_gfx.c index 8df1eadf8a..08e9a17aab 100644 --- a/gfx/drivers/exynos_gfx.c +++ b/gfx/drivers/exynos_gfx.c @@ -1562,7 +1562,7 @@ static void exynos_set_aspect_ratio(void *data, unsigned aspect_ratio_idx) break; } - global->system.aspect_ratio = aspectratio_lut[aspect_ratio_idx].value; + video_driver_set_aspect_ratio_value(aspectratio_lut[aspect_ratio_idx].value); vid->aspect_changed = true; } diff --git a/gfx/drivers/gl.c b/gfx/drivers/gl.c index 48d2b70619..926be3be85 100644 --- a/gfx/drivers/gl.c +++ b/gfx/drivers/gl.c @@ -793,14 +793,14 @@ static void gl_set_viewport(void *data, unsigned viewport_width, { video_viewport_get_scaled_integer(&gl->vp, viewport_width, viewport_height, - global->system.aspect_ratio, gl->keep_aspect); + video_driver_get_aspect_ratio(), gl->keep_aspect); viewport_width = gl->vp.width; viewport_height = gl->vp.height; } else if (gl->keep_aspect && !force_full) { float delta; - float desired_aspect = global->system.aspect_ratio; + float desired_aspect = video_driver_get_aspect_ratio(); #if defined(HAVE_MENU) if (settings->video.aspect_ratio_idx == ASPECT_RATIO_CUSTOM) @@ -3122,7 +3122,7 @@ static void gl_set_aspect_ratio(void *data, unsigned aspect_ratio_idx) break; } - global->system.aspect_ratio = aspectratio_lut[aspect_ratio_idx].value; + video_driver_set_aspect_ratio_value(aspectratio_lut[aspect_ratio_idx].value); if (!gl) return; diff --git a/gfx/drivers/gx_gfx.c b/gfx/drivers/gx_gfx.c index 8aa2fd1af8..8a5126158d 100644 --- a/gfx/drivers/gx_gfx.c +++ b/gfx/drivers/gx_gfx.c @@ -447,7 +447,8 @@ static void gx_set_aspect_ratio(void *data, unsigned aspect_ratio_idx) else if (aspect_ratio_idx == ASPECT_RATIO_CONFIG) video_viewport_set_config(); - global->system.aspect_ratio = aspectratio_lut[aspect_ratio_idx].value; + video_driver_set_aspect_ratio_value( + aspectratio_lut[aspect_ratio_idx].value); if (!gx) return; @@ -845,7 +846,7 @@ static void gx_resize(void *data) if (gx->keep_aspect && gx_mode.efbHeight >= 240) /* ignore this for custom resolutions */ { - float desired_aspect = global->system.aspect_ratio; + float desired_aspect = video_driver_get_aspect_ratio(); if (desired_aspect == 0.0) desired_aspect = 1.0; #ifdef HW_RVL diff --git a/gfx/drivers/psp1_gfx.c b/gfx/drivers/psp1_gfx.c index 7909efbfac..c582edb77e 100644 --- a/gfx/drivers/psp1_gfx.c +++ b/gfx/drivers/psp1_gfx.c @@ -703,14 +703,14 @@ static void psp_update_viewport(psp1_video_t* psp) if (settings->video.scale_integer) { video_viewport_get_scaled_integer(&psp->vp, SCEGU_SCR_WIDTH, - SCEGU_SCR_HEIGHT, global->system.aspect_ratio, psp->keep_aspect); + SCEGU_SCR_HEIGHT, video_driver_get_aspect_ratio(), psp->keep_aspect); width = psp->vp.width; height = psp->vp.height; } else if (psp->keep_aspect) { float delta; - float desired_aspect = global->system.aspect_ratio; + float desired_aspect = video_driver_get_aspect_ratio(); #if defined(HAVE_MENU) if (settings->video.aspect_ratio_idx == ASPECT_RATIO_CUSTOM) @@ -818,7 +818,7 @@ static void psp_set_aspect_ratio(void *data, unsigned aspectratio_index) break; } - global->system.aspect_ratio = aspectratio_lut[aspectratio_index].value; + video_driver_set_aspect_ratio_value(aspectratio_lut[aspectratio_index].value); psp->keep_aspect = true; psp->should_resize = true; diff --git a/gfx/drivers/sdl2_gfx.c b/gfx/drivers/sdl2_gfx.c index 8128b7836f..5f82ca49b5 100644 --- a/gfx/drivers/sdl2_gfx.c +++ b/gfx/drivers/sdl2_gfx.c @@ -274,7 +274,7 @@ static void sdl_refresh_viewport(sdl2_video_t *vid) vid->vp.full_height = win_h; if (settings->video.scale_integer) - video_viewport_get_scaled_integer(&vid->vp, win_w, win_h, global->system.aspect_ratio, + video_viewport_get_scaled_integer(&vid->vp, win_w, win_h, video_driver_get_aspect_ratio(), vid->video.force_aspect); else if (settings->video.aspect_ratio_idx == ASPECT_RATIO_CUSTOM) { @@ -292,7 +292,7 @@ static void sdl_refresh_viewport(sdl2_video_t *vid) { float delta; float device_aspect = (float)win_w / win_h; - float desired_aspect = global->system.aspect_ratio; + float desired_aspect = video_driver_get_aspect_ratio(); if (fabsf(device_aspect - desired_aspect) < 0.0001f) { @@ -660,7 +660,8 @@ static void sdl2_poke_set_aspect_ratio(void *data, unsigned aspectratio_index) break; } - global->system.aspect_ratio = aspectratio_lut[aspectratio_index].value; + video_driver_set_aspect_ratio_value( + aspectratio_lut[aspectratio_index].value); vid->video.force_aspect = true; vid->should_resize = true; diff --git a/gfx/drivers/sdl_gfx.c b/gfx/drivers/sdl_gfx.c index 55d0616434..0ff1be41c5 100644 --- a/gfx/drivers/sdl_gfx.c +++ b/gfx/drivers/sdl_gfx.c @@ -467,7 +467,7 @@ static void sdl_set_aspect_ratio(void *data, unsigned aspectratio_index) break; } - global->system.aspect_ratio = aspectratio_lut[aspectratio_index].value; + video_driver_set_aspect_ratio_value(aspectratio_lut[aspectratio_index].value); } static void sdl_apply_state_changes(void *data) diff --git a/gfx/drivers/vg.c b/gfx/drivers/vg.c index 09ee13c339..9f627b5ec6 100644 --- a/gfx/drivers/vg.c +++ b/gfx/drivers/vg.c @@ -85,7 +85,6 @@ static void *vg_init(const video_info_t *video, const input_driver_t **input, vo VGfloat clearColor[4] = {0, 0, 0, 1}; settings_t *settings = config_get_ptr(); driver_t *driver = driver_get_ptr(); - global_t *global = global_get_ptr(); const gfx_ctx_driver_t *ctx = NULL; vg_t *vg = (vg_t*)calloc(1, sizeof(vg_t)); @@ -232,14 +231,12 @@ static void vg_free(void *data) static void vg_calculate_quad(vg_t *vg) { unsigned width, height; - global_t *global = global_get_ptr(); - video_driver_get_size(&width, &height); /* set viewport for aspect ratio, taken from the OpenGL driver. */ if (vg->mKeepAspect) { - float desired_aspect = global->system.aspect_ratio; + float desired_aspect = video_driver_get_aspect_ratio(); /* If the aspect ratios of screen and desired aspect ratio * are sufficiently equal (floating point stuff), @@ -318,7 +315,6 @@ static bool vg_frame(void *data, const void *frame, { unsigned width, height; vg_t *vg = (vg_t*)data; - global_t *global = global_get_ptr(); RARCH_PERFORMANCE_INIT(vg_fr); RARCH_PERFORMANCE_START(vg_fr); diff --git a/gfx/drivers/xvideo.c b/gfx/drivers/xvideo.c index b9c0008042..4982fc9dca 100644 --- a/gfx/drivers/xvideo.c +++ b/gfx/drivers/xvideo.c @@ -358,13 +358,12 @@ static void calc_out_rect(bool keep_aspect, struct video_viewport *vp, unsigned vp_width, unsigned vp_height) { settings_t *settings = config_get_ptr(); - global_t *global = global_get_ptr(); vp->full_width = vp_width; vp->full_height = vp_height; if (settings->video.scale_integer) - video_viewport_get_scaled_integer(vp, vp_width, vp_height, global->system.aspect_ratio, keep_aspect); + video_viewport_get_scaled_integer(vp, vp_width, vp_height, video_driver_get_aspect_ratio(), keep_aspect); else if (!keep_aspect) { vp->x = 0; vp->y = 0; @@ -373,7 +372,7 @@ static void calc_out_rect(bool keep_aspect, struct video_viewport *vp, } else { - float desired_aspect = global->system.aspect_ratio; + float desired_aspect = video_driver_get_aspect_ratio(); float device_aspect = (float)vp_width / vp_height; /* If the aspect ratios of screen and desired aspect ratio diff --git a/gfx/video_driver.c b/gfx/video_driver.c index bcb334fe06..49495de7be 100644 --- a/gfx/video_driver.c +++ b/gfx/video_driver.c @@ -35,6 +35,7 @@ typedef struct video_driver_state unsigned video_width; unsigned video_height; + float aspect_ratio; } video_driver_state_t; static video_driver_state_t video_state; @@ -501,8 +502,8 @@ void init_video(void) (float)custom_vp->width / custom_vp->height : default_aspect; } - global->system.aspect_ratio = - aspectratio_lut[settings->video.aspect_ratio_idx].value; + video_driver_set_aspect_ratio_value( + aspectratio_lut[settings->video.aspect_ratio_idx].value); if (settings->video.fullscreen) { @@ -514,8 +515,8 @@ void init_video(void) if (settings->video.force_aspect) { /* Do rounding here to simplify integer scale correctness. */ - unsigned base_width = roundf(geom->base_height * - global->system.aspect_ratio); + unsigned base_width = + roundf(geom->base_height * video_driver_get_aspect_ratio()); width = roundf(base_width * settings->video.scale); } else @@ -1087,3 +1088,13 @@ void video_monitor_reset(void) { video_state.frame_time_samples_count = 0; } + +float video_driver_get_aspect_ratio(void) +{ + return video_state.aspect_ratio; +} + +void video_driver_set_aspect_ratio_value(float value) +{ + video_state.aspect_ratio = value; +} diff --git a/gfx/video_driver.h b/gfx/video_driver.h index 83a834dfbe..e833451149 100644 --- a/gfx/video_driver.h +++ b/gfx/video_driver.h @@ -348,6 +348,10 @@ void video_driver_set_size_height(unsigned width); uint64_t video_driver_get_frame_count(void); +float video_driver_get_aspect_ratio(void); + +void video_driver_set_aspect_ratio_value(float value); + #ifdef __cplusplus } #endif diff --git a/record/record_driver.c b/record/record_driver.c index a0f880a517..cb3688fddb 100644 --- a/record/record_driver.c +++ b/record/record_driver.c @@ -354,8 +354,8 @@ bool recording_init(void) params.fb_height = next_pow2(vp.height); if (settings->video.force_aspect && - (global->system.aspect_ratio > 0.0f)) - params.aspect_ratio = global->system.aspect_ratio; + (video_driver_get_aspect_ratio() > 0.0f)) + params.aspect_ratio = video_driver_get_aspect_ratio(); else params.aspect_ratio = (float)vp.width / vp.height; @@ -382,8 +382,8 @@ bool recording_init(void) } if (settings->video.force_aspect && - (global->system.aspect_ratio > 0.0f)) - params.aspect_ratio = global->system.aspect_ratio; + (video_driver_get_aspect_ratio() > 0.0f)) + params.aspect_ratio = video_driver_get_aspect_ratio(); else params.aspect_ratio = (float)params.out_width / params.out_height; diff --git a/runloop.h b/runloop.h index fb9266ec5d..e2baf5bf2e 100644 --- a/runloop.h +++ b/runloop.h @@ -153,7 +153,6 @@ typedef struct global { struct retro_system_info info; struct retro_system_av_info av_info; - float aspect_ratio; unsigned rotation; bool shutdown;