OLD | NEW |
---|---|
1 /* | 1 /* |
bungeman-skia
2013/12/16 16:33:36
I'm unsure of what the changes to this file are fo
zheng.xu
2013/12/17 10:02:51
There are GM cases covers different font styles.
I
| |
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 #include "SkTypeface.h" | |
14 | 15 |
15 extern bool gSkSuppressFontCachePurgeSpew; | 16 extern bool gSkSuppressFontCachePurgeSpew; |
16 | 17 |
18 static const struct { | |
19 const char* fStyleString; | |
20 SkTypeface::Style fStyle; | |
21 } gStyleNames [] = { | |
22 { "normal", SkTypeface::kNormal }, | |
23 { "bold", SkTypeface::kBold }, | |
24 { "italic", SkTypeface::kItalic }, | |
25 { "bolditalic", SkTypeface::kBoldItalic }, | |
26 }; | |
27 | |
17 class FontScalerBench : public SkBenchmark { | 28 class FontScalerBench : public SkBenchmark { |
18 SkString fName; | 29 SkString fName; |
19 SkString fText; | 30 SkString fText; |
20 bool fDoLCD; | 31 SkTypeface::Style fStyle; |
32 bool fDoLCD; | |
21 public: | 33 public: |
22 FontScalerBench(bool doLCD) { | 34 FontScalerBench(SkTypeface::Style style, bool doLCD) { |
23 fName.printf("fontscaler_%s", doLCD ? "lcd" : "aa"); | 35 const char* styleString; |
36 | |
37 styleString = gStyleNames[0].fStyleString; | |
38 fStyle = gStyleNames[0].fStyle; | |
39 | |
40 for (unsigned int i = 0; | |
41 i < sizeof(gStyleNames) / sizeof(gStyleNames[0]); i++) { | |
42 if (gStyleNames[i].fStyle == style) { | |
43 styleString = gStyleNames[i].fStyleString; | |
44 fStyle = style; | |
45 break; | |
46 } | |
47 } | |
48 | |
49 fName.printf("fontscaler_%s_%s", styleString, doLCD ? "lcd" : "aa"); | |
24 fText.set("abcdefghijklmnopqrstuvwxyz01234567890"); | 50 fText.set("abcdefghijklmnopqrstuvwxyz01234567890"); |
51 | |
25 fDoLCD = doLCD; | 52 fDoLCD = doLCD; |
26 } | 53 } |
27 | 54 |
28 protected: | 55 protected: |
29 virtual const char* onGetName() { return fName.c_str(); } | 56 virtual const char* onGetName() { return fName.c_str(); } |
30 virtual void onDraw(const int loops, SkCanvas* canvas) { | 57 virtual void onDraw(const int loops, SkCanvas* canvas) { |
31 SkPaint paint; | 58 SkPaint paint; |
32 this->setupPaint(&paint); | 59 this->setupPaint(&paint); |
60 | |
61 SkTypeface* face = SkTypeface::CreateFromName(NULL, fStyle); | |
bungeman-skia
2013/12/16 16:33:36
SkAutoTUnref<SkTypeface> face(SkTypeface::CreateFr
zheng.xu
2013/12/17 10:02:51
Thanks for the hint. This is quite convenient.
| |
62 paint.setTypeface(face); | |
33 paint.setLCDRenderText(fDoLCD); | 63 paint.setLCDRenderText(fDoLCD); |
34 | 64 |
35 bool prev = gSkSuppressFontCachePurgeSpew; | 65 bool prev = gSkSuppressFontCachePurgeSpew; |
36 gSkSuppressFontCachePurgeSpew = true; | 66 gSkSuppressFontCachePurgeSpew = true; |
37 | 67 |
38 for (int i = 0; i < loops; i++) { | 68 for (int i = 0; i < loops; i++) { |
39 // this is critical - we want to time the creation process, so we | 69 // this is critical - we want to time the creation process, so we |
40 // explicitly flush our cache before each run | 70 // explicitly flush our cache before each run |
41 SkGraphics::PurgeFontCache(); | 71 SkGraphics::PurgeFontCache(); |
42 | 72 |
43 for (int ps = 9; ps <= 24; ps += 2) { | 73 for (int y = 20, ps = 9; ps <= 24; y += ps, ps += 2) { |
44 paint.setTextSize(SkIntToScalar(ps)); | 74 paint.setTextSize(SkIntToScalar(ps)); |
45 canvas->drawText(fText.c_str(), fText.size(), | 75 canvas->drawText(fText.c_str(), fText.size(), |
46 0, SkIntToScalar(20), paint); | 76 0, SkIntToScalar(y), paint); |
47 } | 77 } |
48 } | 78 } |
49 | 79 |
50 gSkSuppressFontCachePurgeSpew = prev; | 80 gSkSuppressFontCachePurgeSpew = prev; |
81 | |
82 SkSafeUnref(face); | |
51 } | 83 } |
52 private: | 84 private: |
53 typedef SkBenchmark INHERITED; | 85 typedef SkBenchmark INHERITED; |
54 }; | 86 }; |
55 | 87 |
56 /////////////////////////////////////////////////////////////////////////////// | 88 /////////////////////////////////////////////////////////////////////////////// |
57 | 89 |
58 DEF_BENCH( return SkNEW_ARGS(FontScalerBench, (false)); ) | 90 DEF_BENCH( return SkNEW_ARGS(FontScalerBench, (SkTypeface::kNormal, false)); ) |
59 DEF_BENCH( return SkNEW_ARGS(FontScalerBench, (true)); ) | 91 DEF_BENCH( return SkNEW_ARGS(FontScalerBench, (SkTypeface::kBold, false)); ) |
92 DEF_BENCH( return SkNEW_ARGS(FontScalerBench, (SkTypeface::kItalic, false)); ) | |
93 DEF_BENCH( return SkNEW_ARGS(FontScalerBench, (SkTypeface::kBoldItalic, false)); ) | |
94 DEF_BENCH( return SkNEW_ARGS(FontScalerBench, (SkTypeface::kNormal, true)); ) | |
95 DEF_BENCH( return SkNEW_ARGS(FontScalerBench, (SkTypeface::kBold, true)); ) | |
96 DEF_BENCH( return SkNEW_ARGS(FontScalerBench, (SkTypeface::kItalic, true)); ) | |
97 DEF_BENCH( return SkNEW_ARGS(FontScalerBench, (SkTypeface::kBoldItalic, true)); ) | |
OLD | NEW |