Merge video_viewport.c and video_driver.c

This commit is contained in:
twinaphex 2015-11-21 13:01:23 +01:00
parent 5b44bd0e6b
commit 806c124eae
29 changed files with 250 additions and 327 deletions

View File

@ -149,7 +149,6 @@ OBJ += frontend/frontend.o \
gfx/video_common.o \
gfx/video_driver.o \
gfx/video_pixel_converter.o \
gfx/video_viewport.o \
camera/camera_driver.o \
location/location_driver.o \
driver.o \

View File

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

View File

@ -26,7 +26,6 @@
#include <file/file_path.h>
#include "d3d.h"
#include "../video_viewport.h"
#include "../video_monitor.h"
#include "../video_common.h"
#include "../../dynamic.h"

View File

@ -54,7 +54,6 @@
#include "../font_driver.h"
#include "../font_renderer_driver.h"
#include "../video_context_driver.h"
#include "../video_viewport.h"
#include "../common/d3d_common.h"
#include "render_chain_driver.h"
#ifdef _XBOX

View File

@ -19,7 +19,6 @@
#include "../video_shader_parse.h"
#include "../video_state_tracker.h"
#include "../video_viewport.h"
#include "../../libretro.h"
#include "../../defines/d3d_defines.h"

View File

@ -22,7 +22,6 @@
#include "../../general.h"
#include "../../driver.h"
#include "../video_viewport.h"
#include "../video_monitor.h"
#include "retroarch.h"

View File

@ -16,7 +16,6 @@
#include "../../driver.h"
#include "../../general.h"
#include "../../retroarch.h"
#include "../video_viewport.h"
#include "../video_monitor.h"
#include "../video_context_driver.h"
#include "../font_renderer_driver.h"

View File

@ -35,7 +35,6 @@
#include "../../general.h"
#include "../../retroarch.h"
#include "../../runloop.h"
#include "../video_viewport.h"
#include "../video_monitor.h"
#include "../font_renderer_driver.h"

View File

@ -42,7 +42,6 @@
#endif
#include "../font_driver.h"
#include "../video_viewport.h"
#include "../video_pixel_converter.h"
#include "../video_context_driver.h"
#include "../video_texture.h"

View File

@ -28,7 +28,6 @@
#include "../drivers_font_renderer/bitmap.h"
#include "../../menu/menu_driver.h"
#include "../../menu/menu_display.h"
#include "../video_viewport.h"
#include "../video_monitor.h"
#ifdef HW_RVL

View File

@ -16,7 +16,6 @@
#include "../../general.h"
#include "../../driver.h"
#include "../video_viewport.h"
static void *null_gfx_init(const video_info_t *video,
const input_driver_t **input, void **input_data)

View File

@ -21,7 +21,6 @@
#include "../../retroarch.h"
#include <gfx/scaler/scaler.h>
#include <retro_inline.h>
#include "../video_viewport.h"
#include "../video_monitor.h"
#include "../video_context_driver.h"
#include "../font_renderer_driver.h"

View File

@ -25,7 +25,6 @@
#include "../../defines/psp_defines.h"
#include "../../general.h"
#include "../../driver.h"
#include "../video_viewport.h"
#include "../video_monitor.h"
#ifndef SCEGU_SCR_WIDTH

View File

@ -24,7 +24,6 @@
#include "../../performance.h"
#include <retro_inline.h>
#include <gfx/scaler/scaler.h>
#include "../video_viewport.h"
#include "../video_monitor.h"
#include "../video_context_driver.h"
#include "../font_renderer_driver.h"

View File

@ -21,7 +21,6 @@
#include "../../general.h"
#include "../../performance.h"
#include <gfx/scaler/scaler.h>
#include "../video_viewport.h"
#include "../video_monitor.h"
#include "../video_context_driver.h"
#include "../font_renderer_driver.h"

View File

@ -25,7 +25,6 @@
#include "../../general.h"
#include "../../retroarch.h"
#include "../video_viewport.h"
#include "../video_monitor.h"
#include "../font_renderer_driver.h"

