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" |
| 14 | |
reed@google.com | 1ba7137 | 2011-10-12 20:42:05 +0000 | [diff] [blame] | 15 | class SkRasterClip; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 16 | class SkRegion; |
| 17 | class SkBlitter; |
| 18 | class 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 | */ |
| 23 | typedef SkIRect SkXRect; |
| 24 | |
liyuqian | 38911a7 | 2016-10-04 11:23:22 -0700 | [diff] [blame^] | 25 | class GlobalAAConfig { |
| 26 | private: |
| 27 | GlobalAAConfig() {} |
| 28 | |
| 29 | public: |
| 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 | |
| 41 | class AdditiveBlitter; |
| 42 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 43 | class SkScan { |
| 44 | public: |
reed | 5dc6b7d | 2015-04-14 10:40:44 -0700 | [diff] [blame] | 45 | /* |
| 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.com | 045e62d | 2011-10-24 12:19:46 +0000 | [diff] [blame] | 54 | 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.com | 045e62d | 2011-10-24 12:19:46 +0000 | [diff] [blame] | 61 | static void FillRect(const SkRect&, const SkRasterClip&, SkBlitter*); |
| 62 | static void AntiFillRect(const SkRect&, const SkRasterClip&, SkBlitter*); |
reed@google.com | 045e62d | 2011-10-24 12:19:46 +0000 | [diff] [blame] | 63 | 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*); |
liyuqian | 38911a7 | 2016-10-04 11:23:22 -0700 | [diff] [blame^] | 66 | static void AAAFillPath(const SkPath&, const SkRasterClip&, SkBlitter*); |
reed@google.com | 045e62d | 2011-10-24 12:19:46 +0000 | [diff] [blame] | 67 | 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*); |
reed | 5dc6b7d | 2015-04-14 10:40:44 -0700 | [diff] [blame] | 72 | static void HairLine(const SkPoint[], int count, const SkRasterClip&, SkBlitter*); |
| 73 | static void AntiHairLine(const SkPoint[], int count, const SkRasterClip&, SkBlitter*); |
reed@google.com | 045e62d | 2011-10-24 12:19:46 +0000 | [diff] [blame] | 74 | 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*); |
caryclark | 2028d7f | 2015-12-09 14:04:46 -0800 | [diff] [blame] | 78 | 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.com | 045e62d | 2011-10-24 12:19:46 +0000 | [diff] [blame] | 82 | |
| 83 | private: |
| 84 | friend class SkAAClip; |
| 85 | friend class SkRegion; |
| 86 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 87 | static void FillIRect(const SkIRect&, const SkRegion* clip, SkBlitter*); |
| 88 | static void FillXRect(const SkXRect&, const SkRegion* clip, SkBlitter*); |
reed@google.com | 045e62d | 2011-10-24 12:19:46 +0000 | [diff] [blame] | 89 | static void FillRect(const SkRect&, const SkRegion* clip, SkBlitter*); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 90 | static void AntiFillRect(const SkRect&, const SkRegion* clip, SkBlitter*); |
reed@google.com | 67ba5fa | 2011-10-24 12:56:20 +0000 | [diff] [blame] | 91 | static void AntiFillXRect(const SkXRect&, const SkRegion*, SkBlitter*); |
reed@google.com | 045e62d | 2011-10-24 12:19:46 +0000 | [diff] [blame] | 92 | static void FillPath(const SkPath&, const SkRegion& clip, SkBlitter*); |
reed@google.com | 2c508f2 | 2011-10-03 21:15:46 +0000 | [diff] [blame] | 93 | static void AntiFillPath(const SkPath&, const SkRegion& clip, SkBlitter*, |
| 94 | bool forceRLE = false); |
reed@google.com | 045e62d | 2011-10-24 12:19:46 +0000 | [diff] [blame] | 95 | static void FillTriangle(const SkPoint pts[], const SkRegion*, SkBlitter*); |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 96 | |
reed@google.com | 761fb62 | 2011-04-04 18:58:05 +0000 | [diff] [blame] | 97 | static void AntiFrameRect(const SkRect&, const SkPoint& strokeSize, |
| 98 | const SkRegion*, SkBlitter*); |
reed | 5dc6b7d | 2015-04-14 10:40:44 -0700 | [diff] [blame] | 99 | static void HairLineRgn(const SkPoint[], int count, const SkRegion*, SkBlitter*); |
| 100 | static void AntiHairLineRgn(const SkPoint[], int count, const SkRegion*, SkBlitter*); |
liyuqian | 38911a7 | 2016-10-04 11:23:22 -0700 | [diff] [blame^] | 101 | 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.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 104 | }; |
| 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.com | fc25abd | 2009-01-15 14:38:33 +0000 | [diff] [blame] | 110 | static inline void XRect_set(SkXRect* xr, const SkIRect& src) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 111 | 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 |
fmalita | e736506 | 2016-04-07 19:27:45 -0700 | [diff] [blame] | 118 | 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] | 119 | exceed 32K |
| 120 | */ |
reed@android.com | fc25abd | 2009-01-15 14:38:33 +0000 | [diff] [blame] | 121 | static inline void XRect_set(SkXRect* xr, const SkRect& src) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 122 | 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.com | fc25abd | 2009-01-15 14:38:33 +0000 | [diff] [blame] | 130 | static inline void XRect_round(const SkXRect& xr, SkIRect* dst) { |
mike@reedtribe.org | 9fb0041 | 2014-01-06 03:02:37 +0000 | [diff] [blame] | 131 | 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.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 135 | } |
| 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.com | fc25abd | 2009-01-15 14:38:33 +0000 | [diff] [blame] | 140 | static inline void XRect_roundOut(const SkXRect& xr, SkIRect* dst) { |
mike@reedtribe.org | 9fb0041 | 2014-01-06 03:02:37 +0000 | [diff] [blame] | 141 | 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.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 145 | } |
| 146 | |
| 147 | #endif |