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

Side by Side Diff: bench/PathBench.cpp

Issue 1037793002: C++11 override should now be supported by all of {bots,Chrome,Android,Mozilla} (Closed) Base URL: https://skia.googlesource.com/skia@master
Patch Set: git cl web Created 5 years, 9 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 const char* onGetName() SK_OVERRIDE { 45 const char* onGetName() 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 void onDraw(const int loops, SkCanvas* canvas) SK_OVERRIDE { 53 void onDraw(const int loops, SkCanvas* canvas) 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 void appendName(SkString* name) SK_OVERRIDE { 84 void appendName(SkString* name) override {
85 name->append("triangle"); 85 name->append("triangle");
86 } 86 }
87 void makePath(SkPath* path) SK_OVERRIDE { 87 void makePath(SkPath* path) 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 void appendName(SkString* name) SK_OVERRIDE { 104 void appendName(SkString* name) override {
105 name->append("rect"); 105 name->append("rect");
106 } 106 }
107 void makePath(SkPath* path) SK_OVERRIDE { 107 void makePath(SkPath* path) 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 void appendName(SkString* name) SK_OVERRIDE { 119 void appendName(SkString* name) override {
120 name->append("oval"); 120 name->append("oval");
121 } 121 }
122 void makePath(SkPath* path) SK_OVERRIDE { 122 void makePath(SkPath* path) 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 void appendName(SkString* name) SK_OVERRIDE { 134 void appendName(SkString* name) override {
135 name->append("circle"); 135 name->append("circle");
136 } 136 }
137 void makePath(SkPath* path) SK_OVERRIDE { 137 void makePath(SkPath* path) 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 void appendName(SkString* name) SK_OVERRIDE { 149 void appendName(SkString* name) 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 int complexity() SK_OVERRIDE { return 1; } 170 int complexity() 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 void appendName(SkString* name) SK_OVERRIDE { 179 void appendName(SkString* name) override {
180 name->append("long_curved"); 180 name->append("long_curved");
181 } 181 }
182 void makePath(SkPath* path) SK_OVERRIDE { 182 void makePath(SkPath* path) 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 int complexity() SK_OVERRIDE { return 2; } 193 int complexity() 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 void appendName(SkString* name) SK_OVERRIDE { 202 void appendName(SkString* name) override {
203 name->append("long_line"); 203 name->append("long_line");
204 } 204 }
205 void makePath(SkPath* path) SK_OVERRIDE { 205 void makePath(SkPath* path) 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 int complexity() SK_OVERRIDE { return 2; } 212 int complexity() 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 bool isSuitableFor(Backend backend) SK_OVERRIDE { 219 bool isSuitableFor(Backend backend) 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 const char* onGetName() SK_OVERRIDE { 324 const char* onGetName() override {
325 return "path_create"; 325 return "path_create";
326 } 326 }
327 327
328 void onPreDraw() SK_OVERRIDE { 328 void onPreDraw() override {
329 this->createData(10, 100); 329 this->createData(10, 100);
330 } 330 }
331 331
332 void onDraw(const int loops, SkCanvas*) SK_OVERRIDE { 332 void onDraw(const int loops, SkCanvas*) 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 const char* onGetName() SK_OVERRIDE { 354 const char* onGetName() override {
355 return "path_copy"; 355 return "path_copy";
356 } 356 }
357 void onPreDraw() SK_OVERRIDE { 357 void onPreDraw() 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 void onDraw(const int loops, SkCanvas*) SK_OVERRIDE { 366 void onDraw(const int loops, SkCanvas*) 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 const char* onGetName() SK_OVERRIDE { 389 const char* onGetName() 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 void onPreDraw() SK_OVERRIDE { 393 void onPreDraw() 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 void onDraw(const int loops, SkCanvas*) SK_OVERRIDE { 406 void onDraw(const int loops, SkCanvas*) 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 const char* onGetName() SK_OVERRIDE { 437 const char* onGetName() override {
438 return "path_equality_50%"; 438 return "path_equality_50%";
439 } 439 }
440 440
441 void onPreDraw() SK_OVERRIDE { 441 void onPreDraw() 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 void onDraw(const int loops, SkCanvas*) SK_OVERRIDE { 453 void onDraw(const int loops, SkCanvas*) 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 const char* onGetName() SK_OVERRIDE { 486 const char* onGetName() 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 void onPreDraw() SK_OVERRIDE { 504 void onPreDraw() 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 void onDraw(const int loops, SkCanvas*) SK_OVERRIDE { 517 void onDraw(const int loops, SkCanvas*) 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 const char* onGetName() SK_OVERRIDE { 581 const char* onGetName() override {
582 return fName.c_str(); 582 return fName.c_str();
583 } 583 }
584 584
585 void onDraw(const int loops, SkCanvas* canvas) SK_OVERRIDE { 585 void onDraw(const int loops, SkCanvas* canvas) 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 const char* onGetName() SK_OVERRIDE { 645 const char* onGetName() 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 void onDraw(const int loops, SkCanvas* canvas) SK_OVERRIDE { 691 void onDraw(const int loops, SkCanvas* canvas) 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 bool isSuitableFor(Backend backend) SK_OVERRIDE { 756 bool isSuitableFor(Backend backend) override {
757 return backend == kNonRendering_Backend; 757 return backend == kNonRendering_Backend;
758 } 758 }
759 759
760 private: 760 private:
761 const char* onGetName() SK_OVERRIDE { 761 const char* onGetName() override {
762 return fName.c_str(); 762 return fName.c_str();
763 } 763 }
764 764
765 void onDraw(const int loops, SkCanvas*) SK_OVERRIDE { 765 void onDraw(const int loops, SkCanvas*) 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 void onPreDraw() SK_OVERRIDE { 772 void onPreDraw() 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 const char* onGetName() SK_OVERRIDE { 820 const char* onGetName() override {
821 return "ratquad-chop-0.5"; 821 return "ratquad-chop-0.5";
822 } 822 }
823 823
824 void onDraw(const int loops, SkCanvas*) SK_OVERRIDE { 824 void onDraw(const int loops, SkCanvas*) 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 protected: 835 protected:
836 SkConic fRQ, fDst[2]; 836 SkConic fRQ, fDst[2];
837 SkString fName; 837 SkString fName;
838 const bool fUseV2; 838 const bool fUseV2;
839 public: 839 public:
840 ConicBench_ChopHalf(bool useV2) : fUseV2(useV2) { 840 ConicBench_ChopHalf(bool useV2) : fUseV2(useV2) {
841 fRQ.fPts[0].set(0, 0); 841 fRQ.fPts[0].set(0, 0);
842 fRQ.fPts[1].set(100, 0); 842 fRQ.fPts[1].set(100, 0);
843 fRQ.fPts[2].set(100, 100); 843 fRQ.fPts[2].set(100, 100);
844 fRQ.fW = SkScalarCos(SK_ScalarPI/4); 844 fRQ.fW = SkScalarCos(SK_ScalarPI/4);
845 845
846 fName.printf("conic-chop-half%d", useV2); 846 fName.printf("conic-chop-half%d", useV2);
847 } 847 }
848 848
849 bool isSuitableFor(Backend backend) SK_OVERRIDE { 849 bool isSuitableFor(Backend backend) override {
850 return backend == kNonRendering_Backend; 850 return backend == kNonRendering_Backend;
851 } 851 }
852 852
853 private: 853 private:
854 const char* onGetName() SK_OVERRIDE { return fName.c_str(); } 854 const char* onGetName() override { return fName.c_str(); }
855 855
856 void onDraw(const int loops, SkCanvas*) SK_OVERRIDE { 856 void onDraw(const int loops, SkCanvas*) override {
857 if (fUseV2) { 857 if (fUseV2) {
858 for (int i = 0; i < loops; ++i) { 858 for (int i = 0; i < loops; ++i) {
859 fRQ.chop2(fDst); 859 fRQ.chop2(fDst);
860 } 860 }
861 } else { 861 } else {
862 for (int i = 0; i < loops; ++i) { 862 for (int i = 0; i < loops; ++i) {
863 fRQ.chop(fDst); 863 fRQ.chop(fDst);
864 } 864 }
865 } 865 }
866 } 866 }
867 867
868 typedef Benchmark INHERITED; 868 typedef Benchmark INHERITED;
869 }; 869 };
870 DEF_BENCH( return new ConicBench_ChopHalf(false); ) 870 DEF_BENCH( return new ConicBench_ChopHalf(false); )
871 DEF_BENCH( return new ConicBench_ChopHalf(true); ) 871 DEF_BENCH( return new ConicBench_ChopHalf(true); )
872 872
873 class ConicBench_EvalPos : public ConicBench_ChopHalf { 873 class ConicBench_EvalPos : public ConicBench_ChopHalf {
874 public: 874 public:
875 ConicBench_EvalPos(bool useV2) : ConicBench_ChopHalf(useV2) { 875 ConicBench_EvalPos(bool useV2) : ConicBench_ChopHalf(useV2) {
876 fName.printf("conic-eval-pos%d", useV2); 876 fName.printf("conic-eval-pos%d", useV2);
877 } 877 }
878 void onDraw(const int loops, SkCanvas*) SK_OVERRIDE { 878 void onDraw(const int loops, SkCanvas*) override {
879 if (fUseV2) { 879 if (fUseV2) {
880 for (int i = 0; i < loops; ++i) { 880 for (int i = 0; i < loops; ++i) {
881 for (int j = 0; j < 1000; ++j) { 881 for (int j = 0; j < 1000; ++j) {
882 fDst[0].fPts[0] = fRQ.evalAt(0.4f); 882 fDst[0].fPts[0] = fRQ.evalAt(0.4f);
883 } 883 }
884 } 884 }
885 } else { 885 } else {
886 for (int i = 0; i < loops; ++i) { 886 for (int i = 0; i < loops; ++i) {
887 for (int j = 0; j < 1000; ++j) { 887 for (int j = 0; j < 1000; ++j) {
888 fRQ.evalAt(0.4f, &fDst[0].fPts[0], NULL); 888 fRQ.evalAt(0.4f, &fDst[0].fPts[0], NULL);
889 } 889 }
890 } 890 }
891 } 891 }
892 } 892 }
893 }; 893 };
894 DEF_BENCH( return new ConicBench_EvalPos(false); ) 894 DEF_BENCH( return new ConicBench_EvalPos(false); )
895 DEF_BENCH( return new ConicBench_EvalPos(true); ) 895 DEF_BENCH( return new ConicBench_EvalPos(true); )
896 896
897 class ConicBench_EvalTan : public ConicBench_ChopHalf { 897 class ConicBench_EvalTan : public ConicBench_ChopHalf {
898 public: 898 public:
899 ConicBench_EvalTan(bool useV2) : ConicBench_ChopHalf(useV2) { 899 ConicBench_EvalTan(bool useV2) : ConicBench_ChopHalf(useV2) {
900 fName.printf("conic-eval-tan%d", useV2); 900 fName.printf("conic-eval-tan%d", useV2);
901 } 901 }
902 void onDraw(const int loops, SkCanvas*) SK_OVERRIDE { 902 void onDraw(const int loops, SkCanvas*) override {
903 if (fUseV2) { 903 if (fUseV2) {
904 for (int i = 0; i < loops; ++i) { 904 for (int i = 0; i < loops; ++i) {
905 for (int j = 0; j < 1000; ++j) { 905 for (int j = 0; j < 1000; ++j) {
906 fDst[0].fPts[0] = fRQ.evalTangentAt(0.4f); 906 fDst[0].fPts[0] = fRQ.evalTangentAt(0.4f);
907 } 907 }
908 } 908 }
909 } else { 909 } else {
910 for (int i = 0; i < loops; ++i) { 910 for (int i = 0; i < loops; ++i) {
911 for (int j = 0; j < 1000; ++j) { 911 for (int j = 0; j < 1000; ++j) {
912 fRQ.evalAt(0.4f, NULL, &fDst[0].fPts[0]); 912 fRQ.evalAt(0.4f, NULL, &fDst[0].fPts[0]);
(...skipping 20 matching lines...) Expand all
933 933
934 class ConicBench : public Benchmark { 934 class ConicBench : public Benchmark {
935 public: 935 public:
936 ConicBench() { 936 ConicBench() {
937 SkRandom rand; 937 SkRandom rand;
938 for (int i = 0; i < CONICS; ++i) { 938 for (int i = 0; i < CONICS; ++i) {
939 rand_conic(&fConics[i], rand); 939 rand_conic(&fConics[i], rand);
940 } 940 }
941 } 941 }
942 942
943 bool isSuitableFor(Backend backend) SK_OVERRIDE { 943 bool isSuitableFor(Backend backend) override {
944 return backend == kNonRendering_Backend; 944 return backend == kNonRendering_Backend;
945 } 945 }
946 946
947 protected: 947 protected:
948 enum { 948 enum {
949 CONICS = 100 949 CONICS = 100
950 }; 950 };
951 SkConic fConics[CONICS]; 951 SkConic fConics[CONICS];
952 952
953 private: 953 private:
954 typedef Benchmark INHERITED; 954 typedef Benchmark INHERITED;
955 }; 955 };
956 956
957 class ConicBench_ComputeError : public ConicBench { 957 class ConicBench_ComputeError : public ConicBench {
958 public: 958 public:
959 ConicBench_ComputeError() {} 959 ConicBench_ComputeError() {}
960 960
961 protected: 961 protected:
962 const char* onGetName() SK_OVERRIDE { 962 const char* onGetName() override {
963 return "conic-compute-error"; 963 return "conic-compute-error";
964 } 964 }
965 965
966 void onDraw(const int loops, SkCanvas*) SK_OVERRIDE { 966 void onDraw(const int loops, SkCanvas*) override {
967 SkVector err; 967 SkVector err;
968 for (int i = 0; i < loops; ++i) { 968 for (int i = 0; i < loops; ++i) {
969 for (int j = 0; j < CONICS; ++j) { 969 for (int j = 0; j < CONICS; ++j) {
970 fConics[j].computeAsQuadError(&err); 970 fConics[j].computeAsQuadError(&err);
971 } 971 }
972 } 972 }
973 } 973 }
974 974
975 private: 975 private:
976 typedef ConicBench INHERITED; 976 typedef ConicBench INHERITED;
977 }; 977 };
978 978
979 class ConicBench_asQuadTol : public ConicBench { 979 class ConicBench_asQuadTol : public ConicBench {
980 public: 980 public:
981 ConicBench_asQuadTol() {} 981 ConicBench_asQuadTol() {}
982 982
983 protected: 983 protected:
984 const char* onGetName() SK_OVERRIDE { 984 const char* onGetName() override {
985 return "conic-asQuadTol"; 985 return "conic-asQuadTol";
986 } 986 }
987 987
988 void onDraw(const int loops, SkCanvas*) SK_OVERRIDE { 988 void onDraw(const int loops, SkCanvas*) override {
989 for (int i = 0; i < loops; ++i) { 989 for (int i = 0; i < loops; ++i) {
990 for (int j = 0; j < CONICS; ++j) { 990 for (int j = 0; j < CONICS; ++j) {
991 fConics[j].asQuadTol(SK_ScalarHalf); 991 fConics[j].asQuadTol(SK_ScalarHalf);
992 } 992 }
993 } 993 }
994 } 994 }
995 995
996 private: 996 private:
997 typedef ConicBench INHERITED; 997 typedef ConicBench INHERITED;
998 }; 998 };
999 999
1000 class ConicBench_quadPow2 : public ConicBench { 1000 class ConicBench_quadPow2 : public ConicBench {
1001 public: 1001 public:
1002 ConicBench_quadPow2() {} 1002 ConicBench_quadPow2() {}
1003 1003
1004 protected: 1004 protected:
1005 const char* onGetName() SK_OVERRIDE { 1005 const char* onGetName() override {
1006 return "conic-quadPow2"; 1006 return "conic-quadPow2";
1007 } 1007 }
1008 1008
1009 void onDraw(const int loops, SkCanvas*) SK_OVERRIDE { 1009 void onDraw(const int loops, SkCanvas*) override {
1010 for (int i = 0; i < loops; ++i) { 1010 for (int i = 0; i < loops; ++i) {
1011 for (int j = 0; j < CONICS; ++j) { 1011 for (int j = 0; j < CONICS; ++j) {
1012 fConics[j].computeQuadPOW2(SK_ScalarHalf); 1012 fConics[j].computeQuadPOW2(SK_ScalarHalf);
1013 } 1013 }
1014 } 1014 }
1015 } 1015 }
1016 1016
1017 private: 1017 private:
1018 typedef ConicBench INHERITED; 1018 typedef ConicBench INHERITED;
1019 }; 1019 };
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
1075 DEF_BENCH( return new ConservativelyContainsBench(ConservativelyContainsBench::k Oval_Type); ) 1075 DEF_BENCH( return new ConservativelyContainsBench(ConservativelyContainsBench::k Oval_Type); )
1076 1076
1077 1077
1078 // These seem to be optimized away, which is troublesome for timing. 1078 // These seem to be optimized away, which is troublesome for timing.
1079 /* 1079 /*
1080 DEF_BENCH( return new ConicBench_Chop5() ) 1080 DEF_BENCH( return new ConicBench_Chop5() )
1081 DEF_BENCH( return new ConicBench_ComputeError() ) 1081 DEF_BENCH( return new ConicBench_ComputeError() )
1082 DEF_BENCH( return new ConicBench_asQuadTol() ) 1082 DEF_BENCH( return new ConicBench_asQuadTol() )
1083 DEF_BENCH( return new ConicBench_quadPow2() ) 1083 DEF_BENCH( return new ConicBench_quadPow2() )
1084 */ 1084 */
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