From 4aaa0af7d99f7a44a02542ab8a8d467e3f6a3f64 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Mon, 2 May 2022 13:06:27 -0600 Subject: [PATCH 1/5] [perf/perf] Rely on hb-draw to measure ft performance --- perf/perf-draw.hh | 50 +++++++---------------------------------------- 1 file changed, 7 insertions(+), 43 deletions(-) diff --git a/perf/perf-draw.hh b/perf/perf-draw.hh index d31201e37..35c569081 100644 --- a/perf/perf-draw.hh +++ b/perf/perf-draw.hh @@ -2,8 +2,6 @@ #include "hb.h" #include "hb-ot.h" -#include "hb-ft.h" -#include FT_OUTLINE_H #ifdef HAVE_TTFPARSER #include "ttfparser.h" @@ -26,20 +24,6 @@ _hb_cubic_to (hb_draw_funcs_t *, void *, hb_draw_state_t *, float, float, float, static void _hb_close_path (hb_draw_funcs_t *, void *, hb_draw_state_t *, void *) {} -static void -_ft_move_to (const FT_Vector* to HB_UNUSED, void* user HB_UNUSED) {} - -static void -_ft_line_to (const FT_Vector* to HB_UNUSED, void* user HB_UNUSED) {} - -static void -_ft_conic_to (const FT_Vector* control HB_UNUSED, const FT_Vector* to HB_UNUSED, - void* user HB_UNUSED) {} - -static void -_ft_cubic_to (const FT_Vector* control1 HB_UNUSED, const FT_Vector* control2 HB_UNUSED, - const FT_Vector* to HB_UNUSED, void* user HB_UNUSED) {} - #ifdef HAVE_TTFPARSER static void _tp_move_to (float x HB_UNUSED, float y HB_UNUSED, void *data HB_UNUSED) {} static void _tp_line_to (float x, float y, void *data) {} @@ -62,7 +46,7 @@ static void draw (benchmark::State &state, const char *font_path, bool is_var, b hb_face_destroy (face); } - if (backend == HARFBUZZ) + if (backend == HARFBUZZ || backend == FREETYPE) { if (is_var) { @@ -76,38 +60,18 @@ static void draw (benchmark::State &state, const char *font_path, bool is_var, b hb_draw_funcs_set_cubic_to_func (draw_funcs, _hb_cubic_to, nullptr, nullptr); hb_draw_funcs_set_close_path_func (draw_funcs, _hb_close_path, nullptr, nullptr); + if (backend == FREETYPE) + { + hb_ft_font_set_funcs (font); + hb_ft_font_set_load_flags (font, FT_LOAD_NO_HINTING | FT_LOAD_NO_SCALE); + } + for (auto _ : state) for (unsigned gid = 0; gid < num_glyphs; ++gid) hb_font_get_glyph_shape (font, gid, draw_funcs, nullptr); hb_draw_funcs_destroy (draw_funcs); } - else if (backend == FREETYPE) - { - if (is_var) - { - hb_variation_t wght = {HB_TAG ('w','g','h','t'), 500}; - hb_font_set_variations (font, &wght, 1); - } - hb_ft_font_set_funcs (font); - FT_Face ft_face = hb_ft_font_get_face (font); - hb_ft_font_set_load_flags (font, FT_LOAD_NO_HINTING | FT_LOAD_NO_SCALE); - - FT_Outline_Funcs draw_funcs; - draw_funcs.move_to = (FT_Outline_MoveToFunc) _ft_move_to; - draw_funcs.line_to = (FT_Outline_LineToFunc) _ft_line_to; - draw_funcs.conic_to = (FT_Outline_ConicToFunc) _ft_conic_to; - draw_funcs.cubic_to = (FT_Outline_CubicToFunc) _ft_cubic_to; - draw_funcs.shift = 0; - draw_funcs.delta = 0; - - for (auto _ : state) - for (unsigned gid = 0; gid < num_glyphs; ++gid) - { - FT_Load_Glyph (ft_face, gid, FT_LOAD_NO_HINTING | FT_LOAD_NO_SCALE); - FT_Outline_Decompose (&ft_face->glyph->outline, &draw_funcs, nullptr); - } - } else if (backend == TTF_PARSER) { #ifdef HAVE_TTFPARSER From 746c3c03c5017b4e1404c65a04a5a6122a6cd831 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Mon, 2 May 2022 13:26:41 -0600 Subject: [PATCH 2/5] [perf/perf] Remove ttf-parser backend --- perf/meson.build | 11 +----- perf/perf-draw.hh | 91 +++++++++----------------------------------- perf/perf-extents.hh | 50 ++++-------------------- perf/perf.cc | 2 +- 4 files changed, 28 insertions(+), 126 deletions(-) diff --git a/perf/meson.build b/perf/meson.build index 97e8730af..bca43e13b 100644 --- a/perf/meson.build +++ b/perf/meson.build @@ -1,20 +1,11 @@ google_benchmark = subproject('google-benchmark') google_benchmark_dep = google_benchmark.get_variable('google_benchmark_dep') -ttf_parser_dep = null_dep -if get_option('experimental_api') and add_languages('rust', required: false, native: true) - ttf_parser_dep = subproject('ttf-parser').get_variable('ttf_parser_dep') -endif - benchmark('perf', executable('perf', 'perf.cc', dependencies: [ google_benchmark_dep, freetype_dep, - - # the last two, thread and dl, aren't nice as ttf-parser isn't no_std yet - # https://github.com/RazrFalcon/ttf-parser/issues/29 - ttf_parser_dep, thread_dep, cpp.find_library('dl'), ], - cpp_args: ttf_parser_dep.found() ? ['-DHAVE_TTFPARSER'] : [], + cpp_args: [], include_directories: [incconfig, incsrc], link_with: [libharfbuzz], install: false, diff --git a/perf/perf-draw.hh b/perf/perf-draw.hh index 35c569081..d7c8c31a4 100644 --- a/perf/perf-draw.hh +++ b/perf/perf-draw.hh @@ -3,12 +3,6 @@ #include "hb.h" #include "hb-ot.h" -#ifdef HAVE_TTFPARSER -#include "ttfparser.h" -#endif - -#define HB_UNUSED __attribute__((unused)) - static void _hb_move_to (hb_draw_funcs_t *, void *, hb_draw_state_t *, float, float, void *) {} @@ -24,14 +18,6 @@ _hb_cubic_to (hb_draw_funcs_t *, void *, hb_draw_state_t *, float, float, float, static void _hb_close_path (hb_draw_funcs_t *, void *, hb_draw_state_t *, void *) {} -#ifdef HAVE_TTFPARSER -static void _tp_move_to (float x HB_UNUSED, float y HB_UNUSED, void *data HB_UNUSED) {} -static void _tp_line_to (float x, float y, void *data) {} -static void _tp_quad_to (float x1, float y1, float x, float y, void *data) {} -static void _tp_curve_to (float x1, float y1, float x2, float y2, float x, float y, void *data) {} -static void _tp_close_path (void *data) {} -#endif - static void draw (benchmark::State &state, const char *font_path, bool is_var, backend_t backend) { hb_font_t *font; @@ -46,60 +32,29 @@ static void draw (benchmark::State &state, const char *font_path, bool is_var, b hb_face_destroy (face); } - if (backend == HARFBUZZ || backend == FREETYPE) + if (is_var) { - if (is_var) - { - hb_variation_t wght = {HB_TAG ('w','g','h','t'), 500}; - hb_font_set_variations (font, &wght, 1); - } - hb_draw_funcs_t *draw_funcs = hb_draw_funcs_create (); - hb_draw_funcs_set_move_to_func (draw_funcs, _hb_move_to, nullptr, nullptr); - hb_draw_funcs_set_line_to_func (draw_funcs, _hb_line_to, nullptr, nullptr); - hb_draw_funcs_set_quadratic_to_func (draw_funcs, _hb_quadratic_to, nullptr, nullptr); - hb_draw_funcs_set_cubic_to_func (draw_funcs, _hb_cubic_to, nullptr, nullptr); - hb_draw_funcs_set_close_path_func (draw_funcs, _hb_close_path, nullptr, nullptr); - - if (backend == FREETYPE) - { - hb_ft_font_set_funcs (font); - hb_ft_font_set_load_flags (font, FT_LOAD_NO_HINTING | FT_LOAD_NO_SCALE); - } - - for (auto _ : state) - for (unsigned gid = 0; gid < num_glyphs; ++gid) - hb_font_get_glyph_shape (font, gid, draw_funcs, nullptr); - - hb_draw_funcs_destroy (draw_funcs); + hb_variation_t wght = {HB_TAG ('w','g','h','t'), 500}; + hb_font_set_variations (font, &wght, 1); } - else if (backend == TTF_PARSER) + hb_draw_funcs_t *draw_funcs = hb_draw_funcs_create (); + hb_draw_funcs_set_move_to_func (draw_funcs, _hb_move_to, nullptr, nullptr); + hb_draw_funcs_set_line_to_func (draw_funcs, _hb_line_to, nullptr, nullptr); + hb_draw_funcs_set_quadratic_to_func (draw_funcs, _hb_quadratic_to, nullptr, nullptr); + hb_draw_funcs_set_cubic_to_func (draw_funcs, _hb_cubic_to, nullptr, nullptr); + hb_draw_funcs_set_close_path_func (draw_funcs, _hb_close_path, nullptr, nullptr); + + if (backend == FREETYPE) { -#ifdef HAVE_TTFPARSER - ttfp_face *tp_font = (ttfp_face *) malloc (ttfp_face_size_of ()); - hb_blob_t *blob = hb_face_reference_blob (hb_font_get_face (font)); - assert (ttfp_face_init (hb_blob_get_data (blob, nullptr), hb_blob_get_length (blob), 0, tp_font)); - if (is_var) ttfp_set_variation (tp_font, TTFP_TAG('w','g','h','t'), 500); - - ttfp_outline_builder builder; - builder.move_to = _tp_move_to; - builder.line_to = _tp_line_to; - builder.quad_to = _tp_quad_to; - builder.curve_to = _tp_curve_to; - builder.close_path = _tp_close_path; - - ttfp_rect bbox; - for (auto _ : state) - for (unsigned gid = 0; gid < num_glyphs; ++gid) - ttfp_outline_glyph (tp_font, builder, &builder, gid, &bbox); - - hb_blob_destroy (blob); - free (tp_font); -#else - state.SkipWithError("ttfparser not available."); - return; -#endif + hb_ft_font_set_funcs (font); + hb_ft_font_set_load_flags (font, FT_LOAD_NO_HINTING | FT_LOAD_NO_SCALE); } - else abort (); + + for (auto _ : state) + for (unsigned gid = 0; gid < num_glyphs; ++gid) + hb_font_get_glyph_shape (font, gid, draw_funcs, nullptr); + + hb_draw_funcs_destroy (draw_funcs); hb_font_destroy (font); } @@ -108,32 +63,24 @@ static void draw (benchmark::State &state, const char *font_path, bool is_var, b BENCHMARK_CAPTURE (draw, cff - ot - SourceSansPro, FONT_BASE_PATH "SourceSansPro-Regular.otf", false, HARFBUZZ); BENCHMARK_CAPTURE (draw, cff - ft - SourceSansPro, FONT_BASE_PATH "SourceSansPro-Regular.otf", false, FREETYPE); -BENCHMARK_CAPTURE (draw, cff - tp - SourceSansPro, FONT_BASE_PATH "SourceSansPro-Regular.otf", false, TTF_PARSER); BENCHMARK_CAPTURE (draw, cff2 - ot - AdobeVFPrototype, FONT_BASE_PATH "AdobeVFPrototype.otf", false, HARFBUZZ); BENCHMARK_CAPTURE (draw, cff2 - ft - AdobeVFPrototype, FONT_BASE_PATH "AdobeVFPrototype.otf", false, FREETYPE); -BENCHMARK_CAPTURE (draw, cff2 - tp - AdobeVFPrototype, FONT_BASE_PATH "AdobeVFPrototype.otf", false, TTF_PARSER); BENCHMARK_CAPTURE (draw, cff2/vf - ot - AdobeVFPrototype, FONT_BASE_PATH "AdobeVFPrototype.otf", true, HARFBUZZ); BENCHMARK_CAPTURE (draw, cff2/vf - ft - AdobeVFPrototype, FONT_BASE_PATH "AdobeVFPrototype.otf", true, FREETYPE); -BENCHMARK_CAPTURE (draw, cff2/vf - tp - AdobeVFPrototype, FONT_BASE_PATH "AdobeVFPrototype.otf", true, TTF_PARSER); BENCHMARK_CAPTURE (draw, glyf - ot - SourceSerifVariable, FONT_BASE_PATH "SourceSerifVariable-Roman.ttf", false, HARFBUZZ); BENCHMARK_CAPTURE (draw, glyf - ft - SourceSerifVariable, FONT_BASE_PATH "SourceSerifVariable-Roman.ttf", false, FREETYPE); -BENCHMARK_CAPTURE (draw, glyf - tp - SourceSerifVariable, FONT_BASE_PATH "SourceSerifVariable-Roman.ttf", false, TTF_PARSER); BENCHMARK_CAPTURE (draw, glyf/vf - ot - SourceSerifVariable, FONT_BASE_PATH "SourceSerifVariable-Roman.ttf", true, HARFBUZZ); BENCHMARK_CAPTURE (draw, glyf/vf - ft - SourceSerifVariable, FONT_BASE_PATH "SourceSerifVariable-Roman.ttf", true, FREETYPE); -BENCHMARK_CAPTURE (draw, glyf/vf - tp - SourceSerifVariable, FONT_BASE_PATH "SourceSerifVariable-Roman.ttf", true, TTF_PARSER); BENCHMARK_CAPTURE (draw, glyf - ot - Comfortaa, FONT_BASE_PATH "Comfortaa-Regular-new.ttf", false, HARFBUZZ); BENCHMARK_CAPTURE (draw, glyf - ft - Comfortaa, FONT_BASE_PATH "Comfortaa-Regular-new.ttf", false, FREETYPE); -BENCHMARK_CAPTURE (draw, glyf - tp - Comfortaa, FONT_BASE_PATH "Comfortaa-Regular-new.ttf", false, TTF_PARSER); BENCHMARK_CAPTURE (draw, glyf/vf - ot - Comfortaa, FONT_BASE_PATH "Comfortaa-Regular-new.ttf", true, HARFBUZZ); BENCHMARK_CAPTURE (draw, glyf/vf - ft - Comfortaa, FONT_BASE_PATH "Comfortaa-Regular-new.ttf", true, FREETYPE); -BENCHMARK_CAPTURE (draw, glyf/vf - tp - Comfortaa, FONT_BASE_PATH "Comfortaa-Regular-new.ttf", true, TTF_PARSER); BENCHMARK_CAPTURE (draw, glyf - ot - Roboto, FONT_BASE_PATH "Roboto-Regular.ttf", false, HARFBUZZ); BENCHMARK_CAPTURE (draw, glyf - ft - Roboto, FONT_BASE_PATH "Roboto-Regular.ttf", false, FREETYPE); -BENCHMARK_CAPTURE (draw, glyf - tp - Roboto, FONT_BASE_PATH "Roboto-Regular.ttf", false, TTF_PARSER); diff --git a/perf/perf-extents.hh b/perf/perf-extents.hh index c75252637..4abe841c4 100644 --- a/perf/perf-extents.hh +++ b/perf/perf-extents.hh @@ -4,10 +4,6 @@ #include "hb-ft.h" #include "hb-ot.h" -#ifdef HAVE_TTFPARSER -#include "ttfparser.h" -#endif - static void extents (benchmark::State &state, const char *font_path, bool is_var, backend_t backend) { hb_font_t *font; @@ -28,39 +24,16 @@ static void extents (benchmark::State &state, const char *font_path, bool is_var hb_font_set_variations (font, &wght, 1); } - if (backend == HARFBUZZ || backend == FREETYPE) + if (backend == FREETYPE) { - if (backend == FREETYPE) - { - hb_ft_font_set_funcs (font); - hb_ft_font_set_load_flags (font, FT_LOAD_NO_HINTING | FT_LOAD_NO_SCALE); - } - - hb_glyph_extents_t extents; - for (auto _ : state) - for (unsigned gid = 0; gid < num_glyphs; ++gid) - hb_font_get_glyph_extents (font, gid, &extents); + hb_ft_font_set_funcs (font); + hb_ft_font_set_load_flags (font, FT_LOAD_NO_HINTING | FT_LOAD_NO_SCALE); } - else if (backend == TTF_PARSER) - { -#ifdef HAVE_TTFPARSER - ttfp_face *tp_font = (ttfp_face *) malloc (ttfp_face_size_of ()); - hb_blob_t *blob = hb_face_reference_blob (hb_font_get_face (font)); - assert (ttfp_face_init (hb_blob_get_data (blob, nullptr), hb_blob_get_length (blob), 0, tp_font)); - if (is_var) ttfp_set_variation (tp_font, TTFP_TAG('w','g','h','t'), 500); - ttfp_rect bbox; - for (auto _ : state) - for (unsigned gid = 0; gid < num_glyphs; ++gid) - ttfp_get_glyph_bbox(tp_font, gid, &bbox); - - hb_blob_destroy (blob); - free (tp_font); -#else - state.SkipWithError("ttfparser not available."); - return; -#endif - } + hb_glyph_extents_t extents; + for (auto _ : state) + for (unsigned gid = 0; gid < num_glyphs; ++gid) + hb_font_get_glyph_extents (font, gid, &extents); hb_font_destroy (font); } @@ -69,33 +42,24 @@ static void extents (benchmark::State &state, const char *font_path, bool is_var BENCHMARK_CAPTURE (extents, cff - ot - SourceSansPro, FONT_BASE_PATH "SourceSansPro-Regular.otf", false, HARFBUZZ); BENCHMARK_CAPTURE (extents, cff - ft - SourceSansPro, FONT_BASE_PATH "SourceSansPro-Regular.otf", false, FREETYPE); -BENCHMARK_CAPTURE (extents, cff - tp - SourceSansPro, FONT_BASE_PATH "SourceSansPro-Regular.otf", false, TTF_PARSER); BENCHMARK_CAPTURE (extents, cff2 - ot - AdobeVFPrototype, FONT_BASE_PATH "AdobeVFPrototype.otf", false, HARFBUZZ); BENCHMARK_CAPTURE (extents, cff2 - ft - AdobeVFPrototype, FONT_BASE_PATH "AdobeVFPrototype.otf", false, FREETYPE); -BENCHMARK_CAPTURE (extents, cff2 - tp - AdobeVFPrototype, FONT_BASE_PATH "AdobeVFPrototype.otf", false, TTF_PARSER); BENCHMARK_CAPTURE (extents, cff2/vf - ot - AdobeVFPrototype, FONT_BASE_PATH "AdobeVFPrototype.otf", true, HARFBUZZ); BENCHMARK_CAPTURE (extents, cff2/vf - ft - AdobeVFPrototype, FONT_BASE_PATH "AdobeVFPrototype.otf", true, FREETYPE); -BENCHMARK_CAPTURE (extents, cff2/vf - tp - AdobeVFPrototype, FONT_BASE_PATH "AdobeVFPrototype.otf", true, TTF_PARSER); BENCHMARK_CAPTURE (extents, glyf - ot - SourceSerifVariable, FONT_BASE_PATH "SourceSerifVariable-Roman.ttf", false, HARFBUZZ); BENCHMARK_CAPTURE (extents, glyf - ft - SourceSerifVariable, FONT_BASE_PATH "SourceSerifVariable-Roman.ttf", false, FREETYPE); -BENCHMARK_CAPTURE (extents, glyf - tp - SourceSerifVariable, FONT_BASE_PATH "SourceSerifVariable-Roman.ttf", false, TTF_PARSER); BENCHMARK_CAPTURE (extents, glyf/vf - ot - SourceSerifVariable, FONT_BASE_PATH "SourceSerifVariable-Roman.ttf", true, HARFBUZZ); BENCHMARK_CAPTURE (extents, glyf/vf - ft - SourceSerifVariable, FONT_BASE_PATH "SourceSerifVariable-Roman.ttf", true, FREETYPE); -BENCHMARK_CAPTURE (extents, glyf/vf - tp - SourceSerifVariable, FONT_BASE_PATH "SourceSerifVariable-Roman.ttf", true, TTF_PARSER); BENCHMARK_CAPTURE (extents, glyf - ot - Comfortaa, FONT_BASE_PATH "Comfortaa-Regular-new.ttf", false, HARFBUZZ); BENCHMARK_CAPTURE (extents, glyf - ft - Comfortaa, FONT_BASE_PATH "Comfortaa-Regular-new.ttf", false, FREETYPE); -BENCHMARK_CAPTURE (extents, glyf - tp - Comfortaa, FONT_BASE_PATH "Comfortaa-Regular-new.ttf", false, TTF_PARSER); BENCHMARK_CAPTURE (extents, glyf/vf - ot - Comfortaa, FONT_BASE_PATH "Comfortaa-Regular-new.ttf", true, HARFBUZZ); BENCHMARK_CAPTURE (extents, glyf/vf - ft - Comfortaa, FONT_BASE_PATH "Comfortaa-Regular-new.ttf", true, FREETYPE); -BENCHMARK_CAPTURE (extents, glyf/vf - tp - Comfortaa, FONT_BASE_PATH "Comfortaa-Regular-new.ttf", true, TTF_PARSER); BENCHMARK_CAPTURE (extents, glyf - ot - Roboto, FONT_BASE_PATH "Roboto-Regular.ttf", false, HARFBUZZ); BENCHMARK_CAPTURE (extents, glyf - ft - Roboto, FONT_BASE_PATH "Roboto-Regular.ttf", false, FREETYPE); -BENCHMARK_CAPTURE (extents, glyf - tp - Roboto, FONT_BASE_PATH "Roboto-Regular.ttf", false, TTF_PARSER); - diff --git a/perf/perf.cc b/perf/perf.cc index bfe65d04b..7bd1461de 100644 --- a/perf/perf.cc +++ b/perf/perf.cc @@ -5,7 +5,7 @@ #endif #ifdef HAVE_FREETYPE -enum backend_t { HARFBUZZ, FREETYPE, TTF_PARSER }; +enum backend_t { HARFBUZZ, FREETYPE }; #include "perf-extents.hh" #include "perf-draw.hh" #endif From 036d03d2e91fc20133150696c405d3281326a552 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Mon, 2 May 2022 13:39:54 -0600 Subject: [PATCH 3/5] [perf/perf] Move all logic to perf-draw, for now To be renamed. --- perf/Makefile.am | 1 - perf/perf-draw.hh | 124 +++++++++++++++++++++++++++++++++++----------- perf/perf.cc | 10 ---- 3 files changed, 94 insertions(+), 41 deletions(-) diff --git a/perf/Makefile.am b/perf/Makefile.am index 5e08eebe7..9d5ed6791 100644 --- a/perf/Makefile.am +++ b/perf/Makefile.am @@ -7,7 +7,6 @@ SUBDIRS = EXTRA_DIST += meson.build \ perf-draw.hh \ - perf-extents.hh \ perf.cc \ benchmark-map.cc \ benchmark-set.cc \ diff --git a/perf/perf-draw.hh b/perf/perf-draw.hh index d7c8c31a4..ab22cdcce 100644 --- a/perf/perf-draw.hh +++ b/perf/perf-draw.hh @@ -2,6 +2,15 @@ #include "hb.h" #include "hb-ot.h" +#include "hb-ft.h" + +enum backend_t { HARFBUZZ, FREETYPE }; + +enum operation_t +{ + GLYPH_EXTENTS, + GLYPH_SHAPE, +}; static void _hb_move_to (hb_draw_funcs_t *, void *, hb_draw_state_t *, float, float, void *) {} @@ -18,7 +27,19 @@ _hb_cubic_to (hb_draw_funcs_t *, void *, hb_draw_state_t *, float, float, float, static void _hb_close_path (hb_draw_funcs_t *, void *, hb_draw_state_t *, void *) {} -static void draw (benchmark::State &state, const char *font_path, bool is_var, backend_t backend) +static hb_draw_funcs_t * +_draw_funcs_create (void) +{ + hb_draw_funcs_t *draw_funcs = hb_draw_funcs_create (); + hb_draw_funcs_set_move_to_func (draw_funcs, _hb_move_to, nullptr, nullptr); + hb_draw_funcs_set_line_to_func (draw_funcs, _hb_line_to, nullptr, nullptr); + hb_draw_funcs_set_quadratic_to_func (draw_funcs, _hb_quadratic_to, nullptr, nullptr); + hb_draw_funcs_set_cubic_to_func (draw_funcs, _hb_cubic_to, nullptr, nullptr); + hb_draw_funcs_set_close_path_func (draw_funcs, _hb_close_path, nullptr, nullptr); + return draw_funcs; +} + +static void BM_test (benchmark::State &state, const char *font_path, bool is_var, backend_t backend, operation_t operation) { hb_font_t *font; unsigned num_glyphs; @@ -37,50 +58,93 @@ static void draw (benchmark::State &state, const char *font_path, bool is_var, b hb_variation_t wght = {HB_TAG ('w','g','h','t'), 500}; hb_font_set_variations (font, &wght, 1); } - hb_draw_funcs_t *draw_funcs = hb_draw_funcs_create (); - hb_draw_funcs_set_move_to_func (draw_funcs, _hb_move_to, nullptr, nullptr); - hb_draw_funcs_set_line_to_func (draw_funcs, _hb_line_to, nullptr, nullptr); - hb_draw_funcs_set_quadratic_to_func (draw_funcs, _hb_quadratic_to, nullptr, nullptr); - hb_draw_funcs_set_cubic_to_func (draw_funcs, _hb_cubic_to, nullptr, nullptr); - hb_draw_funcs_set_close_path_func (draw_funcs, _hb_close_path, nullptr, nullptr); - if (backend == FREETYPE) + switch (backend) { - hb_ft_font_set_funcs (font); - hb_ft_font_set_load_flags (font, FT_LOAD_NO_HINTING | FT_LOAD_NO_SCALE); + case HARFBUZZ: + hb_ot_font_set_funcs (font); + break; + + case FREETYPE: + hb_ft_font_set_funcs (font); + break; } - for (auto _ : state) - for (unsigned gid = 0; gid < num_glyphs; ++gid) - hb_font_get_glyph_shape (font, gid, draw_funcs, nullptr); + switch (operation) + { + case GLYPH_EXTENTS: + { + hb_glyph_extents_t extents; + for (auto _ : state) + for (unsigned gid = 0; gid < num_glyphs; ++gid) + hb_font_get_glyph_extents (font, gid, &extents); + break; + } + case GLYPH_SHAPE: + { + hb_draw_funcs_t *draw_funcs = _draw_funcs_create (); + for (auto _ : state) + for (unsigned gid = 0; gid < num_glyphs; ++gid) + hb_font_get_glyph_shape (font, gid, draw_funcs, nullptr); + break; + hb_draw_funcs_destroy (draw_funcs); + } + } - hb_draw_funcs_destroy (draw_funcs); hb_font_destroy (font); } #define FONT_BASE_PATH "test/subset/data/fonts/" -BENCHMARK_CAPTURE (draw, cff - ot - SourceSansPro, FONT_BASE_PATH "SourceSansPro-Regular.otf", false, HARFBUZZ); -BENCHMARK_CAPTURE (draw, cff - ft - SourceSansPro, FONT_BASE_PATH "SourceSansPro-Regular.otf", false, FREETYPE); -BENCHMARK_CAPTURE (draw, cff2 - ot - AdobeVFPrototype, FONT_BASE_PATH "AdobeVFPrototype.otf", false, HARFBUZZ); -BENCHMARK_CAPTURE (draw, cff2 - ft - AdobeVFPrototype, FONT_BASE_PATH "AdobeVFPrototype.otf", false, FREETYPE); +BENCHMARK_CAPTURE (BM_test, GLYPH_EXTENTS/cff - ot - SourceSansPro, FONT_BASE_PATH "SourceSansPro-Regular.otf", false, HARFBUZZ, GLYPH_EXTENTS); +BENCHMARK_CAPTURE (BM_test, GLYPH_EXTENTS/cff - ft - SourceSansPro, FONT_BASE_PATH "SourceSansPro-Regular.otf", false, FREETYPE, GLYPH_EXTENTS); -BENCHMARK_CAPTURE (draw, cff2/vf - ot - AdobeVFPrototype, FONT_BASE_PATH "AdobeVFPrototype.otf", true, HARFBUZZ); -BENCHMARK_CAPTURE (draw, cff2/vf - ft - AdobeVFPrototype, FONT_BASE_PATH "AdobeVFPrototype.otf", true, FREETYPE); +BENCHMARK_CAPTURE (BM_test, GLYPH_EXTENTS/cff2 - ot - AdobeVFPrototype, FONT_BASE_PATH "AdobeVFPrototype.otf", false, HARFBUZZ, GLYPH_EXTENTS); +BENCHMARK_CAPTURE (BM_test, GLYPH_EXTENTS/cff2 - ft - AdobeVFPrototype, FONT_BASE_PATH "AdobeVFPrototype.otf", false, FREETYPE, GLYPH_EXTENTS); -BENCHMARK_CAPTURE (draw, glyf - ot - SourceSerifVariable, FONT_BASE_PATH "SourceSerifVariable-Roman.ttf", false, HARFBUZZ); -BENCHMARK_CAPTURE (draw, glyf - ft - SourceSerifVariable, FONT_BASE_PATH "SourceSerifVariable-Roman.ttf", false, FREETYPE); +BENCHMARK_CAPTURE (BM_test, GLYPH_EXTENTS/cff2/vf - ot - AdobeVFPrototype, FONT_BASE_PATH "AdobeVFPrototype.otf", true, HARFBUZZ, GLYPH_EXTENTS); +BENCHMARK_CAPTURE (BM_test, GLYPH_EXTENTS/cff2/vf - ft - AdobeVFPrototype, FONT_BASE_PATH "AdobeVFPrototype.otf", true, FREETYPE, GLYPH_EXTENTS); -BENCHMARK_CAPTURE (draw, glyf/vf - ot - SourceSerifVariable, FONT_BASE_PATH "SourceSerifVariable-Roman.ttf", true, HARFBUZZ); -BENCHMARK_CAPTURE (draw, glyf/vf - ft - SourceSerifVariable, FONT_BASE_PATH "SourceSerifVariable-Roman.ttf", true, FREETYPE); +BENCHMARK_CAPTURE (BM_test, GLYPH_EXTENTS/glyf - ot - SourceSerifVariable, FONT_BASE_PATH "SourceSerifVariable-Roman.ttf", false, HARFBUZZ, GLYPH_EXTENTS); +BENCHMARK_CAPTURE (BM_test, GLYPH_EXTENTS/glyf - ft - SourceSerifVariable, FONT_BASE_PATH "SourceSerifVariable-Roman.ttf", false, FREETYPE, GLYPH_EXTENTS); -BENCHMARK_CAPTURE (draw, glyf - ot - Comfortaa, FONT_BASE_PATH "Comfortaa-Regular-new.ttf", false, HARFBUZZ); -BENCHMARK_CAPTURE (draw, glyf - ft - Comfortaa, FONT_BASE_PATH "Comfortaa-Regular-new.ttf", false, FREETYPE); +BENCHMARK_CAPTURE (BM_test, GLYPH_EXTENTS/glyf/vf - ot - SourceSerifVariable, FONT_BASE_PATH "SourceSerifVariable-Roman.ttf", true, HARFBUZZ, GLYPH_EXTENTS); +BENCHMARK_CAPTURE (BM_test, GLYPH_EXTENTS/glyf/vf - ft - SourceSerifVariable, FONT_BASE_PATH "SourceSerifVariable-Roman.ttf", true, FREETYPE, GLYPH_EXTENTS); -BENCHMARK_CAPTURE (draw, glyf/vf - ot - Comfortaa, FONT_BASE_PATH "Comfortaa-Regular-new.ttf", true, HARFBUZZ); -BENCHMARK_CAPTURE (draw, glyf/vf - ft - Comfortaa, FONT_BASE_PATH "Comfortaa-Regular-new.ttf", true, FREETYPE); +BENCHMARK_CAPTURE (BM_test, GLYPH_EXTENTS/glyf - ot - Comfortaa, FONT_BASE_PATH "Comfortaa-Regular-new.ttf", false, HARFBUZZ, GLYPH_EXTENTS); +BENCHMARK_CAPTURE (BM_test, GLYPH_EXTENTS/glyf - ft - Comfortaa, FONT_BASE_PATH "Comfortaa-Regular-new.ttf", false, FREETYPE, GLYPH_EXTENTS); -BENCHMARK_CAPTURE (draw, glyf - ot - Roboto, FONT_BASE_PATH "Roboto-Regular.ttf", false, HARFBUZZ); -BENCHMARK_CAPTURE (draw, glyf - ft - Roboto, FONT_BASE_PATH "Roboto-Regular.ttf", false, FREETYPE); +BENCHMARK_CAPTURE (BM_test, GLYPH_EXTENTS/glyf/vf - ot - Comfortaa, FONT_BASE_PATH "Comfortaa-Regular-new.ttf", true, HARFBUZZ, GLYPH_EXTENTS); +BENCHMARK_CAPTURE (BM_test, GLYPH_EXTENTS/glyf/vf - ft - Comfortaa, FONT_BASE_PATH "Comfortaa-Regular-new.ttf", true, FREETYPE, GLYPH_EXTENTS); + +BENCHMARK_CAPTURE (BM_test, GLYPH_EXTENTS/glyf - ot - Roboto, FONT_BASE_PATH "Roboto-Regular.ttf", false, HARFBUZZ, GLYPH_EXTENTS); +BENCHMARK_CAPTURE (BM_test, GLYPH_EXTENTS/glyf - ft - Roboto, FONT_BASE_PATH "Roboto-Regular.ttf", false, FREETYPE, GLYPH_EXTENTS); + + +BENCHMARK_CAPTURE (BM_test, GLYPH_SHAPE/cff - ot - SourceSansPro, FONT_BASE_PATH "SourceSansPro-Regular.otf", false, HARFBUZZ, GLYPH_SHAPE); +BENCHMARK_CAPTURE (BM_test, GLYPH_SHAPE/cff - ft - SourceSansPro, FONT_BASE_PATH "SourceSansPro-Regular.otf", false, FREETYPE, GLYPH_SHAPE); + +BENCHMARK_CAPTURE (BM_test, GLYPH_SHAPE/cff2 - ot - AdobeVFPrototype, FONT_BASE_PATH "AdobeVFPrototype.otf", false, HARFBUZZ, GLYPH_SHAPE); +BENCHMARK_CAPTURE (BM_test, GLYPH_SHAPE/cff2 - ft - AdobeVFPrototype, FONT_BASE_PATH "AdobeVFPrototype.otf", false, FREETYPE, GLYPH_SHAPE); + +BENCHMARK_CAPTURE (BM_test, GLYPH_SHAPE/cff2/vf - ot - AdobeVFPrototype, FONT_BASE_PATH "AdobeVFPrototype.otf", true, HARFBUZZ, GLYPH_SHAPE); +BENCHMARK_CAPTURE (BM_test, GLYPH_SHAPE/cff2/vf - ft - AdobeVFPrototype, FONT_BASE_PATH "AdobeVFPrototype.otf", true, FREETYPE, GLYPH_SHAPE); + +BENCHMARK_CAPTURE (BM_test, GLYPH_SHAPE/glyf - ot - SourceSerifVariable, FONT_BASE_PATH "SourceSerifVariable-Roman.ttf", false, HARFBUZZ, GLYPH_SHAPE); +BENCHMARK_CAPTURE (BM_test, GLYPH_SHAPE/glyf - ft - SourceSerifVariable, FONT_BASE_PATH "SourceSerifVariable-Roman.ttf", false, FREETYPE, GLYPH_SHAPE); + +BENCHMARK_CAPTURE (BM_test, GLYPH_SHAPE/glyf/vf - ot - SourceSerifVariable, FONT_BASE_PATH "SourceSerifVariable-Roman.ttf", true, HARFBUZZ, GLYPH_SHAPE); +BENCHMARK_CAPTURE (BM_test, GLYPH_SHAPE/glyf/vf - ft - SourceSerifVariable, FONT_BASE_PATH "SourceSerifVariable-Roman.ttf", true, FREETYPE, GLYPH_SHAPE); + +BENCHMARK_CAPTURE (BM_test, GLYPH_SHAPE/glyf - ot - Comfortaa, FONT_BASE_PATH "Comfortaa-Regular-new.ttf", false, HARFBUZZ, GLYPH_SHAPE); +BENCHMARK_CAPTURE (BM_test, GLYPH_SHAPE/glyf - ft - Comfortaa, FONT_BASE_PATH "Comfortaa-Regular-new.ttf", false, FREETYPE, GLYPH_SHAPE); + +BENCHMARK_CAPTURE (BM_test, GLYPH_SHAPE/glyf/vf - ot - Comfortaa, FONT_BASE_PATH "Comfortaa-Regular-new.ttf", true, HARFBUZZ, GLYPH_SHAPE); +BENCHMARK_CAPTURE (BM_test, GLYPH_SHAPE/glyf/vf - ft - Comfortaa, FONT_BASE_PATH "Comfortaa-Regular-new.ttf", true, FREETYPE, GLYPH_SHAPE); + +BENCHMARK_CAPTURE (BM_test, GLYPH_SHAPE/glyf - ot - Roboto, FONT_BASE_PATH "Roboto-Regular.ttf", false, HARFBUZZ, GLYPH_SHAPE); +BENCHMARK_CAPTURE (BM_test, GLYPH_SHAPE/glyf - ft - Roboto, FONT_BASE_PATH "Roboto-Regular.ttf", false, FREETYPE, GLYPH_SHAPE); + +BENCHMARK_MAIN (); diff --git a/perf/perf.cc b/perf/perf.cc index 7bd1461de..2c5cad85b 100644 --- a/perf/perf.cc +++ b/perf/perf.cc @@ -1,13 +1,3 @@ -#include "benchmark/benchmark.h" -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#ifdef HAVE_FREETYPE -enum backend_t { HARFBUZZ, FREETYPE }; -#include "perf-extents.hh" #include "perf-draw.hh" -#endif -BENCHMARK_MAIN (); From 636c90e81c2eb9a907a1c14d0f3450902d95f65a Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Mon, 2 May 2022 13:41:49 -0600 Subject: [PATCH 4/5] [perf/perf] Rename to benchmark-font --- perf/Makefile.am | 3 +- perf/{perf-draw.hh => benchmark-font.cc} | 0 perf/meson.build | 7 ++- perf/perf-extents.hh | 65 ------------------------ perf/perf.cc | 3 -- 5 files changed, 4 insertions(+), 74 deletions(-) rename perf/{perf-draw.hh => benchmark-font.cc} (100%) delete mode 100644 perf/perf-extents.hh delete mode 100644 perf/perf.cc diff --git a/perf/Makefile.am b/perf/Makefile.am index 9d5ed6791..78ca3bafb 100644 --- a/perf/Makefile.am +++ b/perf/Makefile.am @@ -6,8 +6,7 @@ SUBDIRS = EXTRA_DIST += meson.build \ - perf-draw.hh \ - perf.cc \ + benchmark-font.cc \ benchmark-map.cc \ benchmark-set.cc \ benchmark-shape.cc \ diff --git a/perf/perf-draw.hh b/perf/benchmark-font.cc similarity index 100% rename from perf/perf-draw.hh rename to perf/benchmark-font.cc diff --git a/perf/meson.build b/perf/meson.build index bca43e13b..93d7b4d7c 100644 --- a/perf/meson.build +++ b/perf/meson.build @@ -1,7 +1,7 @@ google_benchmark = subproject('google-benchmark') google_benchmark_dep = google_benchmark.get_variable('google_benchmark_dep') -benchmark('perf', executable('perf', 'perf.cc', +benchmark('benchmark-font', executable('benchmark-font', 'benchmark-font.cc', dependencies: [ google_benchmark_dep, freetype_dep, ], @@ -11,8 +11,7 @@ benchmark('perf', executable('perf', 'perf.cc', install: false, ), workdir: meson.current_source_dir() / '..', timeout: 100) - -benchmark('benchmark-shape', executable('benchmark-shape', 'benchmark-shape.cc', +benchmark('benchmark-map', executable('benchmark-map', 'benchmark-map.cc', dependencies: [ google_benchmark_dep, ], @@ -32,7 +31,7 @@ benchmark('benchmark-set', executable('benchmark-set', 'benchmark-set.cc', install: false, ), workdir: meson.current_source_dir() / '..', timeout: 100) -benchmark('benchmark-map', executable('benchmark-map', 'benchmark-map.cc', +benchmark('benchmark-shape', executable('benchmark-shape', 'benchmark-shape.cc', dependencies: [ google_benchmark_dep, ], diff --git a/perf/perf-extents.hh b/perf/perf-extents.hh deleted file mode 100644 index 4abe841c4..000000000 --- a/perf/perf-extents.hh +++ /dev/null @@ -1,65 +0,0 @@ -#include "benchmark/benchmark.h" - -#include "hb.h" -#include "hb-ft.h" -#include "hb-ot.h" - -static void extents (benchmark::State &state, const char *font_path, bool is_var, backend_t backend) -{ - hb_font_t *font; - unsigned num_glyphs; - { - hb_blob_t *blob = hb_blob_create_from_file_or_fail (font_path); - assert (blob); - hb_face_t *face = hb_face_create (blob, 0); - hb_blob_destroy (blob); - num_glyphs = hb_face_get_glyph_count (face); - font = hb_font_create (face); - hb_face_destroy (face); - } - - if (is_var) - { - hb_variation_t wght = {HB_TAG ('w','g','h','t'), 500}; - hb_font_set_variations (font, &wght, 1); - } - - if (backend == FREETYPE) - { - hb_ft_font_set_funcs (font); - hb_ft_font_set_load_flags (font, FT_LOAD_NO_HINTING | FT_LOAD_NO_SCALE); - } - - hb_glyph_extents_t extents; - for (auto _ : state) - for (unsigned gid = 0; gid < num_glyphs; ++gid) - hb_font_get_glyph_extents (font, gid, &extents); - - hb_font_destroy (font); -} - -#define FONT_BASE_PATH "test/subset/data/fonts/" - -BENCHMARK_CAPTURE (extents, cff - ot - SourceSansPro, FONT_BASE_PATH "SourceSansPro-Regular.otf", false, HARFBUZZ); -BENCHMARK_CAPTURE (extents, cff - ft - SourceSansPro, FONT_BASE_PATH "SourceSansPro-Regular.otf", false, FREETYPE); - -BENCHMARK_CAPTURE (extents, cff2 - ot - AdobeVFPrototype, FONT_BASE_PATH "AdobeVFPrototype.otf", false, HARFBUZZ); -BENCHMARK_CAPTURE (extents, cff2 - ft - AdobeVFPrototype, FONT_BASE_PATH "AdobeVFPrototype.otf", false, FREETYPE); - -BENCHMARK_CAPTURE (extents, cff2/vf - ot - AdobeVFPrototype, FONT_BASE_PATH "AdobeVFPrototype.otf", true, HARFBUZZ); -BENCHMARK_CAPTURE (extents, cff2/vf - ft - AdobeVFPrototype, FONT_BASE_PATH "AdobeVFPrototype.otf", true, FREETYPE); - -BENCHMARK_CAPTURE (extents, glyf - ot - SourceSerifVariable, FONT_BASE_PATH "SourceSerifVariable-Roman.ttf", false, HARFBUZZ); -BENCHMARK_CAPTURE (extents, glyf - ft - SourceSerifVariable, FONT_BASE_PATH "SourceSerifVariable-Roman.ttf", false, FREETYPE); - -BENCHMARK_CAPTURE (extents, glyf/vf - ot - SourceSerifVariable, FONT_BASE_PATH "SourceSerifVariable-Roman.ttf", true, HARFBUZZ); -BENCHMARK_CAPTURE (extents, glyf/vf - ft - SourceSerifVariable, FONT_BASE_PATH "SourceSerifVariable-Roman.ttf", true, FREETYPE); - -BENCHMARK_CAPTURE (extents, glyf - ot - Comfortaa, FONT_BASE_PATH "Comfortaa-Regular-new.ttf", false, HARFBUZZ); -BENCHMARK_CAPTURE (extents, glyf - ft - Comfortaa, FONT_BASE_PATH "Comfortaa-Regular-new.ttf", false, FREETYPE); - -BENCHMARK_CAPTURE (extents, glyf/vf - ot - Comfortaa, FONT_BASE_PATH "Comfortaa-Regular-new.ttf", true, HARFBUZZ); -BENCHMARK_CAPTURE (extents, glyf/vf - ft - Comfortaa, FONT_BASE_PATH "Comfortaa-Regular-new.ttf", true, FREETYPE); - -BENCHMARK_CAPTURE (extents, glyf - ot - Roboto, FONT_BASE_PATH "Roboto-Regular.ttf", false, HARFBUZZ); -BENCHMARK_CAPTURE (extents, glyf - ft - Roboto, FONT_BASE_PATH "Roboto-Regular.ttf", false, FREETYPE); diff --git a/perf/perf.cc b/perf/perf.cc deleted file mode 100644 index 2c5cad85b..000000000 --- a/perf/perf.cc +++ /dev/null @@ -1,3 +0,0 @@ - -#include "perf-draw.hh" - From 6d29903e86d1f6b0fe7ca884a071d047f0ee130b Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Mon, 2 May 2022 14:03:15 -0600 Subject: [PATCH 5/5] [perf/benchmark-font] Parametrize test --- perf/benchmark-font.cc | 113 +++++++++++++++++++++------------------- perf/benchmark-shape.cc | 2 + 2 files changed, 62 insertions(+), 53 deletions(-) diff --git a/perf/benchmark-font.cc b/perf/benchmark-font.cc index ab22cdcce..e56fb60fc 100644 --- a/perf/benchmark-font.cc +++ b/perf/benchmark-font.cc @@ -4,12 +4,31 @@ #include "hb-ot.h" #include "hb-ft.h" + +#define SUBSET_FONT_BASE_PATH "test/subset/data/fonts/" + +struct test_input_t +{ + const char *font_path; +} tests[] = +{ + {SUBSET_FONT_BASE_PATH "SourceSansPro-Regular.otf"}, + {SUBSET_FONT_BASE_PATH "AdobeVFPrototype.otf"}, + {SUBSET_FONT_BASE_PATH "AdobeVFPrototype.otf"}, + {SUBSET_FONT_BASE_PATH "SourceSerifVariable-Roman.ttf"}, + {SUBSET_FONT_BASE_PATH "SourceSerifVariable-Roman.ttf"}, + {SUBSET_FONT_BASE_PATH "Comfortaa-Regular-new.ttf"}, + {SUBSET_FONT_BASE_PATH "Comfortaa-Regular-new.ttf"}, + {SUBSET_FONT_BASE_PATH "Roboto-Regular.ttf"}, +}; + + enum backend_t { HARFBUZZ, FREETYPE }; enum operation_t { - GLYPH_EXTENTS, - GLYPH_SHAPE, + glyph_extents, + glyph_shape, }; static void @@ -39,12 +58,14 @@ _draw_funcs_create (void) return draw_funcs; } -static void BM_test (benchmark::State &state, const char *font_path, bool is_var, backend_t backend, operation_t operation) +static void BM_Font (benchmark::State &state, + bool is_var, backend_t backend, operation_t operation, + const test_input_t &test_input) { hb_font_t *font; unsigned num_glyphs; { - hb_blob_t *blob = hb_blob_create_from_file_or_fail (font_path); + hb_blob_t *blob = hb_blob_create_from_file_or_fail (test_input.font_path); assert (blob); hb_face_t *face = hb_face_create (blob, 0); hb_blob_destroy (blob); @@ -72,7 +93,7 @@ static void BM_test (benchmark::State &state, const char *font_path, bool is_var switch (operation) { - case GLYPH_EXTENTS: + case glyph_extents: { hb_glyph_extents_t extents; for (auto _ : state) @@ -80,7 +101,7 @@ static void BM_test (benchmark::State &state, const char *font_path, bool is_var hb_font_get_glyph_extents (font, gid, &extents); break; } - case GLYPH_SHAPE: + case glyph_shape: { hb_draw_funcs_t *draw_funcs = _draw_funcs_create (); for (auto _ : state) @@ -95,56 +116,42 @@ static void BM_test (benchmark::State &state, const char *font_path, bool is_var hb_font_destroy (font); } -#define FONT_BASE_PATH "test/subset/data/fonts/" +static void test_backend (backend_t backend, + const char *backend_name, + operation_t op, + const char *op_name, + const test_input_t &test_input) +{ + char name[1024] = "BM_Font/"; + strcat (name, op_name); + strcat (name, "/"); + strcat (name, backend_name); + strcat (name, strrchr (test_input.font_path, '/')); + benchmark::RegisterBenchmark (name, BM_Font, false, backend, op, test_input) + ->Unit(benchmark::kMicrosecond); +} -BENCHMARK_CAPTURE (BM_test, GLYPH_EXTENTS/cff - ot - SourceSansPro, FONT_BASE_PATH "SourceSansPro-Regular.otf", false, HARFBUZZ, GLYPH_EXTENTS); -BENCHMARK_CAPTURE (BM_test, GLYPH_EXTENTS/cff - ft - SourceSansPro, FONT_BASE_PATH "SourceSansPro-Regular.otf", false, FREETYPE, GLYPH_EXTENTS); +static void test_operation (operation_t op, + const char *op_name) +{ + for (auto& test_input : tests) + { + test_backend (HARFBUZZ, "hb", op, op_name, test_input); + test_backend (FREETYPE, "ft", op, op_name, test_input); + } +} -BENCHMARK_CAPTURE (BM_test, GLYPH_EXTENTS/cff2 - ot - AdobeVFPrototype, FONT_BASE_PATH "AdobeVFPrototype.otf", false, HARFBUZZ, GLYPH_EXTENTS); -BENCHMARK_CAPTURE (BM_test, GLYPH_EXTENTS/cff2 - ft - AdobeVFPrototype, FONT_BASE_PATH "AdobeVFPrototype.otf", false, FREETYPE, GLYPH_EXTENTS); +int main(int argc, char** argv) +{ +#define TEST_OPERATION(op) test_operation (op, #op) -BENCHMARK_CAPTURE (BM_test, GLYPH_EXTENTS/cff2/vf - ot - AdobeVFPrototype, FONT_BASE_PATH "AdobeVFPrototype.otf", true, HARFBUZZ, GLYPH_EXTENTS); -BENCHMARK_CAPTURE (BM_test, GLYPH_EXTENTS/cff2/vf - ft - AdobeVFPrototype, FONT_BASE_PATH "AdobeVFPrototype.otf", true, FREETYPE, GLYPH_EXTENTS); + TEST_OPERATION (glyph_extents); + TEST_OPERATION (glyph_shape); -BENCHMARK_CAPTURE (BM_test, GLYPH_EXTENTS/glyf - ot - SourceSerifVariable, FONT_BASE_PATH "SourceSerifVariable-Roman.ttf", false, HARFBUZZ, GLYPH_EXTENTS); -BENCHMARK_CAPTURE (BM_test, GLYPH_EXTENTS/glyf - ft - SourceSerifVariable, FONT_BASE_PATH "SourceSerifVariable-Roman.ttf", false, FREETYPE, GLYPH_EXTENTS); +#undef TEST_OPERATION -BENCHMARK_CAPTURE (BM_test, GLYPH_EXTENTS/glyf/vf - ot - SourceSerifVariable, FONT_BASE_PATH "SourceSerifVariable-Roman.ttf", true, HARFBUZZ, GLYPH_EXTENTS); -BENCHMARK_CAPTURE (BM_test, GLYPH_EXTENTS/glyf/vf - ft - SourceSerifVariable, FONT_BASE_PATH "SourceSerifVariable-Roman.ttf", true, FREETYPE, GLYPH_EXTENTS); - -BENCHMARK_CAPTURE (BM_test, GLYPH_EXTENTS/glyf - ot - Comfortaa, FONT_BASE_PATH "Comfortaa-Regular-new.ttf", false, HARFBUZZ, GLYPH_EXTENTS); -BENCHMARK_CAPTURE (BM_test, GLYPH_EXTENTS/glyf - ft - Comfortaa, FONT_BASE_PATH "Comfortaa-Regular-new.ttf", false, FREETYPE, GLYPH_EXTENTS); - -BENCHMARK_CAPTURE (BM_test, GLYPH_EXTENTS/glyf/vf - ot - Comfortaa, FONT_BASE_PATH "Comfortaa-Regular-new.ttf", true, HARFBUZZ, GLYPH_EXTENTS); -BENCHMARK_CAPTURE (BM_test, GLYPH_EXTENTS/glyf/vf - ft - Comfortaa, FONT_BASE_PATH "Comfortaa-Regular-new.ttf", true, FREETYPE, GLYPH_EXTENTS); - -BENCHMARK_CAPTURE (BM_test, GLYPH_EXTENTS/glyf - ot - Roboto, FONT_BASE_PATH "Roboto-Regular.ttf", false, HARFBUZZ, GLYPH_EXTENTS); -BENCHMARK_CAPTURE (BM_test, GLYPH_EXTENTS/glyf - ft - Roboto, FONT_BASE_PATH "Roboto-Regular.ttf", false, FREETYPE, GLYPH_EXTENTS); - - -BENCHMARK_CAPTURE (BM_test, GLYPH_SHAPE/cff - ot - SourceSansPro, FONT_BASE_PATH "SourceSansPro-Regular.otf", false, HARFBUZZ, GLYPH_SHAPE); -BENCHMARK_CAPTURE (BM_test, GLYPH_SHAPE/cff - ft - SourceSansPro, FONT_BASE_PATH "SourceSansPro-Regular.otf", false, FREETYPE, GLYPH_SHAPE); - -BENCHMARK_CAPTURE (BM_test, GLYPH_SHAPE/cff2 - ot - AdobeVFPrototype, FONT_BASE_PATH "AdobeVFPrototype.otf", false, HARFBUZZ, GLYPH_SHAPE); -BENCHMARK_CAPTURE (BM_test, GLYPH_SHAPE/cff2 - ft - AdobeVFPrototype, FONT_BASE_PATH "AdobeVFPrototype.otf", false, FREETYPE, GLYPH_SHAPE); - -BENCHMARK_CAPTURE (BM_test, GLYPH_SHAPE/cff2/vf - ot - AdobeVFPrototype, FONT_BASE_PATH "AdobeVFPrototype.otf", true, HARFBUZZ, GLYPH_SHAPE); -BENCHMARK_CAPTURE (BM_test, GLYPH_SHAPE/cff2/vf - ft - AdobeVFPrototype, FONT_BASE_PATH "AdobeVFPrototype.otf", true, FREETYPE, GLYPH_SHAPE); - -BENCHMARK_CAPTURE (BM_test, GLYPH_SHAPE/glyf - ot - SourceSerifVariable, FONT_BASE_PATH "SourceSerifVariable-Roman.ttf", false, HARFBUZZ, GLYPH_SHAPE); -BENCHMARK_CAPTURE (BM_test, GLYPH_SHAPE/glyf - ft - SourceSerifVariable, FONT_BASE_PATH "SourceSerifVariable-Roman.ttf", false, FREETYPE, GLYPH_SHAPE); - -BENCHMARK_CAPTURE (BM_test, GLYPH_SHAPE/glyf/vf - ot - SourceSerifVariable, FONT_BASE_PATH "SourceSerifVariable-Roman.ttf", true, HARFBUZZ, GLYPH_SHAPE); -BENCHMARK_CAPTURE (BM_test, GLYPH_SHAPE/glyf/vf - ft - SourceSerifVariable, FONT_BASE_PATH "SourceSerifVariable-Roman.ttf", true, FREETYPE, GLYPH_SHAPE); - -BENCHMARK_CAPTURE (BM_test, GLYPH_SHAPE/glyf - ot - Comfortaa, FONT_BASE_PATH "Comfortaa-Regular-new.ttf", false, HARFBUZZ, GLYPH_SHAPE); -BENCHMARK_CAPTURE (BM_test, GLYPH_SHAPE/glyf - ft - Comfortaa, FONT_BASE_PATH "Comfortaa-Regular-new.ttf", false, FREETYPE, GLYPH_SHAPE); - -BENCHMARK_CAPTURE (BM_test, GLYPH_SHAPE/glyf/vf - ot - Comfortaa, FONT_BASE_PATH "Comfortaa-Regular-new.ttf", true, HARFBUZZ, GLYPH_SHAPE); -BENCHMARK_CAPTURE (BM_test, GLYPH_SHAPE/glyf/vf - ft - Comfortaa, FONT_BASE_PATH "Comfortaa-Regular-new.ttf", true, FREETYPE, GLYPH_SHAPE); - -BENCHMARK_CAPTURE (BM_test, GLYPH_SHAPE/glyf - ot - Roboto, FONT_BASE_PATH "Roboto-Regular.ttf", false, HARFBUZZ, GLYPH_SHAPE); -BENCHMARK_CAPTURE (BM_test, GLYPH_SHAPE/glyf - ft - Roboto, FONT_BASE_PATH "Roboto-Regular.ttf", false, FREETYPE, GLYPH_SHAPE); - -BENCHMARK_MAIN (); + benchmark::Initialize(&argc, argv); + benchmark::RunSpecifiedBenchmarks(); + benchmark::Shutdown(); +} diff --git a/perf/benchmark-shape.cc b/perf/benchmark-shape.cc index d19470f81..924f4870e 100644 --- a/perf/benchmark-shape.cc +++ b/perf/benchmark-shape.cc @@ -3,6 +3,7 @@ #include "hb.h" + struct test_input_t { const char *text_path; @@ -28,6 +29,7 @@ struct test_input_t "perf/fonts/Roboto-Regular.ttf"}, }; + static void BM_Shape (benchmark::State &state, const test_input_t &input) { hb_font_t *font;