OLD | NEW |
---|---|
1 /* | 1 /* |
epoger
2013/09/04 14:45:51
One more toplevel comment:
Presumably, this CL is
scroggo
2013/09/04 14:51:31
I don't know whether you're in the minority, but I
mtklein
2013/09/04 19:06:51
Sure. Added 1590. Guess I'm spoiled by cs/ where
| |
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 "SkAAClip.h" | 9 #include "SkAAClip.h" |
10 #include "SkPath.h" | 10 #include "SkPath.h" |
11 #include "SkRegion.h" | 11 #include "SkRegion.h" |
12 #include "SkString.h" | 12 #include "SkString.h" |
13 #include "SkCanvas.h" | 13 #include "SkCanvas.h" |
14 #include "SkRandom.h" | 14 #include "SkRandom.h" |
15 | 15 |
16 //////////////////////////////////////////////////////////////////////////////// | 16 //////////////////////////////////////////////////////////////////////////////// |
17 // This bench tests out AA/BW clipping via canvas' clipPath and clipRect calls | 17 // This bench tests out AA/BW clipping via canvas' clipPath and clipRect calls |
18 class AAClipBench : public SkBenchmark { | 18 class AAClipBench : public SkBenchmark { |
19 SkString fName; | 19 SkString fName; |
20 SkPath fClipPath; | 20 SkPath fClipPath; |
21 SkRect fClipRect; | 21 SkRect fClipRect; |
22 SkRect fDrawRect; | 22 SkRect fDrawRect; |
23 bool fDoPath; | 23 bool fDoPath; |
24 bool fDoAA; | 24 bool fDoAA; |
25 | 25 |
26 enum { | |
27 N = SkBENCHLOOP(200), | |
28 }; | |
29 | |
30 public: | 26 public: |
31 AAClipBench(void* param, bool doPath, bool doAA) | 27 AAClipBench(void* param, bool doPath, bool doAA) |
32 : INHERITED(param) | 28 : INHERITED(param) |
33 , fDoPath(doPath) | 29 , fDoPath(doPath) |
34 , fDoAA(doAA) { | 30 , fDoAA(doAA) { |
35 | 31 |
36 fName.printf("aaclip_%s_%s", | 32 fName.printf("aaclip_%s_%s", |
37 doPath ? "path" : "rect", | 33 doPath ? "path" : "rect", |
38 doAA ? "AA" : "BW"); | 34 doAA ? "AA" : "BW"); |
39 | 35 |
40 fClipRect.set(SkFloatToScalar(10.5f), SkFloatToScalar(10.5f), | 36 fClipRect.set(SkFloatToScalar(10.5f), SkFloatToScalar(10.5f), |
41 SkFloatToScalar(50.5f), SkFloatToScalar(50.5f)); | 37 SkFloatToScalar(50.5f), SkFloatToScalar(50.5f)); |
42 fClipPath.addRoundRect(fClipRect, SkIntToScalar(10), SkIntToScalar(10)); | 38 fClipPath.addRoundRect(fClipRect, SkIntToScalar(10), SkIntToScalar(10)); |
43 fDrawRect.set(SkIntToScalar(0), SkIntToScalar(0), | 39 fDrawRect.set(SkIntToScalar(0), SkIntToScalar(0), |
44 SkIntToScalar(100), SkIntToScalar(100)); | 40 SkIntToScalar(100), SkIntToScalar(100)); |
45 | 41 |
46 SkASSERT(fClipPath.isConvex()); | 42 SkASSERT(fClipPath.isConvex()); |
47 } | 43 } |
48 | 44 |
49 protected: | 45 protected: |
50 virtual const char* onGetName() { return fName.c_str(); } | 46 virtual const char* onGetName() { return fName.c_str(); } |
51 virtual void onDraw(SkCanvas* canvas) { | 47 virtual void onDraw(SkCanvas* canvas) { |
52 | 48 |
53 SkPaint paint; | 49 SkPaint paint; |
54 this->setupPaint(&paint); | 50 this->setupPaint(&paint); |
55 | 51 |
56 for (int i = 0; i < N; ++i) { | 52 for (int i = 0; i < this->getLoops(); ++i) { |
57 // jostle the clip regions each time to prevent caching | 53 // jostle the clip regions each time to prevent caching |
58 fClipRect.offset((i % 2) == 0 ? SkIntToScalar(10) : SkIntToScalar(-1 0), 0); | 54 fClipRect.offset((i % 2) == 0 ? SkIntToScalar(10) : SkIntToScalar(-1 0), 0); |
59 fClipPath.reset(); | 55 fClipPath.reset(); |
60 fClipPath.addRoundRect(fClipRect, | 56 fClipPath.addRoundRect(fClipRect, |
61 SkIntToScalar(5), SkIntToScalar(5)); | 57 SkIntToScalar(5), SkIntToScalar(5)); |
62 SkASSERT(fClipPath.isConvex()); | 58 SkASSERT(fClipPath.isConvex()); |
63 | 59 |
64 canvas->save(); | 60 canvas->save(); |
65 #if 1 | 61 #if 1 |
66 if (fDoPath) { | 62 if (fDoPath) { |
(...skipping 22 matching lines...) Loading... | |
89 | 85 |
90 //////////////////////////////////////////////////////////////////////////////// | 86 //////////////////////////////////////////////////////////////////////////////// |
91 // This bench tests out nested clip stacks. It is intended to simulate | 87 // This bench tests out nested clip stacks. It is intended to simulate |
92 // how WebKit nests clips. | 88 // how WebKit nests clips. |
93 class NestedAAClipBench : public SkBenchmark { | 89 class NestedAAClipBench : public SkBenchmark { |
94 SkString fName; | 90 SkString fName; |
95 bool fDoAA; | 91 bool fDoAA; |
96 SkRect fDrawRect; | 92 SkRect fDrawRect; |
97 SkRandom fRandom; | 93 SkRandom fRandom; |
98 | 94 |
99 static const int kNumDraws = SkBENCHLOOP(2); | |
100 static const int kNestingDepth = 3; | 95 static const int kNestingDepth = 3; |
101 static const int kImageSize = 400; | 96 static const int kImageSize = 400; |
102 | 97 |
103 SkPoint fSizes[kNestingDepth+1]; | 98 SkPoint fSizes[kNestingDepth+1]; |
104 | 99 |
105 public: | 100 public: |
106 NestedAAClipBench(void* param, bool doAA) | 101 NestedAAClipBench(void* param, bool doAA) |
107 : INHERITED(param) | 102 : INHERITED(param) |
108 , fDoAA(doAA) { | 103 , fDoAA(doAA) { |
109 | 104 |
(...skipping 52 matching lines...) Loading... | |
162 childOffset.fX = offset.fX; | 157 childOffset.fX = offset.fX; |
163 childOffset.fY = offset.fY + fSizes[depth+1].fY; | 158 childOffset.fY = offset.fY + fSizes[depth+1].fY; |
164 this->recurse(canvas, depth+1, childOffset); | 159 this->recurse(canvas, depth+1, childOffset); |
165 } | 160 } |
166 | 161 |
167 canvas->restore(); | 162 canvas->restore(); |
168 } | 163 } |
169 | 164 |
170 virtual void onDraw(SkCanvas* canvas) { | 165 virtual void onDraw(SkCanvas* canvas) { |
171 | 166 |
172 for (int i = 0; i < kNumDraws; ++i) { | 167 for (int i = 0; i < this->getLoops(); ++i) { |
173 SkPoint offset = SkPoint::Make(0, 0); | 168 SkPoint offset = SkPoint::Make(0, 0); |
174 this->recurse(canvas, 0, offset); | 169 this->recurse(canvas, 0, offset); |
175 } | 170 } |
176 } | 171 } |
177 | 172 |
178 private: | 173 private: |
179 typedef SkBenchmark INHERITED; | 174 typedef SkBenchmark INHERITED; |
180 }; | 175 }; |
181 | 176 |
182 //////////////////////////////////////////////////////////////////////////////// | 177 //////////////////////////////////////////////////////////////////////////////// |
183 class AAClipBuilderBench : public SkBenchmark { | 178 class AAClipBuilderBench : public SkBenchmark { |
184 SkString fName; | 179 SkString fName; |
185 SkPath fPath; | 180 SkPath fPath; |
186 SkRect fRect; | 181 SkRect fRect; |
187 SkRegion fRegion; | 182 SkRegion fRegion; |
188 bool fDoPath; | 183 bool fDoPath; |
189 bool fDoAA; | 184 bool fDoAA; |
190 | 185 |
191 enum { | |
192 N = SkBENCHLOOP(200), | |
193 }; | |
194 | |
195 public: | 186 public: |
196 AAClipBuilderBench(void* param, bool doPath, bool doAA) : INHERITED(param) { | 187 AAClipBuilderBench(void* param, bool doPath, bool doAA) : INHERITED(param) { |
197 fDoPath = doPath; | 188 fDoPath = doPath; |
198 fDoAA = doAA; | 189 fDoAA = doAA; |
199 | 190 |
200 fName.printf("aaclip_build_%s_%s", doPath ? "path" : "rect", | 191 fName.printf("aaclip_build_%s_%s", doPath ? "path" : "rect", |
201 doAA ? "AA" : "BW"); | 192 doAA ? "AA" : "BW"); |
202 | 193 |
203 fRegion.setRect(0, 0, 640, 480); | 194 fRegion.setRect(0, 0, 640, 480); |
204 fRect.set(fRegion.getBounds()); | 195 fRect.set(fRegion.getBounds()); |
205 fRect.inset(SK_Scalar1/4, SK_Scalar1/4); | 196 fRect.inset(SK_Scalar1/4, SK_Scalar1/4); |
206 fPath.addRoundRect(fRect, SkIntToScalar(20), SkIntToScalar(20)); | 197 fPath.addRoundRect(fRect, SkIntToScalar(20), SkIntToScalar(20)); |
207 } | 198 } |
208 | 199 |
209 protected: | 200 protected: |
210 virtual const char* onGetName() { return fName.c_str(); } | 201 virtual const char* onGetName() { return fName.c_str(); } |
211 virtual void onDraw(SkCanvas*) { | 202 virtual void onDraw(SkCanvas*) { |
212 SkPaint paint; | 203 SkPaint paint; |
213 this->setupPaint(&paint); | 204 this->setupPaint(&paint); |
214 | 205 |
215 for (int i = 0; i < N; ++i) { | 206 for (int i = 0; i < this->getLoops(); ++i) { |
216 SkAAClip clip; | 207 SkAAClip clip; |
217 if (fDoPath) { | 208 if (fDoPath) { |
218 clip.setPath(fPath, &fRegion, fDoAA); | 209 clip.setPath(fPath, &fRegion, fDoAA); |
219 } else { | 210 } else { |
220 clip.setRect(fRect, fDoAA); | 211 clip.setRect(fRect, fDoAA); |
221 } | 212 } |
222 } | 213 } |
223 } | 214 } |
224 private: | 215 private: |
225 typedef SkBenchmark INHERITED; | 216 typedef SkBenchmark INHERITED; |
(...skipping 11 matching lines...) Loading... | |
237 path.setFillType(SkPath::kEvenOdd_FillType); | 228 path.setFillType(SkPath::kEvenOdd_FillType); |
238 | 229 |
239 SkIRect bounds; | 230 SkIRect bounds; |
240 path.getBounds().roundOut(&bounds); | 231 path.getBounds().roundOut(&bounds); |
241 fRegion.setPath(path, SkRegion(bounds)); | 232 fRegion.setPath(path, SkRegion(bounds)); |
242 } | 233 } |
243 | 234 |
244 protected: | 235 protected: |
245 virtual const char* onGetName() { return "aaclip_setregion"; } | 236 virtual const char* onGetName() { return "aaclip_setregion"; } |
246 virtual void onDraw(SkCanvas*) { | 237 virtual void onDraw(SkCanvas*) { |
247 for (int i = 0; i < N; ++i) { | 238 for (int i = 0; i < this->getLoops(); ++i) { |
248 SkAAClip clip; | 239 SkAAClip clip; |
249 clip.setRegion(fRegion); | 240 clip.setRegion(fRegion); |
250 } | 241 } |
251 } | 242 } |
252 | 243 |
253 private: | 244 private: |
254 enum { | |
255 N = SkBENCHLOOP(400), | |
256 }; | |
257 SkRegion fRegion; | 245 SkRegion fRegion; |
258 typedef SkBenchmark INHERITED; | 246 typedef SkBenchmark INHERITED; |
259 }; | 247 }; |
260 | 248 |
261 //////////////////////////////////////////////////////////////////////////////// | 249 //////////////////////////////////////////////////////////////////////////////// |
262 | 250 |
263 static SkBenchmark* Fact0(void* p) { return SkNEW_ARGS(AAClipBuilderBench, (p, f alse, false)); } | 251 static SkBenchmark* Fact0(void* p) { return SkNEW_ARGS(AAClipBuilderBench, (p, f alse, false)); } |
264 static SkBenchmark* Fact1(void* p) { return SkNEW_ARGS(AAClipBuilderBench, (p, f alse, true)); } | 252 static SkBenchmark* Fact1(void* p) { return SkNEW_ARGS(AAClipBuilderBench, (p, f alse, true)); } |
265 static SkBenchmark* Fact2(void* p) { return SkNEW_ARGS(AAClipBuilderBench, (p, t rue, false)); } | 253 static SkBenchmark* Fact2(void* p) { return SkNEW_ARGS(AAClipBuilderBench, (p, t rue, false)); } |
266 static SkBenchmark* Fact3(void* p) { return SkNEW_ARGS(AAClipBuilderBench, (p, t rue, true)); } | 254 static SkBenchmark* Fact3(void* p) { return SkNEW_ARGS(AAClipBuilderBench, (p, t rue, true)); } |
(...skipping 14 matching lines...) Loading... | |
281 static BenchRegistry gReg000(Fact000); | 269 static BenchRegistry gReg000(Fact000); |
282 static BenchRegistry gReg001(Fact001); | 270 static BenchRegistry gReg001(Fact001); |
283 static BenchRegistry gReg002(Fact002); | 271 static BenchRegistry gReg002(Fact002); |
284 static BenchRegistry gReg003(Fact003); | 272 static BenchRegistry gReg003(Fact003); |
285 | 273 |
286 static SkBenchmark* Fact004(void* p) { return SkNEW_ARGS(NestedAAClipBench, (p, false)); } | 274 static SkBenchmark* Fact004(void* p) { return SkNEW_ARGS(NestedAAClipBench, (p, false)); } |
287 static SkBenchmark* Fact005(void* p) { return SkNEW_ARGS(NestedAAClipBench, (p, true)); } | 275 static SkBenchmark* Fact005(void* p) { return SkNEW_ARGS(NestedAAClipBench, (p, true)); } |
288 | 276 |
289 static BenchRegistry gReg004(Fact004); | 277 static BenchRegistry gReg004(Fact004); |
290 static BenchRegistry gReg005(Fact005); | 278 static BenchRegistry gReg005(Fact005); |
OLD | NEW |