OLD | NEW |
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 "SkBenchmark.h" | 8 #include "SkBenchmark.h" |
9 #include "SkBitmap.h" | 9 #include "SkBitmap.h" |
10 #include "SkCanvas.h" | 10 #include "SkCanvas.h" |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
176 class LongCurvedPathBench : public PathBench { | 176 class LongCurvedPathBench : public PathBench { |
177 public: | 177 public: |
178 LongCurvedPathBench(void * param, Flags flags) | 178 LongCurvedPathBench(void * param, Flags flags) |
179 : INHERITED(param, flags) { | 179 : INHERITED(param, flags) { |
180 } | 180 } |
181 | 181 |
182 virtual void appendName(SkString* name) SK_OVERRIDE { | 182 virtual void appendName(SkString* name) SK_OVERRIDE { |
183 name->append("long_curved"); | 183 name->append("long_curved"); |
184 } | 184 } |
185 virtual void makePath(SkPath* path) SK_OVERRIDE { | 185 virtual void makePath(SkPath* path) SK_OVERRIDE { |
186 SkMWCRandom rand (12); | 186 SkRandom rand (12); |
187 int i; | 187 int i; |
188 for (i = 0; i < 100; i++) { | 188 for (i = 0; i < 100; i++) { |
189 path->quadTo(SkScalarMul(rand.nextUScalar1(), SkIntToScalar(640)), | 189 path->quadTo(SkScalarMul(rand.nextUScalar1(), SkIntToScalar(640)), |
190 SkScalarMul(rand.nextUScalar1(), SkIntToScalar(480)), | 190 SkScalarMul(rand.nextUScalar1(), SkIntToScalar(480)), |
191 SkScalarMul(rand.nextUScalar1(), SkIntToScalar(640)), | 191 SkScalarMul(rand.nextUScalar1(), SkIntToScalar(640)), |
192 SkScalarMul(rand.nextUScalar1(), SkIntToScalar(480))); | 192 SkScalarMul(rand.nextUScalar1(), SkIntToScalar(480))); |
193 } | 193 } |
194 path->close(); | 194 path->close(); |
195 } | 195 } |
196 virtual int complexity() SK_OVERRIDE { return 2; } | 196 virtual int complexity() SK_OVERRIDE { return 2; } |
197 private: | 197 private: |
198 typedef PathBench INHERITED; | 198 typedef PathBench INHERITED; |
199 }; | 199 }; |
200 | 200 |
201 class LongLinePathBench : public PathBench { | 201 class LongLinePathBench : public PathBench { |
202 public: | 202 public: |
203 LongLinePathBench(void * param, Flags flags) | 203 LongLinePathBench(void * param, Flags flags) |
204 : INHERITED(param, flags) { | 204 : INHERITED(param, flags) { |
205 } | 205 } |
206 | 206 |
207 virtual void appendName(SkString* name) SK_OVERRIDE { | 207 virtual void appendName(SkString* name) SK_OVERRIDE { |
208 name->append("long_line"); | 208 name->append("long_line"); |
209 } | 209 } |
210 virtual void makePath(SkPath* path) SK_OVERRIDE { | 210 virtual void makePath(SkPath* path) SK_OVERRIDE { |
211 SkMWCRandom rand; | 211 SkRandom rand; |
212 path->moveTo(rand.nextUScalar1() * 640, rand.nextUScalar1() * 480); | 212 path->moveTo(rand.nextUScalar1() * 640, rand.nextUScalar1() * 480); |
213 for (size_t i = 1; i < 100; i++) { | 213 for (size_t i = 1; i < 100; i++) { |
214 path->lineTo(rand.nextUScalar1() * 640, rand.nextUScalar1() * 480); | 214 path->lineTo(rand.nextUScalar1() * 640, rand.nextUScalar1() * 480); |
215 } | 215 } |
216 } | 216 } |
217 virtual int complexity() SK_OVERRIDE { return 2; } | 217 virtual int complexity() SK_OVERRIDE { return 2; } |
218 private: | 218 private: |
219 typedef PathBench INHERITED; | 219 typedef PathBench INHERITED; |
220 }; | 220 }; |
221 | 221 |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
309 kNumVerbCnts = 1 << 5, | 309 kNumVerbCnts = 1 << 5, |
310 kNumVerbs = 1 << 5, | 310 kNumVerbs = 1 << 5, |
311 kNumPoints = 1 << 5, | 311 kNumPoints = 1 << 5, |
312 }; | 312 }; |
313 SkAutoTArray<int> fVerbCnts; | 313 SkAutoTArray<int> fVerbCnts; |
314 SkAutoTArray<SkPath::Verb> fVerbs; | 314 SkAutoTArray<SkPath::Verb> fVerbs; |
315 SkAutoTArray<SkPoint> fPoints; | 315 SkAutoTArray<SkPoint> fPoints; |
316 int fCurrPath; | 316 int fCurrPath; |
317 int fCurrVerb; | 317 int fCurrVerb; |
318 int fCurrPoint; | 318 int fCurrPoint; |
319 SkMWCRandom fRandom; | 319 SkRandom fRandom; |
320 typedef SkBenchmark INHERITED; | 320 typedef SkBenchmark INHERITED; |
321 }; | 321 }; |
322 | 322 |
323 class PathCreateBench : public RandomPathBench { | 323 class PathCreateBench : public RandomPathBench { |
324 public: | 324 public: |
325 PathCreateBench(void* param) : INHERITED(param) { | 325 PathCreateBench(void* param) : INHERITED(param) { |
326 } | 326 } |
327 | 327 |
328 protected: | 328 protected: |
329 enum { N = SkBENCHLOOP(5000) }; | 329 enum { N = SkBENCHLOOP(5000) }; |
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
646 | 646 |
647 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { | 647 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { |
648 SkPaint paint; | 648 SkPaint paint; |
649 | 649 |
650 paint.setColor(SK_ColorBLACK); | 650 paint.setColor(SK_ColorBLACK); |
651 paint.setAntiAlias(true); | 651 paint.setAntiAlias(true); |
652 if (fFlags & kStroke_Flag) { | 652 if (fFlags & kStroke_Flag) { |
653 paint.setStyle(SkPaint::kStroke_Style); | 653 paint.setStyle(SkPaint::kStroke_Style); |
654 } | 654 } |
655 | 655 |
656 SkMWCRandom rand; | 656 SkRandom rand; |
657 | 657 |
658 SkRect r; | 658 SkRect r; |
659 | 659 |
660 for (int i = 0; i < 5000; ++i) { | 660 for (int i = 0; i < 5000; ++i) { |
661 SkScalar radius = rand.nextUScalar1() * 3; | 661 SkScalar radius = rand.nextUScalar1() * 3; |
662 r.fLeft = rand.nextUScalar1() * 300; | 662 r.fLeft = rand.nextUScalar1() * 300; |
663 r.fTop = rand.nextUScalar1() * 300; | 663 r.fTop = rand.nextUScalar1() * 300; |
664 r.fRight = r.fLeft + 2 * radius; | 664 r.fRight = r.fLeft + 2 * radius; |
665 r.fBottom = r.fTop + 2 * radius; | 665 r.fBottom = r.fTop + 2 * radius; |
666 | 666 |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
747 add_corner_arc(path, r, xCorner, yCorner, 270); | 747 add_corner_arc(path, r, xCorner, yCorner, 270); |
748 add_corner_arc(path, r, xCorner, yCorner, 0); | 748 add_corner_arc(path, r, xCorner, yCorner, 0); |
749 add_corner_arc(path, r, xCorner, yCorner, 90); | 749 add_corner_arc(path, r, xCorner, yCorner, 90); |
750 add_corner_arc(path, r, xCorner, yCorner, 180); | 750 add_corner_arc(path, r, xCorner, yCorner, 180); |
751 path->close(); | 751 path->close(); |
752 | 752 |
753 SkASSERT(path->isConvex()); | 753 SkASSERT(path->isConvex()); |
754 } | 754 } |
755 | 755 |
756 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { | 756 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { |
757 SkMWCRandom rand; | 757 SkRandom rand; |
758 SkRect r; | 758 SkRect r; |
759 | 759 |
760 for (int i = 0; i < 5000; ++i) { | 760 for (int i = 0; i < 5000; ++i) { |
761 SkPaint paint; | 761 SkPaint paint; |
762 paint.setColor(0xff000000 | rand.nextU()); | 762 paint.setColor(0xff000000 | rand.nextU()); |
763 paint.setAntiAlias(true); | 763 paint.setAntiAlias(true); |
764 | 764 |
765 SkScalar size = rand.nextUScalar1() * 30; | 765 SkScalar size = rand.nextUScalar1() * 30; |
766 if (size < SK_Scalar1) { | 766 if (size < SK_Scalar1) { |
767 continue; | 767 continue; |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
827 virtual void onDraw(SkCanvas*) SK_OVERRIDE { | 827 virtual void onDraw(SkCanvas*) SK_OVERRIDE { |
828 for (int i = 0; i < N; ++i) { | 828 for (int i = 0; i < N; ++i) { |
829 const SkRect& rect = fQueryRects[i % kQueryRectCnt]; | 829 const SkRect& rect = fQueryRects[i % kQueryRectCnt]; |
830 fParity = fParity != fPath.conservativelyContainsRect(rect); | 830 fParity = fParity != fPath.conservativelyContainsRect(rect); |
831 } | 831 } |
832 } | 832 } |
833 | 833 |
834 virtual void onPreDraw() SK_OVERRIDE { | 834 virtual void onPreDraw() SK_OVERRIDE { |
835 fQueryRects.setCount(kQueryRectCnt); | 835 fQueryRects.setCount(kQueryRectCnt); |
836 | 836 |
837 SkMWCRandom rand; | 837 SkRandom rand; |
838 for (int i = 0; i < kQueryRectCnt; ++i) { | 838 for (int i = 0; i < kQueryRectCnt; ++i) { |
839 SkSize size; | 839 SkSize size; |
840 SkPoint xy; | 840 SkPoint xy; |
841 size.fWidth = rand.nextRangeScalar(kQueryMin.fWidth, kQueryMax.fWid
th); | 841 size.fWidth = rand.nextRangeScalar(kQueryMin.fWidth, kQueryMax.fWid
th); |
842 size.fHeight = rand.nextRangeScalar(kQueryMin.fHeight, kQueryMax.fHe
ight); | 842 size.fHeight = rand.nextRangeScalar(kQueryMin.fHeight, kQueryMax.fHe
ight); |
843 xy.fX = rand.nextRangeScalar(kBounds.fLeft, kBounds.fRight - size.fW
idth); | 843 xy.fX = rand.nextRangeScalar(kBounds.fLeft, kBounds.fRight - size.fW
idth); |
844 xy.fY = rand.nextRangeScalar(kBounds.fTop, kBounds.fBottom - size.fH
eight); | 844 xy.fY = rand.nextRangeScalar(kBounds.fTop, kBounds.fBottom - size.fH
eight); |
845 | 845 |
846 fQueryRects[i] = SkRect::MakeXYWH(xy.fX, xy.fY, size.fWidth, size.fH
eight); | 846 fQueryRects[i] = SkRect::MakeXYWH(xy.fX, xy.fY, size.fWidth, size.fH
eight); |
847 } | 847 } |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
924 for (int i = 0; i < N; ++i) { | 924 for (int i = 0; i < N; ++i) { |
925 fRQ.chop(dst); | 925 fRQ.chop(dst); |
926 } | 926 } |
927 } | 927 } |
928 | 928 |
929 typedef SkBenchmark INHERITED; | 929 typedef SkBenchmark INHERITED; |
930 }; | 930 }; |
931 | 931 |
932 /////////////////////////////////////////////////////////////////////////////// | 932 /////////////////////////////////////////////////////////////////////////////// |
933 | 933 |
934 static void rand_conic(SkConic* conic, SkMWCRandom& rand) { | 934 static void rand_conic(SkConic* conic, SkRandom& rand) { |
935 for (int i = 0; i < 3; ++i) { | 935 for (int i = 0; i < 3; ++i) { |
936 conic->fPts[i].set(rand.nextUScalar1() * 100, rand.nextUScalar1() * 100)
; | 936 conic->fPts[i].set(rand.nextUScalar1() * 100, rand.nextUScalar1() * 100)
; |
937 } | 937 } |
938 if (rand.nextUScalar1() > 0.5f) { | 938 if (rand.nextUScalar1() > 0.5f) { |
939 conic->fW = rand.nextUScalar1(); | 939 conic->fW = rand.nextUScalar1(); |
940 } else { | 940 } else { |
941 conic->fW = 1 + rand.nextUScalar1() * 4; | 941 conic->fW = 1 + rand.nextUScalar1() * 4; |
942 } | 942 } |
943 } | 943 } |
944 | 944 |
945 class ConicBench : public SkBenchmark { | 945 class ConicBench : public SkBenchmark { |
946 public: | 946 public: |
947 ConicBench(void* param) : INHERITED(param) { | 947 ConicBench(void* param) : INHERITED(param) { |
948 SkMWCRandom rand; | 948 SkRandom rand; |
949 for (int i = 0; i < CONICS; ++i) { | 949 for (int i = 0; i < CONICS; ++i) { |
950 rand_conic(&fConics[i], rand); | 950 rand_conic(&fConics[i], rand); |
951 } | 951 } |
952 fIsRendering = false; | 952 fIsRendering = false; |
953 } | 953 } |
954 | 954 |
955 protected: | 955 protected: |
956 enum { | 956 enum { |
957 N = 20000, | 957 N = 20000, |
958 CONICS = 100 | 958 CONICS = 100 |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1082 DEF_BENCH( return new ArbRoundRectBench(p, true); ) | 1082 DEF_BENCH( return new ArbRoundRectBench(p, true); ) |
1083 DEF_BENCH( return new ConservativelyContainsBench(p, ConservativelyContainsBench
::kRect_Type); ) | 1083 DEF_BENCH( return new ConservativelyContainsBench(p, ConservativelyContainsBench
::kRect_Type); ) |
1084 DEF_BENCH( return new ConservativelyContainsBench(p, ConservativelyContainsBench
::kRoundRect_Type); ) | 1084 DEF_BENCH( return new ConservativelyContainsBench(p, ConservativelyContainsBench
::kRoundRect_Type); ) |
1085 DEF_BENCH( return new ConservativelyContainsBench(p, ConservativelyContainsBench
::kOval_Type); ) | 1085 DEF_BENCH( return new ConservativelyContainsBench(p, ConservativelyContainsBench
::kOval_Type); ) |
1086 | 1086 |
1087 DEF_BENCH( return new ConicBench_Chop5(p) ) | 1087 DEF_BENCH( return new ConicBench_Chop5(p) ) |
1088 DEF_BENCH( return new ConicBench_ChopHalf(p) ) | 1088 DEF_BENCH( return new ConicBench_ChopHalf(p) ) |
1089 DEF_BENCH( return new ConicBench_ComputeError(p) ) | 1089 DEF_BENCH( return new ConicBench_ComputeError(p) ) |
1090 DEF_BENCH( return new ConicBench_asQuadTol(p) ) | 1090 DEF_BENCH( return new ConicBench_asQuadTol(p) ) |
1091 DEF_BENCH( return new ConicBench_quadPow2(p) ) | 1091 DEF_BENCH( return new ConicBench_quadPow2(p) ) |
OLD | NEW |