Create video_driver_set_aspect_ratio_value and video_driver_get_aspect_ratio

This commit is contained in:
twinaphex 2015-05-20 18:24:45 +02:00
parent 52e8d582c0
commit b255b5a325
13 changed files with 44 additions and 33 deletions

View File

@ -332,7 +332,7 @@ static bool d3d_initialize(d3d_video_t *d3d, const video_info_t *info)
video_driver_get_size(&width, &height); video_driver_get_size(&width, &height);
d3d_calculate_rect(d3d, 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)) if (!d3d_init_chain(d3d, info))
{ {
@ -540,7 +540,7 @@ static void d3d_set_aspect_ratio(void *data, unsigned aspect_ratio_idx)
break; 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) if (!d3d)
return; return;
@ -1663,7 +1663,7 @@ static bool d3d_frame(void *data, const void *frame,
if (d3d->should_resize) if (d3d->should_resize)
{ {
d3d_calculate_rect(d3d, width, width, d3d->video_info.force_aspect, 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_driver->set_final_viewport(d3d,
d3d->renderchain_data, &d3d->final_viewport); d3d->renderchain_data, &d3d->final_viewport);

View File

@ -1562,7 +1562,7 @@ static void exynos_set_aspect_ratio(void *data, unsigned aspect_ratio_idx)
break; 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; vid->aspect_changed = true;
} }

View File

@ -793,14 +793,14 @@ static void gl_set_viewport(void *data, unsigned viewport_width,
{ {
video_viewport_get_scaled_integer(&gl->vp, video_viewport_get_scaled_integer(&gl->vp,
viewport_width, viewport_height, 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_width = gl->vp.width;
viewport_height = gl->vp.height; viewport_height = gl->vp.height;
} }
else if (gl->keep_aspect && !force_full) else if (gl->keep_aspect && !force_full)
{ {
float delta; float delta;
float desired_aspect = global->system.aspect_ratio; float desired_aspect = video_driver_get_aspect_ratio();
#if defined(HAVE_MENU) #if defined(HAVE_MENU)
if (settings->video.aspect_ratio_idx == ASPECT_RATIO_CUSTOM) 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; 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) if (!gl)
return; return;

View File

@ -447,7 +447,8 @@ static void gx_set_aspect_ratio(void *data, unsigned aspect_ratio_idx)
else if (aspect_ratio_idx == ASPECT_RATIO_CONFIG) else if (aspect_ratio_idx == ASPECT_RATIO_CONFIG)
video_viewport_set_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) if (!gx)
return; return;
@ -845,7 +846,7 @@ static void gx_resize(void *data)
if (gx->keep_aspect && gx_mode.efbHeight >= 240) /* ignore this for custom resolutions */ 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) if (desired_aspect == 0.0)
desired_aspect = 1.0; desired_aspect = 1.0;
#ifdef HW_RVL #ifdef HW_RVL

View File

@ -703,14 +703,14 @@ static void psp_update_viewport(psp1_video_t* psp)
if (settings->video.scale_integer) if (settings->video.scale_integer)
{ {
video_viewport_get_scaled_integer(&psp->vp, SCEGU_SCR_WIDTH, 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; width = psp->vp.width;
height = psp->vp.height; height = psp->vp.height;
} }
else if (psp->keep_aspect) else if (psp->keep_aspect)
{ {
float delta; float delta;
float desired_aspect = global->system.aspect_ratio; float desired_aspect = video_driver_get_aspect_ratio();
#if defined(HAVE_MENU) #if defined(HAVE_MENU)
if (settings->video.aspect_ratio_idx == ASPECT_RATIO_CUSTOM) 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; 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->keep_aspect = true;
psp->should_resize = true; psp->should_resize = true;

View File

@ -274,7 +274,7 @@ static void sdl_refresh_viewport(sdl2_video_t *vid)
vid->vp.full_height = win_h; vid->vp.full_height = win_h;
if (settings->video.scale_integer) 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); vid->video.force_aspect);
else if (settings->video.aspect_ratio_idx == ASPECT_RATIO_CUSTOM) 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 delta;
float device_aspect = (float)win_w / win_h; 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) 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; 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->video.force_aspect = true;
vid->should_resize = true; vid->should_resize = true;

View File

@ -467,7 +467,7 @@ static void sdl_set_aspect_ratio(void *data, unsigned aspectratio_index)
break; 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) static void sdl_apply_state_changes(void *data)

View File

@ -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}; VGfloat clearColor[4] = {0, 0, 0, 1};
settings_t *settings = config_get_ptr(); settings_t *settings = config_get_ptr();
driver_t *driver = driver_get_ptr(); driver_t *driver = driver_get_ptr();
global_t *global = global_get_ptr();
const gfx_ctx_driver_t *ctx = NULL; const gfx_ctx_driver_t *ctx = NULL;
vg_t *vg = (vg_t*)calloc(1, sizeof(vg_t)); 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) static void vg_calculate_quad(vg_t *vg)
{ {
unsigned width, height; unsigned width, height;
global_t *global = global_get_ptr();
video_driver_get_size(&width, &height); video_driver_get_size(&width, &height);
/* set viewport for aspect ratio, taken from the OpenGL driver. */ /* set viewport for aspect ratio, taken from the OpenGL driver. */
if (vg->mKeepAspect) 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 /* If the aspect ratios of screen and desired aspect ratio
* are sufficiently equal (floating point stuff), * are sufficiently equal (floating point stuff),
@ -318,7 +315,6 @@ static bool vg_frame(void *data, const void *frame,
{ {
unsigned width, height; unsigned width, height;
vg_t *vg = (vg_t*)data; vg_t *vg = (vg_t*)data;
global_t *global = global_get_ptr();
RARCH_PERFORMANCE_INIT(vg_fr); RARCH_PERFORMANCE_INIT(vg_fr);
RARCH_PERFORMANCE_START(vg_fr); RARCH_PERFORMANCE_START(vg_fr);

View File

@ -358,13 +358,12 @@ static void calc_out_rect(bool keep_aspect, struct video_viewport *vp,
unsigned vp_width, unsigned vp_height) unsigned vp_width, unsigned vp_height)
{ {
settings_t *settings = config_get_ptr(); settings_t *settings = config_get_ptr();
global_t *global = global_get_ptr();
vp->full_width = vp_width; vp->full_width = vp_width;
vp->full_height = vp_height; vp->full_height = vp_height;
if (settings->video.scale_integer) 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) else if (!keep_aspect)
{ {
vp->x = 0; vp->y = 0; vp->x = 0; vp->y = 0;
@ -373,7 +372,7 @@ static void calc_out_rect(bool keep_aspect, struct video_viewport *vp,
} }
else else
{ {
float desired_aspect = global->system.aspect_ratio; float desired_aspect = video_driver_get_aspect_ratio();
float device_aspect = (float)vp_width / vp_height; float device_aspect = (float)vp_width / vp_height;
/* If the aspect ratios of screen and desired aspect ratio /* If the aspect ratios of screen and desired aspect ratio

View File

@ -35,6 +35,7 @@ typedef struct video_driver_state
unsigned video_width; unsigned video_width;
unsigned video_height; unsigned video_height;
float aspect_ratio;
} video_driver_state_t; } video_driver_state_t;
static video_driver_state_t video_state; static video_driver_state_t video_state;
@ -501,8 +502,8 @@ void init_video(void)
(float)custom_vp->width / custom_vp->height : default_aspect; (float)custom_vp->width / custom_vp->height : default_aspect;
} }
global->system.aspect_ratio = video_driver_set_aspect_ratio_value(
aspectratio_lut[settings->video.aspect_ratio_idx].value; aspectratio_lut[settings->video.aspect_ratio_idx].value);
if (settings->video.fullscreen) if (settings->video.fullscreen)
{ {
@ -514,8 +515,8 @@ void init_video(void)
if (settings->video.force_aspect) if (settings->video.force_aspect)
{ {
/* Do rounding here to simplify integer scale correctness. */ /* Do rounding here to simplify integer scale correctness. */
unsigned base_width = roundf(geom->base_height * unsigned base_width =
global->system.aspect_ratio); roundf(geom->base_height * video_driver_get_aspect_ratio());
width = roundf(base_width * settings->video.scale); width = roundf(base_width * settings->video.scale);
} }
else else
@ -1087,3 +1088,13 @@ void video_monitor_reset(void)
{ {
video_state.frame_time_samples_count = 0; 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;
}

View File

@ -348,6 +348,10 @@ void video_driver_set_size_height(unsigned width);
uint64_t video_driver_get_frame_count(void); 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 #ifdef __cplusplus
} }
#endif #endif

