epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 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 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 8 | |
| 9 | #ifndef SkScan_DEFINED |
| 10 | #define SkScan_DEFINED |
| 11 | |
benjaminwagner | 6c71e0a | 2016-04-07 08:49:31 -0700 | [diff] [blame] | 12 | #include "SkFixed.h" |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 13 | #include "SkRect.h" |
Mike Klein | 511f2d7 | 2016-10-04 15:45:56 -0400 | [diff] [blame] | 14 | #include <atomic> |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 15 | |
reed@google.com | 1ba7137 | 2011-10-12 20:42:05 +0000 | [diff] [blame] | 16 | class SkRasterClip; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 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 | |
Yuqian Li | df60e36 | 2017-07-25 11:26:31 -0400 | [diff] [blame] | 26 | extern std::atomic<bool> gSkUseDeltaAA; |
| 27 | extern std::atomic<bool> gSkForceDeltaAA; |
Mike Klein | 511f2d7 | 2016-10-04 15:45:56 -0400 | [diff] [blame] | 28 | extern std::atomic<bool> gSkUseAnalyticAA; |
Yuqian Li | 550148b | 2017-01-13 10:13:13 -0500 | [diff] [blame] | 29 | extern std::atomic<bool> gSkForceAnalyticAA; |
liyuqian | 38911a7 | 2016-10-04 11:23:22 -0700 | [diff] [blame] | 30 | |
| 31 | class AdditiveBlitter; |
| 32 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 33 | class SkScan { |
| 34 | public: |
reed | 5dc6b7d | 2015-04-14 10:40:44 -0700 | [diff] [blame] | 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 | |
reed@google.com | 045e62d | 2011-10-24 12:19:46 +0000 | [diff] [blame] | 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*); |
reed@google.com | 045e62d | 2011-10-24 12:19:46 +0000 | [diff] [blame] | 51 | static void FillRect(const SkRect&, const SkRasterClip&, SkBlitter*); |
| 52 | static void AntiFillRect(const SkRect&, const SkRasterClip&, SkBlitter*); |
reed@google.com | 045e62d | 2011-10-24 12:19:46 +0000 | [diff] [blame] | 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*); |
| 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*); |
reed | 5dc6b7d | 2015-04-14 10:40:44 -0700 | [diff] [blame] | 61 | static void HairLine(const SkPoint[], int count, const SkRasterClip&, SkBlitter*); |
| 62 | static void AntiHairLine(const SkPoint[], int count, const SkRasterClip&, SkBlitter*); |
reed@google.com | 045e62d | 2011-10-24 12:19:46 +0000 | [diff] [blame] | 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*); |
caryclark | 2028d7f | 2015-12-09 14:04:46 -0800 | [diff] [blame] | 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*); |
reed@google.com | 045e62d | 2011-10-24 12:19:46 +0000 | [diff] [blame] | 71 | |
Yuqian Li | ca50b87 | 2017-06-12 10:40:50 -0400 | [diff] [blame] | 72 | // Needed by do_fill_path in SkScanPriv.h |
| 73 | static void FillPath(const SkPath&, const SkRegion& clip, SkBlitter*); |
| 74 | |
reed@google.com | 045e62d | 2011-10-24 12:19:46 +0000 | [diff] [blame] | 75 | private: |
| 76 | friend class SkAAClip; |
| 77 | friend class SkRegion; |
| 78 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 79 | static void FillIRect(const SkIRect&, const SkRegion* clip, SkBlitter*); |
| 80 | static void FillXRect(const SkXRect&, const SkRegion* clip, SkBlitter*); |
reed@google.com | 045e62d | 2011-10-24 12:19:46 +0000 | [diff] [blame] | 81 | static void FillRect(const SkRect&, const SkRegion* clip, SkBlitter*); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 82 | static void AntiFillRect(const SkRect&, const SkRegion* clip, SkBlitter*); |
reed@google.com | 67ba5fa | 2011-10-24 12:56:20 +0000 | [diff] [blame] | 83 | static void AntiFillXRect(const SkXRect&, const SkRegion*, SkBlitter*); |
reed@google.com | 2c508f2 | 2011-10-03 21:15:46 +0000 | [diff] [blame] | 84 | static void AntiFillPath(const SkPath&, const SkRegion& clip, SkBlitter*, |
| 85 | bool forceRLE = false); |
reed@google.com | 045e62d | 2011-10-24 12:19:46 +0000 | [diff] [blame] | 86 | static void FillTriangle(const SkPoint pts[], const SkRegion*, SkBlitter*); |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 87 | |
reed@google.com | 761fb62 | 2011-04-04 18:58:05 +0000 | [diff] [blame] | 88 | static void AntiFrameRect(const SkRect&, const SkPoint& strokeSize, |
| 89 | const SkRegion*, SkBlitter*); |
reed | 5dc6b7d | 2015-04-14 10:40:44 -0700 | [diff] [blame] | 90 | static void HairLineRgn(const SkPoint[], int count, const SkRegion*, SkBlitter*); |
| 91 | static void AntiHairLineRgn(const SkPoint[], int count, const SkRegion*, SkBlitter*); |
liyuqian | 2add0ff | 2016-10-20 11:04:39 -0700 | [diff] [blame] | 92 | static void AAAFillPath(const SkPath& path, const SkRegion& origClip, SkBlitter* blitter, |
| 93 | bool forceRLE = false); // SkAAClip uses forceRLE |
Yuqian Li | df60e36 | 2017-07-25 11:26:31 -0400 | [diff] [blame] | 94 | static void DAAFillPath(const SkPath& path, const SkRegion& origClip, SkBlitter* blitter, |
| 95 | bool forceRLE = false); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 96 | }; |
| 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.com | fc25abd | 2009-01-15 14:38:33 +0000 | [diff] [blame] | 102 | static inline void XRect_set(SkXRect* xr, const SkIRect& src) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 103 | 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 |
fmalita | e736506 | 2016-04-07 19:27:45 -0700 | [diff] [blame] | 110 | from SkScalar to SkFixed. Does not check for overflow if the src coordinates |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 111 | exceed 32K |
| 112 | */ |
reed@android.com | fc25abd | 2009-01-15 14:38:33 +0000 | [diff] [blame] | 113 | static inline void XRect_set(SkXRect* xr, const SkRect& src) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 114 | 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.com | fc25abd | 2009-01-15 14:38:33 +0000 | [diff] [blame] | 122 | static inline void XRect_round(const SkXRect& xr, SkIRect* dst) { |
mike@reedtribe.org | 9fb0041 | 2014-01-06 03:02:37 +0000 | [diff] [blame] | 123 | 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.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 127 | } |
| 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.com | fc25abd | 2009-01-15 14:38:33 +0000 | [diff] [blame] | 132 | static inline void XRect_roundOut(const SkXRect& xr, SkIRect* dst) { |
mike@reedtribe.org | 9fb0041 | 2014-01-06 03:02:37 +0000 | [diff] [blame] | 133 | 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.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 137 | } |
| 138 | |
| 139 | #endif |