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