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) && !defined(SK_BUILD_FOR_GOOGLE3) 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 { ShaperBench__anon041661300111::ShaperBench15 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; onGetName__anon041661300111::ShaperBench20 const char* onGetName() override { return fName; } isSuitableFor__anon041661300111::ShaperBench21 bool isSuitableFor(Backend backend) override { return backend == kNonRendering_Backend; } onDelayedSetup__anon041661300111::ShaperBench22 void onDelayedSetup() override { 23 fShaper = SkShaper::Make(); 24 fData = GetResourceAsData(fResource); 25 } onDraw__anon041661300111::ShaperBench26 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 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 76 77 #endif // !defined(SK_BUILD_FOR_ANDROID_FRAMEWORK) && !defined(SK_BUILD_FOR_GOOGLE3) 78