Flutter Engine
The Flutter Engine
Public Member Functions | Public Attributes | List of all members
SkQuadraticEdge Struct Reference

#include <SkEdge.h>

Inheritance diagram for SkQuadraticEdge:
SkEdge

Public Member Functions

bool setQuadraticWithoutUpdate (const SkPoint pts[3], int shiftUp)
 
int setQuadratic (const SkPoint pts[3], int shiftUp)
 
int updateQuadratic ()
 
- Public Member Functions inherited from SkEdge
int setLine (const SkPoint &p0, const SkPoint &p1, const SkIRect *clip, int shiftUp)
 
int setLine (const SkPoint &p0, const SkPoint &p1, int shiftUp)
 
int updateLine (SkFixed ax, SkFixed ay, SkFixed bx, SkFixed by)
 
void chopLineWithClip (const SkIRect &clip)
 
bool intersectsClip (const SkIRect &clip) const
 

Public Attributes

SkFixed fQx
 
SkFixed fQy
 
SkFixed fQDx
 
SkFixed fQDy
 
SkFixed fQDDx
 
SkFixed fQDDy
 
SkFixed fQLastX
 
SkFixed fQLastY
 
- Public Attributes inherited from SkEdge
SkEdgefNext
 
SkEdgefPrev
 
SkFixed fX
 
SkFixed fDX
 
int32_t fFirstY
 
int32_t fLastY
 
Type fEdgeType
 
int8_t fCurveCount
 
uint8_t fCurveShift
 
uint8_t fCubicDShift
 
int8_t fWinding
 

Additional Inherited Members

- Public Types inherited from SkEdge
enum  Type { kLine_Type , kQuad_Type , kCubic_Type }
 

Detailed Description

Definition at line 71 of file SkEdge.h.

Member Function Documentation

◆ setQuadratic()

int SkQuadraticEdge::setQuadratic ( const SkPoint  pts[3],
int  shiftUp 
)

Definition at line 303 of file SkEdge.cpp.

303 {
304 if (!setQuadraticWithoutUpdate(pts, shift)) {
305 return 0;
306 }
307 return this->updateQuadratic();
308}
bool setQuadraticWithoutUpdate(const SkPoint pts[3], int shiftUp)
Definition: SkEdge.cpp:202
int updateQuadratic()
Definition: SkEdge.cpp:310

◆ setQuadraticWithoutUpdate()

bool SkQuadraticEdge::setQuadraticWithoutUpdate ( const SkPoint  pts[3],
int  shiftUp 
)

Definition at line 202 of file SkEdge.cpp.

