OLD | NEW |
---|---|
(Empty) | |
1 /* | |
2 * Copyright 2015 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 | |
9 #include "SkGlyphCache.h" | |
10 | |
11 #include "Benchmark.h" | |
12 #include "SkCanvas.h" | |
13 #include "SkGlyphCache_Globals.h" | |
14 #include "SkGraphics.h" | |
15 #include "SkTaskGroup.h" | |
16 #include "SkTypeface.h" | |
17 #include "sk_tool_utils.h" | |
18 | |
19 | |
20 static void DoFontStuff(SkPaint* paint) { | |
mtklein
2015/09/17 19:38:08
do_font_stuff
| |
21 for (int i = 8; i < 64; i++) { | |
22 paint->setTextSize(i); | |
23 SkAutoGlyphCacheNoGamma autoCache(*paint, nullptr, nullptr); | |
24 SkGlyphCache* cache = autoCache.getCache(); | |
25 uint16_t glyphs['z']; | |
26 for (int c = ' '; c < 'z'; c++) { | |
27 glyphs[c] = cache->unicharToGlyph(c); | |
28 } | |
29 for (int lookups = 0; lookups < 10; lookups++) { | |
30 for (int c = ' '; c < 'z'; c++) { | |
31 const SkGlyph& g = cache->getGlyphIDMetrics(glyphs[c]); | |
32 cache->findImage(g); | |
33 } | |
34 } | |
35 | |
36 } | |
37 } | |
38 | |
39 class SkGlyphCacheBasic : public Benchmark { | |
40 public: | |
41 explicit SkGlyphCacheBasic(size_t cacheSize) : fCacheSize(cacheSize) { } | |
42 | |
43 protected: | |
44 const char* onGetName() override { | |
45 fName.printf("SkGlyphCacheBasic%dK", fCacheSize >> 10); | |
46 return fName.c_str(); | |
47 } | |
48 | |
49 bool isSuitableFor(Backend backend) override { | |
50 return backend == kNonRendering_Backend; | |
51 } | |
52 | |
53 void onDraw(const int loops, SkCanvas*) override { | |
54 size_t oldCacheLimitSize = SkGraphics::GetFontCacheLimit(); | |
55 SkGraphics::SetFontCacheLimit(256 * 1024); | |
56 SkTypeface* typeface = sk_tool_utils::create_portable_typeface( | |
57 "serif", SkTypeface::kItalic); | |
58 SkPaint paint; | |
59 paint.setAntiAlias(true); | |
60 paint.setSubpixelText(true); | |
61 paint.setTypeface(typeface); | |
62 | |
63 for (int work = 0; work < loops; work++) { | |
64 DoFontStuff(&paint); | |
65 } | |
66 SkGraphics::SetFontCacheLimit(oldCacheLimitSize); | |
67 } | |
68 | |
69 private: | |
70 typedef Benchmark INHERITED; | |
71 const int fCacheSize; | |
72 SkString fName; | |
73 }; | |
74 | |
75 class SkGlyphCacheStressTest : public Benchmark { | |
76 public: | |
77 explicit SkGlyphCacheStressTest(int cacheSize) : fCacheSize(cacheSize) { } | |
78 | |
79 protected: | |
80 const char* onGetName() override { | |
81 fName.printf("SkGlyphCacheStressTest%dK", fCacheSize >> 10); | |
82 return fName.c_str(); | |
83 } | |
84 | |
85 bool isSuitableFor(Backend backend) override { | |
86 return backend == kNonRendering_Backend; | |
87 } | |
88 | |
89 void onDraw(const int loops, SkCanvas*) override { | |
90 size_t oldCacheLimitSize = SkGraphics::GetFontCacheLimit(); | |
91 SkGraphics::SetFontCacheLimit(fCacheSize); | |
92 SkTypeface* typefaces[] = | |
93 {sk_tool_utils::create_portable_typeface("serif", SkTypeface::kItali c), | |
94 sk_tool_utils::create_portable_typeface("sans-serif", SkTypeface::k Italic)}; | |
95 | |
96 for (int work = 0; work < loops; work++) { | |
97 sk_parallel_for(16, [&](int threadIndex) { | |
98 SkPaint paint; | |
99 paint.setAntiAlias(true); | |
100 paint.setSubpixelText(true); | |
101 paint.setTypeface(typefaces[threadIndex % 2]); | |
102 DoFontStuff(&paint); | |
103 }); | |
104 } | |
105 SkGraphics::SetFontCacheLimit(oldCacheLimitSize); | |
106 } | |
107 | |
108 private: | |
109 typedef Benchmark INHERITED; | |
110 const int fCacheSize; | |
111 SkString fName; | |
112 }; | |
113 | |
114 DEF_BENCH( return new SkGlyphCacheBasic(256 * 1024); ) | |
115 DEF_BENCH( return new SkGlyphCacheBasic(32 * 1024 * 1024); ) | |
116 DEF_BENCH( return new SkGlyphCacheStressTest(256 * 1024); ) | |
117 DEF_BENCH( return new SkGlyphCacheStressTest(32 * 1024 * 1024); ) | |
OLD | NEW |