OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 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" |
11 #include "SkColorPriv.h" | 11 #include "SkColorPriv.h" |
12 #include "SkPaint.h" | 12 #include "SkPaint.h" |
13 #include "SkRandom.h" | 13 #include "SkRandom.h" |
14 #include "SkShader.h" | 14 #include "SkShader.h" |
15 #include "SkString.h" | 15 #include "SkString.h" |
16 #include "SkTArray.h" | 16 #include "SkTArray.h" |
17 | 17 |
18 | 18 |
19 class LineBench : public Benchmark { | 19 class LineBench : public Benchmark { |
20 SkScalar fStrokeWidth; | 20 SkScalar fStrokeWidth; |
21 bool fDoAA; | 21 bool fDoAA; |
22 SkString fName; | 22 SkString fName; |
23 enum { | 23 enum { |
24 LINES = 500, | 24 PTS = 500, |
25 }; | 25 }; |
26 SkPoint fStartPts[LINES]; | 26 SkPoint fPts[PTS]; |
27 SkPoint fEndPts[LINES]; | |
28 | 27 |
29 public: | 28 public: |
30 enum LineType { | 29 LineBench(SkScalar width, bool doAA) { |
31 SH, // Straight + horizontally | |
32 SV, // Straight + vertically | |
33 RAND, | |
34 }; | |
35 LineBench(SkScalar width, bool doAA, LineType type) { | |
36 fStrokeWidth = width; | 30 fStrokeWidth = width; |
37 fDoAA = doAA; | 31 fDoAA = doAA; |
38 fName.printf("lines_%g_%s_%s", width, doAA ? "AA" : "BW", | 32 fName.printf("lines_%g_%s", width, doAA ? "AA" : "BW"); |
39 type == SH ? "SH" : (type == SV ? "SV" : "RAND")); | |
40 | 33 |
41 SkRandom rand; | 34 SkRandom rand; |
42 for (int i = 0; i < LINES; ++i) { | 35 for (int i = 0; i < PTS; ++i) { |
43 fStartPts[i].set(rand.nextUScalar1() * 640, rand.nextUScalar1() * 48
0); | 36 fPts[i].set(rand.nextUScalar1() * 640, rand.nextUScalar1() * 480); |
44 if (type == SH) { | |
45 fEndPts[i].set(rand.nextUScalar1() * 640, fStartPts[i].y()); | |
46 } else if (type == SV) { | |
47 fEndPts[i].set(fStartPts[i].x(), rand.nextUScalar1() * 480); | |
48 } else { | |
49 fEndPts[i].set(rand.nextUScalar1() * 640, rand.nextUScalar1() *
480); | |
50 } | |
51 } | 37 } |
52 } | 38 } |
53 | 39 |
54 protected: | 40 protected: |
55 const char* onGetName() override { | 41 const char* onGetName() override { |
56 return fName.c_str(); | 42 return fName.c_str(); |
57 } | 43 } |
58 | 44 |
59 void onDraw(int loops, SkCanvas* canvas) override { | 45 void onDraw(int loops, SkCanvas* canvas) override { |
60 SkPaint paint; | 46 SkPaint paint; |
61 this->setupPaint(&paint); | 47 this->setupPaint(&paint); |
62 | 48 |
63 paint.setStyle(SkPaint::kStroke_Style); | 49 paint.setStyle(SkPaint::kStroke_Style); |
64 paint.setAntiAlias(fDoAA); | 50 paint.setAntiAlias(fDoAA); |
65 paint.setStrokeWidth(fStrokeWidth); | 51 paint.setStrokeWidth(fStrokeWidth); |
66 | 52 |
67 for (int i = 0; i < loops; i++) { | 53 for (int i = 0; i < loops; i++) { |
68 canvas->drawLine(fStartPts[i].x(), fStartPts[i].y(), fEndPts[i].x(),
fEndPts[i].y(), paint); | 54 canvas->drawPoints(SkCanvas::kLines_PointMode, PTS, fPts, paint); |
69 } | 55 } |
70 } | 56 } |
71 | 57 |
72 private: | 58 private: |
73 typedef Benchmark INHERITED; | 59 typedef Benchmark INHERITED; |
74 }; | 60 }; |
75 | 61 |
76 DEF_BENCH(return new LineBench(0, false, LineBench::SH);) | 62 DEF_BENCH(return new LineBench(0, false);) |
77 DEF_BENCH(return new LineBench(SK_Scalar1, false, LineBench::SH);) | 63 DEF_BENCH(return new LineBench(SK_Scalar1, false);) |
78 DEF_BENCH(return new LineBench(0, true, LineBench::SH);) | 64 DEF_BENCH(return new LineBench(0, true);) |
79 DEF_BENCH(return new LineBench(SK_Scalar1/2, true, LineBench::SH);) | 65 DEF_BENCH(return new LineBench(SK_Scalar1/2, true);) |
80 DEF_BENCH(return new LineBench(SK_Scalar1, true, LineBench::SH);) | 66 DEF_BENCH(return new LineBench(SK_Scalar1, true);) |
81 DEF_BENCH(return new LineBench(SK_Scalar1*10,true, LineBench::SH);) | |
82 DEF_BENCH(return new LineBench(0, false, LineBench::SV);) | |
83 DEF_BENCH(return new LineBench(SK_Scalar1, false, LineBench::SV);) | |
84 DEF_BENCH(return new LineBench(0, true, LineBench::SV);) | |
85 DEF_BENCH(return new LineBench(SK_Scalar1/2, true, LineBench::SV);) | |
86 DEF_BENCH(return new LineBench(SK_Scalar1, true, LineBench::SV);) | |
87 DEF_BENCH(return new LineBench(SK_Scalar1*10,true, LineBench::SV);) | |
88 DEF_BENCH(return new LineBench(0, false, LineBench::RAND);) | |
89 DEF_BENCH(return new LineBench(SK_Scalar1, false, LineBench::RAND);) | |
90 DEF_BENCH(return new LineBench(0, true, LineBench::RAND);) | |
91 DEF_BENCH(return new LineBench(SK_Scalar1/2, true, LineBench::RAND);) | |
92 DEF_BENCH(return new LineBench(SK_Scalar1, true, LineBench::RAND);) | |
93 DEF_BENCH(return new LineBench(SK_Scalar1*10,true, LineBench::RAND);) | |
OLD | NEW |