Hash :
95b1081b
Author :
Date :
2020-06-09T17:37:36
Add performance benchmark for shaping, get extents and draw
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
#include "benchmark/benchmark.h"
#include "hb.h"
static void shape (benchmark::State &state, const char *text_path,
hb_direction_t direction, hb_script_t script,
const char *font_path)
{
hb_font_t *font;
{
hb_blob_t *blob = hb_blob_create_from_file (font_path);
assert (hb_blob_get_length (blob));
hb_face_t *face = hb_face_create (blob, 0);
hb_blob_destroy (blob);
font = hb_font_create (face);
hb_face_destroy (face);
}
hb_blob_t *text_blob = hb_blob_create_from_file (text_path);
unsigned text_length;
const char *text = hb_blob_get_data (text_blob, &text_length);
assert (text_length);
hb_buffer_t *buf = hb_buffer_create ();
for (auto _ : state)
{
hb_buffer_add_utf8 (buf, text, text_length, 0, -1);
hb_buffer_set_direction (buf, direction);
hb_buffer_set_script (buf, script);
hb_shape (font, buf, nullptr, 0);
hb_buffer_clear_contents (buf);
}
hb_buffer_destroy (buf);
hb_blob_destroy (text_blob);
hb_font_destroy (font);
}
BENCHMARK_CAPTURE (shape, fa-thelittleprince.txt - Amiri,
"perf/texts/fa-thelittleprince.txt",
HB_DIRECTION_RTL, HB_SCRIPT_ARABIC,
"perf/fonts/Amiri-Regular.ttf");
BENCHMARK_CAPTURE (shape, fa-thelittleprince.txt - NotoNastaliqUrdu,
"perf/texts/fa-thelittleprince.txt",
HB_DIRECTION_RTL, HB_SCRIPT_ARABIC,
"perf/fonts/NotoNastaliqUrdu-Regular.ttf");
BENCHMARK_CAPTURE (shape, fa-monologue.txt - Amiri,
"perf/texts/fa-monologue.txt",
HB_DIRECTION_RTL, HB_SCRIPT_ARABIC,
"perf/fonts/Amiri-Regular.ttf");
BENCHMARK_CAPTURE (shape, fa-monologue.txt - NotoNastaliqUrdu,
"perf/texts/fa-monologue.txt",
HB_DIRECTION_RTL, HB_SCRIPT_ARABIC,
"perf/fonts/NotoNastaliqUrdu-Regular.ttf");
BENCHMARK_CAPTURE (shape, en-thelittleprince.txt - Roboto,
"perf/texts/en-thelittleprince.txt",
HB_DIRECTION_LTR, HB_SCRIPT_LATIN,
"perf/fonts/Roboto-Regular.ttf");
BENCHMARK_CAPTURE (shape, en-words.txt - Roboto,
"perf/texts/en-words.txt",
HB_DIRECTION_LTR, HB_SCRIPT_LATIN,
"perf/fonts/Roboto-Regular.ttf");