OLD | NEW |
1 | |
2 /* | 1 /* |
3 * Copyright 2014 Google Inc. | 2 * Copyright 2014 Google Inc. |
4 * | 3 * |
5 * 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 |
6 * found in the LICENSE file. | 5 * found in the LICENSE file. |
7 */ | 6 */ |
| 7 |
8 #include "gm.h" | 8 #include "gm.h" |
9 #include "SkGradientShader.h" | 9 #include "SkGradientShader.h" |
10 | 10 |
11 namespace skiagm { | 11 namespace skiagm { |
12 | 12 |
13 struct GradData { | 13 struct GradData { |
14 int fCount; | 14 int fCount; |
15 const SkColor* fColors; | 15 const SkColor* fColors; |
16 const SkScalar* fPos; | 16 const SkScalar* fPos; |
17 }; | 17 }; |
(...skipping 13 matching lines...) Expand all Loading... |
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 SkShader* Make2ConicalOutside(const SkPoint pts[2], const GradData& data, |
41 SkShader::TileMode tm, SkUnitMapper* mapper, | 41 SkShader::TileMode tm, const SkMatrix& loca
lMatrix) { |
42 const SkMatrix& localMatrix) { | |
43 SkPoint center0, center1; | 42 SkPoint center0, center1; |
44 SkScalar radius0 = SkScalarDiv(pts[1].fX - pts[0].fX, 10); | 43 SkScalar radius0 = SkScalarDiv(pts[1].fX - pts[0].fX, 10); |
45 SkScalar radius1 = SkScalarDiv(pts[1].fX - pts[0].fX, 3); | 44 SkScalar radius1 = SkScalarDiv(pts[1].fX - pts[0].fX, 3); |
46 center0.set(pts[0].fX + radius0, pts[0].fY + radius0); | 45 center0.set(pts[0].fX + radius0, pts[0].fY + radius0); |
47 center1.set(pts[1].fX - radius1, pts[1].fY - radius1); | 46 center1.set(pts[1].fX - radius1, pts[1].fY - radius1); |
48 return SkGradientShader::CreateTwoPointConical(center0, radius0, | 47 return SkGradientShader::CreateTwoPointConical(center0, radius0, |
49 center1, radius1, | 48 center1, radius1, |
50 data.fColors, data.fPos, | 49 data.fColors, data.fPos, |
51 data.fCount, tm, mapper, | 50 data.fCount, tm, 0, &localMat
rix); |
52 0, &localMatrix); | |
53 } | 51 } |
54 | 52 |
55 static SkShader* Make2ConicalOutsideFlip(const SkPoint pts[2], const GradData& d
ata, | 53 static SkShader* Make2ConicalOutsideFlip(const SkPoint pts[2], const GradData& d
ata, |
56 SkShader::TileMode tm, SkUnitMapper* mapper, | 54 SkShader::TileMode tm, const SkMatrix& localMatrix)
{ |
57 const SkMatrix& localMatrix) { | |
58 SkPoint center0, center1; | 55 SkPoint center0, center1; |
59 SkScalar radius0 = SkScalarDiv(pts[1].fX - pts[0].fX, 10); | 56 SkScalar radius0 = SkScalarDiv(pts[1].fX - pts[0].fX, 10); |
60 SkScalar radius1 = SkScalarDiv(pts[1].fX - pts[0].fX, 3); | 57 SkScalar radius1 = SkScalarDiv(pts[1].fX - pts[0].fX, 3); |
61 center0.set(pts[0].fX + radius0, pts[0].fY + radius0); | 58 center0.set(pts[0].fX + radius0, pts[0].fY + radius0); |
62 center1.set(pts[1].fX - radius1, pts[1].fY - radius1); | 59 center1.set(pts[1].fX - radius1, pts[1].fY - radius1); |
63 return SkGradientShader::CreateTwoPointConical(center1, radius1, | 60 return SkGradientShader::CreateTwoPointConical(center1, radius1, |
64 center0, radius0, | 61 center0, radius0, |
65 data.fColors, data.fPos, | 62 data.fColors, data.fPos, |
66 data.fCount, tm, mapper, | 63 data.fCount, tm, 0, &localMat
rix); |
67 0, &localMatrix); | |
68 } | 64 } |
69 | 65 |
70 static SkShader* Make2ConicalInside(const SkPoint pts[2], const GradData& data, | 66 static SkShader* Make2ConicalInside(const SkPoint pts[2], const GradData& data, |
71 SkShader::TileMode tm, SkUnitMapper* mapper, | 67 SkShader::TileMode tm, const SkMatrix& localMatrix)
{ |
72 const SkMatrix& localMatrix) { | |
73 SkPoint center0, center1; | 68 SkPoint center0, center1; |
74 center0.set(SkScalarAve(pts[0].fX, pts[1].fX), | 69 center0.set(SkScalarAve(pts[0].fX, pts[1].fX), |
75 SkScalarAve(pts[0].fY, pts[1].fY)); | 70 SkScalarAve(pts[0].fY, pts[1].fY)); |
76 center1.set(SkScalarInterp(pts[0].fX, pts[1].fX, SkIntToScalar(3)/5), | 71 center1.set(SkScalarInterp(pts[0].fX, pts[1].fX, SkIntToScalar(3)/5), |
77 SkScalarInterp(pts[0].fY, pts[1].fY, SkIntToScalar(1)/4)); | 72 SkScalarInterp(pts[0].fY, pts[1].fY, SkIntToScalar(1)/4)); |
78 return SkGradientShader::CreateTwoPointConical(center1, (pts[1].fX - pts[0].
fX) / 7, | 73 return SkGradientShader::CreateTwoPointConical(center1, (pts[1].fX - pts[0].
fX) / 7, |
79 center0, (pts[1].fX - pts[0].
fX) / 2, | 74 center0, (pts[1].fX - pts[0].
fX) / 2, |
80 data.fColors, data.fPos, data
.fCount, tm, mapper, | 75 data.fColors, data.fPos, data
.fCount, tm, |
81 0, &localMatrix); | 76 0, &localMatrix); |
82 } | 77 } |
83 | 78 |
84 static SkShader* Make2ConicalInsideFlip(const SkPoint pts[2], const GradData& da
ta, | 79 static SkShader* Make2ConicalInsideFlip(const SkPoint pts[2], const GradData& da
ta, |
85 SkShader::TileMode tm, SkUnitMapper* mapper, | 80 SkShader::TileMode tm, const SkMatrix& localMatrix)
{ |
86 const SkMatrix& localMatrix) { | |
87 SkPoint center0, center1; | 81 SkPoint center0, center1; |
88 center0.set(SkScalarAve(pts[0].fX, pts[1].fX), | 82 center0.set(SkScalarAve(pts[0].fX, pts[1].fX), |
89 SkScalarAve(pts[0].fY, pts[1].fY)); | 83 SkScalarAve(pts[0].fY, pts[1].fY)); |
90 center1.set(SkScalarInterp(pts[0].fX, pts[1].fX, SkIntToScalar(3)/5), | 84 center1.set(SkScalarInterp(pts[0].fX, pts[1].fX, SkIntToScalar(3)/5), |
91 SkScalarInterp(pts[0].fY, pts[1].fY, SkIntToScalar(1)/4)); | 85 SkScalarInterp(pts[0].fY, pts[1].fY, SkIntToScalar(1)/4)); |
92 return SkGradientShader::CreateTwoPointConical(center0, (pts[1].fX - pts[0].
fX) / 2, | 86 return SkGradientShader::CreateTwoPointConical(center0, (pts[1].fX - pts[0].
fX) / 2, |
93 center1, (pts[1].fX - pts[0].
fX) / 7, | 87 center1, (pts[1].fX - pts[0].
fX) / 7, |
94 data.fColors, data.fPos, data
.fCount, tm, mapper, | 88 data.fColors, data.fPos, data
.fCount, tm, |
95 0, &localMatrix); | 89 0, &localMatrix); |
96 } | 90 } |
97 | 91 |
98 static SkShader* Make2ConicalInsideCenter(const SkPoint pts[2], const GradData&
data, | 92 static SkShader* Make2ConicalInsideCenter(const SkPoint pts[2], const GradData&
data, |
99 SkShader::TileMode tm, SkUnitMapper* mapper, | 93 SkShader::TileMode tm, const SkMatrix& localMatrix)
{ |
100 const SkMatrix& localMatrix) { | |
101 SkPoint center0, center1; | 94 SkPoint center0, center1; |
102 center0.set(SkScalarAve(pts[0].fX, pts[1].fX), | 95 center0.set(SkScalarAve(pts[0].fX, pts[1].fX), |
103 SkScalarAve(pts[0].fY, pts[1].fY)); | 96 SkScalarAve(pts[0].fY, pts[1].fY)); |
104 center1.set(SkScalarInterp(pts[0].fX, pts[1].fX, SkIntToScalar(3)/5), | 97 center1.set(SkScalarInterp(pts[0].fX, pts[1].fX, SkIntToScalar(3)/5), |
105 SkScalarInterp(pts[0].fY, pts[1].fY, SkIntToScalar(1)/4)); | 98 SkScalarInterp(pts[0].fY, pts[1].fY, SkIntToScalar(1)/4)); |
106 return SkGradientShader::CreateTwoPointConical(center0, (pts[1].fX - pts[0].
fX) / 7, | 99 return SkGradientShader::CreateTwoPointConical(center0, (pts[1].fX - pts[0].
fX) / 7, |
107 center0, (pts[1].fX - pts[0].
fX) / 2, | 100 center0, (pts[1].fX - pts[0].
fX) / 2, |
108 data.fColors, data.fPos, data
.fCount, tm, mapper, | 101 data.fColors, data.fPos, data
.fCount, tm, |
109 0, &localMatrix); | 102 0, &localMatrix); |
110 } | 103 } |
111 | 104 |
112 static SkShader* Make2ConicalZeroRad(const SkPoint pts[2], const GradData& data, | 105 static SkShader* Make2ConicalZeroRad(const SkPoint pts[2], const GradData& data, |
113 SkShader::TileMode tm, SkUnitMapper* mapper, | 106 SkShader::TileMode tm, const SkMatrix& localMatrix)
{ |
114 const SkMatrix& localMatrix) { | |
115 SkPoint center0, center1; | 107 SkPoint center0, center1; |
116 center0.set(SkScalarAve(pts[0].fX, pts[1].fX), | 108 center0.set(SkScalarAve(pts[0].fX, pts[1].fX), |
117 SkScalarAve(pts[0].fY, pts[1].fY)); | 109 SkScalarAve(pts[0].fY, pts[1].fY)); |
118 center1.set(SkScalarInterp(pts[0].fX, pts[1].fX, SkIntToScalar(3)/5), | 110 center1.set(SkScalarInterp(pts[0].fX, pts[1].fX, SkIntToScalar(3)/5), |
119 SkScalarInterp(pts[0].fY, pts[1].fY, SkIntToScalar(1)/4)); | 111 SkScalarInterp(pts[0].fY, pts[1].fY, SkIntToScalar(1)/4)); |
120 return SkGradientShader::CreateTwoPointConical(center1, 0.f, | 112 return SkGradientShader::CreateTwoPointConical(center1, 0.f, |
121 center0, (pts[1].fX - pts[0].
fX) / 2, | 113 center0, (pts[1].fX - pts[0].
fX) / 2, |
122 data.fColors, data.fPos, data
.fCount, tm, mapper, | 114 data.fColors, data.fPos, data
.fCount, tm, |
123 0, &localMatrix); | 115 0, &localMatrix); |
124 } | 116 } |
125 | 117 |
126 static SkShader* Make2ConicalZeroRadFlip(const SkPoint pts[2], const GradData& d
ata, | 118 static SkShader* Make2ConicalZeroRadFlip(const SkPoint pts[2], const GradData& d
ata, |
127 SkShader::TileMode tm, SkUnitMapper* mapper, | 119 SkShader::TileMode tm, const SkMatrix& localMatrix)
{ |
128 const SkMatrix& localMatrix) { | |
129 SkPoint center0, center1; | 120 SkPoint center0, center1; |
130 center0.set(SkScalarAve(pts[0].fX, pts[1].fX), | 121 center0.set(SkScalarAve(pts[0].fX, pts[1].fX), |
131 SkScalarAve(pts[0].fY, pts[1].fY)); | 122 SkScalarAve(pts[0].fY, pts[1].fY)); |
132 center1.set(SkScalarInterp(pts[0].fX, pts[1].fX, SkIntToScalar(3)/5), | 123 center1.set(SkScalarInterp(pts[0].fX, pts[1].fX, SkIntToScalar(3)/5), |
133 SkScalarInterp(pts[0].fY, pts[1].fY, SkIntToScalar(1)/4)); | 124 SkScalarInterp(pts[0].fY, pts[1].fY, SkIntToScalar(1)/4)); |
134 return SkGradientShader::CreateTwoPointConical(center1, (pts[1].fX - pts[0].
fX) / 2, | 125 return SkGradientShader::CreateTwoPointConical(center1, (pts[1].fX - pts[0].
fX) / 2, |
135 center0, 0.f, | 126 center0, 0.f, |
136 data.fColors, data.fPos, data
.fCount, tm, mapper, | 127 data.fColors, data.fPos, data
.fCount, tm, |
137 0, &localMatrix); | 128 0, &localMatrix); |
138 } | 129 } |
139 | 130 |
140 static SkShader* Make2ConicalZeroRadCenter(const SkPoint pts[2], const GradData&
data, | 131 static SkShader* Make2ConicalZeroRadCenter(const SkPoint pts[2], const GradData&
data, |
141 SkShader::TileMode tm, SkUnitMapper* mapper, | 132 SkShader::TileMode tm, const SkMatrix& localMatrix)
{ |
142 const SkMatrix& localMatrix) { | |
143 SkPoint center0, center1; | 133 SkPoint center0, center1; |
144 center0.set(SkScalarAve(pts[0].fX, pts[1].fX), | 134 center0.set(SkScalarAve(pts[0].fX, pts[1].fX), |
145 SkScalarAve(pts[0].fY, pts[1].fY)); | 135 SkScalarAve(pts[0].fY, pts[1].fY)); |
146 center1.set(SkScalarInterp(pts[0].fX, pts[1].fX, SkIntToScalar(3)/5), | 136 center1.set(SkScalarInterp(pts[0].fX, pts[1].fX, SkIntToScalar(3)/5), |
147 SkScalarInterp(pts[0].fY, pts[1].fY, SkIntToScalar(1)/4)); | 137 SkScalarInterp(pts[0].fY, pts[1].fY, SkIntToScalar(1)/4)); |
148 return SkGradientShader::CreateTwoPointConical(center0, 0.f, | 138 return SkGradientShader::CreateTwoPointConical(center0, 0.f, |
149 center0, (pts[1].fX - pts[0].
fX) / 2, | 139 center0, (pts[1].fX - pts[0].
fX) / 2, |
150 data.fColors, data.fPos, data
.fCount, tm, mapper, | 140 data.fColors, data.fPos, data
.fCount, tm, |
151 0, &localMatrix); | 141 0, &localMatrix); |
152 } | 142 } |
153 | 143 |
154 static SkShader* Make2ConicalZeroRadOutside(const SkPoint pts[2], const GradData
& data, | 144 static SkShader* Make2ConicalZeroRadOutside(const SkPoint pts[2], const GradData
& data, |
155 SkShader::TileMode tm, SkUnitMapper* mapper, | 145 SkShader::TileMode tm, const SkMatrix& localMatrix)
{ |
156 const SkMatrix& localMatrix) { | |
157 SkPoint center0, center1; | 146 SkPoint center0, center1; |
158 SkScalar radius0 = 0.f; | 147 SkScalar radius0 = 0.f; |
159 SkScalar radius1 = SkScalarDiv(pts[1].fX - pts[0].fX, 3); | 148 SkScalar radius1 = SkScalarDiv(pts[1].fX - pts[0].fX, 3); |
160 center0.set(pts[0].fX + radius0, pts[0].fY + radius0); | 149 center0.set(pts[0].fX + radius0, pts[0].fY + radius0); |
161 center1.set(pts[1].fX - radius1, pts[1].fY - radius1); | 150 center1.set(pts[1].fX - radius1, pts[1].fY - radius1); |
162 return SkGradientShader::CreateTwoPointConical(center0, radius0, | 151 return SkGradientShader::CreateTwoPointConical(center0, radius0, |
163 center1, radius1, | 152 center1, radius1, |
164 data.fColors, data.fPos, | 153 data.fColors, data.fPos, |
165 data.fCount, tm, mapper, | 154 data.fCount, tm, 0, &localMat
rix); |
166 0, &localMatrix); | |
167 } | 155 } |
168 | 156 |
169 static SkShader* Make2ConicalZeroRadFlipOutside(const SkPoint pts[2], const Grad
Data& data, | 157 static SkShader* Make2ConicalZeroRadFlipOutside(const SkPoint pts[2], const Grad
Data& data, |
170 SkShader::TileMode tm, SkUnitMapper* mapper, | 158 SkShader::TileMode tm, const SkMatrix& localMatrix)
{ |
171 const SkMatrix& localMatrix) { | |
172 SkPoint center0, center1; | 159 SkPoint center0, center1; |
173 SkScalar radius0 = 0.f; | 160 SkScalar radius0 = 0.f; |
174 SkScalar radius1 = SkScalarDiv(pts[1].fX - pts[0].fX, 3); | 161 SkScalar radius1 = SkScalarDiv(pts[1].fX - pts[0].fX, 3); |
175 center0.set(pts[0].fX + radius0, pts[0].fY + radius0); | 162 center0.set(pts[0].fX + radius0, pts[0].fY + radius0); |
176 center1.set(pts[1].fX - radius1, pts[1].fY - radius1); | 163 center1.set(pts[1].fX - radius1, pts[1].fY - radius1); |
177 return SkGradientShader::CreateTwoPointConical(center1, radius1, | 164 return SkGradientShader::CreateTwoPointConical(center1, radius1, |
178 center0, radius0, | 165 center0, radius0, |
179 data.fColors, data.fPos, | 166 data.fColors, data.fPos, |
180 data.fCount, tm, mapper, | 167 data.fCount, tm, 0, &localMat
rix); |
181 0, &localMatrix); | |
182 } | 168 } |
183 | 169 |
184 static SkShader* Make2ConicalEdgeX(const SkPoint pts[2], const GradData& data, | 170 static SkShader* Make2ConicalEdgeX(const SkPoint pts[2], const GradData& data, |
185 SkShader::TileMode tm, SkUnitMapper* mapper, | 171 SkShader::TileMode tm, const SkMatrix& localMatrix)
{ |
186 const SkMatrix& localMatrix) { | |
187 SkPoint center0, center1; | 172 SkPoint center0, center1; |
188 SkScalar radius0 = SkScalarDiv(pts[1].fX - pts[0].fX, 7); | 173 SkScalar radius0 = SkScalarDiv(pts[1].fX - pts[0].fX, 7); |
189 SkScalar radius1 = SkScalarDiv(pts[1].fX - pts[0].fX, 3); | 174 SkScalar radius1 = SkScalarDiv(pts[1].fX - pts[0].fX, 3); |
190 center1.set(SkScalarAve(pts[0].fX, pts[1].fX), | 175 center1.set(SkScalarAve(pts[0].fX, pts[1].fX), |
191 SkScalarAve(pts[0].fY, pts[1].fY)); | 176 SkScalarAve(pts[0].fY, pts[1].fY)); |
192 center0.set(center1.fX + radius1, center1.fY); | 177 center0.set(center1.fX + radius1, center1.fY); |
193 return SkGradientShader::CreateTwoPointConical(center0, radius0, | 178 return SkGradientShader::CreateTwoPointConical(center0, radius0, |
194 center1, radius1, | 179 center1, radius1, |
195 data.fColors, data.fPos, | 180 data.fColors, data.fPos, |
196 data.fCount, tm, mapper, | 181 data.fCount, tm, 0, &localMat
rix); |
197 0, &localMatrix); | |
198 } | 182 } |
199 | 183 |
200 static SkShader* Make2ConicalEdgeY(const SkPoint pts[2], const GradData& data, | 184 static SkShader* Make2ConicalEdgeY(const SkPoint pts[2], const GradData& data, |
201 SkShader::TileMode tm, SkUnitMapper* mapper, | 185 SkShader::TileMode tm, const SkMatrix& localMatrix)
{ |
202 const SkMatrix& localMatrix) { | |
203 SkPoint center0, center1; | 186 SkPoint center0, center1; |
204 SkScalar radius0 = SkScalarDiv(pts[1].fX - pts[0].fX, 7); | 187 SkScalar radius0 = SkScalarDiv(pts[1].fX - pts[0].fX, 7); |
205 SkScalar radius1 = SkScalarDiv(pts[1].fX - pts[0].fX, 3); | 188 SkScalar radius1 = SkScalarDiv(pts[1].fX - pts[0].fX, 3); |
206 center1.set(SkScalarAve(pts[0].fX, pts[1].fX), | 189 center1.set(SkScalarAve(pts[0].fX, pts[1].fX), |
207 SkScalarAve(pts[0].fY, pts[1].fY)); | 190 SkScalarAve(pts[0].fY, pts[1].fY)); |
208 center0.set(center1.fX, center1.fY + radius1); | 191 center0.set(center1.fX, center1.fY + radius1); |
209 return SkGradientShader::CreateTwoPointConical(center0, radius0, | 192 return SkGradientShader::CreateTwoPointConical(center0, radius0, |
210 center1, radius1, | 193 center1, radius1, |
211 data.fColors, data.fPos, | 194 data.fColors, data.fPos, |
212 data.fCount, tm, mapper, | 195 data.fCount, tm, 0, &localMat
rix); |
213 0, &localMatrix); | |
214 } | 196 } |
215 static SkShader* Make2ConicalZeroRadEdgeX(const SkPoint pts[2], const GradData&
data, | 197 static SkShader* Make2ConicalZeroRadEdgeX(const SkPoint pts[2], const GradData&
data, |
216 SkShader::TileMode tm, SkUnitMapper* mapper, | 198 SkShader::TileMode tm, const SkMatrix& localMatrix)
{ |
217 const SkMatrix& localMatrix) { | |
218 SkPoint center0, center1; | 199 SkPoint center0, center1; |
219 SkScalar radius0 = 0.f; | 200 SkScalar radius0 = 0.f; |
220 SkScalar radius1 = SkScalarDiv(pts[1].fX - pts[0].fX, 3); | 201 SkScalar radius1 = SkScalarDiv(pts[1].fX - pts[0].fX, 3); |
221 center1.set(SkScalarAve(pts[0].fX, pts[1].fX), | 202 center1.set(SkScalarAve(pts[0].fX, pts[1].fX), |
222 SkScalarAve(pts[0].fY, pts[1].fY)); | 203 SkScalarAve(pts[0].fY, pts[1].fY)); |
223 center0.set(center1.fX + radius1, center1.fY); | 204 center0.set(center1.fX + radius1, center1.fY); |
224 return SkGradientShader::CreateTwoPointConical(center0, radius0, | 205 return SkGradientShader::CreateTwoPointConical(center0, radius0, |
225 center1, radius1, | 206 center1, radius1, |
226 data.fColors, data.fPos, | 207 data.fColors, data.fPos, |
227 data.fCount, tm, mapper, | 208 data.fCount, tm, 0, &localMat
rix); |
228 0, &localMatrix); | |
229 } | 209 } |
230 | 210 |
231 static SkShader* Make2ConicalZeroRadEdgeY(const SkPoint pts[2], const GradData&
data, | 211 static SkShader* Make2ConicalZeroRadEdgeY(const SkPoint pts[2], const GradData&
data, |
232 SkShader::TileMode tm, SkUnitMapper* mapper, | 212 SkShader::TileMode tm, const SkMatrix& localMatrix)
{ |
233 const SkMatrix& localMatrix) { | |
234 SkPoint center0, center1; | 213 SkPoint center0, center1; |
235 SkScalar radius0 = 0.f; | 214 SkScalar radius0 = 0.f; |
236 SkScalar radius1 = SkScalarDiv(pts[1].fX - pts[0].fX, 3); | 215 SkScalar radius1 = SkScalarDiv(pts[1].fX - pts[0].fX, 3); |
237 center1.set(SkScalarAve(pts[0].fX, pts[1].fX), | 216 center1.set(SkScalarAve(pts[0].fX, pts[1].fX), |
238 SkScalarAve(pts[0].fY, pts[1].fY)); | 217 SkScalarAve(pts[0].fY, pts[1].fY)); |
239 center0.set(center1.fX, center1.fY + radius1); | 218 center0.set(center1.fX, center1.fY + radius1); |
240 return SkGradientShader::CreateTwoPointConical(center0, radius0, | 219 return SkGradientShader::CreateTwoPointConical(center0, radius0, |
241 center1, radius1, | 220 center1, radius1, |
242 data.fColors, data.fPos, | 221 data.fColors, data.fPos, |
243 data.fCount, tm, mapper, | 222 data.fCount, tm, 0, &localMat
rix); |
244 0, &localMatrix); | |
245 } | 223 } |
246 | 224 |
247 static SkShader* Make2ConicalTouchX(const SkPoint pts[2], const GradData& data, | 225 static SkShader* Make2ConicalTouchX(const SkPoint pts[2], const GradData& data, |
248 SkShader::TileMode tm, SkUnitMapper* mapper, | 226 SkShader::TileMode tm, const SkMatrix& localMatrix)
{ |
249 const SkMatrix& localMatrix) { | |
250 SkPoint center0, center1; | 227 SkPoint center0, center1; |
251 SkScalar radius0 = SkScalarDiv(pts[1].fX - pts[0].fX, 7); | 228 SkScalar radius0 = SkScalarDiv(pts[1].fX - pts[0].fX, 7); |
252 SkScalar radius1 = SkScalarDiv(pts[1].fX - pts[0].fX, 3); | 229 SkScalar radius1 = SkScalarDiv(pts[1].fX - pts[0].fX, 3); |
253 center1.set(SkScalarAve(pts[0].fX, pts[1].fX), | 230 center1.set(SkScalarAve(pts[0].fX, pts[1].fX), |
254 SkScalarAve(pts[0].fY, pts[1].fY)); | 231 SkScalarAve(pts[0].fY, pts[1].fY)); |
255 center0.set(center1.fX - radius1 + radius0, center1.fY); | 232 center0.set(center1.fX - radius1 + radius0, center1.fY); |
256 return SkGradientShader::CreateTwoPointConical(center0, radius0, | 233 return SkGradientShader::CreateTwoPointConical(center0, radius0, |
257 center1, radius1, | 234 center1, radius1, |
258 data.fColors, data.fPos, | 235 data.fColors, data.fPos, |
259 data.fCount, tm, mapper, | 236 data.fCount, tm, 0, &localMat
rix); |
260 0, &localMatrix); | |
261 } | 237 } |
262 | 238 |
263 static SkShader* Make2ConicalTouchY(const SkPoint pts[2], const GradData& data, | 239 static SkShader* Make2ConicalTouchY(const SkPoint pts[2], const GradData& data, |
264 SkShader::TileMode tm, SkUnitMapper* mapper, | 240 SkShader::TileMode tm, const SkMatrix& localMatrix)
{ |
265 const SkMatrix& localMatrix) { | |
266 SkPoint center0, center1; | 241 SkPoint center0, center1; |
267 SkScalar radius0 = SkScalarDiv(pts[1].fX - pts[0].fX, 7); | 242 SkScalar radius0 = SkScalarDiv(pts[1].fX - pts[0].fX, 7); |
268 SkScalar radius1 = SkScalarDiv(pts[1].fX - pts[0].fX, 3); | 243 SkScalar radius1 = SkScalarDiv(pts[1].fX - pts[0].fX, 3); |
269 center1.set(SkScalarAve(pts[0].fX, pts[1].fX), | 244 center1.set(SkScalarAve(pts[0].fX, pts[1].fX), |
270 SkScalarAve(pts[0].fY, pts[1].fY)); | 245 SkScalarAve(pts[0].fY, pts[1].fY)); |
271 center0.set(center1.fX, center1.fY + radius1 - radius0); | 246 center0.set(center1.fX, center1.fY + radius1 - radius0); |
272 return SkGradientShader::CreateTwoPointConical(center0, radius0, | 247 return SkGradientShader::CreateTwoPointConical(center0, radius0, |
273 center1, radius1, | 248 center1, radius1, |
274 data.fColors, data.fPos, | 249 data.fColors, data.fPos, |
275 data.fCount, tm, mapper, | 250 data.fCount, tm, 0, &localMat
rix); |
276 0, &localMatrix); | |
277 } | 251 } |
278 | 252 |
279 static SkShader* Make2ConicalInsideSmallRad(const SkPoint pts[2], const GradData
& data, | 253 static SkShader* Make2ConicalInsideSmallRad(const SkPoint pts[2], const GradData
& data, |
280 SkShader::TileMode tm, SkUnitMapper* mapper, | 254 SkShader::TileMode tm, const SkMatrix& localMatrix)
{ |
281 const SkMatrix& localMatrix) { | |
282 SkPoint center0, center1; | 255 SkPoint center0, center1; |
283 center0.set(SkScalarAve(pts[0].fX, pts[1].fX), | 256 center0.set(SkScalarAve(pts[0].fX, pts[1].fX), |
284 SkScalarAve(pts[0].fY, pts[1].fY)); | 257 SkScalarAve(pts[0].fY, pts[1].fY)); |
285 center1.set(SkScalarInterp(pts[0].fX, pts[1].fX, SkIntToScalar(3)/5), | 258 center1.set(SkScalarInterp(pts[0].fX, pts[1].fX, SkIntToScalar(3)/5), |
286 SkScalarInterp(pts[0].fY, pts[1].fY, SkIntToScalar(1)/4)); | 259 SkScalarInterp(pts[0].fY, pts[1].fY, SkIntToScalar(1)/4)); |
287 return SkGradientShader::CreateTwoPointConical(center0, 0.000000000000000000
1f, | 260 return SkGradientShader::CreateTwoPointConical(center0, 0.000000000000000000
1f, |
288 center0, (pts[1].fX - pts[0].
fX) / 2, | 261 center0, (pts[1].fX - pts[0].
fX) / 2, |
289 data.fColors, data.fPos, data
.fCount, tm, mapper, | 262 data.fColors, data.fPos, data
.fCount, tm, |
290 0, &localMatrix); | 263 0, &localMatrix); |
291 } | 264 } |
292 | 265 |
293 typedef SkShader* (*GradMaker)(const SkPoint pts[2], const GradData& data, | 266 typedef SkShader* (*GradMaker)(const SkPoint pts[2], const GradData& data, |
294 SkShader::TileMode tm, SkUnitMapper* mapper, | 267 SkShader::TileMode tm, const SkMatrix& localMatri
x); |
295 const SkMatrix& localMatrix); | |
296 | 268 |
297 static const GradMaker gGradMakersOutside[] = { | 269 static const GradMaker gGradMakersOutside[] = { |
298 Make2ConicalOutside, Make2ConicalOutsideFlip, | 270 Make2ConicalOutside, Make2ConicalOutsideFlip, |
299 Make2ConicalZeroRadOutside, Make2ConicalZeroRadFlipOutside | 271 Make2ConicalZeroRadOutside, Make2ConicalZeroRadFlipOutside |
300 }; | 272 }; |
301 | 273 |
302 static const GradMaker gGradMakersInside[] = { | 274 static const GradMaker gGradMakersInside[] = { |
303 Make2ConicalInside, Make2ConicalInsideFlip, Make2ConicalInsideCenter, | 275 Make2ConicalInside, Make2ConicalInsideFlip, Make2ConicalInsideCenter, |
304 Make2ConicalZeroRad, Make2ConicalZeroRadFlip, Make2ConicalZeroRadCenter, | 276 Make2ConicalZeroRad, Make2ConicalZeroRadFlip, Make2ConicalZeroRadCenter, |
305 }; | 277 }; |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
371 for (size_t i = 0; i < SK_ARRAY_COUNT(gGradData); i++) { | 343 for (size_t i = 0; i < SK_ARRAY_COUNT(gGradData); i++) { |
372 canvas->save(); | 344 canvas->save(); |
373 for (int j = 0; j < count; j++) { | 345 for (int j = 0; j < count; j++) { |
374 SkMatrix scale = SkMatrix::I(); | 346 SkMatrix scale = SkMatrix::I(); |
375 | 347 |
376 if (i == 3) { // if the clamp case | 348 if (i == 3) { // if the clamp case |
377 scale.setScale(0.5f, 0.5f); | 349 scale.setScale(0.5f, 0.5f); |
378 scale.postTranslate(25.f, 25.f); | 350 scale.postTranslate(25.f, 25.f); |
379 } | 351 } |
380 | 352 |
381 SkShader* shader = gradMaker[j](pts, gGradData[i], tm, NULL, sca
le); | 353 SkShader* shader = gradMaker[j](pts, gGradData[i], tm, scale); |
382 paint.setShader(shader); | 354 paint.setShader(shader); |
383 canvas->drawRect(r, paint); | 355 canvas->drawRect(r, paint); |
384 shader->unref(); | 356 shader->unref(); |
385 canvas->translate(0, SkIntToScalar(120)); | 357 canvas->translate(0, SkIntToScalar(120)); |
386 } | 358 } |
387 canvas->restore(); | 359 canvas->restore(); |
388 canvas->translate(SkIntToScalar(120), 0); | 360 canvas->translate(SkIntToScalar(120), 0); |
389 } | 361 } |
390 } | 362 } |
391 | 363 |
392 private: | 364 private: |
393 typedef GM INHERITED; | 365 typedef GM INHERITED; |
394 | 366 |
395 GradCaseType fGradCaseType; | 367 GradCaseType fGradCaseType; |
396 SkString fName; | 368 SkString fName; |
397 }; | 369 }; |
398 /////////////////////////////////////////////////////////////////////////////// | 370 /////////////////////////////////////////////////////////////////////////////// |
399 | 371 |
400 static GM* MyFactory1(void*) { return new ConicalGradientsGM(kInside_GradCaseTyp
e); } | 372 static GM* MyFactory1(void*) { return new ConicalGradientsGM(kInside_GradCaseTyp
e); } |
401 static GMRegistry reg1(MyFactory1); | 373 static GMRegistry reg1(MyFactory1); |
402 | 374 |
403 static GM* MyFactory2(void*) { return new ConicalGradientsGM(kOutside_GradCaseTy
pe); } | 375 static GM* MyFactory2(void*) { return new ConicalGradientsGM(kOutside_GradCaseTy
pe); } |
404 static GMRegistry reg2(MyFactory2); | 376 static GMRegistry reg2(MyFactory2); |
405 | 377 |
406 static GM* MyFactory3(void*) { return new ConicalGradientsGM(kEdge_GradCaseType)
; } | 378 static GM* MyFactory3(void*) { return new ConicalGradientsGM(kEdge_GradCaseType)
; } |
407 static GMRegistry reg3(MyFactory3); | 379 static GMRegistry reg3(MyFactory3); |
408 } | 380 } |
OLD | NEW |