Skip to content

Commit

Permalink
Change msg_len of font driver to size_t - avoids all the type
Browse files Browse the repository at this point in the history
casting/conversion
  • Loading branch information
LibretroAdmin committed Sep 1, 2022
1 parent 77e83a4 commit 0ffdd14
Show file tree
Hide file tree
Showing 33 changed files with 138 additions and 134 deletions.
2 changes: 1 addition & 1 deletion gfx/common/metal_common.m
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ - (void)_renderMessage:(const char *)msg
{
float r, g, b, a;
int msg_width =
font_driver_get_message_width(NULL, msg, (unsigned)strlen(msg), 1.0f);
font_driver_get_message_width(NULL, msg, strlen(msg), 1.0f);
float font_size = settings->floats.video_font_size;
unsigned bgcolor_red
= settings->uints.video_msg_bgcolor_red;
Expand Down
2 changes: 1 addition & 1 deletion gfx/drivers/gl2.c
Original file line number Diff line number Diff line change
Expand Up @@ -2318,7 +2318,7 @@ static void gl2_render_osd_background(gl2_t *gl, const char *msg)
settings_t *settings = config_get_ptr();
float video_font_size = settings->floats.video_font_size;
int msg_width =
font_driver_get_message_width(NULL, msg, (unsigned)strlen(msg), 1.0f);
font_driver_get_message_width(NULL, msg, strlen(msg), 1.0f);

/* shader driver expects vertex coords as 0..1 */
float x = settings->floats.video_msg_pos_x;
Expand Down
2 changes: 1 addition & 1 deletion gfx/drivers_font/caca_font.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ static void caca_font_free(void *data, bool is_threaded)
}

static int caca_font_get_message_width(void *data, const char *msg,
unsigned msg_len, float scale)
size_t msg_len, float scale)
{
return 0;
}
Expand Down
12 changes: 6 additions & 6 deletions gfx/drivers_font/ctr_font.c
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,9 @@ static void ctr_font_free(void* data, bool is_threaded)
}

