Flutter Engine
The Flutter Engine
Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | Static Public Attributes | List of all members
SkAnalyticEdge Struct Reference

#include <SkAnalyticEdge.h>

Inheritance diagram for SkAnalyticEdge:
SkAnalyticCubicEdge SkAnalyticQuadraticEdge

Public Types

enum  Type { kLine_Type , kQuad_Type , kCubic_Type }
 

Public Member Functions

void goY (SkFixed y)
 
void goY (SkFixed y, int yShift)
 
bool setLine (const SkPoint &p0, const SkPoint &p1)
 
bool updateLine (SkFixed ax, SkFixed ay, SkFixed bx, SkFixed by, SkFixed slope)
 
bool update (SkFixed last_y, bool sortY=true)
 

Static Public Member Functions

static SkFixed SnapY (SkFixed y)
 

Public Attributes

SkAnalyticEdgefNext
 
SkAnalyticEdgefPrev
 
SkFixed fX
 
SkFixed fDX
 
SkFixed fUpperX
 
SkFixed fY
 
SkFixed fUpperY
 
SkFixed fLowerY
 
SkFixed fDY
 
Type fEdgeType
 
int8_t fCurveCount
 
uint8_t fCurveShift
 
uint8_t fCubicDShift
 
int8_t fWinding
 

Static Public Attributes

static const int kDefaultAccuracy = 2
 

Detailed Description

Definition at line 21 of file SkAnalyticEdge.h.

Member Enumeration Documentation

◆ Type

Enumerator
kLine_Type 
kQuad_Type 
kCubic_Type 

Definition at line 23 of file SkAnalyticEdge.h.

Member Function Documentation

◆ goY() [1/2]

void SkAnalyticEdge::goY ( SkFixed  y)
inline

Definition at line 57 of file SkAnalyticEdge.h.

57 {
58 if (y == fY + SK_Fixed1) {
59 fX = fX + fDX;
60 fY = y;
61 } else if (y != fY) {
62 // Drop lower digits as our alpha only has 8 bits
63 // (fDX and y - fUpperY may be greater than SK_Fixed1)
65 fY = y;
66 }
67 }
#define SK_Fixed1
Definition: SkFixed.h:26
static SkFixed SkFixedMul(SkFixed a, SkFixed b)
Definition: SkFixed.h:96
double y

◆ goY() [2/2]

void SkAnalyticEdge::goY ( SkFixed  y,
int  yShift 
)
inline

Definition at line 69 of file SkAnalyticEdge.h.

69 {
70 SkASSERT(yShift >= 0 && yShift <= kDefaultAccuracy);
71 SkASSERT(fDX == 0 || y - fY == SK_Fixed1 >> yShift);
72 fY = y;
73 fX += fDX >> yShift;
74 }
#define SkASSERT(cond)
Definition: SkAssert.h:116
static const int kDefaultAccuracy

◆ setLine()

bool SkAnalyticEdge::setLine ( const SkPoint p0,
const SkPoint p1 
)

Definition at line 155 of file SkAnalyticEdge.cpp.

