commit-bot@chromium.org | c8379d7 | 2014-04-22 20:56:37 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2014 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 | */ |
commit-bot@chromium.org | 83f23d8 | 2014-05-22 12:27:41 +0000 | [diff] [blame] | 7 | |
commit-bot@chromium.org | c8379d7 | 2014-04-22 20:56:37 +0000 | [diff] [blame] | 8 | #include "gm.h" |
| 9 | #include "SkGradientShader.h" |
| 10 | |
| 11 | namespace skiagm { |
| 12 | |
| 13 | struct GradData { |
| 14 | int fCount; |
| 15 | const SkColor* fColors; |
| 16 | const SkScalar* fPos; |
| 17 | }; |
| 18 | |
| 19 | static const SkColor gColors[] = { |
| 20 | SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE, SK_ColorWHITE, SK_ColorBLACK |
| 21 | }; |
| 22 | static const SkScalar gPos0[] = { 0, SK_Scalar1 }; |
| 23 | static const SkScalar gPos1[] = { SK_Scalar1/4, SK_Scalar1*3/4 }; |
| 24 | static const SkScalar gPos2[] = { |
| 25 | 0, SK_Scalar1/8, SK_Scalar1/2, SK_Scalar1*7/8, SK_Scalar1 |
| 26 | }; |
| 27 | |
| 28 | static const SkScalar gPosClamp[] = {0.0f, 0.0f, 1.0f, 1.0f}; |
| 29 | static const SkColor gColorClamp[] = { |
| 30 | SK_ColorRED, SK_ColorGREEN, SK_ColorGREEN, SK_ColorBLUE |
| 31 | }; |
| 32 | |
| 33 | static const GradData gGradData[] = { |
| 34 | { 2, gColors, gPos0 }, |
| 35 | { 2, gColors, gPos1 }, |
| 36 | { 5, gColors, gPos2 }, |
| 37 | { 4, gColorClamp, gPosClamp } |
| 38 | }; |
| 39 | |
reed | 1a9b964 | 2016-03-13 14:13:58 -0700 | [diff] [blame] | 40 | static sk_sp<SkShader> Make2ConicalOutside(const SkPoint pts[2], const GradData& data, |
| 41 | SkShader::TileMode tm, const SkMatrix& localMatrix) { |
commit-bot@chromium.org | c8379d7 | 2014-04-22 20:56:37 +0000 | [diff] [blame] | 42 | SkPoint center0, center1; |
reed | 80ea19c | 2015-05-12 10:37:34 -0700 | [diff] [blame] | 43 | SkScalar radius0 = (pts[1].fX - pts[0].fX) / 10; |
| 44 | SkScalar radius1 = (pts[1].fX - pts[0].fX) / 3; |
commit-bot@chromium.org | c8379d7 | 2014-04-22 20:56:37 +0000 | [diff] [blame] | 45 | center0.set(pts[0].fX + radius0, pts[0].fY + radius0); |
| 46 | center1.set(pts[1].fX - radius1, pts[1].fY - radius1); |
reed | 1a9b964 | 2016-03-13 14:13:58 -0700 | [diff] [blame] | 47 | return SkGradientShader::MakeTwoPointConical(center0, radius0, center1, radius1, data.fColors, |
| 48 | data.fPos, data.fCount, tm, 0, &localMatrix); |
commit-bot@chromium.org | c8379d7 | 2014-04-22 20:56:37 +0000 | [diff] [blame] | 49 | } |
| 50 | |
reed | 1a9b964 | 2016-03-13 14:13:58 -0700 | [diff] [blame] | 51 | static sk_sp<SkShader> Make2ConicalOutsideFlip(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, const SkMatrix& localMatrix) { |
commit-bot@chromium.org | c8379d7 | 2014-04-22 20:56:37 +0000 | [diff] [blame] | 53 | SkPoint center0, center1; |
reed | 80ea19c | 2015-05-12 10:37:34 -0700 | [diff] [blame] | 54 | SkScalar radius0 = (pts[1].fX - pts[0].fX) / 10; |
| 55 | SkScalar radius1 = (pts[1].fX - pts[0].fX) / 3; |
commit-bot@chromium.org | c8379d7 | 2014-04-22 20:56:37 +0000 | [diff] [blame] | 56 | center0.set(pts[0].fX + radius0, pts[0].fY + radius0); |
| 57 | center1.set(pts[1].fX - radius1, pts[1].fY - radius1); |
reed | 1a9b964 | 2016-03-13 14:13:58 -0700 | [diff] [blame] | 58 | return SkGradientShader::MakeTwoPointConical(center1, radius1, center0, radius0, data.fColors, |
| 59 | data.fPos, data.fCount, tm, 0, &localMatrix); |
commit-bot@chromium.org | c8379d7 | 2014-04-22 20:56:37 +0000 | [diff] [blame] | 60 | } |
| 61 | |
reed | 1a9b964 | 2016-03-13 14:13:58 -0700 | [diff] [blame] | 62 | static sk_sp<SkShader> Make2ConicalInside(const SkPoint pts[2], const GradData& data, |
| 63 | SkShader::TileMode tm, const SkMatrix& localMatrix) { |
| 64 | SkPoint center0, center1; |
| 65 | center0.set(SkScalarAve(pts[0].fX, pts[1].fX), |
| 66 | SkScalarAve(pts[0].fY, pts[1].fY)); |
| 67 | center1.set(SkScalarInterp(pts[0].fX, pts[1].fX, SkIntToScalar(3)/5), |
| 68 | SkScalarInterp(pts[0].fY, pts[1].fY, SkIntToScalar(1)/4)); |
| 69 | return SkGradientShader::MakeTwoPointConical(center1, (pts[1].fX - pts[0].fX) / 7, |
| 70 | center0, (pts[1].fX - pts[0].fX) / 2, |
| 71 | data.fColors, data.fPos, data.fCount, tm, |
| 72 | 0, &localMatrix); |
| 73 | } |
| 74 | |
| 75 | static sk_sp<SkShader> Make2ConicalInsideFlip(const SkPoint pts[2], const GradData& data, |
| 76 | SkShader::TileMode tm, const SkMatrix& localMatrix) { |
| 77 | SkPoint center0, center1; |
| 78 | center0.set(SkScalarAve(pts[0].fX, pts[1].fX), |
| 79 | SkScalarAve(pts[0].fY, pts[1].fY)); |
| 80 | center1.set(SkScalarInterp(pts[0].fX, pts[1].fX, SkIntToScalar(3)/5), |
| 81 | SkScalarInterp(pts[0].fY, pts[1].fY, SkIntToScalar(1)/4)); |
| 82 | return SkGradientShader::MakeTwoPointConical(center0, (pts[1].fX - pts[0].fX) / 2, |
| 83 | center1, (pts[1].fX - pts[0].fX) / 7, |
| 84 | data.fColors, data.fPos, data.fCount, tm, |
| 85 | 0, &localMatrix); |
| 86 | } |
| 87 | |
| 88 | static sk_sp<SkShader> Make2ConicalInsideCenter(const SkPoint pts[2], const GradData& data, |
commit-bot@chromium.org | 83f23d8 | 2014-05-22 12:27:41 +0000 | [diff] [blame] | 89 | SkShader::TileMode tm, const SkMatrix& localMatrix) { |
commit-bot@chromium.org | c8379d7 | 2014-04-22 20:56:37 +0000 | [diff] [blame] | 90 | SkPoint center0, center1; |
| 91 | center0.set(SkScalarAve(pts[0].fX, pts[1].fX), |
| 92 | SkScalarAve(pts[0].fY, pts[1].fY)); |
| 93 | center1.set(SkScalarInterp(pts[0].fX, pts[1].fX, SkIntToScalar(3)/5), |
| 94 | SkScalarInterp(pts[0].fY, pts[1].fY, SkIntToScalar(1)/4)); |
reed | 1a9b964 | 2016-03-13 14:13:58 -0700 | [diff] [blame] | 95 | return SkGradientShader::MakeTwoPointConical(center0, (pts[1].fX - pts[0].fX) / 7, |
| 96 | center0, (pts[1].fX - pts[0].fX) / 2, |
| 97 | data.fColors, data.fPos, data.fCount, tm, |
| 98 | 0, &localMatrix); |
commit-bot@chromium.org | c8379d7 | 2014-04-22 20:56:37 +0000 | [diff] [blame] | 99 | } |
| 100 | |
reed | 1a9b964 | 2016-03-13 14:13:58 -0700 | [diff] [blame] | 101 | static sk_sp<SkShader> Make2ConicalZeroRad(const SkPoint pts[2], const GradData& data, |
| 102 | SkShader::TileMode tm, const SkMatrix& localMatrix) { |
| 103 | SkPoint center0, center1; |
| 104 | center0.set(SkScalarAve(pts[0].fX, pts[1].fX), |
| 105 | SkScalarAve(pts[0].fY, pts[1].fY)); |
| 106 | center1.set(SkScalarInterp(pts[0].fX, pts[1].fX, SkIntToScalar(3)/5), |
| 107 | SkScalarInterp(pts[0].fY, pts[1].fY, SkIntToScalar(1)/4)); |
| 108 | return SkGradientShader::MakeTwoPointConical(center1, 0.f, |
| 109 | center0, (pts[1].fX - pts[0].fX) / 2, |
| 110 | data.fColors, data.fPos, data.fCount, tm, |
| 111 | 0, &localMatrix); |
| 112 | } |
| 113 | |
| 114 | static sk_sp<SkShader> Make2ConicalZeroRadFlip(const SkPoint pts[2], const GradData& data, |
| 115 | SkShader::TileMode tm, const SkMatrix& localMatrix) { |
| 116 | SkPoint center0, center1; |
| 117 | center0.set(SkScalarAve(pts[0].fX, pts[1].fX), |
| 118 | SkScalarAve(pts[0].fY, pts[1].fY)); |
| 119 | center1.set(SkScalarInterp(pts[0].fX, pts[1].fX, SkIntToScalar(3)/5), |
| 120 | SkScalarInterp(pts[0].fY, pts[1].fY, SkIntToScalar(1)/4)); |
| 121 | return SkGradientShader::MakeTwoPointConical(center1, (pts[1].fX - pts[0].fX) / 2, |
| 122 | center0, 0.f, |
| 123 | data.fColors, data.fPos, data.fCount, tm, |
| 124 | 0, &localMatrix); |
| 125 | } |
| 126 | |
| 127 | static sk_sp<SkShader> Make2ConicalZeroRadCenter(const SkPoint pts[2], const GradData& data, |
commit-bot@chromium.org | 83f23d8 | 2014-05-22 12:27:41 +0000 | [diff] [blame] | 128 | SkShader::TileMode tm, const SkMatrix& localMatrix) { |
commit-bot@chromium.org | c8379d7 | 2014-04-22 20:56:37 +0000 | [diff] [blame] | 129 | SkPoint center0, center1; |
| 130 | center0.set(SkScalarAve(pts[0].fX, pts[1].fX), |
| 131 | SkScalarAve(pts[0].fY, pts[1].fY)); |
| 132 | center1.set(SkScalarInterp(pts[0].fX, pts[1].fX, SkIntToScalar(3)/5), |
| 133 | SkScalarInterp(pts[0].fY, pts[1].fY, SkIntToScalar(1)/4)); |
reed | 1a9b964 | 2016-03-13 14:13:58 -0700 | [diff] [blame] | 134 | return SkGradientShader::MakeTwoPointConical(center0, 0.f, center0, (pts[1].fX - pts[0].fX) / 2, |
| 135 | data.fColors, data.fPos, data.fCount, tm, |
| 136 | 0, &localMatrix); |
commit-bot@chromium.org | c8379d7 | 2014-04-22 20:56:37 +0000 | [diff] [blame] | 137 | } |
| 138 | |
reed | 1a9b964 | 2016-03-13 14:13:58 -0700 | [diff] [blame] | 139 | static sk_sp<SkShader> Make2ConicalZeroRadOutside(const SkPoint pts[2], const GradData& data, |
| 140 | SkShader::TileMode tm, |
| 141 | const SkMatrix& localMatrix) { |
commit-bot@chromium.org | c8379d7 | 2014-04-22 20:56:37 +0000 | [diff] [blame] | 142 | SkPoint center0, center1; |
commit-bot@chromium.org | 8089467 | 2014-04-22 21:24:22 +0000 | [diff] [blame] | 143 | SkScalar radius0 = 0.f; |
reed | 80ea19c | 2015-05-12 10:37:34 -0700 | [diff] [blame] | 144 | SkScalar radius1 = (pts[1].fX - pts[0].fX) / 3; |
commit-bot@chromium.org | c8379d7 | 2014-04-22 20:56:37 +0000 | [diff] [blame] | 145 | center0.set(pts[0].fX + radius0, pts[0].fY + radius0); |
| 146 | center1.set(pts[1].fX - radius1, pts[1].fY - radius1); |
reed | 1a9b964 | 2016-03-13 14:13:58 -0700 | [diff] [blame] | 147 | return SkGradientShader::MakeTwoPointConical(center0, radius0, center1, radius1, |
| 148 | data.fColors, data.fPos, |
| 149 | data.fCount, tm, 0, &localMatrix); |
commit-bot@chromium.org | c8379d7 | 2014-04-22 20:56:37 +0000 | [diff] [blame] | 150 | } |
| 151 | |
reed | 1a9b964 | 2016-03-13 14:13:58 -0700 | [diff] [blame] | 152 | static sk_sp<SkShader> Make2ConicalZeroRadFlipOutside(const SkPoint pts[2], const GradData& data, |
| 153 | SkShader::TileMode tm, |
| 154 | const SkMatrix& localMatrix) { |
commit-bot@chromium.org | c8379d7 | 2014-04-22 20:56:37 +0000 | [diff] [blame] | 155 | SkPoint center0, center1; |
commit-bot@chromium.org | 8089467 | 2014-04-22 21:24:22 +0000 | [diff] [blame] | 156 | SkScalar radius0 = 0.f; |
reed | 80ea19c | 2015-05-12 10:37:34 -0700 | [diff] [blame] | 157 | SkScalar radius1 = (pts[1].fX - pts[0].fX) / 3; |
commit-bot@chromium.org | c8379d7 | 2014-04-22 20:56:37 +0000 | [diff] [blame] | 158 | center0.set(pts[0].fX + radius0, pts[0].fY + radius0); |
| 159 | center1.set(pts[1].fX - radius1, pts[1].fY - radius1); |
reed | 1a9b964 | 2016-03-13 14:13:58 -0700 | [diff] [blame] | 160 | return SkGradientShader::MakeTwoPointConical(center1, radius1, center0, radius0, data.fColors, |
| 161 | data.fPos, data.fCount, tm, 0, &localMatrix); |
commit-bot@chromium.org | c8379d7 | 2014-04-22 20:56:37 +0000 | [diff] [blame] | 162 | } |
| 163 | |
reed | 1a9b964 | 2016-03-13 14:13:58 -0700 | [diff] [blame] | 164 | static sk_sp<SkShader> Make2ConicalEdgeX(const SkPoint pts[2], const GradData& data, |
| 165 | SkShader::TileMode tm, const SkMatrix& localMatrix) { |
commit-bot@chromium.org | c8379d7 | 2014-04-22 20:56:37 +0000 | [diff] [blame] | 166 | SkPoint center0, center1; |
reed | 80ea19c | 2015-05-12 10:37:34 -0700 | [diff] [blame] | 167 | SkScalar radius0 = (pts[1].fX - pts[0].fX) / 7; |
| 168 | SkScalar radius1 = (pts[1].fX - pts[0].fX) / 3; |
commit-bot@chromium.org | c8379d7 | 2014-04-22 20:56:37 +0000 | [diff] [blame] | 169 | center1.set(SkScalarAve(pts[0].fX, pts[1].fX), |
| 170 | SkScalarAve(pts[0].fY, pts[1].fY)); |
| 171 | center0.set(center1.fX + radius1, center1.fY); |
reed | 1a9b964 | 2016-03-13 14:13:58 -0700 | [diff] [blame] | 172 | return SkGradientShader::MakeTwoPointConical(center0, radius0, center1, radius1, data.fColors, |
| 173 | data.fPos, data.fCount, tm, 0, &localMatrix); |
commit-bot@chromium.org | c8379d7 | 2014-04-22 20:56:37 +0000 | [diff] [blame] | 174 | } |
| 175 | |
reed | 1a9b964 | 2016-03-13 14:13:58 -0700 | [diff] [blame] | 176 | static sk_sp<SkShader> Make2ConicalEdgeY(const SkPoint pts[2], const GradData& data, |
| 177 | SkShader::TileMode tm, const SkMatrix& localMatrix) { |
commit-bot@chromium.org | c8379d7 | 2014-04-22 20:56:37 +0000 | [diff] [blame] | 178 | SkPoint center0, center1; |
reed | 80ea19c | 2015-05-12 10:37:34 -0700 | [diff] [blame] | 179 | SkScalar radius0 = (pts[1].fX - pts[0].fX) / 7; |
| 180 | SkScalar radius1 = (pts[1].fX - pts[0].fX) / 3; |
commit-bot@chromium.org | c8379d7 | 2014-04-22 20:56:37 +0000 | [diff] [blame] | 181 | center1.set(SkScalarAve(pts[0].fX, pts[1].fX), |
| 182 | SkScalarAve(pts[0].fY, pts[1].fY)); |
| 183 | center0.set(center1.fX, center1.fY + radius1); |
reed | 1a9b964 | 2016-03-13 14:13:58 -0700 | [diff] [blame] | 184 | return SkGradientShader::MakeTwoPointConical(center0, radius0, center1, radius1, data.fColors, |
| 185 | data.fPos, data.fCount, tm, 0, &localMatrix); |
commit-bot@chromium.org | c8379d7 | 2014-04-22 20:56:37 +0000 | [diff] [blame] | 186 | } |
egdaniel | 8405ef9 | 2014-06-09 11:57:28 -0700 | [diff] [blame] | 187 | |
reed | 1a9b964 | 2016-03-13 14:13:58 -0700 | [diff] [blame] | 188 | static sk_sp<SkShader> Make2ConicalZeroRadEdgeX(const SkPoint pts[2], const GradData& data, |
| 189 | SkShader::TileMode tm, |
| 190 | const SkMatrix& localMatrix) { |
commit-bot@chromium.org | c8379d7 | 2014-04-22 20:56:37 +0000 | [diff] [blame] | 191 | SkPoint center0, center1; |
commit-bot@chromium.org | 8089467 | 2014-04-22 21:24:22 +0000 | [diff] [blame] | 192 | SkScalar radius0 = 0.f; |
reed | 80ea19c | 2015-05-12 10:37:34 -0700 | [diff] [blame] | 193 | SkScalar radius1 = (pts[1].fX - pts[0].fX) / 3; |
commit-bot@chromium.org | c8379d7 | 2014-04-22 20:56:37 +0000 | [diff] [blame] | 194 | center1.set(SkScalarAve(pts[0].fX, pts[1].fX), |
| 195 | SkScalarAve(pts[0].fY, pts[1].fY)); |
| 196 | center0.set(center1.fX + radius1, center1.fY); |
reed | 1a9b964 | 2016-03-13 14:13:58 -0700 | [diff] [blame] | 197 | return SkGradientShader::MakeTwoPointConical(center0, radius0, center1, radius1, data.fColors, |
| 198 | data.fPos, data.fCount, tm, 0, &localMatrix); |
commit-bot@chromium.org | c8379d7 | 2014-04-22 20:56:37 +0000 | [diff] [blame] | 199 | } |
| 200 | |
reed | 1a9b964 | 2016-03-13 14:13:58 -0700 | [diff] [blame] | 201 | static sk_sp<SkShader> Make2ConicalZeroRadEdgeY(const SkPoint pts[2], const GradData& data, |
| 202 | SkShader::TileMode tm, const SkMatrix& localMatrix) { |
commit-bot@chromium.org | c8379d7 | 2014-04-22 20:56:37 +0000 | [diff] [blame] | 203 | SkPoint center0, center1; |
commit-bot@chromium.org | 8089467 | 2014-04-22 21:24:22 +0000 | [diff] [blame] | 204 | SkScalar radius0 = 0.f; |
reed | 80ea19c | 2015-05-12 10:37:34 -0700 | [diff] [blame] | 205 | SkScalar radius1 = (pts[1].fX - pts[0].fX) / 3; |
commit-bot@chromium.org | c8379d7 | 2014-04-22 20:56:37 +0000 | [diff] [blame] | 206 | center1.set(SkScalarAve(pts[0].fX, pts[1].fX), |
| 207 | SkScalarAve(pts[0].fY, pts[1].fY)); |
| 208 | center0.set(center1.fX, center1.fY + radius1); |
reed | 1a9b964 | 2016-03-13 14:13:58 -0700 | [diff] [blame] | 209 | return SkGradientShader::MakeTwoPointConical(center0, radius0, center1, radius1, data.fColors, |
| 210 | data.fPos, data.fCount, tm, 0, &localMatrix); |
commit-bot@chromium.org | c8379d7 | 2014-04-22 20:56:37 +0000 | [diff] [blame] | 211 | } |
| 212 | |
reed | 1a9b964 | 2016-03-13 14:13:58 -0700 | [diff] [blame] | 213 | static sk_sp<SkShader> Make2ConicalTouchX(const SkPoint pts[2], const GradData& data, |
| 214 | SkShader::TileMode tm, const SkMatrix& localMatrix) { |
commit-bot@chromium.org | c8379d7 | 2014-04-22 20:56:37 +0000 | [diff] [blame] | 215 | SkPoint center0, center1; |
reed | 80ea19c | 2015-05-12 10:37:34 -0700 | [diff] [blame] | 216 | SkScalar radius0 = (pts[1].fX - pts[0].fX) / 7; |
| 217 | SkScalar radius1 = (pts[1].fX - pts[0].fX) / 3; |
commit-bot@chromium.org | c8379d7 | 2014-04-22 20:56:37 +0000 | [diff] [blame] | 218 | center1.set(SkScalarAve(pts[0].fX, pts[1].fX), |
| 219 | SkScalarAve(pts[0].fY, pts[1].fY)); |
| 220 | center0.set(center1.fX - radius1 + radius0, center1.fY); |
reed | 1a9b964 | 2016-03-13 14:13:58 -0700 | [diff] [blame] | 221 | return SkGradientShader::MakeTwoPointConical(center0, radius0, center1, radius1, data.fColors, |
| 222 | data.fPos, data.fCount, tm, 0, &localMatrix); |
commit-bot@chromium.org | c8379d7 | 2014-04-22 20:56:37 +0000 | [diff] [blame] | 223 | } |
| 224 | |
reed | 1a9b964 | 2016-03-13 14:13:58 -0700 | [diff] [blame] | 225 | static sk_sp<SkShader> Make2ConicalTouchY(const SkPoint pts[2], const GradData& data, |
| 226 | SkShader::TileMode tm, const SkMatrix& localMatrix) { |
commit-bot@chromium.org | c8379d7 | 2014-04-22 20:56:37 +0000 | [diff] [blame] | 227 | SkPoint center0, center1; |
reed | 80ea19c | 2015-05-12 10:37:34 -0700 | [diff] [blame] | 228 | SkScalar radius0 = (pts[1].fX - pts[0].fX) / 7; |
| 229 | SkScalar radius1 = (pts[1].fX - pts[0].fX) / 3; |
commit-bot@chromium.org | c8379d7 | 2014-04-22 20:56:37 +0000 | [diff] [blame] | 230 | center1.set(SkScalarAve(pts[0].fX, pts[1].fX), |
| 231 | SkScalarAve(pts[0].fY, pts[1].fY)); |
| 232 | center0.set(center1.fX, center1.fY + radius1 - radius0); |
reed | 1a9b964 | 2016-03-13 14:13:58 -0700 | [diff] [blame] | 233 | return SkGradientShader::MakeTwoPointConical(center0, radius0, center1, radius1, data.fColors, |
| 234 | data.fPos, data.fCount, tm, 0, &localMatrix); |
commit-bot@chromium.org | c8379d7 | 2014-04-22 20:56:37 +0000 | [diff] [blame] | 235 | } |
| 236 | |
reed | 1a9b964 | 2016-03-13 14:13:58 -0700 | [diff] [blame] | 237 | static sk_sp<SkShader> Make2ConicalInsideSmallRad(const SkPoint pts[2], const GradData& data, |
commit-bot@chromium.org | 83f23d8 | 2014-05-22 12:27:41 +0000 | [diff] [blame] | 238 | SkShader::TileMode tm, const SkMatrix& localMatrix) { |
commit-bot@chromium.org | c8379d7 | 2014-04-22 20:56:37 +0000 | [diff] [blame] | 239 | SkPoint center0, center1; |
| 240 | center0.set(SkScalarAve(pts[0].fX, pts[1].fX), |
| 241 | SkScalarAve(pts[0].fY, pts[1].fY)); |
| 242 | center1.set(SkScalarInterp(pts[0].fX, pts[1].fX, SkIntToScalar(3)/5), |
| 243 | SkScalarInterp(pts[0].fY, pts[1].fY, SkIntToScalar(1)/4)); |
reed | 1a9b964 | 2016-03-13 14:13:58 -0700 | [diff] [blame] | 244 | return SkGradientShader::MakeTwoPointConical(center0, 0.0000000000000000001f, |
commit-bot@chromium.org | 9c9005a | 2014-04-28 14:55:39 +0000 | [diff] [blame] | 245 | center0, (pts[1].fX - pts[0].fX) / 2, |
commit-bot@chromium.org | 83f23d8 | 2014-05-22 12:27:41 +0000 | [diff] [blame] | 246 | data.fColors, data.fPos, data.fCount, tm, |
commit-bot@chromium.org | 9c9005a | 2014-04-28 14:55:39 +0000 | [diff] [blame] | 247 | 0, &localMatrix); |
commit-bot@chromium.org | c8379d7 | 2014-04-22 20:56:37 +0000 | [diff] [blame] | 248 | } |
| 249 | |
reed | 1a9b964 | 2016-03-13 14:13:58 -0700 | [diff] [blame] | 250 | typedef sk_sp<SkShader> (*GradMaker)(const SkPoint pts[2], const GradData& data, |
| 251 | SkShader::TileMode tm, const SkMatrix& localMatrix); |
commit-bot@chromium.org | c8379d7 | 2014-04-22 20:56:37 +0000 | [diff] [blame] | 252 | |
| 253 | static const GradMaker gGradMakersOutside[] = { |
| 254 | Make2ConicalOutside, Make2ConicalOutsideFlip, |
| 255 | Make2ConicalZeroRadOutside, Make2ConicalZeroRadFlipOutside |
| 256 | }; |
| 257 | |
| 258 | static const GradMaker gGradMakersInside[] = { |
| 259 | Make2ConicalInside, Make2ConicalInsideFlip, Make2ConicalInsideCenter, |
| 260 | Make2ConicalZeroRad, Make2ConicalZeroRadFlip, Make2ConicalZeroRadCenter, |
| 261 | }; |
| 262 | |
| 263 | static const GradMaker gGradMakersEdgeCases[] = { |
| 264 | Make2ConicalEdgeX, Make2ConicalEdgeY, |
| 265 | Make2ConicalZeroRadEdgeX, Make2ConicalZeroRadEdgeY, |
| 266 | Make2ConicalTouchX, Make2ConicalTouchY, |
| 267 | Make2ConicalInsideSmallRad |
| 268 | }; |
| 269 | |
| 270 | |
| 271 | static const struct { |
| 272 | const GradMaker* fMaker; |
| 273 | const int fCount; |
| 274 | const char* fName; |
| 275 | } gGradCases[] = { |
| 276 | { gGradMakersOutside, SK_ARRAY_COUNT(gGradMakersOutside), "outside" }, |
| 277 | { gGradMakersInside, SK_ARRAY_COUNT(gGradMakersInside), "inside" }, |
| 278 | { gGradMakersEdgeCases, SK_ARRAY_COUNT(gGradMakersEdgeCases), "edge" }, |
| 279 | }; |
| 280 | |
| 281 | enum GradCaseType { // these must match the order in gGradCases |
| 282 | kOutside_GradCaseType, |
| 283 | kInside_GradCaseType, |
| 284 | kEdge_GradCaseType, |
| 285 | }; |
| 286 | |
| 287 | /////////////////////////////////////////////////////////////////////////////// |
| 288 | |
| 289 | class ConicalGradientsGM : public GM { |
| 290 | public: |
fmalita | 063675b | 2015-10-12 10:41:48 -0700 | [diff] [blame] | 291 | ConicalGradientsGM(GradCaseType gradCaseType, bool dither) |
| 292 | : fGradCaseType(gradCaseType) |
| 293 | , fDither(dither) { |
caryclark | 65cdba6 | 2015-06-15 06:51:08 -0700 | [diff] [blame] | 294 | this->setBGColor(sk_tool_utils::color_to_565(0xFFDDDDDD)); |
fmalita | 063675b | 2015-10-12 10:41:48 -0700 | [diff] [blame] | 295 | fName.printf("gradients_2pt_conical_%s%s", gGradCases[gradCaseType].fName, |
| 296 | fDither ? "" : "_nodither"); |
commit-bot@chromium.org | c8379d7 | 2014-04-22 20:56:37 +0000 | [diff] [blame] | 297 | } |
| 298 | |
| 299 | protected: |
| 300 | SkString onShortName() { |
| 301 | return fName; |
| 302 | } |
| 303 | |
| 304 | virtual SkISize onISize() { return SkISize::Make(840, 815); } |
| 305 | |
| 306 | virtual void onDraw(SkCanvas* canvas) { |
| 307 | |
| 308 | SkPoint pts[2] = { |
| 309 | { 0, 0 }, |
| 310 | { SkIntToScalar(100), SkIntToScalar(100) } |
| 311 | }; |
| 312 | SkShader::TileMode tm = SkShader::kClamp_TileMode; |
| 313 | SkRect r = { 0, 0, SkIntToScalar(100), SkIntToScalar(100) }; |
| 314 | SkPaint paint; |
| 315 | paint.setAntiAlias(true); |
fmalita | 063675b | 2015-10-12 10:41:48 -0700 | [diff] [blame] | 316 | paint.setDither(fDither); |
commit-bot@chromium.org | c8379d7 | 2014-04-22 20:56:37 +0000 | [diff] [blame] | 317 | |
| 318 | canvas->translate(SkIntToScalar(20), SkIntToScalar(20)); |
| 319 | |
| 320 | const GradMaker* gradMaker = gGradCases[fGradCaseType].fMaker; |
| 321 | const int count = gGradCases[fGradCaseType].fCount; |
| 322 | |
| 323 | for (size_t i = 0; i < SK_ARRAY_COUNT(gGradData); i++) { |
| 324 | canvas->save(); |
| 325 | for (int j = 0; j < count; j++) { |
commit-bot@chromium.org | 9c9005a | 2014-04-28 14:55:39 +0000 | [diff] [blame] | 326 | SkMatrix scale = SkMatrix::I(); |
commit-bot@chromium.org | c8379d7 | 2014-04-22 20:56:37 +0000 | [diff] [blame] | 327 | |
| 328 | if (i == 3) { // if the clamp case |
commit-bot@chromium.org | c8379d7 | 2014-04-22 20:56:37 +0000 | [diff] [blame] | 329 | scale.setScale(0.5f, 0.5f); |
| 330 | scale.postTranslate(25.f, 25.f); |
commit-bot@chromium.org | c8379d7 | 2014-04-22 20:56:37 +0000 | [diff] [blame] | 331 | } |
| 332 | |
reed | 1a9b964 | 2016-03-13 14:13:58 -0700 | [diff] [blame] | 333 | paint.setShader(gradMaker[j](pts, gGradData[i], tm, scale)); |
commit-bot@chromium.org | c8379d7 | 2014-04-22 20:56:37 +0000 | [diff] [blame] | 334 | canvas->drawRect(r, paint); |
commit-bot@chromium.org | c8379d7 | 2014-04-22 20:56:37 +0000 | [diff] [blame] | 335 | canvas->translate(0, SkIntToScalar(120)); |
| 336 | } |
| 337 | canvas->restore(); |
| 338 | canvas->translate(SkIntToScalar(120), 0); |
| 339 | } |
| 340 | } |
| 341 | |
| 342 | private: |
| 343 | typedef GM INHERITED; |
| 344 | |
| 345 | GradCaseType fGradCaseType; |
| 346 | SkString fName; |
fmalita | 063675b | 2015-10-12 10:41:48 -0700 | [diff] [blame] | 347 | bool fDither; |
commit-bot@chromium.org | c8379d7 | 2014-04-22 20:56:37 +0000 | [diff] [blame] | 348 | }; |
| 349 | /////////////////////////////////////////////////////////////////////////////// |
| 350 | |
fmalita | 063675b | 2015-10-12 10:41:48 -0700 | [diff] [blame] | 351 | DEF_GM( return new ConicalGradientsGM(kInside_GradCaseType, true); ) |
| 352 | DEF_GM( return new ConicalGradientsGM(kOutside_GradCaseType, true); ) |
| 353 | DEF_GM( return new ConicalGradientsGM(kEdge_GradCaseType, true); ) |
commit-bot@chromium.org | c8379d7 | 2014-04-22 20:56:37 +0000 | [diff] [blame] | 354 | |
fmalita | 063675b | 2015-10-12 10:41:48 -0700 | [diff] [blame] | 355 | DEF_GM( return new ConicalGradientsGM(kInside_GradCaseType, false); ) |
| 356 | DEF_GM( return new ConicalGradientsGM(kOutside_GradCaseType, false); ) |
| 357 | DEF_GM( return new ConicalGradientsGM(kEdge_GradCaseType, false); ) |
commit-bot@chromium.org | c8379d7 | 2014-04-22 20:56:37 +0000 | [diff] [blame] | 358 | |
commit-bot@chromium.org | c8379d7 | 2014-04-22 20:56:37 +0000 | [diff] [blame] | 359 | } |