OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 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 "SkGraphics.h" | 10 #include "SkGraphics.h" |
11 #include "SkPaint.h" | 11 #include "SkPaint.h" |
12 #include "SkRandom.h" | 12 #include "SkRandom.h" |
13 #include "SkString.h" | 13 #include "SkString.h" |
14 | 14 |
15 extern bool gSkSuppressFontCachePurgeSpew; | |
16 | |
17 class FontScalerBench : public SkBenchmark { | 15 class FontScalerBench : public SkBenchmark { |
18 SkString fName; | 16 SkString fName; |
19 SkString fText; | 17 SkString fText; |
20 bool fDoLCD; | 18 bool fDoLCD; |
21 public: | 19 public: |
22 FontScalerBench(bool doLCD) { | 20 FontScalerBench(bool doLCD) { |
23 fName.printf("fontscaler_%s", doLCD ? "lcd" : "aa"); | 21 fName.printf("fontscaler_%s", doLCD ? "lcd" : "aa"); |
24 fText.set("abcdefghijklmnopqrstuvwxyz01234567890"); | 22 fText.set("abcdefghijklmnopqrstuvwxyz01234567890"); |
25 fDoLCD = doLCD; | 23 fDoLCD = doLCD; |
26 } | 24 } |
27 | 25 |
28 protected: | 26 protected: |
29 virtual const char* onGetName() { return fName.c_str(); } | 27 virtual const char* onGetName() { return fName.c_str(); } |
30 virtual void onDraw(const int loops, SkCanvas* canvas) { | 28 virtual void onDraw(const int loops, SkCanvas* canvas) { |
31 SkPaint paint; | 29 SkPaint paint; |
32 this->setupPaint(&paint); | 30 this->setupPaint(&paint); |
33 paint.setLCDRenderText(fDoLCD); | 31 paint.setLCDRenderText(fDoLCD); |
34 | 32 |
35 bool prev = gSkSuppressFontCachePurgeSpew; | |
36 gSkSuppressFontCachePurgeSpew = true; | |
37 | |
38 for (int i = 0; i < loops; i++) { | 33 for (int i = 0; i < loops; i++) { |
39 // this is critical - we want to time the creation process, so we | 34 // this is critical - we want to time the creation process, so we |
40 // explicitly flush our cache before each run | 35 // explicitly flush our cache before each run |
41 SkGraphics::PurgeFontCache(); | 36 SkGraphics::PurgeFontCache(); |
42 | 37 |
43 for (int ps = 9; ps <= 24; ps += 2) { | 38 for (int ps = 9; ps <= 24; ps += 2) { |
44 paint.setTextSize(SkIntToScalar(ps)); | 39 paint.setTextSize(SkIntToScalar(ps)); |
45 canvas->drawText(fText.c_str(), fText.size(), | 40 canvas->drawText(fText.c_str(), fText.size(), |
46 0, SkIntToScalar(20), paint); | 41 0, SkIntToScalar(20), paint); |
47 } | 42 } |
48 } | 43 } |
49 | |
50 gSkSuppressFontCachePurgeSpew = prev; | |
51 } | 44 } |
52 private: | 45 private: |
53 typedef SkBenchmark INHERITED; | 46 typedef SkBenchmark INHERITED; |
54 }; | 47 }; |
55 | 48 |
56 /////////////////////////////////////////////////////////////////////////////// | 49 /////////////////////////////////////////////////////////////////////////////// |
57 | 50 |
58 DEF_BENCH( return SkNEW_ARGS(FontScalerBench, (false)); ) | 51 DEF_BENCH( return SkNEW_ARGS(FontScalerBench, (false)); ) |
59 DEF_BENCH( return SkNEW_ARGS(FontScalerBench, (true)); ) | 52 DEF_BENCH( return SkNEW_ARGS(FontScalerBench, (true)); ) |
OLD | NEW |