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

#include <SkEdge.h>

Inheritance diagram for SkCubicEdge:
SkEdge

Public Member Functions

bool setCubicWithoutUpdate (const SkPoint pts[4], int shiftUp, bool sortY=true)
 
int setCubic (const SkPoint pts[4], int shiftUp)
 
int updateCubic ()
 
- 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 fCx
 
SkFixed fCy
 
SkFixed fCDx
 
SkFixed fCDy
 
SkFixed fCDDx
 
SkFixed fCDDy
 
SkFixed fCDDDx
 
SkFixed fCDDDy
 
SkFixed fCLastX
 
SkFixed fCLastY
 
- 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 82 of file SkEdge.h.

Member Function Documentation

◆ setCubic()

int SkCubicEdge::setCubic ( const SkPoint  pts[4],
int  shiftUp 
)

Definition at line 474 of file SkEdge.cpp.

474 {
475 if (!this->setCubicWithoutUpdate(pts, shift)) {
476 return 0;
477 }
478 return this->updateCubic();
479}
int updateCubic()
Definition: SkEdge.cpp:481
bool setCubicWithoutUpdate(const SkPoint pts[4], int shiftUp, bool sortY=true)
Definition: SkEdge.cpp:373

◆ setCubicWithoutUpdate()

bool SkCubicEdge::setCubicWithoutUpdate ( const SkPoint  pts[4],
int  shiftUp,
bool  sortY = true 
)

Definition at line 373 of file SkEdge.cpp.

373 {
374 SkFDot6 x0, y0, x1, y1, x2, y2, x3, y3;
375
376 {
377#ifdef SK_RASTERIZE_EVEN_ROUNDING
378 x0 = SkScalarRoundToFDot6(pts[0].fX, shift);
379 y0 = SkScalarRoundToFDot6(pts[0].fY, shift);
380 x1 = SkScalarRoundToFDot6(pts[1].fX, shift);
381 y1 = SkScalarRoundToFDot6(pts[1].fY, shift);
382 x2 = SkScalarRoundToFDot6(pts[2].fX, shift);
383 y2 = SkScalarRoundToFDot6(pts[2].fY, shift);
384 x3 = SkScalarRoundToFDot6(pts[3].fX, shift);
385 y3 = SkScalarRoundToFDot6(pts[3].fY, shift);
386#else
387 float scale = float(1 << (shift + 6));
388 x0 = int(pts[0].fX * scale);
389 y0 = int(pts[0].fY * scale);
390 x1 = int(pts[1].fX * scale);
391 y1 = int(pts[1].fY * scale);
392 x2 = int(pts[2].fX * scale);
393 y2 = int(pts[2].fY * scale);
394 x3 = int(pts[3].fX * scale);
395 y3 = int(pts[3].fY * scale);
396#endif
397 }
398
399 int winding = 1;
400 if (sortY && y0 > y3)
401 {
402 using std::swap;
403 swap(x0, x3);
404 swap(x1, x2);
405 swap(y0, y3);
406 swap(y1, y2);
407 winding = -1;
408 }
409
410 int top = SkFDot6Round(y0);
411 int bot = SkFDot6Round(y3);
412
413 // are we a zero-height cubic (line)?
414 if (sortY && top == bot)
415 return 0;
416
417 // compute number of steps needed (1 << shift)
418 {
419 // Can't use (center of curve - center of baseline), since center-of-curve
420 // need not be the max delta from the baseline (it could even be coincident)
421 // so we try just looking at the two off-curve points
422 SkFDot6 dx = cubic_delta_from_line(x0, x1, x2, x3);
423 SkFDot6 dy = cubic_delta_from_line(y0, y1, y2, y3);
424 // add 1 (by observation)
425 shift = diff_to_shift(dx, dy) + 1;
426 }
427 // need at least 1 subdivision for our bias trick
428 SkASSERT(shift > 0);
429 if (shift > MAX_COEFF_SHIFT) {
430 shift = MAX_COEFF_SHIFT;
431 }
432
433 /* Since our in coming data is initially shifted down by 10 (or 8 in
434 antialias). That means the most we can shift up is 8. However, we
435 compute coefficients with a 3*, so the safest upshift is really 6
436 */
437 int upShift = 6; // largest safe value
438 int downShift = shift + upShift - 10;
439 if (downShift < 0) {
440 downShift = 0;
441 upShift = 10 - shift;
442 }
443
444 fWinding = SkToS8(winding);
446 fCurveCount = SkToS8(SkLeftShift(-1, shift));
447 fCurveShift = SkToU8(shift);
448 fCubicDShift = SkToU8(downShift);
449
450 SkFixed B = SkFDot6UpShift(3 * (x1 - x0), upShift);
451 SkFixed C = SkFDot6UpShift(3 * (x0 - x1 - x1 + x2), upShift);
452 SkFixed D = SkFDot6UpShift(x3 + 3 * (x1 - x2) - x0, upShift);
453
454 fCx = SkFDot6ToFixed(x0);
455 fCDx = B + (C >> shift) + (D >> 2*shift); // biased by shift
456 fCDDx = 2*C + (3*D >> (shift - 1)); // biased by 2*shift
457 fCDDDx = 3*D >> (shift - 1); // biased by 2*shift
458
459 B = SkFDot6UpShift(3 * (y1 - y0), upShift);
460 C = SkFDot6UpShift(3 * (y0 - y1 - y1 + y2), upShift);
461 D = SkFDot6UpShift(y3 + 3 * (y1 - y2) - y0, upShift);
462
463 fCy = SkFDot6ToFixed(y0);
464 fCDy = B + (C >> shift) + (D >> 2*shift); // biased by shift
465 fCDDy = 2*C + (3*D >> (shift - 1)); // biased by 2*shift
466 fCDDDy = 3*D >> (shift - 1); // biased by 2*shift
467
470
471 return true;
472}
#define SkASSERT(cond)
Definition: SkAssert.h:116
static int SkFDot6UpShift(SkFDot6 x, int upShift)
Definition: SkEdge.cpp:351
static SkFDot6 cubic_delta_from_line(SkFDot6 a, SkFDot6 b, SkFDot6 c, SkFDot6 d)
Definition: SkEdge.cpp:364
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
SkFixed fCx
Definition: SkEdge.h:83
SkFixed fCDDy
Definition: SkEdge.h:85
SkFixed fCLastY
Definition: SkEdge.h:87
SkFixed fCLastX
Definition: SkEdge.h:87
SkFixed fCDDDy
Definition: SkEdge.h:86
SkFixed fCDDDx
Definition: SkEdge.h:86
SkFixed fCDx
Definition: SkEdge.h:84
SkFixed fCy
Definition: SkEdge.h:83
SkFixed fCDy
Definition: SkEdge.h:84
SkFixed fCDDx
Definition: SkEdge.h:85
int8_t fWinding
Definition: SkEdge.h:45
@ kCubic_Type
Definition: SkEdge.h:31
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
uint8_t fCubicDShift
Definition: SkEdge.h:44

