• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2011 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 
9 #ifndef SkScan_DEFINED
10 #define SkScan_DEFINED
11 
12 #include "SkCoverageDelta.h"
13 #include "SkFixed.h"
14 #include "SkRect.h"
15 #include <atomic>
16 
17 class SkRasterClip;
18 class SkRegion;
19 class SkBlitter;
20 class SkPath;
21 
22 /** Defines a fixed-point rectangle, identical to the integer SkIRect, but its
23     coordinates are treated as SkFixed rather than int32_t.
24 */
25 typedef SkIRect SkXRect;
26 
27 extern std::atomic<bool> gSkUseDeltaAA;
28 extern std::atomic<bool> gSkForceDeltaAA;
29 extern std::atomic<bool> gSkUseAnalyticAA;
30 extern std::atomic<bool> gSkForceAnalyticAA;
31 
32 class AdditiveBlitter;
33 
34 class SkScan {
35 public:
36     /*
37      *  Draws count-1 line segments, one at a time:
38      *      line(pts[0], pts[1])
39      *      line(pts[1], pts[2])
40      *      line(......, pts[count - 1])
41      */
42     typedef void (*HairRgnProc)(const SkPoint[], int count, const SkRegion*, SkBlitter*);
43     typedef void (*HairRCProc)(const SkPoint[], int count, const SkRasterClip&, SkBlitter*);
44 
45     static void FillPath(const SkPath&, const SkIRect&, SkBlitter*);
46 
47     ///////////////////////////////////////////////////////////////////////////
48     // rasterclip
49 
50     static void FillIRect(const SkIRect&, const SkRasterClip&, SkBlitter*);
51     static void FillXRect(const SkXRect&, const SkRasterClip&, SkBlitter*);
52     static void FillRect(const SkRect&, const SkRasterClip&, SkBlitter*);
53     static void AntiFillRect(const SkRect&, const SkRasterClip&, SkBlitter*);
54     static void AntiFillXRect(const SkXRect&, const SkRasterClip&, SkBlitter*);
55     static void FillPath(const SkPath&, const SkRasterClip&, SkBlitter*);
56     static void AntiFillPath(const SkPath&, const SkRasterClip&, SkBlitter*, SkDAARecord*);
57     static void FrameRect(const SkRect&, const SkPoint& strokeSize,
58                           const SkRasterClip&, SkBlitter*);
59     static void AntiFrameRect(const SkRect&, const SkPoint& strokeSize,
60                               const SkRasterClip&, SkBlitter*);
61     static void FillTriangle(const SkPoint pts[], const SkRasterClip&, SkBlitter*);
62     static void HairLine(const SkPoint[], int count, const SkRasterClip&, SkBlitter*);
63     static void AntiHairLine(const SkPoint[], int count, const SkRasterClip&, SkBlitter*);
64     static void HairRect(const SkRect&, const SkRasterClip&, SkBlitter*);
65     static void AntiHairRect(const SkRect&, const SkRasterClip&, SkBlitter*);
66     static void HairPath(const SkPath&, const SkRasterClip&, SkBlitter*);
67     static void AntiHairPath(const SkPath&, const SkRasterClip&, SkBlitter*);
68     static void HairSquarePath(const SkPath&, const SkRasterClip&, SkBlitter*);
69     static void AntiHairSquarePath(const SkPath&, const SkRasterClip&, SkBlitter*);
70     static void HairRoundPath(const SkPath&, const SkRasterClip&, SkBlitter*);
71     static void AntiHairRoundPath(const SkPath&, const SkRasterClip&, SkBlitter*);
72 
73     // Needed by do_fill_path in SkScanPriv.h
74     static void FillPath(const SkPath&, const SkRegion& clip, SkBlitter*);
75 
76     // We have this instead of a default nullptr parameter because of function pointer match.
AntiFillPath(const SkPath & path,const SkRasterClip & rc,SkBlitter * blitter)77     static void AntiFillPath(const SkPath& path, const SkRasterClip& rc, SkBlitter* blitter) {
78         AntiFillPath(path, rc, blitter, nullptr);
79     }
80 private:
81     friend class SkAAClip;
82     friend class SkRegion;
83 
84     static void FillIRect(const SkIRect&, const SkRegion* clip, SkBlitter*);
85     static void FillXRect(const SkXRect&, const SkRegion* clip, SkBlitter*);
86     static void FillRect(const SkRect&, const SkRegion* clip, SkBlitter*);
87     static void AntiFillRect(const SkRect&, const SkRegion* clip, SkBlitter*);
88     static void AntiFillXRect(const SkXRect&, const SkRegion*, SkBlitter*);
89     static void AntiFillPath(const SkPath&, const SkRegion& clip, SkBlitter*,
90                              bool forceRLE = false, SkDAARecord* daaRecord = nullptr);
91     static void FillTriangle(const SkPoint pts[], const SkRegion*, SkBlitter*);
92 
93     static void AntiFrameRect(const SkRect&, const SkPoint& strokeSize,
94                               const SkRegion*, SkBlitter*);
95     static void HairLineRgn(const SkPoint[], int count, const SkRegion*, SkBlitter*);
96     static void AntiHairLineRgn(const SkPoint[], int count, const SkRegion*, SkBlitter*);
97     static void AAAFillPath(const SkPath& path, SkBlitter* blitter, const SkIRect& pathIR,
98                             const SkIRect& clipBounds, bool forceRLE);
99     static void DAAFillPath(const SkPath& path, SkBlitter* blitter, const SkIRect& pathIR,
100                             const SkIRect& clipBounds, bool forceRLE, SkDAARecord* daaRecord);
101     static void SAAFillPath(const SkPath& path, SkBlitter* blitter, const SkIRect& pathIR,
102                             const SkIRect& clipBounds, bool forceRLE);
103 };
104 
105 /** Assign an SkXRect from a SkIRect, by promoting the src rect's coordinates
106     from int to SkFixed. Does not check for overflow if the src coordinates
107     exceed 32K
108 */
XRect_set(SkXRect * xr,const SkIRect & src)109 static inline void XRect_set(SkXRect* xr, const SkIRect& src) {
110     xr->fLeft = SkIntToFixed(src.fLeft);
111     xr->fTop = SkIntToFixed(src.fTop);
112     xr->fRight = SkIntToFixed(src.fRight);
113     xr->fBottom = SkIntToFixed(src.fBottom);
114 }
115 
116 /** Assign an SkXRect from a SkRect, by promoting the src rect's coordinates
117     from SkScalar to SkFixed. Does not check for overflow if the src coordinates
118     exceed 32K
119 */
XRect_set(SkXRect * xr,const SkRect & src)120 static inline void XRect_set(SkXRect* xr, const SkRect& src) {
121     xr->fLeft = SkScalarToFixed(src.fLeft);
122     xr->fTop = SkScalarToFixed(src.fTop);
123     xr->fRight = SkScalarToFixed(src.fRight);
124     xr->fBottom = SkScalarToFixed(src.fBottom);
125 }
126 
127 /** Round the SkXRect coordinates, and store the result in the SkIRect.
128 */
XRect_round(const SkXRect & xr,SkIRect * dst)129 static inline void XRect_round(const SkXRect& xr, SkIRect* dst) {
130     dst->fLeft = SkFixedRoundToInt(xr.fLeft);
131     dst->fTop = SkFixedRoundToInt(xr.fTop);
132     dst->fRight = SkFixedRoundToInt(xr.fRight);
133     dst->fBottom = SkFixedRoundToInt(xr.fBottom);
134 }
135 
136 /** Round the SkXRect coordinates out (i.e. use floor for left/top, and ceiling
137     for right/bottom), and store the result in the SkIRect.
138 */
XRect_roundOut(const SkXRect & xr,SkIRect * dst)139 static inline void XRect_roundOut(const SkXRect& xr, SkIRect* dst) {
140     dst->fLeft = SkFixedFloorToInt(xr.fLeft);
141     dst->fTop = SkFixedFloorToInt(xr.fTop);
142     dst->fRight = SkFixedCeilToInt(xr.fRight);
143     dst->fBottom = SkFixedCeilToInt(xr.fBottom);
144 }
145 
146 #endif
147