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

#include <SkQuadClipper.h>

Public Member Functions

 SkQuadClipper ()
 
void setClip (const SkIRect &clip)
 
bool clipQuad (const SkPoint src[3], SkPoint dst[3])
 

Detailed Description

This class is initialized with a clip rectangle, and then can be fed quads, which must already be monotonic in Y.

In the future, it might return a series of segments, allowing it to clip also in X, to ensure that all segments fit in a finite coordinate system.

Definition at line 24 of file SkQuadClipper.h.

Constructor & Destructor Documentation

◆ SkQuadClipper()

SkQuadClipper::SkQuadClipper ( )

Definition at line 14 of file SkQuadClipper.cpp.

14 {
15 fClip.setEmpty();
16}
void setEmpty()
Definition: SkRect.h:842

Member Function Documentation

◆ clipQuad()

bool SkQuadClipper::clipQuad ( const SkPoint  src[3],
SkPoint  dst[3] 
)

Definition at line 54 of file SkQuadClipper.cpp.

54 {
55 bool reverse;
56
57 // we need the data to be monotonically increasing in Y
58 if (srcPts[0].fY > srcPts[2].fY) {
59 dst[0] = srcPts[2];
60 dst[1] = srcPts[1];
61 dst[2] = srcPts[0];
62 reverse = true;
63 } else {
64 memcpy(dst, srcPts, 3 * sizeof(SkPoint));
65 reverse = false;
66 }
67
68 // are we completely above or below
69 const SkScalar ctop = fClip.fTop;
70 const SkScalar cbot = fClip.fBottom;
71 if (dst[2].fY <= ctop || dst[0].fY >= cbot) {
72 return false;
73 }
74
75 SkScalar t;
76 SkPoint tmp[5]; // for SkChopQuadAt
77
78 // are we partially above
79 if (dst[0].fY < ctop) {
80 if (chopMonoQuadAtY(dst, ctop, &t)) {
81 // take the 2nd chopped quad
82 SkChopQuadAt(dst, tmp, t);
83 dst[0] = tmp[2];
84 dst[1] = tmp[3];
85 } else {
86 // if chopMonoQuadAtY failed, then we may have hit inexact numerics
87 // so we just clamp against the top
88 for (int i = 0; i < 3; i++) {
89 if (dst[i].fY < ctop) {
90 dst[i].fY = ctop;
91 }
92 }
93 }
94 }
95
96 // are we partially below
97 if (dst[2].fY > cbot) {
98 if (chopMonoQuadAtY(dst, cbot, &t)) {
99 SkChopQuadAt(dst, tmp, t);
100 dst[1] = tmp[1];
101 dst[2] = tmp[2];
102 } else {
103 // if chopMonoQuadAtY failed, then we may have hit inexact numerics
104 // so we just clamp against the bottom
105 for (int i = 0; i < 3; i++) {
106 if (dst[i].fY > cbot) {
107 dst[i].fY = cbot;
108 }
109 }
110 }
111 }
112
113 if (reverse) {
114 using std::swap;
115 swap(dst[0], dst[2]);
116 }
117 return true;
118}
void SkChopQuadAt(const SkPoint src[3], SkPoint dst[5], SkScalar t)
Definition: SkGeometry.cpp:175
static bool chopMonoQuadAtY(SkPoint pts[3], SkScalar y, SkScalar *t)
void swap(sk_sp< T > &a, sk_sp< T > &b)
Definition: SkRefCnt.h:341
float SkScalar
Definition: extension.cpp:12
dst
Definition: cp.py:12
SkScalar fBottom
larger y-axis bounds
Definition: extension.cpp:17
SkScalar fTop
smaller y-axis bounds
Definition: extension.cpp:15

◆ setClip()

void SkQuadClipper::setClip ( const SkIRect clip)

Definition at line 18 of file SkQuadClipper.cpp.

18 {
19 // conver to scalars, since that's where we'll see the points
20 fClip.set(clip);
21}
static SkPath clip(const SkPath &path, const SkHalfPlane &plane)
Definition: SkPath.cpp:3892
void set(const SkIRect &src)
Definition: SkRect.h:849

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