OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "SkBenchmark.h" | 8 #include "SkBenchmark.h" |
9 #include "SkCanvas.h" | 9 #include "SkCanvas.h" |
10 #include "SkFontHost.h" | 10 #include "SkFontHost.h" |
11 #include "SkPaint.h" | 11 #include "SkPaint.h" |
12 #include "SkString.h" | 12 #include "SkString.h" |
13 #include "SkTemplates.h" | 13 #include "SkTemplates.h" |
14 | 14 |
15 #include "gUniqueGlyphIDs.h" | 15 #include "gUniqueGlyphIDs.h" |
16 #define gUniqueGlyphIDs_Sentinel 0xFFFF | 16 #define gUniqueGlyphIDs_Sentinel 0xFFFF |
17 | 17 |
18 static int count_glyphs(const uint16_t start[]) { | 18 static int count_glyphs(const uint16_t start[]) { |
19 const uint16_t* curr = start; | 19 const uint16_t* curr = start; |
20 while (*curr != gUniqueGlyphIDs_Sentinel) { | 20 while (*curr != gUniqueGlyphIDs_Sentinel) { |
21 curr += 1; | 21 curr += 1; |
22 } | 22 } |
23 return curr - start; | 23 return curr - start; |
24 } | 24 } |
25 | 25 |
26 class FontCacheBench : public SkBenchmark { | 26 class FontCacheBench : public SkBenchmark { |
27 enum { | |
28 N = SkBENCHLOOP(50) | |
29 }; | |
30 | |
31 public: | 27 public: |
32 FontCacheBench(void* param) : INHERITED(param) {} | 28 FontCacheBench(void* param) : INHERITED(param) {} |
33 | 29 |
34 protected: | 30 protected: |
35 virtual const char* onGetName() SK_OVERRIDE { | 31 virtual const char* onGetName() SK_OVERRIDE { |
36 return "fontcache"; | 32 return "fontcache"; |
37 } | 33 } |
38 | 34 |
39 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { | 35 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { |
40 SkPaint paint; | 36 SkPaint paint; |
41 this->setupPaint(&paint); | 37 this->setupPaint(&paint); |
42 paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding); | 38 paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding); |
43 | 39 |
44 const uint16_t* array = gUniqueGlyphIDs; | 40 const uint16_t* array = gUniqueGlyphIDs; |
45 while (*array != gUniqueGlyphIDs_Sentinel) { | 41 while (*array != gUniqueGlyphIDs_Sentinel) { |
46 size_t count = count_glyphs(array); | 42 size_t count = count_glyphs(array); |
47 for (int i = 0; i < N; ++i) { | 43 for (int i = 0; i < this->getLoops(); ++i) { |
48 paint.measureText(array, count * sizeof(uint16_t)); | 44 paint.measureText(array, count * sizeof(uint16_t)); |
49 } | 45 } |
50 array += count + 1; // skip the sentinel | 46 array += count + 1; // skip the sentinel |
51 } | 47 } |
52 } | 48 } |
53 | 49 |
54 private: | 50 private: |
55 typedef SkBenchmark INHERITED; | 51 typedef SkBenchmark INHERITED; |
56 }; | 52 }; |
57 | 53 |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
153 private: | 149 private: |
154 typedef SkBenchmark INHERITED; | 150 typedef SkBenchmark INHERITED; |
155 }; | 151 }; |
156 | 152 |
157 /////////////////////////////////////////////////////////////////////////////// | 153 /////////////////////////////////////////////////////////////////////////////// |
158 | 154 |
159 DEF_BENCH( return new FontCacheBench(p); ) | 155 DEF_BENCH( return new FontCacheBench(p); ) |
160 | 156 |
161 // undefine this to run the efficiency test | 157 // undefine this to run the efficiency test |
162 //DEF_BENCH( return new FontCacheEfficiency(p); ) | 158 //DEF_BENCH( return new FontCacheEfficiency(p); ) |
OLD | NEW |