blob: 29a50d1520c9614d57156d3af86de9bd61c1e13a [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001
2/*
3 * Copyright 2006 The Android Open Source Project
4 *
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
7 */
8
reed@android.com8a1c16f2008-12-17 15:59:43 +00009
10#ifndef SkEdge_DEFINED
11#define SkEdge_DEFINED
12
13#include "SkRect.h"
14
15struct SkEdge {
16 enum Type {
17 kLine_Type,
18 kQuad_Type,
19 kCubic_Type
20 };
21
22 SkEdge* fNext;
23 SkEdge* fPrev;
24
25 SkFixed fX;
26 SkFixed fDX;
27 int32_t fFirstY;
28 int32_t fLastY;
29 int8_t fCurveCount; // only used by kQuad(+) and kCubic(-)
30 uint8_t fCurveShift; // appled to all Dx/DDx/DDDx except for fCubicDShift exception
31 uint8_t fCubicDShift; // applied to fCDx and fCDy only in cubic
32 int8_t fWinding; // 1 or -1
33
34 int setLine(const SkPoint& p0, const SkPoint& p1, const SkIRect* clip,
35 int shiftUp);
36 inline int updateLine(SkFixed ax, SkFixed ay, SkFixed bx, SkFixed by);
37 void chopLineWithClip(const SkIRect& clip);
38
39 inline bool intersectsClip(const SkIRect& clip) const {
40 SkASSERT(fFirstY < clip.fBottom);
41 return fLastY >= clip.fTop;
42 }
43
44#ifdef SK_DEBUG
45 void dump() const {
46 #ifdef SK_CAN_USE_FLOAT
47 SkDebugf("edge: firstY:%d lastY:%d x:%g dx:%g w:%d\n", fFirstY, fLastY, SkFixedToFloat(fX), SkFixedToFloat(fDX), fWinding);
48 #else
49 SkDebugf("edge: firstY:%d lastY:%d x:%x dx:%x w:%d\n", fFirstY, fLastY, fX, fDX, fWinding);
50 #endif
51 }
52
53 void validate() const {
54 SkASSERT(fPrev && fNext);
55 SkASSERT(fPrev->fNext == this);
56 SkASSERT(fNext->fPrev == this);
57
58 SkASSERT(fFirstY <= fLastY);
59 SkASSERT(SkAbs32(fWinding) == 1);
60 }
61#endif
62};
63
64struct SkQuadraticEdge : public SkEdge {
65 SkFixed fQx, fQy;
66 SkFixed fQDx, fQDy;
67 SkFixed fQDDx, fQDDy;
68 SkFixed fQLastX, fQLastY;
69
reed@android.comc07d23a2009-02-06 13:30:58 +000070 int setQuadratic(const SkPoint pts[3], int shiftUp);
reed@android.com8a1c16f2008-12-17 15:59:43 +000071 int updateQuadratic();
72};
73
74struct SkCubicEdge : public SkEdge {
75 SkFixed fCx, fCy;
76 SkFixed fCDx, fCDy;
77 SkFixed fCDDx, fCDDy;
78 SkFixed fCDDDx, fCDDDy;
79 SkFixed fCLastX, fCLastY;
80
81 int setCubic(const SkPoint pts[4], const SkIRect* clip, int shiftUp);
82 int updateCubic();
83};
84
85#endif