From 5b44bd0e6b5692a5691f2b5d8046110dd55b7a20 Mon Sep 17 00:00:00 2001 From: twinaphex Date: Sat, 21 Nov 2015 12:54:38 +0100 Subject: [PATCH] Create RARCH_DISPLAY_CTL_SET_VIEWPORT_SQUARE_PIXEL --- gfx/d3d/d3d.cpp | 5 +---- gfx/drivers/ctr_gfx.c | 5 +---- gfx/drivers/exynos_gfx.c | 6 +----- gfx/drivers/gl.c | 6 +----- gfx/drivers/gx_gfx.c | 9 ++------ gfx/drivers/psp1_gfx.c | 5 +---- gfx/drivers/sdl2_gfx.c | 5 +---- gfx/drivers/sdl_gfx.c | 6 +----- gfx/drivers/vita2d_gfx.c | 6 +----- gfx/video_driver.c | 45 +++++++++++++++++++++++++++++++++++++++- gfx/video_driver.h | 2 ++ gfx/video_viewport.c | 32 ---------------------------- gfx/video_viewport.h | 9 -------- 13 files changed, 56 insertions(+), 85 deletions(-) diff --git a/gfx/d3d/d3d.cpp b/gfx/d3d/d3d.cpp index 9a5a1a007b..c39a4951d3 100644 --- a/gfx/d3d/d3d.cpp +++ b/gfx/d3d/d3d.cpp @@ -491,14 +491,11 @@ 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; - struct retro_system_av_info *av_info = video_viewport_get_system_av_info(); switch (aspect_ratio_idx) { case ASPECT_RATIO_SQUARE: - video_viewport_set_square_pixel( - av_info->geometry.base_width, - av_info->geometry.base_height); + video_driver_ctl(RARCH_DISPLAY_CTL_SET_VIEWPORT_SQUARE_PIXEL, NULL); break; case ASPECT_RATIO_CORE: diff --git a/gfx/drivers/ctr_gfx.c b/gfx/drivers/ctr_gfx.c index 4d1ff05cbc..b4bf59efc4 100644 --- a/gfx/drivers/ctr_gfx.c +++ b/gfx/drivers/ctr_gfx.c @@ -773,14 +773,11 @@ static void ctr_set_filtering(void* data, unsigned index, bool smooth) static void ctr_set_aspect_ratio(void* data, unsigned aspectratio_index) { ctr_video_t *ctr = (ctr_video_t*)data; - struct retro_system_av_info *av_info = video_viewport_get_system_av_info(); switch (aspectratio_index) { case ASPECT_RATIO_SQUARE: - video_viewport_set_square_pixel( - av_info->geometry.base_width, - av_info->geometry.base_height); + video_driver_ctl(RARCH_DISPLAY_CTL_SET_VIEWPORT_SQUARE_PIXEL, NULL); break; case ASPECT_RATIO_CORE: diff --git a/gfx/drivers/exynos_gfx.c b/gfx/drivers/exynos_gfx.c index 322d82cfc8..2cabc6b92e 100644 --- a/gfx/drivers/exynos_gfx.c +++ b/gfx/drivers/exynos_gfx.c @@ -1544,15 +1544,11 @@ 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; - struct retro_system_av_info *av_info = - video_viewport_get_system_av_info(); switch (aspect_ratio_idx) { case ASPECT_RATIO_SQUARE: - video_viewport_set_square_pixel( - av_info->geometry.base_width, - av_info->geometry.base_height); + video_driver_ctl(RARCH_DISPLAY_CTL_SET_VIEWPORT_SQUARE_PIXEL, NULL); break; case ASPECT_RATIO_CORE: diff --git a/gfx/drivers/gl.c b/gfx/drivers/gl.c index 1aa0c962b0..88f84d4bf5 100644 --- a/gfx/drivers/gl.c +++ b/gfx/drivers/gl.c @@ -3266,15 +3266,11 @@ 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; - const struct retro_system_av_info *av_info = - (const struct retro_system_av_info*)video_viewport_get_system_av_info(); switch (aspect_ratio_idx) { case ASPECT_RATIO_SQUARE: - video_viewport_set_square_pixel( - av_info->geometry.base_width, - av_info->geometry.base_height); + video_driver_ctl(RARCH_DISPLAY_CTL_SET_VIEWPORT_SQUARE_PIXEL, NULL); break; case ASPECT_RATIO_CORE: diff --git a/gfx/drivers/gx_gfx.c b/gfx/drivers/gx_gfx.c index f4be27554b..adf0df795b 100644 --- a/gfx/drivers/gx_gfx.c +++ b/gfx/drivers/gx_gfx.c @@ -446,17 +446,12 @@ static void gx_set_video_mode(void *data, unsigned fbWidth, unsigned lines, static void gx_set_aspect_ratio(void *data, unsigned aspect_ratio_idx) { - driver_t *driver = driver_get_ptr(); - gx_video_t *gx = (gx_video_t*)driver->video_data; - const struct retro_system_av_info *av_info = - (const struct retro_system_av_info*)video_viewport_get_system_av_info(); + gx_video_t *gx = (gx_video_t*)data; switch (aspect_ratio_idx) { case ASPECT_RATIO_SQUARE: - video_viewport_set_square_pixel( - av_info->geometry.base_width, - av_info->geometry.base_height); + video_driver_ctl(RARCH_DISPLAY_CTL_SET_VIEWPORT_SQUARE_PIXEL, NULL); break; case ASPECT_RATIO_CORE: video_driver_ctl(RARCH_DISPLAY_CTL_SET_VIEWPORT_CORE, NULL); diff --git a/gfx/drivers/psp1_gfx.c b/gfx/drivers/psp1_gfx.c index 326af5bcd1..de560b047c 100644 --- a/gfx/drivers/psp1_gfx.c +++ b/gfx/drivers/psp1_gfx.c @@ -793,14 +793,11 @@ static void psp_set_filtering(void *data, unsigned index, bool smooth) static void psp_set_aspect_ratio(void *data, unsigned aspectratio_index) { psp1_video_t *psp = (psp1_video_t*)data; - struct retro_system_av_info *av_info = video_viewport_get_system_av_info(); switch (aspectratio_index) { case ASPECT_RATIO_SQUARE: - video_viewport_set_square_pixel( - av_info->geometry.base_width, - av_info->geometry.base_height); + video_driver_ctl(RARCH_DISPLAY_CTL_SET_VIEWPORT_SQUARE_PIXEL, NULL); break; case ASPECT_RATIO_CORE: diff --git a/gfx/drivers/sdl2_gfx.c b/gfx/drivers/sdl2_gfx.c index 39f71a0ada..f4e9c5f605 100644 --- a/gfx/drivers/sdl2_gfx.c +++ b/gfx/drivers/sdl2_gfx.c @@ -656,14 +656,11 @@ static void sdl2_poke_set_filtering(void *data, unsigned index, bool smooth) static void sdl2_poke_set_aspect_ratio(void *data, unsigned aspectratio_index) { sdl2_video_t *vid = (sdl2_video_t*)data; - const struct retro_system_av_info *av_info = - (const struct retro_system_av_info*)video_viewport_get_system_av_info(); switch (aspectratio_index) { case ASPECT_RATIO_SQUARE: - video_viewport_set_square_pixel(av_info->geometry.base_width, - av_info->geometry.base_height); + video_driver_ctl(RARCH_DISPLAY_CTL_SET_VIEWPORT_SQUARE_PIXEL, NULL); break; case ASPECT_RATIO_CORE: diff --git a/gfx/drivers/sdl_gfx.c b/gfx/drivers/sdl_gfx.c index 58a5749d84..44940f0209 100644 --- a/gfx/drivers/sdl_gfx.c +++ b/gfx/drivers/sdl_gfx.c @@ -443,14 +443,10 @@ static void sdl_set_filtering(void *data, unsigned index, bool smooth) static void sdl_set_aspect_ratio(void *data, unsigned aspectratio_index) { - struct retro_system_av_info *av_info = video_viewport_get_system_av_info(); - switch (aspectratio_index) { case ASPECT_RATIO_SQUARE: - video_viewport_set_square_pixel( - av_info->geometry.base_width, - av_info->geometry.base_height); + video_driver_ctl(RARCH_DISPLAY_CTL_SET_VIEWPORT_SQUARE_PIXEL, NULL); break; case ASPECT_RATIO_CORE: diff --git a/gfx/drivers/vita2d_gfx.c b/gfx/drivers/vita2d_gfx.c index 4af568f4cf..dd0d4b7fdc 100644 --- a/gfx/drivers/vita2d_gfx.c +++ b/gfx/drivers/vita2d_gfx.c @@ -498,14 +498,10 @@ static void vita_set_aspect_ratio(void *data, unsigned aspectratio_index) { vita_video_t *vita = (vita_video_t*)data; - struct retro_system_av_info *av_info = video_viewport_get_system_av_info(); - switch (aspectratio_index) { case ASPECT_RATIO_SQUARE: - video_viewport_set_square_pixel( - av_info->geometry.base_width, - av_info->geometry.base_height); + video_driver_ctl(RARCH_DISPLAY_CTL_SET_VIEWPORT_SQUARE_PIXEL, NULL); break; case ASPECT_RATIO_CORE: diff --git a/gfx/video_driver.c b/gfx/video_driver.c index b0d2c0eb51..ccc6d0f626 100644 --- a/gfx/video_driver.c +++ b/gfx/video_driver.c @@ -536,7 +536,7 @@ static bool init_video(void) scale = video_state.filter.scale; /* Update core-dependent aspect ratio values. */ - video_viewport_set_square_pixel(geom->base_width, geom->base_height); + 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(); @@ -1249,6 +1249,38 @@ void video_driver_menu_settings(void *data, void *subgroup_data, const char *par #endif } +/** + * video_viewport_set_square_pixel: + * @width : Width. + * @height : Height. + * + * Sets viewport to square pixel aspect ratio based on @width and @height. + **/ +static void video_viewport_set_square_pixel(unsigned width, unsigned height) +{ + unsigned len, highest, i, aspect_x, aspect_y; + if (width == 0 || height == 0) + return; + + len = min(width, height); + highest = 1; + + for (i = 1; i < len; i++) + { + if ((width % i) == 0 && (height % i) == 0) + highest = i; + } + + aspect_x = width / highest; + aspect_y = height / highest; + + snprintf(aspectratio_lut[ASPECT_RATIO_SQUARE].name, + sizeof(aspectratio_lut[ASPECT_RATIO_SQUARE].name), + "%u:%u (1:1 PAR)", aspect_x, aspect_y); + + aspectratio_lut[ASPECT_RATIO_SQUARE].value = (float)aspect_x / aspect_y; +} + bool video_driver_ctl(enum rarch_display_ctl_state state, void *data) { driver_t *driver = driver_get_ptr(); @@ -1258,6 +1290,17 @@ bool video_driver_ctl(enum rarch_display_ctl_state state, void *data) switch (state) { + case RARCH_DISPLAY_CTL_SET_VIEWPORT_SQUARE_PIXEL: + { + struct retro_system_av_info *av_info = video_viewport_get_system_av_info(); + struct retro_game_geometry *geom = av_info ? &av_info->geometry : NULL; + + if (!geom) + return false; + + video_viewport_set_square_pixel(geom->base_width, geom->base_height); + } + return true; case RARCH_DISPLAY_CTL_SET_VIEWPORT_CORE: { struct retro_system_av_info *av_info = diff --git a/gfx/video_driver.h b/gfx/video_driver.h index 73276534ee..31da94382e 100644 --- a/gfx/video_driver.h +++ b/gfx/video_driver.h @@ -239,6 +239,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 square pixel aspect ratio based on width/height. */ + RARCH_DISPLAY_CTL_SET_VIEWPORT_SQUARE_PIXEL, 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 02ae7fd780..d6ca776896 100644 --- a/gfx/video_viewport.c +++ b/gfx/video_viewport.c @@ -18,38 +18,6 @@ static struct retro_system_av_info video_viewport_av_info; -/** - * video_viewport_set_square_pixel: - * @width : Width. - * @height : Height. - * - * Sets viewport to square pixel aspect ratio based on @width and @height. - **/ -void video_viewport_set_square_pixel(unsigned width, unsigned height) -{ - unsigned len, highest, i, aspect_x, aspect_y; - if (width == 0 || height == 0) - return; - - len = min(width, height); - highest = 1; - - for (i = 1; i < len; i++) - { - if ((width % i) == 0 && (height % i) == 0) - highest = i; - } - - aspect_x = width / highest; - aspect_y = height / highest; - - snprintf(aspectratio_lut[ASPECT_RATIO_SQUARE].name, - sizeof(aspectratio_lut[ASPECT_RATIO_SQUARE].name), - "%u:%u (1:1 PAR)", aspect_x, aspect_y); - - aspectratio_lut[ASPECT_RATIO_SQUARE].value = (float)aspect_x / aspect_y; -} - /** * video_viewport_set_config: * diff --git a/gfx/video_viewport.h b/gfx/video_viewport.h index a14d91db41..8e4079ed62 100644 --- a/gfx/video_viewport.h +++ b/gfx/video_viewport.h @@ -100,15 +100,6 @@ struct aspect_ratio_elem extern struct aspect_ratio_elem aspectratio_lut[ASPECT_RATIO_END]; -/** - * video_viewport_set_square_pixel: - * @width : Width. - * @height : Height. - * - * Sets viewport to square pixel aspect ratio based on @width and @height. - **/ -void video_viewport_set_square_pixel(unsigned width, unsigned height); - /** * video_viewport_set_config: *