• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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     static void HairSquarePath(const SkPath&, const SkRasterClip&, SkBlitter*);
60     static void AntiHairSquarePath(const SkPath&, const SkRasterClip&, SkBlitter*);
61     static void HairRoundPath(const SkPath&, const SkRasterClip&, SkBlitter*);
62     static void AntiHairRoundPath(const SkPath&, const SkRasterClip&, SkBlitter*);
63 
64 private:
65     friend class SkAAClip;
66     friend class SkRegion;
67 
68     static void FillIRect(const SkIRect&, const SkRegion* clip, SkBlitter*);
69     static void FillXRect(const SkXRect&, const SkRegion* clip, SkBlitter*);
70     static void FillRect(const SkRect&, const SkRegion* clip, SkBlitter*);
71     static void AntiFillRect(const SkRect&, const SkRegion* clip, SkBlitter*);
72     static void AntiFillXRect(const SkXRect&, const SkRegion*, SkBlitter*);
73     static void FillPath(const SkPath&, const SkRegion& clip, SkBlitter*);
74     static void AntiFillPath(const SkPath&, const SkRegion& clip, SkBlitter*,
75                              bool forceRLE = false);
76     static void FillTriangle(const SkPoint pts[], const SkRegion*, SkBlitter*);
77 
78     static void AntiFrameRect(const SkRect&, const SkPoint& strokeSize,
79                               const SkRegion*, SkBlitter*);
80     static void HairLineRgn(const SkPoint[], int count, const SkRegion*, SkBlitter*);
81     static void AntiHairLineRgn(const SkPoint[], int count, const SkRegion*, SkBlitter*);
82 };
83 
84 /** Assign an SkXRect from a SkIRect, by promoting the src rect's coordinates
85     from int to SkFixed. Does not check for overflow if the src coordinates
86     exceed 32K
87 */
XRect_set(SkXRect * xr,const SkIRect & src)88 static inline void XRect_set(SkXRect* xr, const SkIRect& src) {
89     xr->fLeft = SkIntToFixed(src.fLeft);
90     xr->fTop = SkIntToFixed(src.fTop);
91     xr->fRight = SkIntToFixed(src.fRight);
92     xr->fBottom = SkIntToFixed(src.fBottom);
93 }
94 
95 /** Assign an SkXRect from a SkRect, by promoting the src rect's coordinates
96     from SkScalar to SkFixed. Does not check for overflow if the src coordinates
97     exceed 32K
98 */
XRect_set(SkXRect * xr,const SkRect & src)99 static inline void XRect_set(SkXRect* xr, const SkRect& src) {
100     xr->fLeft = SkScalarToFixed(src.fLeft);
101     xr->fTop = SkScalarToFixed(src.fTop);
102     xr->fRight = SkScalarToFixed(src.fRight);
103     xr->fBottom = SkScalarToFixed(src.fBottom);
104 }
105 
106 /** Round the SkXRect coordinates, and store the result in the SkIRect.
107 */
XRect_round(const SkXRect & xr,SkIRect * dst)108 static inline void XRect_round(const SkXRect& xr, SkIRect* dst) {
109     dst->fLeft = SkFixedRoundToInt(xr.fLeft);
110     dst->fTop = SkFixedRoundToInt(xr.fTop);
111     dst->fRight = SkFixedRoundToInt(xr.fRight);
112     dst->fBottom = SkFixedRoundToInt(xr.fBottom);
113 }
114 
115 /** Round the SkXRect coordinates out (i.e. use floor for left/top, and ceiling
116     for right/bottom), and store the result in the SkIRect.
117 */
XRect_roundOut(const SkXRect & xr,SkIRect * dst)118 static inline void XRect_roundOut(const SkXRect& xr, SkIRect* dst) {
119     dst->fLeft = SkFixedFloorToInt(xr.fLeft);
120     dst->fTop = SkFixedFloorToInt(xr.fTop);
121     dst->fRight = SkFixedCeilToInt(xr.fRight);
122     dst->fBottom = SkFixedCeilToInt(xr.fBottom);
123 }
124 
125 #endif
126