View File

@ -354,8 +354,8 @@ bool recording_init(void)
params.fb_height = next_pow2(vp.height); params.fb_height = next_pow2(vp.height);
if (settings->video.force_aspect && if (settings->video.force_aspect &&
(global->system.aspect_ratio > 0.0f)) (video_driver_get_aspect_ratio() > 0.0f))
params.aspect_ratio = global->system.aspect_ratio; params.aspect_ratio = video_driver_get_aspect_ratio();
else else
params.aspect_ratio = (float)vp.width / vp.height; params.aspect_ratio = (float)vp.width / vp.height;
@ -382,8 +382,8 @@ bool recording_init(void)
} }
if (settings->video.force_aspect && if (settings->video.force_aspect &&
(global->system.aspect_ratio > 0.0f)) (video_driver_get_aspect_ratio() > 0.0f))
params.aspect_ratio = global->system.aspect_ratio; params.aspect_ratio = video_driver_get_aspect_ratio();
else else
params.aspect_ratio = (float)params.out_width / params.out_height; params.aspect_ratio = (float)params.out_width / params.out_height;

View File

@ -153,7 +153,6 @@ typedef struct global
{ {
struct retro_system_info info; struct retro_system_info info;
struct retro_system_av_info av_info; struct retro_system_av_info av_info;
float aspect_ratio;
unsigned rotation; unsigned rotation;
bool shutdown; bool shutdown;