1
0
mirror of https://github.com/libretro/RetroArch synced 2024-07-05 09:48:42 +00:00

Add gfx/video_viewport.c/viewport.h

This commit is contained in:
twinaphex 2015-01-18 23:59:57 +01:00
parent 7a0c7bd712
commit 80d4de7c3f
44 changed files with 400 additions and 360 deletions

View File

@ -103,6 +103,7 @@ OBJ += frontend/frontend.o \
gfx/video_driver.o \
gfx/video_monitor.o \
gfx/video_pixel_converter.o \
gfx/video_viewport.o \
osk/osk_driver.o \
camera/camera_driver.o \
menu/menu_driver.o \

View File

@ -3,7 +3,7 @@
#include <OpenGL/OpenGL.h>
#endif
#include "../../gfx/gfx_common.h"
#include "../../gfx/video_viewport.h"
#include "../../gfx/video_monitor.h"
#include "../../gfx/video_context_driver.h"
#include "../../gfx/gl_common.h"

View File

@ -20,7 +20,7 @@
#include <boolean.h>
#include "libretro.h"
#include "driver.h"
#include "gfx/gfx_common.h"
#include "gfx/video_viewport.h"
#ifdef HAVE_CONFIG_H
#include "config.h"

View File

@ -449,9 +449,9 @@ static void init_video(void)
scale = g_extern.filter.scale;
/* Update core-dependent aspect ratio values. */
gfx_set_square_pixel_viewport(geom->base_width, geom->base_height);
gfx_set_core_viewport();
gfx_set_config_viewport();
video_viewport_set_square_pixel(geom->base_width, geom->base_height);
video_viewport_set_core();
video_viewport_set_config();
/* Update CUSTOM viewport. */
custom_vp = (rarch_viewport_t*)&g_extern.console.screen.viewports.custom_vp;

View File

@ -31,6 +31,7 @@
#include "core_options.h"
#include "core_info.h"
#include <retro_miscellaneous.h>
#include "gfx/video_viewport.h"
#include "playlist.h"
@ -84,6 +85,16 @@ enum sound_mode_enums
SOUND_MODE_LAST
};
typedef struct rarch_viewport
{
int x;
int y;
unsigned width;
unsigned height;
unsigned full_width;
unsigned full_height;
} rarch_viewport_t;
struct defaults
{
char menu_config_dir[PATH_MAX_LENGTH];
@ -370,16 +381,6 @@ typedef struct rarch_resolution
unsigned id;
} rarch_resolution_t;
typedef struct rarch_viewport
{
int x;
int y;
unsigned width;
unsigned height;
unsigned full_width;
unsigned full_height;
} rarch_viewport_t;
#define AUDIO_BUFFER_FREE_SAMPLES_COUNT (8 * 1024)
#define MEASURE_FRAME_TIME_SAMPLES_COUNT (2 * 1024)

View File