202 {
203 SkFDot6 x0, y0, x1, y1, x2, y2;
204
205 {
206#ifdef SK_RASTERIZE_EVEN_ROUNDING
207 x0 = SkScalarRoundToFDot6(pts[0].fX, shift);
208 y0 = SkScalarRoundToFDot6(pts[0].fY, shift);
209 x1 = SkScalarRoundToFDot6(pts[1].fX, shift);
210 y1 = SkScalarRoundToFDot6(pts[1].fY, shift);
211 x2 = SkScalarRoundToFDot6(pts[2].fX, shift);
212 y2 = SkScalarRoundToFDot6(pts[2].fY, shift);
213#else
214 float scale = float(1 << (shift + 6));
215 x0 = int(pts[0].fX * scale);
216 y0 = int(pts[0].fY * scale);
217 x1 = int(pts[1].fX * scale);
218 y1 = int(pts[1].fY * scale);
219 x2 = int(pts[2].fX * scale);
220 y2 = int(pts[2].fY * scale);
221#endif
222 }
223
224 int winding = 1;
225 if (y0 > y2)
226 {
227 using std::swap;
228 swap(x0, x2);
229 swap(y0, y2);
230 winding = -1;
231 }
232 SkASSERT(y0 <= y1 && y1 <= y2);
233
234 int top = SkFDot6Round(y0);
235 int bot = SkFDot6Round(y2);
236
237 // are we a zero-height quad (line)?
238 if (top == bot)
239 return 0;
240
241 // compute number of steps needed (1 << shift)
242 {
243 SkFDot6 dx = (SkLeftShift(x1, 1) - x0 - x2) >> 2;
244 SkFDot6 dy = (SkLeftShift(y1, 1) - y0 - y2) >> 2;
245 // This is a little confusing:
246 // before this line, shift is the scale up factor for AA;
247 // after this line, shift is the fCurveShift.
248 shift = diff_to_shift(dx, dy, shift);
249 SkASSERT(shift >= 0);
250 }
251 // need at least 1 subdivision for our bias trick
252 if (shift == 0) {
253 shift = 1;
254 } else if (shift > MAX_COEFF_SHIFT) {
255 shift = MAX_COEFF_SHIFT;
256 }
257
258 fWinding = SkToS8(winding);
259 //fCubicDShift only set for cubics
261 fCurveCount = SkToS8(1 << shift);
262
263 /*
264 * We want to reformulate into polynomial form, to make it clear how we
265 * should forward-difference.
266 *
267 * p0 (1 - t)^2 + p1 t(1 - t) + p2 t^2 ==> At^2 + Bt + C
268 *
269 * A = p0 - 2p1 + p2
270 * B = 2(p1 - p0)
271 * C = p0
272 *
273 * Our caller must have constrained our inputs (p0..p2) to all fit into
274 * 16.16. However, as seen above, we sometimes compute values that can be
275 * larger (e.g. B = 2*(p1 - p0)). To guard against overflow, we will store
276 * A and B at 1/2 of their actual value, and just apply a 2x scale during
277 * application in updateQuadratic(). Hence we store (shift - 1) in
278 * fCurveShift.
279 */
280
281 fCurveShift = SkToU8(shift - 1);
282
283 SkFixed A = SkFDot6ToFixedDiv2(x0 - x1 - x1 + x2); // 1/2 the real value
284 SkFixed B = SkFDot6ToFixed(x1 - x0); // 1/2 the real value
285
286 fQx = SkFDot6ToFixed(x0);
287 fQDx = B + (A >> shift); // biased by shift
288 fQDDx = A >> (shift - 1); // biased by shift
289
290 A = SkFDot6ToFixedDiv2(y0 - y1 - y1 + y2); // 1/2 the real value
291 B = SkFDot6ToFixed(y1 - y0); // 1/2 the real value
292
293 fQy = SkFDot6ToFixed(y0);
294 fQDy = B + (A >> shift); // biased by shift
295 fQDDy = A >> (shift - 1); // biased by shift
296
299
300 return true;
301}
#define SkASSERT(cond)
Definition: SkAssert.h:116
static SkFixed SkFDot6ToFixedDiv2(SkFDot6 value)
Definition: SkEdge.cpp:30
static int diff_to_shift(SkFDot6 dx, SkFDot6 dy, int shiftAA=2)
Definition: SkEdge.cpp:185
#define MAX_COEFF_SHIFT
Definition: SkEdge.cpp:171
#define SkFDot6Round(x)
Definition: SkFDot6.h:54
int32_t SkFDot6
Definition: SkFDot6.h:16
SkFixed SkFDot6ToFixed(SkFDot6 x)
Definition: SkFDot6.h:58
SkFDot6 SkScalarRoundToFDot6(SkScalar x, int shift=0)
Definition: SkFDot6.h:23
int32_t SkFixed
Definition: SkFixed.h:25
static constexpr int32_t SkLeftShift(int32_t value, int32_t shift)
Definition: SkMath.h:37
void swap(sk_sp< T > &a, sk_sp< T > &b)
Definition: SkRefCnt.h:341
constexpr int8_t SkToS8(S x)
Definition: SkTo.h:21
constexpr uint8_t SkToU8(S x)
Definition: SkTo.h:22
skia_private::AutoTArray< sk_sp< SkImageFilter > > filters TypedMatrix matrix TypedMatrix matrix SkScalar dx
Definition: SkRecords.h:208
const Scalar scale
int8_t fWinding
Definition: SkEdge.h:45
@ kQuad_Type
Definition: SkEdge.h:30
SkFixed fX
Definition: SkEdge.h:37
uint8_t fCurveShift
Definition: SkEdge.h:43
Type fEdgeType
Definition: SkEdge.h:41
int8_t fCurveCount
Definition: SkEdge.h:42
SkFixed fQDx
Definition: SkEdge.h:73
SkFixed fQDDx
Definition: SkEdge.h:74
SkFixed fQLastX
Definition: SkEdge.h:75
SkFixed fQDy
Definition: SkEdge.h:73
SkFixed fQDDy
Definition: SkEdge.h:74
SkFixed fQLastY
Definition: SkEdge.h:75
SkFixed fQx
Definition: SkEdge.h:72
SkFixed fQy
Definition: SkEdge.h:72

◆ updateQuadratic()

int SkQuadraticEdge::updateQuadratic ( )

Definition at line 310 of file SkEdge.cpp.

311{
312 int success;
313 int count = fCurveCount;
314 SkFixed oldx = fQx;
315 SkFixed oldy = fQy;
316 SkFixed dx = fQDx;
317 SkFixed dy = fQDy;
318 SkFixed newx, newy;
319 int shift = fCurveShift;
320
321 SkASSERT(count > 0);
322
323 do {
324 if (--count > 0)
325 {
326 newx = oldx + (dx >> shift);
327 dx += fQDDx;
328 newy = oldy + (dy >> shift);
329 dy += fQDDy;
330 }
331 else // last segment
332 {
333 newx = fQLastX;
334 newy = fQLastY;
335 }
336 success = this->updateLine(oldx, oldy, newx, newy);
337 oldx = newx;
338 oldy = newy;
339 } while (count > 0 && !success);
340
341 fQx = newx;
342 fQy = newy;
343 fQDx = dx;
344 fQDy = dy;
346 return success;
347}
int count
Definition: FontMgrTest.cpp:50
int updateLine(SkFixed ax, SkFixed ay, SkFixed bx, SkFixed by)
Definition: SkEdge.cpp:115

Member Data Documentation

◆ fQDDx

SkFixed SkQuadraticEdge::fQDDx

Definition at line 74 of file SkEdge.h.

◆ fQDDy

SkFixed SkQuadraticEdge::fQDDy

Definition at line 74 of file SkEdge.h.

◆ fQDx

SkFixed SkQuadraticEdge::fQDx

Definition at line 73 of file SkEdge.h.

◆ fQDy

SkFixed SkQuadraticEdge::fQDy

Definition at line 73 of file SkEdge.h.

◆ fQLastX

SkFixed SkQuadraticEdge::fQLastX

Definition at line 75 of file SkEdge.h.

◆ fQLastY

SkFixed SkQuadraticEdge::fQLastY

Definition at line 75 of file SkEdge.h.

◆ fQx

SkFixed SkQuadraticEdge::fQx

Definition at line 72 of file SkEdge.h.

◆ fQy

SkFixed SkQuadraticEdge::fQy

Definition at line 72 of file SkEdge.h.


The documentation for this struct was generated from the following files: