1
2 /*
3 * Copyright 2011 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
9
10 #ifndef SkScan_DEFINED
11 #define SkScan_DEFINED
12
13 #include "SkRect.h"
14
15 class SkRasterClip;
16 class SkRegion;
17 class SkBlitter;
18 class SkPath;
19
20 /** Defines a fixed-point rectangle, identical to the integer SkIRect, but its
21 coordinates are treated as SkFixed rather than int32_t.
22 */
23 typedef SkIRect SkXRect;
24
25 class SkScan {
26 public:
27 /*
28 * Draws count-1 line segments, one at a time:
29 * line(pts[0], pts[1])
30 * line(pts[1], pts[2])
31 * line(......, pts[count - 1])
32 */
33 typedef void (*HairRgnProc)(const SkPoint[], int count, const SkRegion*, SkBlitter*);
34 typedef void (*HairRCProc)(const SkPoint[], int count, const SkRasterClip&, SkBlitter*);
35
36 static void FillPath(const SkPath&, const SkIRect&, SkBlitter*);
37
38 ///////////////////////////////////////////////////////////////////////////
39 // rasterclip
40
41 static void FillIRect(const SkIRect&, const SkRasterClip&, SkBlitter*);
42 static void FillXRect(const SkXRect&, const SkRasterClip&, SkBlitter*);
43 static void FillRect(const SkRect&, const SkRasterClip&, SkBlitter*);
44 static void AntiFillRect(const SkRect&, const SkRasterClip&, SkBlitter*);
45 static void AntiFillXRect(const SkXRect&, const SkRasterClip&, SkBlitter*);
46 static void FillPath(const SkPath&, const SkRasterClip&, SkBlitter*);
47 static void AntiFillPath(const SkPath&, const SkRasterClip&, SkBlitter*);
48 static void FrameRect(const SkRect&, const SkPoint& strokeSize,
49 const SkRasterClip&, SkBlitter*);
50 static void AntiFrameRect(const SkRect&, const SkPoint& strokeSize,
51 const SkRasterClip&, SkBlitter*);
52 static void FillTriangle(const SkPoint pts[], const SkRasterClip&, SkBlitter*);
53 static void HairLine(const SkPoint[], int count, const SkRasterClip&, SkBlitter*);
54 static void AntiHairLine(const SkPoint[], int count, const SkRasterClip&, SkBlitter*);
55 static void HairRect(const SkRect&, const SkRasterClip&, SkBlitter*);
56 static void AntiHairRect(const SkRect&, const SkRasterClip&, SkBlitter*);
57 static void HairPath(const SkPath&, const SkRasterClip&, SkBlitter*);
58 static void AntiHairPath(const SkPath&, const SkRasterClip&, SkBlitter*);
59
60 private:
61 friend class SkAAClip;
62 friend class SkRegion;
63
64 static void FillIRect(const SkIRect&, const SkRegion* clip, SkBlitter*);
65 static void FillXRect(const SkXRect&, const SkRegion* clip, SkBlitter*);
66 static void FillRect(const SkRect&, const SkRegion* clip, SkBlitter*);
67 static void AntiFillRect(const SkRect&, const SkRegion* clip, SkBlitter*);
68 static void AntiFillXRect(const SkXRect&, const SkRegion*, SkBlitter*);
69 static void FillPath(const SkPath&, const SkRegion& clip, SkBlitter*);
70 static void AntiFillPath(const SkPath&, const SkRegion& clip, SkBlitter*,
71 bool forceRLE = false);
72 static void FillTriangle(const SkPoint pts[], const SkRegion*, SkBlitter*);
73
74 static void AntiFrameRect(const SkRect&, const SkPoint& strokeSize,
75 const SkRegion*, SkBlitter*);
76 static void HairLineRgn(const SkPoint[], int count, const SkRegion*, SkBlitter*);
77 static void AntiHairLineRgn(const SkPoint[], int count, const SkRegion*, SkBlitter*);
78 };
79
80 /** Assign an SkXRect from a SkIRect, by promoting the src rect's coordinates
81 from int to SkFixed. Does not check for overflow if the src coordinates
82 exceed 32K
83 */
XRect_set(SkXRect * xr,const SkIRect & src)84 static inline void XRect_set(SkXRect* xr, const SkIRect& src) {
85 xr->fLeft = SkIntToFixed(src.fLeft);
86 xr->fTop = SkIntToFixed(src.fTop);
87 xr->fRight = SkIntToFixed(src.fRight);
88 xr->fBottom = SkIntToFixed(src.fBottom);
89 }
90
91 /** Assign an SkXRect from a SkRect, by promoting the src rect's coordinates
92 from SkScalar to SkFixed. Does not check for overflow if the src coordinates
93 exceed 32K
94 */
XRect_set(SkXRect * xr,const SkRect & src)95 static inline void XRect_set(SkXRect* xr, const SkRect& src) {
96 xr->fLeft = SkScalarToFixed(src.fLeft);
97 xr->fTop = SkScalarToFixed(src.fTop);
98 xr->fRight = SkScalarToFixed(src.fRight);
99 xr->fBottom = SkScalarToFixed(src.fBottom);
100 }
101
102 /** Round the SkXRect coordinates, and store the result in the SkIRect.
103 */
XRect_round(const SkXRect & xr,SkIRect * dst)104 static inline void XRect_round(const SkXRect& xr, SkIRect* dst) {
105 dst->fLeft = SkFixedRoundToInt(xr.fLeft);
106 dst->fTop = SkFixedRoundToInt(xr.fTop);
107 dst->fRight = SkFixedRoundToInt(xr.fRight);
108 dst->fBottom = SkFixedRoundToInt(xr.fBottom);
109 }
110
111 /** Round the SkXRect coordinates out (i.e. use floor for left/top, and ceiling
112 for right/bottom), and store the result in the SkIRect.
113 */
XRect_roundOut(const SkXRect & xr,SkIRect * dst)114 static inline void XRect_roundOut(const SkXRect& xr, SkIRect* dst) {
115 dst->fLeft = SkFixedFloorToInt(xr.fLeft);
116 dst->fTop = SkFixedFloorToInt(xr.fTop);
117 dst->fRight = SkFixedCeilToInt(xr.fRight);
118 dst->fBottom = SkFixedCeilToInt(xr.fBottom);
119 }
120
121 #endif
122