mirror of
https://github.com/libretro/RetroArch.git
synced 2024-11-23 16:09:47 +00:00
Refactor viewport handling/aspect ratio scaling.
This mirrors the use of video_viewport_get_scaled_integer for non-integer scaling at various aspect ratios. Two variants are provided, one with implicit device and desired ratios and one with explicit ratios. Also added a flag to video_viewport_get_scaled_integer to indicate the direction of positive y.
This commit is contained in:
parent
05faba73e3
commit
2805694378
@ -1316,74 +1316,35 @@ void d3d9_calculate_rect(d3d9_video_t *d3d,
|
||||
{
|
||||
float device_aspect = (float)*width / *height;
|
||||
settings_t *settings = config_get_ptr();
|
||||
bool scale_integer = settings->bools.video_scale_integer;
|
||||
bool video_scale_integer = settings->bools.video_scale_integer;
|
||||
struct video_viewport vp;
|
||||
|
||||
video_driver_get_size(width, height);
|
||||
|
||||
*x = 0;
|
||||
*y = 0;
|
||||
vp.x = 0;
|
||||
vp.y = 0;
|
||||
vp.width = width;
|
||||
vp.height = height;
|
||||
vp.full_width = width;
|
||||
vp.full_height = height;
|
||||
|
||||
if (scale_integer && !force_full)
|
||||
if (video_scale_integer && !force_full)
|
||||
{
|
||||
struct video_viewport vp;
|
||||
|
||||
vp.x = 0;
|
||||
vp.y = 0;
|
||||
vp.width = 0;
|
||||
vp.height = 0;
|
||||
vp.full_width = 0;
|
||||
vp.full_height = 0;
|
||||
|
||||
video_viewport_get_scaled_integer(&vp,
|
||||
*width,
|
||||
*height,
|
||||
video_driver_get_aspect_ratio(),
|
||||
d3d->keep_aspect);
|
||||
|
||||
*x = vp.x;
|
||||
*y = vp.y;
|
||||
*width = vp.width;
|
||||
*height = vp.height;
|
||||
d3d->keep_aspect,
|
||||
true);
|
||||
}
|
||||
else if (d3d->keep_aspect && !force_full)
|
||||
{
|
||||
float desired_aspect = video_driver_get_aspect_ratio();
|
||||
|
||||
#if defined(HAVE_MENU)
|
||||
if (settings->uints.video_aspect_ratio_idx == ASPECT_RATIO_CUSTOM)
|
||||
{
|
||||
video_viewport_t *custom_vp = &settings->video_viewport_custom;
|
||||
*x = custom_vp->x;
|
||||
*y = custom_vp->y;
|
||||
*width = custom_vp->width;
|
||||
*height = custom_vp->height;
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
float delta;
|
||||
|
||||
if (fabsf(device_aspect - desired_aspect) < 0.0001f)
|
||||
{
|
||||
/* If the aspect ratios of screen and desired aspect
|
||||
* ratio are sufficiently equal (floating point stuff),
|
||||
* assume they are actually equal.
|
||||
*/
|
||||
}
|
||||
else if (device_aspect > desired_aspect)
|
||||
{
|
||||
delta = (desired_aspect / device_aspect - 1.0f) / 2.0f + 0.5f;
|
||||
*x = (int)(roundf(*width * (0.5f - delta)));
|
||||
*width = (unsigned)(roundf(2.0f * (*width) * delta));
|
||||
}
|
||||
else
|
||||
{
|
||||
delta = (device_aspect / desired_aspect - 1.0f) / 2.0f + 0.5f;
|
||||
*y = (int)(roundf(*height * (0.5f - delta)));
|
||||
*height = (unsigned)(roundf(2.0f * (*height) * delta));
|
||||
}
|
||||
}
|
||||
video_viewport_get_scaled_aspect(vp, viewport_width, viewport_height, true);
|
||||
}
|
||||
*x = vp.x;
|
||||
*y = vp.y;
|
||||
*width = vp.width;
|
||||
*height = vp.height;
|
||||
}
|
||||
|
||||
void d3d9_set_rotation(void *data, unsigned rot)
|
||||
|
@ -762,52 +762,14 @@ static void ctr_update_viewport(
|
||||
|
||||
if (video_scale_integer)
|
||||
{
|
||||
/* TODO: does CTR use top-left or bottom-left coordinates? assuming top-left. */
|
||||
video_viewport_get_scaled_integer(&ctr->vp, ctr->vp.full_width,
|
||||
ctr->vp.full_height, desired_aspect, ctr->keep_aspect);
|
||||
ctr->vp.full_height, desired_aspect, ctr->keep_aspect,
|
||||
true);
|
||||
}
|
||||
else if (ctr->keep_aspect)
|
||||
{
|
||||
#if defined(HAVE_MENU)
|
||||
if (aspect_ratio_idx == ASPECT_RATIO_CUSTOM)
|
||||
{
|
||||
x = custom_vp_x;
|
||||
y = custom_vp_y;
|
||||
width = custom_vp_width;
|
||||
height = custom_vp_height;
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
float delta;
|
||||
float device_aspect = ((float)ctr->vp.full_width) / ctr->vp.full_height;
|
||||
|
||||
if (fabsf(device_aspect - desired_aspect) < 0.0001f)
|
||||
{
|
||||
/* If the aspect ratios of screen and desired aspect
|
||||
* ratio are sufficiently equal (floating point stuff),
|
||||
* assume they are actually equal.
|
||||
*/
|
||||
}
|
||||
else if (device_aspect > desired_aspect)
|
||||
{
|
||||
delta = (desired_aspect / device_aspect - 1.0f)
|
||||
/ 2.0f + 0.5f;
|
||||
x = (int)roundf(width * (0.5f - delta));
|
||||
width = (unsigned)roundf(2.0f * width * delta);
|
||||
}
|
||||
else
|
||||
{
|
||||
delta = (device_aspect / desired_aspect - 1.0f)
|
||||
/ 2.0f + 0.5f;
|
||||
y = (int)roundf(height * (0.5f - delta));
|
||||
height = (unsigned)roundf(2.0f * height * delta);
|
||||
}
|
||||
}
|
||||
|
||||
ctr->vp.x = x;
|
||||
ctr->vp.y = y;
|
||||
ctr->vp.width = width;
|
||||
ctr->vp.height = height;
|
||||
video_viewport_get_scaled_aspect(&ctr->vp, width, height, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -1164,74 +1164,34 @@ static void d3d8_calculate_rect(void *data,
|
||||
settings_t *settings = config_get_ptr();
|
||||
bool video_scale_integer = settings->bools.video_scale_integer;
|
||||
unsigned aspect_ratio_idx = settings->uints.video_aspect_ratio_idx;
|
||||
struct video_viewport vp;
|
||||
|
||||
video_driver_get_size(width, height);
|
||||
|
||||
*x = 0;
|
||||
*y = 0;
|
||||
vp.x = 0;
|
||||
vp.y = 0;
|
||||
vp.width = width;
|
||||
vp.height = height;
|
||||
vp.full_width = width;
|
||||
vp.full_height = height;
|
||||
|
||||
if (video_scale_integer && !force_full)
|
||||
{
|
||||
struct video_viewport vp;
|
||||
|
||||
vp.x = 0;
|
||||
vp.y = 0;
|
||||
vp.width = 0;
|
||||
vp.height = 0;
|
||||
vp.full_width = 0;
|
||||
vp.full_height = 0;
|
||||
|
||||
video_viewport_get_scaled_integer(&vp,
|
||||
*width,
|
||||
*height,
|
||||
video_driver_get_aspect_ratio(),
|
||||
d3d->keep_aspect);
|
||||
|
||||
*x = vp.x;
|
||||
*y = vp.y;
|
||||
*width = vp.width;
|
||||
*height = vp.height;
|
||||
d3d->keep_aspect,
|
||||
true);
|
||||
}
|
||||
else if (d3d->keep_aspect && !force_full)
|
||||
{
|
||||
float desired_aspect = video_driver_get_aspect_ratio();
|
||||
|
||||
#if defined(HAVE_MENU)
|
||||
if (aspect_ratio_idx == ASPECT_RATIO_CUSTOM)
|
||||
{
|
||||
video_viewport_t *custom_vp = &settings->video_viewport_custom;
|
||||
|
||||
*x = custom_vp->x;
|
||||
*y = custom_vp->y;
|
||||
*width = custom_vp->width;
|
||||
*height = custom_vp->height;
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
float delta;
|
||||
|
||||
if (fabsf(device_aspect - desired_aspect) < 0.0001f)
|
||||
{
|
||||
/* If the aspect ratios of screen and desired aspect
|
||||
* ratio are sufficiently equal (floating point stuff),
|
||||
* assume they are actually equal.
|
||||
*/
|
||||
}
|
||||
else if (device_aspect > desired_aspect)
|
||||
{
|
||||
delta = (desired_aspect / device_aspect - 1.0f) / 2.0f + 0.5f;
|
||||
*x = (int)(roundf(*width * (0.5f - delta)));
|
||||
*width = (unsigned)(roundf(2.0f * (*width) * delta));
|
||||
}
|
||||
else
|
||||
{
|
||||
delta = (device_aspect / desired_aspect - 1.0f) / 2.0f + 0.5f;
|
||||
*y = (int)(roundf(*height * (0.5f - delta)));
|
||||
*height = (unsigned)(roundf(2.0f * (*height) * delta));
|
||||
}
|
||||
}
|
||||
video_viewport_get_scaled_aspect(vp, viewport_width, viewport_height, true);
|
||||
}
|
||||
*x = vp.x;
|
||||
*y = vp.y;
|
||||
*width = vp.width;
|
||||
*height = vp.height;
|
||||
}
|
||||
|
||||
static void d3d8_set_viewport(void *data,
|
||||
|
@ -1227,54 +1227,16 @@ static void gl1_set_viewport(gl1_t *gl1,
|
||||
video_viewport_get_scaled_integer(&gl1->vp,
|
||||
viewport_width, viewport_height,
|
||||
video_driver_get_aspect_ratio(),
|
||||
gl1->flags & GL1_FLAG_KEEP_ASPECT);
|
||||
gl1->flags & GL1_FLAG_KEEP_ASPECT, false);
|
||||
viewport_width = gl1->vp.width;
|
||||
viewport_height = gl1->vp.height;
|
||||
}
|
||||
else if ((gl1->flags & GL1_FLAG_KEEP_ASPECT) && !force_full)
|
||||
{
|
||||
float desired_aspect = video_driver_get_aspect_ratio();
|
||||
|
||||
#if defined(HAVE_MENU)
|
||||
if (settings->uints.video_aspect_ratio_idx == ASPECT_RATIO_CUSTOM)
|
||||
{
|
||||
video_viewport_t *custom_vp = &settings->video_viewport_custom;
|
||||
/* OpenGL has bottom-left origin viewport. */
|
||||
x = custom_vp->x;
|
||||
y = height - custom_vp->y - custom_vp->height;
|
||||
viewport_width = custom_vp->width;
|
||||
viewport_height = custom_vp->height;
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
float delta;
|
||||
|
||||
if (fabsf(device_aspect - desired_aspect) < 0.0001f)
|
||||
{
|
||||
/* If the aspect ratios of screen and desired aspect
|
||||
* ratio are sufficiently equal (floating point stuff),
|
||||
* assume they are actually equal.
|
||||
*/
|
||||
}
|
||||
else if (device_aspect > desired_aspect)
|
||||
{
|
||||
delta = (desired_aspect / device_aspect - 1.0f) / 2.0f + 0.5f;
|
||||
x = (int)roundf(viewport_width * (0.5f - delta));
|
||||
viewport_width = (unsigned)roundf(2.0f * viewport_width * delta);
|
||||
}
|
||||
else
|
||||
{
|
||||
delta = (device_aspect / desired_aspect - 1.0f) / 2.0f + 0.5f;
|
||||
y = (int)roundf(viewport_height * (0.5f - delta));
|
||||
viewport_height = (unsigned)roundf(2.0f * viewport_height * delta);
|
||||
}
|
||||
}
|
||||
|
||||
gl1->vp.x = x;
|
||||
gl1->vp.y = y;
|
||||
gl1->vp.width = viewport_width;
|
||||
gl1->vp.height = viewport_height;
|
||||
gl1->vp.full_height = gl1->video_height;
|
||||
video_viewport_get_scaled_aspect2(&gl1->vp, viewport_width, viewport_height, false, device_aspect, video_driver_get_aspect_ratio());
|
||||
viewport_width = gl1->vp.width;
|
||||
viewport_height = gl1->vp.height;
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -1283,12 +1245,6 @@ static void gl1_set_viewport(gl1_t *gl1,
|
||||
gl1->vp.height = viewport_height;
|
||||
}
|
||||
|
||||
#if defined(RARCH_MOBILE)
|
||||
/* In portrait mode, we want viewport to gravitate to top of screen. */
|
||||
if (device_aspect < 1.0f)
|
||||
gl1->vp.y *= 2;
|
||||
#endif
|
||||
|
||||
glViewport(gl1->vp.x, gl1->vp.y, gl1->vp.width, gl1->vp.height);
|
||||
gl1_set_projection(gl1, &gl1_default_ortho, allow_rotate);
|
||||
|
||||
|
@ -1273,10 +1273,7 @@ static void gl2_set_viewport(gl2_t *gl,
|
||||
bool force_full, bool allow_rotate)
|
||||
{
|
||||
settings_t *settings = config_get_ptr();
|
||||
unsigned height = gl->video_height;
|
||||
int x = 0;
|
||||
int y = 0;
|
||||
float device_aspect = (float)viewport_width / viewport_height;
|
||||
float device_aspect = (float) viewport_width / (float)viewport_height;
|
||||
|
||||
if (gl->ctx_driver->translate_aspect)
|
||||
device_aspect = gl->ctx_driver->translate_aspect(
|
||||
@ -1287,54 +1284,17 @@ static void gl2_set_viewport(gl2_t *gl,
|
||||
video_viewport_get_scaled_integer(&gl->vp,
|
||||
viewport_width, viewport_height,
|
||||
video_driver_get_aspect_ratio(),
|
||||
(gl->flags & GL2_FLAG_KEEP_ASPECT) ? true : false);
|
||||
(gl->flags & GL2_FLAG_KEEP_ASPECT) ? true : false,
|
||||
false);
|
||||
viewport_width = gl->vp.width;
|
||||
viewport_height = gl->vp.height;
|
||||
}
|
||||
else if ((gl->flags & GL2_FLAG_KEEP_ASPECT) && !force_full)
|
||||
{
|
||||
float desired_aspect = video_driver_get_aspect_ratio();
|
||||
|
||||
#if defined(HAVE_MENU)
|
||||
if (settings->uints.video_aspect_ratio_idx == ASPECT_RATIO_CUSTOM)
|
||||
{
|
||||
video_viewport_t *custom_vp = &settings->video_viewport_custom;
|
||||
/* OpenGL has bottom-left origin viewport. */
|
||||
x = custom_vp->x;
|
||||
y = height - custom_vp->y - custom_vp->height;
|
||||
viewport_width = custom_vp->width;
|
||||
viewport_height = custom_vp->height;
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
float delta;
|
||||
|
||||
if (fabsf(device_aspect - desired_aspect) < 0.0001f)
|
||||
{
|
||||
/* If the aspect ratios of screen and desired aspect
|
||||
* ratio are sufficiently equal (floating point stuff),
|
||||
* assume they are actually equal.
|
||||
*/
|
||||
}
|
||||
else if (device_aspect > desired_aspect)
|
||||
{
|
||||
delta = (desired_aspect / device_aspect - 1.0f) / 2.0f + 0.5f;
|
||||
x = (int)roundf(viewport_width * (0.5f - delta));
|
||||
viewport_width = (unsigned)roundf(2.0f * viewport_width * delta);
|
||||
}
|
||||
else
|
||||
{
|
||||
delta = (device_aspect / desired_aspect - 1.0f) / 2.0f + 0.5f;
|
||||
y = (int)roundf(viewport_height * (0.5f - delta));
|
||||
viewport_height = (unsigned)roundf(2.0f * viewport_height * delta);
|
||||
}
|
||||
}
|
||||
|
||||
gl->vp.x = x;
|
||||
gl->vp.y = y;
|
||||
gl->vp.width = viewport_width;
|
||||
gl->vp.height = viewport_height;
|
||||
gl->vp.full_height = gl->video_height;
|
||||
video_viewport_get_scaled_aspect2(&gl->vp, viewport_width, viewport_height, false, device_aspect, video_driver_get_aspect_ratio());
|
||||
viewport_width = gl->vp.width;
|
||||
viewport_height = gl->vp.height;
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -1343,12 +1303,6 @@ static void gl2_set_viewport(gl2_t *gl,
|
||||
gl->vp.height = viewport_height;
|
||||
}
|
||||
|
||||
#if defined(RARCH_MOBILE)
|
||||
/* In portrait mode, we want viewport to gravitate to top of screen. */
|
||||
if (device_aspect < 1.0f)
|
||||
gl->vp.y *= 2;
|
||||
#endif
|
||||
|
||||
glViewport(gl->vp.x, gl->vp.y, gl->vp.width, gl->vp.height);
|
||||
gl2_set_projection(gl, &default_ortho, allow_rotate);
|
||||
|
||||
|
@ -1385,7 +1385,6 @@ static void gl3_set_viewport(gl3_t *gl,
|
||||
settings_t *settings = config_get_ptr();
|
||||
float device_aspect = (float)viewport_width / viewport_height;
|
||||
bool video_scale_integer = settings->bools.video_scale_integer;
|
||||
unsigned video_aspect_ratio_idx = settings->uints.video_aspect_ratio_idx;
|
||||
|
||||
if (gl->ctx_driver->translate_aspect)
|
||||
device_aspect = gl->ctx_driver->translate_aspect(
|
||||
@ -1396,54 +1395,17 @@ static void gl3_set_viewport(gl3_t *gl,
|
||||
video_viewport_get_scaled_integer(&gl->vp,
|
||||
viewport_width, viewport_height,
|
||||
video_driver_get_aspect_ratio(),
|
||||
(gl->flags & GL3_FLAG_KEEP_ASPECT) ? true : false);
|
||||
(gl->flags & GL3_FLAG_KEEP_ASPECT) ? true : false,
|
||||
false);
|
||||
viewport_width = gl->vp.width;
|
||||
viewport_height = gl->vp.height;
|
||||
}
|
||||
else if ((gl->flags & GL3_FLAG_KEEP_ASPECT) && !force_full)
|
||||
{
|
||||
float desired_aspect = video_driver_get_aspect_ratio();
|
||||
|
||||
#if defined(HAVE_MENU)
|
||||
if (video_aspect_ratio_idx == ASPECT_RATIO_CUSTOM)
|
||||
{
|
||||
video_viewport_t *custom_vp = &settings->video_viewport_custom;
|
||||
/* OpenGL has bottom-left origin viewport. */
|
||||
x = custom_vp->x;
|
||||
y = height - custom_vp->y - custom_vp->height;
|
||||
viewport_width = custom_vp->width;
|
||||
viewport_height = custom_vp->height;
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
float delta;
|
||||
|
||||
if (fabsf(device_aspect - desired_aspect) < 0.0001f)
|
||||
{
|
||||
/* If the aspect ratios of screen and desired aspect
|
||||
* ratio are sufficiently equal (floating point stuff),
|
||||
* assume they are actually equal.
|
||||
*/
|
||||
}
|
||||
else if (device_aspect > desired_aspect)
|
||||
{
|
||||
delta = (desired_aspect / device_aspect - 1.0f) / 2.0f + 0.5f;
|
||||
x = (int)roundf(viewport_width * (0.5f - delta));
|
||||
viewport_width = (unsigned)roundf(2.0f * viewport_width * delta);
|
||||
}
|
||||
else
|
||||
{
|
||||
delta = (device_aspect / desired_aspect - 1.0f) / 2.0f + 0.5f;
|
||||
y = (int)roundf(viewport_height * (0.5f - delta));
|
||||
viewport_height = (unsigned)roundf(2.0f * viewport_height * delta);
|
||||
}
|
||||
}
|
||||
|
||||
gl->vp.x = x;
|
||||
gl->vp.y = y;
|
||||
gl->vp.width = viewport_width;
|
||||
gl->vp.height = viewport_height;
|
||||
gl->vp.full_height = gl->video_height;
|
||||
video_viewport_get_scaled_aspect2(&gl->vp, viewport_width, viewport_height, false, device_aspect, video_driver_get_aspect_ratio());
|
||||
viewport_width = gl->vp.width;
|
||||
viewport_height = gl->vp.height;
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -1452,12 +1414,6 @@ static void gl3_set_viewport(gl3_t *gl,
|
||||
gl->vp.height = viewport_height;
|
||||
}
|
||||
|
||||
#if defined(RARCH_MOBILE)
|
||||
/* In portrait mode, we want viewport to gravitate to top of screen. */
|
||||
if (device_aspect < 1.0f)
|
||||
gl->vp.y *= 2;
|
||||
#endif
|
||||
|
||||
glViewport(gl->vp.x, gl->vp.y, gl->vp.width, gl->vp.height);
|
||||
gl3_set_projection(gl, &gl3_default_ortho, allow_rotate);
|
||||
|
||||
|
@ -936,56 +936,13 @@ static void gx2_update_viewport(wiiu_video_t *wiiu)
|
||||
{
|
||||
video_viewport_get_scaled_integer(&wiiu->vp,
|
||||
viewport_width, viewport_height,
|
||||
video_driver_get_aspect_ratio(), wiiu->keep_aspect);
|
||||
video_driver_get_aspect_ratio(), wiiu->keep_aspect, true);
|
||||
viewport_width = wiiu->vp.width;
|
||||
viewport_height = wiiu->vp.height;
|
||||
}
|
||||
else if (wiiu->keep_aspect)
|
||||
{
|
||||
float desired_aspect = video_driver_get_aspect_ratio();
|
||||
|
||||
#if defined(HAVE_MENU)
|
||||
if (video_aspect_ratio_idx == ASPECT_RATIO_CUSTOM)
|
||||
{
|
||||
video_viewport_t *custom_vp = &settings->video_viewport_custom;
|
||||
/* GX2 has top-left origin viewport. */
|
||||
x = custom_vp->x;
|
||||
y = custom_vp->y;
|
||||
viewport_width = custom_vp->width;
|
||||
viewport_height = custom_vp->height;
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
float delta;
|
||||
|
||||
if (fabsf(device_aspect - desired_aspect) < 0.0001f)
|
||||
{
|
||||
/* If the aspect ratios of screen and desired aspect
|
||||
* ratio are sufficiently equal (floating point stuff),
|
||||
* assume they are actually equal.
|
||||
*/
|
||||
}
|
||||
else if (device_aspect > desired_aspect)
|
||||
{
|
||||
delta = (desired_aspect / device_aspect - 1.0f)
|
||||
/ 2.0f + 0.5f;
|
||||
x = (int)roundf(viewport_width * (0.5f - delta));
|
||||
viewport_width = (unsigned)roundf(2.0f * viewport_width * delta);
|
||||
}
|
||||
else
|
||||
{
|
||||
delta = (device_aspect / desired_aspect - 1.0f)
|
||||
/ 2.0f + 0.5f;
|
||||
y = (int)roundf(viewport_height * (0.5f - delta));
|
||||
viewport_height = (unsigned)roundf(2.0f * viewport_height * delta);
|
||||
}
|
||||
}
|
||||
|
||||
wiiu->vp.x = x;
|
||||
wiiu->vp.y = y;
|
||||
wiiu->vp.width = viewport_width;
|
||||
wiiu->vp.height = viewport_height;
|
||||
video_viewport_get_scaled_aspect(&vk->vp, viewport_width, viewport_height, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -1011,58 +1011,23 @@ static void gx_resize(gx_video_t *gx,
|
||||
/* Ignore this for custom resolutions */
|
||||
if (gx->keep_aspect && gx_mode.efbHeight >= 192)
|
||||
{
|
||||
#ifdef HW_RVL
|
||||
float device_aspect = CONF_GetAspectRatio() == CONF_ASPECT_4_3 ?
|
||||
4.0 / 3.0 : 16.0 / 9.0;
|
||||
#else
|
||||
float device_aspect = 4.0 / 3.0;
|
||||
#endif
|
||||
float desired_aspect = video_driver_get_aspect_ratio();
|
||||
if (desired_aspect == 0.0)
|
||||
desired_aspect = 1.0;
|
||||
if ( (gx->orientation == ORIENTATION_VERTICAL)
|
||||
|| (gx->orientation == ORIENTATION_FLIPPED_ROTATED))
|
||||
desired_aspect = 1.0 / desired_aspect;
|
||||
|
||||
if (aspect_ratio_idx == ASPECT_RATIO_CUSTOM)
|
||||
{
|
||||
video_viewport_t *custom_vp = &settings->video_viewport_custom;
|
||||
|
||||
if (!custom_vp->width || !custom_vp->height)
|
||||
{
|
||||
custom_vp->x = 0;
|
||||
custom_vp->y = 0;
|
||||
custom_vp->width = gx->vp.full_width;
|
||||
custom_vp->height = gx->vp.full_height;
|
||||
}
|
||||
|
||||
x = custom_vp->x;
|
||||
y = custom_vp->y;
|
||||
width = custom_vp->width;
|
||||
height = custom_vp->height;
|
||||
}
|
||||
else
|
||||
{
|
||||
float delta;
|
||||
#ifdef HW_RVL
|
||||
float device_aspect = CONF_GetAspectRatio() == CONF_ASPECT_4_3 ?
|
||||
4.0 / 3.0 : 16.0 / 9.0;
|
||||
#else
|
||||
float device_aspect = 4.0 / 3.0;
|
||||
#endif
|
||||
if (fabs(device_aspect - desired_aspect) < 0.0001)
|
||||
{
|
||||
/* If the aspect ratios of screen and desired aspect ratio
|
||||
* are sufficiently equal (floating point stuff),
|
||||
* assume they are actually equal. */
|
||||
}
|
||||
else if (device_aspect > desired_aspect)
|
||||
{
|
||||
delta = (desired_aspect / device_aspect - 1.0) / 2.0 + 0.5;
|
||||
x = (unsigned)(width * (0.5 - delta));
|
||||
width = (unsigned)(2.0 * width * delta);
|
||||
}
|
||||
else
|
||||
{
|
||||
delta = (device_aspect / desired_aspect - 1.0) / 2.0 + 0.5;
|
||||
y = (unsigned)(height * (0.5 - delta));
|
||||
height = (unsigned)(2.0 * height * delta);
|
||||
}
|
||||
}
|
||||
video_viewport_get_scaled_aspect2(&gx->vp, width, height, true, device_aspect, desired_aspect);
|
||||
x = gx->vp.x;
|
||||
y = gx->vp.y;
|
||||
width = gx->vp.width;
|
||||
height = gx->vp.height;
|
||||
}
|
||||
|
||||
/* Overscan correction */
|
||||
|
@ -257,54 +257,15 @@ static void psp_update_viewport(psp1_video_t* psp,
|
||||
if (video_scale_integer)
|
||||
{
|
||||
video_viewport_get_scaled_integer(&psp->vp, SCEGU_SCR_WIDTH,
|
||||
SCEGU_SCR_HEIGHT, video_driver_get_aspect_ratio(), psp->keep_aspect);
|
||||
SCEGU_SCR_HEIGHT, video_driver_get_aspect_ratio(), psp->keep_aspect, true);
|
||||
width = psp->vp.width;
|
||||
height = psp->vp.height;
|
||||
}
|
||||
else if (psp->keep_aspect)
|
||||
{
|
||||
#if defined(HAVE_MENU)
|
||||
if (aspect_ratio_idx == ASPECT_RATIO_CUSTOM)
|
||||
{
|
||||
x = video_info->custom_vp_x;
|
||||
y = video_info->custom_vp_y;
|
||||
width = video_info->custom_vp_width;
|
||||
height = video_info->custom_vp_height;
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
float delta;
|
||||
float desired_aspect = video_driver_get_aspect_ratio();
|
||||
|
||||
if ( (fabsf(device_aspect - desired_aspect) < 0.0001f)
|
||||
|| (fabsf((16.0/9.0) - desired_aspect) < 0.02f))
|
||||
{
|
||||
/* If the aspect ratios of screen and desired aspect
|
||||
* ratio are sufficiently equal (floating point stuff),
|
||||
* assume they are actually equal.
|
||||
*/
|
||||
}
|
||||
else if (device_aspect > desired_aspect)
|
||||
{
|
||||
delta = (desired_aspect / device_aspect - 1.0f)
|
||||
/ 2.0f + 0.5f;
|
||||
x = (int)roundf(width * (0.5f - delta));
|
||||
width = (unsigned)roundf(2.0f * width * delta);
|
||||
}
|
||||
else
|
||||
{
|
||||
delta = (device_aspect / desired_aspect - 1.0f)
|
||||
/ 2.0f + 0.5f;
|
||||
y = (int)roundf(height * (0.5f - delta));
|
||||
height = (unsigned)roundf(2.0f * height * delta);
|
||||
}
|
||||
}
|
||||
|
||||
psp->vp.x = x;
|
||||
psp->vp.y = y;
|
||||
psp->vp.width = width;
|
||||
psp->vp.height = height;
|
||||
video_viewport_get_scaled_aspect(&psp->vp, width, height, true);
|
||||
width = psp->vp.width;
|
||||
height = psp->vp.height;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -996,55 +996,16 @@ static void rsx_set_viewport(void *data, unsigned viewport_width,
|
||||
{
|
||||
video_viewport_get_scaled_integer(&rsx->vp,
|
||||
viewport_width, viewport_height,
|
||||
video_driver_get_aspect_ratio(), rsx->keep_aspect);
|
||||
viewport_width = rsx->vp.width;
|
||||
viewport_height = rsx->vp.height;
|
||||
video_driver_get_aspect_ratio(), rsx->keep_aspect,
|
||||
true);
|
||||
viewport_width = rsx->vp.width;
|
||||
viewport_height = rsx->vp.height;
|
||||
}
|
||||
else if (rsx->keep_aspect && !force_full)
|
||||
{
|
||||
float desired_aspect = video_driver_get_aspect_ratio();
|
||||
|
||||
#if defined(HAVE_MENU)
|
||||
if (aspect_ratio_idx == ASPECT_RATIO_CUSTOM)
|
||||
{
|
||||
video_viewport_t *custom_vp = &settings->video_viewport_custom;
|
||||
/* RSX/libgcm has top-left origin viewport. */
|
||||
x = custom_vp->x;
|
||||
y = custom_vp->y;
|
||||
viewport_width = custom_vp->width;
|
||||
viewport_height = custom_vp->height;
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
float delta;
|
||||
if (fabsf(device_aspect - desired_aspect) < 0.0001f)
|
||||
{
|
||||
/* If the aspect ratios of screen and desired aspect
|
||||
* ratio are sufficiently equal (floating point stuff),
|
||||
* assume they are actually equal.
|
||||
*/
|
||||
}
|
||||
else if (device_aspect > desired_aspect)
|
||||
{
|
||||
delta = (desired_aspect / device_aspect - 1.0f)
|
||||
/ 2.0f + 0.5f;
|
||||
x = (int)roundf(viewport_width * (0.5f - delta));
|
||||
viewport_width = (unsigned)roundf(2.0f * viewport_width * delta);
|
||||
}
|
||||
else
|
||||
{
|
||||
delta = (device_aspect / desired_aspect - 1.0f)
|
||||
/ 2.0f + 0.5f;
|
||||
y = (int)roundf(viewport_height * (0.5f - delta));
|
||||
viewport_height = (unsigned)roundf(2.0f * viewport_height * delta);
|
||||
}
|
||||
}
|
||||
|
||||
rsx->vp.x = x;
|
||||
rsx->vp.y = y;
|
||||
rsx->vp.width = viewport_width;
|
||||
rsx->vp.height = viewport_height;
|
||||
video_viewport_get_scaled_aspect(&rsx->vp, viewport_width, viewport_height, true);
|
||||
viewport_width = rsx->vp.width;
|
||||
viewport_height = rsx->vp.height;
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -1493,7 +1454,8 @@ static void rsx_update_viewport(rsx_t* rsx)
|
||||
if (video_scale_integer)
|
||||
{
|
||||
video_viewport_get_scaled_integer(&rsx->vp, viewport_width,
|
||||
viewport_height, video_driver_get_aspect_ratio(), rsx->keep_aspect);
|
||||
viewport_height, video_driver_get_aspect_ratio(), rsx->keep_aspect,
|
||||
true);
|
||||
viewport_width = rsx->vp.width;
|
||||
viewport_height = rsx->vp.height;
|
||||
}
|
||||
@ -1525,16 +1487,18 @@ static void rsx_update_viewport(rsx_t* rsx)
|
||||
}
|
||||
else if (device_aspect > desired_aspect)
|
||||
{
|
||||
float viewport_bias = settings->floats.video_viewport_bias_x;
|
||||
delta = (desired_aspect / device_aspect - 1.0f)
|
||||
/ 2.0f + 0.5f;
|
||||
x = (int)roundf(viewport_width * (0.5f - delta));
|
||||
x = (int)roundf(viewport_width * ((0.5f - delta) * (viewport_bias * 2.0f)));
|
||||
viewport_width = (unsigned)roundf(2.0f * viewport_width * delta);
|
||||
}
|
||||
else
|
||||
{
|
||||
float viewport_bias = 1.0 - settings->floats.video_viewport_bias_y;
|
||||
delta = (device_aspect / desired_aspect - 1.0f)
|
||||
/ 2.0f + 0.5f;
|
||||
y = (int)roundf(viewport_height * (0.5f - delta));
|
||||
y = (int)roundf(viewport_height * ((0.5f - delta) * (viewport_bias * 2.0f)));
|
||||
viewport_height = (unsigned)roundf(2.0f * viewport_height * delta);
|
||||
}
|
||||
}
|
||||
|
@ -229,7 +229,6 @@ static void sdl_refresh_viewport(sdl2_video_t *vid)
|
||||
int win_w, win_h;
|
||||
settings_t *settings = config_get_ptr();
|
||||
bool video_scale_integer = settings->bools.video_scale_integer;
|
||||
unsigned aspect_ratio_idx = settings->uints.video_aspect_ratio_idx;
|
||||
|
||||
SDL_GetWindowSize(vid->window, &win_w, &win_h);
|
||||
|
||||
@ -243,39 +242,10 @@ static void sdl_refresh_viewport(sdl2_video_t *vid)
|
||||
if (video_scale_integer)
|
||||
video_viewport_get_scaled_integer(&vid->vp,
|
||||
win_w, win_h, video_driver_get_aspect_ratio(),
|
||||
vid->video.force_aspect);
|
||||
else if (aspect_ratio_idx == ASPECT_RATIO_CUSTOM)
|
||||
{
|
||||
video_viewport_t *custom_vp = &settings->video_viewport_custom;
|
||||
vid->vp.x = custom_vp->x;
|
||||
vid->vp.y = custom_vp->y;
|
||||
vid->vp.width = custom_vp->width;
|
||||
vid->vp.height = custom_vp->height;
|
||||
}
|
||||
vid->video.force_aspect, true);
|
||||
else if (vid->video.force_aspect)
|
||||
{
|
||||
float delta;
|
||||
float device_aspect = (float)win_w / win_h;
|
||||
float desired_aspect = video_driver_get_aspect_ratio();
|
||||
|
||||
if (fabsf(device_aspect - desired_aspect) < 0.0001f)
|
||||
{
|
||||
/* If the aspect ratios of screen and desired aspect ratio are
|
||||
* sufficiently equal (floating point stuff), assume they are
|
||||
* actually equal. */
|
||||
}
|
||||
else if (device_aspect > desired_aspect)
|
||||
{
|
||||
delta = (desired_aspect / device_aspect - 1.0f) / 2.0f + 0.5f;
|
||||
vid->vp.x = (int)roundf(win_w * (0.5f - delta));
|
||||
vid->vp.width = (unsigned)roundf(2.0f * win_w * delta);
|
||||
}
|
||||
else
|
||||
{
|
||||
delta = (device_aspect / desired_aspect - 1.0f) / 2.0f + 0.5f;
|
||||
vid->vp.y = (int)roundf(win_h * (0.5f - delta));
|
||||
vid->vp.height = (unsigned)roundf(2.0f * win_h * delta);
|
||||
}
|
||||
video_viewport_get_scaled_aspect(&vid->vp, win_w, win_h, true);
|
||||
}
|
||||
|
||||
vid->flags &= ~SDL2_FLAG_SHOULD_RESIZE;
|
||||
|
@ -572,50 +572,12 @@ static void switch_update_viewport(switch_video_t *sw,
|
||||
|
||||
if (settings->bools.video_scale_integer)
|
||||
{
|
||||
video_viewport_get_scaled_integer(&sw->vp, sw->vp.full_width, sw->vp.full_height, desired_aspect, sw->keep_aspect);
|
||||
/* TODO: Does nx use top-left or bottom-left origin? I'm assuming top left. */
|
||||
video_viewport_get_scaled_integer(&sw->vp, sw->vp.full_width, sw->vp.full_height, desired_aspect, sw->keep_aspect, true);
|
||||
}
|
||||
else if (sw->keep_aspect)
|
||||
{
|
||||
#if defined(HAVE_MENU)
|
||||
if (settings->uints.video_aspect_ratio_idx == ASPECT_RATIO_CUSTOM)
|
||||
{
|
||||
sw->vp.x = sw->vp.y = 0;
|
||||
sw->vp.width = width;
|
||||
sw->vp.height = height;
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
float delta;
|
||||
float device_aspect = ((float)sw->vp.full_width) / sw->vp.full_height;
|
||||
|
||||
if (fabsf(device_aspect - desired_aspect) < 0.0001f)
|
||||
{
|
||||
/*
|
||||
* If the aspect ratios of screen and desired aspect
|
||||
* ratio are sufficiently equal (floating point stuff),
|
||||
* assume they are actually equal.
|
||||
*/
|
||||
}
|
||||
else if (device_aspect > desired_aspect)
|
||||
{
|
||||
delta = (desired_aspect / device_aspect - 1.0f) / 2.0f + 0.5f;
|
||||
x = (int)roundf(width * (0.5f - delta));
|
||||
width = (unsigned)roundf(2.0f * width * delta);
|
||||
}
|
||||
else
|
||||
{
|
||||
delta = (device_aspect / desired_aspect - 1.0f) / 2.0f + 0.5f;
|
||||
y = (int)roundf(height * (0.5f - delta));
|
||||
height = (unsigned)roundf(2.0f * height * delta);
|
||||
}
|
||||
}
|
||||
|
||||
sw->vp.x = x;
|
||||
sw->vp.y = y;
|
||||
|
||||
sw->vp.width = width;
|
||||
sw->vp.height = height;
|
||||
video_viewport_get_scaled_aspect(&sw->vp, width, height, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -318,45 +318,39 @@ static void vg_free(void *data)
|
||||
static void vg_calculate_quad(vg_t *vg,
|
||||
unsigned width, unsigned height)
|
||||
{
|
||||
/* set viewport for aspect ratio, taken from the OpenGL driver. */
|
||||
if (vg->keep_aspect)
|
||||
{
|
||||
float desired_aspect = video_driver_get_aspect_ratio();
|
||||
settings_t *settings = config_get_ptr();
|
||||
bool video_scale_integer = settings->bools.video_scale_integer;
|
||||
float device_aspect = (float)width / height;
|
||||
struct video_viewport_t vp;
|
||||
|
||||
/* If the aspect ratios of screen and desired aspect ratio
|
||||
* are sufficiently equal (floating point stuff),
|
||||
* assume they are actually equal. */
|
||||
if (fabs(vg->mScreenAspect - desired_aspect) < 0.0001)
|
||||
{
|
||||
vg->x1 = 0;
|
||||
vg->y1 = 0;
|
||||
vg->x2 = width;
|
||||
vg->y2 = height;
|
||||
}
|
||||
else if (vg->mScreenAspect > desired_aspect)
|
||||
{
|
||||
float delta = (desired_aspect / vg->mScreenAspect - 1.0) / 2.0 + 0.5;
|
||||
vg->x1 = width * (0.5 - delta);
|
||||
vg->y1 = 0;
|
||||
vg->x2 = 2.0 * width * delta + vg->x1;
|
||||
vg->y2 = height + vg->y1;
|
||||
}
|
||||
else
|
||||
{
|
||||
float delta = (vg->mScreenAspect / desired_aspect - 1.0) / 2.0 + 0.5;
|
||||
vg->x1 = 0;
|
||||
vg->y1 = height * (0.5 - delta);
|
||||
vg->x2 = width + vg->x1;
|
||||
vg->y2 = 2.0 * height * delta + vg->y1;
|
||||
}
|
||||
}
|
||||
else
|
||||
vp.x = 0;
|
||||
vp.y = 0;
|
||||
vp.width = width;
|
||||
vp.height = height;
|
||||
vp.full_width = width;
|
||||
vp.full_height = height;
|
||||
|
||||
if (vg->ctx_driver->translate_aspect)
|
||||
device_aspect = vg->ctx_driver->translate_aspect(vg->ctx_data, width, height);
|
||||
|
||||
vg->mScreenAspect = device_aspect;
|
||||
/* OpenVG uses a bottom-left origin coordinate system */
|
||||
if (video_scale_integer)
|
||||
{
|
||||
vg->x1 = 0;
|
||||
vg->y1 = 0;
|
||||
vg->x2 = width;
|
||||
vg->y2 = height;
|
||||
video_viewport_get_scaled_integer(&vp,
|
||||
width, height,
|
||||
video_driver_get_aspect_ratio(),
|
||||
vg->keep_aspect,
|
||||
false);
|
||||
}
|
||||
else if (vg->keep_aspect)
|
||||
{
|
||||
video_viewport_get_scaled_aspect(&vp, viewport_width, viewport_height, false);
|
||||
}
|
||||
vg->x1 = vp.x;
|
||||
vg->y1 = vp.y;
|
||||
vg->x2 = vp.width;
|
||||
vg->y2 = vp.height;
|
||||
|
||||
vg->scissor[0] = vg->x1;
|
||||
vg->scissor[1] = vg->y1;
|
||||
|
@ -861,8 +861,9 @@ static void vita2d_update_viewport(vita_video_t* vita,
|
||||
|
||||
if (video_scale_integer)
|
||||
{
|
||||
/* TODO: Does Vita use top-left or bottom-left origin? I'm assuming top left. */
|
||||
video_viewport_get_scaled_integer(&vita->vp, temp_width,
|
||||
temp_height, video_driver_get_aspect_ratio(), vita->keep_aspect);
|
||||
temp_height, video_driver_get_aspect_ratio(), vita->keep_aspect, true);
|
||||
width = vita->vp.width;
|
||||
height = vita->vp.height;
|
||||
}
|
||||
@ -876,54 +877,16 @@ static void vita2d_update_viewport(vita_video_t* vita,
|
||||
width = temp_height;
|
||||
height = temp_width;
|
||||
}
|
||||
#if defined(HAVE_MENU)
|
||||
if (aspect_ratio_idx == ASPECT_RATIO_CUSTOM)
|
||||
video_viewport_get_scaled_aspect(&vita->vp, width, height, true);
|
||||
if ( (vita->rotation == ORIENTATION_VERTICAL) ||
|
||||
(vita->rotation == ORIENTATION_FLIPPED_ROTATED)
|
||||
)
|
||||
{
|
||||
x = video_info->custom_vp_x;
|
||||
y = video_info->custom_vp_y;
|
||||
width = video_info->custom_vp_width;
|
||||
height = video_info->custom_vp_height;
|
||||
// swap x and y
|
||||
unsigned tmp = vita->vp.x;
|
||||
vita->vp.x = vita->vp.y;
|
||||
vita->vp.y = tmp;
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
float delta;
|
||||
|
||||
if ((fabsf(device_aspect - desired_aspect) < 0.0001f))
|
||||
{
|
||||
/* If the aspect ratios of screen and desired aspect
|
||||
* ratio are sufficiently equal (floating point stuff),
|
||||
* assume they are actually equal.
|
||||
*/
|
||||
}
|
||||
else if (device_aspect > desired_aspect)
|
||||
{
|
||||
delta = (desired_aspect / device_aspect - 1.0f)
|
||||
/ 2.0f + 0.5f;
|
||||
x = (int)roundf(width * (0.5f - delta));
|
||||
width = (unsigned)roundf(2.0f * width * delta);
|
||||
}
|
||||
else
|
||||
{
|
||||
delta = (device_aspect / desired_aspect - 1.0f)
|
||||
/ 2.0f + 0.5f;
|
||||
y = (int)roundf(height * (0.5f - delta));
|
||||
height = (unsigned)roundf(2.0f * height * delta);
|
||||
}
|
||||
|
||||
if ( (vita->rotation == ORIENTATION_VERTICAL) ||
|
||||
(vita->rotation == ORIENTATION_FLIPPED_ROTATED)
|
||||
)
|
||||
{
|
||||
x = (temp_width - width) * 0.5f;
|
||||
y = (temp_height - height) * 0.5f;
|
||||
}
|
||||
}
|
||||
|
||||
vita->vp.x = x;
|
||||
vita->vp.y = y;
|
||||
vita->vp.width = width;
|
||||
vita->vp.height = height;
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -954,9 +917,10 @@ static void vita2d_set_viewport_wrapper(void *data, unsigned viewport_width,
|
||||
|
||||
if (video_scale_integer && !force_full)
|
||||
{
|
||||
/* TODO: Does Vita use top-left or bottom-left origin? I'm assuming top left. */
|
||||
video_viewport_get_scaled_integer(&vita->vp,
|
||||
viewport_width, viewport_height,
|
||||
video_driver_get_aspect_ratio(), vita->keep_aspect);
|
||||
video_driver_get_aspect_ratio(), vita->keep_aspect, true);
|
||||
viewport_width = vita->vp.width;
|
||||
viewport_height = vita->vp.height;
|
||||
}
|
||||
@ -986,16 +950,19 @@ static void vita2d_set_viewport_wrapper(void *data, unsigned viewport_width,
|
||||
}
|
||||
else if (device_aspect > desired_aspect)
|
||||
{
|
||||
float viewport_bias = settings->floats.video_viewport_bias_x;
|
||||
delta = (desired_aspect / device_aspect - 1.0f)
|
||||
/ 2.0f + 0.5f;
|
||||
x = (int)roundf(viewport_width * (0.5f - delta));
|
||||
x = (int)roundf(viewport_width * ((0.5f - delta) * (viewport_bias * 2.0f)));
|
||||
viewport_width = (unsigned)roundf(2.0f * viewport_width * delta);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* TODO: Does Vita use top-left or bottom-left origin? I'm assuming top left. */
|
||||
float viewport_bias = settings->floats.video_viewport_bias_y;
|
||||
delta = (device_aspect / desired_aspect - 1.0f)
|
||||
/ 2.0f + 0.5f;
|
||||
y = (int)roundf(viewport_height * (0.5f - delta));
|
||||
y = (int)roundf(viewport_height * ((0.5f - delta) * (viewport_bias * 2.0f)));
|
||||
viewport_height = (unsigned)roundf(2.0f * viewport_height * delta);
|
||||
}
|
||||
}
|
||||
|
@ -3814,7 +3814,6 @@ static void vulkan_set_viewport(void *data, unsigned viewport_width,
|
||||
struct video_ortho ortho = {0, 1, 0, 1, -1, 1};
|
||||
settings_t *settings = config_get_ptr();
|
||||
bool video_scale_integer = settings->bools.video_scale_integer;
|
||||
unsigned aspect_ratio_idx = settings->uints.video_aspect_ratio_idx;
|
||||
vk_t *vk = (vk_t*)data;
|
||||
|
||||
if (vk->ctx_driver->translate_aspect)
|
||||
@ -3826,55 +3825,18 @@ static void vulkan_set_viewport(void *data, unsigned viewport_width,
|
||||
video_viewport_get_scaled_integer(&vk->vp,
|
||||
viewport_width, viewport_height,
|
||||
video_driver_get_aspect_ratio(),
|
||||
vk->flags & VK_FLAG_KEEP_ASPECT);
|
||||
vk->flags & VK_FLAG_KEEP_ASPECT,
|
||||
true);
|
||||
vk->vp.x = MAX(vk->vp.x, 0);
|
||||
vk->vp.y = MAX(vk->vp.y, 0);
|
||||
viewport_width = vk->vp.width;
|
||||
viewport_height = vk->vp.height;
|
||||
}
|
||||
else if ((vk->flags & VK_FLAG_KEEP_ASPECT) && !force_full)
|
||||
{
|
||||
float desired_aspect = video_driver_get_aspect_ratio();
|
||||
#if defined(HAVE_MENU)
|
||||
if (aspect_ratio_idx == ASPECT_RATIO_CUSTOM)
|
||||
{
|
||||
video_viewport_t *custom_vp = &settings->video_viewport_custom;
|
||||
/* Vulkan has top-left origin viewport. */
|
||||
x = custom_vp->x;
|
||||
y = custom_vp->y;
|
||||
viewport_width = custom_vp->width;
|
||||
viewport_height = custom_vp->height;
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
float delta;
|
||||
|
||||
if (fabsf(device_aspect - desired_aspect) < 0.0001f)
|
||||
{
|
||||
/* If the aspect ratios of screen and desired aspect
|
||||
* ratio are sufficiently equal (floating point stuff),
|
||||
* assume they are actually equal.
|
||||
*/
|
||||
}
|
||||
else if (device_aspect > desired_aspect)
|
||||
{
|
||||
delta = (desired_aspect / device_aspect - 1.0f)
|
||||
/ 2.0f + 0.5f;
|
||||
x = (int)roundf(viewport_width * (0.5f - delta));
|
||||
viewport_width = (unsigned)roundf(2.0f * viewport_width * delta);
|
||||
}
|
||||
else
|
||||
{
|
||||
delta = (device_aspect / desired_aspect - 1.0f)
|
||||
/ 2.0f + 0.5f;
|
||||
y = (int)roundf(viewport_height * (0.5f - delta));
|
||||
viewport_height = (unsigned)roundf(2.0f * viewport_height * delta);
|
||||
}
|
||||
}
|
||||
|
||||
vk->vp.x = x;
|
||||
vk->vp.y = y;
|
||||
vk->vp.width = viewport_width;
|
||||
vk->vp.height = viewport_height;
|
||||
video_viewport_get_scaled_aspect2(&vk->vp, viewport_width, viewport_height, true, device_aspect, video_driver_get_aspect_ratio());
|
||||
viewport_width = vk->vp.width;
|
||||
viewport_height = vk->vp.height;
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -3884,12 +3846,6 @@ static void vulkan_set_viewport(void *data, unsigned viewport_width,
|
||||
vk->vp.height = viewport_height;
|
||||
}
|
||||
|
||||
#if defined(RARCH_MOBILE)
|
||||
/* In portrait mode, we want viewport to gravitate to top of screen. */
|
||||
if (device_aspect < 1.0f)
|
||||
vk->vp.y = 0;
|
||||
#endif
|
||||
|
||||
vulkan_set_projection(vk, &ortho, allow_rotate);
|
||||
|
||||
/* Set last backbuffer viewport. */
|
||||
|
@ -599,9 +599,10 @@ static void xv_calc_out_rect(bool keep_aspect,
|
||||
vp->full_width = vp_width;
|
||||
vp->full_height = vp_height;
|
||||
|
||||
/* TODO: Does xvideo have its origin in top left or bottom-left? Assuming top left. */
|
||||
if (scale_integer)
|
||||
video_viewport_get_scaled_integer(vp, vp_width, vp_height,
|
||||
video_driver_get_aspect_ratio(), keep_aspect);
|
||||
video_driver_get_aspect_ratio(), keep_aspect, true);
|
||||
else if (!keep_aspect)
|
||||
{
|
||||
vp->x = 0;
|
||||
@ -611,36 +612,7 @@ static void xv_calc_out_rect(bool keep_aspect,
|
||||
}
|
||||
else
|
||||
{
|
||||
float desired_aspect = video_driver_get_aspect_ratio();
|
||||
float device_aspect = (float)vp_width / vp_height;
|
||||
|
||||
/* If the aspect ratios of screen and desired aspect ratio
|
||||
* are sufficiently equal (floating point stuff),
|
||||
* assume they are actually equal.
|
||||
*/
|
||||
if (fabs(device_aspect - desired_aspect) < 0.0001)
|
||||
{
|
||||
vp->x = 0;
|
||||
vp->y = 0;
|
||||
vp->width = vp_width;
|
||||
vp->height = vp_height;
|
||||
}
|
||||
else if (device_aspect > desired_aspect)
|
||||
{
|
||||
float delta = (desired_aspect / device_aspect - 1.0) / 2.0 + 0.5;
|
||||
vp->x = vp_width * (0.5 - delta);
|
||||
vp->y = 0;
|
||||
vp->width = 2.0 * vp_width * delta;
|
||||
vp->height = vp_height;
|
||||
}
|
||||
else
|
||||
{
|
||||
float delta = (device_aspect / desired_aspect - 1.0) / 2.0 + 0.5;
|
||||
vp->x = 0;
|
||||
vp->y = vp_height * (0.5 - delta);
|
||||
vp->width = vp_width;
|
||||
vp->height = 2.0 * vp_height * delta;
|
||||
}
|
||||
video_viewport_get_scaled_aspect(vp, vp_width, vp_height, true);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2044,6 +2044,72 @@ void video_driver_set_aspect_ratio(void)
|
||||
video_st->poke->set_aspect_ratio(video_st->data, aspect_ratio_idx);
|
||||
}
|
||||
|
||||
void video_viewport_get_scaled_aspect(struct video_viewport *vp, unsigned viewport_width, unsigned viewport_height, bool ydown) {
|
||||
float device_aspect = (float)viewport_width / viewport_height;
|
||||
float desired_aspect = video_driver_get_aspect_ratio();
|
||||
video_viewport_get_scaled_aspect2(vp, viewport_width, viewport_height, ydown, device_aspect, desired_aspect);
|
||||
}
|
||||
|
||||
void video_viewport_get_scaled_aspect2(struct video_viewport *vp, unsigned viewport_width, unsigned viewport_height, bool ydown, float device_aspect, float desired_aspect)
|
||||
{
|
||||
settings_t *settings = config_get_ptr();
|
||||
int x = 0;
|
||||
int y = 0;
|
||||
|
||||
#if defined(HAVE_MENU)
|
||||
if (settings->uints.video_aspect_ratio_idx == ASPECT_RATIO_CUSTOM)
|
||||
{
|
||||
video_viewport_t *custom_vp = &settings->video_viewport_custom;
|
||||
x = custom_vp->x;
|
||||
y = custom_vp->y - custom_vp->height;
|
||||
if (!ydown)
|
||||
y = vp->full_height - y;
|
||||
viewport_width = custom_vp->width;
|
||||
viewport_height = custom_vp->height;
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
float delta;
|
||||
|
||||
if (fabsf(device_aspect - desired_aspect) < 0.0001f)
|
||||
{
|
||||
/* If the aspect ratios of screen and desired aspect
|
||||
* ratio are sufficiently equal (floating point stuff),
|
||||
* assume they are actually equal.
|
||||
*/
|
||||
}
|
||||
else if (device_aspect > desired_aspect)
|
||||
{
|
||||
float viewport_bias = settings->floats.video_viewport_bias_x;
|
||||
#if defined(RARCH_MOBILE)
|
||||
if (device_aspect < 1.0f)
|
||||
viewport_bias = settings->floats.video_viewport_bias_portrait_x;
|
||||
#endif
|
||||
delta = (desired_aspect / device_aspect - 1.0f) / 2.0f + 0.5f;
|
||||
x = (int)roundf(viewport_width * ((0.5f - delta) * (viewport_bias * 2.0f)));
|
||||
viewport_width = (unsigned)roundf(2.0f * viewport_width * delta);
|
||||
}
|
||||
else
|
||||
{
|
||||
float viewport_bias = settings->floats.video_viewport_bias_y;
|
||||
#if defined(RARCH_MOBILE)
|
||||
if (device_aspect < 1.0f)
|
||||
viewport_bias = settings->floats.video_viewport_bias_portrait_y;
|
||||
#endif
|
||||
if (!ydown)
|
||||
viewport_bias = 1.0 - viewport_bias;
|
||||
delta = (device_aspect / desired_aspect - 1.0f) / 2.0f + 0.5f;
|
||||
y = (int)roundf(viewport_height * ((0.5f - delta) * (viewport_bias * 2.0f)));
|
||||
viewport_height = (unsigned)roundf(2.0f * viewport_height * delta);
|
||||
}
|
||||
}
|
||||
vp->x = x;
|
||||
vp->y = y;
|
||||
vp->width = viewport_width;
|
||||
vp->height = viewport_height;
|
||||
}
|
||||
|
||||
void video_driver_update_viewport(
|
||||
struct video_viewport* vp, bool force_full, bool keep_aspect)
|
||||
{
|
||||
@ -2064,58 +2130,11 @@ void video_driver_update_viewport(
|
||||
vp,
|
||||
vp->full_width,
|
||||
vp->full_height,
|
||||
video_driver_aspect_ratio, keep_aspect);
|
||||
video_driver_aspect_ratio, keep_aspect, false);
|
||||
else if (keep_aspect && !force_full)
|
||||
{
|
||||
float desired_aspect = video_driver_aspect_ratio;
|
||||
|
||||
#if defined(HAVE_MENU)
|
||||
if (video_aspect_ratio_idx == ASPECT_RATIO_CUSTOM)
|
||||
{
|
||||
const struct video_viewport *custom_vp = &settings->video_viewport_custom;
|
||||
vp->x = custom_vp->x;
|
||||
vp->y = custom_vp->y;
|
||||
vp->width = custom_vp->width;
|
||||
vp->height = custom_vp->height;
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
float delta;
|
||||
|
||||
if (fabsf(device_aspect - desired_aspect) < 0.0001f)
|
||||
{
|
||||
/* If the aspect ratios of screen and desired aspect
|
||||
* ratio are sufficiently equal (floating point stuff),
|
||||
* assume they are actually equal.
|
||||
*/
|
||||
}
|
||||
else if (device_aspect > desired_aspect)
|
||||
{
|
||||
delta = (desired_aspect / device_aspect - 1.0f)
|
||||
/ 2.0f + 0.5f;
|
||||
vp->x = (int)roundf(vp->full_width * (0.5f - delta));
|
||||
vp->width = (unsigned)roundf(2.0f * vp->full_width * delta);
|
||||
vp->y = 0;
|
||||
vp->height = vp->full_height;
|
||||
}
|
||||
else
|
||||
{
|
||||
vp->x = 0;
|
||||
vp->width = vp->full_width;
|
||||
delta = (device_aspect / desired_aspect - 1.0f)
|
||||
/ 2.0f + 0.5f;
|
||||
vp->y = (int)roundf(vp->full_height * (0.5f - delta));
|
||||
vp->height = (unsigned)roundf(2.0f * vp->full_height * delta);
|
||||
}
|
||||
}
|
||||
video_viewport_get_scaled_aspect(vp, vp->full_width, vp->full_height, false);
|
||||
}
|
||||
|
||||
#if defined(RARCH_MOBILE)
|
||||
/* In portrait mode, we want viewport to gravitate to top of screen. */
|
||||
if (device_aspect < 1.0f)
|
||||
vp->y = 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
void video_driver_restore_cached(void *settings_data)
|
||||
@ -2304,13 +2323,15 @@ bool video_driver_get_viewport_info(struct video_viewport *viewport)
|
||||
* @height : Height.
|
||||
* @aspect_ratio : Aspect ratio (in float).
|
||||
* @keep_aspect : Preserve aspect ratio?
|
||||
* @ydown : Positive y points down?
|
||||
*
|
||||
* Gets viewport scaling dimensions based on
|
||||
* scaled integer aspect ratio.
|
||||
**/
|
||||
void video_viewport_get_scaled_integer(struct video_viewport *vp,
|
||||
unsigned width, unsigned height,
|
||||
float aspect_ratio, bool keep_aspect)
|
||||
float aspect_ratio, bool keep_aspect,
|
||||
bool ydown)
|
||||
{
|
||||
int padding_x = 0;
|
||||
int padding_y = 0;
|
||||
@ -2318,7 +2339,6 @@ void video_viewport_get_scaled_integer(struct video_viewport *vp,
|
||||
video_driver_state_t *video_st = &video_driver_st;
|
||||
unsigned video_aspect_ratio_idx = settings->uints.video_aspect_ratio_idx;
|
||||
bool overscale = settings->bools.video_scale_integer_overscale;
|
||||
|
||||
if (video_aspect_ratio_idx == ASPECT_RATIO_CUSTOM)
|
||||
{
|
||||
struct video_viewport *custom_vp = &settings->video_viewport_custom;
|
||||
@ -2333,12 +2353,24 @@ void video_viewport_get_scaled_integer(struct video_viewport *vp,
|
||||
}
|
||||
else
|
||||
{
|
||||
float viewport_bias_x = settings->floats.video_viewport_bias_x;
|
||||
float viewport_bias_y = settings->floats.video_viewport_bias_y;
|
||||
unsigned base_width;
|
||||
/* Use system reported sizes as these define the
|
||||
* geometry for the "normal" case. */
|
||||
unsigned base_height =
|
||||
video_st->av_info.geometry.base_height;
|
||||
unsigned int rotation = retroarch_get_rotation();
|
||||
#if defined(RARCH_MOBILE)
|
||||
if (aspect_ratio < 1.0f)
|
||||
{
|
||||
viewport_bias_x = settings->floats.video_viewport_bias_portrait_x;
|
||||
viewport_bias_y = settings->floats.video_viewport_bias_portrait_y;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (!ydown)
|
||||
viewport_bias_y = 1.0 - viewport_bias_y;
|
||||
|
||||
if (rotation % 2)
|
||||
base_height = video_st->av_info.geometry.base_width;
|
||||
@ -2382,12 +2414,14 @@ void video_viewport_get_scaled_integer(struct video_viewport *vp,
|
||||
|
||||
width -= padding_x;
|
||||
height -= padding_y;
|
||||
padding_x *= viewport_bias_x;
|
||||
padding_y *= viewport_bias_y;
|
||||
}
|
||||
|
||||
vp->width = width;
|
||||
vp->height = height;
|
||||
vp->x = padding_x / 2;
|
||||
vp->y = padding_y / 2;
|
||||
vp->x = padding_x;
|
||||
vp->y = padding_y;
|
||||
}
|
||||
|
||||
void video_driver_display_type_set(enum rarch_display_type type)
|
||||
|
@ -991,18 +991,49 @@ void video_driver_menu_settings(void **list_data, void *list_info_data,
|
||||
|
||||
/**
|
||||
* video_viewport_get_scaled_integer:
|
||||
* @vp : Viewport handle
|
||||
* @vp : Viewport handle.
|
||||
* @width : Width.
|
||||
* @height : Height.
|
||||
* @aspect_ratio : Aspect ratio (in float).
|
||||
* @keep_aspect : Preserve aspect ratio?
|
||||
* @ydown : Positive y goes "down".
|
||||
*
|
||||
* Gets viewport scaling dimensions based on
|
||||
* scaled integer aspect ratio.
|
||||
**/
|
||||
void video_viewport_get_scaled_integer(struct video_viewport *vp,
|
||||
unsigned width, unsigned height,
|
||||
float aspect_ratio, bool keep_aspect);
|
||||
float aspect_ratio, bool keep_aspect,
|
||||
bool ydown);
|
||||
|
||||
/**
|
||||
* video_viewport_get_scaled_aspect:
|
||||
* @vp : Viewport handle. Fields x, y, width, height will be written, and full_width or full_height might be read.
|
||||
* @width : Viewport width.
|
||||
* @height : Viewport height.
|
||||
* @ydown : Positive y goes "down".
|
||||
*
|
||||
* Gets viewport scaling dimensions based on
|
||||
* scaled non-integer aspect ratio.
|
||||
**/
|
||||
void video_viewport_get_scaled_aspect(struct video_viewport *vp,
|
||||
unsigned width, unsigned height, bool ydown);
|
||||
|
||||
/**
|
||||
* video_viewport_get_scaled_aspect2:
|
||||
* @vp : Viewport handle. Fields x, y, width, height will be written, and full_width or full_height might be read.
|
||||
* @width : Viewport width.
|
||||
* @height : Viewport height.
|
||||
* @ydown : Positive y goes "down".
|
||||
* @device_aspect : Device aspect ratio.
|
||||
* @desired_aspect: Target aspect ratio.
|
||||
*
|
||||
* Gets viewport scaling dimensions based on
|
||||
* scaled non-integer aspect ratio.
|
||||
**/
|
||||
void video_viewport_get_scaled_aspect2(struct video_viewport *vp,
|
||||
unsigned width, unsigned height, bool ydown,
|
||||
float device_aspect, float desired_aspect);
|
||||
|
||||
/**
|
||||
* video_monitor_set_refresh_rate:
|
||||
|
Loading…
Reference in New Issue
Block a user