• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* libs/graphics/sgl/SkScan.h
2 **
3 ** Copyright 2011, The Android Open Source Project
4 **
5 ** Licensed under the Apache License, Version 2.0 (the "License");
6 ** you may not use this file except in compliance with the License.
7 ** You may obtain a copy of the License at
8 **
9 **     http://www.apache.org/licenses/LICENSE-2.0
10 **
11 ** Unless required by applicable law or agreed to in writing, software
12 ** distributed under the License is distributed on an "AS IS" BASIS,
13 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 ** See the License for the specific language governing permissions and
15 ** limitations under the License.
16 */
17 
18 #ifndef SkScan_DEFINED
19 #define SkScan_DEFINED
20 
21 #include "SkRect.h"
22 
23 class SkRegion;
24 class SkBlitter;
25 class SkPath;
26 
27 /** Defines a fixed-point rectangle, identical to the integer SkIRect, but its
28     coordinates are treated as SkFixed rather than int32_t.
29 */
30 typedef SkIRect SkXRect;
31 
32 class SkScan {
33 public:
34     static void FillIRect(const SkIRect&, const SkRegion* clip, SkBlitter*);
35     static void FillXRect(const SkXRect&, const SkRegion* clip, SkBlitter*);
36 
37 #ifdef SK_SCALAR_IS_FIXED
FillRect(const SkRect & rect,const SkRegion * clip,SkBlitter * blitter)38     static void FillRect(const SkRect& rect, const SkRegion* clip,
39                          SkBlitter* blitter) {
40         SkScan::FillXRect(*(const SkXRect*)&rect, clip, blitter);
41     }
42 #else
43     static void FillRect(const SkRect&, const SkRegion* clip, SkBlitter*);
44 #endif
45     static void FillPath(const SkPath&, const SkRegion& clip, SkBlitter*);
46 
47     static void FillTriangle(const SkPoint pts[], const SkRegion*, SkBlitter*);
FillTriangle(const SkPoint & a,const SkPoint & b,const SkPoint & c,const SkRegion * clip,SkBlitter * blitter)48     static void FillTriangle(const SkPoint& a, const SkPoint& b,
49                              const SkPoint& c, const SkRegion* clip,
50                              SkBlitter* blitter) {
51         SkPoint pts[3];
52         pts[0] = a;
53         pts[1] = b;
54         pts[2] = c;
55         FillTriangle(pts, clip, blitter);
56     }
57 
58     static void HairLine(const SkPoint&, const SkPoint&, const SkRegion*,
59                          SkBlitter*);
60     static void HairRect(const SkRect&, const SkRegion* clip, SkBlitter*);
61     static void HairPath(const SkPath&, const SkRegion* clip, SkBlitter*);
62 
63     static void AntiFillXRect(const SkXRect&, const SkRegion* clip, SkBlitter*);
64 #ifdef SK_SCALAR_IS_FIXED
AntiFillRect(const SkRect & rect,const SkRegion * clip,SkBlitter * blitter)65     static void AntiFillRect(const SkRect& rect, const SkRegion* clip,
66                          SkBlitter* blitter) {
67         SkScan::AntiFillXRect(*(const SkXRect*)&rect, clip, blitter);
68     }
69 #else
70     static void AntiFillRect(const SkRect&, const SkRegion* clip, SkBlitter*);
71 #endif
72 
73     static void AntiFillPath(const SkPath&, const SkRegion& clip, SkBlitter*);
74 
75     static void AntiHairLine(const SkPoint&, const SkPoint&, const SkRegion*,
76                              SkBlitter*);
77     static void AntiHairRect(const SkRect&, const SkRegion* clip, SkBlitter*);
78     static void AntiHairPath(const SkPath&, const SkRegion* clip, SkBlitter*);
79 
80     // draws with a miter-join
81     static void FrameRect(const SkRect&, const SkPoint& strokeSize,
82                           const SkRegion*, SkBlitter*);
83     static void AntiFrameRect(const SkRect&, const SkPoint& strokeSize,
84                               const SkRegion*, SkBlitter*);
85 };
86 
87 /** Assign an SkXRect from a SkIRect, by promoting the src rect's coordinates
88     from int to SkFixed. Does not check for overflow if the src coordinates
89     exceed 32K
90 */
XRect_set(SkXRect * xr,const SkIRect & src)91 static inline void XRect_set(SkXRect* xr, const SkIRect& src) {
92     xr->fLeft = SkIntToFixed(src.fLeft);
93     xr->fTop = SkIntToFixed(src.fTop);
94     xr->fRight = SkIntToFixed(src.fRight);
95     xr->fBottom = SkIntToFixed(src.fBottom);
96 }
97 
98 /** Assign an SkXRect from a SkRect, by promoting the src rect's coordinates
99     from SkScalar to SkFixed. Does not check for overflow if the src coordinates
100     exceed 32K
101 */
XRect_set(SkXRect * xr,const SkRect & src)102 static inline void XRect_set(SkXRect* xr, const SkRect& src) {
103     xr->fLeft = SkScalarToFixed(src.fLeft);
104     xr->fTop = SkScalarToFixed(src.fTop);
105     xr->fRight = SkScalarToFixed(src.fRight);
106     xr->fBottom = SkScalarToFixed(src.fBottom);
107 }
108 
109 /** Round the SkXRect coordinates, and store the result in the SkIRect.
110 */
XRect_round(const SkXRect & xr,SkIRect * dst)111 static inline void XRect_round(const SkXRect& xr, SkIRect* dst) {
112     dst->fLeft = SkFixedRound(xr.fLeft);
113     dst->fTop = SkFixedRound(xr.fTop);
114     dst->fRight = SkFixedRound(xr.fRight);
115     dst->fBottom = SkFixedRound(xr.fBottom);
116 }
117 
118 /** Round the SkXRect coordinates out (i.e. use floor for left/top, and ceiling
119     for right/bottom), and store the result in the SkIRect.
120 */
XRect_roundOut(const SkXRect & xr,SkIRect * dst)121 static inline void XRect_roundOut(const SkXRect& xr, SkIRect* dst) {
122     dst->fLeft = SkFixedFloor(xr.fLeft);
123     dst->fTop = SkFixedFloor(xr.fTop);
124     dst->fRight = SkFixedCeil(xr.fRight);
125     dst->fBottom = SkFixedCeil(xr.fBottom);
126 }
127 
128 #endif
129