epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 1 | |
| 2 | /* |
| 3 | * Copyright 2011 Google Inc. |
| 4 | * |
| 5 | * Use of this source code is governed by a BSD-style license that can be |
| 6 | * found in the LICENSE file. |
| 7 | */ |
reed@google.com | 84e9c08 | 2011-04-13 17:44:24 +0000 | [diff] [blame] | 8 | #include "SkBenchmark.h" |
| 9 | #include "SkBitmap.h" |
| 10 | #include "SkCanvas.h" |
| 11 | #include "SkColorPriv.h" |
| 12 | #include "SkGradientShader.h" |
| 13 | #include "SkPaint.h" |
| 14 | #include "SkShader.h" |
| 15 | #include "SkString.h" |
reed@google.com | 84e9c08 | 2011-04-13 17:44:24 +0000 | [diff] [blame] | 16 | |
| 17 | struct GradData { |
| 18 | int fCount; |
| 19 | const SkColor* fColors; |
| 20 | const SkScalar* fPos; |
commit-bot@chromium.org | 5396a04 | 2013-07-10 16:13:14 +0000 | [diff] [blame] | 21 | const char* fName; |
reed@google.com | 84e9c08 | 2011-04-13 17:44:24 +0000 | [diff] [blame] | 22 | }; |
| 23 | |
| 24 | static const SkColor gColors[] = { |
commit-bot@chromium.org | b686539 | 2013-07-09 19:43:29 +0000 | [diff] [blame] | 25 | SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE, SK_ColorWHITE, SK_ColorBLACK, |
commit-bot@chromium.org | 5396a04 | 2013-07-10 16:13:14 +0000 | [diff] [blame] | 26 | SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE, SK_ColorWHITE, SK_ColorBLACK, |
| 27 | 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, |
| 30 | 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, |
| 33 | SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE, SK_ColorWHITE, SK_ColorBLACK, |
| 34 | SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE, SK_ColorWHITE, SK_ColorBLACK, // 10 lines, 50 colors |
reed@google.com | 84e9c08 | 2011-04-13 17:44:24 +0000 | [diff] [blame] | 35 | }; |
| 36 | |
commit-bot@chromium.org | 3400f4b | 2013-09-30 19:41:09 +0000 | [diff] [blame] | 37 | // We have several special-cases depending on the number (and spacing) of colors, so |
| 38 | // try to exercise those here. |
reed@google.com | 84e9c08 | 2011-04-13 17:44:24 +0000 | [diff] [blame] | 39 | static const GradData gGradData[] = { |
commit-bot@chromium.org | 5396a04 | 2013-07-10 16:13:14 +0000 | [diff] [blame] | 40 | { 2, gColors, NULL, "" }, |
| 41 | { 50, gColors, NULL, "_hicolor" }, // many color gradient |
commit-bot@chromium.org | 3400f4b | 2013-09-30 19:41:09 +0000 | [diff] [blame] | 42 | { 3, gColors, NULL, "_3color" }, |
reed@google.com | 84e9c08 | 2011-04-13 17:44:24 +0000 | [diff] [blame] | 43 | }; |
| 44 | |
tomhudson@google.com | 5ea050f | 2011-09-26 15:03:55 +0000 | [diff] [blame] | 45 | /// Ignores scale |
reed@google.com | 84e9c08 | 2011-04-13 17:44:24 +0000 | [diff] [blame] | 46 | static SkShader* MakeLinear(const SkPoint pts[2], const GradData& data, |
commit-bot@chromium.org | 83f23d8 | 2014-05-22 12:27:41 +0000 | [diff] [blame] | 47 | SkShader::TileMode tm, float scale) { |
| 48 | return SkGradientShader::CreateLinear(pts, data.fColors, data.fPos, data.fCount, tm); |
reed@google.com | 84e9c08 | 2011-04-13 17:44:24 +0000 | [diff] [blame] | 49 | } |
| 50 | |
| 51 | static SkShader* MakeRadial(const SkPoint pts[2], const GradData& data, |
commit-bot@chromium.org | 83f23d8 | 2014-05-22 12:27:41 +0000 | [diff] [blame] | 52 | SkShader::TileMode tm, float scale) { |
reed@google.com | 84e9c08 | 2011-04-13 17:44:24 +0000 | [diff] [blame] | 53 | SkPoint center; |
| 54 | center.set(SkScalarAve(pts[0].fX, pts[1].fX), |
| 55 | SkScalarAve(pts[0].fY, pts[1].fY)); |
tomhudson@google.com | 5ea050f | 2011-09-26 15:03:55 +0000 | [diff] [blame] | 56 | return SkGradientShader::CreateRadial(center, center.fX * scale, |
| 57 | data.fColors, |
commit-bot@chromium.org | 83f23d8 | 2014-05-22 12:27:41 +0000 | [diff] [blame] | 58 | data.fPos, data.fCount, tm); |
reed@google.com | 84e9c08 | 2011-04-13 17:44:24 +0000 | [diff] [blame] | 59 | } |
| 60 | |
tomhudson@google.com | 5ea050f | 2011-09-26 15:03:55 +0000 | [diff] [blame] | 61 | /// Ignores scale |
reed@google.com | 84e9c08 | 2011-04-13 17:44:24 +0000 | [diff] [blame] | 62 | static SkShader* MakeSweep(const SkPoint pts[2], const GradData& data, |
commit-bot@chromium.org | 83f23d8 | 2014-05-22 12:27:41 +0000 | [diff] [blame] | 63 | SkShader::TileMode tm, float scale) { |
reed@google.com | 84e9c08 | 2011-04-13 17:44:24 +0000 | [diff] [blame] | 64 | SkPoint center; |
| 65 | center.set(SkScalarAve(pts[0].fX, pts[1].fX), |
| 66 | SkScalarAve(pts[0].fY, pts[1].fY)); |
| 67 | return SkGradientShader::CreateSweep(center.fX, center.fY, data.fColors, |
commit-bot@chromium.org | 83f23d8 | 2014-05-22 12:27:41 +0000 | [diff] [blame] | 68 | data.fPos, data.fCount); |
reed@google.com | 84e9c08 | 2011-04-13 17:44:24 +0000 | [diff] [blame] | 69 | } |
| 70 | |
tomhudson@google.com | 5ea050f | 2011-09-26 15:03:55 +0000 | [diff] [blame] | 71 | /// Ignores scale |
reed@google.com | 84e9c08 | 2011-04-13 17:44:24 +0000 | [diff] [blame] | 72 | static SkShader* Make2Radial(const SkPoint pts[2], const GradData& data, |
commit-bot@chromium.org | 83f23d8 | 2014-05-22 12:27:41 +0000 | [diff] [blame] | 73 | SkShader::TileMode tm, float scale) { |
reed@google.com | 84e9c08 | 2011-04-13 17:44:24 +0000 | [diff] [blame] | 74 | SkPoint center0, center1; |
| 75 | center0.set(SkScalarAve(pts[0].fX, pts[1].fX), |
| 76 | SkScalarAve(pts[0].fY, pts[1].fY)); |
| 77 | center1.set(SkScalarInterp(pts[0].fX, pts[1].fX, SkIntToScalar(3)/5), |
| 78 | SkScalarInterp(pts[0].fY, pts[1].fY, SkIntToScalar(1)/4)); |
| 79 | return SkGradientShader::CreateTwoPointRadial( |
reed@google.com | 258e0bf | 2012-06-07 14:18:34 +0000 | [diff] [blame] | 80 | center1, (pts[1].fX - pts[0].fX) / 7, |
| 81 | center0, (pts[1].fX - pts[0].fX) / 2, |
commit-bot@chromium.org | 83f23d8 | 2014-05-22 12:27:41 +0000 | [diff] [blame] | 82 | data.fColors, data.fPos, data.fCount, tm); |
reed@google.com | 258e0bf | 2012-06-07 14:18:34 +0000 | [diff] [blame] | 83 | } |
| 84 | |
| 85 | /// Ignores scale |
| 86 | static SkShader* MakeConical(const SkPoint pts[2], const GradData& data, |
commit-bot@chromium.org | 83f23d8 | 2014-05-22 12:27:41 +0000 | [diff] [blame] | 87 | SkShader::TileMode tm, float scale) { |
reed@google.com | 258e0bf | 2012-06-07 14:18:34 +0000 | [diff] [blame] | 88 | SkPoint center0, center1; |
| 89 | center0.set(SkScalarAve(pts[0].fX, pts[1].fX), |
| 90 | SkScalarAve(pts[0].fY, pts[1].fY)); |
| 91 | center1.set(SkScalarInterp(pts[0].fX, pts[1].fX, SkIntToScalar(3)/5), |
| 92 | SkScalarInterp(pts[0].fY, pts[1].fY, SkIntToScalar(1)/4)); |
| 93 | return SkGradientShader::CreateTwoPointConical(center1, (pts[1].fX - pts[0].fX) / 7, |
| 94 | center0, (pts[1].fX - pts[0].fX) / 2, |
commit-bot@chromium.org | 83f23d8 | 2014-05-22 12:27:41 +0000 | [diff] [blame] | 95 | data.fColors, data.fPos, data.fCount, tm); |
reed@google.com | 84e9c08 | 2011-04-13 17:44:24 +0000 | [diff] [blame] | 96 | } |
| 97 | |
commit-bot@chromium.org | 95f7926 | 2014-04-14 16:02:31 +0000 | [diff] [blame] | 98 | /// Ignores scale |
| 99 | static SkShader* MakeConicalZeroRad(const SkPoint pts[2], const GradData& data, |
commit-bot@chromium.org | 83f23d8 | 2014-05-22 12:27:41 +0000 | [diff] [blame] | 100 | SkShader::TileMode tm, float scale) { |
commit-bot@chromium.org | 95f7926 | 2014-04-14 16:02:31 +0000 | [diff] [blame] | 101 | SkPoint center0, center1; |
| 102 | center0.set(SkScalarAve(pts[0].fX, pts[1].fX), |
| 103 | SkScalarAve(pts[0].fY, pts[1].fY)); |
| 104 | center1.set(SkScalarInterp(pts[0].fX, pts[1].fX, SkIntToScalar(3)/5), |
| 105 | SkScalarInterp(pts[0].fY, pts[1].fY, SkIntToScalar(1)/4)); |
| 106 | return SkGradientShader::CreateTwoPointConical(center1, 0.0, |
| 107 | center0, (pts[1].fX - pts[0].fX) / 2, |
commit-bot@chromium.org | 83f23d8 | 2014-05-22 12:27:41 +0000 | [diff] [blame] | 108 | data.fColors, data.fPos, data.fCount, tm); |
commit-bot@chromium.org | 95f7926 | 2014-04-14 16:02:31 +0000 | [diff] [blame] | 109 | } |
| 110 | |
| 111 | /// Ignores scale |
| 112 | static SkShader* MakeConicalOutside(const SkPoint pts[2], const GradData& data, |
commit-bot@chromium.org | 83f23d8 | 2014-05-22 12:27:41 +0000 | [diff] [blame] | 113 | SkShader::TileMode tm, float scale) { |
commit-bot@chromium.org | 95f7926 | 2014-04-14 16:02:31 +0000 | [diff] [blame] | 114 | SkPoint center0, center1; |
| 115 | SkScalar radius0 = SkScalarDiv(pts[1].fX - pts[0].fX, 10); |
| 116 | SkScalar radius1 = SkScalarDiv(pts[1].fX - pts[0].fX, 3); |
| 117 | center0.set(pts[0].fX + radius0, pts[0].fY + radius0); |
| 118 | center1.set(pts[1].fX - radius1, pts[1].fY - radius1); |
| 119 | return SkGradientShader::CreateTwoPointConical(center0, radius0, |
| 120 | center1, radius1, |
| 121 | data.fColors, data.fPos, |
commit-bot@chromium.org | 83f23d8 | 2014-05-22 12:27:41 +0000 | [diff] [blame] | 122 | data.fCount, tm); |
commit-bot@chromium.org | 95f7926 | 2014-04-14 16:02:31 +0000 | [diff] [blame] | 123 | } |
| 124 | |
| 125 | /// Ignores scale |
| 126 | static SkShader* MakeConicalOutsideZeroRad(const SkPoint pts[2], const GradData& data, |
commit-bot@chromium.org | 83f23d8 | 2014-05-22 12:27:41 +0000 | [diff] [blame] | 127 | SkShader::TileMode tm, float scale) { |
commit-bot@chromium.org | 95f7926 | 2014-04-14 16:02:31 +0000 | [diff] [blame] | 128 | SkPoint center0, center1; |
| 129 | SkScalar radius0 = SkScalarDiv(pts[1].fX - pts[0].fX, 10); |
| 130 | SkScalar radius1 = SkScalarDiv(pts[1].fX - pts[0].fX, 3); |
| 131 | center0.set(pts[0].fX + radius0, pts[0].fY + radius0); |
| 132 | center1.set(pts[1].fX - radius1, pts[1].fY - radius1); |
| 133 | return SkGradientShader::CreateTwoPointConical(center0, 0.0, |
| 134 | center1, radius1, |
| 135 | data.fColors, data.fPos, |
commit-bot@chromium.org | 83f23d8 | 2014-05-22 12:27:41 +0000 | [diff] [blame] | 136 | data.fCount, tm); |
commit-bot@chromium.org | 95f7926 | 2014-04-14 16:02:31 +0000 | [diff] [blame] | 137 | } |
| 138 | |
reed@google.com | 84e9c08 | 2011-04-13 17:44:24 +0000 | [diff] [blame] | 139 | typedef SkShader* (*GradMaker)(const SkPoint pts[2], const GradData& data, |
commit-bot@chromium.org | 83f23d8 | 2014-05-22 12:27:41 +0000 | [diff] [blame] | 140 | SkShader::TileMode tm, float scale); |
reed@google.com | 84e9c08 | 2011-04-13 17:44:24 +0000 | [diff] [blame] | 141 | |
| 142 | static const struct { |
| 143 | GradMaker fMaker; |
| 144 | const char* fName; |
reed@google.com | 84e9c08 | 2011-04-13 17:44:24 +0000 | [diff] [blame] | 145 | } gGrads[] = { |
commit-bot@chromium.org | 95f7926 | 2014-04-14 16:02:31 +0000 | [diff] [blame] | 146 | { MakeLinear, "linear" }, |
| 147 | { MakeRadial, "radial1" }, |
| 148 | { MakeSweep, "sweep" }, |
| 149 | { Make2Radial, "radial2" }, |
| 150 | { MakeConical, "conical" }, |
| 151 | { MakeConicalZeroRad, "conicalZero" }, |
| 152 | { MakeConicalOutside, "conicalOut" }, |
| 153 | { MakeConicalOutsideZeroRad, "conicalOutZero" }, |
reed@google.com | 84e9c08 | 2011-04-13 17:44:24 +0000 | [diff] [blame] | 154 | }; |
| 155 | |
| 156 | enum GradType { // these must match the order in gGrads |
| 157 | kLinear_GradType, |
| 158 | kRadial_GradType, |
| 159 | kSweep_GradType, |
reed@google.com | 258e0bf | 2012-06-07 14:18:34 +0000 | [diff] [blame] | 160 | kRadial2_GradType, |
commit-bot@chromium.org | 95f7926 | 2014-04-14 16:02:31 +0000 | [diff] [blame] | 161 | kConical_GradType, |
| 162 | kConicalZero_GradType, |
| 163 | kConicalOut_GradType, |
| 164 | kConicalOutZero_GradType |
reed@google.com | 84e9c08 | 2011-04-13 17:44:24 +0000 | [diff] [blame] | 165 | }; |
| 166 | |
tomhudson@google.com | 5ea050f | 2011-09-26 15:03:55 +0000 | [diff] [blame] | 167 | enum GeomType { |
| 168 | kRect_GeomType, |
| 169 | kOval_GeomType |
| 170 | }; |
| 171 | |
reed@google.com | 7241516 | 2011-06-15 21:17:37 +0000 | [diff] [blame] | 172 | static const char* tilemodename(SkShader::TileMode tm) { |
| 173 | switch (tm) { |
| 174 | case SkShader::kClamp_TileMode: |
| 175 | return "clamp"; |
| 176 | case SkShader::kRepeat_TileMode: |
| 177 | return "repeat"; |
| 178 | case SkShader::kMirror_TileMode: |
| 179 | return "mirror"; |
| 180 | default: |
mtklein@google.com | 330313a | 2013-08-22 15:37:26 +0000 | [diff] [blame] | 181 | SkDEBUGFAIL("unknown tilemode"); |
reed@google.com | 7241516 | 2011-06-15 21:17:37 +0000 | [diff] [blame] | 182 | return "error"; |
| 183 | } |
| 184 | } |
| 185 | |
tomhudson@google.com | 5ea050f | 2011-09-26 15:03:55 +0000 | [diff] [blame] | 186 | static const char* geomtypename(GeomType gt) { |
| 187 | switch (gt) { |
| 188 | case kRect_GeomType: |
| 189 | return "rectangle"; |
| 190 | case kOval_GeomType: |
| 191 | return "oval"; |
| 192 | default: |
mtklein@google.com | 330313a | 2013-08-22 15:37:26 +0000 | [diff] [blame] | 193 | SkDEBUGFAIL("unknown geometry type"); |
tomhudson@google.com | 5ea050f | 2011-09-26 15:03:55 +0000 | [diff] [blame] | 194 | return "error"; |
| 195 | } |
| 196 | } |
| 197 | |
reed@google.com | 84e9c08 | 2011-04-13 17:44:24 +0000 | [diff] [blame] | 198 | /////////////////////////////////////////////////////////////////////////////// |
| 199 | |
| 200 | class GradientBench : public SkBenchmark { |
| 201 | SkString fName; |
| 202 | SkShader* fShader; |
reed@google.com | 84e9c08 | 2011-04-13 17:44:24 +0000 | [diff] [blame] | 203 | enum { |
| 204 | W = 400, |
| 205 | H = 400, |
commit-bot@chromium.org | b120bd9 | 2013-10-07 17:18:21 +0000 | [diff] [blame] | 206 | kRepeat = 15, |
reed@google.com | 84e9c08 | 2011-04-13 17:44:24 +0000 | [diff] [blame] | 207 | }; |
| 208 | public: |
mtklein@google.com | 410e6e8 | 2013-09-13 19:52:27 +0000 | [diff] [blame] | 209 | GradientBench(GradType gradType, |
commit-bot@chromium.org | 5396a04 | 2013-07-10 16:13:14 +0000 | [diff] [blame] | 210 | GradData data = gGradData[0], |
tomhudson@google.com | 5ea050f | 2011-09-26 15:03:55 +0000 | [diff] [blame] | 211 | SkShader::TileMode tm = SkShader::kClamp_TileMode, |
| 212 | GeomType geomType = kRect_GeomType, |
commit-bot@chromium.org | 3400f4b | 2013-09-30 19:41:09 +0000 | [diff] [blame] | 213 | float scale = 1.0f) { |
tomhudson@google.com | 5ea050f | 2011-09-26 15:03:55 +0000 | [diff] [blame] | 214 | fName.printf("gradient_%s_%s", gGrads[gradType].fName, |
| 215 | tilemodename(tm)); |
| 216 | if (geomType != kRect_GeomType) { |
| 217 | fName.append("_"); |
| 218 | fName.append(geomtypename(geomType)); |
| 219 | } |
reed@google.com | 84e9c08 | 2011-04-13 17:44:24 +0000 | [diff] [blame] | 220 | |
commit-bot@chromium.org | 3400f4b | 2013-09-30 19:41:09 +0000 | [diff] [blame] | 221 | if (scale != 1.f) { |
| 222 | fName.appendf("_scale_%g", scale); |
| 223 | } |
| 224 | |
commit-bot@chromium.org | 5396a04 | 2013-07-10 16:13:14 +0000 | [diff] [blame] | 225 | fName.append(data.fName); |
| 226 | |
reed@google.com | 84e9c08 | 2011-04-13 17:44:24 +0000 | [diff] [blame] | 227 | const SkPoint pts[2] = { |
| 228 | { 0, 0 }, |
| 229 | { SkIntToScalar(W), SkIntToScalar(H) } |
| 230 | }; |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 231 | |
commit-bot@chromium.org | 83f23d8 | 2014-05-22 12:27:41 +0000 | [diff] [blame] | 232 | fShader = gGrads[gradType].fMaker(pts, data, tm, scale); |
tomhudson@google.com | 5ea050f | 2011-09-26 15:03:55 +0000 | [diff] [blame] | 233 | fGeomType = geomType; |
reed@google.com | 84e9c08 | 2011-04-13 17:44:24 +0000 | [diff] [blame] | 234 | } |
| 235 | |
| 236 | virtual ~GradientBench() { |
| 237 | fShader->unref(); |
| 238 | } |
| 239 | |
| 240 | protected: |
| 241 | virtual const char* onGetName() { |
| 242 | return fName.c_str(); |
| 243 | } |
| 244 | |
commit-bot@chromium.org | 3361471 | 2013-12-03 18:17:16 +0000 | [diff] [blame] | 245 | virtual void onDraw(const int loops, SkCanvas* canvas) { |
reed@google.com | 84e9c08 | 2011-04-13 17:44:24 +0000 | [diff] [blame] | 246 | SkPaint paint; |
| 247 | this->setupPaint(&paint); |
| 248 | |
| 249 | paint.setShader(fShader); |
| 250 | |
| 251 | SkRect r = { 0, 0, SkIntToScalar(W), SkIntToScalar(H) }; |
commit-bot@chromium.org | 3361471 | 2013-12-03 18:17:16 +0000 | [diff] [blame] | 252 | for (int i = 0; i < loops * kRepeat; i++) { |
tomhudson@google.com | 5ea050f | 2011-09-26 15:03:55 +0000 | [diff] [blame] | 253 | switch (fGeomType) { |
| 254 | case kRect_GeomType: |
| 255 | canvas->drawRect(r, paint); |
| 256 | break; |
| 257 | case kOval_GeomType: |
| 258 | canvas->drawOval(r, paint); |
| 259 | break; |
| 260 | } |
reed@google.com | 84e9c08 | 2011-04-13 17:44:24 +0000 | [diff] [blame] | 261 | } |
| 262 | } |
| 263 | |
| 264 | private: |
| 265 | typedef SkBenchmark INHERITED; |
tomhudson@google.com | 5ea050f | 2011-09-26 15:03:55 +0000 | [diff] [blame] | 266 | |
| 267 | GeomType fGeomType; |
reed@google.com | 84e9c08 | 2011-04-13 17:44:24 +0000 | [diff] [blame] | 268 | }; |
| 269 | |
commit-bot@chromium.org | b120bd9 | 2013-10-07 17:18:21 +0000 | [diff] [blame] | 270 | DEF_BENCH( return new GradientBench(kLinear_GradType); ) |
| 271 | DEF_BENCH( return new GradientBench(kLinear_GradType, gGradData[1]); ) |
| 272 | DEF_BENCH( return new GradientBench(kLinear_GradType, gGradData[2]); ) |
| 273 | DEF_BENCH( return new GradientBench(kLinear_GradType, gGradData[0], SkShader::kMirror_TileMode); ) |
| 274 | |
| 275 | DEF_BENCH( return new GradientBench(kRadial_GradType, gGradData[0]); ) |
| 276 | DEF_BENCH( return new GradientBench(kRadial_GradType, gGradData[1]); ) |
| 277 | DEF_BENCH( return new GradientBench(kRadial_GradType, gGradData[2]); ) |
| 278 | // Draw a radial gradient of radius 1/2 on a rectangle; half the lines should |
| 279 | // be completely pinned, the other half should pe partially pinned |
| 280 | DEF_BENCH( return new GradientBench(kRadial_GradType, gGradData[0], SkShader::kClamp_TileMode, kRect_GeomType, 0.5f); ) |
| 281 | |
| 282 | // Draw a radial gradient on a circle of equal size; all the lines should |
| 283 | // hit the unpinned fast path (so long as GradientBench.W == H) |
| 284 | DEF_BENCH( return new GradientBench(kRadial_GradType, gGradData[0], SkShader::kClamp_TileMode, kOval_GeomType); ) |
| 285 | |
| 286 | DEF_BENCH( return new GradientBench(kRadial_GradType, gGradData[0], SkShader::kMirror_TileMode); ) |
commit-bot@chromium.org | 34150b4 | 2013-10-16 18:59:44 +0000 | [diff] [blame] | 287 | DEF_BENCH( return new GradientBench(kRadial_GradType, gGradData[0], SkShader::kRepeat_TileMode); ) |
commit-bot@chromium.org | b120bd9 | 2013-10-07 17:18:21 +0000 | [diff] [blame] | 288 | DEF_BENCH( return new GradientBench(kSweep_GradType); ) |
| 289 | DEF_BENCH( return new GradientBench(kSweep_GradType, gGradData[1]); ) |
| 290 | DEF_BENCH( return new GradientBench(kSweep_GradType, gGradData[2]); ) |
| 291 | DEF_BENCH( return new GradientBench(kRadial2_GradType); ) |
| 292 | DEF_BENCH( return new GradientBench(kRadial2_GradType, gGradData[1]); ) |
| 293 | DEF_BENCH( return new GradientBench(kRadial2_GradType, gGradData[0], SkShader::kMirror_TileMode); ) |
| 294 | DEF_BENCH( return new GradientBench(kConical_GradType); ) |
| 295 | DEF_BENCH( return new GradientBench(kConical_GradType, gGradData[1]); ) |
| 296 | DEF_BENCH( return new GradientBench(kConical_GradType, gGradData[2]); ) |
commit-bot@chromium.org | 95f7926 | 2014-04-14 16:02:31 +0000 | [diff] [blame] | 297 | DEF_BENCH( return new GradientBench(kConicalZero_GradType); ) |
| 298 | DEF_BENCH( return new GradientBench(kConicalZero_GradType, gGradData[1]); ) |
| 299 | DEF_BENCH( return new GradientBench(kConicalZero_GradType, gGradData[2]); ) |
| 300 | DEF_BENCH( return new GradientBench(kConicalOut_GradType); ) |
| 301 | DEF_BENCH( return new GradientBench(kConicalOut_GradType, gGradData[1]); ) |
| 302 | DEF_BENCH( return new GradientBench(kConicalOut_GradType, gGradData[2]); ) |
| 303 | DEF_BENCH( return new GradientBench(kConicalOutZero_GradType); ) |
| 304 | DEF_BENCH( return new GradientBench(kConicalOutZero_GradType, gGradData[1]); ) |
| 305 | DEF_BENCH( return new GradientBench(kConicalOutZero_GradType, gGradData[2]); ) |
commit-bot@chromium.org | b120bd9 | 2013-10-07 17:18:21 +0000 | [diff] [blame] | 306 | |
| 307 | /////////////////////////////////////////////////////////////////////////////// |
| 308 | |
reed@google.com | 8ac7a0f | 2011-06-16 13:14:19 +0000 | [diff] [blame] | 309 | class Gradient2Bench : public SkBenchmark { |
reed@google.com | 73349aa | 2013-02-04 18:09:58 +0000 | [diff] [blame] | 310 | SkString fName; |
| 311 | bool fHasAlpha; |
| 312 | |
reed@google.com | 8ac7a0f | 2011-06-16 13:14:19 +0000 | [diff] [blame] | 313 | public: |
mtklein@google.com | 410e6e8 | 2013-09-13 19:52:27 +0000 | [diff] [blame] | 314 | Gradient2Bench(bool hasAlpha) { |
reed@google.com | 73349aa | 2013-02-04 18:09:58 +0000 | [diff] [blame] | 315 | fName.printf("gradient_create_%s", hasAlpha ? "alpha" : "opaque"); |
| 316 | fHasAlpha = hasAlpha; |
| 317 | } |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 318 | |
reed@google.com | 8ac7a0f | 2011-06-16 13:14:19 +0000 | [diff] [blame] | 319 | protected: |
| 320 | virtual const char* onGetName() { |
reed@google.com | 73349aa | 2013-02-04 18:09:58 +0000 | [diff] [blame] | 321 | return fName.c_str(); |
reed@google.com | 8ac7a0f | 2011-06-16 13:14:19 +0000 | [diff] [blame] | 322 | } |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 323 | |
commit-bot@chromium.org | 3361471 | 2013-12-03 18:17:16 +0000 | [diff] [blame] | 324 | virtual void onDraw(const int loops, SkCanvas* canvas) { |
reed@google.com | 8ac7a0f | 2011-06-16 13:14:19 +0000 | [diff] [blame] | 325 | SkPaint paint; |
| 326 | this->setupPaint(&paint); |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 327 | |
reed@google.com | 8ac7a0f | 2011-06-16 13:14:19 +0000 | [diff] [blame] | 328 | const SkRect r = { 0, 0, SkIntToScalar(4), SkIntToScalar(4) }; |
reed@google.com | 1ca4f26 | 2011-06-24 19:17:37 +0000 | [diff] [blame] | 329 | const SkPoint pts[] = { |
| 330 | { 0, 0 }, |
| 331 | { SkIntToScalar(100), SkIntToScalar(100) }, |
| 332 | }; |
reed@google.com | 8ac7a0f | 2011-06-16 13:14:19 +0000 | [diff] [blame] | 333 | |
commit-bot@chromium.org | 3361471 | 2013-12-03 18:17:16 +0000 | [diff] [blame] | 334 | for (int i = 0; i < loops; i++) { |
reed@google.com | 73349aa | 2013-02-04 18:09:58 +0000 | [diff] [blame] | 335 | const int gray = i % 256; |
| 336 | const int alpha = fHasAlpha ? gray : 0xFF; |
tomhudson@google.com | 5ea050f | 2011-09-26 15:03:55 +0000 | [diff] [blame] | 337 | SkColor colors[] = { |
| 338 | SK_ColorBLACK, |
reed@google.com | 73349aa | 2013-02-04 18:09:58 +0000 | [diff] [blame] | 339 | SkColorSetARGB(alpha, gray, gray, gray), |
tomhudson@google.com | 5ea050f | 2011-09-26 15:03:55 +0000 | [diff] [blame] | 340 | SK_ColorWHITE }; |
reed@google.com | 8ac7a0f | 2011-06-16 13:14:19 +0000 | [diff] [blame] | 341 | SkShader* s = SkGradientShader::CreateLinear(pts, colors, NULL, |
| 342 | SK_ARRAY_COUNT(colors), |
| 343 | SkShader::kClamp_TileMode); |
| 344 | paint.setShader(s)->unref(); |
| 345 | canvas->drawRect(r, paint); |
| 346 | } |
| 347 | } |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 348 | |
reed@google.com | 8ac7a0f | 2011-06-16 13:14:19 +0000 | [diff] [blame] | 349 | private: |
| 350 | typedef SkBenchmark INHERITED; |
| 351 | }; |
| 352 | |
mtklein@google.com | 410e6e8 | 2013-09-13 19:52:27 +0000 | [diff] [blame] | 353 | DEF_BENCH( return new Gradient2Bench(false); ) |
| 354 | DEF_BENCH( return new Gradient2Bench(true); ) |