Flutter Engine
The Flutter Engine
ShaperBench.cpp
Go to the documentation of this file.
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
9#include "tools/Resources.h"
11
12#include <cfloat>
13
14namespace {
15struct 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; }
30 const char* text = (const char*)fData->data();
31 size_t len = fData->size();
32 while (loops-- > 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);)
42SHAPER_BENCH(arabic)
43SHAPER_BENCH(armenian)
44SHAPER_BENCH(balinese)
45SHAPER_BENCH(bengali)
46SHAPER_BENCH(buginese)
47SHAPER_BENCH(cherokee)
48SHAPER_BENCH(cyrillic)
49SHAPER_BENCH(devanagari)
50SHAPER_BENCH(emoji)
51SHAPER_BENCH(english)
52SHAPER_BENCH(ethiopic)
53SHAPER_BENCH(greek)
54SHAPER_BENCH(hangul)
55SHAPER_BENCH(han_simplified)
56SHAPER_BENCH(han_traditional)
57SHAPER_BENCH(hebrew)
58SHAPER_BENCH(javanese)
59SHAPER_BENCH(kana)
60SHAPER_BENCH(khmer)
61SHAPER_BENCH(lao)
62SHAPER_BENCH(mandaic)
63SHAPER_BENCH(myanmar)
64SHAPER_BENCH(newtailue)
65SHAPER_BENCH(nko)
66SHAPER_BENCH(sinhala)
67SHAPER_BENCH(sundanese)
68SHAPER_BENCH(syriac)
69SHAPER_BENCH(taitham)
70SHAPER_BENCH(tamil)
71SHAPER_BENCH(thaana)
72SHAPER_BENCH(thai)
73SHAPER_BENCH(tibetan)
74SHAPER_BENCH(tifnagh)
75SHAPER_BENCH(vai)
76#undef SHAPER_BENCH
77
78#endif // !defined(SK_BUILD_FOR_ANDROID_FRAMEWORK) && !defined(SK_BUILD_FOR_GOOGLE3)
const char * backend
const char * fName
sk_sp< SkData > GetResourceAsData(const char *resource)
Definition: Resources.cpp:42
#define SHAPER_BENCH(X)
Definition: ShaperBench.cpp:41
virtual void onDraw(int loops, SkCanvas *)=0
virtual bool isSuitableFor(Backend backend)
Definition: Benchmark.h:55
virtual void onDelayedSetup()
Definition: Benchmark.h:101
virtual const char * onGetName()=0
const void * data() const
Definition: SkData.h:37
size_t size() const
Definition: SkData.h:30
Definition: SkFont.h:35
static std::unique_ptr< SkShaper > Make(sk_sp< SkFontMgr > fallback=nullptr)
Definition: SkShaper.cpp:36
std::u16string text
SkFont DefaultFont()
font
Font Metadata and Metrics.