reed@google.com | e36707a | 2011-10-04 21:38:55 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2011 Google Inc. |
| 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 | #ifndef SkAAClip_DEFINED |
| 9 | #define SkAAClip_DEFINED |
| 10 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 11 | #include "include/core/SkRegion.h" |
| 12 | #include "src/core/SkAutoMalloc.h" |
| 13 | #include "src/core/SkBlitter.h" |
reed@google.com | e36707a | 2011-10-04 21:38:55 +0000 | [diff] [blame] | 14 | |
reed@google.com | e36707a | 2011-10-04 21:38:55 +0000 | [diff] [blame] | 15 | class SkAAClip { |
| 16 | public: |
| 17 | SkAAClip(); |
| 18 | SkAAClip(const SkAAClip&); |
| 19 | ~SkAAClip(); |
| 20 | |
| 21 | SkAAClip& operator=(const SkAAClip&); |
| 22 | friend bool operator==(const SkAAClip&, const SkAAClip&); |
| 23 | friend bool operator!=(const SkAAClip& a, const SkAAClip& b) { |
| 24 | return !(a == b); |
| 25 | } |
| 26 | |
| 27 | void swap(SkAAClip&); |
| 28 | |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 29 | bool isEmpty() const { return nullptr == fRunHead; } |
reed@google.com | e36707a | 2011-10-04 21:38:55 +0000 | [diff] [blame] | 30 | const SkIRect& getBounds() const { return fBounds; } |
| 31 | |
reed | 202ab2a | 2014-08-07 11:48:10 -0700 | [diff] [blame] | 32 | // Returns true iff the clip is not empty, and is just a hard-edged rect (no partial alpha). |
| 33 | // If true, getBounds() can be used in place of this clip. |
| 34 | bool isRect() const; |
| 35 | |
reed@google.com | e36707a | 2011-10-04 21:38:55 +0000 | [diff] [blame] | 36 | bool setEmpty(); |
| 37 | bool setRect(const SkIRect&); |
reed@google.com | f3c1da1 | 2011-10-10 19:35:47 +0000 | [diff] [blame] | 38 | bool setRect(const SkRect&, bool doAA = true); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 39 | bool setPath(const SkPath&, const SkRegion* clip = nullptr, bool doAA = true); |
reed@google.com | f3c1da1 | 2011-10-10 19:35:47 +0000 | [diff] [blame] | 40 | bool setRegion(const SkRegion&); |
reed@google.com | 3228789 | 2011-10-05 16:27:44 +0000 | [diff] [blame] | 41 | bool set(const SkAAClip&); |
reed@google.com | e36707a | 2011-10-04 21:38:55 +0000 | [diff] [blame] | 42 | |
| 43 | bool op(const SkAAClip&, const SkAAClip&, SkRegion::Op); |
| 44 | |
reed@google.com | 47ac84e | 2011-10-06 13:11:25 +0000 | [diff] [blame] | 45 | // Helpers for op() |
| 46 | bool op(const SkIRect&, SkRegion::Op); |
reed@google.com | 0017708 | 2011-10-12 14:34:30 +0000 | [diff] [blame] | 47 | bool op(const SkRect&, SkRegion::Op, bool doAA); |
reed@google.com | 47ac84e | 2011-10-06 13:11:25 +0000 | [diff] [blame] | 48 | bool op(const SkAAClip&, SkRegion::Op); |
| 49 | |
reed@google.com | 34f7e47 | 2011-10-13 15:11:59 +0000 | [diff] [blame] | 50 | bool translate(int dx, int dy, SkAAClip* dst) const; |
| 51 | bool translate(int dx, int dy) { |
| 52 | return this->translate(dx, dy, this); |
| 53 | } |
reed@google.com | 1c04bf9 | 2011-10-10 12:57:12 +0000 | [diff] [blame] | 54 | |
reed@google.com | 3228789 | 2011-10-05 16:27:44 +0000 | [diff] [blame] | 55 | /** |
| 56 | * Allocates a mask the size of the aaclip, and expands its data into |
| 57 | * the mask, using kA8_Format |
| 58 | */ |
| 59 | void copyToMask(SkMask*) const; |
| 60 | |
reed@google.com | e36707a | 2011-10-04 21:38:55 +0000 | [diff] [blame] | 61 | // called internally |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 62 | |
reed@google.com | e36707a | 2011-10-04 21:38:55 +0000 | [diff] [blame] | 63 | bool quickContains(int left, int top, int right, int bottom) const; |
reed@google.com | 045e62d | 2011-10-24 12:19:46 +0000 | [diff] [blame] | 64 | bool quickContains(const SkIRect& r) const { |
| 65 | return this->quickContains(r.fLeft, r.fTop, r.fRight, r.fBottom); |
| 66 | } |
| 67 | |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 68 | const uint8_t* findRow(int y, int* lastYForRow = nullptr) const; |
| 69 | const uint8_t* findX(const uint8_t data[], int x, int* initialCount = nullptr) const; |
reed@google.com | e36707a | 2011-10-04 21:38:55 +0000 | [diff] [blame] | 70 | |
reed@google.com | 3228789 | 2011-10-05 16:27:44 +0000 | [diff] [blame] | 71 | class Iter; |
reed@google.com | e36707a | 2011-10-04 21:38:55 +0000 | [diff] [blame] | 72 | struct RunHead; |
| 73 | struct YOffset; |
reed@google.com | 3228789 | 2011-10-05 16:27:44 +0000 | [diff] [blame] | 74 | class Builder; |
reed@google.com | e36707a | 2011-10-04 21:38:55 +0000 | [diff] [blame] | 75 | |
reed@google.com | 045e62d | 2011-10-24 12:19:46 +0000 | [diff] [blame] | 76 | #ifdef SK_DEBUG |
| 77 | void validate() const; |
humper | 6d42d9c | 2014-08-08 11:45:46 -0700 | [diff] [blame] | 78 | void debug(bool compress_y=false) const; |
reed@google.com | 045e62d | 2011-10-24 12:19:46 +0000 | [diff] [blame] | 79 | #else |
| 80 | void validate() const {} |
humper | 6d42d9c | 2014-08-08 11:45:46 -0700 | [diff] [blame] | 81 | void debug(bool compress_y=false) const {} |
reed@google.com | 045e62d | 2011-10-24 12:19:46 +0000 | [diff] [blame] | 82 | #endif |
| 83 | |
reed@google.com | 3228789 | 2011-10-05 16:27:44 +0000 | [diff] [blame] | 84 | private: |
reed@google.com | e36707a | 2011-10-04 21:38:55 +0000 | [diff] [blame] | 85 | SkIRect fBounds; |
| 86 | RunHead* fRunHead; |
| 87 | |
| 88 | void freeRuns(); |
reed@google.com | 045e62d | 2011-10-24 12:19:46 +0000 | [diff] [blame] | 89 | bool trimBounds(); |
reed@google.com | c904191 | 2011-10-27 16:58:46 +0000 | [diff] [blame] | 90 | bool trimTopBottom(); |
| 91 | bool trimLeftRight(); |
reed@google.com | e36707a | 2011-10-04 21:38:55 +0000 | [diff] [blame] | 92 | |
reed@google.com | e36707a | 2011-10-04 21:38:55 +0000 | [diff] [blame] | 93 | friend class Builder; |
| 94 | class BuilderBlitter; |
| 95 | friend class BuilderBlitter; |
| 96 | }; |
| 97 | |
| 98 | /////////////////////////////////////////////////////////////////////////////// |
| 99 | |
| 100 | class SkAAClipBlitter : public SkBlitter { |
| 101 | public: |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 102 | SkAAClipBlitter() : fScanlineScratch(nullptr) {} |
Brian Salomon | d3b6597 | 2017-03-22 12:05:03 -0400 | [diff] [blame] | 103 | ~SkAAClipBlitter() override; |
reed@google.com | e36707a | 2011-10-04 21:38:55 +0000 | [diff] [blame] | 104 | |
| 105 | void init(SkBlitter* blitter, const SkAAClip* aaclip) { |
| 106 | SkASSERT(aaclip && !aaclip->isEmpty()); |
| 107 | fBlitter = blitter; |
| 108 | fAAClip = aaclip; |
| 109 | fAAClipBounds = aaclip->getBounds(); |
| 110 | } |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 111 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 112 | void blitH(int x, int y, int width) override; |
reed | 41e010c | 2015-06-09 12:16:53 -0700 | [diff] [blame] | 113 | void blitAntiH(int x, int y, const SkAlpha[], const int16_t runs[]) override; |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 114 | void blitV(int x, int y, int height, SkAlpha alpha) override; |
| 115 | void blitRect(int x, int y, int width, int height) override; |
| 116 | void blitMask(const SkMask&, const SkIRect& clip) override; |
reed | 41e010c | 2015-06-09 12:16:53 -0700 | [diff] [blame] | 117 | const SkPixmap* justAnOpaqueColor(uint32_t* value) override; |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 118 | |
reed@google.com | e36707a | 2011-10-04 21:38:55 +0000 | [diff] [blame] | 119 | private: |
| 120 | SkBlitter* fBlitter; |
| 121 | const SkAAClip* fAAClip; |
| 122 | SkIRect fAAClipBounds; |
| 123 | |
reed@google.com | 045e62d | 2011-10-24 12:19:46 +0000 | [diff] [blame] | 124 | // point into fScanlineScratch |
reed@google.com | e36707a | 2011-10-04 21:38:55 +0000 | [diff] [blame] | 125 | int16_t* fRuns; |
reed@google.com | 045e62d | 2011-10-24 12:19:46 +0000 | [diff] [blame] | 126 | SkAlpha* fAA; |
| 127 | |
| 128 | enum { |
| 129 | kSize = 32 * 32 |
| 130 | }; |
| 131 | SkAutoSMalloc<kSize> fGrayMaskScratch; // used for blitMask |
| 132 | void* fScanlineScratch; // enough for a mask at 32bit, or runs+aa |
reed@google.com | e36707a | 2011-10-04 21:38:55 +0000 | [diff] [blame] | 133 | |
| 134 | void ensureRunsAndAA(); |
| 135 | }; |
| 136 | |
| 137 | #endif |