◆ updateCubic()

int SkCubicEdge::updateCubic ( )

Definition at line 481 of file SkEdge.cpp.

482{
483 int success;
484 int count = fCurveCount;
485 SkFixed oldx = fCx;
486 SkFixed oldy = fCy;
487 SkFixed newx, newy;
488 const int ddshift = fCurveShift;
489 const int dshift = fCubicDShift;
490
491 SkASSERT(count < 0);
492
493 do {
494 if (++count < 0)
495 {
496 newx = oldx + (fCDx >> dshift);
497 fCDx += fCDDx >> ddshift;
498 fCDDx += fCDDDx;
499
500 newy = oldy + (fCDy >> dshift);
501 fCDy += fCDDy >> ddshift;
502 fCDDy += fCDDDy;
503 }
504 else // last segment
505 {
506 // SkDebugf("LastX err=%d, LastY err=%d\n", (oldx + (fCDx >> shift) - fLastX), (oldy + (fCDy >> shift) - fLastY));
507 newx = fCLastX;
508 newy = fCLastY;
509 }
510
511 // we want to say SkASSERT(oldy <= newy), but our finite fixedpoint
512 // doesn't always achieve that, so we have to explicitly pin it here.
513 if (newy < oldy) {
514 newy = oldy;
515 }
516
517 success = this->updateLine(oldx, oldy, newx, newy);
518 oldx = newx;
519 oldy = newy;
520 } while (count < 0 && !success);
521
522 fCx = newx;
523 fCy = newy;
525 return success;
526}
int count
Definition: FontMgrTest.cpp:50
int updateLine(SkFixed ax, SkFixed ay, SkFixed bx, SkFixed by)
Definition: SkEdge.cpp:115

Member Data Documentation

◆ fCDDDx

SkFixed SkCubicEdge::fCDDDx

Definition at line 86 of file SkEdge.h.

◆ fCDDDy

SkFixed SkCubicEdge::fCDDDy

Definition at line 86 of file SkEdge.h.

◆ fCDDx

SkFixed SkCubicEdge::fCDDx

Definition at line 85 of file SkEdge.h.

◆ fCDDy

SkFixed SkCubicEdge::fCDDy

Definition at line 85 of file SkEdge.h.

◆ fCDx

SkFixed SkCubicEdge::fCDx

Definition at line 84 of file SkEdge.h.

◆ fCDy

SkFixed SkCubicEdge::fCDy

Definition at line 84 of file SkEdge.h.

◆ fCLastX

SkFixed SkCubicEdge::fCLastX

Definition at line 87 of file SkEdge.h.

◆ fCLastY

SkFixed SkCubicEdge::fCLastY

Definition at line 87 of file SkEdge.h.

◆ fCx

SkFixed SkCubicEdge::fCx

Definition at line 83 of file SkEdge.h.

◆ fCy

SkFixed SkCubicEdge::fCy

Definition at line 83 of file SkEdge.h.


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