155 {
156 // We must set X/Y using the same way (e.g., times 4, to FDot6, then to Fixed) as Quads/Cubics.
157 // Otherwise the order of the edge might be wrong due to precision limit.
158 const int accuracy = kDefaultAccuracy;
159#ifdef SK_RASTERIZE_EVEN_ROUNDING
160 SkFixed x0 = SkFDot6ToFixed(SkScalarRoundToFDot6(p0.fX, accuracy)) >> accuracy;
161 SkFixed y0 = SnapY(SkFDot6ToFixed(SkScalarRoundToFDot6(p0.fY, accuracy)) >> accuracy);
162 SkFixed x1 = SkFDot6ToFixed(SkScalarRoundToFDot6(p1.fX, accuracy)) >> accuracy;
163 SkFixed y1 = SnapY(SkFDot6ToFixed(SkScalarRoundToFDot6(p1.fY, accuracy)) >> accuracy);
164#else
165 const int multiplier = (1 << kDefaultAccuracy);
166 SkFixed x0 = SkFDot6ToFixed(SkScalarToFDot6(p0.fX * multiplier)) >> accuracy;
167 SkFixed y0 = SnapY(SkFDot6ToFixed(SkScalarToFDot6(p0.fY * multiplier)) >> accuracy);
168 SkFixed x1 = SkFDot6ToFixed(SkScalarToFDot6(p1.fX * multiplier)) >> accuracy;
169 SkFixed y1 = SnapY(SkFDot6ToFixed(SkScalarToFDot6(p1.fY * multiplier)) >> accuracy);
170#endif
171
172 int winding = 1;
173
174 if (y0 > y1) {
175 using std::swap;
176 swap(x0, x1);
177 swap(y0, y1);
178 winding = -1;
179 }
180
181 // are we a zero-height line?
182 SkFDot6 dy = SkFixedToFDot6(y1 - y0);
183 if (dy == 0) {
184 return false;
185 }
186 SkFDot6 dx = SkFixedToFDot6(x1 - x0);
187 SkFixed slope = quick_div(dx, dy);
188 SkFixed absSlope = SkAbs32(slope);
189
190 fX = x0;
191 fDX = slope;
192 fUpperX = x0;
193 fY = y0;
194 fUpperY = y0;
195 fLowerY = y1;
196 fDY = dx == 0 || slope == 0 ? SK_MaxS32 : absSlope < kInverseTableSize
197 ? quick_inverse(absSlope)
198 : SkAbs32(quick_div(dy, dx));
200 fCurveCount = 0;
201 fWinding = SkToS8(winding);
202 fCurveShift = 0;
203
204 return true;
205}
static SkFixed quick_div(SkFDot6 a, SkFDot6 b)
static const int kInverseTableSize
static SkFixed quick_inverse(SkFDot6 x)
#define SkFixedToFDot6(x)
Definition: SkFDot6.h:56
int32_t SkFDot6
Definition: SkFDot6.h:16
SkFixed SkFDot6ToFixed(SkFDot6 x)
Definition: SkFDot6.h:58
#define SkScalarToFDot6(x)
Definition: SkFDot6.h:64
SkFDot6 SkScalarRoundToFDot6(SkScalar x, int shift=0)
Definition: SkFDot6.h:23
int32_t SkFixed
Definition: SkFixed.h:25
static constexpr int32_t SK_MaxS32
Definition: SkMath.h:21
void swap(sk_sp< T > &a, sk_sp< T > &b)
Definition: SkRefCnt.h:341
static int32_t SkAbs32(int32_t value)
Definition: SkSafe32.h:41
constexpr int8_t SkToS8(S x)
Definition: SkTo.h:21
skia_private::AutoTArray< sk_sp< SkImageFilter > > filters TypedMatrix matrix TypedMatrix matrix SkScalar dx
Definition: SkRecords.h:208
uint8_t fCurveShift
static SkFixed SnapY(SkFixed y)
float fX
x-axis value
Definition: SkPoint_impl.h:164
float fY
y-axis value
Definition: SkPoint_impl.h:165

◆ SnapY()

static SkFixed SkAnalyticEdge::SnapY ( SkFixed  y)
inlinestatic

Definition at line 50 of file SkAnalyticEdge.h.

50 {
51 const int accuracy = kDefaultAccuracy;
52 // This approach is safer than left shift, round, then right shift
53 return ((unsigned)y + (SK_Fixed1 >> (accuracy + 1))) >> (16 - accuracy) << (16 - accuracy);
54 }

◆ update()

bool SkAnalyticEdge::update ( SkFixed  last_y,
bool  sortY = true 
)

Definition at line 254 of file SkAnalyticEdge.cpp.

254 {
255 SkASSERT(last_y >= fLowerY); // we shouldn't update edge if last_y < fLowerY
256 if (fCurveCount < 0) {
257 return static_cast<SkAnalyticCubicEdge*>(this)->updateCubic(sortY);
258 } else if (fCurveCount > 0) {
259 return static_cast<SkAnalyticQuadraticEdge*>(this)->updateQuadratic();
260 }
261 return false;
262}

