diff --git a/gfx/d3d/d3d.cpp b/gfx/d3d/d3d.cpp index 3aab8d707b..aaaf17397a 100644 --- a/gfx/d3d/d3d.cpp +++ b/gfx/d3d/d3d.cpp @@ -490,25 +490,29 @@ static bool d3d_has_windowed(void *data) static void d3d_set_aspect_ratio(void *data, unsigned aspect_ratio_idx) { d3d_video_t *d3d = (d3d_video_t*)data; + enum rarch_display_ctl_state cmd = RARCH_DISPLAY_CTL_NONE; switch (aspect_ratio_idx) { case ASPECT_RATIO_SQUARE: - video_driver_ctl(RARCH_DISPLAY_CTL_SET_VIEWPORT_SQUARE_PIXEL, NULL); + cmd = RARCH_DISPLAY_CTL_SET_VIEWPORT_SQUARE_PIXEL; break; case ASPECT_RATIO_CORE: - video_driver_ctl(RARCH_DISPLAY_CTL_SET_VIEWPORT_CORE, NULL); + cmd = RARCH_DISPLAY_CTL_SET_VIEWPORT_CORE; break; case ASPECT_RATIO_CONFIG: - video_viewport_set_config(); + cmd = RARCH_DISPLAY_CTL_SET_VIEWPORT_CONFIG; break; default: break; } + if (cmd != RARCH_DISPLAY_CTL_NONE) + video_driver_ctl(cmd, NULL); + video_driver_set_aspect_ratio_value(aspectratio_lut[aspect_ratio_idx].value); if (!d3d) diff --git a/gfx/drivers/ctr_gfx.c b/gfx/drivers/ctr_gfx.c index 81512807e4..3676367875 100644 --- a/gfx/drivers/ctr_gfx.c +++ b/gfx/drivers/ctr_gfx.c @@ -769,29 +769,33 @@ static void ctr_set_filtering(void* data, unsigned index, bool smooth) ctr->smooth = smooth; } -static void ctr_set_aspect_ratio(void* data, unsigned aspectratio_index) +static void ctr_set_aspect_ratio(void* data, unsigned aspect_ratio_idx) { ctr_video_t *ctr = (ctr_video_t*)data; + enum rarch_display_ctl_state cmd = RARCH_DISPLAY_CTL_NONE; - switch (aspectratio_index) + switch (aspect_ratio_idx) { case ASPECT_RATIO_SQUARE: - video_driver_ctl(RARCH_DISPLAY_CTL_SET_VIEWPORT_SQUARE_PIXEL, NULL); + cmd = RARCH_DISPLAY_CTL_SET_VIEWPORT_SQUARE_PIXEL; break; case ASPECT_RATIO_CORE: - video_driver_ctl(RARCH_DISPLAY_CTL_SET_VIEWPORT_CORE, NULL); + cmd = RARCH_DISPLAY_CTL_SET_VIEWPORT_CORE; break; case ASPECT_RATIO_CONFIG: - video_viewport_set_config(); + cmd = RARCH_DISPLAY_CTL_SET_VIEWPORT_CONFIG; break; default: break; } - video_driver_set_aspect_ratio_value(aspectratio_lut[aspectratio_index].value); + if (cmd != RARCH_DISPLAY_CTL_NONE) + video_driver_ctl(cmd, NULL); + + video_driver_set_aspect_ratio_value(aspectratio_lut[aspect_ratio_idx].value); ctr->keep_aspect = true; ctr->should_resize = true; diff --git a/gfx/drivers/exynos_gfx.c b/gfx/drivers/exynos_gfx.c index 1e1cf11450..49ab1d89a0 100644 --- a/gfx/drivers/exynos_gfx.c +++ b/gfx/drivers/exynos_gfx.c @@ -1543,25 +1543,29 @@ static void exynos_gfx_viewport_info(void *data, struct video_viewport *vp) static void exynos_set_aspect_ratio(void *data, unsigned aspect_ratio_idx) { struct exynos_video *vid = (struct exynos_video*)data; + enum rarch_display_ctl_state cmd = RARCH_DISPLAY_CTL_NONE; switch (aspect_ratio_idx) { case ASPECT_RATIO_SQUARE: - video_driver_ctl(RARCH_DISPLAY_CTL_SET_VIEWPORT_SQUARE_PIXEL, NULL); + cmd = RARCH_DISPLAY_CTL_SET_VIEWPORT_SQUARE_PIXEL; break; case ASPECT_RATIO_CORE: - video_driver_ctl(RARCH_DISPLAY_CTL_SET_VIEWPORT_CORE, NULL); + cmd = RARCH_DISPLAY_CTL_SET_VIEWPORT_CORE; break; case ASPECT_RATIO_CONFIG: - video_viewport_set_config(); + cmd = RARCH_DISPLAY_CTL_SET_VIEWPORT_CONFIG; break; default: break; } + if (cmd != RARCH_DISPLAY_CTL_NONE) + video_driver_ctl(cmd, NULL); + 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 177b2c4d29..f19dc43f12 100644 --- a/gfx/drivers/gl.c +++ b/gfx/drivers/gl.c @@ -3265,25 +3265,29 @@ static retro_proc_address_t gl_get_proc_address(void *data, const char *sym) static void gl_set_aspect_ratio(void *data, unsigned aspect_ratio_idx) { gl_t *gl = (gl_t*)data; + enum rarch_display_ctl_state cmd = RARCH_DISPLAY_CTL_NONE; switch (aspect_ratio_idx) { case ASPECT_RATIO_SQUARE: - video_driver_ctl(RARCH_DISPLAY_CTL_SET_VIEWPORT_SQUARE_PIXEL, NULL); + cmd = RARCH_DISPLAY_CTL_SET_VIEWPORT_SQUARE_PIXEL; break; case ASPECT_RATIO_CORE: - video_driver_ctl(RARCH_DISPLAY_CTL_SET_VIEWPORT_CORE, NULL); + cmd = RARCH_DISPLAY_CTL_SET_VIEWPORT_CORE; break; case ASPECT_RATIO_CONFIG: - video_viewport_set_config(); + cmd = RARCH_DISPLAY_CTL_SET_VIEWPORT_CONFIG; break; default: break; } + if (cmd != RARCH_DISPLAY_CTL_NONE) + video_driver_ctl(cmd, NULL); + video_driver_set_aspect_ratio_value(aspectratio_lut[aspect_ratio_idx].value); if (!gl) diff --git a/gfx/drivers/gx_gfx.c b/gfx/drivers/gx_gfx.c index 4b7466c89f..1e0fe61467 100644 --- a/gfx/drivers/gx_gfx.c +++ b/gfx/drivers/gx_gfx.c @@ -446,22 +446,30 @@ static void gx_set_video_mode(void *data, unsigned fbWidth, unsigned lines, static void gx_set_aspect_ratio(void *data, unsigned aspect_ratio_idx) { gx_video_t *gx = (gx_video_t*)data; + enum rarch_display_ctl_state cmd = RARCH_DISPLAY_CTL_NONE; switch (aspect_ratio_idx) { case ASPECT_RATIO_SQUARE: - video_driver_ctl(RARCH_DISPLAY_CTL_SET_VIEWPORT_SQUARE_PIXEL, NULL); + cmd = RARCH_DISPLAY_CTL_SET_VIEWPORT_SQUARE_PIXEL; break; + case ASPECT_RATIO_CORE: - video_driver_ctl(RARCH_DISPLAY_CTL_SET_VIEWPORT_CORE, NULL); + cmd = RARCH_DISPLAY_CTL_SET_VIEWPORT_CORE; break; + case ASPECT_RATIO_CONFIG: - video_viewport_set_config(); + cmd = RARCH_DISPLAY_CTL_SET_VIEWPORT_CONFIG; + break; + + default: break; } - video_driver_set_aspect_ratio_value( - aspectratio_lut[aspect_ratio_idx].value); + if (cmd != RARCH_DISPLAY_CTL_NONE) + video_driver_ctl(cmd, NULL); + + video_driver_set_aspect_ratio_value(aspectratio_lut[aspect_ratio_idx].value); if (!gx) return; diff --git a/gfx/drivers/psp1_gfx.c b/gfx/drivers/psp1_gfx.c index 4b7be2d30c..3f9da8dc1c 100644 --- a/gfx/drivers/psp1_gfx.c +++ b/gfx/drivers/psp1_gfx.c @@ -789,29 +789,33 @@ static void psp_set_filtering(void *data, unsigned index, bool smooth) psp->tex_filter = smooth? GU_LINEAR : GU_NEAREST; } -static void psp_set_aspect_ratio(void *data, unsigned aspectratio_index) +static void psp_set_aspect_ratio(void *data, unsigned aspect_ratio_idx) { psp1_video_t *psp = (psp1_video_t*)data; + enum rarch_display_ctl_state cmd = RARCH_DISPLAY_CTL_NONE; - switch (aspectratio_index) + switch (aspect_ratio_idx) { case ASPECT_RATIO_SQUARE: - video_driver_ctl(RARCH_DISPLAY_CTL_SET_VIEWPORT_SQUARE_PIXEL, NULL); + cmd = RARCH_DISPLAY_CTL_SET_VIEWPORT_SQUARE_PIXEL; break; case ASPECT_RATIO_CORE: - video_driver_ctl(RARCH_DISPLAY_CTL_SET_VIEWPORT_CORE, NULL); + cmd = RARCH_DISPLAY_CTL_SET_VIEWPORT_CORE; break; case ASPECT_RATIO_CONFIG: - video_viewport_set_config(); + cmd = RARCH_DISPLAY_CTL_SET_VIEWPORT_CONFIG; break; default: break; } - video_driver_set_aspect_ratio_value(aspectratio_lut[aspectratio_index].value); + if (cmd != RARCH_DISPLAY_CTL_NONE) + video_driver_ctl(cmd, NULL); + + video_driver_set_aspect_ratio_value(aspectratio_lut[aspect_ratio_idx].value); psp->keep_aspect = true; psp->should_resize = true; diff --git a/gfx/drivers/sdl2_gfx.c b/gfx/drivers/sdl2_gfx.c index 0444db486c..91985733c1 100644 --- a/gfx/drivers/sdl2_gfx.c +++ b/gfx/drivers/sdl2_gfx.c @@ -652,30 +652,33 @@ static void sdl2_poke_set_filtering(void *data, unsigned index, bool smooth) sdl_tex_zero(&vid->frame); } -static void sdl2_poke_set_aspect_ratio(void *data, unsigned aspectratio_index) +static void sdl2_poke_set_aspect_ratio(void *data, unsigned aspect_ratio_idx) { sdl2_video_t *vid = (sdl2_video_t*)data; + enum rarch_display_ctl_state cmd = RARCH_DISPLAY_CTL_NONE; - switch (aspectratio_index) + switch (aspect_ratio_idx) { case ASPECT_RATIO_SQUARE: - video_driver_ctl(RARCH_DISPLAY_CTL_SET_VIEWPORT_SQUARE_PIXEL, NULL); + cmd = RARCH_DISPLAY_CTL_SET_VIEWPORT_SQUARE_PIXEL; break; case ASPECT_RATIO_CORE: - video_driver_ctl(RARCH_DISPLAY_CTL_SET_VIEWPORT_CORE, NULL); + cmd = RARCH_DISPLAY_CTL_SET_VIEWPORT_CORE; break; case ASPECT_RATIO_CONFIG: - video_viewport_set_config(); + cmd = RARCH_DISPLAY_CTL_SET_VIEWPORT_CONFIG; break; default: break; } - video_driver_set_aspect_ratio_value( - aspectratio_lut[aspectratio_index].value); + if (cmd != RARCH_DISPLAY_CTL_NONE) + video_driver_ctl(cmd, NULL); + + video_driver_set_aspect_ratio_value(aspectratio_lut[aspect_ratio_idx].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 e3126abfc6..bac729e1d4 100644 --- a/gfx/drivers/sdl_gfx.c +++ b/gfx/drivers/sdl_gfx.c @@ -440,26 +440,31 @@ static void sdl_set_filtering(void *data, unsigned index, bool smooth) vid->scaler.scaler_type = smooth ? SCALER_TYPE_BILINEAR : SCALER_TYPE_POINT; } -static void sdl_set_aspect_ratio(void *data, unsigned aspectratio_index) +static void sdl_set_aspect_ratio(void *data, unsigned aspect_ratio_idx) { - switch (aspectratio_index) + enum rarch_display_ctl_state cmd = RARCH_DISPLAY_CTL_NONE; + + switch (aspect_ratio_idx) { case ASPECT_RATIO_SQUARE: - video_driver_ctl(RARCH_DISPLAY_CTL_SET_VIEWPORT_SQUARE_PIXEL, NULL); + cmd = RARCH_DISPLAY_CTL_SET_VIEWPORT_SQUARE_PIXEL; break; case ASPECT_RATIO_CORE: - video_driver_ctl(RARCH_DISPLAY_CTL_SET_VIEWPORT_CORE, NULL); + cmd = RARCH_DISPLAY_CTL_SET_VIEWPORT_CORE; break; case ASPECT_RATIO_CONFIG: - video_viewport_set_config(); + cmd = RARCH_DISPLAY_CTL_SET_VIEWPORT_CONFIG; break; default: break; } + if (cmd != RARCH_DISPLAY_CTL_NONE) + video_driver_ctl(cmd, NULL); + video_driver_set_aspect_ratio_value(aspectratio_lut[aspectratio_index].value); } diff --git a/gfx/drivers/vita2d_gfx.c b/gfx/drivers/vita2d_gfx.c index 007a0318de..f2166437e4 100644 --- a/gfx/drivers/vita2d_gfx.c +++ b/gfx/drivers/vita2d_gfx.c @@ -493,29 +493,33 @@ static void vita_set_filtering(void *data, unsigned index, bool smooth) } } -static void vita_set_aspect_ratio(void *data, unsigned aspectratio_index) +static void vita_set_aspect_ratio(void *data, unsigned aspect_ratio_idx) { vita_video_t *vita = (vita_video_t*)data; + enum rarch_display_ctl_state cmd = RARCH_DISPLAY_CTL_NONE; - switch (aspectratio_index) + switch (aspect_ratio_idx) { case ASPECT_RATIO_SQUARE: - video_driver_ctl(RARCH_DISPLAY_CTL_SET_VIEWPORT_SQUARE_PIXEL, NULL); + cmd = RARCH_DISPLAY_CTL_SET_VIEWPORT_SQUARE_PIXEL; break; case ASPECT_RATIO_CORE: - video_driver_ctl(RARCH_DISPLAY_CTL_SET_VIEWPORT_CORE, NULL); + cmd = RARCH_DISPLAY_CTL_SET_VIEWPORT_CORE; break; case ASPECT_RATIO_CONFIG: - video_viewport_set_config(); + cmd = RARCH_DISPLAY_CTL_SET_VIEWPORT_CONFIG; break; default: break; } - video_driver_set_aspect_ratio_value(aspectratio_lut[aspectratio_index].value); + if (cmd != RARCH_DISPLAY_CTL_NONE) + video_driver_ctl(cmd, NULL); + + video_driver_set_aspect_ratio_value(aspectratio_lut[aspect_ratio_idx].value); vita->keep_aspect = true; vita->should_resize = true; diff --git a/gfx/video_driver.c b/gfx/video_driver.c index 36acb097a1..c81e1f4f8a 100644 --- a/gfx/video_driver.c +++ b/gfx/video_driver.c @@ -539,7 +539,7 @@ static bool init_video(void) /* Update core-dependent aspect ratio values. */ video_driver_ctl(RARCH_DISPLAY_CTL_SET_VIEWPORT_SQUARE_PIXEL, NULL); video_driver_ctl(RARCH_DISPLAY_CTL_SET_VIEWPORT_CORE, NULL); - video_viewport_set_config(); + video_driver_ctl(RARCH_DISPLAY_CTL_SET_VIEWPORT_CONFIG, NULL); /* Update CUSTOM viewport. */ custom_vp = video_viewport_get_custom(); @@ -1282,6 +1282,46 @@ static void video_viewport_set_square_pixel(unsigned width, unsigned height) aspectratio_lut[ASPECT_RATIO_SQUARE].value = (float)aspect_x / aspect_y; } +/** + * video_viewport_set_config: + * + * Sets viewport to config aspect ratio. + **/ +static bool video_viewport_set_config(void) +{ + settings_t *settings = config_get_ptr(); + struct retro_system_av_info *av_info = video_viewport_get_system_av_info(); + + if (settings->video.aspect_ratio < 0.0f) + { + struct retro_game_geometry *geom = &av_info->geometry; + + if (!geom) + return false; + + if (geom->aspect_ratio > 0.0f && settings->video.aspect_ratio_auto) + aspectratio_lut[ASPECT_RATIO_CONFIG].value = geom->aspect_ratio; + else + { + unsigned base_width = geom->base_width; + unsigned base_height = geom->base_height; + + /* Get around division by zero errors */ + if (base_width == 0) + base_width = 1; + if (base_height == 0) + base_height = 1; + aspectratio_lut[ASPECT_RATIO_CONFIG].value = + (float)base_width / base_height; /* 1:1 PAR. */ + } + } + else + aspectratio_lut[ASPECT_RATIO_CONFIG].value = + settings->video.aspect_ratio; + + return true; +} + bool video_driver_ctl(enum rarch_display_ctl_state state, void *data) { driver_t *driver = driver_get_ptr(); @@ -1291,6 +1331,8 @@ bool video_driver_ctl(enum rarch_display_ctl_state state, void *data) switch (state) { + case RARCH_DISPLAY_CTL_SET_VIEWPORT_CONFIG: + return video_viewport_set_config(); case RARCH_DISPLAY_CTL_SET_VIEWPORT_SQUARE_PIXEL: { struct retro_system_av_info *av_info = video_viewport_get_system_av_info(); @@ -1489,43 +1531,6 @@ bool video_driver_ctl(enum rarch_display_ctl_state state, void *data) return false; } -/** - * video_viewport_set_config: - * - * Sets viewport to config aspect ratio. - **/ -void video_viewport_set_config(void) -{ - settings_t *settings = config_get_ptr(); - struct retro_system_av_info *av_info = video_viewport_get_system_av_info(); - - if (settings->video.aspect_ratio < 0.0f) - { - struct retro_game_geometry *geom = &av_info->geometry; - - if (!geom) - return; - - if (geom->aspect_ratio > 0.0f && settings->video.aspect_ratio_auto) - aspectratio_lut[ASPECT_RATIO_CONFIG].value = geom->aspect_ratio; - else - { - unsigned base_width = geom->base_width; - unsigned base_height = geom->base_height; - - /* Get around division by zero errors */ - if (base_width == 0) - base_width = 1; - if (base_height == 0) - base_height = 1; - aspectratio_lut[ASPECT_RATIO_CONFIG].value = - (float)base_width / base_height; /* 1:1 PAR. */ - } - } - else - aspectratio_lut[ASPECT_RATIO_CONFIG].value = - settings->video.aspect_ratio; -} /** * video_viewport_get_scaled_integer: diff --git a/gfx/video_driver.h b/gfx/video_driver.h index adcd2ba2fb..23bca3b12d 100644 --- a/gfx/video_driver.h +++ b/gfx/video_driver.h @@ -295,6 +295,8 @@ enum rarch_display_ctl_state RARCH_DISPLAY_CTL_SET_ASPECT_RATIO, /* Sets viewport to aspect ratio set by core. */ RARCH_DISPLAY_CTL_SET_VIEWPORT_CORE, + /* Sets viewport to config aspect ratio. */ + RARCH_DISPLAY_CTL_SET_VIEWPORT_CONFIG, /* Sets viewport to square pixel aspect ratio based on width/height. */ RARCH_DISPLAY_CTL_SET_VIEWPORT_SQUARE_PIXEL, RARCH_DISPLAY_CTL_RESET_CUSTOM_VIEWPORT, @@ -434,13 +436,6 @@ void video_driver_cached_frame_get(const void **data, unsigned *width, void video_driver_menu_settings(void *data, void *subgroup_data, const char *parent_group); -/** - * video_viewport_set_config: - * - * Sets viewport to config aspect ratio. - **/ -void video_viewport_set_config(void); - /** * video_viewport_get_scaled_integer: * @vp : Viewport handle