diff --git a/Makefile.common b/Makefile.common index 62a4f904c7..3d86328675 100644 --- a/Makefile.common +++ b/Makefile.common @@ -769,8 +769,7 @@ endif # Video -OBJ += gfx/video_context_driver.o \ - gfx/drivers_context/gfx_null_ctx.o \ +OBJ += gfx/drivers_context/gfx_null_ctx.o \ gfx/video_state_tracker.o ifeq ($(HAVE_KMS), 1) diff --git a/dynamic.c b/dynamic.c index 9d09cde824..d8341466a4 100644 --- a/dynamic.c +++ b/dynamic.c @@ -50,7 +50,7 @@ #include "core.h" #include "driver.h" #include "performance_counters.h" -#include "gfx/video_context_driver.h" +#include "gfx/video_driver.h" #include "cores/internal_cores.h" #include "frontend/frontend_driver.h" diff --git a/gfx/common/egl_common.h b/gfx/common/egl_common.h index 5e1dbc8ad1..70f48b666d 100644 --- a/gfx/common/egl_common.h +++ b/gfx/common/egl_common.h @@ -26,7 +26,7 @@ #include #include -#include "../video_context_driver.h" +#include "../video_driver.h" #ifndef EGL_CONTEXT_FLAGS_KHR #define EGL_CONTEXT_FLAGS_KHR 0x30FC diff --git a/gfx/common/gl_common.h b/gfx/common/gl_common.h index 46514d99f5..636d005618 100644 --- a/gfx/common/gl_common.h +++ b/gfx/common/gl_common.h @@ -31,7 +31,7 @@ #include "../../verbosity.h" #include "../font_driver.h" #include "../video_coord_array.h" -#include "../video_context_driver.h" +#include "../video_driver.h" #include "../drivers/gl_symlinks.h" RETRO_BEGIN_DECLS diff --git a/gfx/common/vulkan_common.h b/gfx/common/vulkan_common.h index a849d40410..69298845c5 100644 --- a/gfx/common/vulkan_common.h +++ b/gfx/common/vulkan_common.h @@ -46,7 +46,7 @@ #include "../../retroarch.h" #include "../../verbosity.h" #include "../font_driver.h" -#include "../video_context_driver.h" +#include "../video_driver.h" #include "../drivers_shader/shader_vulkan.h" RETRO_BEGIN_DECLS diff --git a/gfx/common/win32_common.h b/gfx/common/win32_common.h index d0a2baa31e..0dfca29025 100644 --- a/gfx/common/win32_common.h +++ b/gfx/common/win32_common.h @@ -27,7 +27,7 @@ #include #include #include "../../driver.h" -#include "../video_context_driver.h" +#include "../video_driver.h" #ifdef _XBOX #include "../../defines/xdk_defines.h" diff --git a/gfx/common/x11_common.h b/gfx/common/x11_common.h index ad745a70a7..96924485c1 100644 --- a/gfx/common/x11_common.h +++ b/gfx/common/x11_common.h @@ -22,7 +22,6 @@ #include #include "../video_driver.h" -#include "../video_context_driver.h" extern Window g_x11_win; extern Display *g_x11_dpy; diff --git a/gfx/drivers/d3d.h b/gfx/drivers/d3d.h index f78d8ccf12..919477fa72 100644 --- a/gfx/drivers/d3d.h +++ b/gfx/drivers/d3d.h @@ -51,7 +51,7 @@ #endif #include "../font_driver.h" -#include "../video_context_driver.h" +#include "../video_driver.h" #include "../common/d3d_common.h" #include "../video_renderchain_driver.h" #ifdef _XBOX diff --git a/gfx/drivers/dispmanx_gfx.c b/gfx/drivers/dispmanx_gfx.c index 0249322e6e..e69504770e 100644 --- a/gfx/drivers/dispmanx_gfx.c +++ b/gfx/drivers/dispmanx_gfx.c @@ -28,7 +28,6 @@ #include "../../driver.h" #include "../../retroarch.h" -#include "../video_context_driver.h" #include "../font_driver.h" struct dispmanx_page diff --git a/gfx/drivers/drm_gfx.c b/gfx/drivers/drm_gfx.c index 99eed65b59..223ab63aaa 100644 --- a/gfx/drivers/drm_gfx.c +++ b/gfx/drivers/drm_gfx.c @@ -37,7 +37,6 @@ #endif #include "../font_driver.h" -#include "../video_context_driver.h" #include "../../retroarch.h" #include "drm_pixformats.h" diff --git a/gfx/drivers/gl.c b/gfx/drivers/gl.c index 918ca002ac..fcc51031d1 100644 --- a/gfx/drivers/gl.c +++ b/gfx/drivers/gl.c @@ -54,7 +54,6 @@ #endif #include "../font_driver.h" -#include "../video_context_driver.h" #ifdef HAVE_GLSL #include "../drivers_shader/shader_glsl.h" diff --git a/gfx/drivers/omap_gfx.c b/gfx/drivers/omap_gfx.c index 3ddfcbd0ba..1adb488de1 100644 --- a/gfx/drivers/omap_gfx.c +++ b/gfx/drivers/omap_gfx.c @@ -49,8 +49,6 @@ #include "../../driver.h" #include "../../retroarch.h" -#include "../video_context_driver.h" - typedef struct omapfb_page { unsigned yoffset; diff --git a/gfx/drivers/sdl2_gfx.c b/gfx/drivers/sdl2_gfx.c index 1585460dad..d7c479d9e1 100644 --- a/gfx/drivers/sdl2_gfx.c +++ b/gfx/drivers/sdl2_gfx.c @@ -41,7 +41,6 @@ #include "../../configuration.h" #include "../../retroarch.h" #include "../../verbosity.h" -#include "../video_context_driver.h" typedef struct sdl2_tex { diff --git a/gfx/drivers/sdl_gfx.c b/gfx/drivers/sdl_gfx.c index 25d14d4ce2..9154acc628 100644 --- a/gfx/drivers/sdl_gfx.c +++ b/gfx/drivers/sdl_gfx.c @@ -44,8 +44,6 @@ #include "../../configuration.h" -#include "../video_context_driver.h" - typedef struct sdl_menu_frame { bool active; diff --git a/gfx/drivers/vg.c b/gfx/drivers/vg.c index 9902ab4945..157c1c232f 100644 --- a/gfx/drivers/vg.c +++ b/gfx/drivers/vg.c @@ -37,7 +37,6 @@ #endif #include "../font_driver.h" -#include "../video_context_driver.h" #include "../../retroarch.h" #include "../../driver.h" diff --git a/gfx/drivers/vita2d_gfx.c b/gfx/drivers/vita2d_gfx.c index 7a18ebdff6..c6e6b8b1b9 100644 --- a/gfx/drivers/vita2d_gfx.c +++ b/gfx/drivers/vita2d_gfx.c @@ -33,7 +33,6 @@ #include "../common/vita2d_common.h" #include "../../driver.h" #include "../video_coord_array.h" -#include "../video_context_driver.h" #include "../../verbosity.h" #include "../../configuration.h" diff --git a/gfx/drivers/vulkan.c b/gfx/drivers/vulkan.c index bbbe535a1e..2902ec3912 100644 --- a/gfx/drivers/vulkan.c +++ b/gfx/drivers/vulkan.c @@ -47,7 +47,6 @@ #include "../../retroarch.h" #include "../../verbosity.h" -#include "../video_context_driver.h" #include "../video_coord_array.h" static void vulkan_set_viewport(void *data, unsigned viewport_width, diff --git a/gfx/drivers_context/cgl_ctx.c b/gfx/drivers_context/cgl_ctx.c index 74ab9c3f64..95673270a0 100644 --- a/gfx/drivers_context/cgl_ctx.c +++ b/gfx/drivers_context/cgl_ctx.c @@ -29,7 +29,7 @@ #include #include -#include "../video_context_driver.h" +#include "../video_driver.h" typedef int CGSConnectionID; typedef int CGSWindowID; diff --git a/gfx/drivers_context/cocoa_gl_ctx.m b/gfx/drivers_context/cocoa_gl_ctx.m index d43a888bdc..64377471dd 100644 --- a/gfx/drivers_context/cocoa_gl_ctx.m +++ b/gfx/drivers_context/cocoa_gl_ctx.m @@ -39,7 +39,7 @@ #include #import "../../ui/drivers/cocoa/cocoa_common.h" -#include "../video_context_driver.h" +#include "../video_driver.h" #include "../../configuration.h" #include "../../verbosity.h" diff --git a/gfx/drivers_context/emscriptenegl_ctx.c b/gfx/drivers_context/emscriptenegl_ctx.c index 8212507112..3bc7264441 100644 --- a/gfx/drivers_context/emscriptenegl_ctx.c +++ b/gfx/drivers_context/emscriptenegl_ctx.c @@ -25,7 +25,7 @@ #include "../../config.h" #endif -#include "../video_context_driver.h" +#include "../video_driver.h" #ifdef HAVE_EGL #include "../common/egl_common.h" diff --git a/gfx/drivers_context/gdi_ctx.cpp b/gfx/drivers_context/gdi_ctx.cpp index 9e9b770262..f423684ac5 100644 --- a/gfx/drivers_context/gdi_ctx.cpp +++ b/gfx/drivers_context/gdi_ctx.cpp @@ -35,7 +35,7 @@ #include "../../configuration.h" #include "../../dynamic.h" #include "../../verbosity.h" -#include "../video_context_driver.h" +#include "../video_driver.h" #include "../common/win32_common.h" diff --git a/gfx/drivers_context/gfx_null_ctx.c b/gfx/drivers_context/gfx_null_ctx.c index ff51ea6de4..d045ae797c 100644 --- a/gfx/drivers_context/gfx_null_ctx.c +++ b/gfx/drivers_context/gfx_null_ctx.c @@ -16,7 +16,7 @@ /* Null context. */ -#include "../video_context_driver.h" +#include "../video_driver.h" static void gfx_ctx_null_swap_interval(void *data, unsigned interval) { diff --git a/gfx/drivers_context/ps3_ctx.c b/gfx/drivers_context/ps3_ctx.c index fb3af25cdb..8deafaff37 100644 --- a/gfx/drivers_context/ps3_ctx.c +++ b/gfx/drivers_context/ps3_ctx.c @@ -33,7 +33,7 @@ #include "../../configuration.h" #include "../../defines/ps3_defines.h" #include "../common/gl_common.h" -#include "../video_context_driver.h" +#include "../video_driver.h" typedef struct gfx_ctx_ps3_data { diff --git a/gfx/drivers_context/vc_egl_ctx.c b/gfx/drivers_context/vc_egl_ctx.c index fee7c6f2fe..0872e24636 100644 --- a/gfx/drivers_context/vc_egl_ctx.c +++ b/gfx/drivers_context/vc_egl_ctx.c @@ -32,7 +32,7 @@ #include #include "../../configuration.h" -#include "../video_context_driver.h" +#include "../video_driver.h" #include "../../frontend/frontend_driver.h" diff --git a/gfx/drivers_context/wgl_ctx.cpp b/gfx/drivers_context/wgl_ctx.cpp index 9d082947f1..15fc5c10b9 100644 --- a/gfx/drivers_context/wgl_ctx.cpp +++ b/gfx/drivers_context/wgl_ctx.cpp @@ -41,7 +41,7 @@ #include "../../configuration.h" #include "../../dynamic.h" -#include "../video_context_driver.h" +#include "../video_driver.h" #include "../common/win32_common.h" diff --git a/gfx/drivers_font/gl_raster_font.c b/gfx/drivers_font/gl_raster_font.c index bb4896ed69..f69e8c2652 100644 --- a/gfx/drivers_font/gl_raster_font.c +++ b/gfx/drivers_font/gl_raster_font.c @@ -23,7 +23,7 @@ #include "../common/gl_common.h" #include "../font_driver.h" #include "../video_shader_driver.h" -#include "../video_context_driver.h" +#include "../video_driver.h" /* TODO: Move viewport side effects to the caller: it's a source of bugs. */ diff --git a/gfx/video_context_driver.c b/gfx/video_context_driver.c deleted file mode 100644 index a25bcedeb2..0000000000 --- a/gfx/video_context_driver.c +++ /dev/null @@ -1,516 +0,0 @@ -/* RetroArch - A frontend for libretro. - * Copyright (C) 2010-2014 - Hans-Kristian Arntzen - * Copyright (C) 2011-2017 - Daniel De Matteis - * Copyright (C) 2016-2017 - Brad Parker - * - * 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 - -#include -#include - -#include "video_context_driver.h" - -#ifdef HAVE_CONFIG_H -#include "../config.h" -#endif - -#include "../configuration.h" -#include "../runloop.h" -#include "../verbosity.h" - -static const gfx_ctx_driver_t *gfx_ctx_drivers[] = { -#if defined(__CELLOS_LV2__) - &gfx_ctx_ps3, -#endif -#if defined(HAVE_D3D) - &gfx_ctx_d3d, -#endif -#if defined(HAVE_VIDEOCORE) - &gfx_ctx_videocore, -#endif -#if defined(HAVE_MALI_FBDEV) - &gfx_ctx_mali_fbdev, -#endif -#if defined(HAVE_VIVANTE_FBDEV) - &gfx_ctx_vivante_fbdev, -#endif -#if defined(HAVE_OPENDINGUX_FBDEV) - &gfx_ctx_opendingux_fbdev, -#endif -#if defined(_WIN32) && (defined(HAVE_OPENGL) || defined(HAVE_VULKAN)) - &gfx_ctx_wgl, -#endif -#if defined(HAVE_WAYLAND) - &gfx_ctx_wayland, -#endif -#if defined(HAVE_X11) && !defined(HAVE_OPENGLES) -#if defined(HAVE_OPENGL) || defined(HAVE_VULKAN) - &gfx_ctx_x, -#endif -#endif -#if defined(HAVE_X11) && defined(HAVE_OPENGL) && defined(HAVE_EGL) - &gfx_ctx_x_egl, -#endif -#if defined(HAVE_KMS) - &gfx_ctx_drm, -#endif -#if defined(ANDROID) - &gfx_ctx_android, -#endif -#if defined(__QNX__) - &gfx_ctx_qnx, -#endif -#if defined(HAVE_COCOA) || defined(HAVE_COCOATOUCH) - &gfx_ctx_cocoagl, -#endif -#if defined(__APPLE__) && !defined(TARGET_IPHONE_SIMULATOR) && !defined(TARGET_OS_IPHONE) - &gfx_ctx_cgl, -#endif -#if (defined(HAVE_SDL) || defined(HAVE_SDL2)) && defined(HAVE_OPENGL) - &gfx_ctx_sdl_gl, -#endif -#ifdef HAVE_OSMESA - &gfx_ctx_osmesa, -#endif -#ifdef EMSCRIPTEN - &gfx_ctx_emscripten, -#endif -#if defined(HAVE_VULKAN) && defined(HAVE_VULKAN_DISPLAY) - &gfx_ctx_khr_display, -#endif -#if defined(_WIN32) && !defined(_XBOX) - &gfx_ctx_gdi, -#endif - &gfx_ctx_null, - NULL -}; - -const gfx_ctx_driver_t *current_video_context = NULL; -void *video_context_data = NULL; - -/** - * find_video_context_driver_driver_index: - * @ident : Identifier of resampler driver to find. - * - * Finds graphics context driver index by @ident name. - * - * Returns: graphics context driver index if driver was found, otherwise - * -1. - **/ -static int find_video_context_driver_index(const char *ident) -{ - unsigned i; - for (i = 0; gfx_ctx_drivers[i]; i++) - if (string_is_equal_noncase(ident, gfx_ctx_drivers[i]->ident)) - return i; - return -1; -} - -/** - * find_prev_context_driver: - * - * Finds previous driver in graphics context driver array. - **/ -bool video_context_driver_find_prev_driver(void) -{ - settings_t *settings = config_get_ptr(); - int i = find_video_context_driver_index( - settings->arrays.video_context_driver); - - if (i > 0) - { - strlcpy(settings->arrays.video_context_driver, - gfx_ctx_drivers[i - 1]->ident, - sizeof(settings->arrays.video_context_driver)); - return true; - } - - RARCH_WARN("Couldn't find any previous video context driver.\n"); - return false; -} - -/** - * find_next_context_driver: - * - * Finds next driver in graphics context driver array. - **/ -bool video_context_driver_find_next_driver(void) -{ - settings_t *settings = config_get_ptr(); - int i = find_video_context_driver_index(settings->arrays.video_context_driver); - - if (i >= 0 && gfx_ctx_drivers[i + 1]) - { - strlcpy(settings->arrays.video_context_driver, - gfx_ctx_drivers[i + 1]->ident, - sizeof(settings->arrays.video_context_driver)); - return true; - } - - RARCH_WARN("Couldn't find any next video context driver.\n"); - return false; -} - -/** - * video_context_driver_init: - * @data : Input data. - * @ctx : Graphics context driver to initialize. - * @ident : Identifier of graphics context driver to find. - * @api : API of higher-level graphics API. - * @major : Major version number of higher-level graphics API. - * @minor : Minor version number of higher-level graphics API. - * @hw_render_ctx : Request a graphics context driver capable of - * hardware rendering? - * - * Initialize graphics context driver. - * - * Returns: graphics context driver if successfully initialized, otherwise NULL. - **/ -static const gfx_ctx_driver_t *video_context_driver_init( - void *data, - const gfx_ctx_driver_t *ctx, - const char *ident, - enum gfx_ctx_api api, unsigned major, - unsigned minor, bool hw_render_ctx) -{ - if (ctx->bind_api(data, api, major, minor)) - { - video_frame_info_t video_info; - void *ctx_data = NULL; - - video_driver_build_info(&video_info); - - ctx_data = ctx->init(&video_info, data); - - if (!ctx_data) - return NULL; - - if (ctx->bind_hw_render) - ctx->bind_hw_render(ctx_data, - video_info.shared_context && hw_render_ctx); - - video_context_driver_set_data(ctx_data); - return ctx; - } - -#ifndef _WIN32 - RARCH_WARN("Failed to bind API (#%u, version %u.%u) on context driver \"%s\".\n", - (unsigned)api, major, minor, ctx->ident); -#endif - - return NULL; -} - -/** - * video_context_driver_find_driver: - * @data : Input data. - * @ident : Identifier of graphics context driver to find. - * @api : API of higher-level graphics API. - * @major : Major version number of higher-level graphics API. - * @minor : Minor version number of higher-level graphics API. - * @hw_render_ctx : Request a graphics context driver capable of - * hardware rendering? - * - * Finds graphics context driver and initializes. - * - * Returns: graphics context driver if found, otherwise NULL. - **/ -static const gfx_ctx_driver_t *video_context_driver_find_driver(void *data, - const char *ident, - enum gfx_ctx_api api, unsigned major, - unsigned minor, bool hw_render_ctx) -{ - int i = find_video_context_driver_index(ident); - - if (i >= 0) - return video_context_driver_init(data, gfx_ctx_drivers[i], ident, - api, major, minor, hw_render_ctx); - - for (i = 0; gfx_ctx_drivers[i]; i++) - { - const gfx_ctx_driver_t *ctx = - video_context_driver_init(data, gfx_ctx_drivers[i], ident, - api, major, minor, hw_render_ctx); - - if (ctx) - return ctx; - } - - return NULL; -} - -/** - * video_context_driver_init_first: - * @data : Input data. - * @ident : Identifier of graphics context driver to find. - * @api : API of higher-level graphics API. - * @major : Major version number of higher-level graphics API. - * @minor : Minor version number of higher-level graphics API. - * @hw_render_ctx : Request a graphics context driver capable of - * hardware rendering? - * - * Finds first suitable graphics context driver and initializes. - * - * Returns: graphics context driver if found, otherwise NULL. - **/ -const gfx_ctx_driver_t *video_context_driver_init_first(void *data, - const char *ident, enum gfx_ctx_api api, unsigned major, - unsigned minor, bool hw_render_ctx) -{ - return video_context_driver_find_driver(data, ident, api, - major, minor, hw_render_ctx); -} - -bool video_context_driver_check_window(gfx_ctx_size_t *size_data) -{ - if ( video_context_data - && current_video_context - && current_video_context->check_window) - { - bool is_shutdown = runloop_ctl(RUNLOOP_CTL_IS_SHUTDOWN, NULL); - current_video_context->check_window(video_context_data, - size_data->quit, - size_data->resize, - size_data->width, - size_data->height, - is_shutdown); - return true; - } - - return false; -} - -bool video_context_driver_init_image_buffer(const video_info_t *data) -{ - if ( current_video_context - && current_video_context->image_buffer_init - && current_video_context->image_buffer_init(video_context_data, data)) - return true; - return false; -} - -bool video_context_driver_write_to_image_buffer(gfx_ctx_image_t *img) -{ - if ( current_video_context - && current_video_context->image_buffer_write - && current_video_context->image_buffer_write(video_context_data, - img->frame, img->width, img->height, img->pitch, - img->rgb32, img->index, img->handle)) - return true; - return false; -} - -bool video_context_driver_get_video_output_prev(void) -{ - if (!current_video_context - || !current_video_context->get_video_output_prev) - return false; - current_video_context->get_video_output_prev(video_context_data); - return true; -} - -bool video_context_driver_get_video_output_next(void) -{ - if (!current_video_context || - !current_video_context->get_video_output_next) - return false; - current_video_context->get_video_output_next(video_context_data); - return true; -} - -bool video_context_driver_bind_hw_render(bool *enable) -{ - if (!current_video_context || !current_video_context->bind_hw_render) - return false; - current_video_context->bind_hw_render(video_context_data, *enable); - return true; -} - -void video_context_driver_make_current(bool release) -{ - if (current_video_context && current_video_context->make_current) - current_video_context->make_current(release); -} - -bool video_context_driver_set(const gfx_ctx_driver_t *data) -{ - if (!data) - return false; - current_video_context = data; - return true; -} - -void video_context_driver_destroy(void) -{ - current_video_context = NULL; -} - -bool video_context_driver_translate_aspect(gfx_ctx_aspect_t *aspect) -{ - if (!video_context_data || !aspect) - return false; - if (!current_video_context->translate_aspect) - return false; - *aspect->aspect = current_video_context->translate_aspect( - video_context_data, aspect->width, aspect->height); - return true; -} - -void video_context_driver_free(void) -{ - if (current_video_context->destroy) - current_video_context->destroy(video_context_data); - current_video_context = NULL; - video_context_data = NULL; -} - -bool video_context_driver_get_video_output_size(gfx_ctx_size_t *size_data) -{ - if (!size_data) - return false; - if (!current_video_context || !current_video_context->get_video_output_size) - return false; - current_video_context->get_video_output_size(video_context_data, - size_data->width, size_data->height); - return true; -} - -bool video_context_driver_swap_interval(unsigned *interval) -{ - if (!current_video_context || !current_video_context->swap_interval) - return false; - current_video_context->swap_interval(video_context_data, *interval); - return true; -} - -bool video_context_driver_get_proc_address(gfx_ctx_proc_address_t *proc) -{ - if (!current_video_context || !current_video_context->get_proc_address) - return false; - - proc->addr = current_video_context->get_proc_address(proc->sym); - - return true; -} - -bool video_context_driver_get_metrics(gfx_ctx_metrics_t *metrics) -{ - if ( current_video_context - && current_video_context->get_metrics - && current_video_context->get_metrics(video_context_data, - metrics->type, - metrics->value)) - return true; - return false; -} - -bool video_context_driver_input_driver(gfx_ctx_input_t *inp) -{ - settings_t *settings = config_get_ptr(); - const char *joypad_name = settings ? settings->arrays.input_joypad_driver : NULL; - - if (!current_video_context || !current_video_context->input_driver) - return false; - current_video_context->input_driver( - video_context_data, joypad_name, - inp->input, inp->input_data); - return true; -} - -bool video_context_driver_suppress_screensaver(bool *bool_data) -{ - if ( video_context_data - && current_video_context - && current_video_context->suppress_screensaver( - video_context_data, *bool_data)) - return true; - return false; -} - -bool video_context_driver_get_ident(gfx_ctx_ident_t *ident) -{ - if (!ident) - return false; - ident->ident = NULL; - if (current_video_context) - ident->ident = current_video_context->ident; - return true; -} - -bool video_context_driver_set_video_mode(gfx_ctx_mode_t *mode_info) -{ - video_frame_info_t video_info; - - if (!current_video_context || !current_video_context->set_video_mode) - return false; - - video_driver_build_info(&video_info); - - if (!current_video_context->set_video_mode( - video_context_data, &video_info, mode_info->width, - mode_info->height, mode_info->fullscreen)) - return false; - return true; -} - -bool video_context_driver_get_video_size(gfx_ctx_mode_t *mode_info) -{ - if (!current_video_context || !current_video_context->get_video_size) - return false; - current_video_context->get_video_size(video_context_data, - &mode_info->width, &mode_info->height); - return true; -} - -bool video_context_driver_get_context_data(void *data) -{ - if (!current_video_context || !current_video_context->get_context_data) - return false; - *(void**)data = current_video_context->get_context_data(video_context_data); - return true; -} - -bool video_context_driver_show_mouse(bool *bool_data) -{ - if (!current_video_context || !current_video_context->show_mouse) - return false; - current_video_context->show_mouse(video_context_data, *bool_data); - return true; -} - -void video_context_driver_set_data(void *data) -{ - video_context_data = data; -} - -bool video_context_driver_get_flags(gfx_ctx_flags_t *flags) -{ - if (!flags) - return false; - if (!current_video_context || !current_video_context->get_flags) - return false; - flags->flags = current_video_context->get_flags(video_context_data); - return true; -} - -bool video_context_driver_set_flags(gfx_ctx_flags_t *flags) -{ - if (!flags) - return false; - if (!current_video_context || !current_video_context->set_flags) - return false; - current_video_context->set_flags(video_context_data, flags->flags); - return true; -} diff --git a/gfx/video_context_driver.h b/gfx/video_context_driver.h deleted file mode 100644 index 6bc9b30d4d..0000000000 --- a/gfx/video_context_driver.h +++ /dev/null @@ -1,349 +0,0 @@ -/* RetroArch - A frontend for libretro. - * Copyright (C) 2010-2014 - Hans-Kristian Arntzen - * Copyright (C) 2011-2017 - Daniel De Matteis - * Copyright (C) 2016-2017 - Brad Parker - * - * 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_CONTEXT_DRIVER_H -#define __VIDEO_CONTEXT_DRIVER_H - -#include -#include - -#include "video_driver.h" - -RETRO_BEGIN_DECLS - -#ifndef MAX_EGLIMAGE_TEXTURES -#define MAX_EGLIMAGE_TEXTURES 32 -#endif - -enum gfx_ctx_api -{ - GFX_CTX_NONE = 0, - GFX_CTX_OPENGL_API, - GFX_CTX_OPENGL_ES_API, - GFX_CTX_DIRECT3D8_API, - GFX_CTX_DIRECT3D9_API, - GFX_CTX_OPENVG_API, - GFX_CTX_VULKAN_API, - GFX_CTX_GDI_API -}; - -enum display_metric_types -{ - DISPLAY_METRIC_NONE = 0, - DISPLAY_METRIC_MM_WIDTH, - DISPLAY_METRIC_MM_HEIGHT, - DISPLAY_METRIC_DPI -}; - -enum display_flags -{ - GFX_CTX_FLAGS_NONE = 0, - GFX_CTX_FLAGS_GL_CORE_CONTEXT, - GFX_CTX_FLAGS_MULTISAMPLING, - GFX_CTX_FLAGS_CUSTOMIZABLE_SWAPCHAIN_IMAGES -}; - - -typedef void (*gfx_ctx_proc_t)(void); - -typedef struct gfx_ctx_driver -{ - /* The opaque pointer is the underlying video driver data (e.g. gl_t for - * OpenGL contexts). Although not advised, the context driver is allowed - * to hold a pointer to it as the context never outlives the video driver. - * - * The context driver is responsible for it's own data.*/ - void* (*init)(video_frame_info_t *video_info, void *video_driver); - void (*destroy)(void *data); - - /* Which API to bind to. */ - bool (*bind_api)(void *video_driver, enum gfx_ctx_api, - unsigned major, unsigned minor); - - /* Sets the swap interval. */ - void (*swap_interval)(void *data, unsigned); - - /* Sets video mode. Creates a window, etc. */ - bool (*set_video_mode)(void*, video_frame_info_t *video_info, unsigned, unsigned, bool); - - /* Gets current window size. - * If not initialized yet, it returns current screen size. */ - void (*get_video_size)(void*, unsigned*, unsigned*); - - void (*get_video_output_size)(void*, unsigned*, unsigned*); - - void (*get_video_output_prev)(void*); - - void (*get_video_output_next)(void*); - - bool (*get_metrics)(void *data, enum display_metric_types type, - float *value); - - /* Translates a window size to an aspect ratio. - * In most cases this will be just width / height, but - * some contexts will better know which actual aspect ratio is used. - * This can be NULL to assume the default behavior. - */ - float (*translate_aspect)(void*, unsigned, unsigned); - - /* Asks driver to update window title (FPS, etc). */ - void (*update_window_title)(void*, video_frame_info_t *video_info); - - /* Queries for resize and quit events. - * Also processes events. */ - void (*check_window)(void*, bool*, bool*, - unsigned*, unsigned*, bool); - - /* Acknowledge a resize event. This is needed for some APIs. - * Most backends will ignore this. */ - bool (*set_resize)(void*, unsigned, unsigned); - - /* Checks if window has input focus. */ - bool (*has_focus)(void*); - - /* Should the screensaver be suppressed? */ - bool (*suppress_screensaver)(void *data, bool enable); - - /* Checks if context driver has windowed support. */ - bool (*has_windowed)(void*); - - /* Swaps buffers. VBlank sync depends on - * earlier calls to swap_interval. */ - void (*swap_buffers)(void*, video_frame_info_t *video_info); - - /* Most video backends will want to use a certain input driver. - * Checks for it here. */ - void (*input_driver)(void*, const char *, const input_driver_t**, void**); - - /* Wraps whatever gl_proc_address() there is. - * Does not take opaque, to avoid lots of ugly wrapper code. */ - gfx_ctx_proc_t (*get_proc_address)(const char*); - - /* Returns true if this context supports EGLImage buffers for - * screen drawing and was initalized correctly. */ - bool (*image_buffer_init)(void*, const video_info_t*); - - /* Writes the frame to the EGLImage and sets image_handle to it. - * Returns true if a new image handle is created. - * Always returns true the first time it's called for a new index. - * The graphics core must handle a change in the handle correctly. */ - bool (*image_buffer_write)(void*, const void *frame, unsigned width, - unsigned height, unsigned pitch, bool rgb32, - unsigned index, void **image_handle); - - /* Shows or hides mouse. Can be NULL if context doesn't - * have a concept of mouse pointer. */ - void (*show_mouse)(void *data, bool state); - - /* Human readable string. */ - const char *ident; - - uint32_t (*get_flags)(void *data); - - void (*set_flags)(void *data, uint32_t flags); - - /* Optional. Binds HW-render offscreen context. */ - void (*bind_hw_render)(void *data, bool enable); - - /* Optional. Gets base data for the context which is used by the driver. - * This is mostly relevant for graphics APIs such as Vulkan - * which do not have global context state. */ - void *(*get_context_data)(void *data); - - /* Optional. Makes driver context (only GLX right now) - * active for this thread. */ - void (*make_current)(bool release); -} gfx_ctx_driver_t; - - -typedef struct gfx_ctx_flags -{ - uint32_t flags; -} gfx_ctx_flags_t; - -typedef struct gfx_ctx_size -{ - bool *quit; - bool *resize; - unsigned *width; - unsigned *height; -} gfx_ctx_size_t; - -typedef struct gfx_ctx_mode -{ - unsigned width; - unsigned height; - bool fullscreen; -} gfx_ctx_mode_t; - -typedef struct gfx_ctx_metrics -{ - enum display_metric_types type; - float *value; -} gfx_ctx_metrics_t; - -typedef struct gfx_ctx_aspect -{ - float *aspect; - unsigned width; - unsigned height; -} gfx_ctx_aspect_t; - -typedef struct gfx_ctx_image -{ - const void *frame; - unsigned width; - unsigned height; - unsigned pitch; - unsigned index; - bool rgb32; - void **handle; -} gfx_ctx_image_t; - -typedef struct gfx_ctx_input -{ - const input_driver_t **input; - void **input_data; -} gfx_ctx_input_t; - -typedef struct gfx_ctx_proc_address -{ - const char *sym; - retro_proc_address_t addr; -} gfx_ctx_proc_address_t; - -typedef struct gfx_ctx_ident -{ - const char *ident; -} gfx_ctx_ident_t; - -extern const gfx_ctx_driver_t gfx_ctx_osmesa; -extern const gfx_ctx_driver_t gfx_ctx_sdl_gl; -extern const gfx_ctx_driver_t gfx_ctx_x_egl; -extern const gfx_ctx_driver_t gfx_ctx_wayland; -extern const gfx_ctx_driver_t gfx_ctx_x; -extern const gfx_ctx_driver_t gfx_ctx_d3d; -extern const gfx_ctx_driver_t gfx_ctx_drm; -extern const gfx_ctx_driver_t gfx_ctx_mali_fbdev; -extern const gfx_ctx_driver_t gfx_ctx_vivante_fbdev; -extern const gfx_ctx_driver_t gfx_ctx_android; -extern const gfx_ctx_driver_t gfx_ctx_ps3; -extern const gfx_ctx_driver_t gfx_ctx_wgl; -extern const gfx_ctx_driver_t gfx_ctx_videocore; -extern const gfx_ctx_driver_t gfx_ctx_qnx; -extern const gfx_ctx_driver_t gfx_ctx_cgl; -extern const gfx_ctx_driver_t gfx_ctx_cocoagl; -extern const gfx_ctx_driver_t gfx_ctx_emscripten; -extern const gfx_ctx_driver_t gfx_ctx_opendingux_fbdev; -extern const gfx_ctx_driver_t gfx_ctx_khr_display; -extern const gfx_ctx_driver_t gfx_ctx_gdi; -extern const gfx_ctx_driver_t gfx_ctx_null; - -/** - * video_context_driver_init_first: - * @data : Input data. - * @ident : Identifier of graphics context driver to find. - * @api : API of higher-level graphics API. - * @major : Major version number of higher-level graphics API. - * @minor : Minor version number of higher-level graphics API. - * @hw_render_ctx : Request a graphics context driver capable of - * hardware rendering? - * - * Finds first suitable graphics context driver and initializes. - * - * Returns: graphics context driver if found, otherwise NULL. - **/ -const gfx_ctx_driver_t *video_context_driver_init_first(void *data, const char *ident, - enum gfx_ctx_api api, unsigned major, unsigned minor, bool hw_render_ctx); - -bool video_context_driver_check_window(gfx_ctx_size_t *size_data); - -bool video_context_driver_find_prev_driver(void); - -bool video_context_driver_find_next_driver(void); - -bool video_context_driver_init_image_buffer(const video_info_t *data); - -bool video_context_driver_write_to_image_buffer(gfx_ctx_image_t *img); - -bool video_context_driver_get_video_output_prev(void); - -bool video_context_driver_get_video_output_next(void); - -bool video_context_driver_bind_hw_render(bool *enable); - -void video_context_driver_make_current(bool restore); - -bool video_context_driver_set(const gfx_ctx_driver_t *data); - -void video_context_driver_destroy(void); - -#define video_context_driver_update_window_title(video_info) \ - if (current_video_context && current_video_context->update_window_title) \ - current_video_context->update_window_title(video_context_data, video_info) - -#define video_context_driver_swap_buffers(video_info) \ - if (current_video_context && current_video_context->swap_buffers) \ - current_video_context->swap_buffers(video_context_data, video_info) - -#define video_context_driver_focus() ((video_context_data && current_video_context->has_focus && current_video_context->has_focus(video_context_data)) ? true : false) - -#define video_context_driver_set_resize(mode_info) \ - if (current_video_context && current_video_context->set_resize) \ - current_video_context->set_resize(video_context_data, mode_info.width, mode_info.height) - -bool video_context_driver_get_video_output_size(gfx_ctx_size_t *size_data); - -bool video_context_driver_swap_interval(unsigned *interval); - -bool video_context_driver_get_proc_address(gfx_ctx_proc_address_t *proc); - -bool video_context_driver_suppress_screensaver(bool *bool_data); - -bool video_context_driver_get_ident(gfx_ctx_ident_t *ident); - -bool video_context_driver_set_video_mode(gfx_ctx_mode_t *mode_info); - -bool video_context_driver_get_video_size(gfx_ctx_mode_t *mode_info); - -bool video_context_driver_get_context_data(void *data); - -bool video_context_driver_show_mouse(bool *bool_data); - -void video_context_driver_set_data(void *data); - -bool video_context_driver_get_flags(gfx_ctx_flags_t *flags); - -bool video_context_driver_set_flags(gfx_ctx_flags_t *flags); - -bool video_context_driver_get_metrics(gfx_ctx_metrics_t *metrics); - -bool video_context_driver_translate_aspect(gfx_ctx_aspect_t *aspect); - -bool video_context_driver_input_driver(gfx_ctx_input_t *inp); - -#define video_context_driver_has_windowed() ((video_context_data && current_video_context->has_windowed && current_video_context->has_windowed(video_context_data)) ? true : false) - -void video_context_driver_free(void); - -extern const gfx_ctx_driver_t *current_video_context; - -extern void *video_context_data; - -RETRO_END_DECLS - -#endif diff --git a/gfx/video_driver.c b/gfx/video_driver.c index 2b8784b395..7e2f630079 100644 --- a/gfx/video_driver.c +++ b/gfx/video_driver.c @@ -44,7 +44,7 @@ #endif #include "video_thread_wrapper.h" -#include "video_context_driver.h" +#include "video_driver.h" #include "../frontend/frontend_driver.h" #include "../record/record_driver.h" @@ -196,6 +196,9 @@ static slock_t *display_lock = NULL; static slock_t *context_lock = NULL; #endif +const gfx_ctx_driver_t *current_video_context = NULL; +void *video_context_data = NULL; + struct aspect_ratio_elem aspectratio_lut[ASPECT_RATIO_END] = { { "4:3", 1.3333f }, { "16:9", 1.7778f }, @@ -293,6 +296,73 @@ static const video_driver_t *video_drivers[] = { NULL, }; +static const gfx_ctx_driver_t *gfx_ctx_drivers[] = { +#if defined(__CELLOS_LV2__) + &gfx_ctx_ps3, +#endif +#if defined(HAVE_D3D) + &gfx_ctx_d3d, +#endif +#if defined(HAVE_VIDEOCORE) + &gfx_ctx_videocore, +#endif +#if defined(HAVE_MALI_FBDEV) + &gfx_ctx_mali_fbdev, +#endif +#if defined(HAVE_VIVANTE_FBDEV) + &gfx_ctx_vivante_fbdev, +#endif +#if defined(HAVE_OPENDINGUX_FBDEV) + &gfx_ctx_opendingux_fbdev, +#endif +#if defined(_WIN32) && (defined(HAVE_OPENGL) || defined(HAVE_VULKAN)) + &gfx_ctx_wgl, +#endif +#if defined(HAVE_WAYLAND) + &gfx_ctx_wayland, +#endif +#if defined(HAVE_X11) && !defined(HAVE_OPENGLES) +#if defined(HAVE_OPENGL) || defined(HAVE_VULKAN) + &gfx_ctx_x, +#endif +#endif +#if defined(HAVE_X11) && defined(HAVE_OPENGL) && defined(HAVE_EGL) + &gfx_ctx_x_egl, +#endif +#if defined(HAVE_KMS) + &gfx_ctx_drm, +#endif +#if defined(ANDROID) + &gfx_ctx_android, +#endif +#if defined(__QNX__) + &gfx_ctx_qnx, +#endif +#if defined(HAVE_COCOA) || defined(HAVE_COCOATOUCH) + &gfx_ctx_cocoagl, +#endif +#if defined(__APPLE__) && !defined(TARGET_IPHONE_SIMULATOR) && !defined(TARGET_OS_IPHONE) + &gfx_ctx_cgl, +#endif +#if (defined(HAVE_SDL) || defined(HAVE_SDL2)) && defined(HAVE_OPENGL) + &gfx_ctx_sdl_gl, +#endif +#ifdef HAVE_OSMESA + &gfx_ctx_osmesa, +#endif +#ifdef EMSCRIPTEN + &gfx_ctx_emscripten, +#endif +#if defined(HAVE_VULKAN) && defined(HAVE_VULKAN_DISPLAY) + &gfx_ctx_khr_display, +#endif +#if defined(_WIN32) && !defined(_XBOX) + &gfx_ctx_gdi, +#endif + &gfx_ctx_null, + NULL +}; + /** * video_driver_find_handle: * @idx : index of driver to get handle to. @@ -2416,3 +2486,418 @@ void video_driver_get_status(uint64_t *frame_count, bool * is_alive, *is_alive = video_driver_is_alive(); *is_focused = video_driver_is_focused(); } + +/** + * find_video_context_driver_driver_index: + * @ident : Identifier of resampler driver to find. + * + * Finds graphics context driver index by @ident name. + * + * Returns: graphics context driver index if driver was found, otherwise + * -1. + **/ +static int find_video_context_driver_index(const char *ident) +{ + unsigned i; + for (i = 0; gfx_ctx_drivers[i]; i++) + if (string_is_equal_noncase(ident, gfx_ctx_drivers[i]->ident)) + return i; + return -1; +} + +/** + * find_prev_context_driver: + * + * Finds previous driver in graphics context driver array. + **/ +bool video_context_driver_find_prev_driver(void) +{ + settings_t *settings = config_get_ptr(); + int i = find_video_context_driver_index( + settings->arrays.video_context_driver); + + if (i > 0) + { + strlcpy(settings->arrays.video_context_driver, + gfx_ctx_drivers[i - 1]->ident, + sizeof(settings->arrays.video_context_driver)); + return true; + } + + RARCH_WARN("Couldn't find any previous video context driver.\n"); + return false; +} + +/** + * find_next_context_driver: + * + * Finds next driver in graphics context driver array. + **/ +bool video_context_driver_find_next_driver(void) +{ + settings_t *settings = config_get_ptr(); + int i = find_video_context_driver_index(settings->arrays.video_context_driver); + + if (i >= 0 && gfx_ctx_drivers[i + 1]) + { + strlcpy(settings->arrays.video_context_driver, + gfx_ctx_drivers[i + 1]->ident, + sizeof(settings->arrays.video_context_driver)); + return true; + } + + RARCH_WARN("Couldn't find any next video context driver.\n"); + return false; +} + +/** + * video_context_driver_init: + * @data : Input data. + * @ctx : Graphics context driver to initialize. + * @ident : Identifier of graphics context driver to find. + * @api : API of higher-level graphics API. + * @major : Major version number of higher-level graphics API. + * @minor : Minor version number of higher-level graphics API. + * @hw_render_ctx : Request a graphics context driver capable of + * hardware rendering? + * + * Initialize graphics context driver. + * + * Returns: graphics context driver if successfully initialized, otherwise NULL. + **/ +static const gfx_ctx_driver_t *video_context_driver_init( + void *data, + const gfx_ctx_driver_t *ctx, + const char *ident, + enum gfx_ctx_api api, unsigned major, + unsigned minor, bool hw_render_ctx) +{ + if (ctx->bind_api(data, api, major, minor)) + { + video_frame_info_t video_info; + void *ctx_data = NULL; + + video_driver_build_info(&video_info); + + ctx_data = ctx->init(&video_info, data); + + if (!ctx_data) + return NULL; + + if (ctx->bind_hw_render) + ctx->bind_hw_render(ctx_data, + video_info.shared_context && hw_render_ctx); + + video_context_driver_set_data(ctx_data); + return ctx; + } + +#ifndef _WIN32 + RARCH_WARN("Failed to bind API (#%u, version %u.%u) on context driver \"%s\".\n", + (unsigned)api, major, minor, ctx->ident); +#endif + + return NULL; +} + +/** + * video_context_driver_find_driver: + * @data : Input data. + * @ident : Identifier of graphics context driver to find. + * @api : API of higher-level graphics API. + * @major : Major version number of higher-level graphics API. + * @minor : Minor version number of higher-level graphics API. + * @hw_render_ctx : Request a graphics context driver capable of + * hardware rendering? + * + * Finds graphics context driver and initializes. + * + * Returns: graphics context driver if found, otherwise NULL. + **/ +static const gfx_ctx_driver_t *video_context_driver_find_driver(void *data, + const char *ident, + enum gfx_ctx_api api, unsigned major, + unsigned minor, bool hw_render_ctx) +{ + int i = find_video_context_driver_index(ident); + + if (i >= 0) + return video_context_driver_init(data, gfx_ctx_drivers[i], ident, + api, major, minor, hw_render_ctx); + + for (i = 0; gfx_ctx_drivers[i]; i++) + { + const gfx_ctx_driver_t *ctx = + video_context_driver_init(data, gfx_ctx_drivers[i], ident, + api, major, minor, hw_render_ctx); + + if (ctx) + return ctx; + } + + return NULL; +} + +/** + * video_context_driver_init_first: + * @data : Input data. + * @ident : Identifier of graphics context driver to find. + * @api : API of higher-level graphics API. + * @major : Major version number of higher-level graphics API. + * @minor : Minor version number of higher-level graphics API. + * @hw_render_ctx : Request a graphics context driver capable of + * hardware rendering? + * + * Finds first suitable graphics context driver and initializes. + * + * Returns: graphics context driver if found, otherwise NULL. + **/ +const gfx_ctx_driver_t *video_context_driver_init_first(void *data, + const char *ident, enum gfx_ctx_api api, unsigned major, + unsigned minor, bool hw_render_ctx) +{ + return video_context_driver_find_driver(data, ident, api, + major, minor, hw_render_ctx); +} + +bool video_context_driver_check_window(gfx_ctx_size_t *size_data) +{ + if ( video_context_data + && current_video_context + && current_video_context->check_window) + { + bool is_shutdown = runloop_ctl(RUNLOOP_CTL_IS_SHUTDOWN, NULL); + current_video_context->check_window(video_context_data, + size_data->quit, + size_data->resize, + size_data->width, + size_data->height, + is_shutdown); + return true; + } + + return false; +} + +bool video_context_driver_init_image_buffer(const video_info_t *data) +{ + if ( current_video_context + && current_video_context->image_buffer_init + && current_video_context->image_buffer_init(video_context_data, data)) + return true; + return false; +} + +bool video_context_driver_write_to_image_buffer(gfx_ctx_image_t *img) +{ + if ( current_video_context + && current_video_context->image_buffer_write + && current_video_context->image_buffer_write(video_context_data, + img->frame, img->width, img->height, img->pitch, + img->rgb32, img->index, img->handle)) + return true; + return false; +} + +bool video_context_driver_get_video_output_prev(void) +{ + if (!current_video_context + || !current_video_context->get_video_output_prev) + return false; + current_video_context->get_video_output_prev(video_context_data); + return true; +} + +bool video_context_driver_get_video_output_next(void) +{ + if (!current_video_context || + !current_video_context->get_video_output_next) + return false; + current_video_context->get_video_output_next(video_context_data); + return true; +} + +bool video_context_driver_bind_hw_render(bool *enable) +{ + if (!current_video_context || !current_video_context->bind_hw_render) + return false; + current_video_context->bind_hw_render(video_context_data, *enable); + return true; +} + +void video_context_driver_make_current(bool release) +{ + if (current_video_context && current_video_context->make_current) + current_video_context->make_current(release); +} + +bool video_context_driver_set(const gfx_ctx_driver_t *data) +{ + if (!data) + return false; + current_video_context = data; + return true; +} + +void video_context_driver_destroy(void) +{ + current_video_context = NULL; +} + +bool video_context_driver_translate_aspect(gfx_ctx_aspect_t *aspect) +{ + if (!video_context_data || !aspect) + return false; + if (!current_video_context->translate_aspect) + return false; + *aspect->aspect = current_video_context->translate_aspect( + video_context_data, aspect->width, aspect->height); + return true; +} + +void video_context_driver_free(void) +{ + if (current_video_context->destroy) + current_video_context->destroy(video_context_data); + current_video_context = NULL; + video_context_data = NULL; +} + +bool video_context_driver_get_video_output_size(gfx_ctx_size_t *size_data) +{ + if (!size_data) + return false; + if (!current_video_context || !current_video_context->get_video_output_size) + return false; + current_video_context->get_video_output_size(video_context_data, + size_data->width, size_data->height); + return true; +} + +bool video_context_driver_swap_interval(unsigned *interval) +{ + if (!current_video_context || !current_video_context->swap_interval) + return false; + current_video_context->swap_interval(video_context_data, *interval); + return true; +} + +bool video_context_driver_get_proc_address(gfx_ctx_proc_address_t *proc) +{ + if (!current_video_context || !current_video_context->get_proc_address) + return false; + + proc->addr = current_video_context->get_proc_address(proc->sym); + + return true; +} + +bool video_context_driver_get_metrics(gfx_ctx_metrics_t *metrics) +{ + if ( current_video_context + && current_video_context->get_metrics + && current_video_context->get_metrics(video_context_data, + metrics->type, + metrics->value)) + return true; + return false; +} + +bool video_context_driver_input_driver(gfx_ctx_input_t *inp) +{ + settings_t *settings = config_get_ptr(); + const char *joypad_name = settings ? settings->arrays.input_joypad_driver : NULL; + + if (!current_video_context || !current_video_context->input_driver) + return false; + current_video_context->input_driver( + video_context_data, joypad_name, + inp->input, inp->input_data); + return true; +} + +bool video_context_driver_suppress_screensaver(bool *bool_data) +{ + if ( video_context_data + && current_video_context + && current_video_context->suppress_screensaver( + video_context_data, *bool_data)) + return true; + return false; +} + +bool video_context_driver_get_ident(gfx_ctx_ident_t *ident) +{ + if (!ident) + return false; + ident->ident = NULL; + if (current_video_context) + ident->ident = current_video_context->ident; + return true; +} + +bool video_context_driver_set_video_mode(gfx_ctx_mode_t *mode_info) +{ + video_frame_info_t video_info; + + if (!current_video_context || !current_video_context->set_video_mode) + return false; + + video_driver_build_info(&video_info); + + if (!current_video_context->set_video_mode( + video_context_data, &video_info, mode_info->width, + mode_info->height, mode_info->fullscreen)) + return false; + return true; +} + +bool video_context_driver_get_video_size(gfx_ctx_mode_t *mode_info) +{ + if (!current_video_context || !current_video_context->get_video_size) + return false; + current_video_context->get_video_size(video_context_data, + &mode_info->width, &mode_info->height); + return true; +} + +bool video_context_driver_get_context_data(void *data) +{ + if (!current_video_context || !current_video_context->get_context_data) + return false; + *(void**)data = current_video_context->get_context_data(video_context_data); + return true; +} + +bool video_context_driver_show_mouse(bool *bool_data) +{ + if (!current_video_context || !current_video_context->show_mouse) + return false; + current_video_context->show_mouse(video_context_data, *bool_data); + return true; +} + +void video_context_driver_set_data(void *data) +{ + video_context_data = data; +} + +bool video_context_driver_get_flags(gfx_ctx_flags_t *flags) +{ + if (!flags) + return false; + if (!current_video_context || !current_video_context->get_flags) + return false; + flags->flags = current_video_context->get_flags(video_context_data); + return true; +} + +bool video_context_driver_set_flags(gfx_ctx_flags_t *flags) +{ + if (!flags) + return false; + if (!current_video_context || !current_video_context->set_flags) + return false; + current_video_context->set_flags(video_context_data, flags->flags); + return true; +} diff --git a/gfx/video_driver.h b/gfx/video_driver.h index 86931811ab..2109ef2323 100644 --- a/gfx/video_driver.h +++ b/gfx/video_driver.h @@ -40,6 +40,39 @@ RETRO_BEGIN_DECLS +#ifndef MAX_EGLIMAGE_TEXTURES +#define MAX_EGLIMAGE_TEXTURES 32 +#endif + +enum gfx_ctx_api +{ + GFX_CTX_NONE = 0, + GFX_CTX_OPENGL_API, + GFX_CTX_OPENGL_ES_API, + GFX_CTX_DIRECT3D8_API, + GFX_CTX_DIRECT3D9_API, + GFX_CTX_OPENVG_API, + GFX_CTX_VULKAN_API, + GFX_CTX_GDI_API +}; + +enum display_metric_types +{ + DISPLAY_METRIC_NONE = 0, + DISPLAY_METRIC_MM_WIDTH, + DISPLAY_METRIC_MM_HEIGHT, + DISPLAY_METRIC_DPI +}; + +enum display_flags +{ + GFX_CTX_FLAGS_NONE = 0, + GFX_CTX_FLAGS_GL_CORE_CONTEXT, + GFX_CTX_FLAGS_MULTISAMPLING, + GFX_CTX_FLAGS_CUSTOMIZABLE_SWAPCHAIN_IMAGES +}; + + typedef struct video_info { /* Width of window. @@ -641,6 +674,292 @@ extern const void *frame_cache_data; extern void *video_driver_data; extern video_driver_t *current_video; +typedef void (*gfx_ctx_proc_t)(void); + +typedef struct gfx_ctx_driver +{ + /* The opaque pointer is the underlying video driver data (e.g. gl_t for + * OpenGL contexts). Although not advised, the context driver is allowed + * to hold a pointer to it as the context never outlives the video driver. + * + * The context driver is responsible for it's own data.*/ + void* (*init)(video_frame_info_t *video_info, void *video_driver); + void (*destroy)(void *data); + + /* Which API to bind to. */ + bool (*bind_api)(void *video_driver, enum gfx_ctx_api, + unsigned major, unsigned minor); + + /* Sets the swap interval. */ + void (*swap_interval)(void *data, unsigned); + + /* Sets video mode. Creates a window, etc. */ + bool (*set_video_mode)(void*, video_frame_info_t *video_info, unsigned, unsigned, bool); + + /* Gets current window size. + * If not initialized yet, it returns current screen size. */ + void (*get_video_size)(void*, unsigned*, unsigned*); + + void (*get_video_output_size)(void*, unsigned*, unsigned*); + + void (*get_video_output_prev)(void*); + + void (*get_video_output_next)(void*); + + bool (*get_metrics)(void *data, enum display_metric_types type, + float *value); + + /* Translates a window size to an aspect ratio. + * In most cases this will be just width / height, but + * some contexts will better know which actual aspect ratio is used. + * This can be NULL to assume the default behavior. + */ + float (*translate_aspect)(void*, unsigned, unsigned); + + /* Asks driver to update window title (FPS, etc). */ + void (*update_window_title)(void*, video_frame_info_t *video_info); + + /* Queries for resize and quit events. + * Also processes events. */ + void (*check_window)(void*, bool*, bool*, + unsigned*, unsigned*, bool); + + /* Acknowledge a resize event. This is needed for some APIs. + * Most backends will ignore this. */ + bool (*set_resize)(void*, unsigned, unsigned); + + /* Checks if window has input focus. */ + bool (*has_focus)(void*); + + /* Should the screensaver be suppressed? */ + bool (*suppress_screensaver)(void *data, bool enable); + + /* Checks if context driver has windowed support. */ + bool (*has_windowed)(void*); + + /* Swaps buffers. VBlank sync depends on + * earlier calls to swap_interval. */ + void (*swap_buffers)(void*, video_frame_info_t *video_info); + + /* Most video backends will want to use a certain input driver. + * Checks for it here. */ + void (*input_driver)(void*, const char *, const input_driver_t**, void**); + + /* Wraps whatever gl_proc_address() there is. + * Does not take opaque, to avoid lots of ugly wrapper code. */ + gfx_ctx_proc_t (*get_proc_address)(const char*); + + /* Returns true if this context supports EGLImage buffers for + * screen drawing and was initalized correctly. */ + bool (*image_buffer_init)(void*, const video_info_t*); + + /* Writes the frame to the EGLImage and sets image_handle to it. + * Returns true if a new image handle is created. + * Always returns true the first time it's called for a new index. + * The graphics core must handle a change in the handle correctly. */ + bool (*image_buffer_write)(void*, const void *frame, unsigned width, + unsigned height, unsigned pitch, bool rgb32, + unsigned index, void **image_handle); + + /* Shows or hides mouse. Can be NULL if context doesn't + * have a concept of mouse pointer. */ + void (*show_mouse)(void *data, bool state); + + /* Human readable string. */ + const char *ident; + + uint32_t (*get_flags)(void *data); + + void (*set_flags)(void *data, uint32_t flags); + + /* Optional. Binds HW-render offscreen context. */ + void (*bind_hw_render)(void *data, bool enable); + + /* Optional. Gets base data for the context which is used by the driver. + * This is mostly relevant for graphics APIs such as Vulkan + * which do not have global context state. */ + void *(*get_context_data)(void *data); + + /* Optional. Makes driver context (only GLX right now) + * active for this thread. */ + void (*make_current)(bool release); +} gfx_ctx_driver_t; + + +typedef struct gfx_ctx_flags +{ + uint32_t flags; +} gfx_ctx_flags_t; + +typedef struct gfx_ctx_size +{ + bool *quit; + bool *resize; + unsigned *width; + unsigned *height; +} gfx_ctx_size_t; + +typedef struct gfx_ctx_mode +{ + unsigned width; + unsigned height; + bool fullscreen; +} gfx_ctx_mode_t; + +typedef struct gfx_ctx_metrics +{ + enum display_metric_types type; + float *value; +} gfx_ctx_metrics_t; + +typedef struct gfx_ctx_aspect +{ + float *aspect; + unsigned width; + unsigned height; +} gfx_ctx_aspect_t; + +typedef struct gfx_ctx_image +{ + const void *frame; + unsigned width; + unsigned height; + unsigned pitch; + unsigned index; + bool rgb32; + void **handle; +} gfx_ctx_image_t; + +typedef struct gfx_ctx_input +{ + const input_driver_t **input; + void **input_data; +} gfx_ctx_input_t; + +typedef struct gfx_ctx_proc_address +{ + const char *sym; + retro_proc_address_t addr; +} gfx_ctx_proc_address_t; + +typedef struct gfx_ctx_ident +{ + const char *ident; +} gfx_ctx_ident_t; + +extern const gfx_ctx_driver_t gfx_ctx_osmesa; +extern const gfx_ctx_driver_t gfx_ctx_sdl_gl; +extern const gfx_ctx_driver_t gfx_ctx_x_egl; +extern const gfx_ctx_driver_t gfx_ctx_wayland; +extern const gfx_ctx_driver_t gfx_ctx_x; +extern const gfx_ctx_driver_t gfx_ctx_d3d; +extern const gfx_ctx_driver_t gfx_ctx_drm; +extern const gfx_ctx_driver_t gfx_ctx_mali_fbdev; +extern const gfx_ctx_driver_t gfx_ctx_vivante_fbdev; +extern const gfx_ctx_driver_t gfx_ctx_android; +extern const gfx_ctx_driver_t gfx_ctx_ps3; +extern const gfx_ctx_driver_t gfx_ctx_wgl; +extern const gfx_ctx_driver_t gfx_ctx_videocore; +extern const gfx_ctx_driver_t gfx_ctx_qnx; +extern const gfx_ctx_driver_t gfx_ctx_cgl; +extern const gfx_ctx_driver_t gfx_ctx_cocoagl; +extern const gfx_ctx_driver_t gfx_ctx_emscripten; +extern const gfx_ctx_driver_t gfx_ctx_opendingux_fbdev; +extern const gfx_ctx_driver_t gfx_ctx_khr_display; +extern const gfx_ctx_driver_t gfx_ctx_gdi; +extern const gfx_ctx_driver_t gfx_ctx_null; + +/** + * video_context_driver_init_first: + * @data : Input data. + * @ident : Identifier of graphics context driver to find. + * @api : API of higher-level graphics API. + * @major : Major version number of higher-level graphics API. + * @minor : Minor version number of higher-level graphics API. + * @hw_render_ctx : Request a graphics context driver capable of + * hardware rendering? + * + * Finds first suitable graphics context driver and initializes. + * + * Returns: graphics context driver if found, otherwise NULL. + **/ +const gfx_ctx_driver_t *video_context_driver_init_first(void *data, const char *ident, + enum gfx_ctx_api api, unsigned major, unsigned minor, bool hw_render_ctx); + +bool video_context_driver_check_window(gfx_ctx_size_t *size_data); + +bool video_context_driver_find_prev_driver(void); + +bool video_context_driver_find_next_driver(void); + +bool video_context_driver_init_image_buffer(const video_info_t *data); + +bool video_context_driver_write_to_image_buffer(gfx_ctx_image_t *img); + +bool video_context_driver_get_video_output_prev(void); + +bool video_context_driver_get_video_output_next(void); + +bool video_context_driver_bind_hw_render(bool *enable); + +void video_context_driver_make_current(bool restore); + +bool video_context_driver_set(const gfx_ctx_driver_t *data); + +void video_context_driver_destroy(void); + +#define video_context_driver_update_window_title(video_info) \ + if (current_video_context && current_video_context->update_window_title) \ + current_video_context->update_window_title(video_context_data, video_info) + +#define video_context_driver_swap_buffers(video_info) \ + if (current_video_context && current_video_context->swap_buffers) \ + current_video_context->swap_buffers(video_context_data, video_info) + +#define video_context_driver_focus() ((video_context_data && current_video_context->has_focus && current_video_context->has_focus(video_context_data)) ? true : false) + +#define video_context_driver_set_resize(mode_info) \ + if (current_video_context && current_video_context->set_resize) \ + current_video_context->set_resize(video_context_data, mode_info.width, mode_info.height) + +bool video_context_driver_get_video_output_size(gfx_ctx_size_t *size_data); + +bool video_context_driver_swap_interval(unsigned *interval); + +bool video_context_driver_get_proc_address(gfx_ctx_proc_address_t *proc); + +bool video_context_driver_suppress_screensaver(bool *bool_data); + +bool video_context_driver_get_ident(gfx_ctx_ident_t *ident); + +bool video_context_driver_set_video_mode(gfx_ctx_mode_t *mode_info); + +bool video_context_driver_get_video_size(gfx_ctx_mode_t *mode_info); + +bool video_context_driver_get_context_data(void *data); + +bool video_context_driver_show_mouse(bool *bool_data); + +void video_context_driver_set_data(void *data); + +bool video_context_driver_get_flags(gfx_ctx_flags_t *flags); + +bool video_context_driver_set_flags(gfx_ctx_flags_t *flags); + +bool video_context_driver_get_metrics(gfx_ctx_metrics_t *metrics); + +bool video_context_driver_translate_aspect(gfx_ctx_aspect_t *aspect); + +bool video_context_driver_input_driver(gfx_ctx_input_t *inp); + +#define video_context_driver_has_windowed() ((video_context_data && current_video_context->has_windowed && current_video_context->has_windowed(video_context_data)) ? true : false) + +void video_context_driver_free(void); + +extern const gfx_ctx_driver_t *current_video_context; + +extern void *video_context_data; + RETRO_END_DECLS #endif diff --git a/gfx/video_shader_driver.h b/gfx/video_shader_driver.h index fe5996c406..0f29f5b83f 100644 --- a/gfx/video_shader_driver.h +++ b/gfx/video_shader_driver.h @@ -53,7 +53,7 @@ #define DEFAULT_SHADER_TYPE RARCH_SHADER_NONE #endif -#include "video_context_driver.h" +#include "video_driver.h" RETRO_BEGIN_DECLS diff --git a/griffin/griffin.c b/griffin/griffin.c index 5be8e8af3a..b1a513415d 100644 --- a/griffin/griffin.c +++ b/griffin/griffin.c @@ -153,8 +153,6 @@ CHEATS /*============================================================ VIDEO CONTEXT ============================================================ */ - -#include "../gfx/video_context_driver.c" #include "../gfx/drivers_context/gfx_null_ctx.c" #if defined(__CELLOS_LV2__) diff --git a/input/drivers/sdl_input.c b/input/drivers/sdl_input.c index 126613892d..385f12b564 100644 --- a/input/drivers/sdl_input.c +++ b/input/drivers/sdl_input.c @@ -30,7 +30,7 @@ #include "../input_keymaps.h" #include "../input_keyboard.h" -#include "../../gfx/video_context_driver.h" +#include "../../gfx/video_driver.h" #include "../../verbosity.h" #include "../../tasks/tasks_internal.h" diff --git a/menu/drivers/xui.cpp b/menu/drivers/xui.cpp index 24171bbfb4..03fe13f12e 100644 --- a/menu/drivers/xui.cpp +++ b/menu/drivers/xui.cpp @@ -41,7 +41,6 @@ #include "../widgets/menu_input_dialog.h" #include "../../gfx/video_driver.h" -#include "../../gfx/video_context_driver.h" #include "../../configuration.h" #include "../../runloop.h" diff --git a/menu/drivers_display/menu_display_caca.c b/menu/drivers_display/menu_display_caca.c index 85973b4300..5b8ba4c1af 100644 --- a/menu/drivers_display/menu_display_caca.c +++ b/menu/drivers_display/menu_display_caca.c @@ -21,7 +21,7 @@ #include "../../config.def.h" #include "../../gfx/font_driver.h" -#include "../../gfx/video_context_driver.h" +#include "../../gfx/video_driver.h" #include "../menu_display.h" diff --git a/menu/drivers_display/menu_display_ctr.c b/menu/drivers_display/menu_display_ctr.c index 401929a6ee..427ee610c6 100644 --- a/menu/drivers_display/menu_display_ctr.c +++ b/menu/drivers_display/menu_display_ctr.c @@ -23,7 +23,7 @@ #include "../../retroarch.h" #include "../../gfx/font_driver.h" -#include "../../gfx/video_context_driver.h" +#include "../../gfx/video_driver.h" #include "../../gfx/video_shader_driver.h" #include "../../gfx/common/ctr_common.h" #include "../../gfx/drivers/ctr_gu.h" diff --git a/menu/drivers_display/menu_display_d3d.cpp b/menu/drivers_display/menu_display_d3d.cpp index 4ea27cf5c9..1492e427de 100644 --- a/menu/drivers_display/menu_display_d3d.cpp +++ b/menu/drivers_display/menu_display_d3d.cpp @@ -25,7 +25,7 @@ #include "../../retroarch.h" #include "../../gfx/font_driver.h" -#include "../../gfx/video_context_driver.h" +#include "../../gfx/video_driver.h" #include "../../gfx/drivers/d3d.h" #include "../../gfx/common/d3d_common.h" diff --git a/menu/drivers_display/menu_display_gdi.c b/menu/drivers_display/menu_display_gdi.c index b131ff9015..b0ae6bff5a 100644 --- a/menu/drivers_display/menu_display_gdi.c +++ b/menu/drivers_display/menu_display_gdi.c @@ -21,7 +21,7 @@ #include "../../config.def.h" #include "../../gfx/font_driver.h" -#include "../../gfx/video_context_driver.h" +#include "../../gfx/video_driver.h" #include "../menu_display.h" diff --git a/menu/drivers_display/menu_display_gl.c b/menu/drivers_display/menu_display_gl.c index e0f8b83dbb..9b591b02a1 100644 --- a/menu/drivers_display/menu_display_gl.c +++ b/menu/drivers_display/menu_display_gl.c @@ -21,7 +21,7 @@ #include "../../retroarch.h" #include "../../gfx/font_driver.h" -#include "../../gfx/video_context_driver.h" +#include "../../gfx/video_driver.h" #include "../../gfx/video_shader_driver.h" #include "../../gfx/common/gl_common.h" diff --git a/menu/drivers_display/menu_display_null.c b/menu/drivers_display/menu_display_null.c index 67b2628da2..86cf2d63a7 100644 --- a/menu/drivers_display/menu_display_null.c +++ b/menu/drivers_display/menu_display_null.c @@ -19,7 +19,7 @@ #include #include "../../gfx/font_driver.h" -#include "../../gfx/video_context_driver.h" +#include "../../gfx/video_driver.h" #include "../menu_display.h" diff --git a/menu/drivers_display/menu_display_vga.c b/menu/drivers_display/menu_display_vga.c index 7ec9814d41..faa362b03d 100644 --- a/menu/drivers_display/menu_display_vga.c +++ b/menu/drivers_display/menu_display_vga.c @@ -21,7 +21,7 @@ #include "../../config.def.h" #include "../../gfx/font_driver.h" -#include "../../gfx/video_context_driver.h" +#include "../../gfx/video_driver.h" #include "../menu_display.h" diff --git a/menu/drivers_display/menu_display_vita2d.c b/menu/drivers_display/menu_display_vita2d.c index 385f679a7c..4ef6fcab5b 100644 --- a/menu/drivers_display/menu_display_vita2d.c +++ b/menu/drivers_display/menu_display_vita2d.c @@ -25,7 +25,7 @@ #include "../../retroarch.h" #include "../../gfx/font_driver.h" -#include "../../gfx/video_context_driver.h" +#include "../../gfx/video_driver.h" #include "../../gfx/video_shader_driver.h" #include "../../gfx/common/vita2d_common.h" #include "../../defines/psp_defines.h" diff --git a/menu/drivers_display/menu_display_vulkan.c b/menu/drivers_display/menu_display_vulkan.c index 669ae31733..3612e5e9c3 100644 --- a/menu/drivers_display/menu_display_vulkan.c +++ b/menu/drivers_display/menu_display_vulkan.c @@ -23,7 +23,7 @@ #include "../menu_display.h" #include "../../gfx/font_driver.h" -#include "../../gfx/video_context_driver.h" +#include "../../gfx/video_driver.h" #include "../../gfx/common/vulkan_common.h" #include "../../gfx/video_shader_driver.h" diff --git a/menu/menu_display.h b/menu/menu_display.h index 11f480705f..1416167bf4 100644 --- a/menu/menu_display.h +++ b/menu/menu_display.h @@ -27,7 +27,7 @@ #include "../file_path_special.h" #include "../gfx/font_driver.h" -#include "../gfx/video_context_driver.h" +#include "../gfx/video_driver.h" #include "../gfx/video_coord_array.h" RETRO_BEGIN_DECLS diff --git a/ui/drivers/ui_win32.c b/ui/drivers/ui_win32.c index 13eb35d553..81d17b6a63 100644 --- a/ui/drivers/ui_win32.c +++ b/ui/drivers/ui_win32.c @@ -50,7 +50,7 @@ #include "../../driver.h" #include "../../paths.h" #include "../../runloop.h" -#include "../../gfx/video_context_driver.h" +#include "../../gfx/video_driver.h" #include "../../gfx/video_shader_driver.h" #include "../../tasks/tasks_internal.h"