/* 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 #include #include "video_driver.h" #include "video_thread_wrapper.h" #include "../general.h" static const video_driver_t *video_drivers[] = { #ifdef HAVE_OPENGL &video_gl, #endif #ifdef XENON &video_xenon360, #endif #if defined(_XBOX) && (defined(HAVE_D3D8) || defined(HAVE_D3D9)) || defined(HAVE_WIN32_D3D9) &video_d3d, #endif #ifdef SN_TARGET_PSP2 &video_vita, #endif #ifdef PSP &video_psp1, #endif #ifdef HAVE_SDL &video_sdl, #endif #ifdef HAVE_SDL2 &video_sdl2, #endif #ifdef HAVE_XVIDEO &video_xvideo, #endif #ifdef GEKKO &video_gx, #endif #ifdef HAVE_VG &video_vg, #endif #ifdef HAVE_OMAP &video_omap, #endif #ifdef HAVE_EXYNOS &video_exynos, #endif &video_null, NULL, }; /** * video_driver_find_handle: * @idx : index of driver to get handle to. * * Returns: handle to video driver at index. Can be NULL * if nothing found. **/ const void *video_driver_find_handle(int idx) { const void *drv = video_drivers[idx]; if (!drv) return NULL; return drv; } /** * video_driver_find_ident: * @idx : index of driver to get handle to. * * Returns: Human-readable identifier of video driver at index. Can be NULL * if nothing found. **/ const char *video_driver_find_ident(int idx) { const video_driver_t *drv = video_drivers[idx]; if (!drv) return NULL; return drv->ident; } /** * config_get_video_driver_options: * * Get an enumerated list of all video driver names, separated by '|'. * * Returns: string listing of all video driver names, separated by '|'. **/ const char* config_get_video_driver_options(void) { union string_list_elem_attr attr; unsigned i; char *options = NULL; int options_len = 0; struct string_list *options_l = string_list_new(); attr.i = 0; for (i = 0; video_driver_find_handle(i); i++) { const char *opt = video_driver_find_ident(i); options_len += strlen(opt) + 1; string_list_append(options_l, opt, attr); } options = (char*)calloc(options_len, sizeof(char)); string_list_join_concat(options, options_len, options_l, "|"); string_list_free(options_l); options_l = NULL; return options; } void find_video_driver(void) { int i; #if defined(HAVE_OPENGL) && defined(HAVE_FBO) if (g_extern.system.hw_render_callback.context_type) { RARCH_LOG("Using HW render, OpenGL driver forced.\n"); driver.video = &video_gl; return; } #endif if (driver.frontend_ctx && driver.frontend_ctx->get_video_driver) { driver.video = driver.frontend_ctx->get_video_driver(); if (driver.video) return; RARCH_WARN("Frontend supports get_video_driver() but did not specify one.\n"); } i = find_driver_index("video_driver", g_settings.video.driver); if (i >= 0) driver.video = (const video_driver_t*)video_driver_find_handle(i); else { unsigned d; RARCH_ERR("Couldn't find any video driver named \"%s\"\n", g_settings.video.driver); RARCH_LOG_OUTPUT("Available video drivers are:\n"); for (d = 0; video_driver_find_handle(d); d++) RARCH_LOG_OUTPUT("\t%s\n", video_driver_find_ident(d)); RARCH_WARN("Going to default to first video driver...\n"); driver.video = (const video_driver_t*)video_driver_find_handle(0); if (!driver.video) rarch_fail(1, "find_video_driver()"); } } /** * video_driver_resolve: * @drv : real video driver will be set to this. * * Use this if you need the real video driver * and driver data pointers. * * Returns: video driver's userdata. **/ void *video_driver_resolve(const video_driver_t **drv) { #ifdef HAVE_THREADS if (g_settings.video.threaded && !g_extern.system.hw_render_callback.context_type) return rarch_threaded_video_resolve(drv); #endif if (drv) *drv = driver.video; return driver.video_data; } /** * video_driver_get_current_framebuffer: * * Gets pointer to current hardware renderer framebuffer object. * Used by RETRO_ENVIRONMENT_SET_HW_RENDER. * * Returns: pointer to hardware framebuffer object, otherwise 0. **/ uintptr_t video_driver_get_current_framebuffer(void) { #ifdef HAVE_FBO if (driver.video_poke && driver.video_poke->get_current_framebuffer) return driver.video_poke->get_current_framebuffer(driver.video_data); #endif return 0; } retro_proc_address_t video_driver_get_proc_address(const char *sym) { #ifdef HAVE_FBO if (driver.video_poke && driver.video_poke->get_proc_address) return driver.video_poke->get_proc_address(driver.video_data, sym); #endif return NULL; }