Line data Source code
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> 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 : ///////////////////////////////////////////////////////////////////////////
45 : // rasterclip
46 :
47 : static void FillIRect(const SkIRect&, const SkRasterClip&, SkBlitter*);
48 : static void FillXRect(const SkXRect&, const SkRasterClip&, SkBlitter*);
49 : static void FillRect(const SkRect&, const SkRasterClip&, SkBlitter*);
50 : static void AntiFillRect(const SkRect&, const SkRasterClip&, SkBlitter*);
51 : static void AntiFillXRect(const SkXRect&, const SkRasterClip&, SkBlitter*);
52 : static void FillPath(const SkPath&, const SkRasterClip&, SkBlitter*);
53 : static void AntiFillPath(const SkPath&, const SkRasterClip&, SkBlitter*);
54 : static void AAAFillPath(const SkPath&, const SkRasterClip&, SkBlitter*);
55 : static void FrameRect(const SkRect&, const SkPoint& strokeSize,
56 : const SkRasterClip&, SkBlitter*);
57 : static void AntiFrameRect(const SkRect&, const SkPoint& strokeSize,
58 : const SkRasterClip&, SkBlitter*);
59 : static void FillTriangle(const SkPoint pts[], const SkRasterClip&, SkBlitter*);
60 : static void HairLine(const SkPoint[], int count, const SkRasterClip&, SkBlitter*);
61 : static void AntiHairLine(const SkPoint[], int count, const SkRasterClip&, SkBlitter*);
62 : static void HairRect(const SkRect&, const SkRasterClip&, SkBlitter*);
63 : static void AntiHairRect(const SkRect&, const SkRasterClip&, SkBlitter*);
64 : static void HairPath(const SkPath&, const SkRasterClip&, SkBlitter*);
65 : static void AntiHairPath(const SkPath&, const SkRasterClip&, SkBlitter*);
66 : static void HairSquarePath(const SkPath&, const SkRasterClip&, SkBlitter*);
67 : static void AntiHairSquarePath(const SkPath&, const SkRasterClip&, SkBlitter*);
68 : static void HairRoundPath(const SkPath&, const SkRasterClip&, SkBlitter*);
69 : static void AntiHairRoundPath(const SkPath&, const SkRasterClip&, SkBlitter*);
70 :
71 : private:
72 : friend class SkAAClip;
73 : friend class SkRegion;
74 :
75 : static void FillIRect(const SkIRect&, const SkRegion* clip, SkBlitter*);
76 : static void FillXRect(const SkXRect&, const SkRegion* clip, SkBlitter*);
77 : static void FillRect(const SkRect&, const SkRegion* clip, SkBlitter*);
78 : static void AntiFillRect(const SkRect&, const SkRegion* clip, SkBlitter*);
79 : static void AntiFillXRect(const SkXRect&, const SkRegion*, SkBlitter*);
80 : static void FillPath(const SkPath&, const SkRegion& clip, SkBlitter*);
81 : static void AntiFillPath(const SkPath&, const SkRegion& clip, SkBlitter*,
82 : bool forceRLE = false);
83 : static void FillTriangle(const SkPoint pts[], const SkRegion*, SkBlitter*);
84 :
85 : static void AntiFrameRect(const SkRect&, const SkPoint& strokeSize,
86 : const SkRegion*, SkBlitter*);
87 : static void HairLineRgn(const SkPoint[], int count, const SkRegion*, SkBlitter*);
88 : static void AntiHairLineRgn(const SkPoint[], int count, const SkRegion*, SkBlitter*);
89 : static void AAAFillPath(const SkPath& path, const SkRegion& origClip, SkBlitter* blitter,
90 : bool forceRLE = false); // SkAAClip uses forceRLE
91 : };
92 :
93 : /** Assign an SkXRect from a SkIRect, by promoting the src rect's coordinates
94 : from int to SkFixed. Does not check for overflow if the src coordinates
95 : exceed 32K
96 : */
97 0 : static inline void XRect_set(SkXRect* xr, const SkIRect& src) {
98 0 : xr->fLeft = SkIntToFixed(src.fLeft);
99 0 : xr->fTop = SkIntToFixed(src.fTop);
100 0 : xr->fRight = SkIntToFixed(src.fRight);
101 0 : xr->fBottom = SkIntToFixed(src.fBottom);
102 0 : }
103 :
104 : /** Assign an SkXRect from a SkRect, by promoting the src rect's coordinates
105 : from SkScalar to SkFixed. Does not check for overflow if the src coordinates
106 : exceed 32K
107 : */
108 236 : static inline void XRect_set(SkXRect* xr, const SkRect& src) {
109 236 : xr->fLeft = SkScalarToFixed(src.fLeft);
110 236 : xr->fTop = SkScalarToFixed(src.fTop);
111 236 : xr->fRight = SkScalarToFixed(src.fRight);
112 236 : xr->fBottom = SkScalarToFixed(src.fBottom);
113 236 : }
114 :
115 : /** Round the SkXRect coordinates, and store the result in the SkIRect.
116 : */
117 0 : static inline void XRect_round(const SkXRect& xr, SkIRect* dst) {
118 0 : dst->fLeft = SkFixedRoundToInt(xr.fLeft);
119 0 : dst->fTop = SkFixedRoundToInt(xr.fTop);
120 0 : dst->fRight = SkFixedRoundToInt(xr.fRight);
121 0 : dst->fBottom = SkFixedRoundToInt(xr.fBottom);
122 0 : }
123 :
124 : /** Round the SkXRect coordinates out (i.e. use floor for left/top, and ceiling
125 : for right/bottom), and store the result in the SkIRect.
126 : */
127 0 : static inline void XRect_roundOut(const SkXRect& xr, SkIRect* dst) {
128 0 : dst->fLeft = SkFixedFloorToInt(xr.fLeft);
129 0 : dst->fTop = SkFixedFloorToInt(xr.fTop);
130 0 : dst->fRight = SkFixedCeilToInt(xr.fRight);
131 0 : dst->fBottom = SkFixedCeilToInt(xr.fBottom);
132 0 : }
133 :
134 : #endif
|