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