diff --git a/gfx/common/gdi_common.h b/gfx/common/gdi_common.h index ddb33b3fb3..4bac582f3f 100644 --- a/gfx/common/gdi_common.h +++ b/gfx/common/gdi_common.h @@ -34,6 +34,7 @@ typedef struct gdi unsigned video_height; unsigned screen_width; unsigned screen_height; + void *ctx_data; } gdi_t; typedef struct gdi_texture diff --git a/gfx/common/gl_common.h b/gfx/common/gl_common.h index 0f77410cd5..4488287813 100644 --- a/gfx/common/gl_common.h +++ b/gfx/common/gl_common.h @@ -317,6 +317,7 @@ struct gl const gl_renderchain_driver_t *renderchain_driver; void *renderchain_data; + void *ctx_data; }; static INLINE void gl_bind_texture(GLuint id, GLint wrap_mode, GLint mag_filter, diff --git a/gfx/common/sixel_common.h b/gfx/common/sixel_common.h index 5d6e40ced1..d0bda4cef9 100644 --- a/gfx/common/sixel_common.h +++ b/gfx/common/sixel_common.h @@ -29,6 +29,7 @@ typedef struct sixel unsigned video_height; unsigned screen_width; unsigned screen_height; + void *ctx_data; } sixel_t; #endif diff --git a/gfx/common/vulkan_common.h b/gfx/common/vulkan_common.h index e4e3a50570..524f69336d 100644 --- a/gfx/common/vulkan_common.h +++ b/gfx/common/vulkan_common.h @@ -332,6 +332,7 @@ typedef struct vk vulkan_context_t *context; video_info_t video; + void *ctx_data; VkFormat tex_fmt; math_matrix_4x4 mvp, mvp_no_rot; diff --git a/gfx/drivers/gdi_gfx.c b/gfx/drivers/gdi_gfx.c index 6b820c1e18..b560f52d07 100644 --- a/gfx/drivers/gdi_gfx.c +++ b/gfx/drivers/gdi_gfx.c @@ -82,6 +82,7 @@ static void *gdi_gfx_init(const video_info_t *video, unsigned full_x, full_y; gfx_ctx_input_t inp; gfx_ctx_mode_t mode; + void *ctx_data = NULL; const gfx_ctx_driver_t *ctx_driver = NULL; unsigned win_width = 0, win_height = 0; unsigned temp_width = 0, temp_height = 0; @@ -106,10 +107,13 @@ static void *gdi_gfx_init(const video_info_t *video, ctx_driver = video_context_driver_init_first(gdi, settings->arrays.video_context_driver, - GFX_CTX_GDI_API, 1, 0, false); + GFX_CTX_GDI_API, 1, 0, false, &ctx_data); if (!ctx_driver) goto error; + if (ctx_data) + gdi->ctx_data = ctx_data; + video_context_driver_set((const gfx_ctx_driver_t*)ctx_driver); RARCH_LOG("[GDI]: Found GDI context: %s\n", ctx_driver->ident); diff --git a/gfx/drivers/gl.c b/gfx/drivers/gl.c index 0111500ad2..9ba79b00e4 100644 --- a/gfx/drivers/gl.c +++ b/gfx/drivers/gl.c @@ -1501,6 +1501,8 @@ static bool gl_init_pbo_readback(gl_t *gl) static const gfx_ctx_driver_t *gl_get_context(gl_t *gl) { enum gfx_ctx_api api; + const gfx_ctx_driver_t *gfx_ctx = NULL; + void *ctx_data = NULL; const char *api_name = NULL; settings_t *settings = config_get_ptr(); struct retro_hw_render_callback *hwr = video_driver_get_hw_context(); @@ -1533,9 +1535,14 @@ static const gfx_ctx_driver_t *gl_get_context(gl_t *gl) && (hwr->context_type != RETRO_HW_CONTEXT_NONE)) gl_shared_context_use = true; - return video_context_driver_init_first(gl, + gfx_ctx = video_context_driver_init_first(gl, settings->arrays.video_context_driver, - api, major, minor, gl_shared_context_use); + api, major, minor, gl_shared_context_use, &ctx_data); + + if (ctx_data) + gl->ctx_data = ctx_data; + + return gfx_ctx; } #ifdef GL_DEBUG diff --git a/gfx/drivers/sixel_gfx.c b/gfx/drivers/sixel_gfx.c index 4777587688..20676cc755 100644 --- a/gfx/drivers/sixel_gfx.c +++ b/gfx/drivers/sixel_gfx.c @@ -188,9 +188,10 @@ static void scroll_on_demand(int pixelheight) static void *sixel_gfx_init(const video_info_t *video, const input_driver_t **input, void **input_data) { + gfx_ctx_input_t inp; + void *ctx_data = NULL; settings_t *settings = config_get_ptr(); sixel_t *sixel = (sixel_t*)calloc(1, sizeof(*sixel)); - gfx_ctx_input_t inp; const gfx_ctx_driver_t *ctx_driver = NULL; const char *scale_str = NULL; @@ -218,11 +219,14 @@ static void *sixel_gfx_init(const video_info_t *video, ctx_driver = video_context_driver_init_first(sixel, settings->arrays.video_context_driver, - GFX_CTX_SIXEL_API, 1, 0, false); + GFX_CTX_SIXEL_API, 1, 0, false, &ctx_data); if (!ctx_driver) goto error; + if (ctx_data) + sixel->ctx_data = ctx_data; + video_context_driver_set((const gfx_ctx_driver_t*)ctx_driver); RARCH_LOG("[SIXEL]: Found SIXEL context: %s\n", ctx_driver->ident); diff --git a/gfx/drivers/vg.c b/gfx/drivers/vg.c index 7f9c383d3e..f830e89117 100644 --- a/gfx/drivers/vg.c +++ b/gfx/drivers/vg.c @@ -102,15 +102,19 @@ static void *vg_init(const video_info_t *video, int interval = 0; unsigned temp_width = 0; unsigned temp_height = 0; + void *ctx_data = NULL; settings_t *settings = config_get_ptr(); vg_t *vg = (vg_t*)calloc(1, sizeof(vg_t)); const gfx_ctx_driver_t *ctx = video_context_driver_init_first( vg, settings->arrays.video_context_driver, - GFX_CTX_OPENVG_API, 0, 0, false); + GFX_CTX_OPENVG_API, 0, 0, false, &ctx_data); if (!vg || !ctx) goto error; + if (ctx_data) + vg->ctx_data = ctx_data; + video_context_driver_set((void*)ctx); video_context_driver_get_video_size(&mode); diff --git a/gfx/drivers/vulkan.c b/gfx/drivers/vulkan.c index cec0089daa..abf12506fb 100644 --- a/gfx/drivers/vulkan.c +++ b/gfx/drivers/vulkan.c @@ -61,14 +61,19 @@ static void vulkan_viewport_info(void *data, struct video_viewport *vp); static const gfx_ctx_driver_t *vulkan_get_context(vk_t *vk) { - unsigned major = 1; - unsigned minor = 0; - settings_t *settings = config_get_ptr(); - enum gfx_ctx_api api = GFX_CTX_VULKAN_API; - - return video_context_driver_init_first( + void *ctx_data = NULL; + unsigned major = 1; + unsigned minor = 0; + settings_t *settings = config_get_ptr(); + enum gfx_ctx_api api = GFX_CTX_VULKAN_API; + const gfx_ctx_driver_t *gfx_ctx = video_context_driver_init_first( vk, settings->arrays.video_context_driver, - api, major, minor, false); + api, major, minor, false, &ctx_data); + + if (ctx_data) + vk->ctx_data = ctx_data; + + return gfx_ctx; } static void vulkan_init_render_pass( diff --git a/gfx/video_driver.c b/gfx/video_driver.c index 4a126070a9..c9aa356823 100644 --- a/gfx/video_driver.c +++ b/gfx/video_driver.c @@ -3051,18 +3051,17 @@ static const gfx_ctx_driver_t *video_context_driver_init( **/ const gfx_ctx_driver_t *video_context_driver_init_first(void *data, const char *ident, enum gfx_ctx_api api, unsigned major, - unsigned minor, bool hw_render_ctx) + unsigned minor, bool hw_render_ctx, void **ctx_data) { - void *ctx_data = NULL; int i = find_video_context_driver_index(ident); if (i >= 0) { const gfx_ctx_driver_t *ctx = video_context_driver_init(data, gfx_ctx_drivers[i], ident, - api, major, minor, hw_render_ctx, &ctx_data); + api, major, minor, hw_render_ctx, ctx_data); if (ctx) { - video_context_data = ctx_data; + video_context_data = *ctx_data; return ctx; } } @@ -3071,11 +3070,11 @@ const gfx_ctx_driver_t *video_context_driver_init_first(void *data, { const gfx_ctx_driver_t *ctx = video_context_driver_init(data, gfx_ctx_drivers[i], ident, - api, major, minor, hw_render_ctx, &ctx_data); + api, major, minor, hw_render_ctx, ctx_data); if (ctx) { - video_context_data = ctx_data; + video_context_data = *ctx_data; return ctx; } } diff --git a/gfx/video_driver.h b/gfx/video_driver.h index 97c4dd63b8..6add41cec4 100644 --- a/gfx/video_driver.h +++ b/gfx/video_driver.h @@ -1140,8 +1140,10 @@ void video_driver_get_status(uint64_t *frame_count, bool * is_alive, * * Returns: graphics context driver if found, otherwise NULL. **/ -const gfx_ctx_driver_t *video_context_driver_init_first(void *data, const char *ident, - enum gfx_ctx_api api, unsigned major, unsigned minor, bool hw_render_ctx); +const gfx_ctx_driver_t *video_context_driver_init_first( + void *data, const char *ident, + enum gfx_ctx_api api, unsigned major, unsigned minor, + bool hw_render_ctx, void **ctx_data); bool video_context_driver_check_window(gfx_ctx_size_t *size_data);