(driver.c) Add driver_video_resolve()

This function returns the real video driver data when threaded video is
in use.
This commit is contained in:
Higor Eurípedes 2014-09-12 17:18:44 -03:00
parent d6de5773b5
commit 85cef84bd4
6 changed files with 62 additions and 20 deletions

View File

@ -1544,3 +1544,19 @@ void uninit_video_input(void)
deinit_shader_dir(); deinit_shader_dir();
compute_monitor_fps_statistics(); compute_monitor_fps_statistics();
} }
void *driver_video_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);
else
#endif
{
if (drv)
*drv = driver.video;
return driver.video_data;
}
}

View File

@ -554,6 +554,9 @@ bool driver_set_sensor_state(unsigned port,
float driver_sensor_get_input(unsigned port, unsigned action); float driver_sensor_get_input(unsigned port, unsigned action);
/* Use this if you need the real video driver and driver data pointers */
void *driver_video_resolve(const video_driver_t **drv);
#ifdef HAVE_DYLIB #ifdef HAVE_DYLIB
void rarch_deinit_filter(void); void rarch_deinit_filter(void);
void rarch_init_filter(enum retro_pixel_format); void rarch_init_filter(enum retro_pixel_format);

View File

@ -49,7 +49,8 @@ const gl_font_renderer_t *font_driver;
static void blit_line(float x, float y, const char *message, bool green) static void blit_line(float x, float y, const char *message, bool green)
{ {
gl_t *gl = (gl_t*)driver.video_data; gl_t *gl = (gl_t*)driver_video_resolve(NULL);
if (!driver.menu || !gl) if (!driver.menu || !gl)
return; return;
@ -77,7 +78,8 @@ static void glui_render_background(void)
0.0f, 0.0f, 0.0f, 0.9f, 0.0f, 0.0f, 0.0f, 0.9f,
}; };
gl_t *gl = (gl_t*)driver.video_data; gl_t *gl = (gl_t*)driver_video_resolve(NULL);
if (!gl) if (!gl)
return; return;
@ -103,7 +105,7 @@ static void glui_render_messagebox(const char *message)
static void glui_frame(void) static void glui_frame(void)
{ {
gl_t *gl = (gl_t*)driver.video_data; gl_t *gl = (gl_t*)driver_video_resolve(NULL);
if (!driver.menu || !gl) if (!driver.menu || !gl)
return; return;
@ -258,10 +260,19 @@ static void glui_init_core_info(void *data)
static void *glui_init(void) static void *glui_init(void)
{ {
menu_handle_t *menu = (menu_handle_t*)calloc(1, sizeof(*menu)); menu_handle_t *menu;
gl_t *gl = (gl_t*)driver.video_data; const video_driver_t *video_driver = NULL;
gl_t *gl = (gl_t*)driver_video_resolve(&video_driver);
if (!menu || !gl) if (video_driver != &video_gl || !gl)
{
RARCH_ERR("Cannot initialize GLUI menu driver: gl video driver is not active.\n");
return NULL;
}
menu = (menu_handle_t*)calloc(1, sizeof(*menu));
if (!menu)
return NULL; return NULL;
glui_init_core_info(menu); glui_init_core_info(menu);
@ -300,7 +311,7 @@ static void glui_context_reset(void *data)
{ {
char mediapath[256], themepath[256], iconpath[256]; char mediapath[256], themepath[256], iconpath[256];
menu_handle_t *menu = (menu_handle_t*)data; menu_handle_t *menu = (menu_handle_t*)data;
gl_t *gl = (gl_t*)driver.video_data; gl_t *gl = (gl_t*)driver_video_resolve(NULL);
driver.gfx_use_rgba = true; driver.gfx_use_rgba = true;

View File

@ -120,7 +120,8 @@ static int numtweens = 0;
static void lakka_responsive(void) static void lakka_responsive(void)
{ {
gl_t *gl = (gl_t*)driver.video_data; gl_t *gl = (gl_t*)driver_video_resolve(NULL);
if (!gl) if (!gl)
return; return;
@ -352,7 +353,8 @@ static void lakka_draw_text(const char *str, float x,
if (alpha == 0) if (alpha == 0)
return; return;
gl_t *gl = (gl_t*)driver.video_data; gl_t *gl = (gl_t*)driver_video_resolve(NULL);
if (!gl) if (!gl)
return; return;
@ -383,7 +385,8 @@ void lakka_draw_background(void)
1.0f, 1.0f, 1.0f, global_alpha, 1.0f, 1.0f, 1.0f, global_alpha,
}; };
gl_t *gl = (gl_t*)driver.video_data; gl_t *gl = (gl_t*)driver_video_resolve(NULL);
if (!gl) if (!gl)
return; return;
@ -416,7 +419,7 @@ void lakka_draw_icon(GLuint texture, float x, float y,
if (alpha == 0) if (alpha == 0)
return; return;
gl_t *gl = (gl_t*)driver.video_data; gl_t *gl = (gl_t*)driver_video_resolve(NULL);
if (!gl) if (!gl)
return; return;
@ -623,7 +626,7 @@ static void lakka_draw_categories(void)
static void lakka_frame(void) static void lakka_frame(void)
{ {
gl_t *gl = (gl_t*)driver.video_data; gl_t *gl = (gl_t*)driver_video_resolve(NULL);
menu_category_t *active_category = (menu_category_t*) menu_category_t *active_category = (menu_category_t*)
&categories[menu_active_category]; &categories[menu_active_category];
menu_item_t *active_item; menu_item_t *active_item;
@ -680,9 +683,7 @@ static GLuint png_texture_load(const char * file_name)
static void lakka_context_destroy(void *data) static void lakka_context_destroy(void *data)
{ {
int i, j, k; int i, j, k;
gl_t *gl = (gl_t*)driver.video_data; (void)data;
(void)gl;
for (i = 0; i < TEXTURE_LAST; i++) for (i = 0; i < TEXTURE_LAST; i++)
glDeleteTextures(1, &textures[i].id); glDeleteTextures(1, &textures[i].id);
@ -841,7 +842,7 @@ static void lakka_context_reset(void *data)
int i, j, k; int i, j, k;
char mediapath[256], themepath[256], iconpath[256]; char mediapath[256], themepath[256], iconpath[256];
menu_handle_t *menu = (menu_handle_t*)data; menu_handle_t *menu = (menu_handle_t*)data;
gl_t *gl = (gl_t*)driver.video_data; gl_t *gl = (gl_t*)driver_video_resolve(NULL);
driver.gfx_use_rgba = true; driver.gfx_use_rgba = true;
@ -1105,18 +1106,18 @@ static void *lakka_init(void)
{ {
int i; int i;
menu_handle_t *menu; menu_handle_t *menu;
gl_t *gl; const video_driver_t *video_driver = NULL;
gl_t *gl = (gl_t*)driver_video_resolve(&video_driver);
if (driver.video != &video_gl) if (video_driver != &video_gl || !gl)
{ {
RARCH_ERR("Cannot initialize Lakka menu driver: gl video driver is not active.\n"); RARCH_ERR("Cannot initialize Lakka menu driver: gl video driver is not active.\n");
return NULL; return NULL;
} }
menu = (menu_handle_t*)calloc(1, sizeof(*menu)); menu = (menu_handle_t*)calloc(1, sizeof(*menu));
gl = (gl_t*)driver.video_data;
if (!menu || !gl) if (!menu)
return NULL; return NULL;
lakka_responsive(); lakka_responsive();

View File

@ -26,5 +26,7 @@ bool rarch_threaded_video_init(
const input_driver_t **input, void **input_data, const input_driver_t **input, void **input_data,
const video_driver_t *driver, const video_info_t *info); const video_driver_t *driver, const video_info_t *info);
void *rarch_threaded_video_resolve(const video_driver_t **drv);
#endif #endif

View File

@ -926,4 +926,13 @@ bool rarch_threaded_video_init(const video_driver_t **out_driver,
return thread_init(thr, info, input, input_data); return thread_init(thr, info, input, input_data);
} }
void *rarch_threaded_video_resolve(const video_driver_t **drv)
{
const thread_video_t *thr = (const thread_video_t*)driver.video_data;
if (drv)
*drv = thr->driver;
return thr->driver_data;
}