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