OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2011 Google Inc. | 3 * Copyright 2011 Google Inc. |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 #include "SkBenchmark.h" | 8 #include "SkBenchmark.h" |
9 #include "SkCanvas.h" | 9 #include "SkCanvas.h" |
10 #include "SkColorShader.h" | 10 #include "SkColorShader.h" |
(...skipping 19 matching lines...) Expand all Loading... |
30 return "LCD"; | 30 return "LCD"; |
31 } | 31 } |
32 return "AA"; | 32 return "AA"; |
33 } | 33 } |
34 | 34 |
35 class ShaderMaskBench : public SkBenchmark { | 35 class ShaderMaskBench : public SkBenchmark { |
36 SkPaint fPaint; | 36 SkPaint fPaint; |
37 SkString fText; | 37 SkString fText; |
38 SkString fName; | 38 SkString fName; |
39 FontQuality fFQ; | 39 FontQuality fFQ; |
40 enum { N = SkBENCHLOOP(500) }; | |
41 public: | 40 public: |
42 ShaderMaskBench(void* param, bool isOpaque, FontQuality fq) : INHERITED(para
m) { | 41 ShaderMaskBench(void* param, bool isOpaque, FontQuality fq) : INHERITED(para
m) { |
43 fFQ = fq; | 42 fFQ = fq; |
44 fText.set(STR); | 43 fText.set(STR); |
45 | 44 |
46 fPaint.setAntiAlias(kBW != fq); | 45 fPaint.setAntiAlias(kBW != fq); |
47 fPaint.setLCDRenderText(kLCD == fq); | 46 fPaint.setLCDRenderText(kLCD == fq); |
48 fPaint.setAlpha(isOpaque ? 0xFF : 0x80); | 47 fPaint.setAlpha(isOpaque ? 0xFF : 0x80); |
49 fPaint.setShader(new SkColorShader)->unref(); | 48 fPaint.setShader(new SkColorShader)->unref(); |
50 } | 49 } |
(...skipping 14 matching lines...) Expand all Loading... |
65 this->setupPaint(&paint); | 64 this->setupPaint(&paint); |
66 // explicitly need these | 65 // explicitly need these |
67 paint.setAlpha(fPaint.getAlpha()); | 66 paint.setAlpha(fPaint.getAlpha()); |
68 paint.setAntiAlias(kBW != fFQ); | 67 paint.setAntiAlias(kBW != fFQ); |
69 paint.setLCDRenderText(kLCD == fFQ); | 68 paint.setLCDRenderText(kLCD == fFQ); |
70 | 69 |
71 const SkScalar x0 = SkIntToScalar(-10); | 70 const SkScalar x0 = SkIntToScalar(-10); |
72 const SkScalar y0 = SkIntToScalar(-10); | 71 const SkScalar y0 = SkIntToScalar(-10); |
73 | 72 |
74 paint.setTextSize(SkIntToScalar(12)); | 73 paint.setTextSize(SkIntToScalar(12)); |
75 for (int i = 0; i < N; i++) { | 74 for (int i = 0; i < this->getLoops(); i++) { |
76 SkScalar x = x0 + rand.nextUScalar1() * dim.fX; | 75 SkScalar x = x0 + rand.nextUScalar1() * dim.fX; |
77 SkScalar y = y0 + rand.nextUScalar1() * dim.fY; | 76 SkScalar y = y0 + rand.nextUScalar1() * dim.fY; |
78 canvas->drawText(fText.c_str(), fText.size(), x, y, paint); | 77 canvas->drawText(fText.c_str(), fText.size(), x, y, paint); |
79 } | 78 } |
80 | 79 |
81 paint.setTextSize(SkIntToScalar(48)); | 80 paint.setTextSize(SkIntToScalar(48)); |
82 for (int i = 0; i < N/4; i++) { | 81 for (int i = 0; i < this->getLoops() / 4 ; i++) { |
83 SkScalar x = x0 + rand.nextUScalar1() * dim.fX; | 82 SkScalar x = x0 + rand.nextUScalar1() * dim.fX; |
84 SkScalar y = y0 + rand.nextUScalar1() * dim.fY; | 83 SkScalar y = y0 + rand.nextUScalar1() * dim.fY; |
85 canvas->drawText(fText.c_str(), fText.size(), x, y, paint); | 84 canvas->drawText(fText.c_str(), fText.size(), x, y, paint); |
86 } | 85 } |
87 } | 86 } |
88 | 87 |
89 private: | 88 private: |
90 typedef SkBenchmark INHERITED; | 89 typedef SkBenchmark INHERITED; |
91 }; | 90 }; |
92 | 91 |
93 /////////////////////////////////////////////////////////////////////////////// | 92 /////////////////////////////////////////////////////////////////////////////// |
94 | 93 |
95 static SkBenchmark* Fact00(void* p) { return new ShaderMaskBench(p, true, kBW);
} | 94 static SkBenchmark* Fact00(void* p) { return new ShaderMaskBench(p, true, kBW);
} |
96 static SkBenchmark* Fact01(void* p) { return new ShaderMaskBench(p, false, kBW);
} | 95 static SkBenchmark* Fact01(void* p) { return new ShaderMaskBench(p, false, kBW);
} |
97 static SkBenchmark* Fact10(void* p) { return new ShaderMaskBench(p, true, kAA);
} | 96 static SkBenchmark* Fact10(void* p) { return new ShaderMaskBench(p, true, kAA);
} |
98 static SkBenchmark* Fact11(void* p) { return new ShaderMaskBench(p, false, kAA);
} | 97 static SkBenchmark* Fact11(void* p) { return new ShaderMaskBench(p, false, kAA);
} |
99 static SkBenchmark* Fact20(void* p) { return new ShaderMaskBench(p, true, kLCD)
; } | 98 static SkBenchmark* Fact20(void* p) { return new ShaderMaskBench(p, true, kLCD)
; } |
100 static SkBenchmark* Fact21(void* p) { return new ShaderMaskBench(p, false, kLCD)
; } | 99 static SkBenchmark* Fact21(void* p) { return new ShaderMaskBench(p, false, kLCD)
; } |
101 | 100 |
102 static BenchRegistry gReg00(Fact00); | 101 static BenchRegistry gReg00(Fact00); |
103 static BenchRegistry gReg01(Fact01); | 102 static BenchRegistry gReg01(Fact01); |
104 static BenchRegistry gReg10(Fact10); | 103 static BenchRegistry gReg10(Fact10); |
105 static BenchRegistry gReg11(Fact11); | 104 static BenchRegistry gReg11(Fact11); |
106 static BenchRegistry gReg20(Fact20); | 105 static BenchRegistry gReg20(Fact20); |
107 static BenchRegistry gReg21(Fact21); | 106 static BenchRegistry gReg21(Fact21); |
OLD | NEW |