blob: df258a71005a51a4453bbb6ad6ff805bc4854172 [file] [log] [blame]
Hal Canarydc193912019-05-02 14:23:04 -04001// 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
Hal Canary70aab822019-05-03 13:18:44 -04006#if !defined(SK_BUILD_FOR_ANDROID_FRAMEWORK) && !defined(SK_BUILD_FOR_GOOGLE3)
Hal Canarydc193912019-05-02 14:23:04 -04007
8#include "modules/skshaper/include/SkShaper.h"
9#include "tools/Resources.h"
10
11#include <cfloat>
12
13namespace {
14struct ShaperBench : public Benchmark {
15 ShaperBench(const char* r, const char* n) : fResource(r), fName(n) {}
16 std::unique_ptr<SkShaper> fShaper;
17 sk_sp<SkData> fData;
18 const char* fResource;
19 const char* fName;
20 const char* onGetName() override { return fName; }
21 bool isSuitableFor(Backend backend) override { return backend == kNonRendering_Backend; }
22 void onDelayedSetup() override {
23 fShaper = SkShaper::Make();
24 fData = GetResourceAsData(fResource);
25 }
26 void onDraw(int loops, SkCanvas*) override {
27 if (!fData || !fShaper) { return; }
28 SkFont font;
29 const char* text = (const char*)fData->data();
30 size_t len = fData->size();
31 while (loops-- > 0) {
32 SkTextBlobBuilderRunHandler rh(text, {0, 0});
33 fShaper->shape(text, len, font, true, FLT_MAX, &rh);
34 (void)rh.makeBlob();
35 }
36 }
37};
38} // namespace
39
Hal Canary56947a72019-05-03 09:49:27 -040040#define SHAPER_BENCH(X) DEF_BENCH(return new ShaperBench("text/" #X ".txt", "shaper_" #X);)
41SHAPER_BENCH(arabic)
42SHAPER_BENCH(armenian)
43SHAPER_BENCH(balinese)
44SHAPER_BENCH(bengali)
45SHAPER_BENCH(buginese)
46SHAPER_BENCH(cherokee)
47SHAPER_BENCH(cyrillic)
48SHAPER_BENCH(devanagari)
49SHAPER_BENCH(emoji)
50SHAPER_BENCH(english)
51SHAPER_BENCH(ethiopic)
52SHAPER_BENCH(greek)
53SHAPER_BENCH(hangul)
54SHAPER_BENCH(han_simplified)
55SHAPER_BENCH(han_traditional)
56SHAPER_BENCH(hebrew)
57SHAPER_BENCH(javanese)
58SHAPER_BENCH(kana)
59SHAPER_BENCH(khmer)
60SHAPER_BENCH(lao)
61SHAPER_BENCH(mandaic)
62SHAPER_BENCH(myanmar)
63SHAPER_BENCH(newtailue)
64SHAPER_BENCH(nko)
65SHAPER_BENCH(sinhala)
66SHAPER_BENCH(sundanese)
67SHAPER_BENCH(syriac)
68SHAPER_BENCH(taitham)
69SHAPER_BENCH(tamil)
70SHAPER_BENCH(thaana)
71SHAPER_BENCH(thai)
72SHAPER_BENCH(tibetan)
73SHAPER_BENCH(tifnagh)
74SHAPER_BENCH(vai)
75#undef SHAPER_BENCH
Hal Canarydc193912019-05-02 14:23:04 -040076
Hal Canary70aab822019-05-03 13:18:44 -040077#endif // !defined(SK_BUILD_FOR_ANDROID_FRAMEWORK) && !defined(SK_BUILD_FOR_GOOGLE3)