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 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 SkPoint center0, center1; | 95 SkPoint center0, center1; |
96 center0.set(SkScalarAve(pts[0].fX, pts[1].fX), | 96 center0.set(SkScalarAve(pts[0].fX, pts[1].fX), |
97 SkScalarAve(pts[0].fY, pts[1].fY)); | 97 SkScalarAve(pts[0].fY, pts[1].fY)); |
98 center1.set(SkScalarInterp(pts[0].fX, pts[1].fX, SkIntToScalar(3)/5), | 98 center1.set(SkScalarInterp(pts[0].fX, pts[1].fX, SkIntToScalar(3)/5), |
99 SkScalarInterp(pts[0].fY, pts[1].fY, SkIntToScalar(1)/4)); | 99 SkScalarInterp(pts[0].fY, pts[1].fY, SkIntToScalar(1)/4)); |
100 return SkGradientShader::CreateTwoPointConical(center1, (pts[1].fX - pts[0].
fX) / 7, | 100 return SkGradientShader::CreateTwoPointConical(center1, (pts[1].fX - pts[0].
fX) / 7, |
101 center0, (pts[1].fX - pts[0].
fX) / 2, | 101 center0, (pts[1].fX - pts[0].
fX) / 2, |
102 data.fColors, data.fPos, data
.fCount, tm, mapper); | 102 data.fColors, data.fPos, data
.fCount, tm, mapper); |
103 } | 103 } |
104 | 104 |
| 105 /// Ignores scale |
| 106 static SkShader* MakeConicalZeroRad(const SkPoint pts[2], const GradData& data, |
| 107 SkShader::TileMode tm, SkUnitMapper* mapper, |
| 108 float scale) { |
| 109 SkPoint center0, center1; |
| 110 center0.set(SkScalarAve(pts[0].fX, pts[1].fX), |
| 111 SkScalarAve(pts[0].fY, pts[1].fY)); |
| 112 center1.set(SkScalarInterp(pts[0].fX, pts[1].fX, SkIntToScalar(3)/5), |
| 113 SkScalarInterp(pts[0].fY, pts[1].fY, SkIntToScalar(1)/4)); |
| 114 return SkGradientShader::CreateTwoPointConical(center1, 0.0, |
| 115 center0, (pts[1].fX - pts[0].
fX) / 2, |
| 116 data.fColors, data.fPos, data
.fCount, tm, mapper); |
| 117 } |
| 118 |
| 119 /// Ignores scale |
| 120 static SkShader* MakeConicalOutside(const SkPoint pts[2], const GradData& data, |
| 121 SkShader::TileMode tm, SkUnitMapper* mapper, |
| 122 float scale) { |
| 123 SkPoint center0, center1; |
| 124 SkScalar radius0 = SkScalarDiv(pts[1].fX - pts[0].fX, 10); |
| 125 SkScalar radius1 = SkScalarDiv(pts[1].fX - pts[0].fX, 3); |
| 126 center0.set(pts[0].fX + radius0, pts[0].fY + radius0); |
| 127 center1.set(pts[1].fX - radius1, pts[1].fY - radius1); |
| 128 return SkGradientShader::CreateTwoPointConical(center0, radius0, |
| 129 center1, radius1, |
| 130 data.fColors, data.fPos, |
| 131 data.fCount, tm, mapper); |
| 132 } |
| 133 |
| 134 /// Ignores scale |
| 135 static SkShader* MakeConicalOutsideZeroRad(const SkPoint pts[2], const GradData&
data, |
| 136 SkShader::TileMode tm, SkUnitMapper*
mapper, |
| 137 float scale) { |
| 138 SkPoint center0, center1; |
| 139 SkScalar radius0 = SkScalarDiv(pts[1].fX - pts[0].fX, 10); |
| 140 SkScalar radius1 = SkScalarDiv(pts[1].fX - pts[0].fX, 3); |
| 141 center0.set(pts[0].fX + radius0, pts[0].fY + radius0); |
| 142 center1.set(pts[1].fX - radius1, pts[1].fY - radius1); |
| 143 return SkGradientShader::CreateTwoPointConical(center0, 0.0, |
| 144 center1, radius1, |
| 145 data.fColors, data.fPos, |
| 146 data.fCount, tm, mapper); |
| 147 } |
| 148 |
105 typedef SkShader* (*GradMaker)(const SkPoint pts[2], const GradData& data, | 149 typedef SkShader* (*GradMaker)(const SkPoint pts[2], const GradData& data, |
106 SkShader::TileMode tm, SkUnitMapper* mapper, | 150 SkShader::TileMode tm, SkUnitMapper* mapper, |
107 float scale); | 151 float scale); |
108 | 152 |
109 static const struct { | 153 static const struct { |
110 GradMaker fMaker; | 154 GradMaker fMaker; |
111 const char* fName; | 155 const char* fName; |
112 } gGrads[] = { | 156 } gGrads[] = { |
113 { MakeLinear, "linear" }, | 157 { MakeLinear, "linear" }, |
114 { MakeRadial, "radial1" }, | 158 { MakeRadial, "radial1" }, |
115 { MakeSweep, "sweep" }, | 159 { MakeSweep, "sweep" }, |
116 { Make2Radial, "radial2" }, | 160 { Make2Radial, "radial2" }, |
117 { MakeConical, "conical" }, | 161 { MakeConical, "conical" }, |
| 162 { MakeConicalZeroRad, "conicalZero" }, |
| 163 { MakeConicalOutside, "conicalOut" }, |
| 164 { MakeConicalOutsideZeroRad, "conicalOutZero" }, |
118 }; | 165 }; |
119 | 166 |
120 enum GradType { // these must match the order in gGrads | 167 enum GradType { // these must match the order in gGrads |
121 kLinear_GradType, | 168 kLinear_GradType, |
122 kRadial_GradType, | 169 kRadial_GradType, |
123 kSweep_GradType, | 170 kSweep_GradType, |
124 kRadial2_GradType, | 171 kRadial2_GradType, |
125 kConical_GradType | 172 kConical_GradType, |
| 173 kConicalZero_GradType, |
| 174 kConicalOut_GradType, |
| 175 kConicalOutZero_GradType |
126 }; | 176 }; |
127 | 177 |
128 enum GeomType { | 178 enum GeomType { |
129 kRect_GeomType, | 179 kRect_GeomType, |
130 kOval_GeomType | 180 kOval_GeomType |
131 }; | 181 }; |
132 | 182 |
133 static const char* tilemodename(SkShader::TileMode tm) { | 183 static const char* tilemodename(SkShader::TileMode tm) { |
134 switch (tm) { | 184 switch (tm) { |
135 case SkShader::kClamp_TileMode: | 185 case SkShader::kClamp_TileMode: |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
248 DEF_BENCH( return new GradientBench(kRadial_GradType, gGradData[0], SkShader::kR
epeat_TileMode); ) | 298 DEF_BENCH( return new GradientBench(kRadial_GradType, gGradData[0], SkShader::kR
epeat_TileMode); ) |
249 DEF_BENCH( return new GradientBench(kSweep_GradType); ) | 299 DEF_BENCH( return new GradientBench(kSweep_GradType); ) |
250 DEF_BENCH( return new GradientBench(kSweep_GradType, gGradData[1]); ) | 300 DEF_BENCH( return new GradientBench(kSweep_GradType, gGradData[1]); ) |
251 DEF_BENCH( return new GradientBench(kSweep_GradType, gGradData[2]); ) | 301 DEF_BENCH( return new GradientBench(kSweep_GradType, gGradData[2]); ) |
252 DEF_BENCH( return new GradientBench(kRadial2_GradType); ) | 302 DEF_BENCH( return new GradientBench(kRadial2_GradType); ) |
253 DEF_BENCH( return new GradientBench(kRadial2_GradType, gGradData[1]); ) | 303 DEF_BENCH( return new GradientBench(kRadial2_GradType, gGradData[1]); ) |
254 DEF_BENCH( return new GradientBench(kRadial2_GradType, gGradData[0], SkShader::k
Mirror_TileMode); ) | 304 DEF_BENCH( return new GradientBench(kRadial2_GradType, gGradData[0], SkShader::k
Mirror_TileMode); ) |
255 DEF_BENCH( return new GradientBench(kConical_GradType); ) | 305 DEF_BENCH( return new GradientBench(kConical_GradType); ) |
256 DEF_BENCH( return new GradientBench(kConical_GradType, gGradData[1]); ) | 306 DEF_BENCH( return new GradientBench(kConical_GradType, gGradData[1]); ) |
257 DEF_BENCH( return new GradientBench(kConical_GradType, gGradData[2]); ) | 307 DEF_BENCH( return new GradientBench(kConical_GradType, gGradData[2]); ) |
| 308 DEF_BENCH( return new GradientBench(kConicalZero_GradType); ) |
| 309 DEF_BENCH( return new GradientBench(kConicalZero_GradType, gGradData[1]); ) |
| 310 DEF_BENCH( return new GradientBench(kConicalZero_GradType, gGradData[2]); ) |
| 311 DEF_BENCH( return new GradientBench(kConicalOut_GradType); ) |
| 312 DEF_BENCH( return new GradientBench(kConicalOut_GradType, gGradData[1]); ) |
| 313 DEF_BENCH( return new GradientBench(kConicalOut_GradType, gGradData[2]); ) |
| 314 DEF_BENCH( return new GradientBench(kConicalOutZero_GradType); ) |
| 315 DEF_BENCH( return new GradientBench(kConicalOutZero_GradType, gGradData[1]); ) |
| 316 DEF_BENCH( return new GradientBench(kConicalOutZero_GradType, gGradData[2]); ) |
258 | 317 |
259 /////////////////////////////////////////////////////////////////////////////// | 318 /////////////////////////////////////////////////////////////////////////////// |
260 | 319 |
261 class Gradient2Bench : public SkBenchmark { | 320 class Gradient2Bench : public SkBenchmark { |
262 SkString fName; | 321 SkString fName; |
263 bool fHasAlpha; | 322 bool fHasAlpha; |
264 | 323 |
265 public: | 324 public: |
266 Gradient2Bench(bool hasAlpha) { | 325 Gradient2Bench(bool hasAlpha) { |
267 fName.printf("gradient_create_%s", hasAlpha ? "alpha" : "opaque"); | 326 fName.printf("gradient_create_%s", hasAlpha ? "alpha" : "opaque"); |
(...skipping 29 matching lines...) Expand all Loading... |
297 canvas->drawRect(r, paint); | 356 canvas->drawRect(r, paint); |
298 } | 357 } |
299 } | 358 } |
300 | 359 |
301 private: | 360 private: |
302 typedef SkBenchmark INHERITED; | 361 typedef SkBenchmark INHERITED; |
303 }; | 362 }; |
304 | 363 |
305 DEF_BENCH( return new Gradient2Bench(false); ) | 364 DEF_BENCH( return new Gradient2Bench(false); ) |
306 DEF_BENCH( return new Gradient2Bench(true); ) | 365 DEF_BENCH( return new Gradient2Bench(true); ) |
OLD | NEW |