Skip to content

Commit 23b62af

Browse files
committed
(Video drivers) Go through function pointer for glyph_q
1 parent 0f0dba3 commit 23b62af

6 files changed

Lines changed: 89 additions & 56 deletions

File tree

gfx/drivers/gl1.c

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -526,6 +526,8 @@ static void *gl1_raster_font_init(void *data,
526526
static int gl1_raster_font_get_message_width(void *data, const char *msg,
527527
size_t msg_len, float scale)
528528
{
529+
void *font_data;
530+
const struct font_glyph* (*get_glyph)(void*, uint32_t);
529531
const struct font_glyph* glyph_q = NULL;
530532
gl1_raster_t *font = (gl1_raster_t*)data;
531533
const char* msg_end = msg + msg_len;
@@ -536,16 +538,17 @@ static int gl1_raster_font_get_message_width(void *data, const char *msg,
536538
|| !font->font_data )
537539
return 0;
538540

539-
glyph_q = font->font_driver->get_glyph(font->font_data, '?');
541+
get_glyph = font->font_driver->get_glyph;
542+
font_data = font->font_data;
543+
glyph_q = get_glyph(font_data, '?');
540544

541545
while (msg < msg_end)
542546
{
543547
const struct font_glyph *glyph;
544-
unsigned code = utf8_walk(&msg);
548+
unsigned code = utf8_walk(&msg);
545549

546550
/* Do something smarter here ... */
547-
if (!(glyph = font->font_driver->get_glyph(
548-
font->font_data, code)))
551+
if (!(glyph = get_glyph(font_data, code)))
549552
if (!(glyph = glyph_q))
550553
continue;
551554

@@ -641,6 +644,8 @@ static void gl1_raster_font_render_line(gl1_t *gl,
641644
int y = roundf(pos_y * gl->vp.height);
642645
int delta_x = 0;
643646
int delta_y = 0;
647+
const struct font_glyph* (*get_glyph)(void*, uint32_t) = font->font_driver->get_glyph;
648+
void *font_data = font->font_data;
644649

645650
/* For right/center alignment, compute width with a lightweight pass
646651
* that only accumulates advance_x — avoids the redundant glyph lookups
@@ -655,7 +660,7 @@ static void gl1_raster_font_render_line(gl1_t *gl,
655660
{
656661
const struct font_glyph *glyph;
657662
uint32_t code = utf8_walk(&scan);
658-
if (!(glyph = font->font_driver->get_glyph(font->font_data, code)))
663+
if (!(glyph = get_glyph(font_data, code)))
659664
if (!(glyph = glyph_q))
660665
continue;
661666
width_accum += glyph->advance_x;
@@ -677,8 +682,7 @@ static void gl1_raster_font_render_line(gl1_t *gl,
677682
unsigned code = utf8_walk(&msg);
678683

679684
/* Do something smarter here ... */
680-
if (!(glyph = font->font_driver->get_glyph(
681-
font->font_data, code)))
685+
if (!(glyph = get_glyph(font_data, code)))
682686
if (!(glyph = glyph_q))
683687
continue;
684688

gfx/drivers/gl2.c

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -905,6 +905,8 @@ static void *gl2_raster_font_init(void *data,
905905
static int gl2_raster_font_get_message_width(void *data, const char *msg,
906906
size_t msg_len, float scale)
907907
{
908+
void *font_data;
909+
const struct font_glyph* (*get_glyph)(void*, uint32_t);
908910
const struct font_glyph* glyph_q = NULL;
909911
gl2_raster_t *font = (gl2_raster_t*)data;
910912
const char* msg_end = msg + msg_len;
@@ -915,16 +917,17 @@ static int gl2_raster_font_get_message_width(void *data, const char *msg,
915917
|| !font->font_data )
916918
return 0;
917919

918-
glyph_q = font->font_driver->get_glyph(font->font_data, '?');
920+
get_glyph = font->font_driver->get_glyph;
921+
font_data = font->font_data;
922+
glyph_q = get_glyph(font_data, '?');
919923

920924
while (msg < msg_end)
921925
{
922926
const struct font_glyph *glyph;
923927
unsigned code = utf8_walk(&msg);
924928

925929
/* Do something smarter here ... */
926-
if (!(glyph = font->font_driver->get_glyph(
927-
font->font_data, code)))
930+
if (!(glyph = get_glyph(font_data, code)))
928931
if (!(glyph = glyph_q))
929932
continue;
930933

@@ -975,6 +978,8 @@ static void gl2_raster_font_render_line(gl2_t *gl,
975978
float inv_tex_size_y = 1.0f / font->tex_height;
976979
float inv_win_width = 1.0f / gl->vp.width;
977980
float inv_win_height = 1.0f / gl->vp.height;
981+
const struct font_glyph* (*get_glyph)(void*, uint32_t) = font->font_driver->get_glyph;
982+
void *font_data = font->font_data;
978983

979984
/* For right/center alignment, compute width with a lightweight pass
980985
* that only accumulates advance_x — avoids the redundant glyph lookups
@@ -989,7 +994,7 @@ static void gl2_raster_font_render_line(gl2_t *gl,
989994
{
990995
const struct font_glyph *glyph;
991996
uint32_t code = utf8_walk(&scan);
992-
if (!(glyph = font->font_driver->get_glyph(font->font_data, code)))
997+
if (!(glyph = get_glyph(font_data, code)))
993998
if (!(glyph = glyph_q))
994999
continue;
9951000
width_accum += glyph->advance_x;
@@ -1001,7 +1006,7 @@ static void gl2_raster_font_render_line(gl2_t *gl,
10011006
x -= (int)(width_accum * scale) / 2;
10021007
}
10031008

1004-
glyph_q = font->font_driver->get_glyph(font->font_data, '?');
1009+
glyph_q = get_glyph(font_data, '?');
10051010

10061011
while (msg < msg_end)
10071012
{
@@ -1013,8 +1018,7 @@ static void gl2_raster_font_render_line(gl2_t *gl,
10131018
unsigned code = utf8_walk(&msg);
10141019

10151020
/* Do something smarter here ... */
1016-
if (!(glyph = font->font_driver->get_glyph(
1017-
font->font_data, code)))
1021+
if (!(glyph = get_glyph(font_data, code)))
10181022
if (!(glyph = glyph_q))
10191023
continue;
10201024

gfx/drivers/gl3.c

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -970,6 +970,8 @@ static void *gl3_raster_font_init(void *data,
970970
static int gl3_raster_font_get_message_width(void *data, const char *msg,
971971
size_t msg_len, float scale)
972972
{
973+
void *font_data;
974+
const struct font_glyph* (*get_glyph)(void*, uint32_t);
973975
const struct font_glyph* glyph_q = NULL;
974976
gl3_raster_t *font = (gl3_raster_t*)data;
975977
const char* msg_end = msg + msg_len;
@@ -980,16 +982,17 @@ static int gl3_raster_font_get_message_width(void *data, const char *msg,
980982
|| !font->font_data )
981983
return 0;
982984

983-
glyph_q = font->font_driver->get_glyph(font->font_data, '?');
985+
get_glyph = font->font_driver->get_glyph;
986+
font_data = font->font_data;
987+
glyph_q = get_glyph(font_data, '?');
984988

985989
while (msg < msg_end)
986990
{
987991
const struct font_glyph *glyph;
988-
unsigned code = utf8_walk(&msg);
992+
unsigned code = utf8_walk(&msg);
989993

990994
/* Do something smarter here ... */
991-
if (!(glyph = font->font_driver->get_glyph(
992-
font->font_data, code)))
995+
if (!(glyph = get_glyph(font_data, code)))
993996
if (!(glyph = glyph_q))
994997
continue;
995998

@@ -1088,6 +1091,8 @@ static void gl3_raster_font_render_line(gl3_t *gl,
10881091
int y = roundf(pos_y * gl->vp.height);
10891092
int delta_x = 0;
10901093
int delta_y = 0;
1094+
const struct font_glyph* (*get_glyph)(void*, uint32_t) = font->font_driver->get_glyph;
1095+
void *font_data = font->font_data;
10911096

10921097
/* For right/center alignment, compute width with a lightweight pass
10931098
* that only accumulates advance_x — avoids the redundant glyph lookups
@@ -1102,7 +1107,7 @@ static void gl3_raster_font_render_line(gl3_t *gl,
11021107
{
11031108
const struct font_glyph *glyph;
11041109
uint32_t code = utf8_walk(&scan);
1105-
if (!(glyph = font->font_driver->get_glyph(font->font_data, code)))
1110+
if (!(glyph = get_glyph(font_data, code)))
11061111
if (!(glyph = glyph_q))
11071112
continue;
11081113
width_accum += glyph->advance_x;
@@ -1124,8 +1129,7 @@ static void gl3_raster_font_render_line(gl3_t *gl,
11241129
unsigned code = utf8_walk(&msg);
11251130

11261131
/* Do something smarter here ... */
1127-
if (!(glyph = font->font_driver->get_glyph(
1128-
font->font_data, code)))
1132+
if (!(glyph = get_glyph(font_data, code)))
11291133
if (!(glyph = glyph_q))
11301134
continue;
11311135

gfx/drivers/gx2_gfx.c

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -712,13 +712,17 @@ static int gx2_font_get_message_width(void* data, const char* msg,
712712
{
713713
int i;
714714
int delta_x = 0;
715+
void *font_data;
716+
const struct font_glyph* (*get_glyph)(void*, uint32_t);
715717
const struct font_glyph* glyph_q = NULL;
716718
gx2_font_t *font = (gx2_font_t*)data;
717719

718720
if (!font)
719721
return 0;
720722

721-
glyph_q = font->font_driver->get_glyph(font->font_data, '?');
723+
get_glyph = font->font_driver->get_glyph;
724+
font_data = font->font_data;
725+
glyph_q = get_glyph(font_data, '?');
722726

723727
for (i = 0; i < msg_len; i++)
724728
{
@@ -731,8 +735,7 @@ static int gx2_font_get_message_width(void* data, const char* msg,
731735
i += skip - 1;
732736

733737
/* Do something smarter here ... */
734-
if (!(glyph =
735-
font->font_driver->get_glyph(font->font_data, code)))
738+
if (!(glyph = get_glyph(font_data, code)))
736739
if (!(glyph = glyph_q))
737740
continue;
738741

@@ -759,6 +762,8 @@ static void gx2_font_render_line(
759762
const char* msg_end = msg + msg_len;
760763
int x = pre_x;
761764
int y = roundf((1.0 - pos_y) * height);
765+
const struct font_glyph* (*get_glyph)(void*, uint32_t) = font->font_driver->get_glyph;
766+
void *font_data = font->font_data;
762767

763768
/* For right/center alignment, compute width with a lightweight pass
764769
* that only accumulates advance_x — avoids the redundant glyph lookups
@@ -772,7 +777,7 @@ static void gx2_font_render_line(
772777
{
773778
const struct font_glyph *glyph;
774779
uint32_t code = utf8_walk(&scan);
775-
if (!(glyph = font->font_driver->get_glyph(font->font_data, code)))
780+
if (!(glyph = get_glyph(font_data, code)))
776781
if (!(glyph = glyph_q))
777782
continue;
778783
width_accum += glyph->advance_x;
@@ -797,8 +802,7 @@ static void gx2_font_render_line(
797802
i += skip - 1;
798803

799804
/* Do something smarter here ... */
800-
if (!(glyph =
801-
font->font_driver->get_glyph(font->font_data, code)))
805+
if (!(glyph = get_glyph(font_data, code)))
802806
if (!(glyph = glyph_q))
803807
continue;
804808

gfx/drivers/ps2_gfx.c

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -202,11 +202,14 @@ static int ps2_font_get_message_width(void* data, const char* msg,
202202
const struct font_glyph* glyph_q = NULL;
203203
int delta_x = 0;
204204
ps2_font_t* font = (ps2_font_t*)data;
205+
const struct font_glyph* (*get_glyph)(void*, uint32_t)
206+
= font->font_driver->get_glyph;
207+
void *font_data = font->font_data;
205208

206209
if (!font)
207210
return 0;
208211

209-
glyph_q = font->font_driver->get_glyph(font->font_data, '?');
212+
glyph_q = get_glyph(font_data, '?');
210213

211214
for (i = 0; i < msg_len; i++)
212215
{
@@ -219,8 +222,7 @@ static int ps2_font_get_message_width(void* data, const char* msg,
219222
i += skip - 1;
220223

221224
/* Do something smarter here ... */
222-
if (!(glyph =
223-
font->font_driver->get_glyph(font->font_data, code)))
225+
if (!(glyph = get_glyph(font_data, code)))
224226
if (!(glyph = glyph_q))
225227
continue;
226228

@@ -255,6 +257,9 @@ static void ps2_font_render_line(
255257
int color_b = (int)(((color & 0x00FF0000) >> 16) >> 1);
256258
int color_g = (int)(((color & 0x0000FF00) >> 8) >> 1);
257259
int color_r = (int)(((color & 0x000000FF) >> 0) >> 1);
260+
const struct font_glyph* (*get_glyph)(void*, uint32_t)
261+
= font->font_driver->get_glyph;
262+
void *font_data = font->font_data;
258263

259264
/* Enable Alpha for font */
260265
gsKit_set_primalpha(ps2->gsGlobal, GS_SETREG_ALPHA(0, 1, 0, 1, 0), 0);
@@ -273,7 +278,7 @@ static void ps2_font_render_line(
273278
{
274279
const struct font_glyph *glyph;
275280
uint32_t code = utf8_walk(&scan);
276-
if (!(glyph = font->font_driver->get_glyph(font->font_data, code)))
281+
if (!(glyph = get_glyph(font_data, code)))
277282
if (!(glyph = glyph_q))
278283
continue;
279284
width_accum += glyph->advance_x;
@@ -298,8 +303,7 @@ static void ps2_font_render_line(
298303
i += skip - 1;
299304

300305
/* Do something smarter here ... */
301-
if (!(glyph =
302-
font->font_driver->get_glyph(font->font_data, code)))
306+
if (!(glyph = get_glyph(font_data, code)))
303307
if (!(glyph = glyph_q))
304308
continue;
305309

0 commit comments

Comments
 (0)