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
|
2016-01-10 04:41:52 +01:00
|
|
|
* Copyright (C) 2011-2016 - 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/>.
|
|
|
|
*/
|
|
|
|
|
2012-09-28 23:34:19 +02:00
|
|
|
#include <string.h>
|
2012-09-25 01:26:22 +02:00
|
|
|
|
2016-01-20 17:34:19 +01:00
|
|
|
#include <string/stdstring.h>
|
|
|
|
|
2015-11-23 12:03:38 +01:00
|
|
|
#include "video_context_driver.h"
|
|
|
|
|
2012-09-25 01:26:22 +02:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "../config.h"
|
|
|
|
#endif
|
|
|
|
|
2015-11-23 12:03:38 +01:00
|
|
|
#include "../general.h"
|
|
|
|
#include "../verbosity.h"
|
|
|
|
|
2012-09-25 01:26:22 +02:00
|
|
|
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-05-09 11:27:51 +02:00
|
|
|
#if defined(HAVE_X11) && defined(HAVE_OPENGL) && !defined(HAVE_OPENGLES)
|
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
|
2015-04-19 17:27:51 +02:00
|
|
|
#if defined(HAVE_COCOA) || defined(HAVE_COCOATOUCH)
|
2015-04-19 17:40:10 +02:00
|
|
|
&gfx_ctx_cocoagl,
|
2013-02-06 09:54:15 -05:00
|
|
|
#endif
|
2015-04-26 03:59:55 +02:00
|
|
|
#if defined(__APPLE__) && !defined(TARGET_IPHONE_SIMULATOR) && !defined(TARGET_OS_IPHONE)
|
2015-04-26 03:48:35 +02:00
|
|
|
&gfx_ctx_cgl,
|
|
|
|
#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-11-30 09:02:12 +01:00
|
|
|
static const gfx_ctx_driver_t *current_video_context;
|
2015-11-23 21:24:02 +01:00
|
|
|
static void *video_context_data;
|
2015-04-09 21:58:58 +02:00
|
|
|
|
2015-11-23 21:20:21 +01:00
|
|
|
void gfx_ctx_set(const gfx_ctx_driver_t *ctx_driver)
|
|
|
|
{
|
2015-11-23 21:24:02 +01:00
|
|
|
if (!ctx_driver)
|
2015-11-23 21:20:21 +01:00
|
|
|
return;
|
2015-11-30 09:02:12 +01:00
|
|
|
current_video_context = ctx_driver;
|
2015-11-23 21:20:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void gfx_ctx_destroy(const gfx_ctx_driver_t *ctx_driver)
|
|
|
|
{
|
2015-11-30 09:02:12 +01:00
|
|
|
current_video_context = NULL;
|
2015-11-23 21:20:21 +01:00
|
|
|
}
|
|
|
|
|
2015-12-08 12:18:57 -03:00
|
|
|
void gfx_ctx_free(void)
|
2015-04-10 08:26:43 +02:00
|
|
|
{
|
2015-11-30 09:02:12 +01:00
|
|
|
if (current_video_context->destroy)
|
2015-12-08 12:18:57 -03:00
|
|
|
current_video_context->destroy(video_context_data);
|
2015-11-30 09:02:12 +01:00
|
|
|
current_video_context = NULL;
|
2015-12-08 13:54:03 -03:00
|
|
|
video_context_data = NULL;
|
2015-04-10 08:26:43 +02:00
|
|
|
}
|
|
|
|
|
2015-04-16 20:00:10 +02:00
|
|
|
const char *gfx_ctx_get_ident(void)
|
|
|
|
{
|
2015-11-30 09:02:12 +01:00
|
|
|
const gfx_ctx_driver_t *ctx = current_video_context;
|
2015-04-16 20:00:10 +02:00
|
|
|
|
|
|
|
if (!ctx)
|
|
|
|
return NULL;
|
|
|
|
return ctx->ident;
|
|
|
|
}
|
|
|
|
|
2015-12-08 12:18:57 -03:00
|
|
|
void gfx_ctx_update_window_title(void)
|
2015-04-10 08:26:43 +02:00
|
|
|
{
|
2015-11-30 09:02:12 +01:00
|
|
|
if (current_video_context->update_window_title)
|
2015-12-08 12:18:57 -03:00
|
|
|
current_video_context->update_window_title(video_context_data);
|
2015-04-10 08:26:43 +02:00
|
|
|
}
|
|
|
|
|
2016-02-13 08:19:56 +01:00
|
|
|
void gfx_ctx_get_video_output_size(unsigned *width, unsigned *height)
|
2015-04-10 09:11:17 +02:00
|
|
|
{
|
2016-02-13 08:19:56 +01:00
|
|
|
if (!current_video_context || !current_video_context->get_video_output_size)
|
|
|
|
return;
|
|
|
|
current_video_context->get_video_output_size(video_context_data, width, height);
|
2015-04-10 09:11:17 +02:00
|
|
|
}
|
|
|
|
|
2015-12-08 12:18:57 -03:00
|
|
|
bool gfx_ctx_get_video_output_prev(void)
|
2015-04-10 09:11:17 +02:00
|
|
|
{
|
2016-02-13 08:19:56 +01:00
|
|
|
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;
|
2015-04-10 09:11:17 +02:00
|
|
|
}
|
|
|
|
|
2015-12-08 12:18:57 -03:00
|
|
|
bool gfx_ctx_get_video_output_next(void)
|
2015-04-10 09:11:17 +02:00
|
|
|
{
|
2016-02-13 08:19:56 +01:00
|
|
|
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;
|
2015-04-10 09:11:17 +02:00
|
|
|
}
|
|
|
|
|
2015-12-08 12:18:57 -03:00
|
|
|
void gfx_ctx_swap_buffers(void)
|
2015-04-09 21:58:58 +02:00
|
|
|
{
|
2015-12-03 23:59:54 +01:00
|
|
|
if (!current_video_context)
|
|
|
|
return;
|
2015-11-30 09:02:12 +01:00
|
|
|
if (current_video_context->swap_buffers)
|
2015-12-08 12:18:57 -03:00
|
|
|
current_video_context->swap_buffers(video_context_data);
|
2015-04-09 21:58:58 +02:00
|
|
|
}
|
|
|
|
|
2015-12-08 12:18:57 -03:00
|
|
|
void gfx_ctx_bind_hw_render(bool enable)
|
2015-04-10 09:07:53 +02:00
|
|
|
{
|
2015-11-30 09:02:12 +01:00
|
|
|
if (current_video_context->bind_hw_render)
|
2015-12-08 12:18:57 -03:00
|
|
|
current_video_context->bind_hw_render(video_context_data, enable);
|
2015-04-10 09:07:53 +02:00
|
|
|
}
|
|
|
|
|
2015-12-08 12:18:57 -03:00
|
|
|
bool gfx_ctx_focus(void)
|
2015-04-09 21:58:58 +02:00
|
|
|
{
|
2016-02-13 08:19:56 +01:00
|
|
|
if (!video_context_data || !current_video_context->has_focus)
|
|
|
|
return false;
|
|
|
|
return current_video_context->has_focus(video_context_data);
|
2015-04-09 21:58:58 +02:00
|
|
|
}
|
|
|
|
|
2015-12-08 12:18:57 -03:00
|
|
|
bool gfx_ctx_set_video_mode(
|
2015-04-09 21:58:58 +02:00
|
|
|
unsigned width, unsigned height,
|
|
|
|
bool fullscreen)
|
|
|
|
{
|
2016-02-13 08:19:56 +01:00
|
|
|
if (!current_video_context || !current_video_context->set_video_mode)
|
|
|
|
return false;
|
|
|
|
return current_video_context->set_video_mode(
|
|
|
|
video_context_data, width, height, fullscreen);
|
2015-04-09 21:58:58 +02:00
|
|
|
}
|
|
|
|
|
2015-12-08 12:18:57 -03:00
|
|
|
void gfx_ctx_translate_aspect(float *aspect,
|
2015-04-09 21:48:20 +02:00
|
|
|
unsigned width, unsigned height)
|
|
|
|
{
|
2016-01-21 21:27:54 +01:00
|
|
|
if (!current_video_context || !current_video_context->translate_aspect)
|
|
|
|
return;
|
|
|
|
|
2016-02-06 21:51:37 +01:00
|
|
|
*aspect = current_video_context->translate_aspect(
|
|
|
|
video_context_data, width, height);
|
2015-04-09 21:48:20 +02:00
|
|
|
}
|
|
|
|
|
2015-04-09 18:55:22 +02:00
|
|
|
bool gfx_ctx_get_metrics(enum display_metric_types type, float *value)
|
|
|
|
{
|
2016-01-21 21:27:54 +01:00
|
|
|
if (!current_video_context || !current_video_context->get_metrics)
|
|
|
|
return false;
|
|
|
|
return current_video_context->get_metrics(video_context_data, type,
|
|
|
|
value);
|
2015-04-09 18:55:22 +02:00
|
|
|
}
|
|
|
|
|
2015-12-08 17:24:39 -03:00
|
|
|
bool gfx_ctx_image_buffer_init(const video_info_t* info)
|
2015-04-10 09:02:24 +02:00
|
|
|
{
|
2016-02-13 08:19:56 +01:00
|
|
|
if (!current_video_context || !current_video_context->image_buffer_init)
|
|
|
|
return false;
|
|
|
|
return current_video_context->image_buffer_init(video_context_data, info);
|
2015-04-10 09:02:24 +02:00
|
|
|
}
|
|
|
|
|
2015-12-08 17:24:39 -03:00
|
|
|
bool gfx_ctx_image_buffer_write(const void *frame, unsigned width,
|
2015-04-10 05:47:36 +02:00
|
|
|
unsigned height, unsigned pitch, bool rgb32,
|
|
|
|
unsigned index, void **image_handle)
|
|
|
|
{
|
2016-02-13 08:19:56 +01:00
|
|
|
if (!current_video_context || !current_video_context->image_buffer_write)
|
|
|
|
return false;
|
|
|
|
return current_video_context->image_buffer_write(video_context_data,
|
|
|
|
frame, width, height, pitch,
|
|
|
|
rgb32, index, image_handle);
|
2015-04-10 05:47:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
retro_proc_address_t gfx_ctx_get_proc_address(const char *sym)
|
|
|
|
{
|
2015-11-30 09:02:12 +01:00
|
|
|
return current_video_context->get_proc_address(sym);
|
2015-04-10 05:47:36 +02:00
|
|
|
}
|
|
|
|
|
2015-12-08 12:18:57 -03:00
|
|
|
void gfx_ctx_show_mouse(bool state)
|
2015-04-10 05:47:36 +02:00
|
|
|
{
|
2016-02-13 08:19:56 +01:00
|
|
|
if (!video_context_data || !current_video_context->show_mouse)
|
|
|
|
return;
|
|
|
|
current_video_context->show_mouse(video_context_data, state);
|
2015-04-10 05:47:36 +02:00
|
|
|
}
|
|
|
|
|
2015-12-08 12:18:57 -03:00
|
|
|
bool gfx_ctx_has_windowed(void)
|
2015-04-10 05:47:36 +02:00
|
|
|
{
|
2016-02-13 08:19:56 +01:00
|
|
|
if (!video_context_data)
|
|
|
|
return false;
|
|
|
|
return current_video_context->has_windowed(video_context_data);
|
2015-04-10 05:47:36 +02:00
|
|
|
}
|
|
|
|
|
2015-12-08 12:18:57 -03:00
|
|
|
bool gfx_ctx_check_window(bool *quit, bool *resize,
|
2015-04-10 06:10:05 +02:00
|
|
|
unsigned *width, unsigned *height)
|
|
|
|
{
|
2015-11-20 15:08:27 +01:00
|
|
|
uint64_t *frame_count;
|
|
|
|
|
|
|
|
video_driver_ctl(RARCH_DISPLAY_CTL_GET_FRAME_COUNT, &frame_count);
|
2015-04-10 06:10:05 +02:00
|
|
|
|
2015-12-08 12:18:57 -03:00
|
|
|
if (!video_context_data)
|
2015-04-10 06:10:05 +02:00
|
|
|
return false;
|
|
|
|
|
2016-02-06 21:51:37 +01:00
|
|
|
current_video_context->check_window(video_context_data, quit,
|
|
|
|
resize, width, height, (unsigned int)*frame_count);
|
2015-04-10 06:10:05 +02:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-12-08 12:18:57 -03:00
|
|
|
bool gfx_ctx_suppress_screensaver(bool enable)
|
2015-04-10 06:13:20 +02:00
|
|
|
{
|
2015-12-08 12:18:57 -03:00
|
|
|
if (video_context_data && current_video_context)
|
2016-02-06 21:51:37 +01:00
|
|
|
return current_video_context->suppress_screensaver(
|
|
|
|
video_context_data, enable);
|
2015-04-10 06:13:20 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-02-13 08:19:56 +01:00
|
|
|
void gfx_ctx_get_video_size(unsigned *width, unsigned *height)
|
2015-04-10 07:12:15 +02:00
|
|
|
{
|
2015-12-08 12:18:57 -03:00
|
|
|
current_video_context->get_video_size(video_context_data, width, height);
|
2015-04-10 07:12:15 +02:00
|
|
|
}
|
|
|
|
|
2015-12-08 12:18:57 -03:00
|
|
|
void gfx_ctx_swap_interval(unsigned interval)
|
2015-04-10 08:33:07 +02:00
|
|
|
{
|
2015-11-30 09:02:12 +01:00
|
|
|
if (current_video_context)
|
2015-12-08 12:18:57 -03:00
|
|
|
current_video_context->swap_interval(video_context_data, interval);
|
2015-04-10 08:33:07 +02:00
|
|
|
}
|
|
|
|
|
2016-01-07 00:58:33 +01:00
|
|
|
bool gfx_ctx_set_resize(unsigned width, unsigned height)
|
2015-04-10 08:33:07 +02:00
|
|
|
{
|
2016-01-07 00:58:33 +01:00
|
|
|
if (!current_video_context)
|
|
|
|
return false;
|
|
|
|
|
2016-02-06 21:51:37 +01:00
|
|
|
return current_video_context->set_resize(
|
|
|
|
video_context_data, width, height);
|
2015-04-10 08:33:07 +02:00
|
|
|
}
|
|
|
|
|
2015-12-08 12:18:57 -03:00
|
|
|
void gfx_ctx_input_driver(
|
2015-04-10 08:53:45 +02:00
|
|
|
const input_driver_t **input, void **input_data)
|
|
|
|
{
|
2015-11-30 09:02:12 +01:00
|
|
|
if (current_video_context)
|
2016-02-06 21:51:37 +01:00
|
|
|
current_video_context->input_driver(
|
|
|
|
video_context_data, input, input_data);
|
2015-04-10 08:53:45 +02:00
|
|
|
}
|
|
|
|
|
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++)
|
2016-01-20 17:34:19 +01:00
|
|
|
if (string_is_equal_noncase(ident, gfx_ctx_drivers[i]->ident))
|
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))
|
|
|
|
{
|
2015-12-08 12:18:57 -03:00
|
|
|
void *ctx_data = ctx->init(data);
|
2014-10-24 03:12:08 +02:00
|
|
|
|
2015-12-08 12:18:57 -03:00
|
|
|
if (!ctx_data)
|
2014-10-24 03:12:08 +02:00
|
|
|
return NULL;
|
|
|
|
|
2014-10-23 23:09:37 +02:00
|
|
|
if (ctx->bind_hw_render)
|
2015-12-08 12:18:57 -03:00
|
|
|
ctx->bind_hw_render(ctx_data,
|
2015-03-20 20:43:22 +01:00
|
|
|
settings->video.shared_context && hw_render_ctx);
|
2014-10-23 23:09:37 +02:00
|
|
|
|
2015-12-08 12:18:57 -03:00
|
|
|
video_context_data = ctx_data;
|
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: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-09-29 17:35:28 +02:00
|
|
|
const gfx_ctx_driver_t *ctx =
|
|
|
|
gfx_ctx_init(data, gfx_ctx_drivers[i], ident,
|
2015-01-09 23:32:32 +01:00
|
|
|
api, major, minor, hw_render_ctx);
|
2015-09-29 17:35:28 +02:00
|
|
|
|
2015-01-09 23:32:32 +01:00
|
|
|
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)
|
|
|
|
{
|
2016-02-06 21:51:37 +01:00
|
|
|
return gfx_ctx_find_driver(data, ident, api,
|
|
|
|
major, minor, hw_render_ctx);
|
2014-10-23 23:55:30 +02:00
|
|
|
}
|