@ -24,7 +24,7 @@
#ifndef _XBOX
#include "render_chain.h"
#endif
#include "../gfx_common.h"
#include "../video_viewport.h"
#include "../drivers_context/win32_common.h"
@ -348,7 +348,7 @@ static void d3d_calculate_rect(d3d_video_t *d3d,
if (g_settings.video.scale_integer)
{
struct rarch_viewport vp = {0};
gfx_scale_integer(&vp, width, height, desired_aspect, keep);
video_viewport_get_scaled_integer(&vp, width, height, desired_aspect, keep);
d3d_set_viewport(d3d, vp.x, vp.y, vp.width, vp.height);
}
else if (!keep)
@ -443,17 +443,17 @@ static void d3d_set_aspect_ratio(void *data, unsigned aspect_ratio_idx)
switch (aspect_ratio_idx)
{
case ASPECT_RATIO_SQUARE:
gfx_set_square_pixel_viewport(
video_viewport_set_square_pixel(
g_extern.system.av_info.geometry.base_width,
g_extern.system.av_info.geometry.base_height);
break;
case ASPECT_RATIO_CORE:
gfx_set_core_viewport();
video_viewport_set_core();
break;
case ASPECT_RATIO_CONFIG:
gfx_set_config_viewport();
video_viewport_set_config();
break;
default:

View File

@ -51,7 +51,6 @@
#include "../font_d3d_driver.h"
#include "../video_context_driver.h"
#include "../gfx_common.h"
#ifdef HAVE_CG
#include <Cg/cg.h>

View File

@ -32,7 +32,7 @@
#include "../../general.h"
#include "../../retroarch.h"
#include "../gfx_common.h"
#include "../video_viewport.h"
#include "../video_monitor.h"
#include "../font_renderer_driver.h"
@ -1389,17 +1389,17 @@ static void exynos_set_aspect_ratio(void *data, unsigned aspect_ratio_idx)
switch (aspect_ratio_idx)
{
case ASPECT_RATIO_SQUARE:
gfx_set_square_pixel_viewport(
video_viewport_set_square_pixel(
g_extern.system.av_info.geometry.base_width,
g_extern.system.av_info.geometry.base_height);
break;
case ASPECT_RATIO_CORE:
gfx_set_core_viewport();
video_viewport_set_core();
break;
case ASPECT_RATIO_CONFIG:
gfx_set_config_viewport();
video_viewport_set_config();
break;
default:

View File

@ -37,7 +37,7 @@
#endif
#include "../gl_common.h"
#include "../gfx_common.h"
#include "../video_viewport.h"
#include "../video_context_driver.h"
#include <compat/strl.h>
@ -793,7 +793,7 @@ void gl_set_viewport(gl_t *gl, unsigned width,
if (g_settings.video.scale_integer && !force_full)
{
gfx_scale_integer(&gl->vp, width, height,
video_viewport_get_scaled_integer(&gl->vp, width, height,
g_extern.system.aspect_ratio, gl->keep_aspect);
width = gl->vp.width;
height = gl->vp.height;
@ -2973,17 +2973,17 @@ static void gl_set_aspect_ratio(void *data, unsigned aspect_ratio_idx)
switch (aspect_ratio_idx)
{
case ASPECT_RATIO_SQUARE:
gfx_set_square_pixel_viewport(
video_viewport_set_square_pixel(
g_extern.system.av_info.geometry.base_width,
g_extern.system.av_info.geometry.base_height);
break;
case ASPECT_RATIO_CORE:
gfx_set_core_viewport();
video_viewport_set_core();
break;
case ASPECT_RATIO_CONFIG:
gfx_set_config_viewport();
video_viewport_set_config();
break;
default:

View File

@ -19,7 +19,7 @@
#include "../../general.h"
#include "../drivers_font_renderer/bitmap.h"
#include "../../menu/menu.h"
#include "../gfx_common.h"
#include "../video_viewport.h"
#include "../video_monitor.h"
#ifdef HW_RVL
@ -316,13 +316,13 @@ static void gx_set_aspect_ratio(void *data, unsigned aspect_ratio_idx)
gx_video_t *gx = (gx_video_t*)driver.video_data;
if (aspect_ratio_idx == ASPECT_RATIO_SQUARE)
gfx_set_square_pixel_viewport(
video_viewport_set_square_pixel(
g_extern.system.av_info.geometry.base_width,
g_extern.system.av_info.geometry.base_height);
else if (aspect_ratio_idx == ASPECT_RATIO_CORE)
gfx_set_core_viewport();
video_viewport_set_core();
else if (aspect_ratio_idx == ASPECT_RATIO_CONFIG)
gfx_set_config_viewport();
video_viewport_set_config();
g_extern.system.aspect_ratio = aspectratio_lut[aspect_ratio_idx].value;

View File

@ -20,7 +20,7 @@
#include "../../general.h"
#include "../../retroarch.h"
#include <gfx/scaler/scaler.h>
#include "../gfx_common.h"
#include "../video_viewport.h"
#include "../video_monitor.h"
#include "../video_context_driver.h"
#include "../font_renderer_driver.h"

View File

@ -24,7 +24,7 @@
#include "psp_sdk_defines.h"
#include "../../general.h"
#include "../../driver.h"
#include "../gfx_common.h"
#include "../video_viewport.h"
#include "../video_monitor.h"
#ifndef SCEGU_SCR_WIDTH
@ -703,7 +703,7 @@ static void psp_update_viewport(psp1_video_t* psp)
if (g_settings.video.scale_integer)
{
gfx_scale_integer(&psp->vp, SCEGU_SCR_WIDTH,
video_viewport_get_scaled_integer(&psp->vp, SCEGU_SCR_WIDTH,
SCEGU_SCR_HEIGHT, g_extern.system.aspect_ratio, psp->keep_aspect);
width = psp->vp.width;
height = psp->vp.height;
@ -798,17 +798,17 @@ static void psp_set_aspect_ratio(void *data, unsigned aspectratio_index)
switch (aspectratio_index)
{
case ASPECT_RATIO_SQUARE:
gfx_set_square_pixel_viewport(
video_viewport_set_square_pixel(
g_extern.system.av_info.geometry.base_width,
g_extern.system.av_info.geometry.base_height);
break;
case ASPECT_RATIO_CORE:
gfx_set_core_viewport();
video_viewport_set_core();
break;
case ASPECT_RATIO_CONFIG:
gfx_set_config_viewport();
video_viewport_set_config();
break;
default:

View File

@ -23,7 +23,7 @@
#include "../../retroarch.h"
#include "../../performance.h"
#include <gfx/scaler/scaler.h>
#include "../gfx_common.h"
#include "../video_viewport.h"
#include "../video_monitor.h"
#include "../video_context_driver.h"
#include "../font_renderer_driver.h"
@ -264,7 +264,7 @@ static void sdl_refresh_viewport(sdl2_video_t *vid)
vid->vp.full_height = win_h;
if (g_settings.video.scale_integer)
gfx_scale_integer(&vid->vp, win_w, win_h, g_extern.system.aspect_ratio,
video_viewport_get_scaled_integer(&vid->vp, win_w, win_h, g_extern.system.aspect_ratio,
vid->video.force_aspect);
else if (g_settings.video.aspect_ratio_idx == ASPECT_RATIO_CUSTOM)
{
@ -635,16 +635,16 @@ static void sdl2_poke_set_aspect_ratio(void *data, unsigned aspectratio_index)
switch (aspectratio_index)
{
case ASPECT_RATIO_SQUARE:
gfx_set_square_pixel_viewport(g_extern.system.av_info.geometry.base_width,
video_viewport_set_square_pixel(g_extern.system.av_info.geometry.base_width,
g_extern.system.av_info.geometry.base_height);
break;
case ASPECT_RATIO_CORE:
gfx_set_core_viewport();
video_viewport_set_core();
break;
case ASPECT_RATIO_CONFIG:
gfx_set_config_viewport();
video_viewport_set_config();
break;
default:

View File

@ -20,7 +20,7 @@
#include <string.h>
#include "../../general.h"
#include <gfx/scaler/scaler.h>
#include "../gfx_common.h"
#include "../video_viewport.h"
#include "../video_monitor.h"
#include "../video_context_driver.h"
#include "../font_renderer_driver.h"
@ -434,16 +434,16 @@ static void sdl_set_aspect_ratio(void *data, unsigned aspectratio_index)
switch (aspectratio_index)
{
case ASPECT_RATIO_SQUARE:
gfx_set_square_pixel_viewport(g_extern.system.av_info.geometry.base_width,
video_viewport_set_square_pixel(g_extern.system.av_info.geometry.base_width,
g_extern.system.av_info.geometry.base_height);
break;
case ASPECT_RATIO_CORE:
gfx_set_core_viewport();
video_viewport_set_core();
break;
case ASPECT_RATIO_CONFIG:
gfx_set_config_viewport();
video_viewport_set_config();
break;
default:

View File

@ -19,7 +19,7 @@
#include <string.h>
#include <signal.h>
#include <math.h>
#include "../gfx_common.h"
#include "../video_viewport.h"
#include "../video_monitor.h"
#include "../font_renderer_driver.h"
@ -358,7 +358,7 @@ static void calc_out_rect(bool keep_aspect, struct rarch_viewport *vp,
if (g_settings.video.scale_integer)
{
gfx_scale_integer(vp, vp_width, vp_height, g_extern.system.aspect_ratio, keep_aspect);
video_viewport_get_scaled_integer(vp, vp_width, vp_height, g_extern.system.aspect_ratio, keep_aspect);
}
else if (!keep_aspect)
{

View File

@ -16,7 +16,6 @@
#include "../../driver.h"
#include "../../general.h"
#include "../gfx_common.h"
#include "../video_monitor.h"
#include "../gl_common.h"

View File

@ -16,7 +16,6 @@
#include "../../driver.h"
#include "../../general.h"
#include "../gfx_common.h"
#include "../video_monitor.h"
#include "../gl_common.h"

View File

@ -18,7 +18,6 @@
#include "../d3d/d3d.h"
#include "win32_common.h"
#include "../gfx_common.h"
#include "../video_monitor.h"
#ifdef _MSC_VER

View File

@ -20,7 +20,6 @@
#include "../../driver.h"
#include "../gl_common.h"
#include "../gfx_common.h"
#include "../video_monitor.h"
#include <file/dir_list.h>

View File

@ -17,7 +17,6 @@
#include "../../driver.h"
#include "../video_context_driver.h"
#include "../gl_common.h"
#include "../gfx_common.h"
#include "../video_monitor.h"
#ifdef HAVE_CONFIG_H

View File

@ -18,7 +18,6 @@
#include "../../driver.h"
#include "../video_context_driver.h"
#include "../gfx_common.h"
#include "../video_monitor.h"
static void gfx_ctx_null_swap_interval(void *data, unsigned interval)

View File

@ -16,7 +16,6 @@
#include "../../driver.h"
#include "../gl_common.h"
#include "../gfx_common.h"
#include "../video_monitor.h"
#include "x11_common.h"

View File

@ -15,7 +15,6 @@
#include "../../driver.h"
#include "../../general.h"
#include "../gfx_common.h"
#include "../video_monitor.h"
#include "../gl_common.h"

View File

@ -23,7 +23,6 @@
#endif
#endif
#include "../gfx_common.h"
#include "../video_monitor.h"
#ifndef __PSL1GHT__

View File

@ -16,7 +16,6 @@
#include "../../driver.h"
#include "../gl_common.h"
#include "../gfx_common.h"
#include "../video_monitor.h"
#include "SDL.h"

View File

@ -17,7 +17,6 @@
#include "../../driver.h"
#include "../video_context_driver.h"
#include "../gl_common.h"
#include "../gfx_common.h"
#include "../video_monitor.h"
#ifdef HAVE_CONFIG_H

View File

@ -16,7 +16,6 @@
#include "../../driver.h"
#include "../../general.h"
#include "../gfx_common.h"
#include "../video_monitor.h"
#include "../gl_common.h"

View File

@ -16,7 +16,6 @@
#include "../../driver.h"
#include "../../general.h"
#include "../gfx_common.h"
#include "../video_monitor.h"
#include "../gl_common.h"

View File

@ -24,7 +24,6 @@
#include "../../driver.h"
#include "../video_context_driver.h"
#include "../gl_common.h"
#include "../gfx_common.h"
#include "../video_monitor.h"
#include "win32_common.h"
#include <windows.h>

View File

@ -18,7 +18,6 @@
#endif
#include "../../driver.h"
#include "../gfx_common.h"
#include "win32_common.h"
#include <windows.h>
#include <commdlg.h>

View File

@ -20,7 +20,6 @@
#include "../../driver.h"
#include "../gl_common.h"
#include "../gfx_common.h"
#include "../video_monitor.h"
#include "x11_common.h"

View File

@ -16,7 +16,6 @@
#include "../d3d/d3d.h"
#include "../font_d3d_driver.h"
#include "../gfx_common.h"
#include "../../general.h"
static LPD3DXFONT d3d_font;

View File

@ -14,7 +14,6 @@
* If not, see <http://www.gnu.org/licenses/>.
*/
#include "../gfx_common.h"
#include "../gl_common.h"
#include "../video_shader_driver.h"

View File

@ -15,7 +15,6 @@
*/
#include "../font_renderer_driver.h"
#include "../gfx_common.h"
#include "../gl_common.h"
#if defined(SN_TARGET_PSP2)

View File

@ -16,7 +16,6 @@
#include <xtl.h>
#include "../font_d3d_driver.h"
#include "../gfx_common.h"
#include "../../general.h"
static XFONT *debug_font;

View File

@ -17,7 +17,6 @@
#include <xtl.h>
#include "../font_d3d_driver.h"
#include "../d3d/d3d.h"
#include "../gfx_common.h"
#include "../../general.h"
#include "../../xdk/xdk_resources.h"

View File

@ -86,191 +86,3 @@ void gfx_set_dwm(void)
dwm_composition_disabled = g_settings.video.disable_composition;
}
#endif
/**
* gfx_scale_integer:
* @vp : Viewport handle
* @width : Width.
* @height : Height.
* @aspect_ratio : Aspect ratio (in float).
* @keep_aspect : Preserve aspect ratio?
*
* Gets new viewport scaling dimensions based on
* scaled integer aspect ratio.
**/
void gfx_scale_integer(struct rarch_viewport *vp, unsigned width,
unsigned height, float aspect_ratio, bool keep_aspect)
{
int padding_x = 0, padding_y = 0;
if (g_settings.video.aspect_ratio_idx == ASPECT_RATIO_CUSTOM)
{
const struct rarch_viewport *custom =
(const struct rarch_viewport*)
&g_extern.console.screen.viewports.custom_vp;
padding_x = width - custom->width;
padding_y = height - custom->height;
width = custom->width;
height = custom->height;
}
else
{
unsigned base_width;
/* Use system reported sizes as these define the
* geometry for the "normal" case. */
unsigned base_height = g_extern.system.av_info.geometry.base_height;
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
* g_extern.system.av_info.base_height. */
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;
}
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"
};
/**
* gfx_set_square_pixel_viewport:
* @width : Width.
* @height : Height.
*
* Sets viewport to square pixel aspect ratio based on @width and @height.
**/
void gfx_set_square_pixel_viewport(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;
}
/**
* gfx_set_core_viewport:
*
* Sets viewport to aspect ratio set by core A/V info.
**/
void gfx_set_core_viewport(void)
{
const struct retro_game_geometry *geom =
(const struct retro_game_geometry*)&g_extern.system.av_info.geometry;
if (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;
}
void gfx_set_config_viewport(void)
{
if (g_settings.video.aspect_ratio < 0.0f)
{
const struct retro_game_geometry *geom =
(const struct retro_game_geometry*)
&g_extern.system.av_info.geometry;
if (geom->aspect_ratio > 0.0f && g_settings.video.aspect_ratio_auto)
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 =
g_settings.video.aspect_ratio;
}

View File

@ -34,103 +34,6 @@ extern "C" {
void gfx_set_dwm(void);
#endif
/**
* gfx_scale_integer:
* @vp : Viewport handle
* @width : Width.
* @height : Height.
* @aspect_ratio : Aspect ratio (in float).
* @keep_aspect : Preserve aspect ratio?
*
* Gets new viewport scaling dimensions based on
* scaled integer aspect ratio.
**/
void gfx_scale_integer(struct rarch_viewport *vp,
unsigned win_width, unsigned win_height,
float aspect_ratio, bool keep_aspect);
enum aspect_ratio
{
ASPECT_RATIO_4_3 = 0,
ASPECT_RATIO_16_9,
ASPECT_RATIO_16_10,
ASPECT_RATIO_16_15,
ASPECT_RATIO_1_1,
ASPECT_RATIO_2_1,
ASPECT_RATIO_3_2,
ASPECT_RATIO_3_4,
ASPECT_RATIO_4_1,
ASPECT_RATIO_4_4,
ASPECT_RATIO_5_4,
ASPECT_RATIO_6_5,
ASPECT_RATIO_7_9,
ASPECT_RATIO_8_3,
ASPECT_RATIO_8_7,
ASPECT_RATIO_19_12,
ASPECT_RATIO_19_14,
ASPECT_RATIO_30_17,
ASPECT_RATIO_32_9,
ASPECT_RATIO_CONFIG,
ASPECT_RATIO_SQUARE,
ASPECT_RATIO_CORE,
ASPECT_RATIO_CUSTOM,
ASPECT_RATIO_END
};
#define LAST_ASPECT_RATIO ASPECT_RATIO_CUSTOM
enum rotation
{
ORIENTATION_NORMAL = 0,
ORIENTATION_VERTICAL,
ORIENTATION_FLIPPED,
ORIENTATION_FLIPPED_ROTATED,
ORIENTATION_END
};
extern char rotation_lut[4][32];
/* ABGR color format defines */
#define WHITE 0xffffffffu
#define RED 0xff0000ffu
#define GREEN 0xff00ff00u
#define BLUE 0xffff0000u
#define YELLOW 0xff00ffffu
#define PURPLE 0xffff00ffu
#define CYAN 0xffffff00u
#define ORANGE 0xff0063ffu
#define SILVER 0xff8c848cu
#define LIGHTBLUE 0xFFFFE0E0U
#define LIGHTORANGE 0xFFE0EEFFu
struct aspect_ratio_elem
{
char name[64];
float value;
};
extern struct aspect_ratio_elem aspectratio_lut[ASPECT_RATIO_END];
/**
* gfx_set_square_pixel_viewport:
* @width : Width.
* @height : Height.
*
* Sets viewport to square pixel aspect ratio based on @width and @height.
**/
void gfx_set_square_pixel_viewport(unsigned width, unsigned height);
/**
* gfx_set_core_viewport:
*
* Sets viewport to aspect ratio set by core A/V info.
**/
void gfx_set_core_viewport(void);
void gfx_set_config_viewport(void);
#ifdef __cplusplus
}
#endif

212
gfx/video_viewport.c Normal file
View File

@ -0,0 +1,212 @@
/* 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"
#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"
};
/**
* 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_core:
*
* Sets viewport to aspect ratio set by core.
**/
void video_viewport_set_core(void)
{
const struct retro_game_geometry *geom =
(const struct retro_game_geometry*)&g_extern.system.av_info.geometry;
if (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:
*
* Sets viewport to config aspect ratio.
**/
void video_viewport_set_config(void)
{
if (g_settings.video.aspect_ratio < 0.0f)
{
const struct retro_game_geometry *geom =
(const struct retro_game_geometry*)
&g_extern.system.av_info.geometry;
if (geom->aspect_ratio > 0.0f && g_settings.video.aspect_ratio_auto)
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 =
g_settings.video.aspect_ratio;
}
/**
* 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.
**/
void video_viewport_get_scaled_integer(struct rarch_viewport *vp,
unsigned width, unsigned height,
float aspect_ratio, bool keep_aspect)
{
int padding_x = 0, padding_y = 0;
if (g_settings.video.aspect_ratio_idx == ASPECT_RATIO_CUSTOM)
{
const struct rarch_viewport *custom =
(const struct rarch_viewport*)
&g_extern.console.screen.viewports.custom_vp;
padding_x = width - custom->width;
padding_y = height - custom->height;
width = custom->width;
height = custom->height;
}
else
{
unsigned base_width;
/* Use system reported sizes as these define the
* geometry for the "normal" case. */
unsigned base_height = g_extern.system.av_info.geometry.base_height;
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
* g_extern.system.av_info.base_height. */
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;
}

135
gfx/video_viewport.h Normal file
View File

@ -0,0 +1,135 @@
/* 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/>.
*/
#ifndef _VIDEO_VIEWPORT_H
#define _VIDEO_VIEWPORT_H
#include <stddef.h>
#include <stdint.h>
#include <boolean.h>
#include "../general.h"
#ifdef __cplusplus
extern "C" {
#endif
enum aspect_ratio
{
ASPECT_RATIO_4_3 = 0,
ASPECT_RATIO_16_9,
ASPECT_RATIO_16_10,
ASPECT_RATIO_16_15,
ASPECT_RATIO_1_1,
ASPECT_RATIO_2_1,
ASPECT_RATIO_3_2,
ASPECT_RATIO_3_4,
ASPECT_RATIO_4_1,
ASPECT_RATIO_4_4,
ASPECT_RATIO_5_4,
ASPECT_RATIO_6_5,
ASPECT_RATIO_7_9,
ASPECT_RATIO_8_3,
ASPECT_RATIO_8_7,
ASPECT_RATIO_19_12,
ASPECT_RATIO_19_14,
ASPECT_RATIO_30_17,
ASPECT_RATIO_32_9,
ASPECT_RATIO_CONFIG,
ASPECT_RATIO_SQUARE,
ASPECT_RATIO_CORE,
ASPECT_RATIO_CUSTOM,
ASPECT_RATIO_END
};
#define LAST_ASPECT_RATIO ASPECT_RATIO_CUSTOM
enum rotation
{
ORIENTATION_NORMAL = 0,
ORIENTATION_VERTICAL,
ORIENTATION_FLIPPED,
ORIENTATION_FLIPPED_ROTATED,
ORIENTATION_END
};
extern char rotation_lut[4][32];
/* ABGR color format defines */
#define WHITE 0xffffffffu
#define RED 0xff0000ffu
#define GREEN 0xff00ff00u
#define BLUE 0xffff0000u
#define YELLOW 0xff00ffffu
#define PURPLE 0xffff00ffu
#define CYAN 0xffffff00u
#define ORANGE 0xff0063ffu
#define SILVER 0xff8c848cu
#define LIGHTBLUE 0xFFFFE0E0U
#define LIGHTORANGE 0xFFE0EEFFu
struct aspect_ratio_elem
{
char name[64];
float value;
};
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_core:
*
* Sets viewport to aspect ratio set by core.
**/
void video_viewport_set_core(void);
/**
* video_viewport_set_config:
*
* Sets viewport to config aspect ratio.
**/
void video_viewport_set_config(void);
/**
* 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.
**/
void video_viewport_get_scaled_integer(struct rarch_viewport *vp,
unsigned width, unsigned height,
float aspect_ratio, bool keep_aspect);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -508,6 +508,7 @@ DRIVERS
#include "../gfx/video_driver.c"
#include "../gfx/video_monitor.c"
#include "../gfx/video_pixel_converter.c"
#include "../gfx/video_viewport.c"
#include "../input/input_driver.c"
#include "../audio/audio_driver.c"
#include "../audio/audio_monitor.c"

View File

@ -24,7 +24,6 @@
#include "../menu_action.h"
#include "../menu_navigation.h"
#include "../../gfx/gfx_common.h"
#include "../../driver.h"
#include "../../file_ext.h"
#include "../../input/input_common.h"

View File

@ -24,7 +24,6 @@
#include "../menu_driver.h"
#include "../menu.h"
#include "../../general.h"
#include "../../gfx/gfx_common.h"
#include "../../config.def.h"
#include <compat/posix_string.h>
#include "../../performance.h"

View File

@ -24,7 +24,6 @@
#include "../menu.h"
#include "../menu_list.h"
#include "../../gfx/gfx_common.h"
#include "../../gfx/video_context_driver.h"
#include "../../settings_data.h"