OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "gm.h" | 8 #include "gm.h" |
9 #include "SkGradientShader.h" | 9 #include "SkGradientShader.h" |
10 | 10 |
(...skipping 19 matching lines...) Expand all Loading... |
30 SK_ColorRED, SK_ColorGREEN, SK_ColorGREEN, SK_ColorBLUE | 30 SK_ColorRED, SK_ColorGREEN, SK_ColorGREEN, SK_ColorBLUE |
31 }; | 31 }; |
32 | 32 |
33 static const GradData gGradData[] = { | 33 static const GradData gGradData[] = { |
34 { 2, gColors, gPos0 }, | 34 { 2, gColors, gPos0 }, |
35 { 2, gColors, gPos1 }, | 35 { 2, gColors, gPos1 }, |
36 { 5, gColors, gPos2 }, | 36 { 5, gColors, gPos2 }, |
37 { 4, gColorClamp, gPosClamp } | 37 { 4, gColorClamp, gPosClamp } |
38 }; | 38 }; |
39 | 39 |
40 static SkShader* Make2ConicalOutside(const SkPoint pts[2], const GradData& data, | 40 static sk_sp<SkShader> Make2ConicalOutside(const SkPoint pts[2], const GradData&
data, |
41 SkShader::TileMode tm, const SkMatrix& loca
lMatrix) { | 41 SkShader::TileMode tm, const SkMatrix
& localMatrix) { |
42 SkPoint center0, center1; | 42 SkPoint center0, center1; |
43 SkScalar radius0 = (pts[1].fX - pts[0].fX) / 10; | 43 SkScalar radius0 = (pts[1].fX - pts[0].fX) / 10; |
44 SkScalar radius1 = (pts[1].fX - pts[0].fX) / 3; | 44 SkScalar radius1 = (pts[1].fX - pts[0].fX) / 3; |
45 center0.set(pts[0].fX + radius0, pts[0].fY + radius0); | 45 center0.set(pts[0].fX + radius0, pts[0].fY + radius0); |
46 center1.set(pts[1].fX - radius1, pts[1].fY - radius1); | 46 center1.set(pts[1].fX - radius1, pts[1].fY - radius1); |
47 return SkGradientShader::CreateTwoPointConical(center0, radius0, | 47 return SkGradientShader::MakeTwoPointConical(center0, radius0, center1, radi
us1, data.fColors, |
48 center1, radius1, | 48 data.fPos, data.fCount, tm, 0,
&localMatrix); |
49 data.fColors, data.fPos, | 49 } |
50 data.fCount, tm, 0, &localMat
rix); | 50 |
51 } | 51 static sk_sp<SkShader> Make2ConicalOutsideFlip(const SkPoint pts[2], const GradD
ata& data, |
52 | |
53 static SkShader* Make2ConicalOutsideFlip(const SkPoint pts[2], const GradData& d
ata, | |
54 SkShader::TileMode tm, const SkMatrix& localMatrix)
{ | 52 SkShader::TileMode tm, const SkMatrix& localMatrix)
{ |
55 SkPoint center0, center1; | 53 SkPoint center0, center1; |
56 SkScalar radius0 = (pts[1].fX - pts[0].fX) / 10; | 54 SkScalar radius0 = (pts[1].fX - pts[0].fX) / 10; |
57 SkScalar radius1 = (pts[1].fX - pts[0].fX) / 3; | 55 SkScalar radius1 = (pts[1].fX - pts[0].fX) / 3; |
58 center0.set(pts[0].fX + radius0, pts[0].fY + radius0); | 56 center0.set(pts[0].fX + radius0, pts[0].fY + radius0); |
59 center1.set(pts[1].fX - radius1, pts[1].fY - radius1); | 57 center1.set(pts[1].fX - radius1, pts[1].fY - radius1); |
60 return SkGradientShader::CreateTwoPointConical(center1, radius1, | 58 return SkGradientShader::MakeTwoPointConical(center1, radius1, center0, radi
us0, data.fColors, |
61 center0, radius0, | 59 data.fPos, data.fCount, tm, 0,
&localMatrix); |
62 data.fColors, data.fPos, | 60 } |
63 data.fCount, tm, 0, &localMat
rix); | 61 |
64 } | 62 static sk_sp<SkShader> Make2ConicalInside(const SkPoint pts[2], const GradData&
data, |
65 | 63 SkShader::TileMode tm, const SkMatrix&
localMatrix) { |
66 static SkShader* Make2ConicalInside(const SkPoint pts[2], const GradData& data, | 64 SkPoint center0, center1; |
67 SkShader::TileMode tm, const SkMatrix& localMatrix)
{ | 65 center0.set(SkScalarAve(pts[0].fX, pts[1].fX), |
68 SkPoint center0, center1; | 66 SkScalarAve(pts[0].fY, pts[1].fY)); |
69 center0.set(SkScalarAve(pts[0].fX, pts[1].fX), | 67 center1.set(SkScalarInterp(pts[0].fX, pts[1].fX, SkIntToScalar(3)/5), |
70 SkScalarAve(pts[0].fY, pts[1].fY)); | 68 SkScalarInterp(pts[0].fY, pts[1].fY, SkIntToScalar(1)/4)); |
71 center1.set(SkScalarInterp(pts[0].fX, pts[1].fX, SkIntToScalar(3)/5), | 69 return SkGradientShader::MakeTwoPointConical(center1, (pts[1].fX - pts[0].fX
) / 7, |
72 SkScalarInterp(pts[0].fY, pts[1].fY, SkIntToScalar(1)/4)); | 70 center0, (pts[1].fX - pts[0].fX
) / 2, |
73 return SkGradientShader::CreateTwoPointConical(center1, (pts[1].fX - pts[0].
fX) / 7, | 71 data.fColors, data.fPos, data.f
Count, tm, |
| 72 0, &localMatrix); |
| 73 } |
| 74 |
| 75 static sk_sp<SkShader> Make2ConicalInsideFlip(const SkPoint pts[2], const GradDa
ta& data, |
| 76 SkShader::TileMode tm, const SkMat
rix& 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.f
Count, tm, |
| 85 0, &localMatrix); |
| 86 } |
| 87 |
| 88 static sk_sp<SkShader> Make2ConicalInsideCenter(const SkPoint pts[2], const Grad
Data& data, |
| 89 SkShader::TileMode tm, const SkMatrix& localMatrix)
{ |
| 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)); |
| 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.f
Count, tm, |
| 98 0, &localMatrix); |
| 99 } |
| 100 |
| 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.f
Count, tm, |
| 111 0, &localMatrix); |
| 112 } |
| 113 |
| 114 static sk_sp<SkShader> Make2ConicalZeroRadFlip(const SkPoint pts[2], const GradD
ata& data, |
| 115 SkShader::TileMode tm, const SkMa
trix& 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.f
Count, tm, |
| 124 0, &localMatrix); |
| 125 } |
| 126 |
| 127 static sk_sp<SkShader> Make2ConicalZeroRadCenter(const SkPoint pts[2], const Gra
dData& data, |
| 128 SkShader::TileMode tm, const SkMatrix& localMatrix)
{ |
| 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)); |
| 134 return SkGradientShader::MakeTwoPointConical(center0, 0.f, center0, (pts[1].
fX - pts[0].fX) / 2, |
| 135 data.fColors, data.fPos, data.f
Count, tm, |
| 136 0, &localMatrix); |
| 137 } |
| 138 |
| 139 static sk_sp<SkShader> Make2ConicalZeroRadOutside(const SkPoint pts[2], const Gr
adData& data, |
| 140 SkShader::TileMode tm, |
| 141 const SkMatrix& localMatrix) { |
| 142 SkPoint center0, center1; |
| 143 SkScalar radius0 = 0.f; |
| 144 SkScalar radius1 = (pts[1].fX - pts[0].fX) / 3; |
| 145 center0.set(pts[0].fX + radius0, pts[0].fY + radius0); |
| 146 center1.set(pts[1].fX - radius1, pts[1].fY - radius1); |
| 147 return SkGradientShader::MakeTwoPointConical(center0, radius0, center1, radi
us1, |
| 148 data.fColors, data.fPos, |
| 149 data.fCount, tm, 0, &localMatri
x); |
| 150 } |
| 151 |
| 152 static sk_sp<SkShader> Make2ConicalZeroRadFlipOutside(const SkPoint pts[2], cons
t GradData& data, |
| 153 SkShader::TileMode tm, |
| 154 const SkMatrix& localMatri
x) { |
| 155 SkPoint center0, center1; |
| 156 SkScalar radius0 = 0.f; |
| 157 SkScalar radius1 = (pts[1].fX - pts[0].fX) / 3; |
| 158 center0.set(pts[0].fX + radius0, pts[0].fY + radius0); |
| 159 center1.set(pts[1].fX - radius1, pts[1].fY - radius1); |
| 160 return SkGradientShader::MakeTwoPointConical(center1, radius1, center0, radi
us0, data.fColors, |
| 161 data.fPos, data.fCount, tm, 0,
&localMatrix); |
| 162 } |
| 163 |
| 164 static sk_sp<SkShader> Make2ConicalEdgeX(const SkPoint pts[2], const GradData& d
ata, |
| 165 SkShader::TileMode tm, const SkMatrix&
localMatrix) { |
| 166 SkPoint center0, center1; |
| 167 SkScalar radius0 = (pts[1].fX - pts[0].fX) / 7; |
| 168 SkScalar radius1 = (pts[1].fX - pts[0].fX) / 3; |
| 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); |
| 172 return SkGradientShader::MakeTwoPointConical(center0, radius0, center1, radi
us1, data.fColors, |
| 173 data.fPos, data.fCount, tm, 0,
&localMatrix); |
| 174 } |
| 175 |
| 176 static sk_sp<SkShader> Make2ConicalEdgeY(const SkPoint pts[2], const GradData& d
ata, |
| 177 SkShader::TileMode tm, const SkMatrix&
localMatrix) { |
| 178 SkPoint center0, center1; |
| 179 SkScalar radius0 = (pts[1].fX - pts[0].fX) / 7; |
| 180 SkScalar radius1 = (pts[1].fX - pts[0].fX) / 3; |
| 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); |
| 184 return SkGradientShader::MakeTwoPointConical(center0, radius0, center1, radi
us1, data.fColors, |
| 185 data.fPos, data.fCount, tm, 0,
&localMatrix); |
| 186 } |
| 187 |
| 188 static sk_sp<SkShader> Make2ConicalZeroRadEdgeX(const SkPoint pts[2], const Grad
Data& data, |
| 189 SkShader::TileMode tm, |
| 190 const SkMatrix& localMatrix) { |
| 191 SkPoint center0, center1; |
| 192 SkScalar radius0 = 0.f; |
| 193 SkScalar radius1 = (pts[1].fX - pts[0].fX) / 3; |
| 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); |
| 197 return SkGradientShader::MakeTwoPointConical(center0, radius0, center1, radi
us1, data.fColors, |
| 198 data.fPos, data.fCount, tm, 0,
&localMatrix); |
| 199 } |
| 200 |
| 201 static sk_sp<SkShader> Make2ConicalZeroRadEdgeY(const SkPoint pts[2], const Grad
Data& data, |
| 202 SkShader::TileMode tm, const SkM
atrix& localMatrix) { |
| 203 SkPoint center0, center1; |
| 204 SkScalar radius0 = 0.f; |
| 205 SkScalar radius1 = (pts[1].fX - pts[0].fX) / 3; |
| 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); |
| 209 return SkGradientShader::MakeTwoPointConical(center0, radius0, center1, radi
us1, data.fColors, |
| 210 data.fPos, data.fCount, tm, 0,
&localMatrix); |
| 211 } |
| 212 |
| 213 static sk_sp<SkShader> Make2ConicalTouchX(const SkPoint pts[2], const GradData&
data, |
| 214 SkShader::TileMode tm, const SkMatrix&
localMatrix) { |
| 215 SkPoint center0, center1; |
| 216 SkScalar radius0 = (pts[1].fX - pts[0].fX) / 7; |
| 217 SkScalar radius1 = (pts[1].fX - pts[0].fX) / 3; |
| 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); |
| 221 return SkGradientShader::MakeTwoPointConical(center0, radius0, center1, radi
us1, data.fColors, |
| 222 data.fPos, data.fCount, tm, 0,
&localMatrix); |
| 223 } |
| 224 |
| 225 static sk_sp<SkShader> Make2ConicalTouchY(const SkPoint pts[2], const GradData&
data, |
| 226 SkShader::TileMode tm, const SkMatrix&
localMatrix) { |
| 227 SkPoint center0, center1; |
| 228 SkScalar radius0 = (pts[1].fX - pts[0].fX) / 7; |
| 229 SkScalar radius1 = (pts[1].fX - pts[0].fX) / 3; |
| 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); |
| 233 return SkGradientShader::MakeTwoPointConical(center0, radius0, center1, radi
us1, data.fColors, |
| 234 data.fPos, data.fCount, tm, 0,
&localMatrix); |
| 235 } |
| 236 |
| 237 static sk_sp<SkShader> Make2ConicalInsideSmallRad(const SkPoint pts[2], const Gr
adData& data, |
| 238 SkShader::TileMode tm, const SkMatrix& localMatrix)
{ |
| 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)); |
| 244 return SkGradientShader::MakeTwoPointConical(center0, 0.0000000000000000001f
, |
74 center0, (pts[1].fX - pts[0].
fX) / 2, | 245 center0, (pts[1].fX - pts[0].
fX) / 2, |
75 data.fColors, data.fPos, data
.fCount, tm, | 246 data.fColors, data.fPos, data
.fCount, tm, |
76 0, &localMatrix); | 247 0, &localMatrix); |
77 } | 248 } |
78 | 249 |
79 static SkShader* Make2ConicalInsideFlip(const SkPoint pts[2], const GradData& da
ta, | 250 typedef sk_sp<SkShader> (*GradMaker)(const SkPoint pts[2], const GradData& data, |
80 SkShader::TileMode tm, const SkMatrix& localMatrix)
{ | 251 SkShader::TileMode tm, const SkMatrix& loca
lMatrix); |
81 SkPoint center0, center1; | |
82 center0.set(SkScalarAve(pts[0].fX, pts[1].fX), | |
83 SkScalarAve(pts[0].fY, pts[1].fY)); | |
84 center1.set(SkScalarInterp(pts[0].fX, pts[1].fX, SkIntToScalar(3)/5), | |
85 SkScalarInterp(pts[0].fY, pts[1].fY, SkIntToScalar(1)/4)); | |
86 return SkGradientShader::CreateTwoPointConical(center0, (pts[1].fX - pts[0].
fX) / 2, | |
87 center1, (pts[1].fX - pts[0].
fX) / 7, | |
88 data.fColors, data.fPos, data
.fCount, tm, | |
89 0, &localMatrix); | |
90 } | |
91 | |
92 static SkShader* Make2ConicalInsideCenter(const SkPoint pts[2], const GradData&
data, | |
93 SkShader::TileMode tm, const SkMatrix& localMatrix)
{ | |
94 SkPoint center0, center1; | |
95 center0.set(SkScalarAve(pts[0].fX, pts[1].fX), | |
96 SkScalarAve(pts[0].fY, pts[1].fY)); | |
97 center1.set(SkScalarInterp(pts[0].fX, pts[1].fX, SkIntToScalar(3)/5), | |
98 SkScalarInterp(pts[0].fY, pts[1].fY, SkIntToScalar(1)/4)); | |
99 return SkGradientShader::CreateTwoPointConical(center0, (pts[1].fX - pts[0].
fX) / 7, | |
100 center0, (pts[1].fX - pts[0].
fX) / 2, | |
101 data.fColors, data.fPos, data
.fCount, tm, | |
102 0, &localMatrix); | |
103 } | |
104 | |
105 static SkShader* Make2ConicalZeroRad(const SkPoint pts[2], const GradData& data, | |
106 SkShader::TileMode tm, const SkMatrix& localMatrix)
{ | |
107 SkPoint center0, center1; | |
108 center0.set(SkScalarAve(pts[0].fX, pts[1].fX), | |
109 SkScalarAve(pts[0].fY, pts[1].fY)); | |
110 center1.set(SkScalarInterp(pts[0].fX, pts[1].fX, SkIntToScalar(3)/5), | |
111 SkScalarInterp(pts[0].fY, pts[1].fY, SkIntToScalar(1)/4)); | |
112 return SkGradientShader::CreateTwoPointConical(center1, 0.f, | |
113 center0, (pts[1].fX - pts[0].
fX) / 2, | |
114 data.fColors, data.fPos, data
.fCount, tm, | |
115 0, &localMatrix); | |
116 } | |
117 | |
118 static SkShader* Make2ConicalZeroRadFlip(const SkPoint pts[2], const GradData& d
ata, | |
119 SkShader::TileMode tm, const SkMatrix& localMatrix)
{ | |
120 SkPoint center0, center1; | |
121 center0.set(SkScalarAve(pts[0].fX, pts[1].fX), | |
122 SkScalarAve(pts[0].fY, pts[1].fY)); | |
123 center1.set(SkScalarInterp(pts[0].fX, pts[1].fX, SkIntToScalar(3)/5), | |
124 SkScalarInterp(pts[0].fY, pts[1].fY, SkIntToScalar(1)/4)); | |
125 return SkGradientShader::CreateTwoPointConical(center1, (pts[1].fX - pts[0].
fX) / 2, | |
126 center0, 0.f, | |
127 data.fColors, data.fPos, data
.fCount, tm, | |
128 0, &localMatrix); | |
129 } | |
130 | |
131 static SkShader* Make2ConicalZeroRadCenter(const SkPoint pts[2], const GradData&
data, | |
132 SkShader::TileMode tm, const SkMatrix& localMatrix)
{ | |
133 SkPoint center0, center1; | |
134 center0.set(SkScalarAve(pts[0].fX, pts[1].fX), | |
135 SkScalarAve(pts[0].fY, pts[1].fY)); | |
136 center1.set(SkScalarInterp(pts[0].fX, pts[1].fX, SkIntToScalar(3)/5), | |
137 SkScalarInterp(pts[0].fY, pts[1].fY, SkIntToScalar(1)/4)); | |
138 return SkGradientShader::CreateTwoPointConical(center0, 0.f, | |
139 center0, (pts[1].fX - pts[0].
fX) / 2, | |
140 data.fColors, data.fPos, data
.fCount, tm, | |
141 0, &localMatrix); | |
142 } | |
143 | |
144 static SkShader* Make2ConicalZeroRadOutside(const SkPoint pts[2], const GradData
& data, | |
145 SkShader::TileMode tm, const SkMatrix& localMatrix)
{ | |
146 SkPoint center0, center1; | |
147 SkScalar radius0 = 0.f; | |
148 SkScalar radius1 = (pts[1].fX - pts[0].fX) / 3; | |
149 center0.set(pts[0].fX + radius0, pts[0].fY + radius0); | |
150 center1.set(pts[1].fX - radius1, pts[1].fY - radius1); | |
151 return SkGradientShader::CreateTwoPointConical(center0, radius0, | |
152 center1, radius1, | |
153 data.fColors, data.fPos, | |
154 data.fCount, tm, 0, &localMat
rix); | |
155 } | |
156 | |
157 static SkShader* Make2ConicalZeroRadFlipOutside(const SkPoint pts[2], const Grad
Data& data, | |
158 SkShader::TileMode tm, const SkMatrix& localMatrix)
{ | |
159 SkPoint center0, center1; | |
160 SkScalar radius0 = 0.f; | |
161 SkScalar radius1 = (pts[1].fX - pts[0].fX) / 3; | |
162 center0.set(pts[0].fX + radius0, pts[0].fY + radius0); | |
163 center1.set(pts[1].fX - radius1, pts[1].fY - radius1); | |
164 return SkGradientShader::CreateTwoPointConical(center1, radius1, | |
165 center0, radius0, | |
166 data.fColors, data.fPos, | |
167 data.fCount, tm, 0, &localMat
rix); | |
168 } | |
169 | |
170 static SkShader* Make2ConicalEdgeX(const SkPoint pts[2], const GradData& data, | |
171 SkShader::TileMode tm, const SkMatrix& localMatrix)
{ | |
172 SkPoint center0, center1; | |
173 SkScalar radius0 = (pts[1].fX - pts[0].fX) / 7; | |
174 SkScalar radius1 = (pts[1].fX - pts[0].fX) / 3; | |
175 center1.set(SkScalarAve(pts[0].fX, pts[1].fX), | |
176 SkScalarAve(pts[0].fY, pts[1].fY)); | |
177 center0.set(center1.fX + radius1, center1.fY); | |
178 return SkGradientShader::CreateTwoPointConical(center0, radius0, | |
179 center1, radius1, | |
180 data.fColors, data.fPos, | |
181 data.fCount, tm, 0, &localMat
rix); | |
182 } | |
183 | |
184 static SkShader* Make2ConicalEdgeY(const SkPoint pts[2], const GradData& data, | |
185 SkShader::TileMode tm, const SkMatrix& localMatrix)
{ | |
186 SkPoint center0, center1; | |
187 SkScalar radius0 = (pts[1].fX - pts[0].fX) / 7; | |
188 SkScalar radius1 = (pts[1].fX - pts[0].fX) / 3; | |
189 center1.set(SkScalarAve(pts[0].fX, pts[1].fX), | |
190 SkScalarAve(pts[0].fY, pts[1].fY)); | |
191 center0.set(center1.fX, center1.fY + radius1); | |
192 return SkGradientShader::CreateTwoPointConical(center0, radius0, | |
193 center1, radius1, | |
194 data.fColors, data.fPos, | |
195 data.fCount, tm, 0, &localMat
rix); | |
196 } | |
197 | |
198 static SkShader* Make2ConicalZeroRadEdgeX(const SkPoint pts[2], const GradData&
data, | |
199 SkShader::TileMode tm, const SkMatrix& localMatrix)
{ | |
200 SkPoint center0, center1; | |
201 SkScalar radius0 = 0.f; | |
202 SkScalar radius1 = (pts[1].fX - pts[0].fX) / 3; | |
203 center1.set(SkScalarAve(pts[0].fX, pts[1].fX), | |
204 SkScalarAve(pts[0].fY, pts[1].fY)); | |
205 center0.set(center1.fX + radius1, center1.fY); | |
206 return SkGradientShader::CreateTwoPointConical(center0, radius0, | |
207 center1, radius1, | |
208 data.fColors, data.fPos, | |
209 data.fCount, tm, 0, &localMat
rix); | |
210 } | |
211 | |
212 static SkShader* Make2ConicalZeroRadEdgeY(const SkPoint pts[2], const GradData&
data, | |
213 SkShader::TileMode tm, const SkMatrix& localMatrix)
{ | |
214 SkPoint center0, center1; | |
215 SkScalar radius0 = 0.f; | |
216 SkScalar radius1 = (pts[1].fX - pts[0].fX) / 3; | |
217 center1.set(SkScalarAve(pts[0].fX, pts[1].fX), | |
218 SkScalarAve(pts[0].fY, pts[1].fY)); | |
219 center0.set(center1.fX, center1.fY + radius1); | |
220 return SkGradientShader::CreateTwoPointConical(center0, radius0, | |
221 center1, radius1, | |
222 data.fColors, data.fPos, | |
223 data.fCount, tm, 0, &localMat
rix); | |
224 } | |
225 | |
226 static SkShader* Make2ConicalTouchX(const SkPoint pts[2], const GradData& data, | |
227 SkShader::TileMode tm, const SkMatrix& localMatrix)
{ | |
228 SkPoint center0, center1; | |
229 SkScalar radius0 = (pts[1].fX - pts[0].fX) / 7; | |
230 SkScalar radius1 = (pts[1].fX - pts[0].fX) / 3; | |
231 center1.set(SkScalarAve(pts[0].fX, pts[1].fX), | |
232 SkScalarAve(pts[0].fY, pts[1].fY)); | |
233 center0.set(center1.fX - radius1 + radius0, center1.fY); | |
234 return SkGradientShader::CreateTwoPointConical(center0, radius0, | |
235 center1, radius1, | |
236 data.fColors, data.fPos, | |
237 data.fCount, tm, 0, &localMat
rix); | |
238 } | |
239 | |
240 static SkShader* Make2ConicalTouchY(const SkPoint pts[2], const GradData& data, | |
241 SkShader::TileMode tm, const SkMatrix& localMatrix)
{ | |
242 SkPoint center0, center1; | |
243 SkScalar radius0 = (pts[1].fX - pts[0].fX) / 7; | |
244 SkScalar radius1 = (pts[1].fX - pts[0].fX) / 3; | |
245 center1.set(SkScalarAve(pts[0].fX, pts[1].fX), | |
246 SkScalarAve(pts[0].fY, pts[1].fY)); | |
247 center0.set(center1.fX, center1.fY + radius1 - radius0); | |
248 return SkGradientShader::CreateTwoPointConical(center0, radius0, | |
249 center1, radius1, | |
250 data.fColors, data.fPos, | |
251 data.fCount, tm, 0, &localMat
rix); | |
252 } | |
253 | |
254 static SkShader* Make2ConicalInsideSmallRad(const SkPoint pts[2], const GradData
& data, | |
255 SkShader::TileMode tm, const SkMatrix& localMatrix)
{ | |
256 SkPoint center0, center1; | |
257 center0.set(SkScalarAve(pts[0].fX, pts[1].fX), | |
258 SkScalarAve(pts[0].fY, pts[1].fY)); | |
259 center1.set(SkScalarInterp(pts[0].fX, pts[1].fX, SkIntToScalar(3)/5), | |
260 SkScalarInterp(pts[0].fY, pts[1].fY, SkIntToScalar(1)/4)); | |
261 return SkGradientShader::CreateTwoPointConical(center0, 0.000000000000000000
1f, | |
262 center0, (pts[1].fX - pts[0].
fX) / 2, | |
263 data.fColors, data.fPos, data
.fCount, tm, | |
264 0, &localMatrix); | |
265 } | |
266 | |
267 typedef SkShader* (*GradMaker)(const SkPoint pts[2], const GradData& data, | |
268 SkShader::TileMode tm, const SkMatrix& localMatri
x); | |
269 | 252 |
270 static const GradMaker gGradMakersOutside[] = { | 253 static const GradMaker gGradMakersOutside[] = { |
271 Make2ConicalOutside, Make2ConicalOutsideFlip, | 254 Make2ConicalOutside, Make2ConicalOutsideFlip, |
272 Make2ConicalZeroRadOutside, Make2ConicalZeroRadFlipOutside | 255 Make2ConicalZeroRadOutside, Make2ConicalZeroRadFlipOutside |
273 }; | 256 }; |
274 | 257 |
275 static const GradMaker gGradMakersInside[] = { | 258 static const GradMaker gGradMakersInside[] = { |
276 Make2ConicalInside, Make2ConicalInsideFlip, Make2ConicalInsideCenter, | 259 Make2ConicalInside, Make2ConicalInsideFlip, Make2ConicalInsideCenter, |
277 Make2ConicalZeroRad, Make2ConicalZeroRadFlip, Make2ConicalZeroRadCenter, | 260 Make2ConicalZeroRad, Make2ConicalZeroRadFlip, Make2ConicalZeroRadCenter, |
278 }; | 261 }; |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
340 for (size_t i = 0; i < SK_ARRAY_COUNT(gGradData); i++) { | 323 for (size_t i = 0; i < SK_ARRAY_COUNT(gGradData); i++) { |
341 canvas->save(); | 324 canvas->save(); |
342 for (int j = 0; j < count; j++) { | 325 for (int j = 0; j < count; j++) { |
343 SkMatrix scale = SkMatrix::I(); | 326 SkMatrix scale = SkMatrix::I(); |
344 | 327 |
345 if (i == 3) { // if the clamp case | 328 if (i == 3) { // if the clamp case |
346 scale.setScale(0.5f, 0.5f); | 329 scale.setScale(0.5f, 0.5f); |
347 scale.postTranslate(25.f, 25.f); | 330 scale.postTranslate(25.f, 25.f); |
348 } | 331 } |
349 | 332 |
350 SkShader* shader = gradMaker[j](pts, gGradData[i], tm, scale); | 333 paint.setShader(gradMaker[j](pts, gGradData[i], tm, scale)); |
351 paint.setShader(shader); | |
352 canvas->drawRect(r, paint); | 334 canvas->drawRect(r, paint); |
353 shader->unref(); | |
354 canvas->translate(0, SkIntToScalar(120)); | 335 canvas->translate(0, SkIntToScalar(120)); |
355 } | 336 } |
356 canvas->restore(); | 337 canvas->restore(); |
357 canvas->translate(SkIntToScalar(120), 0); | 338 canvas->translate(SkIntToScalar(120), 0); |
358 } | 339 } |
359 } | 340 } |
360 | 341 |
361 private: | 342 private: |
362 typedef GM INHERITED; | 343 typedef GM INHERITED; |
363 | 344 |
364 GradCaseType fGradCaseType; | 345 GradCaseType fGradCaseType; |
365 SkString fName; | 346 SkString fName; |
366 bool fDither; | 347 bool fDither; |
367 }; | 348 }; |
368 /////////////////////////////////////////////////////////////////////////////// | 349 /////////////////////////////////////////////////////////////////////////////// |
369 | 350 |
370 DEF_GM( return new ConicalGradientsGM(kInside_GradCaseType, true); ) | 351 DEF_GM( return new ConicalGradientsGM(kInside_GradCaseType, true); ) |
371 DEF_GM( return new ConicalGradientsGM(kOutside_GradCaseType, true); ) | 352 DEF_GM( return new ConicalGradientsGM(kOutside_GradCaseType, true); ) |
372 DEF_GM( return new ConicalGradientsGM(kEdge_GradCaseType, true); ) | 353 DEF_GM( return new ConicalGradientsGM(kEdge_GradCaseType, true); ) |
373 | 354 |
374 DEF_GM( return new ConicalGradientsGM(kInside_GradCaseType, false); ) | 355 DEF_GM( return new ConicalGradientsGM(kInside_GradCaseType, false); ) |
375 DEF_GM( return new ConicalGradientsGM(kOutside_GradCaseType, false); ) | 356 DEF_GM( return new ConicalGradientsGM(kOutside_GradCaseType, false); ) |
376 DEF_GM( return new ConicalGradientsGM(kEdge_GradCaseType, false); ) | 357 DEF_GM( return new ConicalGradientsGM(kEdge_GradCaseType, false); ) |
377 | 358 |
378 } | 359 } |
OLD | NEW |