40 |
void* user_data ); |
void* user_data ); |
41 |
|
|
42 |
typedef struct { |
typedef struct { |
43 |
char* title; |
const char* title; |
44 |
bcall_t bench; |
bcall_t bench; |
45 |
int cache_first; |
int cache_first; |
46 |
void* user_data; |
void* user_data; |
47 |
} btest_t; |
} btest_t; |
48 |
|
|
49 |
typedef struct |
typedef struct |
50 |
{ |
{ |
51 |
FT_UInt size; |
FT_Int size; |
52 |
FT_ULong* code; |
FT_ULong* code; |
53 |
} bcharset_t; |
} bcharset_t; |
54 |
|
|
65 |
#define FACE_SIZE 10 |
#define FACE_SIZE 10 |
66 |
|
|
67 |
FT_Library lib; |
FT_Library lib; |
|
FT_Face face; |
|
68 |
FTC_Manager cache_man; |
FTC_Manager cache_man; |
69 |
FTC_CMapCache cmap_cache; |
FTC_CMapCache cmap_cache; |
70 |
FTC_ImageCache image_cache; |
FTC_ImageCache image_cache; |
93 |
NULL |
NULL |
94 |
}; |
}; |
95 |
|
|
|
bcharset_t charset; |
|
|
|
|
96 |
int preload; |
int preload; |
97 |
char* filename; |
char* filename; |
98 |
|
|
105 |
*/ |
*/ |
106 |
|
|
107 |
FT_Error |
FT_Error |
108 |
face_requester (FTC_FaceID face_id, |
face_requester( FTC_FaceID face_id, |
109 |
FT_Library library, |
FT_Library library, |
110 |
FT_Pointer request_data,\ |
FT_Pointer request_data, |
111 |
FT_Face* aface) |
FT_Face* aface ) |
112 |
{ |
{ |
113 |
FT_UNUSED( face_id ); |
FT_UNUSED( face_id ); |
114 |
FT_UNUSED( library ); |
FT_UNUSED( library ); |
|
FT_UNUSED( request_data ); |
|
115 |
|
|
116 |
*aface = face; |
*aface = (FT_Face)request_data; |
117 |
|
|
118 |
return 0; |
return 0; |
119 |
} |
} |
120 |
|
|
148 |
*/ |
*/ |
149 |
|
|
150 |
void |
void |
151 |
benchmark( btest_t* test, |
benchmark( FT_Face face, |
152 |
|
btest_t* test, |
153 |
int max_iter, |
int max_iter, |
154 |
double max_time ) |
double max_time ) |
155 |
{ |
{ |
202 |
FT_Face face, |
FT_Face face, |
203 |
void* user_data ) |
void* user_data ) |
204 |
{ |
{ |
205 |
int i, done = 0; |
int i, done = 0; |
206 |
|
|
207 |
|
|
208 |
FT_UNUSED( user_data ); |
FT_UNUSED( user_data ); |
226 |
FT_Face face, |
FT_Face face, |
227 |
void* user_data ) |
void* user_data ) |
228 |
{ |
{ |
229 |
int i, done = 0; |
int i, done = 0; |
230 |
|
|
231 |
|
|
232 |
FT_UNUSED( user_data ); |
FT_UNUSED( user_data ); |
312 |
FT_Face face, |
FT_Face face, |
313 |
void* user_data ) |
void* user_data ) |
314 |
{ |
{ |
315 |
int i, done = 0; |
bcharset_t* charset = (bcharset_t*)user_data; |
316 |
|
int i, done = 0; |
317 |
|
|
|
FT_UNUSED( user_data ); |
|
318 |
|
|
319 |
TIMER_START( timer ); |
TIMER_START( timer ); |
320 |
|
|
321 |
for ( i = 0; i < charset.size; i++ ) |
for ( i = 0; i < charset->size; i++ ) |
322 |
{ |
{ |
323 |
if ( FT_Get_Char_Index(face, charset.code[i]) ) |
if ( FT_Get_Char_Index(face, charset->code[i]) ) |
324 |
done++; |
done++; |
325 |
} |
} |
326 |
|
|
335 |
FT_Face face, |
FT_Face face, |
336 |
void* user_data ) |
void* user_data ) |
337 |
{ |
{ |
338 |
int i, done = 0; |
bcharset_t* charset = (bcharset_t*)user_data; |
339 |
|
int i, done = 0; |
340 |
|
|
341 |
|
|
342 |
FT_UNUSED( user_data ); |
FT_UNUSED( face ); |
343 |
|
|
344 |
if ( !cmap_cache ) |
if ( !cmap_cache ) |
345 |
{ |
{ |
349 |
|
|
350 |
TIMER_START( timer ); |
TIMER_START( timer ); |
351 |
|
|
352 |
for ( i = 0; i < charset.size; i++ ) |
for ( i = 0; i < charset->size; i++ ) |
353 |
{ |
{ |
354 |
if ( FTC_CMapCache_Lookup( cmap_cache, font_type.face_id, 0, charset.code[i] ) ) |
if ( FTC_CMapCache_Lookup( cmap_cache, font_type.face_id, 0, charset->code[i] ) ) |
355 |
done++; |
done++; |
356 |
} |
} |
357 |
|
|
366 |
FT_Face face, |
FT_Face face, |
367 |
void* user_data ) |
void* user_data ) |
368 |
{ |
{ |
369 |
FT_Glyph glyph; |
FT_Glyph glyph; |
370 |
int i, done = 0; |
int i, done = 0; |
371 |
|
|
372 |
|
|
373 |
FT_UNUSED( user_data ); |
FT_UNUSED( user_data ); |
397 |
FT_Face face, |
FT_Face face, |
398 |
void* user_data ) |
void* user_data ) |
399 |
{ |
{ |
400 |
FTC_SBit glyph; |
FTC_SBit glyph; |
401 |
int i, done = 0; |
int i, done = 0; |
402 |
|
|
403 |
|
|
404 |
FT_UNUSED( user_data ); |
FT_UNUSED( user_data ); |
451 |
FT_Face face, |
FT_Face face, |
452 |
void* user_data ) |
void* user_data ) |
453 |
{ |
{ |
454 |
FT_Face bench_face; |
FT_Face bench_face; |
455 |
|
|
456 |
|
|
457 |
FT_UNUSED( face ); |
FT_UNUSED( face ); |
473 |
*/ |
*/ |
474 |
|
|
475 |
void |
void |
476 |
get_charset( FT_Face face ) |
get_charset( FT_Face face, |
477 |
|
bcharset_t* charset ) |
478 |
{ |
{ |
479 |
FT_ULong charcode; |
FT_ULong charcode; |
480 |
FT_UInt gindex; |
FT_UInt gindex; |
481 |
int i; |
int i; |
482 |
|
|
483 |
|
|
484 |
charset.code = (FT_ULong*)calloc( face->num_glyphs, sizeof( FT_ULong ) ); |
charset->code = (FT_ULong*)calloc( face->num_glyphs, sizeof( FT_ULong ) ); |
485 |
if ( !charset.code ) |
if ( !charset->code ) |
486 |
return; |
return; |
487 |
|
|
488 |
if ( face->charmap ) |
if ( face->charmap ) |
495 |
/* */ |
/* */ |
496 |
while ( gindex && i < face->num_glyphs ) |
while ( gindex && i < face->num_glyphs ) |
497 |
{ |
{ |
498 |
charset.code[i++] = charcode; |
charset->code[i++] = charcode; |
499 |
charcode = FT_Get_Next_Char(face, charcode, &gindex); |
charcode = FT_Get_Next_Char(face, charcode, &gindex); |
500 |
} |
} |
501 |
|
|
504 |
{ |
{ |
505 |
/* no charmap, do an identity mapping */ |
/* no charmap, do an identity mapping */ |
506 |
for ( i = 0; i < face->num_glyphs; i++ ) |
for ( i = 0; i < face->num_glyphs; i++ ) |
507 |
charset.code[i] = i; |
charset->code[i] = i; |
508 |
} |
} |
509 |
|
|
510 |
charset.size = i; |
charset->size = i; |
511 |
} |
} |
512 |
|
|
513 |
|
|
570 |
|
|
571 |
void usage(void) |
void usage(void) |
572 |
{ |
{ |
573 |
int i; |
int i; |
574 |
|
|
575 |
|
|
576 |
fprintf( stderr, |
fprintf( stderr, |
607 |
main(int argc, |
main(int argc, |
608 |
char** argv) |
char** argv) |
609 |
{ |
{ |
610 |
long max_bytes = CACHE_SIZE * 1024; |
FT_Face face; |
611 |
char* test_string = NULL; |
long max_bytes = CACHE_SIZE * 1024; |
612 |
int size = FACE_SIZE; |
char* test_string = NULL; |
613 |
int max_iter = 0; |
int size = FACE_SIZE; |
614 |
double max_time = BENCH_TIME; |
int max_iter = 0; |
615 |
int compare_cached = 0; |
double max_time = BENCH_TIME; |
616 |
int i; |
int compare_cached = 0; |
617 |
|
int i; |
618 |
|
|
619 |
while ( 1 ) |
while ( 1 ) |
620 |
{ |
{ |
646 |
break; |
break; |
647 |
case 'r': |
case 'r': |
648 |
render_mode = atoi( optarg ); |
render_mode = atoi( optarg ); |
649 |
if ( render_mode < 0 || render_mode >= FT_RENDER_MODE_MAX ) |
if ( render_mode >= FT_RENDER_MODE_MAX ) |
650 |
render_mode = FT_RENDER_MODE_NORMAL; |
render_mode = FT_RENDER_MODE_NORMAL; |
651 |
break; |
break; |
652 |
case 's': |
case 's': |
699 |
else |
else |
700 |
size = face->available_sizes[0].width; |
size = face->available_sizes[0].width; |
701 |
|
|
702 |
get_charset( face ); |
FTC_Manager_New( lib, 0, 0, max_bytes, face_requester, face, &cache_man ); |
|
|
|
|
FTC_Manager_New( lib, 0, 0, max_bytes, face_requester, NULL, &cache_man ); |
|
703 |
|
|
704 |
font_type.face_id = (FTC_FaceID) 1; |
font_type.face_id = (FTC_FaceID) 1; |
705 |
font_type.width = (short) size; |
font_type.width = (short) size; |
724 |
case FT_BENCH_LOAD_GLYPH: |
case FT_BENCH_LOAD_GLYPH: |
725 |
test.title = "Load"; |
test.title = "Load"; |
726 |
test.bench = test_load; |
test.bench = test_load; |
727 |
benchmark( &test, max_iter, max_time ); |
benchmark( face, &test, max_iter, max_time ); |
728 |
|
|
729 |
if ( compare_cached ) |
if ( compare_cached ) |
730 |
{ |
{ |
732 |
|
|
733 |
test.title = "Load (image cached)"; |
test.title = "Load (image cached)"; |
734 |
test.bench = test_image_cache; |
test.bench = test_image_cache; |
735 |
benchmark( &test, max_iter, max_time ); |
benchmark( face, &test, max_iter, max_time ); |
736 |
|
|
737 |
test.title = "Load (sbit cached)"; |
test.title = "Load (sbit cached)"; |
738 |
test.bench = test_sbit_cache; |
test.bench = test_sbit_cache; |
739 |
benchmark( &test, max_iter, max_time ); |
benchmark( face, &test, max_iter, max_time ); |
740 |
} |
} |
741 |
break; |
break; |
742 |
case FT_BENCH_RENDER: |
case FT_BENCH_RENDER: |
743 |
test.title = "Render"; |
test.title = "Render"; |
744 |
test.bench = test_render; |
test.bench = test_render; |
745 |
benchmark( &test, max_iter, max_time ); |
benchmark( face, &test, max_iter, max_time ); |
746 |
break; |
break; |
747 |
case FT_BENCH_GET_GLYPH: |
case FT_BENCH_GET_GLYPH: |
748 |
test.title = "Get_Glyph"; |
test.title = "Get_Glyph"; |
749 |
test.bench = test_get_glyph; |
test.bench = test_get_glyph; |
750 |
benchmark( &test, max_iter, max_time ); |
benchmark( face, &test, max_iter, max_time ); |
751 |
break; |
break; |
752 |
case FT_BENCH_GET_CBOX: |
case FT_BENCH_GET_CBOX: |
753 |
test.title = "Get_CBox"; |
test.title = "Get_CBox"; |
754 |
test.bench = test_get_cbox; |
test.bench = test_get_cbox; |
755 |
benchmark( &test, max_iter, max_time ); |
benchmark( face, &test, max_iter, max_time ); |
756 |
break; |
break; |
757 |
case FT_BENCH_CMAP: |
case FT_BENCH_CMAP: |
|
test.title = "Get_Char_Index"; |
|
|
test.bench = test_get_char_index; |
|
|
benchmark( &test, max_iter, max_time ); |
|
|
|
|
|
if ( compare_cached ) |
|
758 |
{ |
{ |
759 |
test.cache_first = 1; |
bcharset_t charset; |
760 |
|
|
761 |
|
|
762 |
|
get_charset( face, &charset ); |
763 |
|
if ( charset.code ) |
764 |
|
{ |
765 |
|
test.user_data = (void*)&charset; |
766 |
|
|
767 |
|
|
768 |
test.title = "Get_Char_Index (cached)"; |
test.title = "Get_Char_Index"; |
769 |
test.bench = test_cmap_cache; |
test.bench = test_get_char_index; |
770 |
benchmark( &test, max_iter, max_time ); |
|
771 |
|
benchmark( face, &test, max_iter, max_time ); |
772 |
|
|
773 |
|
if ( compare_cached ) |
774 |
|
{ |
775 |
|
test.cache_first = 1; |
776 |
|
|
777 |
|
test.title = "Get_Char_Index (cached)"; |
778 |
|
test.bench = test_cmap_cache; |
779 |
|
benchmark( face, &test, max_iter, max_time ); |
780 |
|
} |
781 |
|
|
782 |
|
free( charset.code ); |
783 |
|
} |
784 |
} |
} |
785 |
break; |
break; |
786 |
case FT_BENCH_CMAP_ITER: |
case FT_BENCH_CMAP_ITER: |
787 |
test.title = "Iterate CMap"; |
test.title = "Iterate CMap"; |
788 |
test.bench = test_cmap_iter; |
test.bench = test_cmap_iter; |
789 |
benchmark( &test, max_iter, max_time ); |
benchmark( face, &test, max_iter, max_time ); |
790 |
break; |
break; |
791 |
case FT_BENCH_NEW_FACE: |
case FT_BENCH_NEW_FACE: |
792 |
test.title = "New_Face"; |
test.title = "New_Face"; |
793 |
test.bench = test_new_face; |
test.bench = test_new_face; |
794 |
benchmark( &test, max_iter, max_time ); |
benchmark( face, &test, max_iter, max_time ); |
795 |
break; |
break; |
796 |
} |
} |
797 |
} |
} |
799 |
if ( cache_man ) |
if ( cache_man ) |
800 |
FTC_Manager_Done( cache_man ); |
FTC_Manager_Done( cache_man ); |
801 |
|
|
|
if ( charset.code ) |
|
|
free( charset.code ); |
|
|
|
|
802 |
FT_Done_Face( face ); |
FT_Done_Face( face ); |
803 |
|
|
804 |
FT_Done_FreeType( lib ); |
FT_Done_FreeType( lib ); |