blob: 4448badd7bf810994c3ec5e2468031e9b5560163 [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001
2/*
3 * Copyright 2011 Google Inc.
4 *
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
7 */
reed@google.comd34658a2011-04-11 13:12:51 +00008#include "SkBenchmark.h"
9#include "SkBitmap.h"
10#include "SkCanvas.h"
11#include "SkColorPriv.h"
12#include "SkPaint.h"
tomhudson@google.com6e8d3352011-06-22 17:16:35 +000013#include "SkRandom.h"
reed@google.comd34658a2011-04-11 13:12:51 +000014#include "SkShader.h"
15#include "SkString.h"
bsalomon@google.com30e6d2c2012-08-13 14:03:31 +000016#include "SkTArray.h"
17
reed@google.comd34658a2011-04-11 13:12:51 +000018
19enum Flags {
20 kStroke_Flag = 1 << 0,
21 kBig_Flag = 1 << 1
22};
23
24#define FLAGS00 Flags(0)
25#define FLAGS01 Flags(kStroke_Flag)
26#define FLAGS10 Flags(kBig_Flag)
27#define FLAGS11 Flags(kStroke_Flag | kBig_Flag)
28
29class PathBench : public SkBenchmark {
30 SkPaint fPaint;
31 SkString fName;
32 Flags fFlags;
tomhudson@google.comca529d32011-10-28 15:34:49 +000033 enum { N = SkBENCHLOOP(1000) };
reed@google.comd34658a2011-04-11 13:12:51 +000034public:
35 PathBench(void* param, Flags flags) : INHERITED(param), fFlags(flags) {
36 fPaint.setStyle(flags & kStroke_Flag ? SkPaint::kStroke_Style :
37 SkPaint::kFill_Style);
38 fPaint.setStrokeWidth(SkIntToScalar(5));
39 fPaint.setStrokeJoin(SkPaint::kBevel_Join);
40 }
41
42 virtual void appendName(SkString*) = 0;
43 virtual void makePath(SkPath*) = 0;
tomhudson@google.com6e8d3352011-06-22 17:16:35 +000044 virtual int complexity() { return 0; }
reed@google.comd34658a2011-04-11 13:12:51 +000045
46protected:
bsalomon@google.com1647a192012-04-11 15:34:46 +000047 virtual const char* onGetName() SK_OVERRIDE {
reed@google.comd34658a2011-04-11 13:12:51 +000048 fName.printf("path_%s_%s_",
49 fFlags & kStroke_Flag ? "stroke" : "fill",
50 fFlags & kBig_Flag ? "big" : "small");
51 this->appendName(&fName);
52 return fName.c_str();
53 }
54
bsalomon@google.com1647a192012-04-11 15:34:46 +000055 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE {
reed@google.comd34658a2011-04-11 13:12:51 +000056 SkPaint paint(fPaint);
57 this->setupPaint(&paint);
58
59 SkPath path;
60 this->makePath(&path);
61 if (fFlags & kBig_Flag) {
62 SkMatrix m;
63 m.setScale(SkIntToScalar(10), SkIntToScalar(10));
64 path.transform(m);
65 }
66
67 int count = N;
68 if (fFlags & kBig_Flag) {
69 count >>= 2;
70 }
tomhudson@google.com6e8d3352011-06-22 17:16:35 +000071 count >>= (3 * complexity());
reed@google.comd34658a2011-04-11 13:12:51 +000072
73 for (int i = 0; i < count; i++) {
74 canvas->drawPath(path, paint);
75 }
76 }
77
78private:
79 typedef SkBenchmark INHERITED;
80};
81
82class TrianglePathBench : public PathBench {
83public:
84 TrianglePathBench(void* param, Flags flags) : INHERITED(param, flags) {}
85
bsalomon@google.com1647a192012-04-11 15:34:46 +000086 virtual void appendName(SkString* name) SK_OVERRIDE {
reed@google.comd34658a2011-04-11 13:12:51 +000087 name->append("triangle");
88 }
bsalomon@google.com1647a192012-04-11 15:34:46 +000089 virtual void makePath(SkPath* path) SK_OVERRIDE {
reed@google.comd34658a2011-04-11 13:12:51 +000090 static const int gCoord[] = {
91 10, 10, 15, 5, 20, 20
92 };
93 path->moveTo(SkIntToScalar(gCoord[0]), SkIntToScalar(gCoord[1]));
94 path->lineTo(SkIntToScalar(gCoord[2]), SkIntToScalar(gCoord[3]));
95 path->lineTo(SkIntToScalar(gCoord[4]), SkIntToScalar(gCoord[5]));
96 path->close();
97 }
98private:
99 typedef PathBench INHERITED;
100};
101
102class RectPathBench : public PathBench {
103public:
104 RectPathBench(void* param, Flags flags) : INHERITED(param, flags) {}
105
bsalomon@google.com1647a192012-04-11 15:34:46 +0000106 virtual void appendName(SkString* name) SK_OVERRIDE {
reed@google.comd34658a2011-04-11 13:12:51 +0000107 name->append("rect");
108 }
bsalomon@google.com1647a192012-04-11 15:34:46 +0000109 virtual void makePath(SkPath* path) SK_OVERRIDE {
reed@google.comd34658a2011-04-11 13:12:51 +0000110 SkRect r = { 10, 10, 20, 20 };
111 path->addRect(r);
112 }
113private:
114 typedef PathBench INHERITED;
115};
116
117class OvalPathBench : public PathBench {
118public:
119 OvalPathBench(void* param, Flags flags) : INHERITED(param, flags) {}
120
bsalomon@google.com1647a192012-04-11 15:34:46 +0000121 virtual void appendName(SkString* name) SK_OVERRIDE {
reed@google.comd34658a2011-04-11 13:12:51 +0000122 name->append("oval");
123 }
bsalomon@google.com1647a192012-04-11 15:34:46 +0000124 virtual void makePath(SkPath* path) SK_OVERRIDE {
reed@google.comd34658a2011-04-11 13:12:51 +0000125 SkRect r = { 10, 10, 20, 20 };
126 path->addOval(r);
127 }
128private:
129 typedef PathBench INHERITED;
130};
131
bsalomon@google.com1647a192012-04-11 15:34:46 +0000132class CirclePathBench: public PathBench {
133public:
134 CirclePathBench(void* param, Flags flags) : INHERITED(param, flags) {}
135
136 virtual void appendName(SkString* name) SK_OVERRIDE {
137 name->append("circle");
138 }
139 virtual void makePath(SkPath* path) SK_OVERRIDE {
140 path->addCircle(SkIntToScalar(20), SkIntToScalar(20),
141 SkIntToScalar(10));
142 }
143private:
144 typedef PathBench INHERITED;
145};
146
reed@google.comd34658a2011-04-11 13:12:51 +0000147class SawToothPathBench : public PathBench {
148public:
149 SawToothPathBench(void* param, Flags flags) : INHERITED(param, flags) {}
150
bsalomon@google.com1647a192012-04-11 15:34:46 +0000151 virtual void appendName(SkString* name) SK_OVERRIDE {
reed@google.comd34658a2011-04-11 13:12:51 +0000152 name->append("sawtooth");
153 }
154 virtual void makePath(SkPath* path) {
155 SkScalar x = SkIntToScalar(20);
156 SkScalar y = SkIntToScalar(20);
157 const SkScalar x0 = x;
158 const SkScalar dx = SK_Scalar1 * 5;
159 const SkScalar dy = SK_Scalar1 * 10;
160
161 path->moveTo(x, y);
162 for (int i = 0; i < 32; i++) {
163 x += dx;
164 path->lineTo(x, y - dy);
165 x += dx;
166 path->lineTo(x, y + dy);
167 }
168 path->lineTo(x, y + 2 * dy);
169 path->lineTo(x0, y + 2 * dy);
170 path->close();
171 }
bsalomon@google.com1647a192012-04-11 15:34:46 +0000172 virtual int complexity() SK_OVERRIDE { return 1; }
reed@google.comd34658a2011-04-11 13:12:51 +0000173private:
174 typedef PathBench INHERITED;
175};
176
tomhudson@google.com6e8d3352011-06-22 17:16:35 +0000177class LongCurvedPathBench : public PathBench {
178public:
179 LongCurvedPathBench(void * param, Flags flags)
180 : INHERITED(param, flags) {
181 }
182
bsalomon@google.com1647a192012-04-11 15:34:46 +0000183 virtual void appendName(SkString* name) SK_OVERRIDE {
tomhudson@google.com6e8d3352011-06-22 17:16:35 +0000184 name->append("long_curved");
185 }
bsalomon@google.com1647a192012-04-11 15:34:46 +0000186 virtual void makePath(SkPath* path) SK_OVERRIDE {
tomhudson@google.com6e8d3352011-06-22 17:16:35 +0000187 SkRandom rand (12);
188 int i;
189 for (i = 0; i < 100; i++) {
190 path->quadTo(SkScalarMul(rand.nextUScalar1(), SkIntToScalar(640)),
191 SkScalarMul(rand.nextUScalar1(), SkIntToScalar(480)),
192 SkScalarMul(rand.nextUScalar1(), SkIntToScalar(640)),
193 SkScalarMul(rand.nextUScalar1(), SkIntToScalar(480)));
194 }
195 path->close();
196 }
bsalomon@google.com1647a192012-04-11 15:34:46 +0000197 virtual int complexity() SK_OVERRIDE { return 2; }
tomhudson@google.com6e8d3352011-06-22 17:16:35 +0000198private:
199 typedef PathBench INHERITED;
200};
201
senorblanco@chromium.orge50f7362012-01-12 19:10:35 +0000202class LongLinePathBench : public PathBench {
203public:
204 LongLinePathBench(void * param, Flags flags)
205 : INHERITED(param, flags) {
206 }
207
bsalomon@google.com1647a192012-04-11 15:34:46 +0000208 virtual void appendName(SkString* name) SK_OVERRIDE {
senorblanco@chromium.orge50f7362012-01-12 19:10:35 +0000209 name->append("long_line");
210 }
bsalomon@google.com1647a192012-04-11 15:34:46 +0000211 virtual void makePath(SkPath* path) SK_OVERRIDE {
senorblanco@chromium.orge50f7362012-01-12 19:10:35 +0000212 SkRandom rand;
213 path->moveTo(rand.nextUScalar1() * 640, rand.nextUScalar1() * 480);
214 for (size_t i = 1; i < 100; i++) {
215 path->lineTo(rand.nextUScalar1() * 640, rand.nextUScalar1() * 480);
216 }
217 }
bsalomon@google.com1647a192012-04-11 15:34:46 +0000218 virtual int complexity() SK_OVERRIDE { return 2; }
senorblanco@chromium.orge50f7362012-01-12 19:10:35 +0000219private:
220 typedef PathBench INHERITED;
221};
tomhudson@google.com6e8d3352011-06-22 17:16:35 +0000222
bsalomon@google.com30e6d2c2012-08-13 14:03:31 +0000223class RandomPathBench : public SkBenchmark {
224public:
225 RandomPathBench(void* param) : INHERITED(param) {
226 }
227
228protected:
229 void createData(int minVerbs,
230 int maxVerbs,
bsalomon@google.com30e6d2c2012-08-13 14:03:31 +0000231 bool allowMoves = true,
232 SkRect* bounds = NULL) {
233 SkRect tempBounds;
234 if (NULL == bounds) {
235 tempBounds.setXYWH(0, 0, SK_Scalar1, SK_Scalar1);
236 bounds = &tempBounds;
237 }
bsalomon@google.com6d552ee2012-08-14 15:10:09 +0000238 fVerbCnts.reset(kNumVerbCnts);
239 for (int i = 0; i < kNumVerbCnts; ++i) {
240 fVerbCnts[i] = fRandom.nextRangeU(minVerbs, maxVerbs + 1);
241 }
242 fVerbs.reset(kNumVerbs);
243 for (int i = 0; i < kNumVerbs; ++i) {
244 do {
245 fVerbs[i] = static_cast<SkPath::Verb>(fRandom.nextULessThan(SkPath::kDone_Verb));
246 } while (!allowMoves && SkPath::kMove_Verb == fVerbs[i]);
247 }
248 fPoints.reset(kNumPoints);
249 for (int i = 0; i < kNumPoints; ++i) {
250 fPoints[i].set(fRandom.nextRangeScalar(bounds->fLeft, bounds->fRight),
251 fRandom.nextRangeScalar(bounds->fTop, bounds->fBottom));
bsalomon@google.com30e6d2c2012-08-13 14:03:31 +0000252 }
253 this->restartMakingPaths();
254 }
255
256 void restartMakingPaths() {
257 fCurrPath = 0;
258 fCurrVerb = 0;
259 fCurrPoint = 0;
260 }
261
262 void makePath(SkPath* path) {
bsalomon@google.com6d552ee2012-08-14 15:10:09 +0000263 int vCount = fVerbCnts[(fCurrPath++) & (kNumVerbCnts - 1)];
bsalomon@google.com30e6d2c2012-08-13 14:03:31 +0000264 for (int v = 0; v < vCount; ++v) {
bsalomon@google.com6d552ee2012-08-14 15:10:09 +0000265 int verb = fVerbs[(fCurrVerb++) & (kNumVerbs - 1)];
266 switch (verb) {
bsalomon@google.com30e6d2c2012-08-13 14:03:31 +0000267 case SkPath::kMove_Verb:
bsalomon@google.com6d552ee2012-08-14 15:10:09 +0000268 path->moveTo(fPoints[(fCurrPoint++) & (kNumPoints - 1)]);
bsalomon@google.com30e6d2c2012-08-13 14:03:31 +0000269 break;
270 case SkPath::kLine_Verb:
bsalomon@google.com6d552ee2012-08-14 15:10:09 +0000271 path->lineTo(fPoints[(fCurrPoint++) & (kNumPoints - 1)]);
bsalomon@google.com30e6d2c2012-08-13 14:03:31 +0000272 break;
273 case SkPath::kQuad_Verb:
bsalomon@google.com6d552ee2012-08-14 15:10:09 +0000274 path->quadTo(fPoints[(fCurrPoint++) & (kNumPoints - 1)],
275 fPoints[(fCurrPoint++) & (kNumPoints - 1)]);
bsalomon@google.com30e6d2c2012-08-13 14:03:31 +0000276 break;
277 case SkPath::kCubic_Verb:
bsalomon@google.com6d552ee2012-08-14 15:10:09 +0000278 path->cubicTo(fPoints[(fCurrPoint++) & (kNumPoints - 1)],
279 fPoints[(fCurrPoint++) & (kNumPoints - 1)],
280 fPoints[(fCurrPoint++) & (kNumPoints - 1)]);
bsalomon@google.com30e6d2c2012-08-13 14:03:31 +0000281 break;
282 case SkPath::kClose_Verb:
283 path->close();
284 break;
285 default:
286 SkDEBUGFAIL("Unexpected path verb");
287 break;
288 }
289 }
290 }
291
292 void finishedMakingPaths() {
bsalomon@google.com6d552ee2012-08-14 15:10:09 +0000293 fVerbCnts.reset(0);
294 fVerbs.reset(0);
295 fPoints.reset(0);
bsalomon@google.com30e6d2c2012-08-13 14:03:31 +0000296 }
297
298private:
bsalomon@google.com6d552ee2012-08-14 15:10:09 +0000299 enum {
300 // these should all be pow 2
301 kNumVerbCnts = 32,
302 kNumVerbs = 32,
303 kNumPoints = 32,
304 };
305 SkAutoTArray<int> fVerbCnts;
306 SkAutoTArray<SkPath::Verb> fVerbs;
307 SkAutoTArray<SkPoint> fPoints;
308 int fCurrPath;
309 int fCurrVerb;
310 int fCurrPoint;
311 SkRandom fRandom;
bsalomon@google.com30e6d2c2012-08-13 14:03:31 +0000312 typedef SkBenchmark INHERITED;
313};
314
315class PathCreateBench : public RandomPathBench {
316public:
317 PathCreateBench(void* param) : INHERITED(param) {
318 }
319
320protected:
321 enum { N = SkBENCHLOOP(5000) };
322
323 virtual const char* onGetName() SK_OVERRIDE {
324 return "path_create";
325 }
326
327 virtual void onPreDraw() SK_OVERRIDE {
bsalomon@google.com6d552ee2012-08-14 15:10:09 +0000328 this->createData(10, 100);
bsalomon@google.com30e6d2c2012-08-13 14:03:31 +0000329 SkASSERT(0 == fPaths.count());
330 fPaths.resize_back(N);
331 }
332
333 virtual void onDraw(SkCanvas*) SK_OVERRIDE {
334 for (int i = 0; i < N; ++i) {
335 this->makePath(&fPaths[i]);
336 }
337 this->restartMakingPaths();
338 }
339
340 virtual void onPostDraw() SK_OVERRIDE {
341 this->finishedMakingPaths();
342 fPaths.reset();
343 }
344
345private:
346 SkTArray<SkPath> fPaths;
347
348 typedef RandomPathBench INHERITED;
349};
350
351class PathCopyBench : public RandomPathBench {
352public:
353 PathCopyBench(void* param) : INHERITED(param) {
354 }
355
356protected:
bsalomon@google.com62e41902012-08-13 16:59:21 +0000357 enum { N = SkBENCHLOOP(30000) };
bsalomon@google.com30e6d2c2012-08-13 14:03:31 +0000358
359 virtual const char* onGetName() SK_OVERRIDE {
360 return "path_copy";
361 }
362 virtual void onPreDraw() SK_OVERRIDE {
bsalomon@google.com6d552ee2012-08-14 15:10:09 +0000363 this->createData(10, 100);
bsalomon@google.com30e6d2c2012-08-13 14:03:31 +0000364 SkASSERT(0 == fPaths.count());
365 fPaths.resize_back(N);
366 fCopies.resize_back(N);
367 for (int i = 0; i < N; ++i) {
368 this->makePath(&fPaths[i]);
369 }
370 this->finishedMakingPaths();
371 }
372 virtual void onDraw(SkCanvas*) SK_OVERRIDE {
373 for (int i = 0; i < N; ++i) {
374 fCopies[i] = fPaths[i];
375 }
376 }
377 virtual void onPostDraw() SK_OVERRIDE {
378 fPaths.reset();
379 fCopies.reset();
380 }
381
382private:
383 SkTArray<SkPath> fPaths;
384 SkTArray<SkPath> fCopies;
385
386 typedef RandomPathBench INHERITED;
387};
388
389class PathTransformBench : public RandomPathBench {
390public:
391 PathTransformBench(bool inPlace, void* param)
392 : INHERITED(param)
393 , fInPlace(inPlace) {
394 }
395
396protected:
397 enum { N = SkBENCHLOOP(30000) };
398
399 virtual const char* onGetName() SK_OVERRIDE {
400 return fInPlace ? "path_transform_in_place" : "path_transform_copy";
401 }
402
403 virtual void onPreDraw() SK_OVERRIDE {
404 fMatrix.setScale(5 * SK_Scalar1, 6 * SK_Scalar1);
bsalomon@google.com6d552ee2012-08-14 15:10:09 +0000405 this->createData(10, 100);
bsalomon@google.com30e6d2c2012-08-13 14:03:31 +0000406 SkASSERT(0 == fPaths.count());
407 SkASSERT(0 == fTransformed.count());
408 fPaths.resize_back(N);
409 for (int i = 0; i < N; ++i) {
410 this->makePath(&fPaths[i]);
411 }
412 if (!fInPlace) {
413 fTransformed.resize_back(N);
414 }
415 }
416
417 virtual void onDraw(SkCanvas*) SK_OVERRIDE {
418 if (fInPlace) {
419 for (int i = 0; i < N; ++i) {
420 fPaths[i].transform(fMatrix);
421 }
422 } else {
423 for (int i = 0; i < N; ++i) {
424 fPaths[i].transform(fMatrix, &fTransformed[i]);
425 }
426 }
427 }
428
429 virtual void onPostDraw() SK_OVERRIDE {
430 fPaths.reset();
431 fTransformed.reset();
432 }
433
434private:
435 SkTArray<SkPath> fPaths;
436 SkTArray<SkPath> fTransformed;
437 SkMatrix fMatrix;
438 bool fInPlace;
439 typedef RandomPathBench INHERITED;
440};
441
442class PathEqualityBench : public RandomPathBench {
443public:
444 PathEqualityBench(void* param)
445 : INHERITED(param) {
446 }
447
448protected:
449 enum { N = SkBENCHLOOP(40000) };
450
451 virtual const char* onGetName() SK_OVERRIDE {
452 return "path_equality_50%";
453 }
454
455 virtual void onPreDraw() SK_OVERRIDE {
456 fParity = 0;
bsalomon@google.com6d552ee2012-08-14 15:10:09 +0000457 this->createData(10, 100);
bsalomon@google.com30e6d2c2012-08-13 14:03:31 +0000458 SkASSERT(0 == fPaths.count());
459 SkASSERT(0 == fCopies.count());
460 fPaths.resize_back(N);
461 fCopies.resize_back(N);
462 for (int i = 0; i < N; ++i) {
463 this->makePath(&fPaths[i]);
464 fCopies[i] = fPaths[i];
465 }
466 this->finishedMakingPaths();
467 }
468
469 virtual void onDraw(SkCanvas*) SK_OVERRIDE {
470 for (int i = 0; i < N; ++i) {
471 fParity ^= (fPaths[i] == fCopies[i & ~0x1]);
472 }
473 }
474
475 virtual void onPostDraw() SK_OVERRIDE {
476 fPaths.reset();
477 }
478
479private:
480 bool fParity; // attempt to keep compiler from optimizing out the ==
481 SkTArray<SkPath> fPaths;
482 SkTArray<SkPath> fCopies;
483 typedef RandomPathBench INHERITED;
484};
485
486class SkBench_AddPathTest : public RandomPathBench {
487public:
488 enum AddType {
489 kAdd_AddType,
490 kAddTrans_AddType,
491 kAddMatrix_AddType,
492 kPathTo_AddType,
493 kReverseAdd_AddType,
494 kReversePathTo_AddType,
495 };
496
497 SkBench_AddPathTest(AddType type, void* param)
498 : INHERITED(param)
499 , fType(type) {
500 fMatrix.setRotate(60 * SK_Scalar1);
501 }
502
503protected:
504 enum { N = SkBENCHLOOP(15000) };
505
506 virtual const char* onGetName() SK_OVERRIDE {
507 switch (fType) {
508 case kAdd_AddType:
509 return "path_add_path";
510 case kAddTrans_AddType:
511 return "path_add_path_trans";
512 case kAddMatrix_AddType:
513 return "path_add_path_matrix";
514 case kPathTo_AddType:
515 return "path_path_to";
516 case kReverseAdd_AddType:
517 return "path_reverse_add_path";
518 case kReversePathTo_AddType:
519 return "path_reverse_path_to";
520 default:
521 SkDEBUGFAIL("Bad add type");
522 return "";
523 }
524 }
525
526 virtual void onPreDraw() SK_OVERRIDE {
527 // pathTo and reversePathTo assume a single contour path.
528 bool allowMoves = kPathTo_AddType != fType &&
529 kReversePathTo_AddType != fType;
bsalomon@google.com6d552ee2012-08-14 15:10:09 +0000530 this->createData(10, 100, allowMoves);
bsalomon@google.com30e6d2c2012-08-13 14:03:31 +0000531 SkASSERT(0 == fPaths0.count());
532 SkASSERT(0 == fPaths1.count());
533 fPaths0.resize_back(N);
534 fPaths1.resize_back(N);
535 for (int i = 0; i < N; ++i) {
536 this->makePath(&fPaths0[i]);
537 this->makePath(&fPaths1[i]);
538 }
539 this->finishedMakingPaths();
540 }
541
542 virtual void onDraw(SkCanvas*) SK_OVERRIDE {
543 switch (fType) {
544 case kAdd_AddType:
545 for (int i = 0; i < N; ++i) {
546 SkPath result = fPaths0[i];
547 result.addPath(fPaths1[i]);
548 }
549 break;
550 case kAddTrans_AddType:
551 for (int i = 0; i < N; ++i) {
552 SkPath result = fPaths0[i];
553 result.addPath(fPaths1[i], 2 * SK_Scalar1, 5 * SK_Scalar1);
554 }
555 break;
556 case kAddMatrix_AddType:
557 for (int i = 0; i < N; ++i) {
558 SkPath result = fPaths0[i];
559 result.addPath(fPaths1[i], fMatrix);
560 }
561 break;
562 case kPathTo_AddType:
563 for (int i = 0; i < N; ++i) {
564 SkPath result = fPaths0[i];
565 result.pathTo(fPaths1[i]);
566 }
567 break;
568 case kReverseAdd_AddType:
569 for (int i = 0; i < N; ++i) {
570 SkPath result = fPaths0[i];
571 result.reverseAddPath(fPaths1[i]);
572 }
573 break;
574 case kReversePathTo_AddType:
575 for (int i = 0; i < N; ++i) {
576 SkPath result = fPaths0[i];
577 result.reversePathTo(fPaths1[i]);
578 }
579 break;
580 }
581 }
582
583 virtual void onPostDraw() SK_OVERRIDE {
584 fPaths0.reset();
585 fPaths1.reset();
586 }
587
588private:
589 AddType fType; // or reverseAddPath
590 SkTArray<SkPath> fPaths0;
591 SkTArray<SkPath> fPaths1;
592 SkMatrix fMatrix;
593 typedef RandomPathBench INHERITED;
594};
tomhudson@google.com6e8d3352011-06-22 17:16:35 +0000595
reed@google.comd34658a2011-04-11 13:12:51 +0000596static SkBenchmark* FactT00(void* p) { return new TrianglePathBench(p, FLAGS00); }
597static SkBenchmark* FactT01(void* p) { return new TrianglePathBench(p, FLAGS01); }
598static SkBenchmark* FactT10(void* p) { return new TrianglePathBench(p, FLAGS10); }
599static SkBenchmark* FactT11(void* p) { return new TrianglePathBench(p, FLAGS11); }
600
601static SkBenchmark* FactR00(void* p) { return new RectPathBench(p, FLAGS00); }
602static SkBenchmark* FactR01(void* p) { return new RectPathBench(p, FLAGS01); }
603static SkBenchmark* FactR10(void* p) { return new RectPathBench(p, FLAGS10); }
604static SkBenchmark* FactR11(void* p) { return new RectPathBench(p, FLAGS11); }
605
606static SkBenchmark* FactO00(void* p) { return new OvalPathBench(p, FLAGS00); }
607static SkBenchmark* FactO01(void* p) { return new OvalPathBench(p, FLAGS01); }
608static SkBenchmark* FactO10(void* p) { return new OvalPathBench(p, FLAGS10); }
609static SkBenchmark* FactO11(void* p) { return new OvalPathBench(p, FLAGS11); }
610
bsalomon@google.com1647a192012-04-11 15:34:46 +0000611static SkBenchmark* FactC00(void* p) { return new CirclePathBench(p, FLAGS00); }
612static SkBenchmark* FactC01(void* p) { return new CirclePathBench(p, FLAGS01); }
613static SkBenchmark* FactC10(void* p) { return new CirclePathBench(p, FLAGS10); }
614static SkBenchmark* FactC11(void* p) { return new CirclePathBench(p, FLAGS11); }
615
reed@google.comd34658a2011-04-11 13:12:51 +0000616static SkBenchmark* FactS00(void* p) { return new SawToothPathBench(p, FLAGS00); }
617static SkBenchmark* FactS01(void* p) { return new SawToothPathBench(p, FLAGS01); }
618
tomhudson@google.com6e8d3352011-06-22 17:16:35 +0000619static SkBenchmark* FactLC00(void* p) {
620 return new LongCurvedPathBench(p, FLAGS00);
621}
622static SkBenchmark* FactLC01(void* p) {
623 return new LongCurvedPathBench(p, FLAGS01);
624}
625
senorblanco@chromium.orge50f7362012-01-12 19:10:35 +0000626static SkBenchmark* FactLL00(void* p) {
627 return new LongLinePathBench(p, FLAGS00);
628}
629
630static SkBenchmark* FactLL01(void* p) {
631 return new LongLinePathBench(p, FLAGS01);
632}
633
reed@google.comd34658a2011-04-11 13:12:51 +0000634static BenchRegistry gRegT00(FactT00);
635static BenchRegistry gRegT01(FactT01);
636static BenchRegistry gRegT10(FactT10);
637static BenchRegistry gRegT11(FactT11);
638
639static BenchRegistry gRegR00(FactR00);
640static BenchRegistry gRegR01(FactR01);
641static BenchRegistry gRegR10(FactR10);
642static BenchRegistry gRegR11(FactR11);
643
644static BenchRegistry gRegO00(FactO00);
645static BenchRegistry gRegO01(FactO01);
646static BenchRegistry gRegO10(FactO10);
647static BenchRegistry gRegO11(FactO11);
648
bsalomon@google.com1647a192012-04-11 15:34:46 +0000649static BenchRegistry gRegC00(FactC00);
650static BenchRegistry gRegC01(FactC01);
651static BenchRegistry gRegC10(FactC10);
652static BenchRegistry gRegC11(FactC11);
653
reed@google.comd34658a2011-04-11 13:12:51 +0000654static BenchRegistry gRegS00(FactS00);
655static BenchRegistry gRegS01(FactS01);
656
tomhudson@google.com6e8d3352011-06-22 17:16:35 +0000657static BenchRegistry gRegLC00(FactLC00);
658static BenchRegistry gRegLC01(FactLC01);
659
senorblanco@chromium.orge50f7362012-01-12 19:10:35 +0000660static BenchRegistry gRegLL00(FactLL00);
661static BenchRegistry gRegLL01(FactLL01);
662
bsalomon@google.com30e6d2c2012-08-13 14:03:31 +0000663static SkBenchmark* FactCreate(void* p) { return new PathCreateBench(p); }
664static BenchRegistry gRegCreate(FactCreate);
665
666static SkBenchmark* FactCopy(void* p) { return new PathCopyBench(p); }
667static BenchRegistry gRegCopy(FactCopy);
668
669static SkBenchmark* FactPathTransformInPlace(void* p) { return new PathTransformBench(true, p); }
670static BenchRegistry gRegPathTransformInPlace(FactPathTransformInPlace);
671
672static SkBenchmark* FactPathTransformCopy(void* p) { return new PathTransformBench(false, p); }
673static BenchRegistry gRegPathTransformCopy(FactPathTransformCopy);
674
675static SkBenchmark* FactEquality(void* p) { return new PathEqualityBench(p); }
676static BenchRegistry gRegEquality(FactEquality);
677
678static SkBenchmark* FactAdd(void* p) { return new SkBench_AddPathTest(SkBench_AddPathTest::kAdd_AddType, p); }
679static SkBenchmark* FactAddTrans(void* p) { return new SkBench_AddPathTest(SkBench_AddPathTest::kAddTrans_AddType, p); }
680static SkBenchmark* FactAddMatrix(void* p) { return new SkBench_AddPathTest(SkBench_AddPathTest::kAddMatrix_AddType, p); }
681static SkBenchmark* FactPathTo(void* p) { return new SkBench_AddPathTest(SkBench_AddPathTest::kPathTo_AddType, p); }
682static SkBenchmark* FactReverseAdd(void* p) { return new SkBench_AddPathTest(SkBench_AddPathTest::kReverseAdd_AddType, p); }
683static SkBenchmark* FactReverseTo(void* p) { return new SkBench_AddPathTest(SkBench_AddPathTest::kReversePathTo_AddType, p); }
684
685static BenchRegistry gRegAdd(FactAdd);
686static BenchRegistry gRegAddTrans(FactAddTrans);
687static BenchRegistry gRegAddMatrix(FactAddMatrix);
688static BenchRegistry gRegPathTo(FactPathTo);
689static BenchRegistry gRegReverseAdd(FactReverseAdd);
690static BenchRegistry gRegReverseTo(FactReverseTo);