Create RARCH_DISPLAY_CTL_SET_VIEWPORT_SQUARE_PIXEL

This commit is contained in:
twinaphex 2015-11-21 12:54:38 +01:00
parent 4db97a5300
commit 5b44bd0e6b
13 changed files with 56 additions and 85 deletions

View file

@ -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:

View file

@ -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:

View file

@ -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:

View file

@ -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:

View file

@ -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);

View file

@ -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:

View file

@ -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:

View file

@ -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:

View file

@ -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:

View file

@ -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 =

View file

@ -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,

View file

@ -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:
*

View file

@ -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:
*