Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
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
11#include "include/core/SkRect.h"
18#include "src/core/SkFDot6.h"
19
20#include <cstdint>
21#include <utility>
22
23// This correctly favors the lower-pixel when y0 is on a 1/2 pixel boundary
24#define SkEdge_Compute_DY(top, y0) (SkLeftShift(top, 6) + 32 - (y0))
25
26struct SkEdge {
32
35
38 int32_t fFirstY;
39 int32_t fLastY;
40 Type fEdgeType; // Remembers the *initial* edge type
41 int8_t fCurveCount; // only used by kQuad(+) and kCubic(-)
42 uint8_t fCurveShift; // appled to all Dx/DDx/DDDx except for fCubicDShift exception
43 uint8_t fCubicDShift; // applied to fCDx and fCDy only in cubic
44 int8_t fWinding; // 1 or -1
45
46 int setLine(const SkPoint& p0, const SkPoint& p1, const SkIRect* clip, int shiftUp);
47 // call this version if you know you don't have a clip
48 inline int setLine(const SkPoint& p0, const SkPoint& p1, int shiftUp);
49 inline int updateLine(SkFixed ax, SkFixed ay, SkFixed bx, SkFixed by);
50 void chopLineWithClip(const SkIRect& clip);
51
52 inline bool intersectsClip(const SkIRect& clip) const {
53 SkASSERT(fFirstY < clip.fBottom);
54 return fLastY >= clip.fTop;
55 }
56
57#ifdef SK_DEBUG
58 void dump() const;
59 void validate() const {
61 SkASSERT(fPrev->fNext == this);
62 SkASSERT(fNext->fPrev == this);
63
66 }
67#endif
68};
69
70struct SkQuadraticEdge : public SkEdge {
75
76 bool setQuadraticWithoutUpdate(const SkPoint pts[3], int shiftUp);
77 int setQuadratic(const SkPoint pts[3], int shiftUp);
78 int updateQuadratic();
79};
80
81struct SkCubicEdge : public SkEdge {
87
88 bool setCubicWithoutUpdate(const SkPoint pts[4], int shiftUp, bool sortY = true);
89 int setCubic(const SkPoint pts[4], int shiftUp);
90 int updateCubic();
91};
92
93int SkEdge::setLine(const SkPoint& p0, const SkPoint& p1, int shift) {
94 SkFDot6 x0, y0, x1, y1;
95
96 {
97#ifdef SK_RASTERIZE_EVEN_ROUNDING
98 x0 = SkScalarRoundToFDot6(p0.fX, shift);
99 y0 = SkScalarRoundToFDot6(p0.fY, shift);
100 x1 = SkScalarRoundToFDot6(p1.fX, shift);
101 y1 = SkScalarRoundToFDot6(p1.fY, shift);
102#else
103 float scale = float(1 << (shift + 6));
104 x0 = int(p0.fX * scale);
105 y0 = int(p0.fY * scale);
106 x1 = int(p1.fX * scale);
107 y1 = int(p1.fY * scale);
108#endif
109 }
110
111 int winding = 1;
112
113 if (y0 > y1) {
114 using std::swap;
115 swap(x0, x1);
116 swap(y0, y1);
117 winding = -1;
118 }
119
120 int top = SkFDot6Round(y0);
121 int bot = SkFDot6Round(y1);
122
123 // are we a zero-height line?
124 if (top == bot) {
125 return 0;
126 }
127
128 SkFixed slope = SkFDot6Div(x1 - x0, y1 - y0);
129 const SkFDot6 dy = SkEdge_Compute_DY(top, y0);
130
131 fX = SkFDot6ToFixed(x0 + SkFixedMul(slope, dy)); // + SK_Fixed1/2
132 fDX = slope;
133 fFirstY = top;
134 fLastY = bot - 1;
136 fCurveCount = 0;
137 fWinding = SkToS8(winding);
138 fCurveShift = 0;
139 return 1;
140}
141
142#endif
#define SkASSERT(cond)
Definition SkAssert.h:116
#define SkEdge_Compute_DY(top, y0)
Definition SkEdge.h:24
#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:3824
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)
Type::kYUV Type::kRGBA() int(0.7 *637)
const Scalar scale
int updateCubic()
Definition SkEdge.cpp:481
SkFixed fCx
Definition SkEdge.h:82
SkFixed fCDDy
Definition SkEdge.h:84
bool setCubicWithoutUpdate(const SkPoint pts[4], int shiftUp, bool sortY=true)
Definition SkEdge.cpp:373
SkFixed fCLastY
Definition SkEdge.h:86
int setCubic(const SkPoint pts[4], int shiftUp)
Definition SkEdge.cpp:474
SkFixed fCLastX
Definition SkEdge.h:86
SkFixed fCDDDy
Definition SkEdge.h:85
SkFixed fCDDDx
Definition SkEdge.h:85
SkFixed fCDx
Definition SkEdge.h:83
SkFixed fCy
Definition SkEdge.h:82
SkFixed fCDy
Definition SkEdge.h:83
SkFixed fCDDx
Definition SkEdge.h:84
SkEdge * fNext
Definition SkEdge.h:33
int8_t fWinding
Definition SkEdge.h:44
SkEdge * fPrev
Definition SkEdge.h:34
int32_t fLastY
Definition SkEdge.h:39
@ kCubic_Type
Definition SkEdge.h:30
@ kLine_Type
Definition SkEdge.h:28
@ kQuad_Type
Definition SkEdge.h:29
SkFixed fX
Definition SkEdge.h:36
int setLine(const SkPoint &p0, const SkPoint &p1, const SkIRect *clip, int shiftUp)
Definition SkEdge.cpp:57
uint8_t fCurveShift
Definition SkEdge.h:42
int updateLine(SkFixed ax, SkFixed ay, SkFixed bx, SkFixed by)
Definition SkEdge.cpp:115
SkFixed fDX
Definition SkEdge.h:37
Type fEdgeType
Definition SkEdge.h:40
int8_t fCurveCount
Definition SkEdge.h:41
void chopLineWithClip(const SkIRect &clip)
Definition SkEdge.cpp:149
int32_t fFirstY
Definition SkEdge.h:38
uint8_t fCubicDShift
Definition SkEdge.h:43
bool intersectsClip(const SkIRect &clip) const
Definition SkEdge.h:52
float fX
x-axis value
float fY
y-axis value
int setQuadratic(const SkPoint pts[3], int shiftUp)
Definition SkEdge.cpp:303
SkFixed fQDx
Definition SkEdge.h:72
SkFixed fQDDx
Definition SkEdge.h:73
SkFixed fQLastX
Definition SkEdge.h:74
SkFixed fQDy
Definition SkEdge.h:72
SkFixed fQDDy
Definition SkEdge.h:73
SkFixed fQLastY
Definition SkEdge.h:74
bool setQuadraticWithoutUpdate(const SkPoint pts[3], int shiftUp)
Definition SkEdge.cpp:202
int updateQuadratic()
Definition SkEdge.cpp:310
SkFixed fQx
Definition SkEdge.h:71
SkFixed fQy
Definition SkEdge.h:71