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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 | 44 |
45 protected: | 45 protected: |
46 const char* onGetName() override { | 46 const char* onGetName() override { |
47 fName.printf("path_%s_%s_", | 47 fName.printf("path_%s_%s_", |
48 fFlags & kStroke_Flag ? "stroke" : "fill", | 48 fFlags & kStroke_Flag ? "stroke" : "fill", |
49 fFlags & kBig_Flag ? "big" : "small"); | 49 fFlags & kBig_Flag ? "big" : "small"); |
50 this->appendName(&fName); | 50 this->appendName(&fName); |
51 return fName.c_str(); | 51 return fName.c_str(); |
52 } | 52 } |
53 | 53 |
54 void onDraw(const int loops, SkCanvas* canvas) override { | 54 void onDraw(int loops, SkCanvas* canvas) override { |
55 SkPaint paint(fPaint); | 55 SkPaint paint(fPaint); |
56 this->setupPaint(&paint); | 56 this->setupPaint(&paint); |
57 | 57 |
58 SkPath path; | 58 SkPath path; |
59 this->makePath(&path); | 59 this->makePath(&path); |
60 if (fFlags & kBig_Flag) { | 60 if (fFlags & kBig_Flag) { |
61 const SkMatrix m = SkMatrix::MakeScale(SkIntToScalar(10), SkIntToSca
lar(10)); | 61 const SkMatrix m = SkMatrix::MakeScale(SkIntToScalar(10), SkIntToSca
lar(10)); |
62 path.transform(m); | 62 path.transform(m); |
63 } | 63 } |
64 | 64 |
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 onDelayedSetup() 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(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: |
(...skipping 13 matching lines...) Expand all Loading... |
356 } | 356 } |
357 void onDelayedSetup() 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(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, |
(...skipping 19 matching lines...) Expand all Loading... |
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*) override { | 406 void onDraw(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 26 matching lines...) Expand all Loading... |
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*) override { | 453 void onDraw(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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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*) override { | 517 void onDraw(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 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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() 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) override { | 585 void onDraw(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 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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) override { | 691 void onDraw(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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
755 | 755 |
756 bool isSuitableFor(Backend backend) 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() 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*) override { | 765 void onDraw(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 onDelayedSetup() override { | 772 void onDelayedSetup() override { |
773 fQueryRects.setCount(kQueryRectCnt); | 773 fQueryRects.setCount(kQueryRectCnt); |
774 | 774 |
775 SkRandom rand; | 775 SkRandom rand; |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
818 fRQ.fW = SkScalarCos(SK_ScalarPI/4); | 818 fRQ.fW = SkScalarCos(SK_ScalarPI/4); |
819 } | 819 } |
820 | 820 |
821 bool isSuitableFor(Backend backend) override { | 821 bool isSuitableFor(Backend backend) override { |
822 return backend == kNonRendering_Backend; | 822 return backend == kNonRendering_Backend; |
823 } | 823 } |
824 | 824 |
825 private: | 825 private: |
826 const char* onGetName() override { return fName.c_str(); } | 826 const char* onGetName() override { return fName.c_str(); } |
827 | 827 |
828 void onDraw(const int loops, SkCanvas*) override { | 828 void onDraw(int loops, SkCanvas*) override { |
829 for (int i = 0; i < loops; ++i) { | 829 for (int i = 0; i < loops; ++i) { |
830 fRQ.chop(fDst); | 830 fRQ.chop(fDst); |
831 } | 831 } |
832 } | 832 } |
833 | 833 |
834 typedef Benchmark INHERITED; | 834 typedef Benchmark INHERITED; |
835 }; | 835 }; |
836 DEF_BENCH( return new ConicBench_Chop; ) | 836 DEF_BENCH( return new ConicBench_Chop; ) |
837 | 837 |
838 class ConicBench_EvalPos : public ConicBench_Chop { | 838 class ConicBench_EvalPos : public ConicBench_Chop { |
839 const bool fUseV2; | 839 const bool fUseV2; |
840 public: | 840 public: |
841 ConicBench_EvalPos(bool useV2) : fUseV2(useV2) { | 841 ConicBench_EvalPos(bool useV2) : fUseV2(useV2) { |
842 fName.printf("conic-eval-pos%d", useV2); | 842 fName.printf("conic-eval-pos%d", useV2); |
843 } | 843 } |
844 void onDraw(const int loops, SkCanvas*) override { | 844 void onDraw(int loops, SkCanvas*) override { |
845 if (fUseV2) { | 845 if (fUseV2) { |
846 for (int i = 0; i < loops; ++i) { | 846 for (int i = 0; i < loops; ++i) { |
847 for (int j = 0; j < 1000; ++j) { | 847 for (int j = 0; j < 1000; ++j) { |
848 fDst[0].fPts[0] = fRQ.evalAt(0.4f); | 848 fDst[0].fPts[0] = fRQ.evalAt(0.4f); |
849 } | 849 } |
850 } | 850 } |
851 } else { | 851 } else { |
852 for (int i = 0; i < loops; ++i) { | 852 for (int i = 0; i < loops; ++i) { |
853 for (int j = 0; j < 1000; ++j) { | 853 for (int j = 0; j < 1000; ++j) { |
854 fRQ.evalAt(0.4f, &fDst[0].fPts[0], nullptr); | 854 fRQ.evalAt(0.4f, &fDst[0].fPts[0], nullptr); |
855 } | 855 } |
856 } | 856 } |
857 } | 857 } |
858 } | 858 } |
859 }; | 859 }; |
860 DEF_BENCH( return new ConicBench_EvalPos(false); ) | 860 DEF_BENCH( return new ConicBench_EvalPos(false); ) |
861 DEF_BENCH( return new ConicBench_EvalPos(true); ) | 861 DEF_BENCH( return new ConicBench_EvalPos(true); ) |
862 | 862 |
863 class ConicBench_EvalTan : public ConicBench_Chop { | 863 class ConicBench_EvalTan : public ConicBench_Chop { |
864 const bool fUseV2; | 864 const bool fUseV2; |
865 public: | 865 public: |
866 ConicBench_EvalTan(bool useV2) : fUseV2(useV2) { | 866 ConicBench_EvalTan(bool useV2) : fUseV2(useV2) { |
867 fName.printf("conic-eval-tan%d", useV2); | 867 fName.printf("conic-eval-tan%d", useV2); |
868 } | 868 } |
869 void onDraw(const int loops, SkCanvas*) override { | 869 void onDraw(int loops, SkCanvas*) override { |
870 if (fUseV2) { | 870 if (fUseV2) { |
871 for (int i = 0; i < loops; ++i) { | 871 for (int i = 0; i < loops; ++i) { |
872 for (int j = 0; j < 1000; ++j) { | 872 for (int j = 0; j < 1000; ++j) { |
873 fDst[0].fPts[0] = fRQ.evalTangentAt(0.4f); | 873 fDst[0].fPts[0] = fRQ.evalTangentAt(0.4f); |
874 } | 874 } |
875 } | 875 } |
876 } else { | 876 } else { |
877 for (int i = 0; i < loops; ++i) { | 877 for (int i = 0; i < loops; ++i) { |
878 for (int j = 0; j < 1000; ++j) { | 878 for (int j = 0; j < 1000; ++j) { |
879 fRQ.evalAt(0.4f, nullptr, &fDst[0].fPts[0]); | 879 fRQ.evalAt(0.4f, nullptr, &fDst[0].fPts[0]); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
923 | 923 |
924 class ConicBench_ComputeError : public ConicBench { | 924 class ConicBench_ComputeError : public ConicBench { |
925 public: | 925 public: |
926 ConicBench_ComputeError() {} | 926 ConicBench_ComputeError() {} |
927 | 927 |
928 protected: | 928 protected: |
929 const char* onGetName() override { | 929 const char* onGetName() override { |
930 return "conic-compute-error"; | 930 return "conic-compute-error"; |
931 } | 931 } |
932 | 932 |
933 void onDraw(const int loops, SkCanvas*) override { | 933 void onDraw(int loops, SkCanvas*) override { |
934 SkVector err; | 934 SkVector err; |
935 for (int i = 0; i < loops; ++i) { | 935 for (int i = 0; i < loops; ++i) { |
936 for (int j = 0; j < CONICS; ++j) { | 936 for (int j = 0; j < CONICS; ++j) { |
937 fConics[j].computeAsQuadError(&err); | 937 fConics[j].computeAsQuadError(&err); |
938 } | 938 } |
939 } | 939 } |
940 } | 940 } |
941 | 941 |
942 private: | 942 private: |
943 typedef ConicBench INHERITED; | 943 typedef ConicBench INHERITED; |
944 }; | 944 }; |
945 | 945 |
946 class ConicBench_asQuadTol : public ConicBench { | 946 class ConicBench_asQuadTol : public ConicBench { |
947 public: | 947 public: |
948 ConicBench_asQuadTol() {} | 948 ConicBench_asQuadTol() {} |
949 | 949 |
950 protected: | 950 protected: |
951 const char* onGetName() override { | 951 const char* onGetName() override { |
952 return "conic-asQuadTol"; | 952 return "conic-asQuadTol"; |
953 } | 953 } |
954 | 954 |
955 void onDraw(const int loops, SkCanvas*) override { | 955 void onDraw(int loops, SkCanvas*) override { |
956 for (int i = 0; i < loops; ++i) { | 956 for (int i = 0; i < loops; ++i) { |
957 for (int j = 0; j < CONICS; ++j) { | 957 for (int j = 0; j < CONICS; ++j) { |
958 fConics[j].asQuadTol(SK_ScalarHalf); | 958 fConics[j].asQuadTol(SK_ScalarHalf); |
959 } | 959 } |
960 } | 960 } |
961 } | 961 } |
962 | 962 |
963 private: | 963 private: |
964 typedef ConicBench INHERITED; | 964 typedef ConicBench INHERITED; |
965 }; | 965 }; |
966 | 966 |
967 class ConicBench_quadPow2 : public ConicBench { | 967 class ConicBench_quadPow2 : public ConicBench { |
968 public: | 968 public: |
969 ConicBench_quadPow2() {} | 969 ConicBench_quadPow2() {} |
970 | 970 |
971 protected: | 971 protected: |
972 const char* onGetName() override { | 972 const char* onGetName() override { |
973 return "conic-quadPow2"; | 973 return "conic-quadPow2"; |
974 } | 974 } |
975 | 975 |
976 void onDraw(const int loops, SkCanvas*) override { | 976 void onDraw(int loops, SkCanvas*) override { |
977 for (int i = 0; i < loops; ++i) { | 977 for (int i = 0; i < loops; ++i) { |
978 for (int j = 0; j < CONICS; ++j) { | 978 for (int j = 0; j < CONICS; ++j) { |
979 fConics[j].computeQuadPOW2(SK_ScalarHalf); | 979 fConics[j].computeQuadPOW2(SK_ScalarHalf); |
980 } | 980 } |
981 } | 981 } |
982 } | 982 } |
983 | 983 |
984 private: | 984 private: |
985 typedef ConicBench INHERITED; | 985 typedef ConicBench INHERITED; |
986 }; | 986 }; |
(...skipping 55 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 |