(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();
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);
/* 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
void rarch_deinit_filter(void);
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)
{
gl_t *gl = (gl_t*)driver.video_data;
gl_t *gl = (gl_t*)driver_video_resolve(NULL);
if (!driver.menu || !gl)
return;
@ -77,7 +78,8 @@ static void glui_render_background(void)
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)
return;
@ -103,7 +105,7 @@ static void glui_render_messagebox(const char *message)
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)
return;
@ -258,10 +260,19 @@ static void glui_init_core_info(void *data)
static void *glui_init(void)
{
menu_handle_t *menu = (menu_handle_t*)calloc(1, sizeof(*menu));
gl_t *gl = (gl_t*)driver.video_data;
menu_handle_t *menu;
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;
glui_init_core_info(menu);
@ -300,7 +311,7 @@ static void glui_context_reset(void *data)
{
char mediapath[256], themepath[256], iconpath[256];
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;

View File

@ -120,7 +120,8 @@ static int numtweens = 0;
static void lakka_responsive(void)
{
gl_t *gl = (gl_t*)driver.video_data;
gl_t *gl = (gl_t*)driver_video_resolve(NULL);
if (!gl)
return;
@ -352,7 +353,8 @@ static void lakka_draw_text(const char *str, float x,
if (alpha == 0)
return;
gl_t *gl = (gl_t*)driver.video_data;
gl_t *gl = (gl_t*)driver_video_resolve(NULL);
if (!gl)
return;
@ -383,7 +385,8 @@ void lakka_draw_background(void)
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)
return;
@ -416,7 +419,7 @@ void lakka_draw_icon(GLuint texture, float x, float y,
if (alpha == 0)
return;
gl_t *gl = (gl_t*)driver.video_data;
gl_t *gl = (gl_t*)driver_video_resolve(NULL);
if (!gl)
return;
@ -623,7 +626,7 @@ static void lakka_draw_categories(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*)
&categories[menu_active_category];
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)
{
int i, j, k;
gl_t *gl = (gl_t*)driver.video_data;
(void)gl;
(void)data;
for (i = 0; i < TEXTURE_LAST; i++)
glDeleteTextures(1, &textures[i].id);
@ -841,7 +842,7 @@ static void lakka_context_reset(void *data)
int i, j, k;
char mediapath[256], themepath[256], iconpath[256];
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;
@ -1105,18 +1106,18 @@ static void *lakka_init(void)
{
int i;
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");
return NULL;
}
menu = (menu_handle_t*)calloc(1, sizeof(*menu));
gl = (gl_t*)driver.video_data;
if (!menu || !gl)
if (!menu)
return NULL;
lakka_responsive();

View File

@ -26,5 +26,7 @@ bool rarch_threaded_video_init(
const input_driver_t **input, void **input_data,
const video_driver_t *driver, const video_info_t *info);
void *rarch_threaded_video_resolve(const video_driver_t **drv);
#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);
}
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;
}