(font) Create font_data_t and update font_driver_init_first()

This commit is contained in:
Higor Eurípedes 2016-10-18 20:07:00 -03:00
parent 20716633fa
commit 6f2cb9742d
13 changed files with 109 additions and 87 deletions

View File

@ -433,13 +433,7 @@ static void* ctr_init(const video_info_t* video,
driver_ctl(RARCH_DRIVER_CTL_SET_REFRESH_RATE, &refresh_rate);
aptHook(&ctr->lcd_aptHook, ctr_lcd_aptHook, ctr);
if (!font_driver_init_first(NULL, NULL, ctr, *settings->path.font
? settings->path.font : NULL, settings->video.font_size, false,
FONT_DRIVER_RENDER_CTR))
{
RARCH_ERR("Font: Failed to initialize font renderer.\n");
return false;
}
font_driver_init_osd(ctr, false, FONT_DRIVER_RENDER_CTR);
ctr->msg_rendering_enabled = false;
ctr->menu_texture_frame_enable = false;

View File

@ -815,13 +815,7 @@ static bool d3d_initialize(d3d_video_t *d3d, const video_info_t *info)
strlcpy(settings->path.font, "game:\\media\\Arial_12.xpr",
sizeof(settings->path.font));
#endif
if (!font_driver_init_first(NULL, NULL,
d3d, settings->path.font, 0, false,
FONT_DRIVER_RENDER_DIRECT3D_API))
{
RARCH_ERR("[D3D]: Failed to initialize font renderer.\n");
return false;
}
font_driver_init_osd(d3d, false, FONT_DRIVER_RENDER_DIRECT3D_API);
return true;
}

View File

