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