diff --git a/gfx/d3d/d3d.cpp b/gfx/d3d/d3d.cpp index a87492cc06..9a5a1a007b 100644 --- a/gfx/d3d/d3d.cpp +++ b/gfx/d3d/d3d.cpp @@ -502,7 +502,7 @@ static void d3d_set_aspect_ratio(void *data, unsigned aspect_ratio_idx) break; case ASPECT_RATIO_CORE: - video_viewport_set_core(); + video_driver_ctl(RARCH_DISPLAY_CTL_SET_VIEWPORT_CORE, NULL); break; case ASPECT_RATIO_CONFIG: diff --git a/gfx/drivers/ctr_gfx.c b/gfx/drivers/ctr_gfx.c index 8a2f49cedf..4d1ff05cbc 100644 --- a/gfx/drivers/ctr_gfx.c +++ b/gfx/drivers/ctr_gfx.c @@ -784,7 +784,7 @@ static void ctr_set_aspect_ratio(void* data, unsigned aspectratio_index) break; case ASPECT_RATIO_CORE: - video_viewport_set_core(); + video_driver_ctl(RARCH_DISPLAY_CTL_SET_VIEWPORT_CORE, NULL); break; case ASPECT_RATIO_CONFIG: diff --git a/gfx/drivers/exynos_gfx.c b/gfx/drivers/exynos_gfx.c index 3428769939..322d82cfc8 100644 --- a/gfx/drivers/exynos_gfx.c +++ b/gfx/drivers/exynos_gfx.c @@ -1556,7 +1556,7 @@ static void exynos_set_aspect_ratio(void *data, unsigned aspect_ratio_idx) break; case ASPECT_RATIO_CORE: - video_viewport_set_core(); + video_driver_ctl(RARCH_DISPLAY_CTL_SET_VIEWPORT_CORE, NULL); break; case ASPECT_RATIO_CONFIG: diff --git a/gfx/drivers/gl.c b/gfx/drivers/gl.c index dc22666ee0..1aa0c962b0 100644 --- a/gfx/drivers/gl.c +++ b/gfx/drivers/gl.c @@ -3278,7 +3278,7 @@ static void gl_set_aspect_ratio(void *data, unsigned aspect_ratio_idx) break; case ASPECT_RATIO_CORE: - video_viewport_set_core(); + video_driver_ctl(RARCH_DISPLAY_CTL_SET_VIEWPORT_CORE, NULL); break; case ASPECT_RATIO_CONFIG: diff --git a/gfx/drivers/gx_gfx.c b/gfx/drivers/gx_gfx.c index 3035d9ac96..f4be27554b 100644 --- a/gfx/drivers/gx_gfx.c +++ b/gfx/drivers/gx_gfx.c @@ -451,14 +451,20 @@ static void gx_set_aspect_ratio(void *data, unsigned aspect_ratio_idx) const struct retro_system_av_info *av_info = (const struct retro_system_av_info*)video_viewport_get_system_av_info(); - if (aspect_ratio_idx == ASPECT_RATIO_SQUARE) - video_viewport_set_square_pixel( - av_info->geometry.base_width, - av_info->geometry.base_height); - else if (aspect_ratio_idx == ASPECT_RATIO_CORE) - video_viewport_set_core(); - else if (aspect_ratio_idx == ASPECT_RATIO_CONFIG) - video_viewport_set_config(); + switch (aspect_ratio_idx) + { + case ASPECT_RATIO_SQUARE: + video_viewport_set_square_pixel( + av_info->geometry.base_width, + av_info->geometry.base_height); + break; + case ASPECT_RATIO_CORE: + video_driver_ctl(RARCH_DISPLAY_CTL_SET_VIEWPORT_CORE, NULL); + break; + case ASPECT_RATIO_CONFIG: + video_viewport_set_config(); + break; + } video_driver_set_aspect_ratio_value( aspectratio_lut[aspect_ratio_idx].value); diff --git a/gfx/drivers/psp1_gfx.c b/gfx/drivers/psp1_gfx.c index 5d0bbfcf25..326af5bcd1 100644 --- a/gfx/drivers/psp1_gfx.c +++ b/gfx/drivers/psp1_gfx.c @@ -804,7 +804,7 @@ static void psp_set_aspect_ratio(void *data, unsigned aspectratio_index) break; case ASPECT_RATIO_CORE: - video_viewport_set_core(); + video_driver_ctl(RARCH_DISPLAY_CTL_SET_VIEWPORT_CORE, NULL); break; case ASPECT_RATIO_CONFIG: diff --git a/gfx/drivers/sdl2_gfx.c b/gfx/drivers/sdl2_gfx.c index f05ba7b67a..39f71a0ada 100644 --- a/gfx/drivers/sdl2_gfx.c +++ b/gfx/drivers/sdl2_gfx.c @@ -667,7 +667,7 @@ static void sdl2_poke_set_aspect_ratio(void *data, unsigned aspectratio_index) break; case ASPECT_RATIO_CORE: - video_viewport_set_core(); + video_driver_ctl(RARCH_DISPLAY_CTL_SET_VIEWPORT_CORE, NULL); break; case ASPECT_RATIO_CONFIG: diff --git a/gfx/drivers/sdl_gfx.c b/gfx/drivers/sdl_gfx.c index 1562dbe52b..58a5749d84 100644 --- a/gfx/drivers/sdl_gfx.c +++ b/gfx/drivers/sdl_gfx.c @@ -454,7 +454,7 @@ static void sdl_set_aspect_ratio(void *data, unsigned aspectratio_index) break; case ASPECT_RATIO_CORE: - video_viewport_set_core(); + video_driver_ctl(RARCH_DISPLAY_CTL_SET_VIEWPORT_CORE, NULL); break; case ASPECT_RATIO_CONFIG: diff --git a/gfx/drivers/vita2d_gfx.c b/gfx/drivers/vita2d_gfx.c index 2c893c00bd..4af568f4cf 100644 --- a/gfx/drivers/vita2d_gfx.c +++ b/gfx/drivers/vita2d_gfx.c @@ -509,7 +509,7 @@ static void vita_set_aspect_ratio(void *data, unsigned aspectratio_index) break; case ASPECT_RATIO_CORE: - video_viewport_set_core(); + video_driver_ctl(RARCH_DISPLAY_CTL_SET_VIEWPORT_CORE, NULL); break; case ASPECT_RATIO_CONFIG: diff --git a/gfx/video_driver.c b/gfx/video_driver.c index 2c795ce149..b0d2c0eb51 100644 --- a/gfx/video_driver.c +++ b/gfx/video_driver.c @@ -67,6 +67,40 @@ typedef struct video_driver_state static video_driver_state_t video_state; +char rotation_lut[4][32] = +{ + "Normal", + "90 deg", + "180 deg", + "270 deg" +}; + +struct aspect_ratio_elem aspectratio_lut[ASPECT_RATIO_END] = { + { "4:3", 1.3333f }, + { "16:9", 1.7778f }, + { "16:10", 1.6f }, + { "16:15", 16.0f / 15.0f }, + { "1:1", 1.0f }, + { "2:1", 2.0f }, + { "3:2", 1.5f }, + { "3:4", 0.75f }, + { "4:1", 4.0f }, + { "4:4", 1.0f }, + { "5:4", 1.25f }, + { "6:5", 1.2f }, + { "7:9", 0.7777f }, + { "8:3", 2.6666f }, + { "8:7", 1.1428f }, + { "19:12", 1.5833f }, + { "19:14", 1.3571f }, + { "30:17", 1.7647f }, + { "32:9", 3.5555f }, + { "Config", 0.0f }, + { "Square pixel", 1.0f }, + { "Core provided", 1.0f }, + { "Custom", 0.0f } +}; + static const video_driver_t *video_drivers[] = { #ifdef HAVE_OPENGL &video_gl, @@ -503,7 +537,7 @@ static bool init_video(void) /* Update core-dependent aspect ratio values. */ video_viewport_set_square_pixel(geom->base_width, geom->base_height); - video_viewport_set_core(); + video_driver_ctl(RARCH_DISPLAY_CTL_SET_VIEWPORT_CORE, NULL); video_viewport_set_config(); /* Update CUSTOM viewport. */ @@ -1224,6 +1258,23 @@ bool video_driver_ctl(enum rarch_display_ctl_state state, void *data) switch (state) { + case RARCH_DISPLAY_CTL_SET_VIEWPORT_CORE: + { + struct retro_system_av_info *av_info = + video_viewport_get_system_av_info(); + struct retro_game_geometry *geom = &av_info->geometry; + + if (!geom || geom->base_width <= 0.0f || geom->base_height <= 0.0f) + return false; + + /* Fallback to 1:1 pixel ratio if none provided */ + if (geom->aspect_ratio > 0.0f) + aspectratio_lut[ASPECT_RATIO_CORE].value = geom->aspect_ratio; + else + aspectratio_lut[ASPECT_RATIO_CORE].value = + (float)geom->base_width / geom->base_height; + } + return true; case RARCH_DISPLAY_CTL_RESET_CUSTOM_VIEWPORT: { struct video_viewport *custom_vp = video_viewport_get_custom(); diff --git a/gfx/video_driver.h b/gfx/video_driver.h index 050ab8752c..73276534ee 100644 --- a/gfx/video_driver.h +++ b/gfx/video_driver.h @@ -237,6 +237,8 @@ enum rarch_display_ctl_state RARCH_DISPLAY_CTL_HAS_WINDOWED, RARCH_DISPLAY_CTL_IS_FOCUSED, RARCH_DISPLAY_CTL_SET_ASPECT_RATIO, + /* Sets viewport to aspect ratio set by core. */ + RARCH_DISPLAY_CTL_SET_VIEWPORT_CORE, RARCH_DISPLAY_CTL_RESET_CUSTOM_VIEWPORT, RARCH_DISPLAY_CTL_READ_VIEWPORT, RARCH_DISPLAY_CTL_SET_NONBLOCK_STATE, diff --git a/gfx/video_viewport.c b/gfx/video_viewport.c index f526d2ae8f..02ae7fd780 100644 --- a/gfx/video_viewport.c +++ b/gfx/video_viewport.c @@ -16,40 +16,6 @@ #include "../general.h" -struct aspect_ratio_elem aspectratio_lut[ASPECT_RATIO_END] = { - { "4:3", 1.3333f }, - { "16:9", 1.7778f }, - { "16:10", 1.6f }, - { "16:15", 16.0f / 15.0f }, - { "1:1", 1.0f }, - { "2:1", 2.0f }, - { "3:2", 1.5f }, - { "3:4", 0.75f }, - { "4:1", 4.0f }, - { "4:4", 1.0f }, - { "5:4", 1.25f }, - { "6:5", 1.2f }, - { "7:9", 0.7777f }, - { "8:3", 2.6666f }, - { "8:7", 1.1428f }, - { "19:12", 1.5833f }, - { "19:14", 1.3571f }, - { "30:17", 1.7647f }, - { "32:9", 3.5555f }, - { "Config", 0.0f }, - { "Square pixel", 1.0f }, - { "Core provided", 1.0f }, - { "Custom", 0.0f } -}; - -char rotation_lut[4][32] = -{ - "Normal", - "90 deg", - "180 deg", - "270 deg" -}; - static struct retro_system_av_info video_viewport_av_info; /** @@ -84,28 +50,6 @@ void video_viewport_set_square_pixel(unsigned width, unsigned height) aspectratio_lut[ASPECT_RATIO_SQUARE].value = (float)aspect_x / aspect_y; } -/** - * video_viewport_set_core: - * - * Sets viewport to aspect ratio set by core. - **/ -void video_viewport_set_core(void) -{ - struct retro_system_av_info *av_info = - video_viewport_get_system_av_info(); - struct retro_game_geometry *geom = &av_info->geometry; - - if (!geom || geom->base_width <= 0.0f || geom->base_height <= 0.0f) - return; - - /* Fallback to 1:1 pixel ratio if none provided */ - if (geom->aspect_ratio > 0.0f) - aspectratio_lut[ASPECT_RATIO_CORE].value = geom->aspect_ratio; - else - aspectratio_lut[ASPECT_RATIO_CORE].value = - (float)geom->base_width / geom->base_height; -} - /** * video_viewport_set_config: * diff --git a/gfx/video_viewport.h b/gfx/video_viewport.h index bf0f6a751c..a14d91db41 100644 --- a/gfx/video_viewport.h +++ b/gfx/video_viewport.h @@ -109,13 +109,6 @@ extern struct aspect_ratio_elem aspectratio_lut[ASPECT_RATIO_END]; **/ void video_viewport_set_square_pixel(unsigned width, unsigned height); -/** - * video_viewport_set_core: - * - * Sets viewport to aspect ratio set by core. - **/ -void video_viewport_set_core(void); - /** * video_viewport_set_config: *