From 80d4de7c3f74ba5246ec0992d13fb967b801f21b Mon Sep 17 00:00:00 2001 From: twinaphex Date: Sun, 18 Jan 2015 23:59:57 +0100 Subject: [PATCH] Add gfx/video_viewport.c/viewport.h --- Makefile.common | 1 + apple/common/apple_gfx_context.c.inl | 2 +- config.def.h | 2 +- driver.c | 6 +- general.h | 21 ++- gfx/d3d/d3d.cpp | 10 +- gfx/d3d/d3d.h | 1 - gfx/drivers/exynos_gfx.c | 8 +- gfx/drivers/gl.c | 10 +- gfx/drivers/gx_gfx.c | 8 +- gfx/drivers/omap_gfx.c | 2 +- gfx/drivers/psp1_gfx.c | 10 +- gfx/drivers/sdl2_gfx.c | 10 +- gfx/drivers/sdl_gfx.c | 8 +- gfx/drivers/xvideo.c | 4 +- gfx/drivers_context/androidegl_ctx.c | 1 - gfx/drivers_context/bbqnx_ctx.c | 1 - gfx/drivers_context/d3d_ctx.cpp | 1 - gfx/drivers_context/drm_egl_ctx.c | 1 - gfx/drivers_context/emscriptenegl_ctx.c | 1 - gfx/drivers_context/gfx_null_ctx.c | 1 - gfx/drivers_context/glx_ctx.c | 1 - gfx/drivers_context/mali_fbdev_ctx.c | 1 - gfx/drivers_context/ps3_ctx.c | 1 - gfx/drivers_context/sdl_gl_ctx.c | 1 - gfx/drivers_context/vc_egl_ctx.c | 1 - gfx/drivers_context/vivante_fbdev_ctx.c | 1 - gfx/drivers_context/wayland_ctx.c | 1 - gfx/drivers_context/wgl_ctx.c | 1 - gfx/drivers_context/win32_common.c | 1 - gfx/drivers_context/xegl_ctx.c | 1 - gfx/drivers_font/d3d_w32_font.cpp | 1 - gfx/drivers_font/gl_raster_font.c | 1 - gfx/drivers_font/ps_libdbgfont.c | 1 - gfx/drivers_font/xdk1_xfonts.c | 1 - gfx/drivers_font/xdk360_fonts.cpp | 1 - gfx/gfx_common.c | 188 ------------------- gfx/gfx_common.h | 97 ---------- gfx/video_viewport.c | 212 ++++++++++++++++++++++ gfx/video_viewport.h | 135 ++++++++++++++ griffin/griffin.c | 1 + menu/drivers_backend/menu_lakka_backend.c | 1 - menu/drivers_display/rmenu.c | 1 - menu/drivers_display/rmenu_xui.cpp | 1 - 44 files changed, 400 insertions(+), 360 deletions(-) create mode 100644 gfx/video_viewport.c create mode 100644 gfx/video_viewport.h diff --git a/Makefile.common b/Makefile.common index fcd4a50663..5634890559 100644 --- a/Makefile.common +++ b/Makefile.common @@ -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 \ diff --git a/apple/common/apple_gfx_context.c.inl b/apple/common/apple_gfx_context.c.inl index eecc984758..859690204e 100644 --- a/apple/common/apple_gfx_context.c.inl +++ b/apple/common/apple_gfx_context.c.inl @@ -3,7 +3,7 @@ #include #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" diff --git a/config.def.h b/config.def.h index faa3a5801a..898a3cfa97 100644 --- a/config.def.h +++ b/config.def.h @@ -20,7 +20,7 @@ #include #include "libretro.h" #include "driver.h" -#include "gfx/gfx_common.h" +#include "gfx/video_viewport.h" #ifdef HAVE_CONFIG_H #include "config.h" diff --git a/driver.c b/driver.c index 297435d6f4..56e8d438f9 100644 --- a/driver.c +++ b/driver.c @@ -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; diff --git a/general.h b/general.h index a7f847de1d..25ccef6efb 100644 --- a/general.h +++ b/general.h @@ -31,6 +31,7 @@ #include "core_options.h" #include "core_info.h" #include +#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) diff --git a/gfx/d3d/d3d.cpp b/gfx/d3d/d3d.cpp index 0c17d07236..46bfc537e5 100644 --- a/gfx/d3d/d3d.cpp +++ b/gfx/d3d/d3d.cpp @@ -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: diff --git a/gfx/d3d/d3d.h b/gfx/d3d/d3d.h index 809a55a883..e713663fa9 100644 --- a/gfx/d3d/d3d.h +++ b/gfx/d3d/d3d.h @@ -51,7 +51,6 @@ #include "../font_d3d_driver.h" #include "../video_context_driver.h" -#include "../gfx_common.h" #ifdef HAVE_CG #include diff --git a/gfx/drivers/exynos_gfx.c b/gfx/drivers/exynos_gfx.c index 22a9a8511e..c0482a2fc2 100644 --- a/gfx/drivers/exynos_gfx.c +++ b/gfx/drivers/exynos_gfx.c @@ -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: diff --git a/gfx/drivers/gl.c b/gfx/drivers/gl.c index 390117ef87..cdc3129fdd 100644 --- a/gfx/drivers/gl.c +++ b/gfx/drivers/gl.c @@ -37,7 +37,7 @@ #endif #include "../gl_common.h" -#include "../gfx_common.h" +#include "../video_viewport.h" #include "../video_context_driver.h" #include @@ -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: diff --git a/gfx/drivers/gx_gfx.c b/gfx/drivers/gx_gfx.c index 3ccf10f2bf..13ae141a15 100644 --- a/gfx/drivers/gx_gfx.c +++ b/gfx/drivers/gx_gfx.c @@ -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; diff --git a/gfx/drivers/omap_gfx.c b/gfx/drivers/omap_gfx.c index 20ab5f0d9f..a33354275d 100644 --- a/gfx/drivers/omap_gfx.c +++ b/gfx/drivers/omap_gfx.c @@ -20,7 +20,7 @@ #include "../../general.h" #include "../../retroarch.h" #include -#include "../gfx_common.h" +#include "../video_viewport.h" #include "../video_monitor.h" #include "../video_context_driver.h" #include "../font_renderer_driver.h" diff --git a/gfx/drivers/psp1_gfx.c b/gfx/drivers/psp1_gfx.c index cfdba1aaea..c905d60b2e 100644 --- a/gfx/drivers/psp1_gfx.c +++ b/gfx/drivers/psp1_gfx.c @@ -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: diff --git a/gfx/drivers/sdl2_gfx.c b/gfx/drivers/sdl2_gfx.c index 73413a06bf..e1f60ab8ed 100644 --- a/gfx/drivers/sdl2_gfx.c +++ b/gfx/drivers/sdl2_gfx.c @@ -23,7 +23,7 @@ #include "../../retroarch.h" #include "../../performance.h" #include -#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: diff --git a/gfx/drivers/sdl_gfx.c b/gfx/drivers/sdl_gfx.c index 756c65493c..f5e50e50a7 100644 --- a/gfx/drivers/sdl_gfx.c +++ b/gfx/drivers/sdl_gfx.c @@ -20,7 +20,7 @@ #include #include "../../general.h" #include -#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: diff --git a/gfx/drivers/xvideo.c b/gfx/drivers/xvideo.c index d4b7543b24..203eed0d2f 100644 --- a/gfx/drivers/xvideo.c +++ b/gfx/drivers/xvideo.c @@ -19,7 +19,7 @@ #include #include #include -#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) { diff --git a/gfx/drivers_context/androidegl_ctx.c b/gfx/drivers_context/androidegl_ctx.c index 50d19bfbd3..dc923bc879 100644 --- a/gfx/drivers_context/androidegl_ctx.c +++ b/gfx/drivers_context/androidegl_ctx.c @@ -16,7 +16,6 @@ #include "../../driver.h" #include "../../general.h" -#include "../gfx_common.h" #include "../video_monitor.h" #include "../gl_common.h" diff --git a/gfx/drivers_context/bbqnx_ctx.c b/gfx/drivers_context/bbqnx_ctx.c index 1722302ac8..56d8e1ac8f 100644 --- a/gfx/drivers_context/bbqnx_ctx.c +++ b/gfx/drivers_context/bbqnx_ctx.c @@ -16,7 +16,6 @@ #include "../../driver.h" #include "../../general.h" -#include "../gfx_common.h" #include "../video_monitor.h" #include "../gl_common.h" diff --git a/gfx/drivers_context/d3d_ctx.cpp b/gfx/drivers_context/d3d_ctx.cpp index 982be1a517..259615436b 100644 --- a/gfx/drivers_context/d3d_ctx.cpp +++ b/gfx/drivers_context/d3d_ctx.cpp @@ -18,7 +18,6 @@ #include "../d3d/d3d.h" #include "win32_common.h" -#include "../gfx_common.h" #include "../video_monitor.h" #ifdef _MSC_VER diff --git a/gfx/drivers_context/drm_egl_ctx.c b/gfx/drivers_context/drm_egl_ctx.c index 2d33b6f784..a79a81953e 100644 --- a/gfx/drivers_context/drm_egl_ctx.c +++ b/gfx/drivers_context/drm_egl_ctx.c @@ -20,7 +20,6 @@ #include "../../driver.h" #include "../gl_common.h" -#include "../gfx_common.h" #include "../video_monitor.h" #include diff --git a/gfx/drivers_context/emscriptenegl_ctx.c b/gfx/drivers_context/emscriptenegl_ctx.c index f9054f1664..7715be30e8 100644 --- a/gfx/drivers_context/emscriptenegl_ctx.c +++ b/gfx/drivers_context/emscriptenegl_ctx.c @@ -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 diff --git a/gfx/drivers_context/gfx_null_ctx.c b/gfx/drivers_context/gfx_null_ctx.c index 9ae51b16a1..285f214cc4 100644 --- a/gfx/drivers_context/gfx_null_ctx.c +++ b/gfx/drivers_context/gfx_null_ctx.c @@ -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) diff --git a/gfx/drivers_context/glx_ctx.c b/gfx/drivers_context/glx_ctx.c index 91e05a7937..5317d167b1 100644 --- a/gfx/drivers_context/glx_ctx.c +++ b/gfx/drivers_context/glx_ctx.c @@ -16,7 +16,6 @@ #include "../../driver.h" #include "../gl_common.h" -#include "../gfx_common.h" #include "../video_monitor.h" #include "x11_common.h" diff --git a/gfx/drivers_context/mali_fbdev_ctx.c b/gfx/drivers_context/mali_fbdev_ctx.c index a6c9f23a20..8baed37863 100644 --- a/gfx/drivers_context/mali_fbdev_ctx.c +++ b/gfx/drivers_context/mali_fbdev_ctx.c @@ -15,7 +15,6 @@ #include "../../driver.h" #include "../../general.h" -#include "../gfx_common.h" #include "../video_monitor.h" #include "../gl_common.h" diff --git a/gfx/drivers_context/ps3_ctx.c b/gfx/drivers_context/ps3_ctx.c index a2287f7b70..9dc92850d3 100644 --- a/gfx/drivers_context/ps3_ctx.c +++ b/gfx/drivers_context/ps3_ctx.c @@ -23,7 +23,6 @@ #endif #endif -#include "../gfx_common.h" #include "../video_monitor.h" #ifndef __PSL1GHT__ diff --git a/gfx/drivers_context/sdl_gl_ctx.c b/gfx/drivers_context/sdl_gl_ctx.c index 8b76158ef5..9691495ad3 100644 --- a/gfx/drivers_context/sdl_gl_ctx.c +++ b/gfx/drivers_context/sdl_gl_ctx.c @@ -16,7 +16,6 @@ #include "../../driver.h" #include "../gl_common.h" -#include "../gfx_common.h" #include "../video_monitor.h" #include "SDL.h" diff --git a/gfx/drivers_context/vc_egl_ctx.c b/gfx/drivers_context/vc_egl_ctx.c index 418b31dea6..6f6aa23e2a 100644 --- a/gfx/drivers_context/vc_egl_ctx.c +++ b/gfx/drivers_context/vc_egl_ctx.c @@ -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 diff --git a/gfx/drivers_context/vivante_fbdev_ctx.c b/gfx/drivers_context/vivante_fbdev_ctx.c index df3559c1c0..c20e1500c1 100644 --- a/gfx/drivers_context/vivante_fbdev_ctx.c +++ b/gfx/drivers_context/vivante_fbdev_ctx.c @@ -16,7 +16,6 @@ #include "../../driver.h" #include "../../general.h" -#include "../gfx_common.h" #include "../video_monitor.h" #include "../gl_common.h" diff --git a/gfx/drivers_context/wayland_ctx.c b/gfx/drivers_context/wayland_ctx.c index cd06809fd7..e43e1379d4 100644 --- a/gfx/drivers_context/wayland_ctx.c +++ b/gfx/drivers_context/wayland_ctx.c @@ -16,7 +16,6 @@ #include "../../driver.h" #include "../../general.h" -#include "../gfx_common.h" #include "../video_monitor.h" #include "../gl_common.h" diff --git a/gfx/drivers_context/wgl_ctx.c b/gfx/drivers_context/wgl_ctx.c index 9302137a66..db0767f201 100644 --- a/gfx/drivers_context/wgl_ctx.c +++ b/gfx/drivers_context/wgl_ctx.c @@ -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 diff --git a/gfx/drivers_context/win32_common.c b/gfx/drivers_context/win32_common.c index a1bf009cc3..7878324fbc 100644 --- a/gfx/drivers_context/win32_common.c +++ b/gfx/drivers_context/win32_common.c @@ -18,7 +18,6 @@ #endif #include "../../driver.h" -#include "../gfx_common.h" #include "win32_common.h" #include #include diff --git a/gfx/drivers_context/xegl_ctx.c b/gfx/drivers_context/xegl_ctx.c index c2feaac244..a476fe58c6 100644 --- a/gfx/drivers_context/xegl_ctx.c +++ b/gfx/drivers_context/xegl_ctx.c @@ -20,7 +20,6 @@ #include "../../driver.h" #include "../gl_common.h" -#include "../gfx_common.h" #include "../video_monitor.h" #include "x11_common.h" diff --git a/gfx/drivers_font/d3d_w32_font.cpp b/gfx/drivers_font/d3d_w32_font.cpp index bb32272272..d48be503bd 100644 --- a/gfx/drivers_font/d3d_w32_font.cpp +++ b/gfx/drivers_font/d3d_w32_font.cpp @@ -16,7 +16,6 @@ #include "../d3d/d3d.h" #include "../font_d3d_driver.h" -#include "../gfx_common.h" #include "../../general.h" static LPD3DXFONT d3d_font; diff --git a/gfx/drivers_font/gl_raster_font.c b/gfx/drivers_font/gl_raster_font.c index e3f003cf2d..73a0af844c 100644 --- a/gfx/drivers_font/gl_raster_font.c +++ b/gfx/drivers_font/gl_raster_font.c @@ -14,7 +14,6 @@ * If not, see . */ -#include "../gfx_common.h" #include "../gl_common.h" #include "../video_shader_driver.h" diff --git a/gfx/drivers_font/ps_libdbgfont.c b/gfx/drivers_font/ps_libdbgfont.c index 517f1f7ab4..fb78f5b8c8 100644 --- a/gfx/drivers_font/ps_libdbgfont.c +++ b/gfx/drivers_font/ps_libdbgfont.c @@ -15,7 +15,6 @@ */ #include "../font_renderer_driver.h" -#include "../gfx_common.h" #include "../gl_common.h" #if defined(SN_TARGET_PSP2) diff --git a/gfx/drivers_font/xdk1_xfonts.c b/gfx/drivers_font/xdk1_xfonts.c index e72479ef2e..c22851a222 100644 --- a/gfx/drivers_font/xdk1_xfonts.c +++ b/gfx/drivers_font/xdk1_xfonts.c @@ -16,7 +16,6 @@ #include #include "../font_d3d_driver.h" -#include "../gfx_common.h" #include "../../general.h" static XFONT *debug_font; diff --git a/gfx/drivers_font/xdk360_fonts.cpp b/gfx/drivers_font/xdk360_fonts.cpp index 436f3054a3..12a77c8549 100644 --- a/gfx/drivers_font/xdk360_fonts.cpp +++ b/gfx/drivers_font/xdk360_fonts.cpp @@ -17,7 +17,6 @@ #include #include "../font_d3d_driver.h" #include "../d3d/d3d.h" -#include "../gfx_common.h" #include "../../general.h" #include "../../xdk/xdk_resources.h" diff --git a/gfx/gfx_common.c b/gfx/gfx_common.c index 32a87f0d89..840c383125 100644 --- a/gfx/gfx_common.c +++ b/gfx/gfx_common.c @@ -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; -} diff --git a/gfx/gfx_common.h b/gfx/gfx_common.h index e3f361dc5f..d7265147ca 100644 --- a/gfx/gfx_common.h +++ b/gfx/gfx_common.h @@ -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 diff --git a/gfx/video_viewport.c b/gfx/video_viewport.c new file mode 100644 index 0000000000..a234be5ccc --- /dev/null +++ b/gfx/video_viewport.c @@ -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 . + */ + +#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; +} diff --git a/gfx/video_viewport.h b/gfx/video_viewport.h new file mode 100644 index 0000000000..3560f7df17 --- /dev/null +++ b/gfx/video_viewport.h @@ -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 . + */ + +#ifndef _VIDEO_VIEWPORT_H +#define _VIDEO_VIEWPORT_H + +#include +#include +#include +#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 diff --git a/griffin/griffin.c b/griffin/griffin.c index 36d7860949..a3979d8f8b 100644 --- a/griffin/griffin.c +++ b/griffin/griffin.c @@ -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" diff --git a/menu/drivers_backend/menu_lakka_backend.c b/menu/drivers_backend/menu_lakka_backend.c index f4833ecc71..7b1d4847f0 100644 --- a/menu/drivers_backend/menu_lakka_backend.c +++ b/menu/drivers_backend/menu_lakka_backend.c @@ -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" diff --git a/menu/drivers_display/rmenu.c b/menu/drivers_display/rmenu.c index c89fbebe09..8f697ee02e 100644 --- a/menu/drivers_display/rmenu.c +++ b/menu/drivers_display/rmenu.c @@ -24,7 +24,6 @@ #include "../menu_driver.h" #include "../menu.h" #include "../../general.h" -#include "../../gfx/gfx_common.h" #include "../../config.def.h" #include #include "../../performance.h" diff --git a/menu/drivers_display/rmenu_xui.cpp b/menu/drivers_display/rmenu_xui.cpp index 48eca9cdf2..09866ca152 100644 --- a/menu/drivers_display/rmenu_xui.cpp +++ b/menu/drivers_display/rmenu_xui.cpp @@ -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"