blob: 1e3d60a290406b2288216f416328494a468bf359 [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"
14
reed@google.com1ba71372011-10-12 20:42:05 +000015class SkRasterClip;
reed@android.com8a1c16f2008-12-17 15:59:43 +000016class SkRegion;
17class SkBlitter;
18class SkPath;
19
20/** Defines a fixed-point rectangle, identical to the integer SkIRect, but its
21 coordinates are treated as SkFixed rather than int32_t.
22*/
23typedef SkIRect SkXRect;
24
liyuqian38911a72016-10-04 11:23:22 -070025class GlobalAAConfig {
26private:
27 GlobalAAConfig() {}
28
29public:
30 bool fUseAnalyticAA = false;
31
32 GlobalAAConfig(const GlobalAAConfig&) = delete;
33 void operator=(const GlobalAAConfig&) = delete;
34
35 static GlobalAAConfig& getInstance() {
36 static GlobalAAConfig instance;
37 return instance;
38 }
39};
40
41class AdditiveBlitter;
42
reed@android.com8a1c16f2008-12-17 15:59:43 +000043class SkScan {
44public:
reed5dc6b7d2015-04-14 10:40:44 -070045 /*
46 * Draws count-1 line segments, one at a time:
47 * line(pts[0], pts[1])
48 * line(pts[1], pts[2])
49 * line(......, pts[count - 1])
50 */
51 typedef void (*HairRgnProc)(const SkPoint[], int count, const SkRegion*, SkBlitter*);
52 typedef void (*HairRCProc)(const SkPoint[], int count, const SkRasterClip&, SkBlitter*);
53
reed@google.com045e62d2011-10-24 12:19:46 +000054 static void FillPath(const SkPath&, const SkIRect&, SkBlitter*);
55
56 ///////////////////////////////////////////////////////////////////////////
57 // rasterclip
58
59 static void FillIRect(const SkIRect&, const SkRasterClip&, SkBlitter*);
60 static void FillXRect(const SkXRect&, const SkRasterClip&, SkBlitter*);
reed@google.com045e62d2011-10-24 12:19:46 +000061 static void FillRect(const SkRect&, const SkRasterClip&, SkBlitter*);
62 static void AntiFillRect(const SkRect&, const SkRasterClip&, SkBlitter*);
reed@google.com045e62d2011-10-24 12:19:46 +000063 static void AntiFillXRect(const SkXRect&, const SkRasterClip&, SkBlitter*);
64 static void FillPath(const SkPath&, const SkRasterClip&, SkBlitter*);
65 static void AntiFillPath(const SkPath&, const SkRasterClip&, SkBlitter*);
liyuqian38911a72016-10-04 11:23:22 -070066 static void AAAFillPath(const SkPath&, const SkRasterClip&, SkBlitter*);
reed@google.com045e62d2011-10-24 12:19:46 +000067 static void FrameRect(const SkRect&, const SkPoint& strokeSize,
68 const SkRasterClip&, SkBlitter*);
69 static void AntiFrameRect(const SkRect&, const SkPoint& strokeSize,
70 const SkRasterClip&, SkBlitter*);
71 static void FillTriangle(const SkPoint pts[], const SkRasterClip&, SkBlitter*);
reed5dc6b7d2015-04-14 10:40:44 -070072 static void HairLine(const SkPoint[], int count, const SkRasterClip&, SkBlitter*);
73 static void AntiHairLine(const SkPoint[], int count, const SkRasterClip&, SkBlitter*);
reed@google.com045e62d2011-10-24 12:19:46 +000074 static void HairRect(const SkRect&, const SkRasterClip&, SkBlitter*);
75 static void AntiHairRect(const SkRect&, const SkRasterClip&, SkBlitter*);
76 static void HairPath(const SkPath&, const SkRasterClip&, SkBlitter*);
77 static void AntiHairPath(const SkPath&, const SkRasterClip&, SkBlitter*);
caryclark2028d7f2015-12-09 14:04:46 -080078 static void HairSquarePath(const SkPath&, const SkRasterClip&, SkBlitter*);
79 static void AntiHairSquarePath(const SkPath&, const SkRasterClip&, SkBlitter*);
80 static void HairRoundPath(const SkPath&, const SkRasterClip&, SkBlitter*);
81 static void AntiHairRoundPath(const SkPath&, const SkRasterClip&, SkBlitter*);
reed@google.com045e62d2011-10-24 12:19:46 +000082
83private:
84 friend class SkAAClip;
85 friend class SkRegion;
86
reed@android.com8a1c16f2008-12-17 15:59:43 +000087 static void FillIRect(const SkIRect&, const SkRegion* clip, SkBlitter*);
88 static void FillXRect(const SkXRect&, const SkRegion* clip, SkBlitter*);
reed@google.com045e62d2011-10-24 12:19:46 +000089 static void FillRect(const SkRect&, const SkRegion* clip, SkBlitter*);
reed@android.com8a1c16f2008-12-17 15:59:43 +000090 static void AntiFillRect(const SkRect&, const SkRegion* clip, SkBlitter*);
reed@google.com67ba5fa2011-10-24 12:56:20 +000091 static void AntiFillXRect(const SkXRect&, const SkRegion*, SkBlitter*);
reed@google.com045e62d2011-10-24 12:19:46 +000092 static void FillPath(const SkPath&, const SkRegion& clip, SkBlitter*);
reed@google.com2c508f22011-10-03 21:15:46 +000093 static void AntiFillPath(const SkPath&, const SkRegion& clip, SkBlitter*,
94 bool forceRLE = false);
reed@google.com045e62d2011-10-24 12:19:46 +000095 static void FillTriangle(const SkPoint pts[], const SkRegion*, SkBlitter*);
rmistry@google.comfbfcd562012-08-23 18:09:54 +000096
reed@google.com761fb622011-04-04 18:58:05 +000097 static void AntiFrameRect(const SkRect&, const SkPoint& strokeSize,
98 const SkRegion*, SkBlitter*);
reed5dc6b7d2015-04-14 10:40:44 -070099 static void HairLineRgn(const SkPoint[], int count, const SkRegion*, SkBlitter*);
100 static void AntiHairLineRgn(const SkPoint[], int count, const SkRegion*, SkBlitter*);
liyuqian38911a72016-10-04 11:23:22 -0700101 static void AAAFillPath(const SkPath& path, const SkRegion& origClip, SkBlitter* blitter);
102 static void aaa_fill_path(const SkPath& path, const SkIRect* clipRect, AdditiveBlitter*,
103 int start_y, int stop_y, const SkRegion& clipRgn, bool isUsingMask);
reed@android.com8a1c16f2008-12-17 15:59:43 +0000104};
105
106/** Assign an SkXRect from a SkIRect, by promoting the src rect's coordinates
107 from int to SkFixed. Does not check for overflow if the src coordinates
108 exceed 32K
109*/
reed@android.comfc25abd2009-01-15 14:38:33 +0000110static inline void XRect_set(SkXRect* xr, const SkIRect& src) {
reed@android.com8a1c16f2008-12-17 15:59:43 +0000111 xr->fLeft = SkIntToFixed(src.fLeft);
112 xr->fTop = SkIntToFixed(src.fTop);
113 xr->fRight = SkIntToFixed(src.fRight);
114 xr->fBottom = SkIntToFixed(src.fBottom);
115}
116
117/** Assign an SkXRect from a SkRect, by promoting the src rect's coordinates
fmalitae7365062016-04-07 19:27:45 -0700118 from SkScalar to SkFixed. Does not check for overflow if the src coordinates
reed@android.com8a1c16f2008-12-17 15:59:43 +0000119 exceed 32K
120*/
reed@android.comfc25abd2009-01-15 14:38:33 +0000121static inline void XRect_set(SkXRect* xr, const SkRect& src) {
reed@android.com8a1c16f2008-12-17 15:59:43 +0000122 xr->fLeft = SkScalarToFixed(src.fLeft);
123 xr->fTop = SkScalarToFixed(src.fTop);
124 xr->fRight = SkScalarToFixed(src.fRight);
125 xr->fBottom = SkScalarToFixed(src.fBottom);
126}
127
128/** Round the SkXRect coordinates, and store the result in the SkIRect.
129*/
reed@android.comfc25abd2009-01-15 14:38:33 +0000130static inline void XRect_round(const SkXRect& xr, SkIRect* dst) {
mike@reedtribe.org9fb00412014-01-06 03:02:37 +0000131 dst->fLeft = SkFixedRoundToInt(xr.fLeft);
132 dst->fTop = SkFixedRoundToInt(xr.fTop);
133 dst->fRight = SkFixedRoundToInt(xr.fRight);
134 dst->fBottom = SkFixedRoundToInt(xr.fBottom);
reed@android.com8a1c16f2008-12-17 15:59:43 +0000135}
136
137/** Round the SkXRect coordinates out (i.e. use floor for left/top, and ceiling
138 for right/bottom), and store the result in the SkIRect.
139*/
reed@android.comfc25abd2009-01-15 14:38:33 +0000140static inline void XRect_roundOut(const SkXRect& xr, SkIRect* dst) {
mike@reedtribe.org9fb00412014-01-06 03:02:37 +0000141 dst->fLeft = SkFixedFloorToInt(xr.fLeft);
142 dst->fTop = SkFixedFloorToInt(xr.fTop);
143 dst->fRight = SkFixedCeilToInt(xr.fRight);
144 dst->fBottom = SkFixedCeilToInt(xr.fBottom);
reed@android.com8a1c16f2008-12-17 15:59:43 +0000145}
146
147#endif