Debian Codegraph @

bench/ShaperBench.cpp

raw
1 // Copyright 2019 Google LLC.
2 // Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
3
4 #include "bench/Benchmark.h"
5
6 #if !defined(SK_BUILD_FOR_ANDROID_FRAMEWORK)
7
8 #include "modules/skshaper/include/SkShaper.h"
9 #include "tools/Resources.h"
10 #include "tools/fonts/FontToolUtils.h"
11
12 #include <cfloat>
13
14 namespace {
15 struct ShaperBench : public Benchmark {
16 ShaperBench(const char* r, const char* n) : fResource(r), fName(n) {}
17 std::unique_ptr<SkShaper> fShaper;
18 sk_sp<SkData> fData;
19 const char* fResource;
20 const char* fName;
21 const char* onGetName() override { return fName; }
22 bool isSuitableFor(Backend backend) override { return backend == Backend::kNonRendering; }
23 void onDelayedSetup() override {
24 fShaper = SkShaper::Make();
25 fData = GetResourceAsData(fResource);
26 }
27 void onDraw(int loops, SkCanvas*) override {
28 if (!fData || !fShaper) { return; }
29 SkFont font = ToolUtils::DefaultFont();
30 const char* text = (const char*)fData->data();
31 size_t len = fData->size();
32 while (loops-- > 0) {
33 SkTextBlobBuilderRunHandler rh(text, {0, 0});
34 fShaper->shape(text, len, font, true, FLT_MAX, &rh);
35 (void)rh.makeBlob();
36 }
37 }
38 };
39 } // namespace
40
41 #define SHAPER_BENCH(X) DEF_BENCH(return new ShaperBench("text/" #X ".txt", "shaper_" #X);)
42 SHAPER_BENCH(arabic)
43 SHAPER_BENCH(armenian)
44 SHAPER_BENCH(balinese)
45 SHAPER_BENCH(bengali)
46 SHAPER_BENCH(buginese)
47 SHAPER_BENCH(cherokee)
48 SHAPER_BENCH(cyrillic)
49 SHAPER_BENCH(devanagari)
50 SHAPER_BENCH(emoji)
51 SHAPER_BENCH(english)
52 SHAPER_BENCH(ethiopic)
53 SHAPER_BENCH(greek)
54 SHAPER_BENCH(hangul)
55 SHAPER_BENCH(han_simplified)
56 SHAPER_BENCH(han_traditional)
57 SHAPER_BENCH(hebrew)
58 SHAPER_BENCH(javanese)
59 SHAPER_BENCH(kana)
60 SHAPER_BENCH(khmer)
61 SHAPER_BENCH(lao)
62 SHAPER_BENCH(mandaic)
63 SHAPER_BENCH(myanmar)
64 SHAPER_BENCH(newtailue)
65 SHAPER_BENCH(nko)
66 SHAPER_BENCH(sinhala)
67 SHAPER_BENCH(sundanese)
68 SHAPER_BENCH(syriac)
69 SHAPER_BENCH(taitham)
70 SHAPER_BENCH(tamil)
71 SHAPER_BENCH(thaana)
72 SHAPER_BENCH(thai)
73 SHAPER_BENCH(tibetan)
74 SHAPER_BENCH(tifnagh)
75 SHAPER_BENCH(vai)
76 #undef SHAPER_BENCH
77
78 #endif // !defined(SK_BUILD_FOR_ANDROID_FRAMEWORK)