2015-01-18 22:59:57 +00:00
|
|
|
/* RetroArch - A frontend for libretro.
|
|
|
|
* Copyright (C) 2010-2014 - Hans-Kristian Arntzen
|
|
|
|
* Copyright (C) 2011-2015 - Daniel De Matteis
|
|
|
|
*
|
|
|
|
* RetroArch is free software: you can redistribute it and/or modify it under the terms
|
|
|
|
* of the GNU General Public License as published by the Free Software Found-
|
|
|
|
* ation, either version 3 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
|
|
|
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
|
|
|
* PURPOSE. See the GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along with RetroArch.
|
|
|
|
* If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "video_viewport.h"
|
2015-01-18 23:01:03 +00:00
|
|
|
#include "../general.h"
|
2015-01-18 22:59:57 +00:00
|
|
|
|
2015-05-20 21:13:39 +00:00
|
|
|
static video_viewport_t video_viewport_custom;
|
|
|
|
|
2015-01-18 22:59:57 +00:00
|
|
|
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"
|
|
|
|
};
|
|
|
|
|
2015-05-20 16:57:17 +00:00
|
|
|
static struct retro_system_av_info video_viewport_av_info;
|
|
|
|
|
2015-01-18 22:59:57 +00:00
|
|
|
/**
|
|
|
|
* 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;
|
|
|
|
|
2015-02-14 05:16:24 +00:00
|
|
|
len = min(width, height);
|
|
|
|
highest = 1;
|
|
|
|
|
2015-01-18 22:59:57 +00:00
|
|
|
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_core:
|
|
|
|
*
|
|
|
|
* Sets viewport to aspect ratio set by core.
|
|
|
|
**/
|
|
|
|
void video_viewport_set_core(void)
|
|
|
|
{
|
2015-05-20 16:57:17 +00:00
|
|
|
struct retro_system_av_info *av_info =
|
|
|
|
video_viewport_get_system_av_info();
|
|
|
|
struct retro_game_geometry *geom = &av_info->geometry;
|
2015-01-18 22:59:57 +00:00
|
|
|
|
2015-02-14 05:16:24 +00:00
|
|
|
if (!geom || geom->base_width <= 0.0f || geom->base_height <= 0.0f)
|
2015-01-18 22:59:57 +00:00
|
|
|
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:
|
|
|
|
*
|
|
|
|
* Sets viewport to config aspect ratio.
|
|
|
|
**/
|
|
|
|
void video_viewport_set_config(void)
|
|
|
|
{
|
2015-03-20 19:43:22 +00:00
|
|
|
settings_t *settings = config_get_ptr();
|
2015-05-20 16:57:17 +00:00
|
|
|
struct retro_system_av_info *av_info = video_viewport_get_system_av_info();
|
2015-03-20 19:43:22 +00:00
|
|
|
|
|
|
|
if (settings->video.aspect_ratio < 0.0f)
|
2015-01-18 22:59:57 +00:00
|
|
|
{
|
2015-05-20 16:57:17 +00:00
|
|
|
struct retro_game_geometry *geom = &av_info->geometry;
|
2015-01-18 22:59:57 +00:00
|
|
|
|
2015-03-20 19:43:22 +00:00
|
|
|
if (geom && geom->aspect_ratio > 0.0f && settings->video.aspect_ratio_auto)
|
2015-01-18 22:59:57 +00:00
|
|
|
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 =
|
2015-03-20 19:43:22 +00:00
|
|
|
settings->video.aspect_ratio;
|
2015-01-18 22:59:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* video_viewport_get_scaled_integer:
|
|
|
|
* @vp : Viewport handle
|
|
|
|
* @width : Width.
|
|
|
|
* @height : Height.
|
|
|
|
* @aspect_ratio : Aspect ratio (in float).
|
|
|
|
* @keep_aspect : Preserve aspect ratio?
|
|
|
|
*
|
|
|
|
* Gets viewport scaling dimensions based on
|
|
|
|
* scaled integer aspect ratio.
|
|
|
|
**/
|
2015-02-14 05:12:53 +00:00
|
|
|
void video_viewport_get_scaled_integer(struct video_viewport *vp,
|
2015-01-18 22:59:57 +00:00
|
|
|
unsigned width, unsigned height,
|
|
|
|
float aspect_ratio, bool keep_aspect)
|
|
|
|
{
|
|
|
|
int padding_x = 0, padding_y = 0;
|
2015-03-20 19:43:22 +00:00
|
|
|
settings_t *settings = config_get_ptr();
|
2015-02-14 05:12:53 +00:00
|
|
|
|
|
|
|
if (!vp)
|
|
|
|
return;
|
2015-01-18 22:59:57 +00:00
|
|
|
|
2015-03-20 19:43:22 +00:00
|
|
|
if (settings->video.aspect_ratio_idx == ASPECT_RATIO_CUSTOM)
|
2015-01-18 22:59:57 +00:00
|
|
|
{
|
2015-05-20 16:57:17 +00:00
|
|
|
struct video_viewport *custom = video_viewport_get_custom();
|
2015-01-18 22:59:57 +00:00
|
|
|
|
2015-02-14 04:52:05 +00:00
|
|
|
if (custom)
|
|
|
|
{
|
|
|
|
padding_x = width - custom->width;
|
|
|
|
padding_y = height - custom->height;
|
|
|
|
width = custom->width;
|
|
|
|
height = custom->height;
|
|
|
|
}
|
2015-01-18 22:59:57 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
unsigned base_width;
|
|
|
|
/* Use system reported sizes as these define the
|
|
|
|
* geometry for the "normal" case. */
|
2015-05-20 16:57:17 +00:00
|
|
|
struct retro_system_av_info *av_info = video_viewport_get_system_av_info();
|
|
|
|
unsigned base_height = av_info ? av_info->geometry.base_height : 0;
|
2015-01-18 22:59:57 +00:00
|
|
|
|
|
|
|
if (base_height == 0)
|
|
|
|
base_height = 1;
|
|
|
|
|
|
|
|
/* Account for non-square pixels.
|
|
|
|
* This is sort of contradictory with the goal of integer scale,
|
|
|
|
* but it is desirable in some cases.
|
|
|
|
*
|
|
|
|
* If square pixels are used, base_height will be equal to
|
2015-03-21 03:43:18 +00:00
|
|
|
* global->system.av_info.base_height. */
|
2015-01-18 22:59:57 +00:00
|
|
|
base_width = (unsigned)roundf(base_height * aspect_ratio);
|
|
|
|
|
|
|
|
/* Make sure that we don't get 0x scale ... */
|
|
|
|
if (width >= base_width && height >= base_height)
|
|
|
|
{
|
|
|
|
if (keep_aspect)
|
|
|
|
{
|
|
|
|
/* X/Y scale must be same. */
|
|
|
|
unsigned max_scale = min(width / base_width, height / base_height);
|
|
|
|
padding_x = width - base_width * max_scale;
|
|
|
|
padding_y = height - base_height * max_scale;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* X/Y can be independent, each scaled as much as possible. */
|
|
|
|
padding_x = width % base_width;
|
|
|
|
padding_y = height % base_height;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
width -= padding_x;
|
|
|
|
height -= padding_y;
|
|
|
|
}
|
|
|
|
|
|
|
|
vp->width = width;
|
|
|
|
vp->height = height;
|
|
|
|
vp->x = padding_x / 2;
|
|
|
|
vp->y = padding_y / 2;
|
|
|
|
}
|
2015-05-20 16:57:17 +00:00
|
|
|
|
|
|
|
struct retro_system_av_info *video_viewport_get_system_av_info(void)
|
|
|
|
{
|
|
|
|
return (struct retro_system_av_info*)&video_viewport_av_info;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct video_viewport *video_viewport_get_custom(void)
|
|
|
|
{
|
2015-05-20 21:13:39 +00:00
|
|
|
return &video_viewport_custom;
|
2015-05-20 16:57:17 +00:00
|
|
|
}
|
2015-05-20 17:12:27 +00:00
|
|
|
|
|
|
|
void video_viewport_reset_custom(void)
|
|
|
|
{
|
|
|
|
struct video_viewport *custom_vp = video_viewport_get_custom();
|
|
|
|
if (!custom_vp)
|
|
|
|
return;
|
|
|
|
|
|
|
|
custom_vp->width = 0;
|
|
|
|
custom_vp->height = 0;
|
|
|
|
custom_vp->x = 0;
|
|
|
|
custom_vp->y = 0;
|
|
|
|
}
|