Flutter Engine
The Flutter Engine
Public Member Functions | Static Public Member Functions | List of all members
SkEdgeClipper Class Reference

#include <SkEdgeClipper.h>

Public Member Functions

 SkEdgeClipper (bool canCullToTheRight)
 
bool clipLine (SkPoint p0, SkPoint p1, const SkRect &clip)
 
bool clipQuad (const SkPoint pts[3], const SkRect &clip)
 
bool clipCubic (const SkPoint pts[4], const SkRect &clip)
 
SkPath::Verb next (SkPoint pts[])
 
bool canCullToTheRight () const
 

Static Public Member Functions

static void ClipPath (const SkPath &path, const SkRect &clip, bool canCullToTheRight, void(*consume)(SkEdgeClipper *, bool newCtr, void *ctx), void *ctx)
 

Detailed Description

This is basically an iterator. It is initialized with an edge and a clip, and then next() is called until it returns kDone_Verb.

Definition at line 22 of file SkEdgeClipper.h.

Constructor & Destructor Documentation

◆ SkEdgeClipper()

SkEdgeClipper::SkEdgeClipper ( bool  canCullToTheRight)
inline

Definition at line 24 of file SkEdgeClipper.h.

24: fCanCullToTheRight(canCullToTheRight) {}
bool canCullToTheRight() const
Definition: SkEdgeClipper.h:32

Member Function Documentation

◆ canCullToTheRight()

bool SkEdgeClipper::canCullToTheRight ( ) const
inline

Definition at line 32 of file SkEdgeClipper.h.

32{ return fCanCullToTheRight; }

◆ clipCubic()

bool SkEdgeClipper::clipCubic ( const SkPoint  pts[4],
const SkRect clip 
)

Definition at line 422 of file SkEdgeClipper.cpp.

422 {
423 fCurrPoint = fPoints;
424 fCurrVerb = fVerbs;
425
426 const SkRect bounds = compute_cubic_bounds(srcPts);
427 // check if we're clipped out vertically
428 if (bounds.fBottom > clip.fTop && bounds.fTop < clip.fBottom) {
430 // can't safely clip the cubic, so we give up and draw a line (which we can safely clip)
431 //
432 // If we rewrote chopcubicat*extrema and chopmonocubic using doubles, we could very
433 // likely always handle the cubic safely, but (it seems) at a big loss in speed, so
434 // we'd only want to take that alternate impl if needed. Perhaps a TODO to try it.
435 //
436 return this->clipLine(srcPts[0], srcPts[3], clip);
437 } else {
438 SkPoint monoY[10];
439 int countY = SkChopCubicAtYExtrema(srcPts, monoY);
440 for (int y = 0; y <= countY; y++) {
441 SkPoint monoX[10];
442 int countX = SkChopCubicAtXExtrema(&monoY[y * 3], monoX);
443 for (int x = 0; x <= countX; x++) {
444 this->clipMonoCubic(&monoX[x * 3], clip);
445 SkASSERT(fCurrVerb - fVerbs < kMaxVerbs);
446 SkASSERT(fCurrPoint - fPoints <= kMaxPoints);
447 }
448 }
449 }
450 }
451
452 *fCurrVerb = SkPath::kDone_Verb;
453 fCurrPoint = fPoints;
454 fCurrVerb = fVerbs;
455 return SkPath::kDone_Verb != fVerbs[0];
456}
#define SkASSERT(cond)
Definition: SkAssert.h:116
static bool too_big_for_reliable_float_math(const SkRect &r)
static SkRect compute_cubic_bounds(const SkPoint pts[4])
int SkChopCubicAtYExtrema(const SkPoint src[4], SkPoint dst[10])
Definition: SkGeometry.cpp:698
int SkChopCubicAtXExtrema(const SkPoint src[4], SkPoint dst[10])
Definition: SkGeometry.cpp:714
static SkPath clip(const SkPath &path, const SkHalfPlane &plane)
Definition: SkPath.cpp:3892
bool clipLine(SkPoint p0, SkPoint p1, const SkRect &clip)
@ kDone_Verb
Definition: SkPath.h:1472
double y
double x
Optional< SkRect > bounds
Definition: SkRecords.h:189

◆ clipLine()

bool SkEdgeClipper::clipLine ( SkPoint  p0,
SkPoint  p1,
const SkRect clip 
)

Definition at line 53 of file SkEdgeClipper.cpp.

53 {
54 fCurrPoint = fPoints;
55 fCurrVerb = fVerbs;
56
58 const SkPoint pts[] = { p0, p1 };
59 int lineCount = SkLineClipper::ClipLine(pts, clip, lines, fCanCullToTheRight);
60 for (int i = 0; i < lineCount; i++) {
61 this->appendLine(lines[i], lines[i + 1]);
62 }
63
64 *fCurrVerb = SkPath::kDone_Verb;
65 fCurrPoint = fPoints;
66 fCurrVerb = fVerbs;
67 return SkPath::kDone_Verb != fVerbs[0];
68}
static int ClipLine(const SkPoint pts[2], const SkRect &clip, SkPoint lines[kMaxPoints], bool canCullToTheRight)

