Pass video_driver_is_threaded return value to font driver init/free

functions
This commit is contained in:
twinaphex 2017-01-25 14:47:24 +01:00
parent 631ee03df4
commit affb259409
15 changed files with 128 additions and 79 deletions

View File

@ -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,

View File

@ -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;

View File

@ -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;

View File

@ -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,

View File

@ -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);

View File

@ -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();

View File

@ -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,

View File

@ -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)

View File

@ -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)

View File

@ -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;

View File

@ -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();

View File

@ -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)
{

View File

@ -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,

View File

@ -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);

View File

@ -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);