Flutter Engine
The Flutter Engine
CmapBench.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2013 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8#include "bench/Benchmark.h"
10#include "include/core/SkFont.h"
12#include "src/base/SkRandom.h"
13#include "src/base/SkUTF.h"
14#include "src/core/SkFontPriv.h"
17
18enum {
19 NGLYPHS = 100
20};
21
22namespace {
23struct Rec {
24 const SkCharToGlyphCache& fCache;
25 int fLoops;
26 const SkFont& fFont;
27 const SkUnichar* fText;
28 int fCount;
29};
30} // namespace
31
32typedef void (*TypefaceProc)(const Rec& r);
33
34static void textToGlyphs_proc(const Rec& r) {
35 uint16_t glyphs[NGLYPHS];
36 SkASSERT(r.fCount <= NGLYPHS);
37
38 for (int i = 0; i < r.fLoops; ++i) {
39 r.fFont.textToGlyphs(r.fText, r.fCount*4, SkTextEncoding::kUTF32, glyphs, NGLYPHS);
40 }
41}
42
43static void charsToGlyphs_proc(const Rec& r) {
44 uint16_t glyphs[NGLYPHS];
45 SkASSERT(r.fCount <= NGLYPHS);
46
47 SkTypeface* face = r.fFont.getTypeface();
48 for (int i = 0; i < r.fLoops; ++i) {
49 face->unicharsToGlyphs(r.fText, r.fCount, glyphs);
50 }
51}
52
53static void addcache_proc(const Rec& r) {
54 for (int loop = 0; loop < r.fLoops; ++loop) {
56 for (int i = 0; i < r.fCount; ++i) {
57 cache.addCharAndGlyph(r.fText[i], i);
58 }
59 }
60}
61
62static void findcache_proc(const Rec& r) {
63 for (int loop = 0; loop < r.fLoops; ++loop) {
64 for (int i = 0; i < r.fCount; ++i) {
65 r.fCache.findGlyphIndex(r.fText[i]);
66 }
67 }
68}
69
70class CMAPBench : public Benchmark {
71 TypefaceProc fProc;
72 SkString fName;
73 SkUnichar fText[NGLYPHS];
74 SkFont fFont;
75 SkCharToGlyphCache fCache;
76 int fCount;
77
78public:
79 CMAPBench(TypefaceProc proc, const char name[], int count) {
81
82 fProc = proc;
83 fName.printf("%s_%d", name, count);
84 fCount = count;
85
86 SkRandom rand;
87 for (int i = 0; i < count; ++i) {
88 fText[i] = rand.nextU() & 0xFFFF;
89 fCache.addCharAndGlyph(fText[i], i);
90 }
92 }
93
94 bool isSuitableFor(Backend backend) override {
96 }
97
98protected:
99 const char* onGetName() override {
100 return fName.c_str();
101 }
102
103 void onDraw(int loops, SkCanvas* canvas) override {
104 fProc({fCache, loops, fFont, fText, fCount});
105 }
106
107private:
108
109 using INHERITED = Benchmark;
110};
111
112//////////////////////////////////////////////////////////////////////////////
113
114constexpr int SMALL = 10;
115
116DEF_BENCH( return new CMAPBench(textToGlyphs_proc, "font_charToGlyph", SMALL); )
117DEF_BENCH( return new CMAPBench(charsToGlyphs_proc, "face_charToGlyph", SMALL); )
118DEF_BENCH( return new CMAPBench(addcache_proc, "addcache_charToGlyph", SMALL); )
119DEF_BENCH( return new CMAPBench(findcache_proc, "findcache_charToGlyph", SMALL); )
120
121constexpr int BIG = 100;
122
123DEF_BENCH( return new CMAPBench(textToGlyphs_proc, "font_charToGlyph", BIG); )
124DEF_BENCH( return new CMAPBench(charsToGlyphs_proc, "face_charToGlyph", BIG); )
125DEF_BENCH( return new CMAPBench(addcache_proc, "addcache_charToGlyph", BIG); )
126DEF_BENCH( return new CMAPBench(findcache_proc, "findcache_charToGlyph", BIG); )
#define DEF_BENCH(code)
Definition: Benchmark.h:20
static void charsToGlyphs_proc(const Rec &r)
Definition: CmapBench.cpp:43
constexpr int BIG
Definition: CmapBench.cpp:121
static void addcache_proc(const Rec &r)
Definition: CmapBench.cpp:53
void(* TypefaceProc)(const Rec &r)
Definition: CmapBench.cpp:32
static void textToGlyphs_proc(const Rec &r)
Definition: CmapBench.cpp:34
constexpr int SMALL
Definition: CmapBench.cpp:114
static void findcache_proc(const Rec &r)
Definition: CmapBench.cpp:62
@ NGLYPHS
Definition: CmapBench.cpp:19
const char * backend
const char * fName
uint16_t glyphs[5]
Definition: FontMgrTest.cpp:46
int count
Definition: FontMgrTest.cpp:50
IsFiniteProc fProc
Definition: MathBench.cpp:219
#define SkASSERT(cond)
Definition: SkAssert.h:116
@ kUTF32
uses four byte words to represent all of Unicode
int32_t SkUnichar
Definition: SkTypes.h:175
bool isSuitableFor(Backend backend) override
Definition: CmapBench.cpp:94
void onDraw(int loops, SkCanvas *canvas) override
Definition: CmapBench.cpp:103
CMAPBench(TypefaceProc proc, const char name[], int count)
Definition: CmapBench.cpp:79
const char * onGetName() override
Definition: CmapBench.cpp:99
void addCharAndGlyph(SkUnichar unichar, SkGlyphID glyph)
Definition: SkFont.h:35
void setTypeface(sk_sp< SkTypeface > tf)
Definition: SkFont.cpp:90
uint32_t nextU()
Definition: SkRandom.h:42
void unicharsToGlyphs(const SkUnichar uni[], int count, SkGlyphID glyphs[]) const
Definition: SkTypeface.cpp:357
sk_sp< SkTypeface > DefaultPortableTypeface()
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir Path to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data vm service The hostname IP address on which the Dart VM Service should be served If not defaults to or::depending on whether ipv6 is specified vm service A custom Dart VM Service port The default is to pick a randomly available open port disable vm Disable the Dart VM Service The Dart VM Service is never available in release mode disable vm service Disable mDNS Dart VM Service publication Bind to the IPv6 localhost address for the Dart VM Service Ignored if vm service host is set endless trace Enable an endless trace buffer The default is a ring buffer This is useful when very old events need to viewed For during application launch Memory usage will continue to grow indefinitely however Start app with an specific route defined on the framework flutter assets Path to the Flutter assets directory enable service port Allow the VM service to fallback to automatic port selection if binding to a specified port fails trace Trace early application lifecycle Automatically switches to an endless trace buffer trace skia Filters out all Skia trace event categories except those that are specified in this comma separated list dump skp on shader Automatically dump the skp that triggers new shader compilations This is useful for writing custom ShaderWarmUp to reduce jank By this is not enabled to reduce the overhead purge persistent cache
Definition: switches.h:191
DEF_SWITCHES_START aot vmservice shared library name
Definition: switches.h:32