• 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 "include/core/SkRect.h"
13 #include "include/private/SkFixed.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> gSkUseAnalyticAA;
27 extern std::atomic<bool> gSkForceAnalyticAA;
28 
29 class AdditiveBlitter;
30 
31 class SkScan {
32 public:
33     /*
34      *  Draws count-1 line segments, one at a time:
35      *      line(pts[0], pts[1])
36      *      line(pts[1], pts[2])
37      *      line(......, pts[count - 1])
38      */
39     typedef void (*HairRgnProc)(const SkPoint[], int count, const SkRegion*, SkBlitter*);
40     typedef void (*HairRCProc)(const SkPoint[], int count, const SkRasterClip&, SkBlitter*);
41 
42     static void FillPath(const SkPath&, const SkIRect&, SkBlitter*);
43 
44     // Paths of a certain size cannot be anti-aliased unless externally tiled (handled by SkDraw).
45     // AA clipping doesn't do that, so it's better for the clip stack to adjust AA state early
46     // rather than clip to the internal limits of the blitter.
47     static bool DowngradeClipAA(const SkIRect& bounds);
48 
49     ///////////////////////////////////////////////////////////////////////////
50     // rasterclip
51 
52     static void FillIRect(const SkIRect&, const SkRasterClip&, SkBlitter*);
53     static void FillXRect(const SkXRect&, const SkRasterClip&, SkBlitter*);
54     static void FillRect(const SkRect&, const SkRasterClip&, SkBlitter*);
55     static void AntiFillRect(const SkRect&, const SkRasterClip&, SkBlitter*);
56     static void AntiFillXRect(const SkXRect&, const SkRasterClip&, SkBlitter*);
57     static void FillPath(const SkPath&, const SkRasterClip&, SkBlitter*);
58     static void AntiFillPath(const SkPath&, const SkRasterClip&, SkBlitter*);
59     static void FrameRect(const SkRect&, const SkPoint& strokeSize,
60                           const SkRasterClip&, SkBlitter*);
61     static void AntiFrameRect(const SkRect&, const SkPoint& strokeSize,
62                               const SkRasterClip&, SkBlitter*);
63     static void FillTriangle(const SkPoint pts[], const SkRasterClip&, SkBlitter*);
64     static void HairLine(const SkPoint[], int count, const SkRasterClip&, SkBlitter*);
65     static void AntiHairLine(const SkPoint[], int count, const SkRasterClip&, SkBlitter*);
66     static void HairRect(const SkRect&, const SkRasterClip&, SkBlitter*);
67     static void AntiHairRect(const SkRect&, const SkRasterClip&, SkBlitter*);
68     static void HairPath(const SkPath&, const SkRasterClip&, SkBlitter*);
69     static void AntiHairPath(const SkPath&, const SkRasterClip&, SkBlitter*);
70     static void HairSquarePath(const SkPath&, const SkRasterClip&, SkBlitter*);
71     static void AntiHairSquarePath(const SkPath&, const SkRasterClip&, SkBlitter*);
72     static void HairRoundPath(const SkPath&, const SkRasterClip&, SkBlitter*);
73     static void AntiHairRoundPath(const SkPath&, const SkRasterClip&, SkBlitter*);
74 
75     // Needed by do_fill_path in SkScanPriv.h
76     static void FillPath(const SkPath&, const SkRegion& clip, SkBlitter*);
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*, bool forceRLE);
88     static void FillTriangle(const SkPoint pts[], const SkRegion*, SkBlitter*);
89 
90     static void AntiFrameRect(const SkRect&, const SkPoint& strokeSize,
91                               const SkRegion*, SkBlitter*);
92     static void HairLineRgn(const SkPoint[], int count, const SkRegion*, SkBlitter*);
93     static void AntiHairLineRgn(const SkPoint[], int count, const SkRegion*, SkBlitter*);
94     static void AAAFillPath(const SkPath& path, SkBlitter* blitter, const SkIRect& pathIR,
95                             const SkIRect& clipBounds, bool forceRLE);
96     static void SAAFillPath(const SkPath& path, SkBlitter* blitter, const SkIRect& pathIR,
97                             const SkIRect& clipBounds, bool forceRLE);
98 };
99 
100 /** Assign an SkXRect from a SkIRect, by promoting the src rect's coordinates
101     from int to SkFixed. Does not check for overflow if the src coordinates
102     exceed 32K
103 */
XRect_set(SkXRect * xr,const SkIRect & src)104 static inline void XRect_set(SkXRect* xr, const SkIRect& src) {
105     xr->fLeft = SkIntToFixed(src.fLeft);
106     xr->fTop = SkIntToFixed(src.fTop);
107     xr->fRight = SkIntToFixed(src.fRight);
108     xr->fBottom = SkIntToFixed(src.fBottom);
109 }
110 
111 /** Assign an SkXRect from a SkRect, by promoting the src rect's coordinates
112     from SkScalar to SkFixed. Does not check for overflow if the src coordinates
113     exceed 32K
114 */
XRect_set(SkXRect * xr,const SkRect & src)115 static inline void XRect_set(SkXRect* xr, const SkRect& src) {
116     xr->fLeft = SkScalarToFixed(src.fLeft);
117     xr->fTop = SkScalarToFixed(src.fTop);
118     xr->fRight = SkScalarToFixed(src.fRight);
119     xr->fBottom = SkScalarToFixed(src.fBottom);
120 }
121 
122 /** Round the SkXRect coordinates, and store the result in the SkIRect.
123 */
XRect_round(const SkXRect & xr,SkIRect * dst)124 static inline void XRect_round(const SkXRect& xr, SkIRect* dst) {
125     dst->fLeft = SkFixedRoundToInt(xr.fLeft);
126     dst->fTop = SkFixedRoundToInt(xr.fTop);
127     dst->fRight = SkFixedRoundToInt(xr.fRight);
128     dst->fBottom = SkFixedRoundToInt(xr.fBottom);
129 }
130 
131 /** Round the SkXRect coordinates out (i.e. use floor for left/top, and ceiling
132     for right/bottom), and store the result in the SkIRect.
133 */
XRect_roundOut(const SkXRect & xr,SkIRect * dst)134 static inline void XRect_roundOut(const SkXRect& xr, SkIRect* dst) {
135     dst->fLeft = SkFixedFloorToInt(xr.fLeft);
136     dst->fTop = SkFixedFloorToInt(xr.fTop);
137     dst->fRight = SkFixedCeilToInt(xr.fRight);
138     dst->fBottom = SkFixedCeilToInt(xr.fBottom);
139 }
140 
141 #endif
142