◆ ClipPath()

void SkEdgeClipper::ClipPath ( const SkPath path,
const SkRect clip,
bool  canCullToTheRight,
void(*)(SkEdgeClipper *, bool newCtr, void *ctx)  consume,
void *  ctx 
)
static

Clips each segment from the path, and passes the result (in a clipper) to the consume proc.

Definition at line 566 of file SkEdgeClipper.cpp.

567 {
568 SkASSERT(path.isFinite());
569
570 SkAutoConicToQuads quadder;
571 const SkScalar conicTol = SK_Scalar1 / 4;
572
573 SkPathEdgeIter iter(path);
575
576 while (auto e = iter.next()) {
577 switch (e.fEdge) {
579 if (clipper.clipLine(e.fPts[0], e.fPts[1], clip)) {
580 consume(&clipper, e.fIsNewContour, ctx);
581 }
582 break;
584 if (clipper.clipQuad(e.fPts, clip)) {
585 consume(&clipper, e.fIsNewContour, ctx);
586 }
587 break;
589 const SkPoint* quadPts = quadder.computeQuads(e.fPts, iter.conicWeight(), conicTol);
590 for (int i = 0; i < quadder.countQuads(); ++i) {
591 if (clipper.clipQuad(quadPts, clip)) {
592 consume(&clipper, e.fIsNewContour, ctx);
593 }
594 quadPts += 2;
595 }
596 } break;
598 if (clipper.clipCubic(e.fPts, clip)) {
599 consume(&clipper, e.fIsNewContour, ctx);
600 }
601 break;
602 }
603 }
604}
#define SK_Scalar1
Definition: SkScalar.h:18
const SkPoint * computeQuads(const SkConic &conic, SkScalar tol)
Definition: SkGeometry.h:524
int countQuads() const
Definition: SkGeometry.h:539
float SkScalar
Definition: extension.cpp:12
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir path
Definition: switches.h:57

◆ clipQuad()

bool SkEdgeClipper::clipQuad ( const SkPoint  pts[3],
const SkRect clip 
)

Definition at line 226 of file SkEdgeClipper.cpp.

226 {
227 fCurrPoint = fPoints;
228 fCurrVerb = fVerbs;
229
231 bounds.setBounds(srcPts, 3);
232
233 if (!quick_reject(bounds, clip)) {
234 SkPoint monoY[5];
235 int countY = SkChopQuadAtYExtrema(srcPts, monoY);
236 for (int y = 0; y <= countY; y++) {
237 SkPoint monoX[5];
238 int countX = SkChopQuadAtXExtrema(&monoY[y * 2], monoX);
239 for (int x = 0; x <= countX; x++) {
240 this->clipMonoQuad(&monoX[x * 2], clip);
241 SkASSERT(fCurrVerb - fVerbs < kMaxVerbs);
242 SkASSERT(fCurrPoint - fPoints <= kMaxPoints);
243 }
244 }
245 }
246
247 *fCurrVerb = SkPath::kDone_Verb;
248 fCurrPoint = fPoints;
249 fCurrVerb = fVerbs;
250 return SkPath::kDone_Verb != fVerbs[0];
251}
static bool quick_reject(const SkRect &bounds, const SkRect &clip)
int SkChopQuadAtXExtrema(const SkPoint src[3], SkPoint dst[5])
Definition: SkGeometry.cpp:307
int SkChopQuadAtYExtrema(const SkPoint src[3], SkPoint dst[5])
Definition: SkGeometry.cpp:279

◆ next()

SkPath::Verb SkEdgeClipper::next ( SkPoint  pts[])

Definition at line 506 of file SkEdgeClipper.cpp.

506 {
507 SkPath::Verb verb = *fCurrVerb;
508
509 switch (verb) {
511 memcpy(pts, fCurrPoint, 2 * sizeof(SkPoint));
512 fCurrPoint += 2;
513 fCurrVerb += 1;
514 break;
516 memcpy(pts, fCurrPoint, 3 * sizeof(SkPoint));
517 fCurrPoint += 3;
518 fCurrVerb += 1;
519 break;
521 memcpy(pts, fCurrPoint, 4 * sizeof(SkPoint));
522 fCurrPoint += 4;
523 fCurrVerb += 1;
524 break;
526 break;
527 default:
528 SkDEBUGFAIL("unexpected verb in quadclippper2 iter");
529 break;
530 }
531 return verb;
532}
#define SkDEBUGFAIL(message)
Definition: SkAssert.h:118
@ kCubic_Verb
Definition: SkPath.h:1470
@ kQuad_Verb
Definition: SkPath.h:1468
@ kLine_Verb
Definition: SkPath.h:1467

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