Flutter Engine
The Flutter Engine
SkEdge.h
Go to the documentation of this file.
1/*
2 * Copyright 2006 The Android Open Source Project
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8#ifndef SkEdge_DEFINED
9#define SkEdge_DEFINED
10
12#include "include/core/SkRect.h"
19#include "src/core/SkFDot6.h"
20
21#include <cstdint>
22#include <utility>
23
24// This correctly favors the lower-pixel when y0 is on a 1/2 pixel boundary
25#define SkEdge_Compute_DY(top, y0) (SkLeftShift(top, 6) + 32 - (y0))
26
27struct SkEdge {
28 enum Type {
32 };
33
36
39 int32_t fFirstY;
40 int32_t fLastY;
41 Type fEdgeType; // Remembers the *initial* edge type
42 int8_t fCurveCount; // only used by kQuad(+) and kCubic(-)
43 uint8_t fCurveShift; // appled to all Dx/DDx/DDDx except for fCubicDShift exception
44 uint8_t fCubicDShift; // applied to fCDx and fCDy only in cubic
45 int8_t fWinding; // 1 or -1
46
47 int setLine(const SkPoint& p0, const SkPoint& p1, const SkIRect* clip, int shiftUp);
48 // call this version if you know you don't have a clip
49 inline int setLine(const SkPoint& p0, const SkPoint& p1, int shiftUp);
50 inline int updateLine(SkFixed ax, SkFixed ay, SkFixed bx, SkFixed by);
51 void chopLineWithClip(const SkIRect& clip);
52
53 inline bool intersectsClip(const SkIRect& clip) const {
54 SkASSERT(fFirstY < clip.fBottom);
55 return fLastY >= clip.fTop;
56 }
57
58#ifdef SK_DEBUG
59 void dump() const;
60 void validate() const {
62 SkASSERT(fPrev->fNext == this);
63 SkASSERT(fNext->fPrev == this);
64
67 }
68#endif
69};
70
71struct SkQuadraticEdge : public SkEdge {
76
77 bool setQuadraticWithoutUpdate(const SkPoint pts[3], int shiftUp);
78 int setQuadratic(const SkPoint pts[3], int shiftUp);
79 int updateQuadratic();
80};
81
82struct SkCubicEdge : public SkEdge {
88
89 bool setCubicWithoutUpdate(const SkPoint pts[4], int shiftUp, bool sortY = true);
90 int setCubic(const SkPoint pts[4], int shiftUp);
91 int updateCubic();
92};
93
94int SkEdge::setLine(const SkPoint& p0, const SkPoint& p1, int shift) {
95 SkFDot6 x0, y0, x1, y1;
96
97 {
98#ifdef SK_RASTERIZE_EVEN_ROUNDING
99 x0 = SkScalarRoundToFDot6(p0.fX, shift);
100 y0 = SkScalarRoundToFDot6(p0.fY, shift);
101 x1 = SkScalarRoundToFDot6(p1.fX, shift);
102 y1 = SkScalarRoundToFDot6(p1.fY, shift);
103#else
104 float scale = float(1 << (shift + 6));
105 x0 = int(p0.fX * scale);
106 y0 = int(p0.fY * scale);
107 x1 = int(p1.fX * scale);
108 y1 = int(p1.fY * scale);
109#endif
110 }
111
112 int winding = 1;
113
114 if (y0 > y1) {
115 using std::swap;
116 swap(x0, x1);
117 swap(y0, y1);
118 winding = -1;
119 }
120
121 int top = SkFDot6Round(y0);
122 int bot = SkFDot6Round(y1);
123
124 // are we a zero-height line?
125 if (top == bot) {
126 return 0;
127 }
128
129 SkFixed slope = SkFDot6Div(x1 - x0, y1 - y0);
130 const SkFDot6 dy = SkEdge_Compute_DY(top, y0);
131
132 fX = SkFDot6ToFixed(x0 + SkFixedMul(slope, dy)); // + SK_Fixed1/2
133 fDX = slope;
134 fFirstY = top;
135 fLastY = bot - 1;
137 fCurveCount = 0;
138 fWinding = SkToS8(winding);
139 fCurveShift = 0;
140 return 1;
141}
142
143#endif
#define SkASSERT(cond)
Definition: SkAssert.h:116
#define SkEdge_Compute_DY(top, y0)
Definition: SkEdge.h:25
#define SkFDot6Round(x)
Definition: SkFDot6.h:54
int32_t SkFDot6
Definition: SkFDot6.h:16
SkFixed SkFDot6ToFixed(SkFDot6 x)
Definition: SkFDot6.h:58
SkFixed SkFDot6Div(SkFDot6 a, SkFDot6 b)
Definition: SkFDot6.h:68
SkFDot6 SkScalarRoundToFDot6(SkScalar x, int shift=0)
Definition: SkFDot6.h:23
int32_t SkFixed
Definition: SkFixed.h:25
static SkFixed SkFixedMul(SkFixed a, SkFixed b)
Definition: SkFixed.h:96
static SkPath clip(const SkPath &path, const SkHalfPlane &plane)
Definition: SkPath.cpp:3892
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
static void dump(const float m[20], SkYUVColorSpace cs, bool rgb2yuv)
Definition: SkYUVMath.cpp:629
const Scalar scale
int updateCubic()
Definition: SkEdge.cpp:481
SkFixed fCx
Definition: SkEdge.h:83
SkFixed fCDDy
Definition: SkEdge.h:85
bool setCubicWithoutUpdate(const SkPoint pts[4], int shiftUp, bool sortY=true)
Definition: SkEdge.cpp:373
SkFixed fCLastY
Definition: SkEdge.h:87
int setCubic(const SkPoint pts[4], int shiftUp)
Definition: SkEdge.cpp:474
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
Definition: SkEdge.h:27
SkEdge * fNext
Definition: SkEdge.h:34
int8_t fWinding
Definition: SkEdge.h:45
SkEdge * fPrev
Definition: SkEdge.h:35
int32_t fLastY
Definition: SkEdge.h:40
@ kCubic_Type
Definition: SkEdge.h:31
@ kLine_Type
Definition: SkEdge.h:29
@ kQuad_Type
Definition: SkEdge.h:30
SkFixed fX
Definition: SkEdge.h:37
int setLine(const SkPoint &p0, const SkPoint &p1, const SkIRect *clip, int shiftUp)
Definition: SkEdge.cpp:57
uint8_t fCurveShift
Definition: SkEdge.h:43
int updateLine(SkFixed ax, SkFixed ay, SkFixed bx, SkFixed by)
Definition: SkEdge.cpp:115
SkFixed fDX
Definition: SkEdge.h:38
Type fEdgeType
Definition: SkEdge.h:41
int8_t fCurveCount
Definition: SkEdge.h:42
void chopLineWithClip(const SkIRect &clip)
Definition: SkEdge.cpp:149
int32_t fFirstY
Definition: SkEdge.h:39
uint8_t fCubicDShift
Definition: SkEdge.h:44
bool intersectsClip(const SkIRect &clip) const
Definition: SkEdge.h:53
Definition: SkRect.h:32
float fX
x-axis value
Definition: SkPoint_impl.h:164
float fY
y-axis value
Definition: SkPoint_impl.h:165
int setQuadratic(const SkPoint pts[3], int shiftUp)
Definition: SkEdge.cpp:303
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
bool setQuadraticWithoutUpdate(const SkPoint pts[3], int shiftUp)
Definition: SkEdge.cpp:202
int updateQuadratic()
Definition: SkEdge.cpp:310
SkFixed fQx
Definition: SkEdge.h:72
SkFixed fQy
Definition: SkEdge.h:72