View File

@ -33,7 +33,6 @@
#include "../font_renderer_driver.h"
#include "../../content.h"
#include "../../runloop.h"
#include "../video_viewport.h"
typedef struct
{

View File

@ -20,7 +20,6 @@
#include "../../defines/psp_defines.h"
#include "../../general.h"
#include "../../driver.h"
#include "../video_viewport.h"
#include "../video_monitor.h"
typedef struct vita_menu_frame

View File

@ -25,8 +25,6 @@
#include "../../driver.h"
#include "../../general.h"
#Include "../video_viewport.h"
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

View File

@ -19,7 +19,6 @@
#include <string.h>
#include <signal.h>
#include <math.h>
#include "../video_viewport.h"
#include "../video_monitor.h"
#include "../font_renderer_driver.h"
#include <retro_inline.h>

View File

@ -31,7 +31,6 @@
#include "../../driver.h"
#include "../../general.h"
#include "../video_viewport.h"
#include "../video_monitor.h"
#include "../font_renderer_driver.h"

View File

@ -65,6 +65,7 @@ typedef struct video_driver_state
} filter;
} video_driver_state_t;
static struct retro_system_av_info video_viewport_av_info;
static video_driver_state_t video_state;
char rotation_lut[4][32] =
@ -1487,3 +1488,132 @@ bool video_driver_ctl(enum rarch_display_ctl_state state, void *data)
return false;
}
/**
* video_viewport_set_config:
*
* Sets viewport to config aspect ratio.
**/
void video_viewport_set_config(void)
{
settings_t *settings = config_get_ptr();
struct retro_system_av_info *av_info = video_viewport_get_system_av_info();
if (settings->video.aspect_ratio < 0.0f)
{
struct retro_game_geometry *geom = &av_info->geometry;
if (!geom)
return;
if (geom->aspect_ratio > 0.0f && 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 =
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 video_viewport *vp,
unsigned width, unsigned height,
float aspect_ratio, bool keep_aspect)
{
int padding_x = 0, padding_y = 0;
settings_t *settings = config_get_ptr();
if (!vp)
return;
if (settings->video.aspect_ratio_idx == ASPECT_RATIO_CUSTOM)
{
struct video_viewport *custom = video_viewport_get_custom();
if (custom)
{
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. */
struct retro_system_av_info *av_info = video_viewport_get_system_av_info();
unsigned base_height = av_info ? av_info->geometry.base_height : 0;
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
* 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 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)
{
settings_t *settings = config_get_ptr();
return &settings->video_viewport_custom;
}

View File

@ -24,7 +24,6 @@
#include <gfx/scaler/scaler.h>
#include "video_filter.h"
#include "video_shader_parse.h"
#include "video_viewport.h"
#include "../libretro.h"
#include "../input/input_driver.h"
@ -126,6 +125,16 @@ typedef struct video_poke_interface
struct video_shader *(*get_current_shader)(void *data);
} video_poke_interface_t;
typedef struct video_viewport
{
int x;
int y;
unsigned width;
unsigned height;
unsigned full_width;
unsigned full_height;
} video_viewport_t;
typedef struct video_driver
{
/* Should the video driver act as an input driver as well?
@ -188,24 +197,71 @@ typedef struct video_driver
unsigned (*wrap_type_to_enum)(enum gfx_wrap_type type);
} video_driver_t;
extern video_driver_t video_gl;
extern video_driver_t video_psp1;
extern video_driver_t video_vita2d;
extern video_driver_t video_ctr;
extern video_driver_t video_d3d;
extern video_driver_t video_gx;
extern video_driver_t video_xenon360;
extern video_driver_t video_xvideo;
extern video_driver_t video_xdk_d3d;
extern video_driver_t video_sdl;
extern video_driver_t video_sdl2;
extern video_driver_t video_vg;
extern video_driver_t video_omap;
extern video_driver_t video_exynos;
extern video_driver_t video_dispmanx;
extern video_driver_t video_sunxi;
extern video_driver_t video_xshm;
extern video_driver_t video_null;
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];
enum rarch_display_type
{
@ -378,6 +434,51 @@ void video_driver_cached_frame_get(const void **data, unsigned *width,
void video_driver_menu_settings(void *data, void *subgroup_data, const char *parent_group);
/**
* 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 video_viewport *vp,
unsigned width, unsigned height,
float aspect_ratio, bool keep_aspect);
struct retro_system_av_info *video_viewport_get_system_av_info(void);
struct video_viewport *video_viewport_get_custom(void);
extern video_driver_t video_gl;
extern video_driver_t video_psp1;
extern video_driver_t video_vita2d;
extern video_driver_t video_ctr;
extern video_driver_t video_d3d;
extern video_driver_t video_gx;
extern video_driver_t video_xenon360;
extern video_driver_t video_xvideo;
extern video_driver_t video_xdk_d3d;
extern video_driver_t video_sdl;
extern video_driver_t video_sdl2;
extern video_driver_t video_vg;
extern video_driver_t video_omap;
extern video_driver_t video_exynos;
extern video_driver_t video_dispmanx;
extern video_driver_t video_sunxi;
extern video_driver_t video_xshm;
extern video_driver_t video_null;
#ifdef __cplusplus
}
#endif

View File

@ -1,148 +0,0 @@
/* 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 "../general.h"
static struct retro_system_av_info video_viewport_av_info;
/**
* video_viewport_set_config:
*
* Sets viewport to config aspect ratio.
**/
void video_viewport_set_config(void)
{
settings_t *settings = config_get_ptr();
struct retro_system_av_info *av_info = video_viewport_get_system_av_info();
if (settings->video.aspect_ratio < 0.0f)
{
struct retro_game_geometry *geom = &av_info->geometry;
if (!geom)
return;
if (geom->aspect_ratio > 0.0f && 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 =
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 video_viewport *vp,
unsigned width, unsigned height,
float aspect_ratio, bool keep_aspect)
{
int padding_x = 0, padding_y = 0;
settings_t *settings = config_get_ptr();
if (!vp)
return;
if (settings->video.aspect_ratio_idx == ASPECT_RATIO_CUSTOM)
{
struct video_viewport *custom = video_viewport_get_custom();
if (custom)
{
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. */
struct retro_system_av_info *av_info = video_viewport_get_system_av_info();
unsigned base_height = av_info ? av_info->geometry.base_height : 0;
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
* 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 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)
{
settings_t *settings = config_get_ptr();
return &settings->video_viewport_custom;
}

View File

@ -1,133 +0,0 @@
/* 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>
#ifdef __cplusplus
extern "C" {
#endif
typedef struct video_viewport
{
int x;
int y;
unsigned width;
unsigned height;
unsigned full_width;
unsigned full_height;
} video_viewport_t;
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_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 video_viewport *vp,
unsigned width, unsigned height,
float aspect_ratio, bool keep_aspect);
struct retro_system_av_info *video_viewport_get_system_av_info(void);
struct video_viewport *video_viewport_get_custom(void);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -535,7 +535,6 @@ DRIVERS
#include "../gfx/video_driver.c"
#include "../gfx/video_common.c"
#include "../gfx/video_pixel_converter.c"
#include "../gfx/video_viewport.c"
#include "../input/input_driver.c"
#include "../audio/audio_driver.c"
#include "../camera/camera_driver.c"

View File

@ -27,7 +27,6 @@
#include "../input_keymaps.h"
#include "../../driver.h"
#include "../../gfx/video_viewport.h"
#include "../../general.h"
typedef struct x11_input

View File

@ -28,8 +28,6 @@
#include "../config.h"
#endif
#include "../gfx/video_viewport.h"
static const char *bind_user_prefix[MAX_USERS] = {
"input_player1",
"input_player2",

View File

@ -46,7 +46,6 @@
#include "retroarch.h"
#include "screenshot.h"
#include "gfx/video_driver.h"
#include "gfx/video_viewport.h"
#ifdef HAVE_CONFIG_H
#include "config.h"