Hal Canary | dc19391 | 2019-05-02 14:23:04 -0400 | [diff] [blame] | 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 | |
Hal Canary | 70aab82 | 2019-05-03 13:18:44 -0400 | [diff] [blame] | 6 | #if !defined(SK_BUILD_FOR_ANDROID_FRAMEWORK) && !defined(SK_BUILD_FOR_GOOGLE3) |
Hal Canary | dc19391 | 2019-05-02 14:23:04 -0400 | [diff] [blame] | 7 | |
| 8 | #include "modules/skshaper/include/SkShaper.h" |
| 9 | #include "tools/Resources.h" |
| 10 | |
| 11 | #include <cfloat> |
| 12 | |
| 13 | namespace { |
| 14 | struct 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 Canary | 56947a7 | 2019-05-03 09:49:27 -0400 | [diff] [blame] | 40 | #define SHAPER_BENCH(X) DEF_BENCH(return new ShaperBench("text/" #X ".txt", "shaper_" #X);) |
| 41 | SHAPER_BENCH(arabic) |
| 42 | SHAPER_BENCH(armenian) |
| 43 | SHAPER_BENCH(balinese) |
| 44 | SHAPER_BENCH(bengali) |
| 45 | SHAPER_BENCH(buginese) |
| 46 | SHAPER_BENCH(cherokee) |
| 47 | SHAPER_BENCH(cyrillic) |
| 48 | SHAPER_BENCH(devanagari) |
| 49 | SHAPER_BENCH(emoji) |
| 50 | SHAPER_BENCH(english) |
| 51 | SHAPER_BENCH(ethiopic) |
| 52 | SHAPER_BENCH(greek) |
| 53 | SHAPER_BENCH(hangul) |
| 54 | SHAPER_BENCH(han_simplified) |
| 55 | SHAPER_BENCH(han_traditional) |
| 56 | SHAPER_BENCH(hebrew) |
| 57 | SHAPER_BENCH(javanese) |
| 58 | SHAPER_BENCH(kana) |
| 59 | SHAPER_BENCH(khmer) |
| 60 | SHAPER_BENCH(lao) |
| 61 | SHAPER_BENCH(mandaic) |
| 62 | SHAPER_BENCH(myanmar) |
| 63 | SHAPER_BENCH(newtailue) |
| 64 | SHAPER_BENCH(nko) |
| 65 | SHAPER_BENCH(sinhala) |
| 66 | SHAPER_BENCH(sundanese) |
| 67 | SHAPER_BENCH(syriac) |
| 68 | SHAPER_BENCH(taitham) |
| 69 | SHAPER_BENCH(tamil) |
| 70 | SHAPER_BENCH(thaana) |
| 71 | SHAPER_BENCH(thai) |
| 72 | SHAPER_BENCH(tibetan) |
| 73 | SHAPER_BENCH(tifnagh) |
| 74 | SHAPER_BENCH(vai) |
| 75 | #undef SHAPER_BENCH |
Hal Canary | dc19391 | 2019-05-02 14:23:04 -0400 | [diff] [blame] | 76 | |
Hal Canary | 70aab82 | 2019-05-03 13:18:44 -0400 | [diff] [blame] | 77 | #endif // !defined(SK_BUILD_FOR_ANDROID_FRAMEWORK) && !defined(SK_BUILD_FOR_GOOGLE3) |