From affb2594099cf81041efb8c2e758008fdc0dde93 Mon Sep 17 00:00:00 2001 From: twinaphex Date: Wed, 25 Jan 2017 14:47:24 +0100 Subject: [PATCH] Pass video_driver_is_threaded return value to font driver init/free functions --- gfx/drivers_font/caca_font.c | 8 ++- gfx/drivers_font/ctr_font.c | 5 +- gfx/drivers_font/d3d_w32_font.cpp | 5 +- gfx/drivers_font/gdi_font.c | 8 ++- gfx/drivers_font/gl_raster_font.c | 14 ++-- gfx/drivers_font/ps_libdbgfont.c | 5 +- gfx/drivers_font/vga_font.c | 8 ++- gfx/drivers_font/vita2d_font.c | 8 ++- gfx/drivers_font/vulkan_raster_font.c | 10 +-- gfx/drivers_font/xdk1_xfonts.c | 5 +- gfx/drivers_font/xdk360_fonts.cpp | 17 ++--- gfx/font_driver.c | 95 +++++++++++++++++---------- gfx/font_driver.h | 5 +- gfx/video_thread_wrapper.c | 8 ++- gfx/video_thread_wrapper.h | 6 +- 15 files changed, 128 insertions(+), 79 deletions(-) diff --git a/gfx/drivers_font/caca_font.c b/gfx/drivers_font/caca_font.c index 349bd7ab1a..dfe0f9c91f 100644 --- a/gfx/drivers_font/caca_font.c +++ b/gfx/drivers_font/caca_font.c @@ -35,7 +35,8 @@ typedef struct } caca_raster_t; static void *caca_init_font(void *data, - const char *font_path, float font_size) + const char *font_path, float font_size, + bool is_threaded) { caca_raster_t *font = (caca_raster_t*)calloc(1, sizeof(*font)); @@ -56,9 +57,10 @@ static void *caca_init_font(void *data, return font; } -static void caca_render_free_font(void *data) +static void caca_render_free_font(void *data, bool is_threaded) { - + (void)data; + (void)is_threaded; } static int caca_get_message_width(void *data, const char *msg, diff --git a/gfx/drivers_font/ctr_font.c b/gfx/drivers_font/ctr_font.c index 4c483679f4..6d83ee9105 100644 --- a/gfx/drivers_font/ctr_font.c +++ b/gfx/drivers_font/ctr_font.c @@ -45,7 +45,8 @@ typedef struct void* font_data; } ctr_font_t; -static void* ctr_font_init_font(void* data, const char* font_path, float font_size) +static void* ctr_font_init_font(void* data, const char* font_path, + float font_size, bool is_threaded) { const struct font_atlas* atlas = NULL; ctr_font_t* font = (ctr_font_t*)calloc(1, sizeof(*font)); @@ -96,7 +97,7 @@ static void* ctr_font_init_font(void* data, const char* font_path, float font_si return font; } -static void ctr_font_free_font(void* data) +static void ctr_font_free_font(void* data, bool is_threaded) { ctr_font_t* font = (ctr_font_t*)data; diff --git a/gfx/drivers_font/d3d_w32_font.cpp b/gfx/drivers_font/d3d_w32_font.cpp index dca48280d1..06f8f9e744 100644 --- a/gfx/drivers_font/d3d_w32_font.cpp +++ b/gfx/drivers_font/d3d_w32_font.cpp @@ -35,7 +35,8 @@ typedef struct } d3dfonts_t; static void *d3dfonts_w32_init_font(void *video_data, - const char *font_path, float font_size) + const char *font_path, float font_size, + bool is_threaded) { uint32_t r, g, b; d3dfonts_t *d3dfonts = NULL; @@ -78,7 +79,7 @@ static void *d3dfonts_w32_init_font(void *video_data, return NULL; } -static void d3dfonts_w32_free_font(void *data) +static void d3dfonts_w32_free_font(void *data, bool is_threaded) { d3dfonts_t *d3dfonts = (d3dfonts_t*)data; diff --git a/gfx/drivers_font/gdi_font.c b/gfx/drivers_font/gdi_font.c index ef02b452a4..9e43be5072 100644 --- a/gfx/drivers_font/gdi_font.c +++ b/gfx/drivers_font/gdi_font.c @@ -41,7 +41,8 @@ typedef struct } gdi_raster_t; static void *gdi_init_font(void *data, - const char *font_path, float font_size) + const char *font_path, float font_size, + bool is_threaded) { gdi_raster_t *font = (gdi_raster_t*)calloc(1, sizeof(*font)); @@ -62,9 +63,10 @@ static void *gdi_init_font(void *data, return font; } -static void gdi_render_free_font(void *data) +static void gdi_render_free_font(void *data, bool is_threaded) { - + (void)data; + (void)is_threaded; } static int gdi_get_message_width(void *data, const char *msg, diff --git a/gfx/drivers_font/gl_raster_font.c b/gfx/drivers_font/gl_raster_font.c index d20c33b470..b34628d6f5 100644 --- a/gfx/drivers_font/gl_raster_font.c +++ b/gfx/drivers_font/gl_raster_font.c @@ -55,7 +55,7 @@ typedef struct video_font_raster_block_t *block; } gl_raster_t; -static void gl_raster_font_free_font(void *data); +static void gl_raster_font_free_font(void *data, bool is_threaded); static bool gl_raster_font_upload_atlas(gl_raster_t *font) { @@ -143,7 +143,8 @@ static bool gl_raster_font_upload_atlas(gl_raster_t *font) } static void *gl_raster_font_init_font(void *data, - const char *font_path, float font_size) + const char *font_path, float font_size, + bool is_threaded) { gl_raster_t *font = (gl_raster_t*)calloc(1, sizeof(*font)); @@ -160,7 +161,7 @@ static void *gl_raster_font_init_font(void *data, return NULL; } - if (video_driver_is_threaded()) + if (is_threaded) video_context_driver_make_current(false); glGenTextures(1, &font->tex); @@ -184,13 +185,14 @@ static void *gl_raster_font_init_font(void *data, return font; error: - gl_raster_font_free_font(font); + gl_raster_font_free_font(font, is_threaded); font = NULL; return NULL; } -static void gl_raster_font_free_font(void *data) +static void gl_raster_font_free_font(void *data, + bool is_threaded) { gl_raster_t *font = (gl_raster_t*)data; if (!font) @@ -199,7 +201,7 @@ static void gl_raster_font_free_font(void *data) if (font->font_driver && font->font_data) font->font_driver->free(font->font_data); - if (video_driver_is_threaded()) + if (is_threaded) video_context_driver_make_current(true); glDeleteTextures(1, &font->tex); diff --git a/gfx/drivers_font/ps_libdbgfont.c b/gfx/drivers_font/ps_libdbgfont.c index cef0d400b7..25268c031e 100644 --- a/gfx/drivers_font/ps_libdbgfont.c +++ b/gfx/drivers_font/ps_libdbgfont.c @@ -31,7 +31,8 @@ #include "../font_driver.h" -static void *libdbg_font_init_font(void *gl_data, const char *font_path, float font_size) +static void *libdbg_font_init_font(void *gl_data, const char *font_path, + float font_size, bool is_threaded) { unsigned width, height; @@ -57,7 +58,7 @@ static void *libdbg_font_init_font(void *gl_data, const char *font_path, float f return (void*)-1; } -static void libdbg_font_free_font(void *data) +static void libdbg_font_free_font(void *data, bool is_threaded) { (void)data; DbgFontExit(); diff --git a/gfx/drivers_font/vga_font.c b/gfx/drivers_font/vga_font.c index 024c2ed49c..2a8f032602 100644 --- a/gfx/drivers_font/vga_font.c +++ b/gfx/drivers_font/vga_font.c @@ -34,7 +34,8 @@ typedef struct } vga_raster_t; static void *vga_init_font(void *data, - const char *font_path, float font_size) + const char *font_path, float font_size, + bool is_threaded) { vga_raster_t *font = (vga_raster_t*)calloc(1, sizeof(*font)); @@ -55,9 +56,10 @@ static void *vga_init_font(void *data, return font; } -static void vga_render_free_font(void *data) +static void vga_render_free_font(void *data, bool is_threaded) { - + (void)data; + (void)is_threaded; } static int vga_get_message_width(void *data, const char *msg, diff --git a/gfx/drivers_font/vita2d_font.c b/gfx/drivers_font/vita2d_font.c index 1b8af4cda2..80554993ad 100644 --- a/gfx/drivers_font/vita2d_font.c +++ b/gfx/drivers_font/vita2d_font.c @@ -33,7 +33,9 @@ typedef struct struct font_atlas *atlas; } vita_font_t; -static void *vita2d_font_init_font(void *data, const char *font_path, float font_size) +static void *vita2d_font_init_font(void *data, + const char *font_path, float font_size, + bool is_threaded) { unsigned int stride, pitch, j, k; const uint8_t *frame32 = NULL; @@ -44,7 +46,7 @@ static void *vita2d_font_init_font(void *data, const char *font_path, float font if (!font) return NULL; - font->vita = (vita_video_t*)data; + font->vita = (vita_video_t*)data; if (!font_renderer_create_default((const void**)&font->font_driver, &font->font_data, font_path, font_size)) @@ -87,7 +89,7 @@ error: return NULL; } -static void vita2d_font_free_font(void *data) +static void vita2d_font_free_font(void *data, bool is_threaded) { vita_font_t *font = (vita_font_t*)data; if (!font) diff --git a/gfx/drivers_font/vulkan_raster_font.c b/gfx/drivers_font/vulkan_raster_font.c index 5e7fcd93cd..6b7f51c217 100644 --- a/gfx/drivers_font/vulkan_raster_font.c +++ b/gfx/drivers_font/vulkan_raster_font.c @@ -33,13 +33,15 @@ typedef struct unsigned vertices; } vulkan_raster_t; -static void vulkan_raster_font_free_font(void *data); +static void vulkan_raster_font_free_font(void *data, bool is_threaded); static void *vulkan_raster_font_init_font(void *data, - const char *font_path, float font_size) + const char *font_path, float font_size, + bool is_threaded) { const struct font_atlas *atlas = NULL; - vulkan_raster_t *font = (vulkan_raster_t*)calloc(1, sizeof(*font)); + vulkan_raster_t *font = + (vulkan_raster_t*)calloc(1, sizeof(*font)); #if 0 VkComponentMapping swizzle = { @@ -71,7 +73,7 @@ static void *vulkan_raster_font_init_font(void *data, return font; } -static void vulkan_raster_font_free_font(void *data) +static void vulkan_raster_font_free_font(void *data, bool is_threaded) { vulkan_raster_t *font = (vulkan_raster_t*)data; if (!font) diff --git a/gfx/drivers_font/xdk1_xfonts.c b/gfx/drivers_font/xdk1_xfonts.c index 47bf9b757d..4e0c808d64 100644 --- a/gfx/drivers_font/xdk1_xfonts.c +++ b/gfx/drivers_font/xdk1_xfonts.c @@ -32,7 +32,8 @@ typedef struct } xfonts_t; static void *xfonts_init_font(void *video_data, - const char *font_path, float font_size) + const char *font_path, float font_size, + bool is_threaded) { xfonts_t *xfont = (xfonts_t*)calloc(1, sizeof(*xfont)); @@ -53,7 +54,7 @@ static void *xfonts_init_font(void *video_data, return xfont; } -static void xfonts_free_font(void *data) +static void xfonts_free_font(void *data, bool is_threaded) { xfonts_t *font = (xfonts_t*)data; diff --git a/gfx/drivers_font/xdk360_fonts.cpp b/gfx/drivers_font/xdk360_fonts.cpp index 54c319c037..22e79b0195 100644 --- a/gfx/drivers_font/xdk360_fonts.cpp +++ b/gfx/drivers_font/xdk360_fonts.cpp @@ -519,7 +519,8 @@ static HRESULT xdk360_video_font_create_shaders(xdk360_video_font_t * font) } static void *xdk360_init_font(void *video_data, - const char *font_path, float font_size) + const char *font_path, float font_size, + bool is_threaded) { uint32_t dwFileVersion; const void *pFontData = NULL; @@ -591,7 +592,7 @@ error: return NULL; } -static void xdk360_free_font(void *data) +static void xdk360_free_font(void *data, bool is_threaded) { xdk360_video_font_t *font = (xdk360_video_font_t*)data; @@ -599,10 +600,10 @@ static void xdk360_free_font(void *data) return; /* Destroy the font */ - font->m_pFontTexture = NULL; - font->m_dwNumGlyphs = 0L; - font->m_Glyphs = NULL; - font->m_cMaxGlyph = 0; + font->m_pFontTexture = NULL; + font->m_dwNumGlyphs = 0L; + font->m_Glyphs = NULL; + font->m_cMaxGlyph = 0; font->m_TranslatorTable = NULL; if (font->s_FontLocals.m_pFontPixelShader) @@ -612,9 +613,9 @@ static void xdk360_free_font(void *data) if (font->s_FontLocals.m_pFontVertexDecl) font->s_FontLocals.m_pFontVertexDecl->Release(); - font->s_FontLocals.m_pFontPixelShader = NULL; + font->s_FontLocals.m_pFontPixelShader = NULL; font->s_FontLocals.m_pFontVertexShader = NULL; - font->s_FontLocals.m_pFontVertexDecl = NULL; + font->s_FontLocals.m_pFontVertexDecl = NULL; if (m_xprResource.Initialized()) m_xprResource.Destroy(); diff --git a/gfx/font_driver.c b/gfx/font_driver.c index a6342a7a7f..fd813604d0 100644 --- a/gfx/font_driver.c +++ b/gfx/font_driver.c @@ -44,7 +44,7 @@ static const font_renderer_driver_t *font_backends[] = { NULL }; -static void *video_font_driver; +static void *video_font_driver = NULL; int font_renderer_create_default(const void **data, void **handle, const char *font_path, unsigned font_size) @@ -95,14 +95,16 @@ static const font_renderer_t *d3d_font_backends[] = { static bool d3d_font_init_first( const void **font_driver, void **font_handle, - void *video_data, const char *font_path, float font_size) + void *video_data, const char *font_path, + float font_size, bool is_threaded) { unsigned i; for (i = 0; i < ARRAY_SIZE(d3d_font_backends); i++) { void *data = d3d_font_backends[i]->init( - video_data, font_path, font_size); + video_data, font_path, font_size, + is_threaded); if (!data) continue; @@ -128,14 +130,16 @@ static const font_renderer_t *gl_font_backends[] = { static bool gl_font_init_first( const void **font_driver, void **font_handle, - void *video_data, const char *font_path, float font_size) + void *video_data, const char *font_path, + float font_size, bool is_threaded) { unsigned i; for (i = 0; gl_font_backends[i]; i++) { void *data = gl_font_backends[i]->init( - video_data, font_path, font_size); + video_data, font_path, font_size, + is_threaded); if (!data) continue; @@ -157,14 +161,16 @@ static const font_renderer_t *caca_font_backends[] = { static bool caca_font_init_first( const void **font_driver, void **font_handle, - void *video_data, const char *font_path, float font_size) + void *video_data, const char *font_path, + float font_size, bool is_threaded) { unsigned i; for (i = 0; caca_font_backends[i]; i++) { void *data = caca_font_backends[i]->init( - video_data, font_path, font_size); + video_data, font_path, font_size, + is_threaded); if (!data) continue; @@ -186,14 +192,16 @@ static const font_renderer_t *vga_font_backends[] = { static bool vga_font_init_first( const void **font_driver, void **font_handle, - void *video_data, const char *font_path, float font_size) + void *video_data, const char *font_path, + float font_size, bool is_threaded) { unsigned i; for (i = 0; vga_font_backends[i]; i++) { void *data = vga_font_backends[i]->init( - video_data, font_path, font_size); + video_data, font_path, font_size, + is_threaded); if (!data) continue; @@ -215,14 +223,16 @@ static const font_renderer_t *gdi_font_backends[] = { static bool gdi_font_init_first( const void **font_driver, void **font_handle, - void *video_data, const char *font_path, float font_size) + void *video_data, const char *font_path, + float font_size, bool is_threaded) { unsigned i; for (i = 0; gdi_font_backends[i]; i++) { void *data = gdi_font_backends[i]->init( - video_data, font_path, font_size); + video_data, font_path, font_size, + is_threaded); if (!data) continue; @@ -244,13 +254,16 @@ static const font_renderer_t *vulkan_font_backends[] = { static bool vulkan_font_init_first( const void **font_driver, void **font_handle, - void *video_data, const char *font_path, float font_size) + void *video_data, const char *font_path, + float font_size, bool is_threaded) { unsigned i; for (i = 0; vulkan_font_backends[i]; i++) { - void *data = vulkan_font_backends[i]->init(video_data, font_path, font_size); + void *data = vulkan_font_backends[i]->init(video_data, + font_path, font_size, + is_threaded); if (!data) continue; @@ -271,14 +284,16 @@ static const font_renderer_t *vita2d_font_backends[] = { static bool vita2d_font_init_first( const void **font_driver, void **font_handle, - void *video_data, const char *font_path, float font_size) + void *video_data, const char *font_path, + float font_size, bool is_threaded) { unsigned i; for (i = 0; vita2d_font_backends[i]; i++) { void *data = vita2d_font_backends[i]->init( - video_data, font_path, font_size); + video_data, font_path, font_size, + is_threaded); if (!data) continue; @@ -299,14 +314,16 @@ static const font_renderer_t *ctr_font_backends[] = { static bool ctr_font_init_first( const void **font_driver, void **font_handle, - void *video_data, const char *font_path, float font_size) + void *video_data, const char *font_path, + float font_size, bool is_threaded) { unsigned i; for (i = 0; ctr_font_backends[i]; i++) { void *data = ctr_font_backends[i]->init( - video_data, font_path, font_size); + video_data, font_path, font_size, + is_threaded); if (!data) continue; @@ -323,7 +340,7 @@ static bool ctr_font_init_first( static bool font_init_first( const void **font_driver, void **font_handle, void *video_data, const char *font_path, float font_size, - enum font_driver_render_api api) + enum font_driver_render_api api, bool is_threaded) { if (font_path && !font_path[0]) font_path = NULL; @@ -333,42 +350,42 @@ static bool font_init_first( #ifdef HAVE_D3D case FONT_DRIVER_RENDER_DIRECT3D_API: return d3d_font_init_first(font_driver, font_handle, - video_data, font_path, font_size); + video_data, font_path, font_size, is_threaded); #endif #ifdef HAVE_OPENGL case FONT_DRIVER_RENDER_OPENGL_API: return gl_font_init_first(font_driver, font_handle, - video_data, font_path, font_size); + video_data, font_path, font_size, is_threaded); #endif #ifdef HAVE_VULKAN case FONT_DRIVER_RENDER_VULKAN_API: return vulkan_font_init_first(font_driver, font_handle, - video_data, font_path, font_size); + video_data, font_path, font_size, is_threaded); #endif #ifdef HAVE_VITA2D case FONT_DRIVER_RENDER_VITA2D: return vita2d_font_init_first(font_driver, font_handle, - video_data, font_path, font_size); + video_data, font_path, font_size, is_threaded); #endif #ifdef _3DS case FONT_DRIVER_RENDER_CTR: return ctr_font_init_first(font_driver, font_handle, - video_data, font_path, font_size); + video_data, font_path, font_size, is_threaded); #endif #ifdef HAVE_CACA case FONT_DRIVER_RENDER_CACA: return caca_font_init_first(font_driver, font_handle, - video_data, font_path, font_size); + video_data, font_path, font_size, is_threaded); #endif #if defined(_WIN32) && !defined(_XBOX) case FONT_DRIVER_RENDER_GDI: return gdi_font_init_first(font_driver, font_handle, - video_data, font_path, font_size); + video_data, font_path, font_size, is_threaded); #endif #ifdef DJGPP case FONT_DRIVER_RENDER_VGA: return vga_font_init_first(font_driver, font_handle, - video_data, font_path, font_size); + video_data, font_path, font_size, is_threaded); #endif case FONT_DRIVER_RENDER_DONT_CARE: /* TODO/FIXME - lookup graphics driver's 'API' */ @@ -420,8 +437,13 @@ void font_driver_free(void *font_data) if (font) { + bool is_threaded = false; +#ifdef HAVE_THREADS + is_threaded = video_driver_is_threaded(); +#endif + if (font->renderer && font->renderer->free) - font->renderer->free(font->renderer_data); + font->renderer->free(font->renderer_data, is_threaded); font->renderer = NULL; font->renderer_data = NULL; @@ -434,20 +456,23 @@ font_data_t *font_driver_init_first( void *video_data, const char *font_path, float font_size, bool threading_hint, enum font_driver_render_api api) { - const void *font_driver; - void *font_handle; - bool ok = false; - + const void *font_driver = NULL; + void *font_handle = NULL; + bool ok = false; + bool is_threaded = false; #ifdef HAVE_THREADS - if (threading_hint - && video_driver_is_threaded() + is_threaded = video_driver_is_threaded(); + + if ( threading_hint + && is_threaded && !video_driver_is_hw_context()) ok = video_thread_font_init(&font_driver, &font_handle, - video_data, font_path, font_size, api, font_init_first); + video_data, font_path, font_size, api, font_init_first, + is_threaded); else #endif ok = font_init_first(&font_driver, &font_handle, - video_data, font_path, font_size, api); + video_data, font_path, font_size, api, is_threaded); if (ok) { diff --git a/gfx/font_driver.h b/gfx/font_driver.h index 86c6365176..39806f5831 100644 --- a/gfx/font_driver.h +++ b/gfx/font_driver.h @@ -101,8 +101,9 @@ struct font_params typedef struct font_renderer { - void *(*init)(void *data, const char *font_path, float font_size); - void (*free)(void *data); + void *(*init)(void *data, const char *font_path, + float font_size, bool is_threaded); + void (*free)(void *data, bool is_threaded); void (*render_msg)( video_frame_info_t *video_info, void *data, const char *msg, diff --git a/gfx/video_thread_wrapper.c b/gfx/video_thread_wrapper.c index ce76aa5fb5..f24134ccaf 100644 --- a/gfx/video_thread_wrapper.c +++ b/gfx/video_thread_wrapper.c @@ -142,6 +142,7 @@ struct thread_packet const char *font_path; float font_size; bool return_value; + bool is_threaded; enum font_driver_render_api api; } font_init; } data; @@ -544,7 +545,8 @@ static bool video_thread_handle_packet( pkt.data.font_init.video_data, pkt.data.font_init.font_path, pkt.data.font_init.font_size, - pkt.data.font_init.api); + pkt.data.font_init.api, + pkt.data.font_init.is_threaded); video_thread_reply(thr, &pkt); break; @@ -1417,7 +1419,8 @@ static void video_thread_send_and_wait(thread_video_t *thr, bool video_thread_font_init(const void **font_driver, void **font_handle, void *data, const char *font_path, float font_size, - enum font_driver_render_api api, custom_font_command_method_t func) + enum font_driver_render_api api, custom_font_command_method_t func, + bool is_threaded) { thread_packet_t pkt; thread_video_t *thr = (thread_video_t*)video_driver_get_ptr(true); @@ -1432,6 +1435,7 @@ bool video_thread_font_init(const void **font_driver, void **font_handle, pkt.data.font_init.video_data = data; pkt.data.font_init.font_path = font_path; pkt.data.font_init.font_size = font_size; + pkt.data.font_init.is_threaded = is_threaded; pkt.data.font_init.api = api; video_thread_send_and_wait(thr, &pkt); diff --git a/gfx/video_thread_wrapper.h b/gfx/video_thread_wrapper.h index 5368edabd7..31c2010cff 100644 --- a/gfx/video_thread_wrapper.h +++ b/gfx/video_thread_wrapper.h @@ -31,7 +31,8 @@ typedef int (*custom_command_method_t)(void*); typedef bool (*custom_font_command_method_t)(const void **font_driver, void **font_handle, void *video_data, const char *font_path, - float font_size, enum font_driver_render_api api); + float font_size, enum font_driver_render_api api, + bool is_threaded); typedef struct thread_packet thread_packet_t; @@ -79,7 +80,8 @@ bool video_thread_font_init( const char *font_path, float font_size, enum font_driver_render_api api, - custom_font_command_method_t func); + custom_font_command_method_t func, + bool is_threaded); unsigned video_thread_texture_load(void *data, custom_command_method_t func);