OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 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 "SkCanvas.h" | 9 #include "SkCanvas.h" |
10 #include "SkPaint.h" | 10 #include "SkPaint.h" |
(...skipping 24 matching lines...) Expand all Loading... |
35 public: | 35 public: |
36 HairlinePathBench(Flags flags) : fFlags(flags) { | 36 HairlinePathBench(Flags flags) : fFlags(flags) { |
37 fPaint.setStyle(SkPaint::kStroke_Style); | 37 fPaint.setStyle(SkPaint::kStroke_Style); |
38 fPaint.setStrokeWidth(SkIntToScalar(0)); | 38 fPaint.setStrokeWidth(SkIntToScalar(0)); |
39 } | 39 } |
40 | 40 |
41 virtual void appendName(SkString*) = 0; | 41 virtual void appendName(SkString*) = 0; |
42 virtual void makePath(SkPath*) = 0; | 42 virtual void makePath(SkPath*) = 0; |
43 | 43 |
44 protected: | 44 protected: |
45 virtual const char* onGetName() SK_OVERRIDE { | 45 const char* onGetName() SK_OVERRIDE { |
46 fName.printf("path_hairline_%s_%s_", | 46 fName.printf("path_hairline_%s_%s_", |
47 fFlags & kBig_Flag ? "big" : "small", | 47 fFlags & kBig_Flag ? "big" : "small", |
48 fFlags & kAA_Flag ? "AA" : "noAA"); | 48 fFlags & kAA_Flag ? "AA" : "noAA"); |
49 this->appendName(&fName); | 49 this->appendName(&fName); |
50 return fName.c_str(); | 50 return fName.c_str(); |
51 } | 51 } |
52 | 52 |
53 virtual void onDraw(const int loops, SkCanvas* canvas) SK_OVERRIDE { | 53 void onDraw(const int loops, SkCanvas* canvas) SK_OVERRIDE { |
54 SkPaint paint(fPaint); | 54 SkPaint paint(fPaint); |
55 this->setupPaint(&paint); | 55 this->setupPaint(&paint); |
56 | 56 |
57 paint.setAntiAlias(fFlags & kAA_Flag ? true : false); | 57 paint.setAntiAlias(fFlags & kAA_Flag ? true : false); |
58 | 58 |
59 SkPath path; | 59 SkPath path; |
60 this->makePath(&path); | 60 this->makePath(&path); |
61 if (fFlags & kBig_Flag) { | 61 if (fFlags & kBig_Flag) { |
62 SkMatrix m; | 62 SkMatrix m; |
63 m.setScale(SkIntToScalar(3), SkIntToScalar(3)); | 63 m.setScale(SkIntToScalar(3), SkIntToScalar(3)); |
64 path.transform(m); | 64 path.transform(m); |
65 } | 65 } |
66 | 66 |
67 for (int i = 0; i < loops; i++) { | 67 for (int i = 0; i < loops; i++) { |
68 canvas->drawPath(path, paint); | 68 canvas->drawPath(path, paint); |
69 } | 69 } |
70 } | 70 } |
71 | 71 |
72 private: | 72 private: |
73 SkPaint fPaint; | 73 SkPaint fPaint; |
74 SkString fName; | 74 SkString fName; |
75 Flags fFlags; | 75 Flags fFlags; |
76 typedef Benchmark INHERITED; | 76 typedef Benchmark INHERITED; |
77 }; | 77 }; |
78 | 78 |
79 class LinePathBench : public HairlinePathBench { | 79 class LinePathBench : public HairlinePathBench { |
80 public: | 80 public: |
81 LinePathBench(Flags flags) : INHERITED(flags) {} | 81 LinePathBench(Flags flags) : INHERITED(flags) {} |
82 | 82 |
83 virtual void appendName(SkString* name) SK_OVERRIDE { | 83 void appendName(SkString* name) SK_OVERRIDE { |
84 name->append("line"); | 84 name->append("line"); |
85 } | 85 } |
86 virtual void makePath(SkPath* path) SK_OVERRIDE { | 86 void makePath(SkPath* path) SK_OVERRIDE { |
87 SkRandom rand; | 87 SkRandom rand; |
88 int size = SK_ARRAY_COUNT(points); | 88 int size = SK_ARRAY_COUNT(points); |
89 int hSize = size / 2; | 89 int hSize = size / 2; |
90 for (int i = 0; i < kMaxPathSize; ++i) { | 90 for (int i = 0; i < kMaxPathSize; ++i) { |
91 int xTrans = 10 + 40 * (i%(kMaxPathSize/2)); | 91 int xTrans = 10 + 40 * (i%(kMaxPathSize/2)); |
92 int yTrans = 0; | 92 int yTrans = 0; |
93 if (i > kMaxPathSize/2 - 1) { | 93 if (i > kMaxPathSize/2 - 1) { |
94 yTrans = 40; | 94 yTrans = 40; |
95 } | 95 } |
96 int base1 = 2 * rand.nextULessThan(hSize); | 96 int base1 = 2 * rand.nextULessThan(hSize); |
97 int base2 = 2 * rand.nextULessThan(hSize); | 97 int base2 = 2 * rand.nextULessThan(hSize); |
98 int base3 = 2 * rand.nextULessThan(hSize); | 98 int base3 = 2 * rand.nextULessThan(hSize); |
99 path->moveTo(SkIntToScalar(points[base1] + xTrans), | 99 path->moveTo(SkIntToScalar(points[base1] + xTrans), |
100 SkIntToScalar(points[base1+1] + yTrans)); | 100 SkIntToScalar(points[base1+1] + yTrans)); |
101 path->lineTo(SkIntToScalar(points[base2] + xTrans), | 101 path->lineTo(SkIntToScalar(points[base2] + xTrans), |
102 SkIntToScalar(points[base2+1] + yTrans)); | 102 SkIntToScalar(points[base2+1] + yTrans)); |
103 path->lineTo(SkIntToScalar(points[base3] + xTrans), | 103 path->lineTo(SkIntToScalar(points[base3] + xTrans), |
104 SkIntToScalar(points[base3+1] + yTrans)); | 104 SkIntToScalar(points[base3+1] + yTrans)); |
105 } | 105 } |
106 } | 106 } |
107 private: | 107 private: |
108 typedef HairlinePathBench INHERITED; | 108 typedef HairlinePathBench INHERITED; |
109 }; | 109 }; |
110 | 110 |
111 class QuadPathBench : public HairlinePathBench { | 111 class QuadPathBench : public HairlinePathBench { |
112 public: | 112 public: |
113 QuadPathBench(Flags flags) : INHERITED(flags) {} | 113 QuadPathBench(Flags flags) : INHERITED(flags) {} |
114 | 114 |
115 virtual void appendName(SkString* name) SK_OVERRIDE { | 115 void appendName(SkString* name) SK_OVERRIDE { |
116 name->append("quad"); | 116 name->append("quad"); |
117 } | 117 } |
118 virtual void makePath(SkPath* path) SK_OVERRIDE { | 118 void makePath(SkPath* path) SK_OVERRIDE { |
119 SkRandom rand; | 119 SkRandom rand; |
120 int size = SK_ARRAY_COUNT(points); | 120 int size = SK_ARRAY_COUNT(points); |
121 int hSize = size / 2; | 121 int hSize = size / 2; |
122 for (int i = 0; i < kMaxPathSize; ++i) { | 122 for (int i = 0; i < kMaxPathSize; ++i) { |
123 int xTrans = 10 + 40 * (i%(kMaxPathSize/2)); | 123 int xTrans = 10 + 40 * (i%(kMaxPathSize/2)); |
124 int yTrans = 0; | 124 int yTrans = 0; |
125 if (i > kMaxPathSize/2 - 1) { | 125 if (i > kMaxPathSize/2 - 1) { |
126 yTrans = 40; | 126 yTrans = 40; |
127 } | 127 } |
128 int base1 = 2 * rand.nextULessThan(hSize); | 128 int base1 = 2 * rand.nextULessThan(hSize); |
129 int base2 = 2 * rand.nextULessThan(hSize); | 129 int base2 = 2 * rand.nextULessThan(hSize); |
130 int base3 = 2 * rand.nextULessThan(hSize); | 130 int base3 = 2 * rand.nextULessThan(hSize); |
131 path->moveTo(SkIntToScalar(points[base1] + xTrans), | 131 path->moveTo(SkIntToScalar(points[base1] + xTrans), |
132 SkIntToScalar(points[base1+1] + yTrans)); | 132 SkIntToScalar(points[base1+1] + yTrans)); |
133 path->quadTo(SkIntToScalar(points[base2] + xTrans), | 133 path->quadTo(SkIntToScalar(points[base2] + xTrans), |
134 SkIntToScalar(points[base2+1] + yTrans), | 134 SkIntToScalar(points[base2+1] + yTrans), |
135 SkIntToScalar(points[base3] + xTrans), | 135 SkIntToScalar(points[base3] + xTrans), |
136 SkIntToScalar(points[base3+1] + yTrans)); | 136 SkIntToScalar(points[base3+1] + yTrans)); |
137 } | 137 } |
138 } | 138 } |
139 private: | 139 private: |
140 typedef HairlinePathBench INHERITED; | 140 typedef HairlinePathBench INHERITED; |
141 }; | 141 }; |
142 | 142 |
143 class ConicPathBench : public HairlinePathBench { | 143 class ConicPathBench : public HairlinePathBench { |
144 public: | 144 public: |
145 ConicPathBench(Flags flags) : INHERITED(flags) {} | 145 ConicPathBench(Flags flags) : INHERITED(flags) {} |
146 | 146 |
147 virtual void appendName(SkString* name) SK_OVERRIDE { | 147 void appendName(SkString* name) SK_OVERRIDE { |
148 name->append("conic"); | 148 name->append("conic"); |
149 } | 149 } |
150 virtual void makePath(SkPath* path) SK_OVERRIDE { | 150 void makePath(SkPath* path) SK_OVERRIDE { |
151 SkRandom rand; | 151 SkRandom rand; |
152 SkRandom randWeight; | 152 SkRandom randWeight; |
153 int size = SK_ARRAY_COUNT(points); | 153 int size = SK_ARRAY_COUNT(points); |
154 int hSize = size / 2; | 154 int hSize = size / 2; |
155 for (int i = 0; i < kMaxPathSize; ++i) { | 155 for (int i = 0; i < kMaxPathSize; ++i) { |
156 int xTrans = 10 + 40 * (i%(kMaxPathSize/2)); | 156 int xTrans = 10 + 40 * (i%(kMaxPathSize/2)); |
157 int yTrans = 0; | 157 int yTrans = 0; |
158 if (i > kMaxPathSize/2 - 1) { | 158 if (i > kMaxPathSize/2 - 1) { |
159 yTrans = 40; | 159 yTrans = 40; |
160 } | 160 } |
(...skipping 12 matching lines...) Expand all Loading... |
173 } | 173 } |
174 | 174 |
175 private: | 175 private: |
176 typedef HairlinePathBench INHERITED; | 176 typedef HairlinePathBench INHERITED; |
177 }; | 177 }; |
178 | 178 |
179 class CubicPathBench : public HairlinePathBench { | 179 class CubicPathBench : public HairlinePathBench { |
180 public: | 180 public: |
181 CubicPathBench(Flags flags) : INHERITED(flags) {} | 181 CubicPathBench(Flags flags) : INHERITED(flags) {} |
182 | 182 |
183 virtual void appendName(SkString* name) SK_OVERRIDE { | 183 void appendName(SkString* name) SK_OVERRIDE { |
184 name->append("cubic"); | 184 name->append("cubic"); |
185 } | 185 } |
186 virtual void makePath(SkPath* path) SK_OVERRIDE { | 186 void makePath(SkPath* path) SK_OVERRIDE { |
187 SkRandom rand; | 187 SkRandom rand; |
188 int size = SK_ARRAY_COUNT(points); | 188 int size = SK_ARRAY_COUNT(points); |
189 int hSize = size / 2; | 189 int hSize = size / 2; |
190 for (int i = 0; i < kMaxPathSize; ++i) { | 190 for (int i = 0; i < kMaxPathSize; ++i) { |
191 int xTrans = 10 + 40 * (i%(kMaxPathSize/2)); | 191 int xTrans = 10 + 40 * (i%(kMaxPathSize/2)); |
192 int yTrans = 0; | 192 int yTrans = 0; |
193 if (i > kMaxPathSize/2 - 1) { | 193 if (i > kMaxPathSize/2 - 1) { |
194 yTrans = 40; | 194 yTrans = 40; |
195 } | 195 } |
196 int base1 = 2 * rand.nextULessThan(hSize); | 196 int base1 = 2 * rand.nextULessThan(hSize); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
229 // Don't have default path renderer for conics yet on GPU, so must use AA | 229 // Don't have default path renderer for conics yet on GPU, so must use AA |
230 // DEF_BENCH( return new ConicPathBench(FLAGS00); ) | 230 // DEF_BENCH( return new ConicPathBench(FLAGS00); ) |
231 // DEF_BENCH( return new ConicPathBench(FLAGS01); ) | 231 // DEF_BENCH( return new ConicPathBench(FLAGS01); ) |
232 DEF_BENCH( return new ConicPathBench(FLAGS10); ) | 232 DEF_BENCH( return new ConicPathBench(FLAGS10); ) |
233 DEF_BENCH( return new ConicPathBench(FLAGS11); ) | 233 DEF_BENCH( return new ConicPathBench(FLAGS11); ) |
234 | 234 |
235 DEF_BENCH( return new CubicPathBench(FLAGS00); ) | 235 DEF_BENCH( return new CubicPathBench(FLAGS00); ) |
236 DEF_BENCH( return new CubicPathBench(FLAGS01); ) | 236 DEF_BENCH( return new CubicPathBench(FLAGS01); ) |
237 DEF_BENCH( return new CubicPathBench(FLAGS10); ) | 237 DEF_BENCH( return new CubicPathBench(FLAGS10); ) |
238 DEF_BENCH( return new CubicPathBench(FLAGS11); ) | 238 DEF_BENCH( return new CubicPathBench(FLAGS11); ) |
OLD | NEW |