aboutsummaryrefslogtreecommitdiff
path: root/bench/ShaperBench.cpp
blob: df258a71005a51a4453bbb6ad6ff805bc4854172 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
// Copyright 2019 Google LLC.
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.

#include "bench/Benchmark.h"

#if !defined(SK_BUILD_FOR_ANDROID_FRAMEWORK) && !defined(SK_BUILD_FOR_GOOGLE3)

#include "modules/skshaper/include/SkShaper.h"
#include "tools/Resources.h"

#include <cfloat>

namespace {
struct ShaperBench : public Benchmark {
    ShaperBench(const char* r, const char* n) : fResource(r), fName(n) {}
    std::unique_ptr<SkShaper> fShaper;
    sk_sp<SkData> fData;
    const char* fResource;
    const char* fName;
    const char* onGetName() override { return fName; }
    bool isSuitableFor(Backend backend) override { return backend == kNonRendering_Backend; }
    void onDelayedSetup() override {
        fShaper = SkShaper::Make();
        fData = GetResourceAsData(fResource);
    }
    void onDraw(int loops, SkCanvas*) override {
        if (!fData || !fShaper) { return; }
        SkFont font;
        const char* text = (const char*)fData->data();
        size_t len = fData->size();
        while (loops-- > 0) {
            SkTextBlobBuilderRunHandler rh(text, {0, 0});
            fShaper->shape(text, len, font, true, FLT_MAX, &rh);
            (void)rh.makeBlob();
        }
    }
};
}  // namespace

#define SHAPER_BENCH(X) DEF_BENCH(return new ShaperBench("text/" #X ".txt", "shaper_" #X);)
SHAPER_BENCH(arabic)
SHAPER_BENCH(armenian)
SHAPER_BENCH(balinese)
SHAPER_BENCH(bengali)
SHAPER_BENCH(buginese)
SHAPER_BENCH(cherokee)
SHAPER_BENCH(cyrillic)
SHAPER_BENCH(devanagari)
SHAPER_BENCH(emoji)
SHAPER_BENCH(english)
SHAPER_BENCH(ethiopic)
SHAPER_BENCH(greek)
SHAPER_BENCH(hangul)
SHAPER_BENCH(han_simplified)
SHAPER_BENCH(han_traditional)
SHAPER_BENCH(hebrew)
SHAPER_BENCH(javanese)
SHAPER_BENCH(kana)
SHAPER_BENCH(khmer)
SHAPER_BENCH(lao)
SHAPER_BENCH(mandaic)
SHAPER_BENCH(myanmar)
SHAPER_BENCH(newtailue)
SHAPER_BENCH(nko)
SHAPER_BENCH(sinhala)
SHAPER_BENCH(sundanese)
SHAPER_BENCH(syriac)
SHAPER_BENCH(taitham)
SHAPER_BENCH(tamil)
SHAPER_BENCH(thaana)
SHAPER_BENCH(thai)
SHAPER_BENCH(tibetan)
SHAPER_BENCH(tifnagh)
SHAPER_BENCH(vai)
#undef SHAPER_BENCH

#endif  // !defined(SK_BUILD_FOR_ANDROID_FRAMEWORK) && !defined(SK_BUILD_FOR_GOOGLE3)