Get rid of some code duplication in MaterialUI/Ozone

This commit is contained in:
libretroadmin 2023-06-16 00:48:16 +02:00
parent 8ea67c0d99
commit bc1672708d
4 changed files with 94 additions and 127 deletions

View File

@ -793,6 +793,19 @@ void font_driver_bind_block(void *font_data, void *block)
font->renderer->bind_block(font->renderer_data, block);
}
/* Flushing is slow - only do it if font has actually been used */
void font_flush(
unsigned video_width,
unsigned video_height,
font_data_impl_t *font_data)
{
if (font_data->raster_block.carr.coords.vertices == 0)
return;
if (font_data->font && font_data->font->renderer && font_data->font->renderer->flush)
font_data->font->renderer->flush(video_width, video_height, font_data->font->renderer_data);
font_data->raster_block.carr.coords.vertices = 0;
}
int font_driver_get_message_width(void *font_data,
const char *msg, size_t len, float scale)
{

View File

@ -21,6 +21,7 @@
#include <boolean.h>
#include <retro_common_api.h>
#include <retro_inline.h>
#include "../retroarch.h"
@ -73,6 +74,32 @@ typedef struct
float size;
} font_data_t;
/* This structure holds all objects + metadata
* corresponding to a particular font */
typedef struct
{
font_data_t *font;
video_font_raster_block_t raster_block; /* ptr alignment */
unsigned glyph_width;
unsigned wideglyph_width;
int line_height;
int line_ascender;
int line_centre_offset;
} font_data_impl_t;
void font_driver_bind_block(void *font_data, void *block);
static void INLINE font_bind(font_data_impl_t *font_data)
{
font_driver_bind_block(font_data->font, &font_data->raster_block);
font_data->raster_block.carr.coords.vertices = 0;
}
static void INLINE font_unbind(font_data_impl_t *font_data)
{
font_driver_bind_block(font_data->font, NULL);
}
/* font_path can be NULL for default font. */
int font_renderer_create_default(
const font_renderer_driver_t **drv,
@ -82,12 +109,15 @@ int font_renderer_create_default(
void font_driver_render_msg(void *data,
const char *msg, const struct font_params *params, void *font_data);
void font_driver_bind_block(void *font_data, void *block);
int font_driver_get_message_width(void *font_data, const char *msg, size_t len, float scale);
void font_driver_free(font_data_t *font);
void font_flush(
unsigned video_width,
unsigned video_height,
font_data_impl_t *font_data);
font_data_t *font_driver_init_first(
void *video_data,
const char *font_path,

View File

@ -495,19 +495,6 @@ typedef struct
bool dragged;
} materialui_scrollbar_t;
/* This structure holds all objects + metadata
* corresponding to a particular font */
typedef struct
{
font_data_t *font;
video_font_raster_block_t raster_block; /* ptr alignment */
unsigned glyph_width;
unsigned wideglyph_width;
int line_height;
int line_ascender;
int line_centre_offset;
} materialui_font_data_t;
/* This structure is used to cache system bar
* string data (+ metadata) to improve rendering
* performance */
@ -597,9 +584,9 @@ typedef struct materialui_handle
/* Font data */
struct
{
materialui_font_data_t title; /* ptr alignment */
materialui_font_data_t list; /* ptr alignment */
materialui_font_data_t hint; /* ptr alignment */
font_data_impl_t title; /* ptr alignment */
font_data_impl_t list; /* ptr alignment */
font_data_impl_t hint; /* ptr alignment */
} font_data;
void (*word_wrap)(
@ -2193,30 +2180,6 @@ static const char *materialui_texture_path(unsigned id)
return NULL;
}
static void INLINE materialui_font_bind(materialui_font_data_t *font_data)
{
font_driver_bind_block(font_data->font, &font_data->raster_block);
font_data->raster_block.carr.coords.vertices = 0;
}
static void INLINE materialui_font_unbind(materialui_font_data_t *font_data)
{
font_driver_bind_block(font_data->font, NULL);
}
/* Flushing is slow - only do it if font
* has actually been used */
static void materialui_font_flush(
unsigned video_width, unsigned video_height,
materialui_font_data_t *font_data)
{
if (font_data->raster_block.carr.coords.vertices == 0)
return;
if (font_data->font && font_data->font->renderer && font_data->font->renderer->flush)
font_data->font->renderer->flush(video_width, video_height, font_data->font->renderer_data);
font_data->raster_block.carr.coords.vertices = 0;
}
/* ==============================
* Playlist icons START
* ============================== */
@ -3560,7 +3523,7 @@ static bool (*materialui_render_process_entry)(
static void materialui_init_font(
gfx_display_t *p_disp,
materialui_font_data_t *font_data,
font_data_impl_t *font_data,
int font_size,
bool video_is_threaded,
const char *str_latin);
@ -5119,7 +5082,7 @@ static void materialui_render_selected_entry_aux_playlist_desktop(
/* Status bar overlaps list entries
* > Must flush list font before attempting
* to draw it */
materialui_font_flush(video_width, video_height, &mui->font_data.list);
font_flush(video_width, video_height, &mui->font_data.list);
/* Background
* > Surface */
@ -7070,9 +7033,9 @@ static void materialui_frame(void *data, video_frame_info_t *video_info)
video_st->data, video_width, video_height, true, false);
/* Clear text */
materialui_font_bind(&mui->font_data.title);
materialui_font_bind(&mui->font_data.list);
materialui_font_bind(&mui->font_data.hint);
font_bind(&mui->font_data.title);
font_bind(&mui->font_data.list);
font_bind(&mui->font_data.hint);
/* Update theme colours, if required */
if (mui->color_theme != materialui_color_theme)
@ -7163,8 +7126,8 @@ static void materialui_frame(void *data, video_frame_info_t *video_info)
/* Flush first layer of text
* > Menu list only uses list and hint fonts */
materialui_font_flush(video_width, video_height, &mui->font_data.list);
materialui_font_flush(video_width, video_height, &mui->font_data.hint);
font_flush(video_width, video_height, &mui->font_data.list);
font_flush(video_width, video_height, &mui->font_data.hint);
/* Draw fullscreen thumbnails, if currently active
* > Must be done *after* we flush the first layer
@ -7183,10 +7146,8 @@ static void materialui_frame(void *data, video_frame_info_t *video_info)
/* Flush second layer of text
* > Title + system bar only use title and hint fonts */
materialui_font_flush(video_width,
video_height, &mui->font_data.title);
materialui_font_flush(video_width,
video_height, &mui->font_data.hint);
font_flush(video_width, video_height, &mui->font_data.title);
font_flush(video_width, video_height, &mui->font_data.hint);
/* Handle onscreen keyboard */
if (menu_input_dialog_get_display_kb())
@ -7238,7 +7199,7 @@ static void materialui_frame(void *data, video_frame_info_t *video_info)
/* Flush message box & osk text
* > Message box & osk only use list font */
materialui_font_flush(video_width, video_height, &mui->font_data.list);
font_flush(video_width, video_height, &mui->font_data.list);
}
/* Draw message box */
@ -7267,7 +7228,7 @@ static void materialui_frame(void *data, video_frame_info_t *video_info)
/* Flush message box text
* > Message box only uses list font */
materialui_font_flush(video_width, video_height, &mui->font_data.list);
font_flush(video_width, video_height, &mui->font_data.list);
}
/* Draw mouse cursor */
@ -7304,9 +7265,9 @@ static void materialui_frame(void *data, video_frame_info_t *video_info)
materialui_colors_reset_transition_alpha(mui);
/* Unbind fonts */
materialui_font_unbind(&mui->font_data.title);
materialui_font_unbind(&mui->font_data.list);
materialui_font_unbind(&mui->font_data.hint);
font_unbind(&mui->font_data.title);
font_unbind(&mui->font_data.list);
font_unbind(&mui->font_data.hint);
if (video_st->current_video && video_st->current_video->set_viewport)
video_st->current_video->set_viewport(
@ -7886,7 +7847,7 @@ static void materialui_update_list_view(materialui_handle_t *mui, settings_t *se
static void materialui_init_font(
gfx_display_t *p_disp,
materialui_font_data_t *font_data,
font_data_impl_t *font_data,
int font_size,
bool video_is_threaded,
const char *str_latin

View File

@ -333,19 +333,6 @@ enum ozone_pending_thumbnail_type
OZONE_PENDING_THUMBNAIL_BOTH
};
/* This structure holds all objects + metadata
* corresponding to a particular font */
typedef struct
{
font_data_t *font;
video_font_raster_block_t raster_block; /* ptr alignment */
unsigned glyph_width;
unsigned wideglyph_width;
int line_height;
int line_ascender;
int line_centre_offset;
} ozone_font_data_t;
/* Container for a footer text label */
typedef struct
{
@ -474,12 +461,12 @@ struct ozone_handle
struct
{
ozone_font_data_t footer;
ozone_font_data_t title;
ozone_font_data_t time;
ozone_font_data_t entries_label;
ozone_font_data_t entries_sublabel;
ozone_font_data_t sidebar;
font_data_impl_t footer;
font_data_impl_t title;
font_data_impl_t time;
font_data_impl_t entries_label;
font_data_impl_t entries_sublabel;
font_data_impl_t sidebar;
} fonts;
void (*word_wrap)(
@ -2836,19 +2823,6 @@ static float ozone_sidebar_get_scroll_y(
return scroll_y;
}
/* Flushing is slow - only do it if font has actually been used */
static void ozone_font_flush(
unsigned video_width,
unsigned video_height,
ozone_font_data_t *font_data)
{
if (font_data->raster_block.carr.coords.vertices == 0)
return;
if (font_data->font && font_data->font->renderer && font_data->font->renderer->flush)
font_data->font->renderer->flush(video_width, video_height, font_data->font->renderer_data);
font_data->raster_block.carr.coords.vertices = 0;
}
static void ozone_draw_icon(
gfx_display_t *p_disp,
void *userdata,
@ -3573,7 +3547,7 @@ console_iterate:
dispctx->blend_end(userdata);
}
ozone_font_flush(video_width, video_height, &ozone->fonts.sidebar);
font_flush(video_width, video_height, &ozone->fonts.sidebar);
if (dispctx && dispctx->scissor_end)
dispctx->scissor_end(userdata, video_width, video_height);
@ -6068,10 +6042,10 @@ border_iterate:
}
/* Text layer */
ozone_font_flush(video_width, video_height, &ozone->fonts.entries_label);
font_flush(video_width, video_height, &ozone->fonts.entries_label);
if (menu_show_sublabels)
ozone_font_flush(video_width, video_height, &ozone->fonts.entries_sublabel);
font_flush(video_width, video_height, &ozone->fonts.entries_sublabel);
}
static void ozone_draw_thumbnail_bar(
@ -8946,7 +8920,7 @@ static void ozone_refresh_thumbnail_image(void *data, unsigned i)
}
static bool ozone_init_font(
ozone_font_data_t *font_data,
font_data_impl_t *font_data,
bool is_threaded,
char *font_path,
float font_size)
@ -9365,7 +9339,7 @@ static void ozone_unload_thumbnail_textures(void *data)
gfx_thumbnail_reset(&ozone->thumbnails.savestate);
}
static void INLINE ozone_font_free(ozone_font_data_t *font_data)
static void INLINE ozone_font_free(font_data_impl_t *font_data)
{
if (font_data->font)
font_driver_free(font_data->font);
@ -11335,17 +11309,6 @@ static void ozone_messagebox_fadeout_cb(void *userdata)
ozone->flags &= ~OZONE_FLAG_SHOULD_DRAW_MSGBOX;
}
static void INLINE ozone_font_bind(ozone_font_data_t *font_data)
{
font_driver_bind_block(font_data->font, &font_data->raster_block);
font_data->raster_block.carr.coords.vertices = 0;
}
static void INLINE ozone_font_unbind(ozone_font_data_t *font_data)
{
font_driver_bind_block(font_data->font, NULL);
}
static void ozone_frame(void *data, video_frame_info_t *video_info)
{
math_matrix_4x4 mymat;
@ -11484,12 +11447,12 @@ static void ozone_frame(void *data, video_frame_info_t *video_info)
video_st->data, video_width, video_height, true, false);
/* Clear text */
ozone_font_bind(&ozone->fonts.footer);
ozone_font_bind(&ozone->fonts.title);
ozone_font_bind(&ozone->fonts.time);
ozone_font_bind(&ozone->fonts.entries_label);
ozone_font_bind(&ozone->fonts.entries_sublabel);
ozone_font_bind(&ozone->fonts.sidebar);
font_bind(&ozone->fonts.footer);
font_bind(&ozone->fonts.title);
font_bind(&ozone->fonts.time);
font_bind(&ozone->fonts.entries_label);
font_bind(&ozone->fonts.entries_sublabel);
font_bind(&ozone->fonts.sidebar);
/* Background (Always use running background due to overlays) */
if (menu_framebuffer_opacity < 1.0f)
@ -11624,12 +11587,12 @@ static void ozone_frame(void *data, video_frame_info_t *video_info)
dispctx->scissor_end(userdata, video_width, video_height);
/* Flush first layer of text */
ozone_font_flush(video_width, video_height, &ozone->fonts.footer);
ozone_font_flush(video_width, video_height, &ozone->fonts.title);
ozone_font_flush(video_width, video_height, &ozone->fonts.time);
ozone_font_flush(video_width, video_height, &ozone->fonts.entries_label);
ozone_font_flush(video_width, video_height, &ozone->fonts.entries_sublabel);
ozone_font_flush(video_width, video_height, &ozone->fonts.sidebar);
font_flush(video_width, video_height, &ozone->fonts.footer);
font_flush(video_width, video_height, &ozone->fonts.title);
font_flush(video_width, video_height, &ozone->fonts.time);
font_flush(video_width, video_height, &ozone->fonts.entries_label);
font_flush(video_width, video_height, &ozone->fonts.entries_sublabel);
font_flush(video_width, video_height, &ozone->fonts.sidebar);
/* Draw fullscreen thumbnails, if required */
ozone_draw_fullscreen_thumbnails(ozone,
@ -11718,8 +11681,8 @@ static void ozone_frame(void *data, video_frame_info_t *video_info)
&mymat);
/* Flush second layer of text */
ozone_font_flush(video_width, video_height, &ozone->fonts.footer);
ozone_font_flush(video_width, video_height, &ozone->fonts.entries_label);
font_flush(video_width, video_height, &ozone->fonts.footer);
font_flush(video_width, video_height, &ozone->fonts.entries_label);
}
/* Cursor */
@ -11745,12 +11708,12 @@ static void ozone_frame(void *data, video_frame_info_t *video_info)
}
/* Unbind fonts */
ozone_font_unbind(&ozone->fonts.footer);
ozone_font_unbind(&ozone->fonts.title);
ozone_font_unbind(&ozone->fonts.time);
ozone_font_unbind(&ozone->fonts.entries_label);
ozone_font_unbind(&ozone->fonts.entries_sublabel);
ozone_font_unbind(&ozone->fonts.sidebar);
font_unbind(&ozone->fonts.footer);
font_unbind(&ozone->fonts.title);
font_unbind(&ozone->fonts.time);
font_unbind(&ozone->fonts.entries_label);
font_unbind(&ozone->fonts.entries_sublabel);
font_unbind(&ozone->fonts.sidebar);
if (video_st->current_video && video_st->current_video->set_viewport)
video_st->current_video->set_viewport(