2012-09-25 01:26:22 +02:00
|
|
|
/* RetroArch - A frontend for libretro.
|
2014-01-01 01:50:59 +01:00
|
|
|
* Copyright (C) 2010-2014 - Hans-Kristian Arntzen
|
2015-01-07 18:06:50 +01:00
|
|
|
* Copyright (C) 2011-2015 - Daniel De Matteis
|
2012-09-25 01:26:22 +02:00
|
|
|
*
|
|
|
|
* RetroArch is free software: you can redistribute it and/or modify it under the terms
|
|
|
|
* of the GNU General Public License as published by the Free Software Found-
|
|
|
|
* ation, either version 3 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
|
|
|
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
|
|
|
* PURPOSE. See the GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along with RetroArch.
|
|
|
|
* If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2013-07-17 20:26:01 -04:00
|
|
|
#include "../general.h"
|
2015-01-12 21:53:04 +01:00
|
|
|
#include "video_context_driver.h"
|
2012-09-28 23:34:19 +02:00
|
|
|
#include <string.h>
|
2012-09-25 01:26:22 +02:00
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "../config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static const gfx_ctx_driver_t *gfx_ctx_drivers[] = {
|
|
|
|
#if defined(__CELLOS_LV2__)
|
|
|
|
&gfx_ctx_ps3,
|
|
|
|
#endif
|
2015-04-03 20:36:19 +02:00
|
|
|
#if defined(HAVE_D3D)
|
2014-09-14 06:45:47 +02:00
|
|
|
&gfx_ctx_d3d,
|
2014-01-18 18:43:07 +01:00
|
|
|
#endif
|
2012-09-25 01:26:22 +02:00
|
|
|
#if defined(HAVE_VIDEOCORE)
|
|
|
|
&gfx_ctx_videocore,
|
|
|
|
#endif
|
2014-06-05 12:28:17 +02:00
|
|
|
#if defined(HAVE_MALI_FBDEV)
|
|
|
|
&gfx_ctx_mali_fbdev,
|
|
|
|
#endif
|
2014-07-27 22:19:11 +02:00
|
|
|
#if defined(HAVE_VIVANTE_FBDEV)
|
|
|
|
&gfx_ctx_vivante_fbdev,
|
|
|
|
#endif
|
2012-09-30 11:26:26 +02:00
|
|
|
#if defined(_WIN32) && defined(HAVE_OPENGL)
|
|
|
|
&gfx_ctx_wgl,
|
|
|
|
#endif
|
2015-03-21 23:09:55 +01:00
|
|
|
#if defined(HAVE_X11) && defined(HAVE_OPENGL)
|
2012-09-29 11:59:08 +02:00
|
|
|
&gfx_ctx_glx,
|
2012-09-25 01:26:22 +02:00
|
|
|
#endif
|
2014-08-14 23:21:27 +02:00
|
|
|
#if defined(HAVE_WAYLAND) && defined(HAVE_OPENGL) && defined(HAVE_EGL)
|
|
|
|
&gfx_ctx_wayland,
|
|
|
|
#endif
|
2012-09-29 11:59:08 +02:00
|
|
|
#if defined(HAVE_X11) && defined(HAVE_OPENGL) && defined(HAVE_EGL)
|
2012-09-25 01:26:22 +02:00
|
|
|
&gfx_ctx_x_egl,
|
|
|
|
#endif
|
|
|
|
#if defined(HAVE_KMS)
|
|
|
|
&gfx_ctx_drm_egl,
|
|
|
|
#endif
|
2012-10-09 00:11:11 +02:00
|
|
|
#if defined(ANDROID)
|
|
|
|
&gfx_ctx_android,
|
|
|
|
#endif
|
2014-05-20 02:48:11 +02:00
|
|
|
#if defined(__QNX__)
|
2013-02-26 01:19:03 +01:00
|
|
|
&gfx_ctx_bbqnx,
|
|
|
|
#endif
|
2014-09-08 17:57:18 +02:00
|
|
|
#if defined(IOS) || defined(OSX)
|
2015-01-09 23:32:32 +01:00
|
|
|
/* Don't use __APPLE__ as it breaks basic SDL builds. */
|
2013-07-07 16:24:28 -04:00
|
|
|
&gfx_ctx_apple,
|
2013-02-06 09:54:15 -05:00
|
|
|
#endif
|
2014-08-21 12:54:20 +02:00
|
|
|
#if (defined(HAVE_SDL) || defined(HAVE_SDL2)) && defined(HAVE_OPENGL)
|
2014-08-20 22:09:30 -03:00
|
|
|
&gfx_ctx_sdl_gl,
|
|
|
|
#endif
|
2013-07-17 20:26:01 -04:00
|
|
|
#ifdef EMSCRIPTEN
|
|
|
|
&gfx_ctx_emscripten,
|
|
|
|
#endif
|
2014-10-07 14:31:10 +02:00
|
|
|
&gfx_ctx_null,
|
2014-03-09 16:50:18 +01:00
|
|
|
NULL
|
2012-09-25 01:26:22 +02:00
|
|
|
};
|
|
|
|
|
2015-04-09 21:58:58 +02:00
|
|
|
|
2015-04-09 18:17:52 +02:00
|
|
|
const gfx_ctx_driver_t *gfx_ctx_get_ptr(void)
|
|
|
|
{
|
|
|
|
driver_t *driver = driver_get_ptr();
|
|
|
|
if (!driver)
|
|
|
|
return NULL;
|
|
|
|
return (const gfx_ctx_driver_t*)driver->video_context;
|
|
|
|
}
|
|
|
|
|
2015-04-09 21:58:58 +02:00
|
|
|
void gfx_ctx_swap_buffers(void *data)
|
|
|
|
{
|
|
|
|
const gfx_ctx_driver_t *ctx = gfx_ctx_get_ptr();
|
|
|
|
|
|
|
|
if (ctx->swap_buffers)
|
|
|
|
ctx->swap_buffers(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool gfx_ctx_focus(void *data)
|
|
|
|
{
|
|
|
|
const gfx_ctx_driver_t *ctx = gfx_ctx_get_ptr();
|
|
|
|
|
|
|
|
if (data && ctx && ctx->has_focus)
|
|
|
|
return ctx->has_focus(data);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void gfx_ctx_set_video_mode(void *data,
|
|
|
|
unsigned width, unsigned height,
|
|
|
|
bool fullscreen)
|
|
|
|
{
|
|
|
|
const gfx_ctx_driver_t *ctx = gfx_ctx_get_ptr();
|
|
|
|
|
|
|
|
if (ctx && ctx->set_video_mode)
|
|
|
|
ctx->set_video_mode(data, width, height, fullscreen);
|
|
|
|
}
|
|
|
|
|
2015-04-09 21:48:20 +02:00
|
|
|
void gfx_ctx_translate_aspect(void *data, float *aspect,
|
|
|
|
unsigned width, unsigned height)
|
|
|
|
{
|
|
|
|
const gfx_ctx_driver_t *ctx = gfx_ctx_get_ptr();
|
|
|
|
if (ctx && ctx->translate_aspect)
|
|
|
|
*aspect = ctx->translate_aspect(data, width, height);
|
|
|
|
}
|
|
|
|
|
2015-04-09 18:55:22 +02:00
|
|
|
bool gfx_ctx_get_metrics(enum display_metric_types type, float *value)
|
|
|
|
{
|
|
|
|
driver_t *driver = driver_get_ptr();
|
|
|
|
const gfx_ctx_driver_t *ctx = gfx_ctx_get_ptr();
|
|
|
|
if (!ctx || !driver)
|
|
|
|
return false;
|
|
|
|
return ctx->get_metrics(driver->video_context_data, type,
|
|
|
|
value);
|
|
|
|
}
|
|
|
|
|
2015-04-10 05:47:36 +02:00
|
|
|
bool gfx_ctx_write_egl_image(void *data, const void *frame, unsigned width,
|
|
|
|
unsigned height, unsigned pitch, bool rgb32,
|
|
|
|
unsigned index, void **image_handle)
|
|
|
|
{
|
|
|
|
const gfx_ctx_driver_t *ctx = gfx_ctx_get_ptr();
|
|
|
|
if (ctx && ctx->write_egl_image)
|
|
|
|
return ctx->write_egl_image(data, frame, width, height, pitch,
|
|
|
|
rgb32, index, image_handle);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
retro_proc_address_t gfx_ctx_get_proc_address(const char *sym)
|
|
|
|
{
|
|
|
|
const gfx_ctx_driver_t *ctx = gfx_ctx_get_ptr();
|
|
|
|
return ctx->get_proc_address(sym);
|
|
|
|
}
|
|
|
|
|
|
|
|
void gfx_ctx_show_mouse(void *data, bool state)
|
|
|
|
{
|
|
|
|
const gfx_ctx_driver_t *ctx = gfx_ctx_get_ptr();
|
|
|
|
if (data && ctx->show_mouse)
|
|
|
|
ctx->show_mouse(data, state);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool gfx_ctx_has_windowed(void *data)
|
|
|
|
{
|
|
|
|
const gfx_ctx_driver_t *ctx = gfx_ctx_get_ptr();
|
|
|
|
|
|
|
|
if (data && ctx)
|
|
|
|
return ctx->has_windowed(data);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-04-10 06:10:05 +02:00
|
|
|
bool gfx_ctx_check_window(void *data, bool *quit, bool *resize,
|
|
|
|
unsigned *width, unsigned *height)
|
|
|
|
{
|
|
|
|
runloop_t *runloop = rarch_main_get_ptr();
|
|
|
|
const gfx_ctx_driver_t *ctx = gfx_ctx_get_ptr();
|
|
|
|
unsigned frame_count = runloop ?
|
|
|
|
runloop->frames.video.count : 0;
|
|
|
|
|
|
|
|
if (!data)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
ctx->check_window(data, quit, resize, width, height,
|
|
|
|
frame_count);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-04-10 06:13:20 +02:00
|
|
|
bool gfx_ctx_suppress_screensaver(void *data, bool enable)
|
|
|
|
{
|
|
|
|
const gfx_ctx_driver_t *ctx = gfx_ctx_get_ptr();
|
|
|
|
|
|
|
|
if (data && ctx)
|
|
|
|
return ctx->suppress_screensaver(data, enable);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-01-09 23:32:32 +01:00
|
|
|
/**
|
|
|
|
* find_gfx_ctx_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_gfx_ctx_driver_index(const char *ident)
|
2012-09-25 01:26:22 +02:00
|
|
|
{
|
2013-10-22 15:08:17 +02:00
|
|
|
unsigned i;
|
2014-10-23 23:55:30 +02:00
|
|
|
for (i = 0; gfx_ctx_drivers[i]; i++)
|
2015-01-09 23:32:32 +01:00
|
|
|
if (strcasecmp(ident, gfx_ctx_drivers[i]->ident) == 0)
|
2014-10-23 23:55:30 +02:00
|
|
|
return i;
|
|
|
|
return -1;
|
|
|
|
}
|
2012-09-25 01:26:22 +02:00
|
|
|
|
2015-01-09 23:32:32 +01:00
|
|
|
/**
|
|
|
|
* find_prev_context_driver:
|
|
|
|
*
|
|
|
|
* Finds previous driver in graphics context driver array.
|
|
|
|
**/
|
2014-10-23 23:55:30 +02:00
|
|
|
void find_prev_gfx_context_driver(void)
|
|
|
|
{
|
2015-03-20 20:43:22 +01:00
|
|
|
settings_t *settings = config_get_ptr();
|
|
|
|
int i = find_gfx_ctx_driver_index(settings->video.context_driver);
|
2015-01-09 23:32:32 +01:00
|
|
|
|
2014-10-23 23:55:30 +02:00
|
|
|
if (i > 0)
|
2014-12-14 14:31:13 +01:00
|
|
|
{
|
2015-03-20 20:43:22 +01:00
|
|
|
strlcpy(settings->video.context_driver, gfx_ctx_drivers[i - 1]->ident,
|
|
|
|
sizeof(settings->video.context_driver));
|
2014-12-14 14:31:13 +01:00
|
|
|
}
|
2014-10-23 23:55:30 +02:00
|
|
|
else
|
|
|
|
RARCH_WARN("Couldn't find any previous video context driver.\n");
|
|
|
|
}
|
|
|
|
|
2015-01-09 23:32:32 +01:00
|
|
|
/**
|
|
|
|
* find_next_context_driver:
|
|
|
|
*
|
|
|
|
* Finds next driver in graphics context driver array.
|
|
|
|
**/
|
2014-10-23 23:55:30 +02:00
|
|
|
void find_next_context_driver(void)
|
|
|
|
{
|
2015-03-20 20:43:22 +01:00
|
|
|
settings_t *settings = config_get_ptr();
|
|
|
|
int i = find_gfx_ctx_driver_index(settings->video.context_driver);
|
2015-01-09 23:32:32 +01:00
|
|
|
|
2014-10-23 23:55:30 +02:00
|
|
|
if (i >= 0 && gfx_ctx_drivers[i + 1])
|
2014-12-14 14:31:13 +01:00
|
|
|
{
|
2015-03-20 20:43:22 +01:00
|
|
|
strlcpy(settings->video.context_driver, gfx_ctx_drivers[i + 1]->ident,
|
|
|
|
sizeof(settings->video.context_driver));
|
2014-12-14 14:31:13 +01:00
|
|
|
}
|
2014-10-23 23:55:30 +02:00
|
|
|
else
|
|
|
|
RARCH_WARN("Couldn't find any next video context driver.\n");
|
2012-09-25 01:26:22 +02:00
|
|
|
}
|
|
|
|
|
2015-01-09 23:32:32 +01:00
|
|
|
/**
|
|
|
|
* gfx_ctx_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 *gfx_ctx_init(void *data,
|
2014-10-23 23:09:37 +02:00
|
|
|
const gfx_ctx_driver_t *ctx,
|
2015-01-09 23:32:32 +01:00
|
|
|
const char *ident,
|
2014-10-23 23:09:37 +02:00
|
|
|
enum gfx_ctx_api api, unsigned major,
|
|
|
|
unsigned minor, bool hw_render_ctx)
|
|
|
|
{
|
2015-03-20 20:43:22 +01:00
|
|
|
settings_t *settings = config_get_ptr();
|
|
|
|
|
2014-10-23 23:09:37 +02:00
|
|
|
if (ctx->bind_api(data, api, major, minor))
|
|
|
|
{
|
2014-10-24 03:12:08 +02:00
|
|
|
bool initialized = ctx->init(data);
|
|
|
|
|
|
|
|
if (!initialized)
|
|
|
|
return NULL;
|
|
|
|
|
2014-10-23 23:09:37 +02:00
|
|
|
if (ctx->bind_hw_render)
|
|
|
|
ctx->bind_hw_render(data,
|
2015-03-20 20:43:22 +01:00
|
|
|
settings->video.shared_context && hw_render_ctx);
|
2014-10-23 23:09:37 +02:00
|
|
|
|
2014-10-24 03:12:08 +02:00
|
|
|
return ctx;
|
2014-10-23 23:09:37 +02:00
|
|
|
}
|
2015-01-09 23:32:32 +01:00
|
|
|
|
2015-01-31 06:01:27 +01:00
|
|
|
#ifndef _WIN32
|
2015-01-31 06:00:31 +01:00
|
|
|
RARCH_WARN("Failed to bind API (#%u, version %u.%u) on context driver \"%s\".\n",
|
2015-01-09 23:32:32 +01:00
|
|
|
(unsigned)api, major, minor, ctx->ident);
|
2015-01-31 06:01:27 +01:00
|
|
|
#endif
|
2014-10-23 23:09:37 +02:00
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2015-01-09 23:32:32 +01:00
|
|
|
/**
|
|
|
|
* gfx_ctx_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?
|
|
|
|
*
|
2015-01-11 20:20:34 +01:00
|
|
|
* Finds graphics context driver and initializes.
|
2015-01-09 23:32:32 +01:00
|
|
|
*
|
|
|
|
* Returns: graphics context driver if found, otherwise NULL.
|
|
|
|
**/
|
2014-10-23 23:55:30 +02:00
|
|
|
static const gfx_ctx_driver_t *gfx_ctx_find_driver(void *data,
|
|
|
|
const char *ident,
|
2014-09-08 17:57:18 +02:00
|
|
|
enum gfx_ctx_api api, unsigned major,
|
|
|
|
unsigned minor, bool hw_render_ctx)
|
2012-09-25 01:26:22 +02:00
|
|
|
{
|
2014-10-23 23:09:37 +02:00
|
|
|
const gfx_ctx_driver_t *ctx = NULL;
|
2014-10-23 23:55:30 +02:00
|
|
|
int i = find_gfx_ctx_driver_index(ident);
|
2014-12-14 14:31:13 +01:00
|
|
|
|
2014-10-23 23:55:30 +02:00
|
|
|
if (i >= 0)
|
2015-01-09 23:32:32 +01:00
|
|
|
return gfx_ctx_init(data, gfx_ctx_drivers[i], ident,
|
2014-10-23 23:55:30 +02:00
|
|
|
api, major, minor, hw_render_ctx);
|
2015-01-09 23:32:32 +01:00
|
|
|
|
|
|
|
for (i = 0; gfx_ctx_drivers[i]; i++)
|
2012-09-25 01:26:22 +02:00
|
|
|
{
|
2015-01-09 23:32:32 +01:00
|
|
|
ctx = gfx_ctx_init(data, gfx_ctx_drivers[i], ident,
|
|
|
|
api, major, minor, hw_render_ctx);
|
|
|
|
if (ctx)
|
|
|
|
return ctx;
|
2014-12-14 14:31:13 +01:00
|
|
|
}
|
2015-01-09 23:32:32 +01:00
|
|
|
|
|
|
|
return NULL;
|
2012-09-25 01:26:22 +02:00
|
|
|
}
|
2014-10-23 23:55:30 +02:00
|
|
|
|
2015-01-09 23:32:32 +01:00
|
|
|
/**
|
|
|
|
* gfx_ctx_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.
|
|
|
|
**/
|
2014-10-23 23:55:30 +02:00
|
|
|
const gfx_ctx_driver_t *gfx_ctx_init_first(void *data,
|
2015-01-09 23:32:32 +01:00
|
|
|
const char *ident, enum gfx_ctx_api api, unsigned major,
|
2014-10-23 23:55:30 +02:00
|
|
|
unsigned minor, bool hw_render_ctx)
|
|
|
|
{
|
2015-01-09 23:32:32 +01:00
|
|
|
return gfx_ctx_find_driver(data, ident, api, major, minor, hw_render_ctx);
|
2014-10-23 23:55:30 +02:00
|
|
|
}
|