/[freetype]/ft2demos/src/ftbench.c
ViewVC logotype

Diff of /ft2demos/src/ftbench.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.22 by olvaffe, Fri Dec 2 08:56:40 2005 UTC revision 1.23 by olvaffe, Sun Dec 4 02:39:30 2005 UTC
# Line 40  typedef int Line 40  typedef int
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    
# Line 65  get_face( FT_Face*     face ); Line 65  get_face( FT_Face*     face );
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;
# Line 94  const char* bench_desc[] = { Line 93  const char* bench_desc[] = {
93    NULL    NULL
94  };  };
95    
 bcharset_t      charset;  
   
96  int             preload;  int             preload;
97  char*           filename;  char*           filename;
98    
# Line 108  FT_Int32        load_flags  = FT_LOAD_DE Line 105  FT_Int32        load_flags  = FT_LOAD_DE
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    
# Line 151  get_time(void) Line 148  get_time(void)
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  {  {
# Line 204  test_load( btimer_t*  timer, Line 202  test_load( btimer_t*  timer,
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 );
# Line 228  test_render( btimer_t*  timer, Line 226  test_render( btimer_t*  timer,
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 );
# Line 314  test_get_char_index( btimer_t*  timer, Line 312  test_get_char_index( btimer_t*  timer,
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    
# Line 338  test_cmap_cache( btimer_t*  timer, Line 335  test_cmap_cache( btimer_t*  timer,
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    {    {
# Line 351  test_cmap_cache( btimer_t*  timer, Line 349  test_cmap_cache( btimer_t*  timer,
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    
# Line 368  test_image_cache( btimer_t*  timer, Line 366  test_image_cache( btimer_t*  timer,
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 );
# Line 399  test_sbit_cache( btimer_t*  timer, Line 397  test_sbit_cache( btimer_t*  timer,
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 );
# Line 453  test_new_face( btimer_t*  timer, Line 451  test_new_face( btimer_t*  timer,
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 );
# Line 475  test_new_face( btimer_t*  timer, Line 473  test_new_face( btimer_t*  timer,
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 )
# Line 496  get_charset( FT_Face  face ) Line 495  get_charset( FT_Face  face )
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    
# Line 505  get_charset( FT_Face  face ) Line 504  get_charset( FT_Face  face )
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    
# Line 571  get_face( FT_Face*     face ) Line 570  get_face( FT_Face*     face )
570    
571  void usage(void)  void usage(void)
572  {  {
573    int i;    int  i;
574    
575    
576    fprintf( stderr,    fprintf( stderr,
# Line 608  int Line 607  int
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    {    {
# Line 646  main(int argc, Line 646  main(int argc,
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':
# Line 699  main(int argc, Line 699  main(int argc,
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;
# Line 726  main(int argc, Line 724  main(int argc,
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        {        {
# Line 734  main(int argc, Line 732  main(int argc,
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    }    }
# Line 786  main(int argc, Line 799  main(int argc,
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 );

Legend:
Removed from v.1.22  
changed lines
  Added in v.1.23

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26