@ -1412,8 +1412,7 @@ static void gl_free(void *data)
}
#endif
if (font_driver_has_render_msg())
font_driver_free(NULL);
font_driver_free_osd();
video_shader_driver_deinit();
#ifndef NO_GL_FF_VERTEX
@ -2083,12 +2082,7 @@ static void *gl_init(const video_info_t *video, const input_driver_t **input, vo
video_context_driver_input_driver(&inp);
if (settings->video.font_enable)
{
if (!font_driver_init_first(NULL, NULL, gl, *settings->path.font
? settings->path.font : NULL, settings->video.font_size, false,
FONT_DRIVER_RENDER_OPENGL_API))
RARCH_ERR("[GL]: Failed to initialize font renderer.\n");
}
font_driver_init_osd(gl, false, FONT_DRIVER_RENDER_OPENGL_API);
#ifdef HAVE_GL_ASYNC_READBACK
gl_init_pbo_readback(gl);

View File

@ -102,13 +102,8 @@ static void *vita2d_gfx_init(const video_info_t *video,
#ifdef HAVE_OVERLAY
vita->overlay_enable = false;
#endif
if (!font_driver_init_first(NULL, NULL, vita, *settings->path.font
? settings->path.font : NULL, settings->video.font_size, false,
FONT_DRIVER_RENDER_VITA2D))
{
RARCH_ERR("Font: Failed to initialize font renderer.\n");
return false;
}
font_driver_init_osd(vita, false, FONT_DRIVER_RENDER_VITA2D);
return vita;
}

View File

@ -1113,12 +1113,7 @@ static void *vulkan_init(const video_info_t *video,
video_context_driver_input_driver(&inp);
if (settings->video.font_enable)
{
if (!font_driver_init_first(NULL, NULL, vk, *settings->path.font
? settings->path.font : NULL, settings->video.font_size, false,
FONT_DRIVER_RENDER_VULKAN_API))
RARCH_ERR("[Vulkan]: Failed to initialize font renderer.\n");
}
font_driver_init_osd(vk, false, FONT_DRIVER_RENDER_VULKAN_API);
vulkan_init_readback(vk);
return vk;

View File

@ -681,7 +681,7 @@ static bool gfx_ctx_x_set_video_mode(void *data,
#ifdef HAVE_VULKAN
{
bool quit, resize;
unsigned width, height;
unsigned width = 0, height = 0;
x11_check_window(x, &quit, &resize, &width, &height, 0);
/* Use XCB surface since it's the most supported WSI.

View File

@ -24,6 +24,8 @@
#include "../config.h"
#endif
#include <stdlib.h>
static const font_renderer_driver_t *font_backends[] = {
#ifdef HAVE_FREETYPE
&freetype_font_renderer,
@ -38,9 +40,7 @@ static const font_renderer_driver_t *font_backends[] = {
NULL
};
static const struct font_renderer *font_osd_driver;
static void *font_osd_data;
static void *g_osd_font;
int font_renderer_create_default(const void **data, void **handle,
const char *font_path, unsigned font_size)
@ -276,77 +276,106 @@ static bool font_init_first(
bool font_driver_has_render_msg(void)
{
if (!font_osd_driver || !font_osd_driver->render_msg)
return false;
return true;
}
void font_driver_render_msg(void *font_data,
const char *msg, const struct font_params *params)
{
if (font_osd_driver && font_osd_driver->render_msg)
font_osd_driver->render_msg(font_data
? font_data : font_osd_data, msg, params);
font_data_t *font = (font_data_t*)(font_data ? font_data : g_osd_font);
if (font && font->renderer->render_msg)
font->renderer->render_msg(font->renderer_data, msg, params);
}
void font_driver_bind_block(void *font_data, void *block)
{
void *new_font_data = font_data
? font_data : font_osd_data;
font_data_t *font = (font_data_t*)(font_data ? font_data : g_osd_font);
if (font_osd_driver && font_osd_driver->bind_block)
font_osd_driver->bind_block(new_font_data, block);
if (font->renderer && font->renderer->bind_block)
font->renderer->bind_block(font->renderer_data, block);
}
void font_driver_flush(void *data)
void font_driver_flush(void *font_data)
{
if (font_osd_driver && font_osd_driver->flush)
font_osd_driver->flush(data);
font_data_t *font = (font_data_t*)(font_data ? font_data : g_osd_font);
if (font->renderer && font->renderer->flush)
font->renderer->flush(font->renderer_data);
}
int font_driver_get_message_width(void *data,
int font_driver_get_message_width(void *font_data,
const char *msg, unsigned len, float scale)
{
if (!font_osd_driver || !font_osd_driver->get_message_width)
font_data_t *font = (font_data_t*)(font_data ? font_data : g_osd_font);
if (!font->renderer || !font->renderer->get_message_width)
return -1;
return font_osd_driver->get_message_width(data, msg, len, scale);
return font->renderer->get_message_width(font->renderer_data, msg, len, scale);
}
void font_driver_free(void *data)
void font_driver_free(void *font_data)
{
if (font_osd_driver && font_osd_driver->free)
font_osd_driver->free(data ? data : font_osd_data);
font_data_t *font = (font_data_t*)(font_data ? font_data : g_osd_font);
if (font->renderer && font->renderer->free)
font->renderer->free(font->renderer_data);
if (data)
if (font_data)
return;
font_osd_data = NULL;
font_osd_driver = NULL;
font->renderer = NULL;
font->renderer_data = NULL;
}
bool font_driver_init_first(
const void **font_driver, void **font_handle,
void *data, const char *font_path, float font_size,
bool threading_hint,
enum font_driver_render_api api)
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 **new_font_driver = font_driver ? font_driver
: (const void**)&font_osd_driver;
void **new_font_handle = font_handle ? font_handle
: (void**)&font_osd_data;
const void *font_driver;
void *font_handle;
bool ok = false;
#ifdef HAVE_THREADS
settings_t *settings = config_get_ptr();
if (threading_hint
&& settings->video.threaded
&& !video_driver_is_hw_context())
return video_thread_font_init(new_font_driver, new_font_handle,
data, font_path, font_size, api, font_init_first);
ok = video_thread_font_init(&font_driver, &font_handle,
video_data, font_path, font_size, api, font_init_first);
else
#endif
ok = font_init_first(&font_driver, &font_handle,
video_data, font_path, font_size, api);
return font_init_first(new_font_driver, new_font_handle,
data, font_path, font_size, api);
if (ok)
{
font_data_t *font = (font_data_t*)calloc(1, sizeof(*font));
font->renderer = (const font_renderer_t*)font_driver;
font->renderer_data = font_handle;
font->size = font_size;
return font;
}
return NULL;
}
void font_driver_init_osd(void *video_data, bool threading_hint, enum font_driver_render_api api)
{
if (!g_osd_font)
{
settings_t *settings = config_get_ptr();
g_osd_font = font_driver_init_first(video_data,
*settings->path.font ? settings->path.font : NULL,
settings->video.font_size, threading_hint, api);
if (!g_osd_font)
RARCH_ERR("[font]: Failed to initialize OSD font.\n");
}
}
void font_driver_free_osd(void)
{
if (g_osd_font)
font_driver_free(g_osd_font);
g_osd_font = NULL;
}

View File

@ -126,25 +126,34 @@ typedef struct font_renderer_driver
int (*get_line_height)(void* data);
} font_renderer_driver_t;
typedef struct
{
const font_renderer_t *renderer;
void *renderer_data;
float size;
} font_data_t;
/* font_path can be NULL for default font. */
int font_renderer_create_default(const void **driver,
void **handle, const char *font_path, unsigned font_size);
bool font_driver_has_render_msg(void);
void font_driver_render_msg(void *data, const char *msg, const struct font_params *params);
void font_driver_render_msg(void *font_data, const char *msg, const struct font_params *params);
void font_driver_bind_block(void *font_data, void *block);
int font_driver_get_message_width(void *data, const char *msg, unsigned len, float scale);
int font_driver_get_message_width(void *font_data, const char *msg, unsigned len, float scale);
void font_driver_flush(void *data);
void font_driver_flush(void *font_data);
void font_driver_free(void *data);
void font_driver_free(void *font_data);
bool font_driver_init_first(const void **font_driver, void **font_handle,
void *data, const char *font_path, float font_size,
bool threading_hint, enum font_driver_render_api api);
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);
void font_driver_init_osd(void *video_data, bool threading_hint, enum font_driver_render_api api);
void font_driver_free_osd(void);
extern font_renderer_t gl_raster_font;
extern font_renderer_t libdbg_font;

View File

@ -175,8 +175,10 @@ static bool menu_display_ctr_font_init_first(
void **font_handle, void *video_data,
const char *font_path, float font_size)
{
return font_driver_init_first(NULL, font_handle, video_data,
font_data_t **handle = (font_data_t**)font_handle;
*handle = font_driver_init_first(video_data,
font_path, font_size, true, FONT_DRIVER_RENDER_CTR);
return *handle;
}
menu_display_ctx_driver_t menu_display_ctx_ctr = {

View File

@ -253,8 +253,10 @@ static bool menu_display_d3d_font_init_first(
void **font_handle, void *video_data,
const char *font_path, float font_size)
{
return font_driver_init_first(NULL, font_handle, video_data,
font_data_t **handle = (font_data_t**)font_handle;
*handle = font_driver_init_first(video_data,
font_path, font_size, true, FONT_DRIVER_RENDER_DIRECT3D_API);
return *handle;
}
menu_display_ctx_driver_t menu_display_ctx_d3d = {

View File

@ -217,8 +217,11 @@ static bool menu_display_gl_font_init_first(
void **font_handle, void *video_data,
const char *font_path, float font_size)
{
return font_driver_init_first(NULL, font_handle, video_data,
font_data_t **handle = (font_data_t**)font_handle;
*handle = font_driver_init_first(video_data,
font_path, font_size, true, FONT_DRIVER_RENDER_OPENGL_API);
return *handle;
}
menu_display_ctx_driver_t menu_display_ctx_gl = {

View File

@ -229,8 +229,10 @@ static bool menu_display_vita2d_font_init_first(
void **font_handle, void *video_data,
const char *font_path, float font_size)
{
return font_driver_init_first(NULL, font_handle, video_data,
font_data_t **handle = (font_data_t**)font_handle;
*handle = font_driver_init_first(video_data,
font_path, font_size, true, FONT_DRIVER_RENDER_VITA2D);
return *handle;
}
menu_display_ctx_driver_t menu_display_ctx_vita2d = {

View File

@ -255,8 +255,11 @@ static bool menu_display_vk_font_init_first(
void **font_handle, void *video_data, const char *font_path,
float font_size)
{
return font_driver_init_first(NULL, font_handle, video_data,
font_data_t **handle = (font_data_t**)font_handle;
*handle = font_driver_init_first(video_data,
font_path, font_size, true, FONT_DRIVER_RENDER_VULKAN_API);
return *handle;
}
menu_display_ctx_driver_t menu_display_ctx_vulkan = {