Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(141)

Side by Side Diff: bench/DashBench.cpp

Issue 23478013: Major bench refactoring. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: merge with head agani Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « bench/ColorFilterBench.cpp ('k') | bench/DecodeBench.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "SkBitmap.h" 9 #include "SkBitmap.h"
10 #include "SkCanvas.h" 10 #include "SkCanvas.h"
(...skipping 19 matching lines...) Expand all
30 } 30 }
31 31
32 class DashBench : public SkBenchmark { 32 class DashBench : public SkBenchmark {
33 protected: 33 protected:
34 SkString fName; 34 SkString fName;
35 SkTDArray<SkScalar> fIntervals; 35 SkTDArray<SkScalar> fIntervals;
36 int fWidth; 36 int fWidth;
37 SkPoint fPts[2]; 37 SkPoint fPts[2];
38 bool fDoClip; 38 bool fDoClip;
39 39
40 enum {
41 N = SkBENCHLOOP(100)
42 };
43 public: 40 public:
44 DashBench(void* param, const SkScalar intervals[], int count, int width, 41 DashBench(void* param, const SkScalar intervals[], int count, int width,
45 bool doClip = false) : INHERITED(param) { 42 bool doClip = false) : INHERITED(param) {
46 fIntervals.append(count, intervals); 43 fIntervals.append(count, intervals);
47 for (int i = 0; i < count; ++i) { 44 for (int i = 0; i < count; ++i) {
48 fIntervals[i] *= width; 45 fIntervals[i] *= width;
49 } 46 }
50 fWidth = width; 47 fWidth = width;
51 fName.printf("dash_%d_%s", width, doClip ? "clipped" : "noclip"); 48 fName.printf("dash_%d_%s", width, doClip ? "clipped" : "noclip");
52 fDoClip = doClip; 49 fDoClip = doClip;
(...skipping 25 matching lines...) Expand all
78 fIntervals.count(), 0))->unref( ); 75 fIntervals.count(), 0))->unref( );
79 76
80 if (fDoClip) { 77 if (fDoClip) {
81 SkRect r = path.getBounds(); 78 SkRect r = path.getBounds();
82 r.inset(-SkIntToScalar(20), -SkIntToScalar(20)); 79 r.inset(-SkIntToScalar(20), -SkIntToScalar(20));
83 // now move it so we don't intersect 80 // now move it so we don't intersect
84 r.offset(0, r.height() * 3 / 2); 81 r.offset(0, r.height() * 3 / 2);
85 canvas->clipRect(r); 82 canvas->clipRect(r);
86 } 83 }
87 84
88 this->handlePath(canvas, path, paint, N); 85 this->handlePath(canvas, path, paint, this->getLoops());
89 } 86 }
90 87
91 virtual void handlePath(SkCanvas* canvas, const SkPath& path, 88 virtual void handlePath(SkCanvas* canvas, const SkPath& path,
92 const SkPaint& paint, int N) { 89 const SkPaint& paint, int N) {
93 for (int i = 0; i < N; ++i) { 90 for (int i = 0; i < N; ++i) {
94 // canvas->drawPoints(SkCanvas::kLines_PointMode, 2, fPts, paint); 91 // canvas->drawPoints(SkCanvas::kLines_PointMode, 2, fPts, paint);
95 canvas->drawPath(path, paint); 92 canvas->drawPath(path, paint);
96 } 93 }
97 } 94 }
98 95
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 path->cubicTo(x0, y0 + 400 * SK_Scalar1, 173 path->cubicTo(x0, y0 + 400 * SK_Scalar1,
177 x0 + 600 * SK_Scalar1, y0 + 400 * SK_Scalar1, 174 x0 + 600 * SK_Scalar1, y0 + 400 * SK_Scalar1,
178 x0 + 600 * SK_Scalar1, y0); 175 x0 + 600 * SK_Scalar1, y0);
179 } 176 }
180 177
181 class MakeDashBench : public SkBenchmark { 178 class MakeDashBench : public SkBenchmark {
182 SkString fName; 179 SkString fName;
183 SkPath fPath; 180 SkPath fPath;
184 SkAutoTUnref<SkPathEffect> fPE; 181 SkAutoTUnref<SkPathEffect> fPE;
185 182
186 enum {
187 N = SkBENCHLOOP(400)
188 };
189
190 public: 183 public:
191 MakeDashBench(void* param, void (*proc)(SkPath*), const char name[]) : INHER ITED(param) { 184 MakeDashBench(void* param, void (*proc)(SkPath*), const char name[]) : INHER ITED(param) {
192 fName.printf("makedash_%s", name); 185 fName.printf("makedash_%s", name);
193 proc(&fPath); 186 proc(&fPath);
194 187
195 SkScalar vals[] = { SkIntToScalar(4), SkIntToScalar(4) }; 188 SkScalar vals[] = { SkIntToScalar(4), SkIntToScalar(4) };
196 fPE.reset(new SkDashPathEffect(vals, 2, 0)); 189 fPE.reset(new SkDashPathEffect(vals, 2, 0));
197 } 190 }
198 191
199 protected: 192 protected:
200 virtual const char* onGetName() SK_OVERRIDE { 193 virtual const char* onGetName() SK_OVERRIDE {
201 return fName.c_str(); 194 return fName.c_str();
202 } 195 }
203 196
204 virtual void onDraw(SkCanvas*) SK_OVERRIDE { 197 virtual void onDraw(SkCanvas*) SK_OVERRIDE {
205 SkPath dst; 198 SkPath dst;
206 for (int i = 0; i < N; ++i) { 199 for (int i = 0; i < this->getLoops(); ++i) {
207 SkStrokeRec rec(SkStrokeRec::kHairline_InitStyle); 200 SkStrokeRec rec(SkStrokeRec::kHairline_InitStyle);
208 201
209 fPE->filterPath(&dst, fPath, &rec, NULL); 202 fPE->filterPath(&dst, fPath, &rec, NULL);
210 dst.rewind(); 203 dst.rewind();
211 } 204 }
212 } 205 }
213 206
214 private: 207 private:
215 typedef SkBenchmark INHERITED; 208 typedef SkBenchmark INHERITED;
216 }; 209 };
217 210
218 /* 211 /*
219 * We try to special case square dashes (intervals are equal to strokewidth). 212 * We try to special case square dashes (intervals are equal to strokewidth).
220 */ 213 */
221 class DashLineBench : public SkBenchmark { 214 class DashLineBench : public SkBenchmark {
222 SkString fName; 215 SkString fName;
223 SkScalar fStrokeWidth; 216 SkScalar fStrokeWidth;
224 bool fIsRound; 217 bool fIsRound;
225 SkAutoTUnref<SkPathEffect> fPE; 218 SkAutoTUnref<SkPathEffect> fPE;
226 219
227 enum {
228 N = SkBENCHLOOP(200)
229 };
230
231 public: 220 public:
232 DashLineBench(void* param, SkScalar width, bool isRound) : INHERITED(param) { 221 DashLineBench(void* param, SkScalar width, bool isRound) : INHERITED(param) {
233 fName.printf("dashline_%g_%s", SkScalarToFloat(width), isRound ? "circle " : "square"); 222 fName.printf("dashline_%g_%s", SkScalarToFloat(width), isRound ? "circle " : "square");
234 fStrokeWidth = width; 223 fStrokeWidth = width;
235 fIsRound = isRound; 224 fIsRound = isRound;
236 225
237 SkScalar vals[] = { SK_Scalar1, SK_Scalar1 }; 226 SkScalar vals[] = { SK_Scalar1, SK_Scalar1 };
238 fPE.reset(new SkDashPathEffect(vals, 2, 0)); 227 fPE.reset(new SkDashPathEffect(vals, 2, 0));
239 } 228 }
240 229
241 protected: 230 protected:
242 virtual const char* onGetName() SK_OVERRIDE { 231 virtual const char* onGetName() SK_OVERRIDE {
243 return fName.c_str(); 232 return fName.c_str();
244 } 233 }
245 234
246 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { 235 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE {
247 SkPaint paint; 236 SkPaint paint;
248 this->setupPaint(&paint); 237 this->setupPaint(&paint);
249 paint.setStrokeWidth(fStrokeWidth); 238 paint.setStrokeWidth(fStrokeWidth);
250 paint.setStrokeCap(fIsRound ? SkPaint::kRound_Cap : SkPaint::kSquare_Cap ); 239 paint.setStrokeCap(fIsRound ? SkPaint::kRound_Cap : SkPaint::kSquare_Cap );
251 paint.setPathEffect(fPE); 240 paint.setPathEffect(fPE);
252 for (int i = 0; i < N; ++i) { 241 for (int i = 0; i < this->getLoops(); ++i) {
253 canvas->drawLine(10 * SK_Scalar1, 10 * SK_Scalar1, 242 canvas->drawLine(10 * SK_Scalar1, 10 * SK_Scalar1,
254 640 * SK_Scalar1, 10 * SK_Scalar1, paint); 243 640 * SK_Scalar1, 10 * SK_Scalar1, paint);
255 } 244 }
256 } 245 }
257 246
258 private: 247 private:
259 typedef SkBenchmark INHERITED; 248 typedef SkBenchmark INHERITED;
260 }; 249 };
261 250
262 class DrawPointsDashingBench : public SkBenchmark { 251 class DrawPointsDashingBench : public SkBenchmark {
263 SkString fName; 252 SkString fName;
264 int fStrokeWidth; 253 int fStrokeWidth;
265 bool fDoAA; 254 bool fDoAA;
266 255
267 SkAutoTUnref<SkPathEffect> fPathEffect; 256 SkAutoTUnref<SkPathEffect> fPathEffect;
268 257
269 enum {
270 N = SkBENCHLOOP(480)
271 };
272
273 public: 258 public:
274 DrawPointsDashingBench(void* param, int dashLength, int strokeWidth, bool do AA) 259 DrawPointsDashingBench(void* param, int dashLength, int strokeWidth, bool do AA)
275 : INHERITED(param) { 260 : INHERITED(param) {
276 fName.printf("drawpointsdash_%d_%d%s", dashLength, strokeWidth, doAA ? " _aa" : "_bw"); 261 fName.printf("drawpointsdash_%d_%d%s", dashLength, strokeWidth, doAA ? " _aa" : "_bw");
277 fStrokeWidth = strokeWidth; 262 fStrokeWidth = strokeWidth;
278 fDoAA = doAA; 263 fDoAA = doAA;
279 264
280 SkScalar vals[] = { SkIntToScalar(dashLength), SkIntToScalar(dashLength) }; 265 SkScalar vals[] = { SkIntToScalar(dashLength), SkIntToScalar(dashLength) };
281 fPathEffect.reset(new SkDashPathEffect(vals, 2, SK_Scalar1, false)); 266 fPathEffect.reset(new SkDashPathEffect(vals, 2, SK_Scalar1, false));
282 } 267 }
283 268
284 protected: 269 protected:
285 virtual const char* onGetName() SK_OVERRIDE { 270 virtual const char* onGetName() SK_OVERRIDE {
286 return fName.c_str(); 271 return fName.c_str();
287 } 272 }
288 273
289 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { 274 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE {
290
291 SkPaint p; 275 SkPaint p;
292 this->setupPaint(&p); 276 this->setupPaint(&p);
293 p.setColor(SK_ColorBLACK); 277 p.setColor(SK_ColorBLACK);
294 p.setStyle(SkPaint::kStroke_Style); 278 p.setStyle(SkPaint::kStroke_Style);
295 p.setStrokeWidth(SkIntToScalar(fStrokeWidth)); 279 p.setStrokeWidth(SkIntToScalar(fStrokeWidth));
296 p.setPathEffect(fPathEffect); 280 p.setPathEffect(fPathEffect);
297 p.setAntiAlias(fDoAA); 281 p.setAntiAlias(fDoAA);
298 282
299 SkPoint pts[2] = { 283 SkPoint pts[2] = {
300 { SkIntToScalar(10), 0 }, 284 { SkIntToScalar(10), 0 },
301 { SkIntToScalar(640), 0 } 285 { SkIntToScalar(640), 0 }
302 }; 286 };
303 287
304 for (int i = 0; i < N; ++i) { 288 for (int i = 0; i < this->getLoops(); ++i) {
305
306 pts[0].fY = pts[1].fY = SkIntToScalar(i % 480); 289 pts[0].fY = pts[1].fY = SkIntToScalar(i % 480);
307 canvas->drawPoints(SkCanvas::kLines_PointMode, 2, pts, p); 290 canvas->drawPoints(SkCanvas::kLines_PointMode, 2, pts, p);
308 } 291 }
309 } 292 }
310 293
311 private: 294 private:
312 typedef SkBenchmark INHERITED; 295 typedef SkBenchmark INHERITED;
313 }; 296 };
314 297
315 // Want to test how we handle dashing when 99% of the dash is clipped out 298 // Want to test how we handle dashing when 99% of the dash is clipped out
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
374 return fName.c_str(); 357 return fName.c_str();
375 } 358 }
376 359
377 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { 360 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE {
378 SkPaint p; 361 SkPaint p;
379 this->setupPaint(&p); 362 this->setupPaint(&p);
380 p.setStyle(SkPaint::kStroke_Style); 363 p.setStyle(SkPaint::kStroke_Style);
381 p.setStrokeWidth(fStrokeWidth); 364 p.setStrokeWidth(fStrokeWidth);
382 p.setPathEffect(fPathEffect); 365 p.setPathEffect(fPathEffect);
383 366
384 canvas->drawPoints(SkCanvas::kLines_PointMode, 2, fPts, p); 367 for (int i = 0; i < this->getLoops(); i++) {
368 canvas->drawPoints(SkCanvas::kLines_PointMode, 2, fPts, p);
369 }
385 } 370 }
386 371
387 private: 372 private:
388 typedef SkBenchmark INHERITED; 373 typedef SkBenchmark INHERITED;
389 }; 374 };
390 375
391 376
392 /////////////////////////////////////////////////////////////////////////////// 377 ///////////////////////////////////////////////////////////////////////////////
393 378
394 static const SkScalar gDots[] = { SK_Scalar1, SK_Scalar1 }; 379 static const SkScalar gDots[] = { SK_Scalar1, SK_Scalar1 };
(...skipping 29 matching lines...) Expand all
424 DEF_BENCH( return new GiantDashBench(p, GiantDashBench::kVert_LineType, 0); ) 409 DEF_BENCH( return new GiantDashBench(p, GiantDashBench::kVert_LineType, 0); )
425 DEF_BENCH( return new GiantDashBench(p, GiantDashBench::kDiag_LineType, 0); ) 410 DEF_BENCH( return new GiantDashBench(p, GiantDashBench::kDiag_LineType, 0); )
426 411
427 // pass 2 to explicitly avoid any 1-is-the-same-as-hairline special casing 412 // pass 2 to explicitly avoid any 1-is-the-same-as-hairline special casing
428 413
429 // hori_2 is just too slow to enable at the moment 414 // hori_2 is just too slow to enable at the moment
430 DEF_BENCH( return new GiantDashBench(p, GiantDashBench::kHori_LineType, 2); ) 415 DEF_BENCH( return new GiantDashBench(p, GiantDashBench::kHori_LineType, 2); )
431 DEF_BENCH( return new GiantDashBench(p, GiantDashBench::kVert_LineType, 2); ) 416 DEF_BENCH( return new GiantDashBench(p, GiantDashBench::kVert_LineType, 2); )
432 DEF_BENCH( return new GiantDashBench(p, GiantDashBench::kDiag_LineType, 2); ) 417 DEF_BENCH( return new GiantDashBench(p, GiantDashBench::kDiag_LineType, 2); )
433 #endif 418 #endif
OLDNEW
« no previous file with comments | « bench/ColorFilterBench.cpp ('k') | bench/DecodeBench.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698