| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #include "Benchmark.h" | 8 #include "Benchmark.h" |
| 9 #include "SkBitmap.h" | 9 #include "SkBitmap.h" |
| 10 #include "SkCanvas.h" | 10 #include "SkCanvas.h" |
| (...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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() override { | 324 const char* onGetName() override { |
| 325 return "path_create"; | 325 return "path_create"; |
| 326 } | 326 } |
| 327 | 327 |
| 328 void onPreDraw() override { | 328 void onDelayedSetup() override { |
| 329 this->createData(10, 100); | 329 this->createData(10, 100); |
| 330 } | 330 } |
| 331 | 331 |
| 332 void onDraw(const int loops, SkCanvas*) 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() override { | 354 const char* onGetName() override { |
| 355 return "path_copy"; | 355 return "path_copy"; |
| 356 } | 356 } |
| 357 void onPreDraw() override { | 357 void onDelayedSetup() 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*) 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) { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 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() 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() override { | 393 void onDelayedSetup() 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 } |
| (...skipping 27 matching lines...) Expand all Loading... |
| 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() override { | 437 const char* onGetName() override { |
| 438 return "path_equality_50%"; | 438 return "path_equality_50%"; |
| 439 } | 439 } |
| 440 | 440 |
| 441 void onPreDraw() override { | 441 void onDelayedSetup() 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 } |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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() override { | 504 void onDelayedSetup() 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(); |
| (...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 762 return fName.c_str(); | 762 return fName.c_str(); |
| 763 } | 763 } |
| 764 | 764 |
| 765 void onDraw(const int loops, SkCanvas*) 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() override { | 772 void onDelayedSetup() 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 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1042 DEF_BENCH( return new ConservativelyContainsBench(ConservativelyContainsBench::k
Oval_Type); ) | 1042 DEF_BENCH( return new ConservativelyContainsBench(ConservativelyContainsBench::k
Oval_Type); ) |
| 1043 | 1043 |
| 1044 | 1044 |
| 1045 // These seem to be optimized away, which is troublesome for timing. | 1045 // These seem to be optimized away, which is troublesome for timing. |
| 1046 /* | 1046 /* |
| 1047 DEF_BENCH( return new ConicBench_Chop5() ) | 1047 DEF_BENCH( return new ConicBench_Chop5() ) |
| 1048 DEF_BENCH( return new ConicBench_ComputeError() ) | 1048 DEF_BENCH( return new ConicBench_ComputeError() ) |
| 1049 DEF_BENCH( return new ConicBench_asQuadTol() ) | 1049 DEF_BENCH( return new ConicBench_asQuadTol() ) |
| 1050 DEF_BENCH( return new ConicBench_quadPow2() ) | 1050 DEF_BENCH( return new ConicBench_quadPow2() ) |
| 1051 */ | 1051 */ |
| OLD | NEW |