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 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 data.fColors, data.fPos, data
.fCount, tm, mapper); | 102 data.fColors, data.fPos, data
.fCount, tm, mapper); |
103 } | 103 } |
104 | 104 |
105 typedef SkShader* (*GradMaker)(const SkPoint pts[2], const GradData& data, | 105 typedef SkShader* (*GradMaker)(const SkPoint pts[2], const GradData& data, |
106 SkShader::TileMode tm, SkUnitMapper* mapper, | 106 SkShader::TileMode tm, SkUnitMapper* mapper, |
107 float scale); | 107 float scale); |
108 | 108 |
109 static const struct { | 109 static const struct { |
110 GradMaker fMaker; | 110 GradMaker fMaker; |
111 const char* fName; | 111 const char* fName; |
112 int fRepeat; | |
113 } gGrads[] = { | 112 } gGrads[] = { |
114 { MakeLinear, "linear", 15 }, | 113 { MakeLinear, "linear" }, |
115 { MakeRadial, "radial1", 10 }, | 114 { MakeRadial, "radial1" }, |
116 { MakeSweep, "sweep", 1 }, | 115 { MakeSweep, "sweep" }, |
117 { Make2Radial, "radial2", 5 }, | 116 { Make2Radial, "radial2" }, |
118 { MakeConical, "conical", 5 }, | 117 { MakeConical, "conical" }, |
119 }; | 118 }; |
120 | 119 |
121 enum GradType { // these must match the order in gGrads | 120 enum GradType { // these must match the order in gGrads |
122 kLinear_GradType, | 121 kLinear_GradType, |
123 kRadial_GradType, | 122 kRadial_GradType, |
124 kSweep_GradType, | 123 kSweep_GradType, |
125 kRadial2_GradType, | 124 kRadial2_GradType, |
126 kConical_GradType | 125 kConical_GradType |
127 }; | 126 }; |
128 | 127 |
(...skipping 26 matching lines...) Expand all Loading... |
155 SkDEBUGFAIL("unknown geometry type"); | 154 SkDEBUGFAIL("unknown geometry type"); |
156 return "error"; | 155 return "error"; |
157 } | 156 } |
158 } | 157 } |
159 | 158 |
160 /////////////////////////////////////////////////////////////////////////////// | 159 /////////////////////////////////////////////////////////////////////////////// |
161 | 160 |
162 class GradientBench : public SkBenchmark { | 161 class GradientBench : public SkBenchmark { |
163 SkString fName; | 162 SkString fName; |
164 SkShader* fShader; | 163 SkShader* fShader; |
165 int fRepeat; | |
166 enum { | 164 enum { |
167 W = 400, | 165 W = 400, |
168 H = 400, | 166 H = 400, |
| 167 kRepeat = 15, |
169 }; | 168 }; |
170 public: | 169 public: |
171 GradientBench(GradType gradType, | 170 GradientBench(GradType gradType, |
172 GradData data = gGradData[0], | 171 GradData data = gGradData[0], |
173 SkShader::TileMode tm = SkShader::kClamp_TileMode, | 172 SkShader::TileMode tm = SkShader::kClamp_TileMode, |
174 GeomType geomType = kRect_GeomType, | 173 GeomType geomType = kRect_GeomType, |
175 float scale = 1.0f) { | 174 float scale = 1.0f) { |
176 fName.printf("gradient_%s_%s", gGrads[gradType].fName, | 175 fName.printf("gradient_%s_%s", gGrads[gradType].fName, |
177 tilemodename(tm)); | 176 tilemodename(tm)); |
178 if (geomType != kRect_GeomType) { | 177 if (geomType != kRect_GeomType) { |
179 fName.append("_"); | 178 fName.append("_"); |
180 fName.append(geomtypename(geomType)); | 179 fName.append(geomtypename(geomType)); |
181 } | 180 } |
182 | 181 |
183 if (scale != 1.f) { | 182 if (scale != 1.f) { |
184 fName.appendf("_scale_%g", scale); | 183 fName.appendf("_scale_%g", scale); |
185 } | 184 } |
186 | 185 |
187 fName.append(data.fName); | 186 fName.append(data.fName); |
188 | 187 |
189 const SkPoint pts[2] = { | 188 const SkPoint pts[2] = { |
190 { 0, 0 }, | 189 { 0, 0 }, |
191 { SkIntToScalar(W), SkIntToScalar(H) } | 190 { SkIntToScalar(W), SkIntToScalar(H) } |
192 }; | 191 }; |
193 | 192 |
194 fRepeat = gGrads[gradType].fRepeat; | |
195 fShader = gGrads[gradType].fMaker(pts, data, tm, NULL, scale); | 193 fShader = gGrads[gradType].fMaker(pts, data, tm, NULL, scale); |
196 fGeomType = geomType; | 194 fGeomType = geomType; |
197 } | 195 } |
198 | 196 |
199 virtual ~GradientBench() { | 197 virtual ~GradientBench() { |
200 fShader->unref(); | 198 fShader->unref(); |
201 } | 199 } |
202 | 200 |
203 protected: | 201 protected: |
204 virtual const char* onGetName() { | 202 virtual const char* onGetName() { |
205 return fName.c_str(); | 203 return fName.c_str(); |
206 } | 204 } |
207 | 205 |
208 virtual void onDraw(SkCanvas* canvas) { | 206 virtual void onDraw(SkCanvas* canvas) { |
209 SkPaint paint; | 207 SkPaint paint; |
210 this->setupPaint(&paint); | 208 this->setupPaint(&paint); |
211 | 209 |
212 paint.setShader(fShader); | 210 paint.setShader(fShader); |
213 | 211 |
214 SkRect r = { 0, 0, SkIntToScalar(W), SkIntToScalar(H) }; | 212 SkRect r = { 0, 0, SkIntToScalar(W), SkIntToScalar(H) }; |
215 for (int i = 0; i < this->getLoops() * fRepeat; i++) { | 213 for (int i = 0; i < this->getLoops() * kRepeat; i++) { |
216 switch (fGeomType) { | 214 switch (fGeomType) { |
217 case kRect_GeomType: | 215 case kRect_GeomType: |
218 canvas->drawRect(r, paint); | 216 canvas->drawRect(r, paint); |
219 break; | 217 break; |
220 case kOval_GeomType: | 218 case kOval_GeomType: |
221 canvas->drawOval(r, paint); | 219 canvas->drawOval(r, paint); |
222 break; | 220 break; |
223 } | 221 } |
224 } | 222 } |
225 } | 223 } |
226 | 224 |
227 private: | 225 private: |
228 typedef SkBenchmark INHERITED; | 226 typedef SkBenchmark INHERITED; |
229 | 227 |
230 GeomType fGeomType; | 228 GeomType fGeomType; |
231 }; | 229 }; |
232 | 230 |
| 231 DEF_BENCH( return new GradientBench(kLinear_GradType); ) |
| 232 DEF_BENCH( return new GradientBench(kLinear_GradType, gGradData[1]); ) |
| 233 DEF_BENCH( return new GradientBench(kLinear_GradType, gGradData[2]); ) |
| 234 DEF_BENCH( return new GradientBench(kLinear_GradType, gGradData[0], SkShader::kM
irror_TileMode); ) |
| 235 |
| 236 DEF_BENCH( return new GradientBench(kRadial_GradType, gGradData[0]); ) |
| 237 DEF_BENCH( return new GradientBench(kRadial_GradType, gGradData[1]); ) |
| 238 DEF_BENCH( return new GradientBench(kRadial_GradType, gGradData[2]); ) |
| 239 // Draw a radial gradient of radius 1/2 on a rectangle; half the lines should |
| 240 // be completely pinned, the other half should pe partially pinned |
| 241 DEF_BENCH( return new GradientBench(kRadial_GradType, gGradData[0], SkShader::kC
lamp_TileMode, kRect_GeomType, 0.5f); ) |
| 242 |
| 243 // Draw a radial gradient on a circle of equal size; all the lines should |
| 244 // hit the unpinned fast path (so long as GradientBench.W == H) |
| 245 DEF_BENCH( return new GradientBench(kRadial_GradType, gGradData[0], SkShader::kC
lamp_TileMode, kOval_GeomType); ) |
| 246 |
| 247 DEF_BENCH( return new GradientBench(kRadial_GradType, gGradData[0], SkShader::kM
irror_TileMode); ) |
| 248 DEF_BENCH( return new GradientBench(kSweep_GradType); ) |
| 249 DEF_BENCH( return new GradientBench(kSweep_GradType, gGradData[1]); ) |
| 250 DEF_BENCH( return new GradientBench(kSweep_GradType, gGradData[2]); ) |
| 251 DEF_BENCH( return new GradientBench(kRadial2_GradType); ) |
| 252 DEF_BENCH( return new GradientBench(kRadial2_GradType, gGradData[1]); ) |
| 253 DEF_BENCH( return new GradientBench(kRadial2_GradType, gGradData[0], SkShader::k
Mirror_TileMode); ) |
| 254 DEF_BENCH( return new GradientBench(kConical_GradType); ) |
| 255 DEF_BENCH( return new GradientBench(kConical_GradType, gGradData[1]); ) |
| 256 DEF_BENCH( return new GradientBench(kConical_GradType, gGradData[2]); ) |
| 257 |
| 258 /////////////////////////////////////////////////////////////////////////////// |
| 259 |
233 class Gradient2Bench : public SkBenchmark { | 260 class Gradient2Bench : public SkBenchmark { |
234 SkString fName; | 261 SkString fName; |
235 bool fHasAlpha; | 262 bool fHasAlpha; |
236 | 263 |
237 public: | 264 public: |
238 Gradient2Bench(bool hasAlpha) { | 265 Gradient2Bench(bool hasAlpha) { |
239 fName.printf("gradient_create_%s", hasAlpha ? "alpha" : "opaque"); | 266 fName.printf("gradient_create_%s", hasAlpha ? "alpha" : "opaque"); |
240 fHasAlpha = hasAlpha; | 267 fHasAlpha = hasAlpha; |
241 } | 268 } |
242 | 269 |
(...skipping 24 matching lines...) Expand all Loading... |
267 SkShader::kClamp_TileMo
de); | 294 SkShader::kClamp_TileMo
de); |
268 paint.setShader(s)->unref(); | 295 paint.setShader(s)->unref(); |
269 canvas->drawRect(r, paint); | 296 canvas->drawRect(r, paint); |
270 } | 297 } |
271 } | 298 } |
272 | 299 |
273 private: | 300 private: |
274 typedef SkBenchmark INHERITED; | 301 typedef SkBenchmark INHERITED; |
275 }; | 302 }; |
276 | 303 |
277 DEF_BENCH( return new GradientBench(kLinear_GradType); ) | |
278 DEF_BENCH( return new GradientBench(kLinear_GradType, gGradData[1]); ) | |
279 DEF_BENCH( return new GradientBench(kLinear_GradType, gGradData[2]); ) | |
280 DEF_BENCH( return new GradientBench(kLinear_GradType, gGradData[0], SkShader::kM
irror_TileMode); ) | |
281 | |
282 | |
283 DEF_BENCH( return new GradientBench(kRadial_GradType, gGradData[0]); ) | |
284 DEF_BENCH( return new GradientBench(kRadial_GradType, gGradData[1]); ) | |
285 DEF_BENCH( return new GradientBench(kRadial_GradType, gGradData[2]); ) | |
286 // Draw a radial gradient of radius 1/2 on a rectangle; half the lines should | |
287 // be completely pinned, the other half should pe partially pinned | |
288 DEF_BENCH( return new GradientBench(kRadial_GradType, gGradData[0], SkShader::kC
lamp_TileMode, kRect_GeomType, 0.5f); ) | |
289 | |
290 // Draw a radial gradient on a circle of equal size; all the lines should | |
291 // hit the unpinned fast path (so long as GradientBench.W == H) | |
292 DEF_BENCH( return new GradientBench(kRadial_GradType, gGradData[0], SkShader::kC
lamp_TileMode, kOval_GeomType); ) | |
293 | |
294 DEF_BENCH( return new GradientBench(kRadial_GradType, gGradData[0], SkShader::kM
irror_TileMode); ) | |
295 DEF_BENCH( return new GradientBench(kSweep_GradType); ) | |
296 DEF_BENCH( return new GradientBench(kSweep_GradType, gGradData[1]); ) | |
297 DEF_BENCH( return new GradientBench(kSweep_GradType, gGradData[2]); ) | |
298 DEF_BENCH( return new GradientBench(kRadial2_GradType); ) | |
299 DEF_BENCH( return new GradientBench(kRadial2_GradType, gGradData[1]); ) | |
300 DEF_BENCH( return new GradientBench(kRadial2_GradType, gGradData[0], SkShader::k
Mirror_TileMode); ) | |
301 DEF_BENCH( return new GradientBench(kConical_GradType); ) | |
302 DEF_BENCH( return new GradientBench(kConical_GradType, gGradData[1]); ) | |
303 DEF_BENCH( return new GradientBench(kConical_GradType, gGradData[2]); ) | |
304 | |
305 DEF_BENCH( return new Gradient2Bench(false); ) | 304 DEF_BENCH( return new Gradient2Bench(false); ) |
306 DEF_BENCH( return new Gradient2Bench(true); ) | 305 DEF_BENCH( return new Gradient2Bench(true); ) |
OLD | NEW |