static int ctr_font_get_message_width(void* data, const char* msg,
unsigned msg_len, float scale)
size_t msg_len, float scale)
{
unsigned i;
int i;
int delta_x = 0;
const struct font_glyph* glyph_q = NULL;
ctr_font_t* font = (ctr_font_t*)data;
Expand Down Expand Up @@ -159,7 +159,7 @@ static int ctr_font_get_message_width(void* data, const char* msg,

static void ctr_font_render_line(
ctr_video_t *ctr,
ctr_font_t* font, const char* msg, unsigned msg_len,
ctr_font_t* font, const char* msg, size_t msg_len,
float scale, const unsigned int color, float pos_x,
float pos_y,
unsigned width, unsigned height, unsigned text_align)
Expand Down Expand Up @@ -309,7 +309,7 @@ static void ctr_font_render_message(
if (!font->font_driver->get_line_metrics ||
!font->font_driver->get_line_metrics(font->font_data, &line_metrics))
{
unsigned msg_len = strlen(msg);
size_t msg_len = strlen(msg);
ctr_font_render_line(ctr, font, msg, msg_len,
scale, color, pos_x, pos_y,
width, height, text_align);
Expand All @@ -321,8 +321,8 @@ static void ctr_font_render_message(
for (;;)
{
const char* delim = strchr(msg, '\n');
unsigned msg_len = delim ?
(unsigned)(delim - msg) : strlen(msg);
size_t msg_len = delim ?
(delim - msg) : strlen(msg);

/* Draw the line */
ctr_font_render_line(ctr, font, msg, msg_len,
Expand Down
12 changes: 6 additions & 6 deletions gfx/drivers_font/d3d10_font.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,9 @@ static void d3d10_font_free(void* data, bool is_threaded)
free(font);
}

static int d3d10_font_get_message_width(void* data, const char* msg, unsigned msg_len, float scale)
static int d3d10_font_get_message_width(void* data, const char* msg, size_t msg_len, float scale)
{
unsigned i;
int i;
int delta_x = 0;
const struct font_glyph* glyph_q = NULL;
d3d10_font_t* font = (d3d10_font_t*)data;
Expand Down Expand Up @@ -122,7 +122,7 @@ static void d3d10_font_render_line(
d3d10_video_t *d3d10,
d3d10_font_t* font,
const char* msg,
unsigned msg_len,
size_t msg_len,
float scale,
const unsigned int color,
float pos_x,
Expand Down Expand Up @@ -250,7 +250,7 @@ static void d3d10_font_render_message(
if (!font->font_driver->get_line_metrics ||
!font->font_driver->get_line_metrics(font->font_data, &line_metrics))
{
unsigned msg_len = strlen(msg);
size_t msg_len = strlen(msg);
if (msg_len <= (unsigned)d3d10->sprites.capacity)
d3d10_font_render_line(d3d10,
font, msg, msg_len, scale, color, pos_x, pos_y,
Expand All @@ -263,8 +263,8 @@ static void d3d10_font_render_message(
for (;;)
{
const char* delim = strchr(msg, '\n');
unsigned msg_len = delim ?
(unsigned)(delim - msg) : strlen(msg);
size_t msg_len = delim ?
(delim - msg) : strlen(msg);

/* Draw the line */
if (msg_len <= (unsigned)d3d10->sprites.capacity)
Expand Down
18 changes: 9 additions & 9 deletions gfx/drivers_font/d3d11_font.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,13 @@ static void d3d11_font_free(void* data, bool is_threaded)
free(font);
}

static int d3d11_font_get_message_width(void* data, const char* msg, unsigned msg_len, float scale)
static int d3d11_font_get_message_width(void* data, const char* msg, size_t msg_len, float scale)
{
int i;
int delta_x = 0;
const struct font_glyph* glyph_q = NULL;
d3d11_font_t* font = (d3d11_font_t*)data;

unsigned i;
int delta_x = 0;

if (!font)
return 0;

Expand Down Expand Up @@ -121,7 +120,7 @@ static void d3d11_font_render_line(
d3d11_video_t* d3d11,
d3d11_font_t* font,
const char* msg,
unsigned msg_len,
size_t msg_len,
float scale,
const unsigned int color,
float pos_x,
Expand All @@ -130,7 +129,8 @@ static void d3d11_font_render_line(
unsigned height,
unsigned text_align)
{
unsigned i, count;
int i;
unsigned count;
D3D11_MAPPED_SUBRESOURCE mapped_vbo;
d3d11_sprite_t *v = NULL;
const struct font_glyph* glyph_q = NULL;
Expand Down Expand Up @@ -254,7 +254,7 @@ static void d3d11_font_render_message(
if (!font->font_driver->get_line_metrics ||
!font->font_driver->get_line_metrics(font->font_data, &line_metrics))
{
unsigned msg_len = strlen(msg);
size_t msg_len = strlen(msg);
if (msg_len <= (unsigned)d3d11->sprites.capacity)
d3d11_font_render_line(d3d11,
font, msg, msg_len, scale, color, pos_x, pos_y,
Expand All @@ -267,8 +267,8 @@ static void d3d11_font_render_message(
for (;;)
{
const char* delim = strchr(msg, '\n');
unsigned msg_len = delim ?
(unsigned)(delim - msg) : strlen(msg);
size_t msg_len = delim ?
(delim - msg) : strlen(msg);

/* Draw the line */
if (msg_len <= (unsigned)d3d11->sprites.capacity)
Expand Down
20 changes: 10 additions & 10 deletions gfx/drivers_font/d3d12_font.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,9 @@ static void d3d12_font_free(void* data, bool is_threaded)
}

static int d3d12_font_get_message_width(void* data,
const char* msg, unsigned msg_len, float scale)
const char* msg, size_t msg_len, float scale)
{
unsigned i;
int delta_x = 0;
int i, delta_x = 0;
const struct font_glyph* glyph_q = NULL;
d3d12_font_t* font = (d3d12_font_t*)data;

Expand Down Expand Up @@ -122,7 +121,7 @@ static void d3d12_font_render_line(
d3d12_video_t *d3d12,
d3d12_font_t* font,
const char* msg,
unsigned msg_len,
size_t msg_len,
float scale,
const unsigned int color,
float pos_x,
Expand All @@ -131,8 +130,9 @@ static void d3d12_font_render_line(
unsigned height,
unsigned text_align)
{
int i;
D3D12_RANGE range;
unsigned i, count;
unsigned count;
const struct font_glyph* glyph_q = NULL;
void* mapped_vbo = NULL;
d3d12_sprite_t* v = NULL;
Expand Down Expand Up @@ -256,8 +256,8 @@ static void d3d12_font_render_message(
if (!font->font_driver->get_line_metrics ||
!font->font_driver->get_line_metrics(font->font_data, &line_metrics))
{
unsigned msg_len = strlen(msg);
if (msg_len <= (unsigned)d3d12->sprites.capacity)
size_t msg_len = strlen(msg);
if (msg_len <= d3d12->sprites.capacity)
d3d12_font_render_line(d3d12,
font, msg, msg_len,
scale, color, pos_x, pos_y, width, height, text_align);
Expand All @@ -269,11 +269,11 @@ static void d3d12_font_render_message(
for (;;)
{
const char* delim = strchr(msg, '\n');
unsigned msg_len = delim ?
(unsigned)(delim - msg) : strlen(msg);
size_t msg_len = delim ?
(delim - msg) : strlen(msg);

/* Draw the line */
if (msg_len <= (unsigned)d3d12->sprites.capacity)
if (msg_len <= d3d12->sprites.capacity)
d3d12_font_render_line(d3d12,
font, msg, msg_len, scale, color, pos_x,
pos_y - (float)lines * line_height, width, height, text_align);
Expand Down
4 changes: 2 additions & 2 deletions gfx/drivers_font/d3d_w32_font.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ static void d3d_win32_font_free(void *data, bool is_threaded)
}

static int d3d_win32_font_get_message_width(void* data, const char* msg,
unsigned msg_len, float scale)
size_t msg_len, float scale)
{
RECT box = {0,0,0,0};
d3dfonts_t *d3dfonts = (d3dfonts_t*)data;
Expand All @@ -120,7 +120,7 @@ static int d3d_win32_font_get_message_width(void* data, const char* msg,
return 0;

d3d9x_font_draw_text(d3dfonts->font, NULL, (void*)msg,
msg_len? msg_len : -1, &box, DT_CALCRECT, 0);
msg_len ? msg_len : -1, &box, DT_CALCRECT, 0);

return box.right - box.left;
}
Expand Down
9 changes: 5 additions & 4 deletions gfx/drivers_font/gdi_font.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,11 @@ static void gdi_font_render_msg(
const char *msg,
const struct font_params *params)
{
int i;
char* msg_local;
size_t msg_len;
float x, y, scale, drop_mod, drop_alpha;
int drop_x, drop_y, msg_strlen;
unsigned i;
int drop_x, drop_y;
unsigned new_x, new_y, new_drop_x, new_drop_y;
unsigned align;
unsigned red, green, blue;
Expand Down Expand Up @@ -137,9 +138,9 @@ static void gdi_font_render_msg(
}

msg_local = utf8_to_local_string_alloc(msg);
msg_strlen = strlen(msg_local);
msg_len = strlen(msg_local);

GetTextExtentPoint32(font->gdi->memDC, msg_local, msg_strlen, &text_size);
GetTextExtentPoint32(font->gdi->memDC, msg_local, (int)msg_len, &text_size);

switch (align)
{
Expand Down
12 changes: 6 additions & 6 deletions gfx/drivers_font/gl1_raster_font.c
Original file line number Diff line number Diff line change
Expand Up @@ -174,10 +174,10 @@ static void *gl1_raster_font_init(void *data,
}

static int gl1_raster_font_get_message_width(void *data, const char *msg,
unsigned msg_len, float scale)
size_t msg_len, float scale)
{
const struct font_glyph* glyph_q = NULL;
gl1_raster_t *font = (gl1_raster_t*)data;
gl1_raster_t *font = (gl1_raster_t*)data;
const char* msg_end = msg + msg_len;
int delta_x = 0;

Expand Down Expand Up @@ -264,11 +264,11 @@ static void gl1_raster_font_draw_vertices(gl1_raster_t *font,
}

static void gl1_raster_font_render_line(gl1_t *gl,
gl1_raster_t *font, const char *msg, unsigned msg_len,
gl1_raster_t *font, const char *msg, size_t msg_len,
GLfloat scale, const GLfloat color[4], GLfloat pos_x,
GLfloat pos_y, unsigned text_align)
{
unsigned i;
int i;
struct video_coords coords;
const struct font_glyph* glyph_q = NULL;
GLfloat font_tex_coords[2 * 6 * MAX_MSG_LEN_CHUNK];
Expand Down Expand Up @@ -370,8 +370,8 @@ static void gl1_raster_font_render_message(
for (;;)
{
const char *delim = strchr(msg, '\n');
unsigned msg_len = delim
? (unsigned)(delim - msg) : (unsigned)strlen(msg);
size_t msg_len = delim
? (delim - msg) : strlen(msg);

/* Draw the line */
gl1_raster_font_render_line(font->gl, font,
Expand Down
14 changes: 7 additions & 7 deletions gfx/drivers_font/gl2_raster_font.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ static void gl2_raster_font_free(void *data,

static bool gl2_raster_font_upload_atlas(gl2_raster_t *font)
{
unsigned i, j;
int i, j;
GLint gl_internal = GL_LUMINANCE_ALPHA;
GLenum gl_format = GL_LUMINANCE_ALPHA;
size_t ncomponents = 2;
Expand Down Expand Up @@ -178,7 +178,7 @@ static void *gl2_raster_font_init(void *data,
}

static int gl2_raster_font_get_message_width(void *data, const char *msg,
unsigned msg_len, float scale)
size_t msg_len, float scale)
{
const struct font_glyph* glyph_q = NULL;
gl2_raster_t *font = (gl2_raster_t*)data;
Expand Down Expand Up @@ -230,11 +230,11 @@ static void gl2_raster_font_draw_vertices(gl2_raster_t *font,
}

static void gl2_raster_font_render_line(gl2_t *gl,
gl2_raster_t *font, const char *msg, unsigned msg_len,
gl2_raster_t *font, const char *msg, size_t msg_len,
GLfloat scale, const GLfloat color[4], GLfloat pos_x,
GLfloat pos_y, unsigned text_align)
{
unsigned i;
int i;
struct video_coords coords;
const struct font_glyph* glyph_q = NULL;
GLfloat font_tex_coords[2 * 6 * MAX_MSG_LEN_CHUNK];
Expand Down Expand Up @@ -326,7 +326,7 @@ static void gl2_raster_font_render_message(
!font->font_driver->get_line_metrics(font->font_data, &line_metrics))
{
gl2_raster_font_render_line(font->gl, font,
msg, (unsigned)strlen(msg), scale, color, pos_x,
msg, strlen(msg), scale, color, pos_x,
pos_y, text_align);
return;
}
Expand All @@ -336,8 +336,8 @@ static void gl2_raster_font_render_message(
for (;;)
{
const char *delim = strchr(msg, '\n');
unsigned msg_len = delim
? (unsigned)(delim - msg) : (unsigned)strlen(msg);
size_t msg_len = delim
? (delim - msg) : strlen(msg);

/* Draw the line */
gl2_raster_font_render_line(font->gl, font,
Expand Down
Loading

0 comments on commit 0ffdd14

Please sign in to comment.