◆ updateLine()

bool SkAnalyticEdge::updateLine ( SkFixed  ax,
SkFixed  ay,
SkFixed  bx,
SkFixed  by,
SkFixed  slope 
)

Definition at line 210 of file SkAnalyticEdge.cpp.

210 {
211 // Since we send in the slope, we can no longer snap y inside this function.
212 // If we don't send in the slope, or we do some more sophisticated snapping, this function
213 // could be a performance bottleneck.
214 SkASSERT(fWinding == 1 || fWinding == -1);
215 SkASSERT(fCurveCount != 0);
216
217 // We don't chop at y extrema for cubics so the y is not guaranteed to be increasing for them.
218 // In that case, we have to swap x/y and negate the winding.
219 if (y0 > y1) {
220 using std::swap;
221 swap(x0, x1);
222 swap(y0, y1);
224 }
225
226 SkASSERT(y0 <= y1);
227
228 SkFDot6 dx = SkFixedToFDot6(x1 - x0);
229 SkFDot6 dy = SkFixedToFDot6(y1 - y0);
230
231 // are we a zero-height line?
232 if (dy == 0) {
233 return false;
234 }
235
236 SkASSERT(slope < SK_MaxS32);
237
238 SkFDot6 absSlope = SkAbs32(SkFixedToFDot6(slope));
239 fX = x0;
240 fDX = slope;
241 fUpperX = x0;
242 fY = y0;
243 fUpperY = y0;
244 fLowerY = y1;
245 fDY = (dx == 0 || slope == 0)
246 ? SK_MaxS32
247 : absSlope < kInverseTableSize
248 ? quick_inverse(absSlope)
249 : SkAbs32(quick_div(dy, dx));
250
251 return true;
252}

Member Data Documentation

◆ fCubicDShift

uint8_t SkAnalyticEdge::fCubicDShift

Definition at line 45 of file SkAnalyticEdge.h.

◆ fCurveCount

int8_t SkAnalyticEdge::fCurveCount

Definition at line 43 of file SkAnalyticEdge.h.

◆ fCurveShift

uint8_t SkAnalyticEdge::fCurveShift

Definition at line 44 of file SkAnalyticEdge.h.

◆ fDX

SkFixed SkAnalyticEdge::fDX

Definition at line 33 of file SkAnalyticEdge.h.

◆ fDY

SkFixed SkAnalyticEdge::fDY

Definition at line 38 of file SkAnalyticEdge.h.

◆ fEdgeType

Type SkAnalyticEdge::fEdgeType

Definition at line 41 of file SkAnalyticEdge.h.

◆ fLowerY

SkFixed SkAnalyticEdge::fLowerY

Definition at line 37 of file SkAnalyticEdge.h.

◆ fNext

SkAnalyticEdge* SkAnalyticEdge::fNext

Definition at line 29 of file SkAnalyticEdge.h.

◆ fPrev

SkAnalyticEdge* SkAnalyticEdge::fPrev

Definition at line 30 of file SkAnalyticEdge.h.

◆ fUpperX

SkFixed SkAnalyticEdge::fUpperX

Definition at line 34 of file SkAnalyticEdge.h.

◆ fUpperY

SkFixed SkAnalyticEdge::fUpperY

Definition at line 36 of file SkAnalyticEdge.h.

◆ fWinding

int8_t SkAnalyticEdge::fWinding

Definition at line 46 of file SkAnalyticEdge.h.

◆ fX

SkFixed SkAnalyticEdge::fX

Definition at line 32 of file SkAnalyticEdge.h.

◆ fY

SkFixed SkAnalyticEdge::fY

Definition at line 35 of file SkAnalyticEdge.h.

◆ kDefaultAccuracy

const int SkAnalyticEdge::kDefaultAccuracy = 2
static

Definition at line 48 of file SkAnalyticEdge.h.


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