bsalomon@google.com | 82d1223 | 2013-09-09 15:36:26 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2013 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
Ben Wagner | 7fde8e1 | 2019-05-01 17:28:53 -0400 | [diff] [blame] | 7 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 8 | #include "gm/gm.h" |
Ben Wagner | 7fde8e1 | 2019-05-01 17:28:53 -0400 | [diff] [blame] | 9 | #include "include/core/SkCanvas.h" |
| 10 | #include "include/core/SkColor.h" |
| 11 | #include "include/core/SkPaint.h" |
| 12 | #include "include/core/SkPoint.h" |
| 13 | #include "include/core/SkRect.h" |
| 14 | #include "include/core/SkRefCnt.h" |
| 15 | #include "include/core/SkScalar.h" |
| 16 | #include "include/core/SkShader.h" |
| 17 | #include "include/core/SkSize.h" |
| 18 | #include "include/core/SkString.h" |
| 19 | #include "include/core/SkTileMode.h" |
| 20 | #include "include/core/SkTypes.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 21 | #include "include/effects/SkGradientShader.h" |
bsalomon@google.com | 82d1223 | 2013-09-09 15:36:26 +0000 | [diff] [blame] | 22 | |
Ben Wagner | 7fde8e1 | 2019-05-01 17:28:53 -0400 | [diff] [blame] | 23 | #include <string.h> |
| 24 | |
bsalomon@google.com | 82d1223 | 2013-09-09 15:36:26 +0000 | [diff] [blame] | 25 | using namespace skiagm; |
| 26 | |
| 27 | struct GradData { |
| 28 | int fCount; |
| 29 | const SkColor* fColors; |
| 30 | const SkScalar* fPos; |
| 31 | }; |
| 32 | |
mtklein | dbfd7ab | 2016-09-01 11:24:54 -0700 | [diff] [blame] | 33 | constexpr SkColor gColors[] = { |
bsalomon@google.com | 82d1223 | 2013-09-09 15:36:26 +0000 | [diff] [blame] | 34 | SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE, SK_ColorWHITE, |
| 35 | }; |
| 36 | |
mtklein | dbfd7ab | 2016-09-01 11:24:54 -0700 | [diff] [blame] | 37 | constexpr GradData gGradData[] = { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 38 | { 1, gColors, nullptr }, |
| 39 | { 2, gColors, nullptr }, |
| 40 | { 3, gColors, nullptr }, |
| 41 | { 4, gColors, nullptr }, |
bsalomon@google.com | 82d1223 | 2013-09-09 15:36:26 +0000 | [diff] [blame] | 42 | }; |
| 43 | |
Mike Reed | fae8fce | 2019-04-03 10:27:45 -0400 | [diff] [blame] | 44 | static sk_sp<SkShader> MakeLinear(const SkPoint pts[2], const GradData& data, SkTileMode tm) { |
reed | 1a9b964 | 2016-03-13 14:13:58 -0700 | [diff] [blame] | 45 | return SkGradientShader::MakeLinear(pts, data.fColors, data.fPos, data.fCount, tm); |
bsalomon@google.com | 82d1223 | 2013-09-09 15:36:26 +0000 | [diff] [blame] | 46 | } |
| 47 | |
Mike Reed | fae8fce | 2019-04-03 10:27:45 -0400 | [diff] [blame] | 48 | static sk_sp<SkShader> MakeRadial(const SkPoint pts[2], const GradData& data, SkTileMode tm) { |
bsalomon@google.com | 82d1223 | 2013-09-09 15:36:26 +0000 | [diff] [blame] | 49 | SkPoint center; |
| 50 | center.set(SkScalarAve(pts[0].fX, pts[1].fX), |
| 51 | SkScalarAve(pts[0].fY, pts[1].fY)); |
reed | 1a9b964 | 2016-03-13 14:13:58 -0700 | [diff] [blame] | 52 | return SkGradientShader::MakeRadial(center, center.fX, data.fColors, data.fPos, data.fCount, tm); |
bsalomon@google.com | 82d1223 | 2013-09-09 15:36:26 +0000 | [diff] [blame] | 53 | } |
| 54 | |
Mike Reed | fae8fce | 2019-04-03 10:27:45 -0400 | [diff] [blame] | 55 | static sk_sp<SkShader> MakeSweep(const SkPoint pts[2], const GradData& data, SkTileMode) { |
bsalomon@google.com | 82d1223 | 2013-09-09 15:36:26 +0000 | [diff] [blame] | 56 | SkPoint center; |
| 57 | center.set(SkScalarAve(pts[0].fX, pts[1].fX), |
| 58 | SkScalarAve(pts[0].fY, pts[1].fY)); |
reed | 1a9b964 | 2016-03-13 14:13:58 -0700 | [diff] [blame] | 59 | return SkGradientShader::MakeSweep(center.fX, center.fY, data.fColors, data.fPos, data.fCount); |
bsalomon@google.com | 82d1223 | 2013-09-09 15:36:26 +0000 | [diff] [blame] | 60 | } |
| 61 | |
Mike Reed | fae8fce | 2019-04-03 10:27:45 -0400 | [diff] [blame] | 62 | static sk_sp<SkShader> Make2Radial(const SkPoint pts[2], const GradData& data, SkTileMode tm) { |
bsalomon@google.com | 82d1223 | 2013-09-09 15:36:26 +0000 | [diff] [blame] | 63 | SkPoint center0, center1; |
| 64 | center0.set(SkScalarAve(pts[0].fX, pts[1].fX), |
| 65 | SkScalarAve(pts[0].fY, pts[1].fY)); |
| 66 | center1.set(SkScalarInterp(pts[0].fX, pts[1].fX, SkIntToScalar(3)/5), |
| 67 | SkScalarInterp(pts[0].fY, pts[1].fY, SkIntToScalar(1)/4)); |
reed | 1a9b964 | 2016-03-13 14:13:58 -0700 | [diff] [blame] | 68 | return SkGradientShader::MakeTwoPointConical( |
bsalomon@google.com | 82d1223 | 2013-09-09 15:36:26 +0000 | [diff] [blame] | 69 | center1, (pts[1].fX - pts[0].fX) / 7, |
| 70 | center0, (pts[1].fX - pts[0].fX) / 2, |
commit-bot@chromium.org | 83f23d8 | 2014-05-22 12:27:41 +0000 | [diff] [blame] | 71 | data.fColors, data.fPos, data.fCount, tm); |
bsalomon@google.com | 82d1223 | 2013-09-09 15:36:26 +0000 | [diff] [blame] | 72 | } |
| 73 | |
Mike Reed | fae8fce | 2019-04-03 10:27:45 -0400 | [diff] [blame] | 74 | static sk_sp<SkShader> Make2Conical(const SkPoint pts[2], const GradData& data, SkTileMode tm) { |
bsalomon@google.com | 82d1223 | 2013-09-09 15:36:26 +0000 | [diff] [blame] | 75 | SkPoint center0, center1; |
reed | 80ea19c | 2015-05-12 10:37:34 -0700 | [diff] [blame] | 76 | SkScalar radius0 = (pts[1].fX - pts[0].fX) / 10; |
| 77 | SkScalar radius1 = (pts[1].fX - pts[0].fX) / 3; |
bsalomon@google.com | 82d1223 | 2013-09-09 15:36:26 +0000 | [diff] [blame] | 78 | center0.set(pts[0].fX + radius0, pts[0].fY + radius0); |
| 79 | center1.set(pts[1].fX - radius1, pts[1].fY - radius1); |
reed | 1a9b964 | 2016-03-13 14:13:58 -0700 | [diff] [blame] | 80 | return SkGradientShader::MakeTwoPointConical(center1, radius1, |
bsalomon@google.com | 82d1223 | 2013-09-09 15:36:26 +0000 | [diff] [blame] | 81 | center0, radius0, |
| 82 | data.fColors, data.fPos, |
commit-bot@chromium.org | 83f23d8 | 2014-05-22 12:27:41 +0000 | [diff] [blame] | 83 | data.fCount, tm); |
bsalomon@google.com | 82d1223 | 2013-09-09 15:36:26 +0000 | [diff] [blame] | 84 | } |
| 85 | |
| 86 | |
Mike Reed | fae8fce | 2019-04-03 10:27:45 -0400 | [diff] [blame] | 87 | typedef sk_sp<SkShader> (*GradMaker)(const SkPoint pts[2], const GradData& data, SkTileMode tm); |
commit-bot@chromium.org | 83f23d8 | 2014-05-22 12:27:41 +0000 | [diff] [blame] | 88 | |
mtklein | dbfd7ab | 2016-09-01 11:24:54 -0700 | [diff] [blame] | 89 | constexpr GradMaker gGradMakers[] = { |
bsalomon@google.com | 82d1223 | 2013-09-09 15:36:26 +0000 | [diff] [blame] | 90 | MakeLinear, MakeRadial, MakeSweep, Make2Radial, Make2Conical, |
| 91 | }; |
| 92 | |
| 93 | /////////////////////////////////////////////////////////////////////////////// |
| 94 | |
| 95 | class GradientsNoTextureGM : public GM { |
| 96 | public: |
fmalita | 063675b | 2015-10-12 10:41:48 -0700 | [diff] [blame] | 97 | GradientsNoTextureGM(bool dither) : fDither(dither) { |
Mike Klein | d46dce3 | 2018-08-16 10:17:03 -0400 | [diff] [blame] | 98 | this->setBGColor(0xFFDDDDDD); |
bsalomon@google.com | 82d1223 | 2013-09-09 15:36:26 +0000 | [diff] [blame] | 99 | } |
| 100 | |
| 101 | protected: |
commit-bot@chromium.org | a90c680 | 2014-04-30 13:20:45 +0000 | [diff] [blame] | 102 | |
fmalita | 063675b | 2015-10-12 10:41:48 -0700 | [diff] [blame] | 103 | SkString onShortName() override { |
| 104 | return SkString(fDither ? "gradients_no_texture" : "gradients_no_texture_nodither"); |
| 105 | } |
| 106 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 107 | SkISize onISize() override { return SkISize::Make(640, 615); } |
bsalomon@google.com | 82d1223 | 2013-09-09 15:36:26 +0000 | [diff] [blame] | 108 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 109 | void onDraw(SkCanvas* canvas) override { |
mtklein | dbfd7ab | 2016-09-01 11:24:54 -0700 | [diff] [blame] | 110 | constexpr SkPoint kPts[2] = { { 0, 0 }, |
bsalomon@google.com | 82d1223 | 2013-09-09 15:36:26 +0000 | [diff] [blame] | 111 | { SkIntToScalar(50), SkIntToScalar(50) } }; |
Mike Reed | fae8fce | 2019-04-03 10:27:45 -0400 | [diff] [blame] | 112 | constexpr SkTileMode kTM = SkTileMode::kClamp; |
bsalomon@google.com | 82d1223 | 2013-09-09 15:36:26 +0000 | [diff] [blame] | 113 | SkRect kRect = { 0, 0, SkIntToScalar(50), SkIntToScalar(50) }; |
| 114 | SkPaint paint; |
| 115 | paint.setAntiAlias(true); |
fmalita | 063675b | 2015-10-12 10:41:48 -0700 | [diff] [blame] | 116 | paint.setDither(fDither); |
bsalomon@google.com | 82d1223 | 2013-09-09 15:36:26 +0000 | [diff] [blame] | 117 | |
| 118 | canvas->translate(SkIntToScalar(20), SkIntToScalar(20)); |
mtklein | dbfd7ab | 2016-09-01 11:24:54 -0700 | [diff] [blame] | 119 | constexpr uint8_t kAlphas[] = { 0xff, 0x40 }; |
bsalomon@google.com | 82d1223 | 2013-09-09 15:36:26 +0000 | [diff] [blame] | 120 | for (size_t a = 0; a < SK_ARRAY_COUNT(kAlphas); ++a) { |
| 121 | for (size_t i = 0; i < SK_ARRAY_COUNT(gGradData); ++i) { |
| 122 | canvas->save(); |
| 123 | for (size_t j = 0; j < SK_ARRAY_COUNT(gGradMakers); ++j) { |
reed | 1a9b964 | 2016-03-13 14:13:58 -0700 | [diff] [blame] | 124 | paint.setShader(gGradMakers[j](kPts, gGradData[i], kTM)); |
bsalomon@google.com | 82d1223 | 2013-09-09 15:36:26 +0000 | [diff] [blame] | 125 | paint.setAlpha(kAlphas[a]); |
| 126 | canvas->drawRect(kRect, paint); |
| 127 | canvas->translate(0, SkIntToScalar(kRect.height() + 20)); |
| 128 | } |
| 129 | canvas->restore(); |
| 130 | canvas->translate(SkIntToScalar(kRect.width() + 20), 0); |
| 131 | } |
| 132 | } |
| 133 | } |
| 134 | |
| 135 | private: |
fmalita | 063675b | 2015-10-12 10:41:48 -0700 | [diff] [blame] | 136 | bool fDither; |
| 137 | |
bsalomon@google.com | 82d1223 | 2013-09-09 15:36:26 +0000 | [diff] [blame] | 138 | typedef GM INHERITED; |
| 139 | }; |
| 140 | |
| 141 | /////////////////////////////////////////////////////////////////////////////// |
| 142 | |
reed@google.com | 7b8999b | 2014-04-18 17:55:37 +0000 | [diff] [blame] | 143 | struct ColorPos { |
| 144 | SkColor* fColors; |
| 145 | SkScalar* fPos; |
| 146 | int fCount; |
| 147 | |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 148 | ColorPos() : fColors(nullptr), fPos(nullptr), fCount(0) {} |
reed@google.com | 7b8999b | 2014-04-18 17:55:37 +0000 | [diff] [blame] | 149 | ~ColorPos() { |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 150 | delete[] fColors; |
| 151 | delete[] fPos; |
reed@google.com | 7b8999b | 2014-04-18 17:55:37 +0000 | [diff] [blame] | 152 | } |
| 153 | |
| 154 | void construct(const SkColor colors[], const SkScalar pos[], int count) { |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 155 | fColors = new SkColor[count]; |
reed@google.com | 7b8999b | 2014-04-18 17:55:37 +0000 | [diff] [blame] | 156 | memcpy(fColors, colors, count * sizeof(SkColor)); |
| 157 | if (pos) { |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 158 | fPos = new SkScalar[count]; |
reed@google.com | 7b8999b | 2014-04-18 17:55:37 +0000 | [diff] [blame] | 159 | memcpy(fPos, pos, count * sizeof(SkScalar)); |
| 160 | fPos[0] = 0; |
| 161 | fPos[count - 1] = 1; |
| 162 | } |
| 163 | fCount = count; |
| 164 | } |
| 165 | }; |
| 166 | |
| 167 | static void make0(ColorPos* rec) { |
| 168 | #if 0 |
| 169 | From http://jsfiddle.net/3fe2a/ |
| 170 | |
| 171 | background-image: -webkit-linear-gradient(left, #22d1cd 1%, #22d1cd 0.9510157507590116%, #df4b37 2.9510157507590113%, #df4b37 23.695886056604927%, #22d1cd 25.695886056604927%, #22d1cd 25.39321881940624%, #e6de36 27.39321881940624%, #e6de36 31.849399922570655%, #3267ff 33.849399922570655%, #3267ff 44.57735802921938%, #9d47d1 46.57735802921938%, #9d47d1 53.27185850805876%, #3267ff 55.27185850805876%, #3267ff 61.95718972227316%, #5cdd9d 63.95718972227316%, #5cdd9d 69.89166004442%, #3267ff 71.89166004442%, #3267ff 74.45795382765857%, #9d47d1 76.45795382765857%, #9d47d1 82.78364610713776%, #3267ff 84.78364610713776%, #3267ff 94.52743647737229%, #e3d082 96.52743647737229%, #e3d082 96.03934633331295%); |
| 172 | height: 30px; |
| 173 | #endif |
| 174 | |
| 175 | const SkColor colors[] = { |
| 176 | 0xFF22d1cd, 0xFF22d1cd, 0xFFdf4b37, 0xFFdf4b37, 0xFF22d1cd, 0xFF22d1cd, 0xFFe6de36, 0xFFe6de36, |
| 177 | 0xFF3267ff, 0xFF3267ff, 0xFF9d47d1, 0xFF9d47d1, 0xFF3267ff, 0xFF3267ff, 0xFF5cdd9d, 0xFF5cdd9d, |
| 178 | 0xFF3267ff, 0xFF3267ff, 0xFF9d47d1, 0xFF9d47d1, 0xFF3267ff, 0xFF3267ff, 0xFFe3d082, 0xFFe3d082 |
| 179 | }; |
| 180 | const double percent[] = { |
| 181 | 1, 0.9510157507590116, 2.9510157507590113, 23.695886056604927, |
| 182 | 25.695886056604927, 25.39321881940624, 27.39321881940624, 31.849399922570655, |
| 183 | 33.849399922570655, 44.57735802921938, 46.57735802921938, 53.27185850805876, |
| 184 | 55.27185850805876, 61.95718972227316, 63.95718972227316, 69.89166004442, |
| 185 | 71.89166004442, 74.45795382765857, 76.45795382765857, 82.78364610713776, |
| 186 | 84.78364610713776, 94.52743647737229, 96.52743647737229, 96.03934633331295, |
| 187 | }; |
| 188 | const int N = SK_ARRAY_COUNT(percent); |
| 189 | SkScalar pos[N]; |
| 190 | for (int i = 0; i < N; ++i) { |
| 191 | pos[i] = SkDoubleToScalar(percent[i] / 100); |
| 192 | } |
| 193 | rec->construct(colors, pos, N); |
| 194 | } |
| 195 | |
| 196 | static void make1(ColorPos* rec) { |
| 197 | const SkColor colors[] = { |
| 198 | SK_ColorBLACK, SK_ColorWHITE, SK_ColorBLACK, SK_ColorWHITE, |
| 199 | SK_ColorBLACK, SK_ColorWHITE, SK_ColorBLACK, SK_ColorWHITE, |
| 200 | SK_ColorBLACK, |
| 201 | }; |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 202 | rec->construct(colors, nullptr, SK_ARRAY_COUNT(colors)); |
reed@google.com | 7b8999b | 2014-04-18 17:55:37 +0000 | [diff] [blame] | 203 | } |
| 204 | |
| 205 | static void make2(ColorPos* rec) { |
| 206 | const SkColor colors[] = { |
| 207 | SK_ColorBLACK, SK_ColorWHITE, SK_ColorBLACK, SK_ColorWHITE, |
| 208 | SK_ColorBLACK, SK_ColorWHITE, SK_ColorBLACK, SK_ColorWHITE, |
| 209 | SK_ColorBLACK, |
| 210 | }; |
| 211 | const int N = SK_ARRAY_COUNT(colors); |
| 212 | SkScalar pos[N]; |
| 213 | for (int i = 0; i < N; ++i) { |
| 214 | pos[i] = SK_Scalar1 * i / (N - 1); |
| 215 | } |
| 216 | rec->construct(colors, pos, N); |
| 217 | } |
| 218 | |
reed | 6b90df6 | 2015-11-13 06:23:54 -0800 | [diff] [blame] | 219 | static void make3(ColorPos* rec) { |
| 220 | const SkColor colors[] = { |
| 221 | SK_ColorRED, SK_ColorBLUE, SK_ColorBLUE, SK_ColorGREEN, SK_ColorGREEN, SK_ColorBLACK, |
| 222 | }; |
| 223 | const SkScalar pos[] = { |
| 224 | 0, 0, 0.5f, 0.5, 1, 1, |
| 225 | }; |
| 226 | rec->construct(colors, pos, SK_ARRAY_COUNT(colors)); |
| 227 | } |
| 228 | |
reed@google.com | 7b8999b | 2014-04-18 17:55:37 +0000 | [diff] [blame] | 229 | class GradientsManyColorsGM : public GM { |
| 230 | enum { |
| 231 | W = 800, |
| 232 | }; |
Hal Canary | cefc431 | 2016-11-04 16:26:16 -0400 | [diff] [blame] | 233 | sk_sp<SkShader> fShader; |
reed@google.com | 7b8999b | 2014-04-18 17:55:37 +0000 | [diff] [blame] | 234 | |
| 235 | typedef void (*Proc)(ColorPos*); |
| 236 | public: |
fmalita | 063675b | 2015-10-12 10:41:48 -0700 | [diff] [blame] | 237 | GradientsManyColorsGM(bool dither) : fDither(dither) {} |
skia.committer@gmail.com | 8a777a5 | 2014-04-19 03:04:56 +0000 | [diff] [blame] | 238 | |
reed@google.com | 7b8999b | 2014-04-18 17:55:37 +0000 | [diff] [blame] | 239 | protected: |
commit-bot@chromium.org | a90c680 | 2014-04-30 13:20:45 +0000 | [diff] [blame] | 240 | |
fmalita | 063675b | 2015-10-12 10:41:48 -0700 | [diff] [blame] | 241 | SkString onShortName() override { |
| 242 | return SkString(fDither ? "gradients_many" : "gradients_many_nodither"); |
| 243 | } |
| 244 | |
reed | 6b90df6 | 2015-11-13 06:23:54 -0800 | [diff] [blame] | 245 | SkISize onISize() override { return SkISize::Make(880, 400); } |
skia.committer@gmail.com | 8a777a5 | 2014-04-19 03:04:56 +0000 | [diff] [blame] | 246 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 247 | void onDraw(SkCanvas* canvas) override { |
reed@google.com | 7b8999b | 2014-04-18 17:55:37 +0000 | [diff] [blame] | 248 | const Proc procs[] = { |
reed | 6b90df6 | 2015-11-13 06:23:54 -0800 | [diff] [blame] | 249 | make0, make1, make2, make3, |
reed@google.com | 7b8999b | 2014-04-18 17:55:37 +0000 | [diff] [blame] | 250 | }; |
| 251 | const SkPoint pts[] = { |
| 252 | { 0, 0 }, |
| 253 | { SkIntToScalar(W), 0 }, |
| 254 | }; |
| 255 | const SkRect r = SkRect::MakeWH(SkIntToScalar(W), 30); |
| 256 | |
| 257 | SkPaint paint; |
fmalita | 063675b | 2015-10-12 10:41:48 -0700 | [diff] [blame] | 258 | paint.setDither(fDither); |
skia.committer@gmail.com | 8a777a5 | 2014-04-19 03:04:56 +0000 | [diff] [blame] | 259 | |
reed | 6b90df6 | 2015-11-13 06:23:54 -0800 | [diff] [blame] | 260 | canvas->translate(40, 20); |
skia.committer@gmail.com | 8a777a5 | 2014-04-19 03:04:56 +0000 | [diff] [blame] | 261 | |
reed@google.com | 7b8999b | 2014-04-18 17:55:37 +0000 | [diff] [blame] | 262 | for (int i = 0; i <= 8; ++i) { |
| 263 | SkScalar x = r.width() * i / 8; |
| 264 | canvas->drawLine(x, 0, x, 10000, paint); |
| 265 | } |
| 266 | |
reed | 6b90df6 | 2015-11-13 06:23:54 -0800 | [diff] [blame] | 267 | // expand the drawing rect so we exercise clampping in the gradients |
| 268 | const SkRect drawR = r.makeOutset(20, 0); |
reed@google.com | 7b8999b | 2014-04-18 17:55:37 +0000 | [diff] [blame] | 269 | for (size_t i = 0; i < SK_ARRAY_COUNT(procs); ++i) { |
| 270 | ColorPos rec; |
| 271 | procs[i](&rec); |
reed | 1a9b964 | 2016-03-13 14:13:58 -0700 | [diff] [blame] | 272 | paint.setShader(SkGradientShader::MakeLinear(pts, rec.fColors, rec.fPos, rec.fCount, |
Mike Reed | fae8fce | 2019-04-03 10:27:45 -0400 | [diff] [blame] | 273 | SkTileMode::kClamp)); |
reed | 6b90df6 | 2015-11-13 06:23:54 -0800 | [diff] [blame] | 274 | canvas->drawRect(drawR, paint); |
| 275 | |
| 276 | canvas->save(); |
| 277 | canvas->translate(r.centerX(), r.height() + 4); |
| 278 | canvas->scale(-1, 1); |
| 279 | canvas->translate(-r.centerX(), 0); |
| 280 | canvas->drawRect(drawR, paint); |
| 281 | canvas->restore(); |
| 282 | |
| 283 | canvas->translate(0, r.height() + 2*r.height() + 8); |
reed@google.com | 7b8999b | 2014-04-18 17:55:37 +0000 | [diff] [blame] | 284 | } |
| 285 | } |
skia.committer@gmail.com | 8a777a5 | 2014-04-19 03:04:56 +0000 | [diff] [blame] | 286 | |
reed@google.com | 7b8999b | 2014-04-18 17:55:37 +0000 | [diff] [blame] | 287 | private: |
fmalita | 063675b | 2015-10-12 10:41:48 -0700 | [diff] [blame] | 288 | bool fDither; |
| 289 | |
reed@google.com | 7b8999b | 2014-04-18 17:55:37 +0000 | [diff] [blame] | 290 | typedef GM INHERITED; |
| 291 | }; |
| 292 | |
| 293 | /////////////////////////////////////////////////////////////////////////////// |
| 294 | |
fmalita | 063675b | 2015-10-12 10:41:48 -0700 | [diff] [blame] | 295 | DEF_GM(return new GradientsNoTextureGM(true);) |
| 296 | DEF_GM(return new GradientsNoTextureGM(false);) |
| 297 | DEF_GM(return new GradientsManyColorsGM(true);) |
| 298 | DEF_GM(return new GradientsManyColorsGM(false);) |