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

Side by Side Diff: bench/PathBench.cpp

Issue 806653007: Fix up all the easy virtual ... SK_OVERRIDE cases. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: rebase Created 5 years, 11 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
« no previous file with comments | « bench/PatchGridBench.cpp ('k') | bench/PathIterBench.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 "Benchmark.h" 8 #include "Benchmark.h"
9 #include "SkBitmap.h" 9 #include "SkBitmap.h"
10 #include "SkCanvas.h" 10 #include "SkCanvas.h"
(...skipping 24 matching lines...) Expand all
35 SkPaint::kFill_Style); 35 SkPaint::kFill_Style);
36 fPaint.setStrokeWidth(SkIntToScalar(5)); 36 fPaint.setStrokeWidth(SkIntToScalar(5));
37 fPaint.setStrokeJoin(SkPaint::kBevel_Join); 37 fPaint.setStrokeJoin(SkPaint::kBevel_Join);
38 } 38 }
39 39
40 virtual void appendName(SkString*) = 0; 40 virtual void appendName(SkString*) = 0;
41 virtual void makePath(SkPath*) = 0; 41 virtual void makePath(SkPath*) = 0;
42 virtual int complexity() { return 0; } 42 virtual int complexity() { return 0; }
43 43
44 protected: 44 protected:
45 virtual const char* onGetName() SK_OVERRIDE { 45 const char* onGetName() SK_OVERRIDE {
46 fName.printf("path_%s_%s_", 46 fName.printf("path_%s_%s_",
47 fFlags & kStroke_Flag ? "stroke" : "fill", 47 fFlags & kStroke_Flag ? "stroke" : "fill",
48 fFlags & kBig_Flag ? "big" : "small"); 48 fFlags & kBig_Flag ? "big" : "small");
49 this->appendName(&fName); 49 this->appendName(&fName);
50 return fName.c_str(); 50 return fName.c_str();
51 } 51 }
52 52
53 virtual void onDraw(const int loops, SkCanvas* canvas) SK_OVERRIDE { 53 void onDraw(const int loops, SkCanvas* canvas) SK_OVERRIDE {
54 SkPaint paint(fPaint); 54 SkPaint paint(fPaint);
55 this->setupPaint(&paint); 55 this->setupPaint(&paint);
56 56
57 SkPath path; 57 SkPath path;
58 this->makePath(&path); 58 this->makePath(&path);
59 if (fFlags & kBig_Flag) { 59 if (fFlags & kBig_Flag) {
60 SkMatrix m; 60 SkMatrix m;
61 m.setScale(SkIntToScalar(10), SkIntToScalar(10)); 61 m.setScale(SkIntToScalar(10), SkIntToScalar(10));
62 path.transform(m); 62 path.transform(m);
63 } 63 }
(...skipping 10 matching lines...) Expand all
74 } 74 }
75 75
76 private: 76 private:
77 typedef Benchmark INHERITED; 77 typedef Benchmark INHERITED;
78 }; 78 };
79 79
80 class TrianglePathBench : public PathBench { 80 class TrianglePathBench : public PathBench {
81 public: 81 public:
82 TrianglePathBench(Flags flags) : INHERITED(flags) {} 82 TrianglePathBench(Flags flags) : INHERITED(flags) {}
83 83
84 virtual void appendName(SkString* name) SK_OVERRIDE { 84 void appendName(SkString* name) SK_OVERRIDE {
85 name->append("triangle"); 85 name->append("triangle");
86 } 86 }
87 virtual void makePath(SkPath* path) SK_OVERRIDE { 87 void makePath(SkPath* path) SK_OVERRIDE {
88 static const int gCoord[] = { 88 static const int gCoord[] = {
89 10, 10, 15, 5, 20, 20 89 10, 10, 15, 5, 20, 20
90 }; 90 };
91 path->moveTo(SkIntToScalar(gCoord[0]), SkIntToScalar(gCoord[1])); 91 path->moveTo(SkIntToScalar(gCoord[0]), SkIntToScalar(gCoord[1]));
92 path->lineTo(SkIntToScalar(gCoord[2]), SkIntToScalar(gCoord[3])); 92 path->lineTo(SkIntToScalar(gCoord[2]), SkIntToScalar(gCoord[3]));
93 path->lineTo(SkIntToScalar(gCoord[4]), SkIntToScalar(gCoord[5])); 93 path->lineTo(SkIntToScalar(gCoord[4]), SkIntToScalar(gCoord[5]));
94 path->close(); 94 path->close();
95 } 95 }
96 private: 96 private:
97 typedef PathBench INHERITED; 97 typedef PathBench INHERITED;
98 }; 98 };
99 99
100 class RectPathBench : public PathBench { 100 class RectPathBench : public PathBench {
101 public: 101 public:
102 RectPathBench(Flags flags) : INHERITED(flags) {} 102 RectPathBench(Flags flags) : INHERITED(flags) {}
103 103
104 virtual void appendName(SkString* name) SK_OVERRIDE { 104 void appendName(SkString* name) SK_OVERRIDE {
105 name->append("rect"); 105 name->append("rect");
106 } 106 }
107 virtual void makePath(SkPath* path) SK_OVERRIDE { 107 void makePath(SkPath* path) SK_OVERRIDE {
108 SkRect r = { 10, 10, 20, 20 }; 108 SkRect r = { 10, 10, 20, 20 };
109 path->addRect(r); 109 path->addRect(r);
110 } 110 }
111 private: 111 private:
112 typedef PathBench INHERITED; 112 typedef PathBench INHERITED;
113 }; 113 };
114 114
115 class OvalPathBench : public PathBench { 115 class OvalPathBench : public PathBench {
116 public: 116 public:
117 OvalPathBench(Flags flags) : INHERITED(flags) {} 117 OvalPathBench(Flags flags) : INHERITED(flags) {}
118 118
119 virtual void appendName(SkString* name) SK_OVERRIDE { 119 void appendName(SkString* name) SK_OVERRIDE {
120 name->append("oval"); 120 name->append("oval");
121 } 121 }
122 virtual void makePath(SkPath* path) SK_OVERRIDE { 122 void makePath(SkPath* path) SK_OVERRIDE {
123 SkRect r = { 10, 10, 23, 20 }; 123 SkRect r = { 10, 10, 23, 20 };
124 path->addOval(r); 124 path->addOval(r);
125 } 125 }
126 private: 126 private:
127 typedef PathBench INHERITED; 127 typedef PathBench INHERITED;
128 }; 128 };
129 129
130 class CirclePathBench: public PathBench { 130 class CirclePathBench: public PathBench {
131 public: 131 public:
132 CirclePathBench(Flags flags) : INHERITED(flags) {} 132 CirclePathBench(Flags flags) : INHERITED(flags) {}
133 133
134 virtual void appendName(SkString* name) SK_OVERRIDE { 134 void appendName(SkString* name) SK_OVERRIDE {
135 name->append("circle"); 135 name->append("circle");
136 } 136 }
137 virtual void makePath(SkPath* path) SK_OVERRIDE { 137 void makePath(SkPath* path) SK_OVERRIDE {
138 path->addCircle(SkIntToScalar(20), SkIntToScalar(20), 138 path->addCircle(SkIntToScalar(20), SkIntToScalar(20),
139 SkIntToScalar(10)); 139 SkIntToScalar(10));
140 } 140 }
141 private: 141 private:
142 typedef PathBench INHERITED; 142 typedef PathBench INHERITED;
143 }; 143 };
144 144
145 class SawToothPathBench : public PathBench { 145 class SawToothPathBench : public PathBench {
146 public: 146 public:
147 SawToothPathBench(Flags flags) : INHERITED(flags) {} 147 SawToothPathBench(Flags flags) : INHERITED(flags) {}
148 148
149 virtual void appendName(SkString* name) SK_OVERRIDE { 149 void appendName(SkString* name) SK_OVERRIDE {
150 name->append("sawtooth"); 150 name->append("sawtooth");
151 } 151 }
152 virtual void makePath(SkPath* path) { 152 virtual void makePath(SkPath* path) {
153 SkScalar x = SkIntToScalar(20); 153 SkScalar x = SkIntToScalar(20);
154 SkScalar y = SkIntToScalar(20); 154 SkScalar y = SkIntToScalar(20);
155 const SkScalar x0 = x; 155 const SkScalar x0 = x;
156 const SkScalar dx = SK_Scalar1 * 5; 156 const SkScalar dx = SK_Scalar1 * 5;
157 const SkScalar dy = SK_Scalar1 * 10; 157 const SkScalar dy = SK_Scalar1 * 10;
158 158
159 path->moveTo(x, y); 159 path->moveTo(x, y);
160 for (int i = 0; i < 32; i++) { 160 for (int i = 0; i < 32; i++) {
161 x += dx; 161 x += dx;
162 path->lineTo(x, y - dy); 162 path->lineTo(x, y - dy);
163 x += dx; 163 x += dx;
164 path->lineTo(x, y + dy); 164 path->lineTo(x, y + dy);
165 } 165 }
166 path->lineTo(x, y + 2 * dy); 166 path->lineTo(x, y + 2 * dy);
167 path->lineTo(x0, y + 2 * dy); 167 path->lineTo(x0, y + 2 * dy);
168 path->close(); 168 path->close();
169 } 169 }
170 virtual int complexity() SK_OVERRIDE { return 1; } 170 int complexity() SK_OVERRIDE { return 1; }
171 private: 171 private:
172 typedef PathBench INHERITED; 172 typedef PathBench INHERITED;
173 }; 173 };
174 174
175 class LongCurvedPathBench : public PathBench { 175 class LongCurvedPathBench : public PathBench {
176 public: 176 public:
177 LongCurvedPathBench(Flags flags) : INHERITED(flags) {} 177 LongCurvedPathBench(Flags flags) : INHERITED(flags) {}
178 178
179 virtual void appendName(SkString* name) SK_OVERRIDE { 179 void appendName(SkString* name) SK_OVERRIDE {
180 name->append("long_curved"); 180 name->append("long_curved");
181 } 181 }
182 virtual void makePath(SkPath* path) SK_OVERRIDE { 182 void makePath(SkPath* path) SK_OVERRIDE {
183 SkRandom rand (12); 183 SkRandom rand (12);
184 int i; 184 int i;
185 for (i = 0; i < 100; i++) { 185 for (i = 0; i < 100; i++) {
186 path->quadTo(SkScalarMul(rand.nextUScalar1(), SkIntToScalar(640)), 186 path->quadTo(SkScalarMul(rand.nextUScalar1(), SkIntToScalar(640)),
187 SkScalarMul(rand.nextUScalar1(), SkIntToScalar(480)), 187 SkScalarMul(rand.nextUScalar1(), SkIntToScalar(480)),
188 SkScalarMul(rand.nextUScalar1(), SkIntToScalar(640)), 188 SkScalarMul(rand.nextUScalar1(), SkIntToScalar(640)),
189 SkScalarMul(rand.nextUScalar1(), SkIntToScalar(480))); 189 SkScalarMul(rand.nextUScalar1(), SkIntToScalar(480)));
190 } 190 }
191 path->close(); 191 path->close();
192 } 192 }
193 virtual int complexity() SK_OVERRIDE { return 2; } 193 int complexity() SK_OVERRIDE { return 2; }
194 private: 194 private:
195 typedef PathBench INHERITED; 195 typedef PathBench INHERITED;
196 }; 196 };
197 197
198 class LongLinePathBench : public PathBench { 198 class LongLinePathBench : public PathBench {
199 public: 199 public:
200 LongLinePathBench(Flags flags) : INHERITED(flags) {} 200 LongLinePathBench(Flags flags) : INHERITED(flags) {}
201 201
202 virtual void appendName(SkString* name) SK_OVERRIDE { 202 void appendName(SkString* name) SK_OVERRIDE {
203 name->append("long_line"); 203 name->append("long_line");
204 } 204 }
205 virtual void makePath(SkPath* path) SK_OVERRIDE { 205 void makePath(SkPath* path) SK_OVERRIDE {
206 SkRandom rand; 206 SkRandom rand;
207 path->moveTo(rand.nextUScalar1() * 640, rand.nextUScalar1() * 480); 207 path->moveTo(rand.nextUScalar1() * 640, rand.nextUScalar1() * 480);
208 for (size_t i = 1; i < 100; i++) { 208 for (size_t i = 1; i < 100; i++) {
209 path->lineTo(rand.nextUScalar1() * 640, rand.nextUScalar1() * 480); 209 path->lineTo(rand.nextUScalar1() * 640, rand.nextUScalar1() * 480);
210 } 210 }
211 } 211 }
212 virtual int complexity() SK_OVERRIDE { return 2; } 212 int complexity() SK_OVERRIDE { return 2; }
213 private: 213 private:
214 typedef PathBench INHERITED; 214 typedef PathBench INHERITED;
215 }; 215 };
216 216
217 class RandomPathBench : public Benchmark { 217 class RandomPathBench : public Benchmark {
218 public: 218 public:
219 virtual bool isSuitableFor(Backend backend) SK_OVERRIDE { 219 bool isSuitableFor(Backend backend) SK_OVERRIDE {
220 return backend == kNonRendering_Backend; 220 return backend == kNonRendering_Backend;
221 } 221 }
222 222
223 protected: 223 protected:
224 void createData(int minVerbs, 224 void createData(int minVerbs,
225 int maxVerbs, 225 int maxVerbs,
226 bool allowMoves = true, 226 bool allowMoves = true,
227 SkRect* bounds = NULL) { 227 SkRect* bounds = NULL) {
228 SkRect tempBounds; 228 SkRect tempBounds;
229 if (NULL == bounds) { 229 if (NULL == bounds) {
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
314 SkRandom fRandom; 314 SkRandom fRandom;
315 typedef Benchmark INHERITED; 315 typedef Benchmark INHERITED;
316 }; 316 };
317 317
318 class PathCreateBench : public RandomPathBench { 318 class PathCreateBench : public RandomPathBench {
319 public: 319 public:
320 PathCreateBench() { 320 PathCreateBench() {
321 } 321 }
322 322
323 protected: 323 protected:
324 virtual const char* onGetName() SK_OVERRIDE { 324 const char* onGetName() SK_OVERRIDE {
325 return "path_create"; 325 return "path_create";
326 } 326 }
327 327
328 virtual void onPreDraw() SK_OVERRIDE { 328 void onPreDraw() SK_OVERRIDE {
329 this->createData(10, 100); 329 this->createData(10, 100);
330 } 330 }
331 331
332 virtual void onDraw(const int loops, SkCanvas*) SK_OVERRIDE { 332 void onDraw(const int loops, SkCanvas*) SK_OVERRIDE {
333 for (int i = 0; i < loops; ++i) { 333 for (int i = 0; i < loops; ++i) {
334 if (i % 1000 == 0) { 334 if (i % 1000 == 0) {
335 fPath.reset(); // PathRef memory can grow without bound otherwi se. 335 fPath.reset(); // PathRef memory can grow without bound otherwi se.
336 } 336 }
337 this->makePath(&fPath); 337 this->makePath(&fPath);
338 } 338 }
339 this->restartMakingPaths(); 339 this->restartMakingPaths();
340 } 340 }
341 341
342 private: 342 private:
343 SkPath fPath; 343 SkPath fPath;
344 344
345 typedef RandomPathBench INHERITED; 345 typedef RandomPathBench INHERITED;
346 }; 346 };
347 347
348 class PathCopyBench : public RandomPathBench { 348 class PathCopyBench : public RandomPathBench {
349 public: 349 public:
350 PathCopyBench() { 350 PathCopyBench() {
351 } 351 }
352 352
353 protected: 353 protected:
354 virtual const char* onGetName() SK_OVERRIDE { 354 const char* onGetName() SK_OVERRIDE {
355 return "path_copy"; 355 return "path_copy";
356 } 356 }
357 virtual void onPreDraw() SK_OVERRIDE { 357 void onPreDraw() SK_OVERRIDE {
358 this->createData(10, 100); 358 this->createData(10, 100);
359 fPaths.reset(kPathCnt); 359 fPaths.reset(kPathCnt);
360 fCopies.reset(kPathCnt); 360 fCopies.reset(kPathCnt);
361 for (int i = 0; i < kPathCnt; ++i) { 361 for (int i = 0; i < kPathCnt; ++i) {
362 this->makePath(&fPaths[i]); 362 this->makePath(&fPaths[i]);
363 } 363 }
364 this->finishedMakingPaths(); 364 this->finishedMakingPaths();
365 } 365 }
366 virtual void onDraw(const int loops, SkCanvas*) SK_OVERRIDE { 366 void onDraw(const int loops, SkCanvas*) SK_OVERRIDE {
367 for (int i = 0; i < loops; ++i) { 367 for (int i = 0; i < loops; ++i) {
368 int idx = i & (kPathCnt - 1); 368 int idx = i & (kPathCnt - 1);
369 fCopies[idx] = fPaths[idx]; 369 fCopies[idx] = fPaths[idx];
370 } 370 }
371 } 371 }
372 372
373 private: 373 private:
374 enum { 374 enum {
375 // must be a pow 2 375 // must be a pow 2
376 kPathCnt = 1 << 5, 376 kPathCnt = 1 << 5,
377 }; 377 };
378 SkAutoTArray<SkPath> fPaths; 378 SkAutoTArray<SkPath> fPaths;
379 SkAutoTArray<SkPath> fCopies; 379 SkAutoTArray<SkPath> fCopies;
380 380
381 typedef RandomPathBench INHERITED; 381 typedef RandomPathBench INHERITED;
382 }; 382 };
383 383
384 class PathTransformBench : public RandomPathBench { 384 class PathTransformBench : public RandomPathBench {
385 public: 385 public:
386 PathTransformBench(bool inPlace) : fInPlace(inPlace) {} 386 PathTransformBench(bool inPlace) : fInPlace(inPlace) {}
387 387
388 protected: 388 protected:
389 virtual const char* onGetName() SK_OVERRIDE { 389 const char* onGetName() SK_OVERRIDE {
390 return fInPlace ? "path_transform_in_place" : "path_transform_copy"; 390 return fInPlace ? "path_transform_in_place" : "path_transform_copy";
391 } 391 }
392 392
393 virtual void onPreDraw() SK_OVERRIDE { 393 void onPreDraw() SK_OVERRIDE {
394 fMatrix.setScale(5 * SK_Scalar1, 6 * SK_Scalar1); 394 fMatrix.setScale(5 * SK_Scalar1, 6 * SK_Scalar1);
395 this->createData(10, 100); 395 this->createData(10, 100);
396 fPaths.reset(kPathCnt); 396 fPaths.reset(kPathCnt);
397 for (int i = 0; i < kPathCnt; ++i) { 397 for (int i = 0; i < kPathCnt; ++i) {
398 this->makePath(&fPaths[i]); 398 this->makePath(&fPaths[i]);
399 } 399 }
400 this->finishedMakingPaths(); 400 this->finishedMakingPaths();
401 if (!fInPlace) { 401 if (!fInPlace) {
402 fTransformed.reset(kPathCnt); 402 fTransformed.reset(kPathCnt);
403 } 403 }
404 } 404 }
405 405
406 virtual void onDraw(const int loops, SkCanvas*) SK_OVERRIDE { 406 void onDraw(const int loops, SkCanvas*) SK_OVERRIDE {
407 if (fInPlace) { 407 if (fInPlace) {
408 for (int i = 0; i < loops; ++i) { 408 for (int i = 0; i < loops; ++i) {
409 fPaths[i & (kPathCnt - 1)].transform(fMatrix); 409 fPaths[i & (kPathCnt - 1)].transform(fMatrix);
410 } 410 }
411 } else { 411 } else {
412 for (int i = 0; i < loops; ++i) { 412 for (int i = 0; i < loops; ++i) {
413 int idx = i & (kPathCnt - 1); 413 int idx = i & (kPathCnt - 1);
414 fPaths[idx].transform(fMatrix, &fTransformed[idx]); 414 fPaths[idx].transform(fMatrix, &fTransformed[idx]);
415 } 415 }
416 } 416 }
(...skipping 10 matching lines...) Expand all
427 SkMatrix fMatrix; 427 SkMatrix fMatrix;
428 bool fInPlace; 428 bool fInPlace;
429 typedef RandomPathBench INHERITED; 429 typedef RandomPathBench INHERITED;
430 }; 430 };
431 431
432 class PathEqualityBench : public RandomPathBench { 432 class PathEqualityBench : public RandomPathBench {
433 public: 433 public:
434 PathEqualityBench() { } 434 PathEqualityBench() { }
435 435
436 protected: 436 protected:
437 virtual const char* onGetName() SK_OVERRIDE { 437 const char* onGetName() SK_OVERRIDE {
438 return "path_equality_50%"; 438 return "path_equality_50%";
439 } 439 }
440 440
441 virtual void onPreDraw() SK_OVERRIDE { 441 void onPreDraw() SK_OVERRIDE {
442 fParity = 0; 442 fParity = 0;
443 this->createData(10, 100); 443 this->createData(10, 100);
444 fPaths.reset(kPathCnt); 444 fPaths.reset(kPathCnt);
445 fCopies.reset(kPathCnt); 445 fCopies.reset(kPathCnt);
446 for (int i = 0; i < kPathCnt; ++i) { 446 for (int i = 0; i < kPathCnt; ++i) {
447 this->makePath(&fPaths[i]); 447 this->makePath(&fPaths[i]);
448 fCopies[i] = fPaths[i]; 448 fCopies[i] = fPaths[i];
449 } 449 }
450 this->finishedMakingPaths(); 450 this->finishedMakingPaths();
451 } 451 }
452 452
453 virtual void onDraw(const int loops, SkCanvas*) SK_OVERRIDE { 453 void onDraw(const int loops, SkCanvas*) SK_OVERRIDE {
454 for (int i = 0; i < loops; ++i) { 454 for (int i = 0; i < loops; ++i) {
455 int idx = i & (kPathCnt - 1); 455 int idx = i & (kPathCnt - 1);
456 fParity ^= (fPaths[idx] == fCopies[idx & ~0x1]); 456 fParity ^= (fPaths[idx] == fCopies[idx & ~0x1]);
457 } 457 }
458 } 458 }
459 459
460 private: 460 private:
461 bool fParity; // attempt to keep compiler from optimizing out the == 461 bool fParity; // attempt to keep compiler from optimizing out the ==
462 enum { 462 enum {
463 // must be a pow 2 463 // must be a pow 2
(...skipping 12 matching lines...) Expand all
476 kAddMatrix_AddType, 476 kAddMatrix_AddType,
477 kReverseAdd_AddType, 477 kReverseAdd_AddType,
478 kReversePathTo_AddType, 478 kReversePathTo_AddType,
479 }; 479 };
480 480
481 SkBench_AddPathTest(AddType type) : fType(type) { 481 SkBench_AddPathTest(AddType type) : fType(type) {
482 fMatrix.setRotate(60 * SK_Scalar1); 482 fMatrix.setRotate(60 * SK_Scalar1);
483 } 483 }
484 484
485 protected: 485 protected:
486 virtual const char* onGetName() SK_OVERRIDE { 486 const char* onGetName() SK_OVERRIDE {
487 switch (fType) { 487 switch (fType) {
488 case kAdd_AddType: 488 case kAdd_AddType:
489 return "path_add_path"; 489 return "path_add_path";
490 case kAddTrans_AddType: 490 case kAddTrans_AddType:
491 return "path_add_path_trans"; 491 return "path_add_path_trans";
492 case kAddMatrix_AddType: 492 case kAddMatrix_AddType:
493 return "path_add_path_matrix"; 493 return "path_add_path_matrix";
494 case kReverseAdd_AddType: 494 case kReverseAdd_AddType:
495 return "path_reverse_add_path"; 495 return "path_reverse_add_path";
496 case kReversePathTo_AddType: 496 case kReversePathTo_AddType:
497 return "path_reverse_path_to"; 497 return "path_reverse_path_to";
498 default: 498 default:
499 SkDEBUGFAIL("Bad add type"); 499 SkDEBUGFAIL("Bad add type");
500 return ""; 500 return "";
501 } 501 }
502 } 502 }
503 503
504 virtual void onPreDraw() SK_OVERRIDE { 504 void onPreDraw() SK_OVERRIDE {
505 // reversePathTo assumes a single contour path. 505 // reversePathTo assumes a single contour path.
506 bool allowMoves = kReversePathTo_AddType != fType; 506 bool allowMoves = kReversePathTo_AddType != fType;
507 this->createData(10, 100, allowMoves); 507 this->createData(10, 100, allowMoves);
508 fPaths0.reset(kPathCnt); 508 fPaths0.reset(kPathCnt);
509 fPaths1.reset(kPathCnt); 509 fPaths1.reset(kPathCnt);
510 for (int i = 0; i < kPathCnt; ++i) { 510 for (int i = 0; i < kPathCnt; ++i) {
511 this->makePath(&fPaths0[i]); 511 this->makePath(&fPaths0[i]);
512 this->makePath(&fPaths1[i]); 512 this->makePath(&fPaths1[i]);
513 } 513 }
514 this->finishedMakingPaths(); 514 this->finishedMakingPaths();
515 } 515 }
516 516
517 virtual void onDraw(const int loops, SkCanvas*) SK_OVERRIDE { 517 void onDraw(const int loops, SkCanvas*) SK_OVERRIDE {
518 switch (fType) { 518 switch (fType) {
519 case kAdd_AddType: 519 case kAdd_AddType:
520 for (int i = 0; i < loops; ++i) { 520 for (int i = 0; i < loops; ++i) {
521 int idx = i & (kPathCnt - 1); 521 int idx = i & (kPathCnt - 1);
522 SkPath result = fPaths0[idx]; 522 SkPath result = fPaths0[idx];
523 result.addPath(fPaths1[idx]); 523 result.addPath(fPaths1[idx]);
524 } 524 }
525 break; 525 break;
526 case kAddTrans_AddType: 526 case kAddTrans_AddType:
527 for (int i = 0; i < loops; ++i) { 527 for (int i = 0; i < loops; ++i) {
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
571 protected: 571 protected:
572 SkString fName; 572 SkString fName;
573 Flags fFlags; 573 Flags fFlags;
574 574
575 public: 575 public:
576 CirclesBench(Flags flags) : fFlags(flags) { 576 CirclesBench(Flags flags) : fFlags(flags) {
577 fName.printf("circles_%s", fFlags & kStroke_Flag ? "stroke" : "fill"); 577 fName.printf("circles_%s", fFlags & kStroke_Flag ? "stroke" : "fill");
578 } 578 }
579 579
580 protected: 580 protected:
581 virtual const char* onGetName() SK_OVERRIDE { 581 const char* onGetName() SK_OVERRIDE {
582 return fName.c_str(); 582 return fName.c_str();
583 } 583 }
584 584
585 virtual void onDraw(const int loops, SkCanvas* canvas) SK_OVERRIDE { 585 void onDraw(const int loops, SkCanvas* canvas) SK_OVERRIDE {
586 SkPaint paint; 586 SkPaint paint;
587 587
588 paint.setColor(SK_ColorBLACK); 588 paint.setColor(SK_ColorBLACK);
589 paint.setAntiAlias(true); 589 paint.setAntiAlias(true);
590 if (fFlags & kStroke_Flag) { 590 if (fFlags & kStroke_Flag) {
591 paint.setStyle(SkPaint::kStroke_Style); 591 paint.setStyle(SkPaint::kStroke_Style);
592 } 592 }
593 593
594 SkRandom rand; 594 SkRandom rand;
595 595
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
635 public: 635 public:
636 ArbRoundRectBench(bool zeroRad) : fZeroRad(zeroRad) { 636 ArbRoundRectBench(bool zeroRad) : fZeroRad(zeroRad) {
637 if (zeroRad) { 637 if (zeroRad) {
638 fName.printf("zeroradroundrect"); 638 fName.printf("zeroradroundrect");
639 } else { 639 } else {
640 fName.printf("arbroundrect"); 640 fName.printf("arbroundrect");
641 } 641 }
642 } 642 }
643 643
644 protected: 644 protected:
645 virtual const char* onGetName() SK_OVERRIDE { 645 const char* onGetName() SK_OVERRIDE {
646 return fName.c_str(); 646 return fName.c_str();
647 } 647 }
648 648
649 static void add_corner_arc(SkPath* path, const SkRect& rect, 649 static void add_corner_arc(SkPath* path, const SkRect& rect,
650 SkScalar xIn, SkScalar yIn, 650 SkScalar xIn, SkScalar yIn,
651 int startAngle) 651 int startAngle)
652 { 652 {
653 653
654 SkScalar rx = SkMinScalar(rect.width(), xIn); 654 SkScalar rx = SkMinScalar(rect.width(), xIn);
655 SkScalar ry = SkMinScalar(rect.height(), yIn); 655 SkScalar ry = SkMinScalar(rect.height(), yIn);
(...skipping 25 matching lines...) Expand all
681 // we are lazy here and use the same x & y for each corner 681 // we are lazy here and use the same x & y for each corner
682 add_corner_arc(path, r, xCorner, yCorner, 270); 682 add_corner_arc(path, r, xCorner, yCorner, 270);
683 add_corner_arc(path, r, xCorner, yCorner, 0); 683 add_corner_arc(path, r, xCorner, yCorner, 0);
684 add_corner_arc(path, r, xCorner, yCorner, 90); 684 add_corner_arc(path, r, xCorner, yCorner, 90);
685 add_corner_arc(path, r, xCorner, yCorner, 180); 685 add_corner_arc(path, r, xCorner, yCorner, 180);
686 path->close(); 686 path->close();
687 687
688 SkASSERT(path->isConvex()); 688 SkASSERT(path->isConvex());
689 } 689 }
690 690
691 virtual void onDraw(const int loops, SkCanvas* canvas) SK_OVERRIDE { 691 void onDraw(const int loops, SkCanvas* canvas) SK_OVERRIDE {
692 SkRandom rand; 692 SkRandom rand;
693 SkRect r; 693 SkRect r;
694 694
695 for (int i = 0; i < loops; ++i) { 695 for (int i = 0; i < loops; ++i) {
696 SkPaint paint; 696 SkPaint paint;
697 paint.setColor(0xff000000 | rand.nextU()); 697 paint.setColor(0xff000000 | rand.nextU());
698 paint.setAntiAlias(true); 698 paint.setAntiAlias(true);
699 699
700 SkScalar size = rand.nextUScalar1() * 30; 700 SkScalar size = rand.nextUScalar1() * 30;
701 if (size < SK_Scalar1) { 701 if (size < SK_Scalar1) {
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
746 fName.append("round_rect"); 746 fName.append("round_rect");
747 fPath.addRoundRect(kBaseRect, kRRRadii[0], kRRRadii[1]); 747 fPath.addRoundRect(kBaseRect, kRRRadii[0], kRRRadii[1]);
748 break; 748 break;
749 case kOval_Type: 749 case kOval_Type:
750 fName.append("oval"); 750 fName.append("oval");
751 fPath.addOval(kBaseRect); 751 fPath.addOval(kBaseRect);
752 break; 752 break;
753 } 753 }
754 } 754 }
755 755
756 virtual bool isSuitableFor(Backend backend) SK_OVERRIDE { 756 bool isSuitableFor(Backend backend) SK_OVERRIDE {
757 return backend == kNonRendering_Backend; 757 return backend == kNonRendering_Backend;
758 } 758 }
759 759
760 private: 760 private:
761 virtual const char* onGetName() SK_OVERRIDE { 761 const char* onGetName() SK_OVERRIDE {
762 return fName.c_str(); 762 return fName.c_str();
763 } 763 }
764 764
765 virtual void onDraw(const int loops, SkCanvas*) SK_OVERRIDE { 765 void onDraw(const int loops, SkCanvas*) SK_OVERRIDE {
766 for (int i = 0; i < loops; ++i) { 766 for (int i = 0; i < loops; ++i) {
767 const SkRect& rect = fQueryRects[i % kQueryRectCnt]; 767 const SkRect& rect = fQueryRects[i % kQueryRectCnt];
768 fParity = fParity != fPath.conservativelyContainsRect(rect); 768 fParity = fParity != fPath.conservativelyContainsRect(rect);
769 } 769 }
770 } 770 }
771 771
772 virtual void onPreDraw() SK_OVERRIDE { 772 void onPreDraw() SK_OVERRIDE {
773 fQueryRects.setCount(kQueryRectCnt); 773 fQueryRects.setCount(kQueryRectCnt);
774 774
775 SkRandom rand; 775 SkRandom rand;
776 for (int i = 0; i < kQueryRectCnt; ++i) { 776 for (int i = 0; i < kQueryRectCnt; ++i) {
777 SkSize size; 777 SkSize size;
778 SkPoint xy; 778 SkPoint xy;
779 size.fWidth = rand.nextRangeScalar(kQueryMin.fWidth, kQueryMax.fWid th); 779 size.fWidth = rand.nextRangeScalar(kQueryMin.fWidth, kQueryMax.fWid th);
780 size.fHeight = rand.nextRangeScalar(kQueryMin.fHeight, kQueryMax.fHe ight); 780 size.fHeight = rand.nextRangeScalar(kQueryMin.fHeight, kQueryMax.fHe ight);
781 xy.fX = rand.nextRangeScalar(kBounds.fLeft, kBounds.fRight - size.fW idth); 781 xy.fX = rand.nextRangeScalar(kBounds.fLeft, kBounds.fRight - size.fW idth);
782 xy.fY = rand.nextRangeScalar(kBounds.fTop, kBounds.fBottom - size.fH eight); 782 xy.fY = rand.nextRangeScalar(kBounds.fTop, kBounds.fBottom - size.fH eight);
(...skipping 27 matching lines...) Expand all
810 SkConic fRQ; 810 SkConic fRQ;
811 public: 811 public:
812 ConicBench_Chop5() { 812 ConicBench_Chop5() {
813 fRQ.fPts[0].set(0, 0); 813 fRQ.fPts[0].set(0, 0);
814 fRQ.fPts[1].set(100, 0); 814 fRQ.fPts[1].set(100, 0);
815 fRQ.fPts[2].set(100, 100); 815 fRQ.fPts[2].set(100, 100);
816 fRQ.fW = SkScalarCos(SK_ScalarPI/4); 816 fRQ.fW = SkScalarCos(SK_ScalarPI/4);
817 } 817 }
818 818
819 private: 819 private:
820 virtual const char* onGetName() SK_OVERRIDE { 820 const char* onGetName() SK_OVERRIDE {
821 return "ratquad-chop-0.5"; 821 return "ratquad-chop-0.5";
822 } 822 }
823 823
824 virtual void onDraw(const int loops, SkCanvas*) SK_OVERRIDE { 824 void onDraw(const int loops, SkCanvas*) SK_OVERRIDE {
825 SkConic dst[2]; 825 SkConic dst[2];
826 for (int i = 0; i < loops; ++i) { 826 for (int i = 0; i < loops; ++i) {
827 fRQ.chopAt(0.5f, dst); 827 fRQ.chopAt(0.5f, dst);
828 } 828 }
829 } 829 }
830 830
831 typedef Benchmark INHERITED; 831 typedef Benchmark INHERITED;
832 }; 832 };
833 833
834 class ConicBench_ChopHalf : public Benchmark { 834 class ConicBench_ChopHalf : public Benchmark {
835 SkConic fRQ; 835 SkConic fRQ;
836 public: 836 public:
837 ConicBench_ChopHalf() { 837 ConicBench_ChopHalf() {
838 fRQ.fPts[0].set(0, 0); 838 fRQ.fPts[0].set(0, 0);
839 fRQ.fPts[1].set(100, 0); 839 fRQ.fPts[1].set(100, 0);
840 fRQ.fPts[2].set(100, 100); 840 fRQ.fPts[2].set(100, 100);
841 fRQ.fW = SkScalarCos(SK_ScalarPI/4); 841 fRQ.fW = SkScalarCos(SK_ScalarPI/4);
842 } 842 }
843 843
844 private: 844 private:
845 virtual const char* onGetName() SK_OVERRIDE { 845 const char* onGetName() SK_OVERRIDE {
846 return "ratquad-chop-half"; 846 return "ratquad-chop-half";
847 } 847 }
848 848
849 virtual void onDraw(const int loops, SkCanvas*) SK_OVERRIDE { 849 void onDraw(const int loops, SkCanvas*) SK_OVERRIDE {
850 SkConic dst[2]; 850 SkConic dst[2];
851 for (int i = 0; i < loops; ++i) { 851 for (int i = 0; i < loops; ++i) {
852 fRQ.chop(dst); 852 fRQ.chop(dst);
853 } 853 }
854 } 854 }
855 855
856 typedef Benchmark INHERITED; 856 typedef Benchmark INHERITED;
857 }; 857 };
858 858
859 /////////////////////////////////////////////////////////////////////////////// 859 ///////////////////////////////////////////////////////////////////////////////
(...skipping 11 matching lines...) Expand all
871 871
872 class ConicBench : public Benchmark { 872 class ConicBench : public Benchmark {
873 public: 873 public:
874 ConicBench() { 874 ConicBench() {
875 SkRandom rand; 875 SkRandom rand;
876 for (int i = 0; i < CONICS; ++i) { 876 for (int i = 0; i < CONICS; ++i) {
877 rand_conic(&fConics[i], rand); 877 rand_conic(&fConics[i], rand);
878 } 878 }
879 } 879 }
880 880
881 virtual bool isSuitableFor(Backend backend) SK_OVERRIDE { 881 bool isSuitableFor(Backend backend) SK_OVERRIDE {
882 return backend == kNonRendering_Backend; 882 return backend == kNonRendering_Backend;
883 } 883 }
884 884
885 protected: 885 protected:
886 enum { 886 enum {
887 CONICS = 100 887 CONICS = 100
888 }; 888 };
889 SkConic fConics[CONICS]; 889 SkConic fConics[CONICS];
890 890
891 private: 891 private:
892 typedef Benchmark INHERITED; 892 typedef Benchmark INHERITED;
893 }; 893 };
894 894
895 class ConicBench_ComputeError : public ConicBench { 895 class ConicBench_ComputeError : public ConicBench {
896 public: 896 public:
897 ConicBench_ComputeError() {} 897 ConicBench_ComputeError() {}
898 898
899 protected: 899 protected:
900 virtual const char* onGetName() SK_OVERRIDE { 900 const char* onGetName() SK_OVERRIDE {
901 return "conic-compute-error"; 901 return "conic-compute-error";
902 } 902 }
903 903
904 virtual void onDraw(const int loops, SkCanvas*) SK_OVERRIDE { 904 void onDraw(const int loops, SkCanvas*) SK_OVERRIDE {
905 SkVector err; 905 SkVector err;
906 for (int i = 0; i < loops; ++i) { 906 for (int i = 0; i < loops; ++i) {
907 for (int j = 0; j < CONICS; ++j) { 907 for (int j = 0; j < CONICS; ++j) {
908 fConics[j].computeAsQuadError(&err); 908 fConics[j].computeAsQuadError(&err);
909 } 909 }
910 } 910 }
911 } 911 }
912 912
913 private: 913 private:
914 typedef ConicBench INHERITED; 914 typedef ConicBench INHERITED;
915 }; 915 };
916 916
917 class ConicBench_asQuadTol : public ConicBench { 917 class ConicBench_asQuadTol : public ConicBench {
918 public: 918 public:
919 ConicBench_asQuadTol() {} 919 ConicBench_asQuadTol() {}
920 920
921 protected: 921 protected:
922 virtual const char* onGetName() SK_OVERRIDE { 922 const char* onGetName() SK_OVERRIDE {
923 return "conic-asQuadTol"; 923 return "conic-asQuadTol";
924 } 924 }
925 925
926 virtual void onDraw(const int loops, SkCanvas*) SK_OVERRIDE { 926 void onDraw(const int loops, SkCanvas*) SK_OVERRIDE {
927 for (int i = 0; i < loops; ++i) { 927 for (int i = 0; i < loops; ++i) {
928 for (int j = 0; j < CONICS; ++j) { 928 for (int j = 0; j < CONICS; ++j) {
929 fConics[j].asQuadTol(SK_ScalarHalf); 929 fConics[j].asQuadTol(SK_ScalarHalf);
930 } 930 }
931 } 931 }
932 } 932 }
933 933
934 private: 934 private:
935 typedef ConicBench INHERITED; 935 typedef ConicBench INHERITED;
936 }; 936 };
937 937
938 class ConicBench_quadPow2 : public ConicBench { 938 class ConicBench_quadPow2 : public ConicBench {
939 public: 939 public:
940 ConicBench_quadPow2() {} 940 ConicBench_quadPow2() {}
941 941
942 protected: 942 protected:
943 virtual const char* onGetName() SK_OVERRIDE { 943 const char* onGetName() SK_OVERRIDE {
944 return "conic-quadPow2"; 944 return "conic-quadPow2";
945 } 945 }
946 946
947 virtual void onDraw(const int loops, SkCanvas*) SK_OVERRIDE { 947 void onDraw(const int loops, SkCanvas*) SK_OVERRIDE {
948 for (int i = 0; i < loops; ++i) { 948 for (int i = 0; i < loops; ++i) {
949 for (int j = 0; j < CONICS; ++j) { 949 for (int j = 0; j < CONICS; ++j) {
950 fConics[j].computeQuadPOW2(SK_ScalarHalf); 950 fConics[j].computeQuadPOW2(SK_ScalarHalf);
951 } 951 }
952 } 952 }
953 } 953 }
954 954
955 private: 955 private:
956 typedef ConicBench INHERITED; 956 typedef ConicBench INHERITED;
957 }; 957 };
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
1013 DEF_BENCH( return new ConservativelyContainsBench(ConservativelyContainsBench::k Oval_Type); ) 1013 DEF_BENCH( return new ConservativelyContainsBench(ConservativelyContainsBench::k Oval_Type); )
1014 1014
1015 // These seem to be optimized away, which is troublesome for timing. 1015 // These seem to be optimized away, which is troublesome for timing.
1016 /* 1016 /*
1017 DEF_BENCH( return new ConicBench_Chop5() ) 1017 DEF_BENCH( return new ConicBench_Chop5() )
1018 DEF_BENCH( return new ConicBench_ChopHalf() ) 1018 DEF_BENCH( return new ConicBench_ChopHalf() )
1019 DEF_BENCH( return new ConicBench_ComputeError() ) 1019 DEF_BENCH( return new ConicBench_ComputeError() )
1020 DEF_BENCH( return new ConicBench_asQuadTol() ) 1020 DEF_BENCH( return new ConicBench_asQuadTol() )
1021 DEF_BENCH( return new ConicBench_quadPow2() ) 1021 DEF_BENCH( return new ConicBench_quadPow2() )
1022 */ 1022 */
OLDNEW
« no previous file with comments | « bench/PatchGridBench.cpp ('k') | bench/PathIterBench.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698