blob: 8bb9d1f86deb4f34c7da1faa7383d6a17f42f1ac [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001/*
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
reed@android.com8a1c16f2008-12-17 15:59:43 +00008
9#ifndef SkScan_DEFINED
10#define SkScan_DEFINED
11
benjaminwagner6c71e0a2016-04-07 08:49:31 -070012#include "SkFixed.h"
reed@android.com8a1c16f2008-12-17 15:59:43 +000013#include "SkRect.h"
Mike Klein511f2d72016-10-04 15:45:56 -040014#include <atomic>
reed@android.com8a1c16f2008-12-17 15:59:43 +000015
reed@google.com1ba71372011-10-12 20:42:05 +000016class SkRasterClip;
reed@android.com8a1c16f2008-12-17 15:59:43 +000017class SkRegion;
18class SkBlitter;
19class 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*/
24typedef SkIRect SkXRect;
25
Yuqian Lidf60e362017-07-25 11:26:31 -040026extern std::atomic<bool> gSkUseDeltaAA;
27extern std::atomic<bool> gSkForceDeltaAA;
Mike Klein511f2d72016-10-04 15:45:56 -040028extern std::atomic<bool> gSkUseAnalyticAA;
Yuqian Li550148b2017-01-13 10:13:13 -050029extern std::atomic<bool> gSkForceAnalyticAA;
liyuqian38911a72016-10-04 11:23:22 -070030
31class AdditiveBlitter;
32
reed@android.com8a1c16f2008-12-17 15:59:43 +000033class SkScan {
34public:
reed5dc6b7d2015-04-14 10:40:44 -070035 /*
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
reed@google.com045e62d2011-10-24 12:19:46 +000044 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*);
reed@google.com045e62d2011-10-24 12:19:46 +000051 static void FillRect(const SkRect&, const SkRasterClip&, SkBlitter*);
52 static void AntiFillRect(const SkRect&, const SkRasterClip&, SkBlitter*);
reed@google.com045e62d2011-10-24 12:19:46 +000053 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*);
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*);
reed5dc6b7d2015-04-14 10:40:44 -070061 static void HairLine(const SkPoint[], int count, const SkRasterClip&, SkBlitter*);
62 static void AntiHairLine(const SkPoint[], int count, const SkRasterClip&, SkBlitter*);
reed@google.com045e62d2011-10-24 12:19:46 +000063 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*);
caryclark2028d7f2015-12-09 14:04:46 -080067 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*);
reed@google.com045e62d2011-10-24 12:19:46 +000071
Yuqian Lica50b872017-06-12 10:40:50 -040072 // Needed by do_fill_path in SkScanPriv.h
73 static void FillPath(const SkPath&, const SkRegion& clip, SkBlitter*);
74
reed@google.com045e62d2011-10-24 12:19:46 +000075private:
76 friend class SkAAClip;
77 friend class SkRegion;
78
reed@android.com8a1c16f2008-12-17 15:59:43 +000079 static void FillIRect(const SkIRect&, const SkRegion* clip, SkBlitter*);
80 static void FillXRect(const SkXRect&, const SkRegion* clip, SkBlitter*);
reed@google.com045e62d2011-10-24 12:19:46 +000081 static void FillRect(const SkRect&, const SkRegion* clip, SkBlitter*);
reed@android.com8a1c16f2008-12-17 15:59:43 +000082 static void AntiFillRect(const SkRect&, const SkRegion* clip, SkBlitter*);
reed@google.com67ba5fa2011-10-24 12:56:20 +000083 static void AntiFillXRect(const SkXRect&, const SkRegion*, SkBlitter*);
reed@google.com2c508f22011-10-03 21:15:46 +000084 static void AntiFillPath(const SkPath&, const SkRegion& clip, SkBlitter*,
85 bool forceRLE = false);
reed@google.com045e62d2011-10-24 12:19:46 +000086 static void FillTriangle(const SkPoint pts[], const SkRegion*, SkBlitter*);
rmistry@google.comfbfcd562012-08-23 18:09:54 +000087
reed@google.com761fb622011-04-04 18:58:05 +000088 static void AntiFrameRect(const SkRect&, const SkPoint& strokeSize,
89 const SkRegion*, SkBlitter*);
reed5dc6b7d2015-04-14 10:40:44 -070090 static void HairLineRgn(const SkPoint[], int count, const SkRegion*, SkBlitter*);
91 static void AntiHairLineRgn(const SkPoint[], int count, const SkRegion*, SkBlitter*);
liyuqian2add0ff2016-10-20 11:04:39 -070092 static void AAAFillPath(const SkPath& path, const SkRegion& origClip, SkBlitter* blitter,
93 bool forceRLE = false); // SkAAClip uses forceRLE
Yuqian Lidf60e362017-07-25 11:26:31 -040094 static void DAAFillPath(const SkPath& path, const SkRegion& origClip, SkBlitter* blitter,
95 bool forceRLE = false);
reed@android.com8a1c16f2008-12-17 15:59:43 +000096};
97
98/** Assign an SkXRect from a SkIRect, by promoting the src rect's coordinates
99 from int to SkFixed. Does not check for overflow if the src coordinates
100 exceed 32K
101*/
reed@android.comfc25abd2009-01-15 14:38:33 +0000102static inline void XRect_set(SkXRect* xr, const SkIRect& src) {
reed@android.com8a1c16f2008-12-17 15:59:43 +0000103 xr->fLeft = SkIntToFixed(src.fLeft);
104 xr->fTop = SkIntToFixed(src.fTop);
105 xr->fRight = SkIntToFixed(src.fRight);
106 xr->fBottom = SkIntToFixed(src.fBottom);
107}
108
109/** Assign an SkXRect from a SkRect, by promoting the src rect's coordinates
fmalitae7365062016-04-07 19:27:45 -0700110 from SkScalar to SkFixed. Does not check for overflow if the src coordinates
reed@android.com8a1c16f2008-12-17 15:59:43 +0000111 exceed 32K
112*/
reed@android.comfc25abd2009-01-15 14:38:33 +0000113static inline void XRect_set(SkXRect* xr, const SkRect& src) {
reed@android.com8a1c16f2008-12-17 15:59:43 +0000114 xr->fLeft = SkScalarToFixed(src.fLeft);
115 xr->fTop = SkScalarToFixed(src.fTop);
116 xr->fRight = SkScalarToFixed(src.fRight);
117 xr->fBottom = SkScalarToFixed(src.fBottom);
118}
119
120/** Round the SkXRect coordinates, and store the result in the SkIRect.
121*/
reed@android.comfc25abd2009-01-15 14:38:33 +0000122static inline void XRect_round(const SkXRect& xr, SkIRect* dst) {
mike@reedtribe.org9fb00412014-01-06 03:02:37 +0000123 dst->fLeft = SkFixedRoundToInt(xr.fLeft);
124 dst->fTop = SkFixedRoundToInt(xr.fTop);
125 dst->fRight = SkFixedRoundToInt(xr.fRight);
126 dst->fBottom = SkFixedRoundToInt(xr.fBottom);
reed@android.com8a1c16f2008-12-17 15:59:43 +0000127}
128
129/** Round the SkXRect coordinates out (i.e. use floor for left/top, and ceiling
130 for right/bottom), and store the result in the SkIRect.
131*/
reed@android.comfc25abd2009-01-15 14:38:33 +0000132static inline void XRect_roundOut(const SkXRect& xr, SkIRect* dst) {
mike@reedtribe.org9fb00412014-01-06 03:02:37 +0000133 dst->fLeft = SkFixedFloorToInt(xr.fLeft);
134 dst->fTop = SkFixedFloorToInt(xr.fTop);
135 dst->fRight = SkFixedCeilToInt(xr.fRight);
136 dst->fBottom = SkFixedCeilToInt(xr.fBottom);
reed@android.com8a1c16f2008-12-17 15:59:43 +0000137}
138
139#endif