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 17 matching lines...) Expand all Loading... |
28 SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE, SK_ColorWHITE, SK_ColorBLACK, | 28 SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE, SK_ColorWHITE, SK_ColorBLACK, |
29 SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE, SK_ColorWHITE, SK_ColorBLACK, | 29 SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE, SK_ColorWHITE, SK_ColorBLACK, |
30 SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE, SK_ColorWHITE, SK_ColorBLACK, | 30 SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE, SK_ColorWHITE, SK_ColorBLACK, |
31 SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE, SK_ColorWHITE, SK_ColorBLACK, | 31 SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE, SK_ColorWHITE, SK_ColorBLACK, |
32 SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE, SK_ColorWHITE, SK_ColorBLACK, | 32 SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE, SK_ColorWHITE, SK_ColorBLACK, |
33 SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE, SK_ColorWHITE, SK_ColorBLACK, | 33 SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE, SK_ColorWHITE, SK_ColorBLACK, |
34 SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE, SK_ColorWHITE, SK_ColorBLACK, | 34 SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE, SK_ColorWHITE, SK_ColorBLACK, |
35 SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE, SK_ColorWHITE, SK_ColorBLACK, // 1
0 lines, 50 colors | 35 SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE, SK_ColorWHITE, SK_ColorBLACK, // 1
0 lines, 50 colors |
36 }; | 36 }; |
37 | 37 |
| 38 // We have several special-cases depending on the number (and spacing) of colors
, so |
| 39 // try to exercise those here. |
38 static const GradData gGradData[] = { | 40 static const GradData gGradData[] = { |
39 { 2, gColors, NULL, "" }, | 41 { 2, gColors, NULL, "" }, |
40 { 50, gColors, NULL, "_hicolor" }, // many color gradient | 42 { 50, gColors, NULL, "_hicolor" }, // many color gradient |
| 43 { 3, gColors, NULL, "_3color" }, |
41 }; | 44 }; |
42 | 45 |
43 /// Ignores scale | 46 /// Ignores scale |
44 static SkShader* MakeLinear(const SkPoint pts[2], const GradData& data, | 47 static SkShader* MakeLinear(const SkPoint pts[2], const GradData& data, |
45 SkShader::TileMode tm, SkUnitMapper* mapper, | 48 SkShader::TileMode tm, SkUnitMapper* mapper, |
46 float scale) { | 49 float scale) { |
47 return SkGradientShader::CreateLinear(pts, data.fColors, data.fPos, | 50 return SkGradientShader::CreateLinear(pts, data.fColors, data.fPos, |
48 data.fCount, tm, mapper); | 51 data.fCount, tm, mapper); |
49 } | 52 } |
50 | 53 |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 enum { | 165 enum { |
163 W = 400, | 166 W = 400, |
164 H = 400, | 167 H = 400, |
165 kRepeat = 15, | 168 kRepeat = 15, |
166 }; | 169 }; |
167 public: | 170 public: |
168 GradientBench(GradType gradType, | 171 GradientBench(GradType gradType, |
169 GradData data = gGradData[0], | 172 GradData data = gGradData[0], |
170 SkShader::TileMode tm = SkShader::kClamp_TileMode, | 173 SkShader::TileMode tm = SkShader::kClamp_TileMode, |
171 GeomType geomType = kRect_GeomType, | 174 GeomType geomType = kRect_GeomType, |
172 float scale = 1.0f | 175 float scale = 1.0f) { |
173 ) | |
174 { | |
175 fName.printf("gradient_%s_%s", gGrads[gradType].fName, | 176 fName.printf("gradient_%s_%s", gGrads[gradType].fName, |
176 tilemodename(tm)); | 177 tilemodename(tm)); |
177 if (geomType != kRect_GeomType) { | 178 if (geomType != kRect_GeomType) { |
178 fName.append("_"); | 179 fName.append("_"); |
179 fName.append(geomtypename(geomType)); | 180 fName.append(geomtypename(geomType)); |
180 } | 181 } |
181 | 182 |
| 183 if (scale != 1.f) { |
| 184 fName.appendf("_scale_%g", scale); |
| 185 } |
| 186 |
182 fName.append(data.fName); | 187 fName.append(data.fName); |
183 | 188 |
184 const SkPoint pts[2] = { | 189 const SkPoint pts[2] = { |
185 { 0, 0 }, | 190 { 0, 0 }, |
186 { SkIntToScalar(W), SkIntToScalar(H) } | 191 { SkIntToScalar(W), SkIntToScalar(H) } |
187 }; | 192 }; |
188 | 193 |
189 fShader = gGrads[gradType].fMaker(pts, data, tm, NULL, scale); | 194 fShader = gGrads[gradType].fMaker(pts, data, tm, NULL, scale); |
190 fGeomType = geomType; | 195 fGeomType = geomType; |
191 } | 196 } |
(...skipping 27 matching lines...) Expand all Loading... |
219 } | 224 } |
220 | 225 |
221 private: | 226 private: |
222 typedef SkBenchmark INHERITED; | 227 typedef SkBenchmark INHERITED; |
223 | 228 |
224 GeomType fGeomType; | 229 GeomType fGeomType; |
225 }; | 230 }; |
226 | 231 |
227 DEF_BENCH( return new GradientBench(kLinear_GradType); ) | 232 DEF_BENCH( return new GradientBench(kLinear_GradType); ) |
228 DEF_BENCH( return new GradientBench(kLinear_GradType, gGradData[1]); ) | 233 DEF_BENCH( return new GradientBench(kLinear_GradType, gGradData[1]); ) |
| 234 DEF_BENCH( return new GradientBench(kLinear_GradType, gGradData[2]); ) |
229 DEF_BENCH( return new GradientBench(kLinear_GradType, gGradData[0], SkShader::kM
irror_TileMode); ) | 235 DEF_BENCH( return new GradientBench(kLinear_GradType, gGradData[0], SkShader::kM
irror_TileMode); ) |
230 | 236 |
| 237 |
| 238 DEF_BENCH( return new GradientBench(kRadial_GradType, gGradData[0]); ) |
| 239 DEF_BENCH( return new GradientBench(kRadial_GradType, gGradData[1]); ) |
| 240 DEF_BENCH( return new GradientBench(kRadial_GradType, gGradData[2]); ) |
231 // Draw a radial gradient of radius 1/2 on a rectangle; half the lines should | 241 // Draw a radial gradient of radius 1/2 on a rectangle; half the lines should |
232 // be completely pinned, the other half should pe partially pinned | 242 // be completely pinned, the other half should pe partially pinned |
233 DEF_BENCH( return new GradientBench(kRadial_GradType, gGradData[0], SkShader::kC
lamp_TileMode, kRect_GeomType, 0.5f); ) | 243 DEF_BENCH( return new GradientBench(kRadial_GradType, gGradData[0], SkShader::kC
lamp_TileMode, kRect_GeomType, 0.5f); ) |
234 | 244 |
235 // Draw a radial gradient on a circle of equal size; all the lines should | 245 // Draw a radial gradient on a circle of equal size; all the lines should |
236 // hit the unpinned fast path (so long as GradientBench.W == H) | 246 // hit the unpinned fast path (so long as GradientBench.W == H) |
237 DEF_BENCH( return new GradientBench(kRadial_GradType, gGradData[0], SkShader::kC
lamp_TileMode, kOval_GeomType); ) | 247 DEF_BENCH( return new GradientBench(kRadial_GradType, gGradData[0], SkShader::kC
lamp_TileMode, kOval_GeomType); ) |
238 | 248 |
239 DEF_BENCH( return new GradientBench(kRadial_GradType, gGradData[0], SkShader::kM
irror_TileMode); ) | 249 DEF_BENCH( return new GradientBench(kRadial_GradType, gGradData[0], SkShader::kM
irror_TileMode); ) |
240 DEF_BENCH( return new GradientBench(kSweep_GradType); ) | 250 DEF_BENCH( return new GradientBench(kSweep_GradType); ) |
241 DEF_BENCH( return new GradientBench(kSweep_GradType, gGradData[1]); ) | 251 DEF_BENCH( return new GradientBench(kSweep_GradType, gGradData[1]); ) |
| 252 DEF_BENCH( return new GradientBench(kSweep_GradType, gGradData[2]); ) |
242 DEF_BENCH( return new GradientBench(kRadial2_GradType); ) | 253 DEF_BENCH( return new GradientBench(kRadial2_GradType); ) |
243 DEF_BENCH( return new GradientBench(kRadial2_GradType, gGradData[1]); ) | 254 DEF_BENCH( return new GradientBench(kRadial2_GradType, gGradData[1]); ) |
244 DEF_BENCH( return new GradientBench(kRadial2_GradType, gGradData[0], SkShader::k
Mirror_TileMode); ) | 255 DEF_BENCH( return new GradientBench(kRadial2_GradType, gGradData[0], SkShader::k
Mirror_TileMode); ) |
245 DEF_BENCH( return new GradientBench(kConical_GradType); ) | 256 DEF_BENCH( return new GradientBench(kConical_GradType); ) |
246 DEF_BENCH( return new GradientBench(kConical_GradType, gGradData[1]); ) | 257 DEF_BENCH( return new GradientBench(kConical_GradType, gGradData[1]); ) |
| 258 DEF_BENCH( return new GradientBench(kConical_GradType, gGradData[2]); ) |
247 | 259 |
248 /////////////////////////////////////////////////////////////////////////////// | 260 /////////////////////////////////////////////////////////////////////////////// |
249 | 261 |
250 class Gradient2Bench : public SkBenchmark { | 262 class Gradient2Bench : public SkBenchmark { |
251 SkString fName; | 263 SkString fName; |
252 bool fHasAlpha; | 264 bool fHasAlpha; |
253 | 265 |
254 public: | 266 public: |
255 Gradient2Bench(bool hasAlpha) { | 267 Gradient2Bench(bool hasAlpha) { |
256 fName.printf("gradient_create_%s", hasAlpha ? "alpha" : "opaque"); | 268 fName.printf("gradient_create_%s", hasAlpha ? "alpha" : "opaque"); |
(...skipping 29 matching lines...) Expand all Loading... |
286 canvas->drawRect(r, paint); | 298 canvas->drawRect(r, paint); |
287 } | 299 } |
288 } | 300 } |
289 | 301 |
290 private: | 302 private: |
291 typedef SkBenchmark INHERITED; | 303 typedef SkBenchmark INHERITED; |
292 }; | 304 }; |
293 | 305 |
294 DEF_BENCH( return new Gradient2Bench(false); ) | 306 DEF_BENCH( return new Gradient2Bench(false); ) |
295 DEF_BENCH( return new Gradient2Bench(true); ) | 307 DEF_BENCH( return new Gradient2Bench(true); ) |
OLD | NEW |