OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright 2006 The Android Open Source Project | 2 * Copyright 2006 The Android Open Source Project |
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 | 8 |
9 #ifndef SkEdge_DEFINED | 9 #ifndef SkEdge_DEFINED |
10 #define SkEdge_DEFINED | 10 #define SkEdge_DEFINED |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
123 fX = SkFDot6ToFixed(x0 + SkFixedMul(slope, dy)); // + SK_Fixed1/2 | 123 fX = SkFDot6ToFixed(x0 + SkFixedMul(slope, dy)); // + SK_Fixed1/2 |
124 fDX = slope; | 124 fDX = slope; |
125 fFirstY = top; | 125 fFirstY = top; |
126 fLastY = bot - 1; | 126 fLastY = bot - 1; |
127 fCurveCount = 0; | 127 fCurveCount = 0; |
128 fWinding = SkToS8(winding); | 128 fWinding = SkToS8(winding); |
129 fCurveShift = 0; | 129 fCurveShift = 0; |
130 return 1; | 130 return 1; |
131 } | 131 } |
132 | 132 |
133 //////////////Analytic Edges//////////////////////////////// | |
134 | |
135 struct SkAnalyticEdge { | |
136 enum Type { | |
137 kLine_Type, | |
138 kQuad_Type, | |
caryclark
2016/08/10 13:08:10
could you add a comment about how conic is support
liyuqian
2016/08/16 13:22:05
Done.
| |
139 kCubic_Type | |
140 }; | |
141 | |
142 SkAnalyticEdge* fNext; | |
143 SkAnalyticEdge* fPrev; | |
144 | |
145 SkFixed fX; | |
146 SkFixed fDX; | |
147 SkFixed fUpperX; | |
caryclark
2016/08/10 13:08:10
Could you add comments on what these fields mean a
liyuqian
2016/08/16 13:22:05
Done.
| |
148 SkFixed fY; | |
149 SkFixed fUpperY; | |
150 SkFixed fLowerY; | |
151 SkFixed fDY; // abs of the inverse of fDX; may be SK_MaxS32 when fDX is close to 0 | |
caryclark
2016/08/10 13:08:10
is this comment on the right line?
liyuqian
2016/08/16 13:22:05
Yes, I'm adding an extra newline to make it more c
| |
152 // fDY is only used for blitting trapezoids | |
153 int8_t fCurveCount; // only used by kQuad(+) and kCubic(-) | |
154 uint8_t fCurveShift; // appled to all Dx/DDx/DDDx except for fCubicDShift exception | |
155 uint8_t fCubicDShift; // applied to fCDx and fCDy only in cubic | |
156 int8_t fWinding; // 1 or -1 | |
157 | |
158 static const int kDefaultAccuracy = 4; // default accuracy for snapping y | |
159 | |
160 static inline SkFixed snapY(SkFixed y, int accuracy = kDefaultAccuracy) { | |
161 // We do ceiling to ensure that y is increasing | |
162 return SkFixedCeilToFixed(y << accuracy) >> accuracy; | |
163 } | |
164 | |
165 static inline SkFixed snapX(SkFixed x, int accuracy = kDefaultAccuracy) { | |
166 return SkFixedRoundToFixed(x << accuracy) >> accuracy; | |
167 } | |
168 | |
169 inline void goY(SkFixed y) { | |
170 if (y == fY + SK_Fixed1) { | |
171 fX = fX + fDX; | |
172 return; | |
173 } else if (y != fY) { | |
174 // Drop lower digits as our alpha only has 8 bits | |
175 // (fDX and y - fUpperY may be greater than SK_Fixed1) | |
176 fX = fUpperX + SkFixedMul_lowprec(fDX, y - fUpperY); | |
177 } | |
178 fY = y; | |
179 } | |
180 | |
181 int setLine(const SkPoint& p0, const SkPoint& p1, const SkIRect* clip); | |
caryclark
2016/08/10 13:08:10
what does the return result mean? If it is always
liyuqian
2016/08/16 13:22:05
I've changed it to bool. I don't know why the orig
| |
182 // call this version if you know you don't have a clip | |
183 inline int setLine(const SkPoint& p0, const SkPoint& p1); | |
caryclark
2016/08/10 13:08:10
ditto
liyuqian
2016/08/16 13:22:05
Done.
| |
184 inline int updateLine(SkFixed ax, SkFixed ay, SkFixed bx, SkFixed by); | |
185 void chopLineWithClip(const SkIRect& clip); | |
186 | |
187 inline bool intersectsClip(const SkIRect& clip) const { | |
188 SkASSERT(SkFixedFloorToInt(fUpperY) < clip.fBottom); | |
189 return SkFixedCeilToInt(fLowerY) > clip.fTop; | |
190 } | |
191 | |
192 #ifdef SK_DEBUG | |
193 void dump() const { | |
194 SkDebugf("edge: upperY:%d lowerY:%d y:%g x:%g dx:%g w:%d\n", | |
195 fUpperY, fLowerY, SkFixedToFloat(fY), SkFixedToFloat(fX), | |
196 SkFixedToFloat(fDX), fWinding); | |
197 } | |
198 | |
199 void validate() const { | |
200 SkASSERT(fPrev && fNext); | |
201 SkASSERT(fPrev->fNext == this); | |
202 SkASSERT(fNext->fPrev == this); | |
203 | |
204 SkASSERT(fUpperY < fLowerY); | |
205 SkASSERT(SkAbs32(fWinding) == 1); | |
206 } | |
207 #endif | |
208 }; | |
209 | |
210 struct SkAnalyticQuadraticEdge : public SkAnalyticEdge { | |
211 SkFixed fQx, fQy; | |
212 SkFixed fQDx, fQDy; | |
213 SkFixed fQDDx, fQDDy; | |
214 SkFixed fQLastX, fQLastY; | |
215 | |
216 // snap y to integer points in the middle of the curve to accelerate AAA pat h filling | |
217 SkFixed fSnappedX, fSnappedY; | |
218 | |
219 int setQuadratic(const SkPoint pts[3]); | |
220 int updateQuadratic(); | |
221 }; | |
222 | |
223 struct SkAnalyticCubicEdge : public SkAnalyticEdge { | |
224 SkFixed fCx, fCy; | |
225 SkFixed fCDx, fCDy; | |
226 SkFixed fCDDx, fCDDy; | |
227 SkFixed fCDDDx, fCDDDy; | |
228 SkFixed fCLastX, fCLastY; | |
229 | |
230 int setCubic(const SkPoint pts[4]); | |
231 int updateCubic(); | |
232 }; | |
233 | |
234 int SkAnalyticEdge::setLine(const SkPoint& p0, const SkPoint& p1) { | |
235 SkFixed x0, y0, x1, y1; | |
236 | |
237 x0 = SkScalarToFixed(p0.fX); | |
238 y0 = snapY(SkScalarToFixed(p0.fY)); | |
239 x1 = SkScalarToFixed(p1.fX); | |
240 y1 = snapY(SkScalarToFixed(p1.fY)); | |
241 | |
242 int winding = 1; | |
243 | |
244 if (y0 > y1) { | |
245 SkTSwap(x0, x1); | |
246 SkTSwap(y0, y1); | |
247 winding = -1; | |
248 } | |
249 | |
250 // are we a zero-height line? | |
251 if (y0 == y1) { | |
252 return 0; | |
253 } | |
254 | |
255 SkFixed slope = SkFixedDiv(x1 - x0, y1 - y0); | |
256 | |
257 fX = x0; | |
258 fDX = slope; | |
259 fUpperX = x0; | |
260 fY = y0; | |
261 fUpperY = y0; | |
262 fLowerY = y1; | |
263 fDY = x1 - x0 != 0 ? SkAbs32(SkFixedDiv(y1 - y0, x1 - x0)) : SK_MaxS 32; | |
caryclark
2016/08/10 13:08:10
x1 == x0 ?
liyuqian
2016/08/16 13:22:05
Done.
| |
264 fCurveCount = 0; | |
265 fWinding = SkToS8(winding); | |
266 fCurveShift = 0; | |
267 return 1; | |
268 } | |
269 | |
270 //////////////////////////////////////////////////////////// | |
271 | |
133 | 272 |
134 #endif | 273 #endif |
OLD | NEW |