diff --git a/gfx/font_driver.c b/gfx/font_driver.c index b23ff556ae..f2771e5228 100644 --- a/gfx/font_driver.c +++ b/gfx/font_driver.c @@ -313,15 +313,18 @@ int font_driver_get_message_width(void *font_data, void font_driver_free(void *font_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); + font_data_t *font = (font_data_t*)font_data; - if (font_data) - return; + if (font) + { + if (font->renderer && font->renderer->free) + font->renderer->free(font->renderer_data); - font->renderer = NULL; - font->renderer_data = NULL; + font->renderer = NULL; + font->renderer_data = NULL; + + free(font); + } } font_data_t *font_driver_init_first( diff --git a/menu/drivers/materialui.c b/menu/drivers/materialui.c index 9298735e05..d4593ad911 100644 --- a/menu/drivers/materialui.c +++ b/menu/drivers/materialui.c @@ -118,6 +118,7 @@ typedef struct mui_handle size_t selection_ptr; } categories; + font_data_t *font; video_font_raster_block_t list_block; float scroll_y; } mui_handle_t; @@ -250,16 +251,13 @@ static void mui_draw_tab(mui_handle_t *mui, &tab_color[0]); } -static void mui_draw_text(float x, float y, unsigned width, unsigned height, +static void mui_draw_text(font_data_t *font, float x, float y, unsigned width, unsigned height, const char *msg, uint32_t color, enum text_alignment text_align) { - int font_size; struct font_params params; - font_size = menu_display_get_font_size(); - params.x = x / width; - params.y = 1.0f - (y + font_size / 3) / height; + params.y = 1.0f - (y + font->size / 3) / height; params.scale = 1.0f; params.drop_mod = 0.0f; params.drop_x = 0.0f; @@ -268,7 +266,7 @@ static void mui_draw_text(float x, float y, unsigned width, unsigned height, params.full_screen = true; params.text_align = text_align; - menu_display_draw_text(msg, width, height, ¶ms); + menu_display_draw_text(font, msg, width, height, ¶ms); } static void mui_render_quad(mui_handle_t *mui, @@ -402,13 +400,11 @@ static void mui_render_messagebox(mui_handle_t *mui, video_driver_get_size(&width, &height); - line_height = menu_display_get_font_size() * 1.2; + line_height = mui->font->size * 1.2; x = width / 2; y = height / 2 - (list->size-1) * line_height / 2; - fb_buf = menu_display_get_font_buffer(); - /* find the longest line width */ for (i = 0; i < list->size; i++) { @@ -417,7 +413,7 @@ static void mui_render_messagebox(mui_handle_t *mui, if (len > longest) { longest = len; - longest_width = font_driver_get_message_width(fb_buf, msg, len, 1); + longest_width = font_driver_get_message_width(mui->font, msg, len, 1); } } @@ -437,7 +433,7 @@ static void mui_render_messagebox(mui_handle_t *mui, { const char *msg = list->elems[i].data; if (msg) - mui_draw_text(x - longest_width/2.0, y + i * line_height, + mui_draw_text(mui->font, x - longest_width/2.0, y + i * line_height, width, height, msg, font_color, TEXT_ALIGN_LEFT); } @@ -564,7 +560,7 @@ static void mui_render_label_value(mui_handle_t *mui, menu_animation_ctl(MENU_ANIMATION_CTL_TICKER, &ticker); - mui_draw_text(mui->margin, y + mui->line_height / 2, + mui_draw_text(mui->font, mui->margin, y + mui->line_height / 2, width, height, label_str, color, TEXT_ALIGN_LEFT); if (string_is_equal(value, "disabled") || string_is_equal(value, "off")) @@ -623,7 +619,7 @@ static void mui_render_label_value(mui_handle_t *mui, } if (do_draw_text) - mui_draw_text(width - mui->margin, + mui_draw_text(mui->font, width - mui->margin, y + mui->line_height / 2, width, height, value_str, color, TEXT_ALIGN_RIGHT); @@ -1114,7 +1110,7 @@ static void mui_frame(void *data) &highlighted_entry_color[0] ); - menu_display_font_bind_block(&mui->list_block); + menu_display_font_bind_block(mui->font, &mui->list_block); mui_render_menu_list( mui, @@ -1125,7 +1121,7 @@ static void mui_frame(void *data) &active_tab_marker_color[0] ); - menu_display_font_flush_block(); + menu_display_font_flush_block(mui->font); menu_animation_ctl(MENU_ANIMATION_CTL_SET_ACTIVE, NULL); /* header */ @@ -1216,7 +1212,7 @@ static void mui_frame(void *data) strlcpy(title_buf, title_buf_msg_tmp, sizeof(title_buf)); } - mui_draw_text(title_margin, header_height / 2, width, height, + mui_draw_text(mui->font, title_margin, header_height / 2, width, height, title_buf, font_header_color, TEXT_ALIGN_LEFT); mui_draw_scrollbar(mui, width, height, &grey_bg[0]); @@ -1279,19 +1275,17 @@ static void mui_layout(mui_handle_t *mui) mui->icon_size = scale_factor / 3; menu_display_set_header_height(new_header_height); - menu_display_set_font_size(new_font_size); /* we assume the average glyph aspect ratio is close to 3:4 */ mui->glyph_width = new_font_size * 3/4; - menu_display_font(APPLICATION_SPECIAL_DIRECTORY_ASSETS_MATERIALUI_FONT); + mui->font = menu_display_font(APPLICATION_SPECIAL_DIRECTORY_ASSETS_MATERIALUI_FONT, + new_font_size); - fb_buf = menu_display_get_font_buffer(); - - if (fb_buf) /* calculate a more realistic ticker_limit */ + if (mui->font) /* calculate a more realistic ticker_limit */ { unsigned m_width = - font_driver_get_message_width(fb_buf, "a", 1, 1); + font_driver_get_message_width(mui->font, "a", 1, 1); if (m_width) mui->glyph_width = m_width; @@ -1317,9 +1311,6 @@ static void *mui_init(void **userdata) *userdata = mui; - mui_layout(mui); - menu_display_allocate_white_texture(); - mui->cursor.size = 64.0; return menu; @@ -1361,7 +1352,7 @@ static void mui_context_destroy(void *data) for (i = 0; i < MUI_TEXTURE_LAST; i++) video_driver_texture_unload(&mui->textures.list[i]); - menu_display_font_main_deinit(); + menu_display_font_free(mui->font); mui_context_bg_destroy(mui); } diff --git a/menu/drivers/xmb.c b/menu/drivers/xmb.c index 8eac35495f..5acd331c65 100644 --- a/menu/drivers/xmb.c +++ b/menu/drivers/xmb.c @@ -277,6 +277,8 @@ typedef struct xmb_handle xmb_node_t history_tab_node; xmb_node_t add_tab_node; + font_data_t *font; + float font_size; video_font_raster_block_t raster_block; unsigned tabs[8]; @@ -666,7 +668,7 @@ static void xmb_draw_text(xmb_handle_t *xmb, params.drop_alpha = 0.35f; } - menu_display_draw_text(str, width, height, ¶ms); + menu_display_draw_text(xmb->font, str, width, height, ¶ms); } static void xmb_messagebox(void *data, const char *message) @@ -682,7 +684,7 @@ static void xmb_messagebox(void *data, const char *message) static void xmb_render_messagebox_internal( xmb_handle_t *xmb, const char *message) { - int x, y, font_size, longest = 0, longest_width = 0; + int x, y, longest = 0, longest_width = 0; unsigned i; unsigned width, height; struct string_list *list = NULL; @@ -700,12 +702,8 @@ static void xmb_render_messagebox_internal( if (list->elems == 0) goto end; - font_size = menu_display_get_font_size(); - x = width / 2; - y = height / 2 - (list->size-1) * font_size / 2; - - fb_buf = menu_display_get_font_buffer(); + y = height / 2 - (list->size-1) * xmb->font->size / 2; /* find the longest line width */ for (i = 0; i < list->size; i++) @@ -715,7 +713,7 @@ static void xmb_render_messagebox_internal( if (len > longest) { longest = len; - longest_width = font_driver_get_message_width(fb_buf, msg, len, 1); + longest_width = font_driver_get_message_width(xmb->font, msg, len, 1); } } @@ -727,7 +725,7 @@ static void xmb_render_messagebox_internal( xmb_draw_text( xmb, msg, x - longest_width/2.0, - y + i * font_size, + y + i * xmb->font->size, 1, 1, TEXT_ALIGN_LEFT, @@ -2212,7 +2210,7 @@ static void xmb_frame(void *data) video_driver_get_size(&width, &height); - menu_display_font_bind_block(&xmb->raster_block); + menu_display_font_bind_block(xmb->font, &xmb->raster_block); xmb->raster_block.carr.coords.vertices = 0; @@ -2409,7 +2407,7 @@ static void xmb_frame(void *data) width, height); - menu_display_font_flush_block(); + menu_display_font_flush_block(xmb->font); if (menu_input_dialog_get_display_kb()) { @@ -2492,8 +2490,8 @@ static void xmb_layout_ps3(xmb_handle_t *xmb, int width) xmb->margins.label.top = new_font_size / 3.0; xmb->margins.setting.left = 600.0 * scale_factor; xmb->icon.size = 128.0 * scale_factor; + xmb->font_size = new_font_size; - menu_display_set_font_size(new_font_size); menu_display_set_header_height(new_header_height); } @@ -2543,8 +2541,8 @@ static void xmb_layout_psp(xmb_handle_t *xmb, int width) xmb->margins.label.top = new_font_size / 3.0; xmb->margins.setting.left = 600.0 * scale_factor; xmb->icon.size = 128.0 * scale_factor; + xmb->font_size = new_font_size; - menu_display_set_font_size(new_font_size); menu_display_set_header_height(new_header_height); } @@ -2732,7 +2730,8 @@ static void *xmb_init(void **userdata) menu_display_allocate_white_texture(); xmb_init_horizontal_list(xmb); - menu_display_font(APPLICATION_SPECIAL_DIRECTORY_ASSETS_XMB_FONT); + /* FIXME: remove this? */ + xmb->font = menu_display_font(APPLICATION_SPECIAL_DIRECTORY_ASSETS_XMB_FONT, xmb->font_size); xmb_init_ribbon(xmb); return menu; @@ -2996,7 +2995,7 @@ static void xmb_context_reset(void *data) APPLICATION_SPECIAL_DIRECTORY_ASSETS_XMB_ICONS); xmb_layout(xmb); - menu_display_font(APPLICATION_SPECIAL_DIRECTORY_ASSETS_XMB_FONT); + xmb->font = menu_display_font(APPLICATION_SPECIAL_DIRECTORY_ASSETS_XMB_FONT, xmb->font_size); xmb_context_reset_textures(xmb, iconpath); xmb_context_reset_background(iconpath); xmb_context_reset_horizontal_list(xmb); @@ -3289,7 +3288,7 @@ static void xmb_context_destroy(void *data) xmb_context_destroy_horizontal_list(xmb); xmb_context_bg_destroy(xmb); - menu_display_font_main_deinit(); + menu_display_font_free(xmb->font); } static void xmb_toggle(void *userdata, bool menu_on) diff --git a/menu/menu_display.c b/menu/menu_display.c index e9042cc318..bf7df2d5ce 100644 --- a/menu/menu_display.c +++ b/menu/menu_display.c @@ -163,13 +163,11 @@ static video_coord_array_t menu_disp_ca; static unsigned menu_display_framebuf_width = 0; static unsigned menu_display_framebuf_height = 0; static size_t menu_display_framebuf_pitch = 0; -static int menu_display_font_size = 0; static unsigned menu_display_header_height = 0; static bool menu_display_msg_force = false; static bool menu_display_font_alloc_framebuf = false; static bool menu_display_framebuf_dirty = false; static const uint8_t *menu_display_font_framebuf = NULL; -static void *menu_display_font_buf = NULL; static msg_queue_t *menu_display_msg_queue = NULL; static menu_display_ctx_driver_t *menu_disp = NULL; @@ -187,64 +185,47 @@ void menu_display_blend_end(void) menu_disp->blend_end(); } -void menu_display_font_main_deinit(void) +void menu_display_font_free(font_data_t *font) { - if (menu_display_font_buf) - font_driver_free(menu_display_font_buf); - menu_display_font_buf = NULL; - menu_display_font_size = 0; + font_driver_free(font); } -bool menu_display_font(enum application_special_type type) +font_data_t *menu_display_font(enum application_special_type type, float font_size) { menu_display_ctx_font_t font_info; char fontpath[PATH_MAX_LENGTH] = {0}; - int font_size = menu_display_get_font_size(); fill_pathname_application_special(fontpath, sizeof(fontpath), type); font_info.path = fontpath; font_info.size = font_size; - if (!menu_display_font_main_init(&font_info)) - { - RARCH_WARN("Failed to load font."); - return false; - } - - return true; + return menu_display_font_main_init(&font_info); } -bool menu_display_font_main_init(menu_display_ctx_font_t *font) +font_data_t *menu_display_font_main_init(menu_display_ctx_font_t *font) { - menu_display_font_main_deinit(); + font_data_t *font_data = NULL; + if (!font || !menu_disp) return false; - if (!menu_disp->font_init_first) - return false; - - if (!menu_disp->font_init_first(&menu_display_font_buf, + if (menu_disp->font_init_first((void**)&font_data, video_driver_get_ptr(false), font->path, font->size)) - return false; - - menu_display_font_size = font->size; - return true; + return font_data; + return NULL; } -void menu_display_font_bind_block(void *block) +void menu_display_font_bind_block(font_data_t *font, void *block) { - font_driver_bind_block(menu_display_font_buf, block); + font_driver_bind_block(font, block); } -bool menu_display_font_flush_block(void) +bool menu_display_font_flush_block(font_data_t *font) { - if (!menu_display_font_buf) - return false; - - font_driver_flush(menu_display_font_buf); - font_driver_bind_block(menu_display_font_buf, NULL); + font_driver_flush(font); + font_driver_bind_block(font, NULL); return true; } @@ -286,16 +267,6 @@ video_coord_array_t *menu_display_get_coords_array(void) return &menu_disp_ca; } -void *menu_display_get_font_buffer(void) -{ - return menu_display_font_buf; -} - -void menu_display_set_font_buffer(void *buffer) -{ - menu_display_font_buf = buffer; -} - const uint8_t *menu_display_get_font_framebuffer(void) { return menu_display_font_framebuf; @@ -366,16 +337,6 @@ unsigned menu_display_get_header_height(void) return menu_display_header_height; } -unsigned menu_display_get_font_size(void) -{ - return menu_display_font_size; -} - -void menu_display_set_font_size(unsigned size) -{ - menu_display_font_size = size; -} - size_t menu_display_get_framebuffer_pitch(void) { return menu_display_framebuf_pitch; @@ -827,11 +788,10 @@ void menu_display_snow(int width, int height) } } -void menu_display_draw_text(const char *msg, +void menu_display_draw_text(const font_data_t *font, const char *msg, int width, int height, struct font_params *params) { - void *fb_buf = menu_display_get_font_buffer(); - video_driver_set_osd_msg(msg, params, fb_buf); + video_driver_set_osd_msg(msg, params, (void*)font); } void menu_display_set_alpha(float *color, float alpha_value) diff --git a/menu/menu_display.h b/menu/menu_display.h index 23b3d2fb0e..526a5872a4 100644 --- a/menu/menu_display.h +++ b/menu/menu_display.h @@ -181,10 +181,10 @@ void menu_display_toggle_set_reason(enum menu_toggle_reason reason); void menu_display_blend_begin(void); void menu_display_blend_end(void); -void menu_display_font_main_deinit(void); -bool menu_display_font_main_init(menu_display_ctx_font_t *font); -void menu_display_font_bind_block(void *block); -bool menu_display_font_flush_block(void); +void menu_display_font_free(font_data_t *font); +font_data_t *menu_display_font_main_init(menu_display_ctx_font_t *font); +void menu_display_font_bind_block(font_data_t *font, void *block); +bool menu_display_font_flush_block(font_data_t *font); void menu_display_framebuffer_deinit(void); @@ -193,8 +193,6 @@ bool menu_display_init(void); void menu_display_coords_array_reset(void); video_coord_array_t *menu_display_get_coords_array(void); -void *menu_display_get_font_buffer(void); -void menu_display_set_font_buffer(void *buffer); const uint8_t *menu_display_get_font_framebuffer(void); void menu_display_set_font_framebuffer(const uint8_t *buffer); bool menu_display_libretro_running(void); @@ -206,8 +204,6 @@ void menu_display_set_height(unsigned height); unsigned menu_display_get_height(void); void menu_display_set_header_height(unsigned height); unsigned menu_display_get_header_height(void); -unsigned menu_display_get_font_size(void); -void menu_display_set_font_size(unsigned size); size_t menu_display_get_framebuffer_pitch(void); void menu_display_set_framebuffer_pitch(size_t pitch); @@ -254,14 +250,14 @@ void menu_display_draw_cursor( float *color, float cursor_size, uintptr_t texture, float x, float y, unsigned width, unsigned height); -void menu_display_draw_text(const char *msg, int width, int height, +void menu_display_draw_text(const font_data_t *font, const char *msg, int width, int height, struct font_params *params); bool menu_display_shader_pipeline_active(void); void menu_display_set_alpha(float *color, float alpha_value); -bool menu_display_font(enum application_special_type type); +font_data_t *menu_display_font(enum application_special_type type, float font_size); void menu_display_reset_textures_list(const char *texture_path, const char *iconpath, uintptr_t *item);