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 "Benchmark.h" |
9 #include "SkAAClip.h" | 9 #include "SkAAClip.h" |
| 10 #include "SkCanvas.h" |
10 #include "SkPath.h" | 11 #include "SkPath.h" |
| 12 #include "SkRandom.h" |
11 #include "SkRegion.h" | 13 #include "SkRegion.h" |
12 #include "SkString.h" | 14 #include "SkString.h" |
13 #include "SkCanvas.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 Benchmark { |
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 public: | 26 public: |
27 AAClipBench(bool doPath, bool doAA) | 27 AAClipBench(bool doPath, bool doAA) |
28 : fDoPath(doPath) | 28 : fDoPath(doPath) |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 if (fDoPath) { | 72 if (fDoPath) { |
73 canvas->drawPath(fClipPath, paint); | 73 canvas->drawPath(fClipPath, paint); |
74 } else { | 74 } else { |
75 canvas->drawRect(fClipRect, paint); | 75 canvas->drawRect(fClipRect, paint); |
76 } | 76 } |
77 #endif | 77 #endif |
78 canvas->restore(); | 78 canvas->restore(); |
79 } | 79 } |
80 } | 80 } |
81 private: | 81 private: |
82 typedef SkBenchmark INHERITED; | 82 typedef Benchmark INHERITED; |
83 }; | 83 }; |
84 | 84 |
85 //////////////////////////////////////////////////////////////////////////////// | 85 //////////////////////////////////////////////////////////////////////////////// |
86 // This bench tests out nested clip stacks. It is intended to simulate | 86 // This bench tests out nested clip stacks. It is intended to simulate |
87 // how WebKit nests clips. | 87 // how WebKit nests clips. |
88 class NestedAAClipBench : public SkBenchmark { | 88 class NestedAAClipBench : public Benchmark { |
89 SkString fName; | 89 SkString fName; |
90 bool fDoAA; | 90 bool fDoAA; |
91 SkRect fDrawRect; | 91 SkRect fDrawRect; |
92 SkRandom fRandom; | 92 SkRandom fRandom; |
93 | 93 |
94 static const int kNestingDepth = 3; | 94 static const int kNestingDepth = 3; |
95 static const int kImageSize = 400; | 95 static const int kImageSize = 400; |
96 | 96 |
97 SkPoint fSizes[kNestingDepth+1]; | 97 SkPoint fSizes[kNestingDepth+1]; |
98 | 98 |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 | 160 |
161 virtual void onDraw(const int loops, SkCanvas* canvas) { | 161 virtual void onDraw(const int loops, SkCanvas* canvas) { |
162 | 162 |
163 for (int i = 0; i < loops; ++i) { | 163 for (int i = 0; i < loops; ++i) { |
164 SkPoint offset = SkPoint::Make(0, 0); | 164 SkPoint offset = SkPoint::Make(0, 0); |
165 this->recurse(canvas, 0, offset); | 165 this->recurse(canvas, 0, offset); |
166 } | 166 } |
167 } | 167 } |
168 | 168 |
169 private: | 169 private: |
170 typedef SkBenchmark INHERITED; | 170 typedef Benchmark INHERITED; |
171 }; | 171 }; |
172 | 172 |
173 //////////////////////////////////////////////////////////////////////////////// | 173 //////////////////////////////////////////////////////////////////////////////// |
174 class AAClipBuilderBench : public SkBenchmark { | 174 class AAClipBuilderBench : public Benchmark { |
175 SkString fName; | 175 SkString fName; |
176 SkPath fPath; | 176 SkPath fPath; |
177 SkRect fRect; | 177 SkRect fRect; |
178 SkRegion fRegion; | 178 SkRegion fRegion; |
179 bool fDoPath; | 179 bool fDoPath; |
180 bool fDoAA; | 180 bool fDoAA; |
181 | 181 |
182 public: | 182 public: |
183 AAClipBuilderBench(bool doPath, bool doAA) { | 183 AAClipBuilderBench(bool doPath, bool doAA) { |
184 fDoPath = doPath; | 184 fDoPath = doPath; |
(...skipping 17 matching lines...) Expand all Loading... |
202 for (int i = 0; i < loops; ++i) { | 202 for (int i = 0; i < loops; ++i) { |
203 SkAAClip clip; | 203 SkAAClip clip; |
204 if (fDoPath) { | 204 if (fDoPath) { |
205 clip.setPath(fPath, &fRegion, fDoAA); | 205 clip.setPath(fPath, &fRegion, fDoAA); |
206 } else { | 206 } else { |
207 clip.setRect(fRect, fDoAA); | 207 clip.setRect(fRect, fDoAA); |
208 } | 208 } |
209 } | 209 } |
210 } | 210 } |
211 private: | 211 private: |
212 typedef SkBenchmark INHERITED; | 212 typedef Benchmark INHERITED; |
213 }; | 213 }; |
214 | 214 |
215 //////////////////////////////////////////////////////////////////////////////// | 215 //////////////////////////////////////////////////////////////////////////////// |
216 class AAClipRegionBench : public SkBenchmark { | 216 class AAClipRegionBench : public Benchmark { |
217 public: | 217 public: |
218 AAClipRegionBench() { | 218 AAClipRegionBench() { |
219 SkPath path; | 219 SkPath path; |
220 // test conversion of a complex clip to a aaclip | 220 // test conversion of a complex clip to a aaclip |
221 path.addCircle(0, 0, SkIntToScalar(200)); | 221 path.addCircle(0, 0, SkIntToScalar(200)); |
222 path.addCircle(0, 0, SkIntToScalar(180)); | 222 path.addCircle(0, 0, SkIntToScalar(180)); |
223 // evenodd means we've constructed basically a stroked circle | 223 // evenodd means we've constructed basically a stroked circle |
224 path.setFillType(SkPath::kEvenOdd_FillType); | 224 path.setFillType(SkPath::kEvenOdd_FillType); |
225 | 225 |
226 SkIRect bounds; | 226 SkIRect bounds; |
227 path.getBounds().roundOut(&bounds); | 227 path.getBounds().roundOut(&bounds); |
228 fRegion.setPath(path, SkRegion(bounds)); | 228 fRegion.setPath(path, SkRegion(bounds)); |
229 } | 229 } |
230 | 230 |
231 protected: | 231 protected: |
232 virtual const char* onGetName() { return "aaclip_setregion"; } | 232 virtual const char* onGetName() { return "aaclip_setregion"; } |
233 virtual void onDraw(const int loops, SkCanvas*) { | 233 virtual void onDraw(const int loops, SkCanvas*) { |
234 for (int i = 0; i < loops; ++i) { | 234 for (int i = 0; i < loops; ++i) { |
235 SkAAClip clip; | 235 SkAAClip clip; |
236 clip.setRegion(fRegion); | 236 clip.setRegion(fRegion); |
237 } | 237 } |
238 } | 238 } |
239 | 239 |
240 private: | 240 private: |
241 SkRegion fRegion; | 241 SkRegion fRegion; |
242 typedef SkBenchmark INHERITED; | 242 typedef Benchmark INHERITED; |
243 }; | 243 }; |
244 | 244 |
245 //////////////////////////////////////////////////////////////////////////////// | 245 //////////////////////////////////////////////////////////////////////////////// |
246 | 246 |
247 DEF_BENCH( return SkNEW_ARGS(AAClipBuilderBench, (false, false)); ) | 247 DEF_BENCH( return SkNEW_ARGS(AAClipBuilderBench, (false, false)); ) |
248 DEF_BENCH( return SkNEW_ARGS(AAClipBuilderBench, (false, true)); ) | 248 DEF_BENCH( return SkNEW_ARGS(AAClipBuilderBench, (false, true)); ) |
249 DEF_BENCH( return SkNEW_ARGS(AAClipBuilderBench, (true, false)); ) | 249 DEF_BENCH( return SkNEW_ARGS(AAClipBuilderBench, (true, false)); ) |
250 DEF_BENCH( return SkNEW_ARGS(AAClipBuilderBench, (true, true)); ) | 250 DEF_BENCH( return SkNEW_ARGS(AAClipBuilderBench, (true, true)); ) |
251 DEF_BENCH( return SkNEW_ARGS(AAClipRegionBench, ()); ) | 251 DEF_BENCH( return SkNEW_ARGS(AAClipRegionBench, ()); ) |
252 DEF_BENCH( return SkNEW_ARGS(AAClipBench, (false, false)); ) | 252 DEF_BENCH( return SkNEW_ARGS(AAClipBench, (false, false)); ) |
253 DEF_BENCH( return SkNEW_ARGS(AAClipBench, (false, true)); ) | 253 DEF_BENCH( return SkNEW_ARGS(AAClipBench, (false, true)); ) |
254 DEF_BENCH( return SkNEW_ARGS(AAClipBench, (true, false)); ) | 254 DEF_BENCH( return SkNEW_ARGS(AAClipBench, (true, false)); ) |
255 DEF_BENCH( return SkNEW_ARGS(AAClipBench, (true, true)); ) | 255 DEF_BENCH( return SkNEW_ARGS(AAClipBench, (true, true)); ) |
256 DEF_BENCH( return SkNEW_ARGS(NestedAAClipBench, (false)); ) | 256 DEF_BENCH( return SkNEW_ARGS(NestedAAClipBench, (false)); ) |
257 DEF_BENCH( return SkNEW_ARGS(NestedAAClipBench, (true)); ) | 257 DEF_BENCH( return SkNEW_ARGS(NestedAAClipBench, (true)); ) |
OLD | NEW |