| 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 "include/core/SkRect.h" |
| 13 | #include "include/private/SkFixed.h" |
| 14 | #include "src/core/SkPathView.h" |
| 15 | |
| 16 | #include <atomic> |
| 17 | |
| 18 | class SkRasterClip; |
| 19 | class SkRegion; |
| 20 | class SkBlitter; |
| 21 | |
| 22 | /** Defines a fixed-point rectangle, identical to the integer SkIRect, but its |
| 23 | coordinates are treated as SkFixed rather than int32_t. |
| 24 | */ |
| 25 | typedef SkIRect SkXRect; |
| 26 | |
| 27 | extern std::atomic<bool> gSkUseAnalyticAA; |
| 28 | extern std::atomic<bool> gSkForceAnalyticAA; |
| 29 | |
| 30 | class AdditiveBlitter; |
| 31 | |
| 32 | class SkScan { |
| 33 | public: |
| 34 | /* |
| 35 | * Draws count-1 line segments, one at a time: |
| 36 | * line(pts[0], pts[1]) |
| 37 | * line(pts[1], pts[2]) |
| 38 | * line(......, pts[count - 1]) |
| 39 | */ |
| 40 | typedef void (*HairRgnProc)(const SkPoint[], int count, const SkRegion*, SkBlitter*); |
| 41 | typedef void (*HairRCProc)(const SkPoint[], int count, const SkRasterClip&, SkBlitter*); |
| 42 | |
| 43 | static void FillPath(const SkPathView&, const SkIRect&, SkBlitter*); |
| 44 | |
| 45 | /////////////////////////////////////////////////////////////////////////// |
| 46 | // rasterclip |
| 47 | |
| 48 | static void FillIRect(const SkIRect&, const SkRasterClip&, SkBlitter*); |
| 49 | static void FillXRect(const SkXRect&, const SkRasterClip&, SkBlitter*); |
| 50 | static void FillRect(const SkRect&, const SkRasterClip&, SkBlitter*); |
| 51 | static void AntiFillRect(const SkRect&, const SkRasterClip&, SkBlitter*); |
| 52 | static void AntiFillXRect(const SkXRect&, const SkRasterClip&, SkBlitter*); |
| 53 | static void FillPath(const SkPathView&, const SkRasterClip&, SkBlitter*); |
| 54 | static void AntiFillPath(const SkPathView&, 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 SkPathView&, const SkRasterClip&, SkBlitter*); |
| 65 | static void AntiHairPath(const SkPathView&, const SkRasterClip&, SkBlitter*); |
| 66 | static void HairSquarePath(const SkPathView&, const SkRasterClip&, SkBlitter*); |
| 67 | static void AntiHairSquarePath(const SkPathView&, const SkRasterClip&, SkBlitter*); |
| 68 | static void HairRoundPath(const SkPathView&, const SkRasterClip&, SkBlitter*); |
| 69 | static void AntiHairRoundPath(const SkPathView&, const SkRasterClip&, SkBlitter*); |
| 70 | |
| 71 | // Needed by do_fill_path in SkScanPriv.h |
| 72 | static void FillPath(const SkPathView&, const SkRegion& clip, SkBlitter*); |
| 73 | |
| 74 | private: |
| 75 | friend class SkAAClip; |
| 76 | friend class SkRegion; |
| 77 | |
| 78 | static void FillIRect(const SkIRect&, const SkRegion* clip, SkBlitter*); |
| 79 | static void FillXRect(const SkXRect&, const SkRegion* clip, SkBlitter*); |
| 80 | static void FillRect(const SkRect&, const SkRegion* clip, SkBlitter*); |
| 81 | static void AntiFillRect(const SkRect&, const SkRegion* clip, SkBlitter*); |
| 82 | static void AntiFillXRect(const SkXRect&, const SkRegion*, SkBlitter*); |
| 83 | static void AntiFillPath(const SkPathView&, const SkRegion& clip, SkBlitter*, bool forceRLE); |
| 84 | static void FillTriangle(const SkPoint pts[], const SkRegion*, SkBlitter*); |
| 85 | |
| 86 | static void AntiFrameRect(const SkRect&, const SkPoint& strokeSize, |
| 87 | const SkRegion*, SkBlitter*); |
| 88 | static void HairLineRgn(const SkPoint[], int count, const SkRegion*, SkBlitter*); |
| 89 | static void AntiHairLineRgn(const SkPoint[], int count, const SkRegion*, SkBlitter*); |
| 90 | static void AAAFillPath(const SkPathView& path, SkBlitter* blitter, const SkIRect& pathIR, |
| 91 | const SkIRect& clipBounds, bool forceRLE); |
| 92 | static void SAAFillPath(const SkPathView& path, SkBlitter* blitter, const SkIRect& pathIR, |
| 93 | const SkIRect& clipBounds, bool forceRLE); |
| 94 | }; |
| 95 | |
| 96 | /** Assign an SkXRect from a SkIRect, by promoting the src rect's coordinates |
| 97 | from int to SkFixed. Does not check for overflow if the src coordinates |
| 98 | exceed 32K |
| 99 | */ |
| 100 | static inline void XRect_set(SkXRect* xr, const SkIRect& src) { |
| 101 | xr->fLeft = SkIntToFixed(src.fLeft); |
| 102 | xr->fTop = SkIntToFixed(src.fTop); |
| 103 | xr->fRight = SkIntToFixed(src.fRight); |
| 104 | xr->fBottom = SkIntToFixed(src.fBottom); |
| 105 | } |
| 106 | |
| 107 | /** Assign an SkXRect from a SkRect, by promoting the src rect's coordinates |
| 108 | from SkScalar to SkFixed. Does not check for overflow if the src coordinates |
| 109 | exceed 32K |
| 110 | */ |
| 111 | static inline void XRect_set(SkXRect* xr, const SkRect& src) { |
| 112 | xr->fLeft = SkScalarToFixed(src.fLeft); |
| 113 | xr->fTop = SkScalarToFixed(src.fTop); |
| 114 | xr->fRight = SkScalarToFixed(src.fRight); |
| 115 | xr->fBottom = SkScalarToFixed(src.fBottom); |
| 116 | } |
| 117 | |
| 118 | /** Round the SkXRect coordinates, and store the result in the SkIRect. |
| 119 | */ |
| 120 | static inline void XRect_round(const SkXRect& xr, SkIRect* dst) { |
| 121 | dst->fLeft = SkFixedRoundToInt(xr.fLeft); |
| 122 | dst->fTop = SkFixedRoundToInt(xr.fTop); |
| 123 | dst->fRight = SkFixedRoundToInt(xr.fRight); |
| 124 | dst->fBottom = SkFixedRoundToInt(xr.fBottom); |
| 125 | } |
| 126 | |
| 127 | /** Round the SkXRect coordinates out (i.e. use floor for left/top, and ceiling |
| 128 | for right/bottom), and store the result in the SkIRect. |
| 129 | */ |
| 130 | static inline void XRect_roundOut(const SkXRect& xr, SkIRect* dst) { |
| 131 | dst->fLeft = SkFixedFloorToInt(xr.fLeft); |
| 132 | dst->fTop = SkFixedFloorToInt(xr.fTop); |
| 133 | dst->fRight = SkFixedCeilToInt(xr.fRight); |
| 134 | dst->fBottom = SkFixedCeilToInt(xr.fBottom); |
| 135 | } |
| 136 | |
| 137 | #endif |
| 138 | |