reed@google.com | d1e3c5f | 2011-10-10 19:36:25 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2010 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 | #include "SkRasterClip.h" |
reed | d954498 | 2014-09-09 18:46:22 -0700 | [diff] [blame] | 9 | #include "SkPath.h" |
reed@google.com | d1e3c5f | 2011-10-10 19:36:25 +0000 | [diff] [blame] | 10 | |
reed@google.com | 34f7e47 | 2011-10-13 15:11:59 +0000 | [diff] [blame] | 11 | SkRasterClip::SkRasterClip(const SkRasterClip& src) { |
reed@google.com | 045e62d | 2011-10-24 12:19:46 +0000 | [diff] [blame] | 12 | AUTO_RASTERCLIP_VALIDATE(src); |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 13 | |
reed | d954498 | 2014-09-09 18:46:22 -0700 | [diff] [blame] | 14 | fForceConservativeRects = src.fForceConservativeRects; |
reed@google.com | 34f7e47 | 2011-10-13 15:11:59 +0000 | [diff] [blame] | 15 | fIsBW = src.fIsBW; |
| 16 | if (fIsBW) { |
| 17 | fBW = src.fBW; |
| 18 | } else { |
| 19 | fAA = src.fAA; |
| 20 | } |
reed@google.com | a1c6ff4 | 2012-05-11 14:36:57 +0000 | [diff] [blame] | 21 | |
| 22 | fIsEmpty = src.isEmpty(); |
| 23 | fIsRect = src.isRect(); |
| 24 | SkDEBUGCODE(this->validate();) |
reed@google.com | 34f7e47 | 2011-10-13 15:11:59 +0000 | [diff] [blame] | 25 | } |
| 26 | |
reed | d954498 | 2014-09-09 18:46:22 -0700 | [diff] [blame] | 27 | SkRasterClip::SkRasterClip(const SkIRect& bounds, bool forceConservativeRects) : fBW(bounds) { |
| 28 | fForceConservativeRects = forceConservativeRects; |
reed@google.com | ba16da9 | 2011-10-11 13:15:03 +0000 | [diff] [blame] | 29 | fIsBW = true; |
reed@google.com | a1c6ff4 | 2012-05-11 14:36:57 +0000 | [diff] [blame] | 30 | fIsEmpty = this->computeIsEmpty(); // bounds might be empty, so compute |
| 31 | fIsRect = !fIsEmpty; |
| 32 | SkDEBUGCODE(this->validate();) |
reed@google.com | ba16da9 | 2011-10-11 13:15:03 +0000 | [diff] [blame] | 33 | } |
| 34 | |
reed | d954498 | 2014-09-09 18:46:22 -0700 | [diff] [blame] | 35 | SkRasterClip::SkRasterClip(bool forceConservativeRects) { |
| 36 | fForceConservativeRects = forceConservativeRects; |
| 37 | fIsBW = true; |
| 38 | fIsEmpty = true; |
| 39 | fIsRect = false; |
| 40 | SkDEBUGCODE(this->validate();) |
| 41 | } |
| 42 | |
reed@google.com | 045e62d | 2011-10-24 12:19:46 +0000 | [diff] [blame] | 43 | SkRasterClip::~SkRasterClip() { |
reed@google.com | a1c6ff4 | 2012-05-11 14:36:57 +0000 | [diff] [blame] | 44 | SkDEBUGCODE(this->validate();) |
reed@google.com | d1e3c5f | 2011-10-10 19:36:25 +0000 | [diff] [blame] | 45 | } |
| 46 | |
| 47 | bool SkRasterClip::isComplex() const { |
| 48 | return fIsBW ? fBW.isComplex() : !fAA.isEmpty(); |
| 49 | } |
| 50 | |
| 51 | const SkIRect& SkRasterClip::getBounds() const { |
| 52 | return fIsBW ? fBW.getBounds() : fAA.getBounds(); |
| 53 | } |
| 54 | |
| 55 | bool SkRasterClip::setEmpty() { |
reed@google.com | 045e62d | 2011-10-24 12:19:46 +0000 | [diff] [blame] | 56 | AUTO_RASTERCLIP_VALIDATE(*this); |
| 57 | |
reed@google.com | d1e3c5f | 2011-10-10 19:36:25 +0000 | [diff] [blame] | 58 | fIsBW = true; |
| 59 | fBW.setEmpty(); |
| 60 | fAA.setEmpty(); |
reed@google.com | a1c6ff4 | 2012-05-11 14:36:57 +0000 | [diff] [blame] | 61 | fIsEmpty = true; |
| 62 | fIsRect = false; |
reed@google.com | d1e3c5f | 2011-10-10 19:36:25 +0000 | [diff] [blame] | 63 | return false; |
| 64 | } |
| 65 | |
reed@google.com | ba16da9 | 2011-10-11 13:15:03 +0000 | [diff] [blame] | 66 | bool SkRasterClip::setRect(const SkIRect& rect) { |
reed@google.com | 045e62d | 2011-10-24 12:19:46 +0000 | [diff] [blame] | 67 | AUTO_RASTERCLIP_VALIDATE(*this); |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 68 | |
reed@google.com | d1e3c5f | 2011-10-10 19:36:25 +0000 | [diff] [blame] | 69 | fIsBW = true; |
| 70 | fAA.setEmpty(); |
reed@google.com | a1c6ff4 | 2012-05-11 14:36:57 +0000 | [diff] [blame] | 71 | fIsRect = fBW.setRect(rect); |
| 72 | fIsEmpty = !fIsRect; |
| 73 | return fIsRect; |
reed@google.com | d1e3c5f | 2011-10-10 19:36:25 +0000 | [diff] [blame] | 74 | } |
| 75 | |
reed | d954498 | 2014-09-09 18:46:22 -0700 | [diff] [blame] | 76 | ///////////////////////////////////////////////////////////////////////////////////// |
| 77 | |
| 78 | bool SkRasterClip::setConservativeRect(const SkRect& r, const SkIRect& clipR, bool isInverse) { |
reed | d954498 | 2014-09-09 18:46:22 -0700 | [diff] [blame] | 79 | SkRegion::Op op; |
| 80 | if (isInverse) { |
| 81 | op = SkRegion::kDifference_Op; |
| 82 | } else { |
| 83 | op = SkRegion::kIntersect_Op; |
| 84 | } |
| 85 | fBW.setRect(clipR); |
reed | b07a94f | 2014-11-19 05:03:18 -0800 | [diff] [blame] | 86 | fBW.op(r.roundOut(), op); |
reed | d954498 | 2014-09-09 18:46:22 -0700 | [diff] [blame] | 87 | return this->updateCacheAndReturnNonEmpty(); |
| 88 | } |
| 89 | |
| 90 | ///////////////////////////////////////////////////////////////////////////////////// |
| 91 | |
| 92 | enum MutateResult { |
| 93 | kDoNothing_MutateResult, |
| 94 | kReplaceClippedAgainstGlobalBounds_MutateResult, |
| 95 | kContinue_MutateResult, |
| 96 | }; |
| 97 | |
| 98 | static MutateResult mutate_conservative_op(SkRegion::Op* op, bool inverseFilled) { |
| 99 | if (inverseFilled) { |
| 100 | switch (*op) { |
| 101 | case SkRegion::kIntersect_Op: |
| 102 | case SkRegion::kDifference_Op: |
| 103 | // These ops can only shrink the current clip. So leaving |
| 104 | // the clip unchanged conservatively respects the contract. |
| 105 | return kDoNothing_MutateResult; |
| 106 | case SkRegion::kUnion_Op: |
| 107 | case SkRegion::kReplace_Op: |
| 108 | case SkRegion::kReverseDifference_Op: |
| 109 | case SkRegion::kXOR_Op: { |
| 110 | // These ops can grow the current clip up to the extents of |
| 111 | // the input clip, which is inverse filled, so we just set |
| 112 | // the current clip to the device bounds. |
| 113 | *op = SkRegion::kReplace_Op; |
| 114 | return kReplaceClippedAgainstGlobalBounds_MutateResult; |
| 115 | } |
| 116 | } |
| 117 | } else { |
| 118 | // Not inverse filled |
| 119 | switch (*op) { |
| 120 | case SkRegion::kIntersect_Op: |
| 121 | case SkRegion::kUnion_Op: |
| 122 | case SkRegion::kReplace_Op: |
| 123 | return kContinue_MutateResult; |
| 124 | case SkRegion::kDifference_Op: |
| 125 | // Difference can only shrink the current clip. |
| 126 | // Leaving clip unchanged conservatively fullfills the contract. |
| 127 | return kDoNothing_MutateResult; |
| 128 | case SkRegion::kReverseDifference_Op: |
| 129 | // To reverse, we swap in the bounds with a replace op. |
| 130 | // As with difference, leave it unchanged. |
| 131 | *op = SkRegion::kReplace_Op; |
| 132 | return kContinue_MutateResult; |
| 133 | case SkRegion::kXOR_Op: |
| 134 | // Be conservative, based on (A XOR B) always included in (A union B), |
| 135 | // which is always included in (bounds(A) union bounds(B)) |
| 136 | *op = SkRegion::kUnion_Op; |
| 137 | return kContinue_MutateResult; |
| 138 | } |
| 139 | } |
| 140 | SkFAIL("should not get here"); |
| 141 | return kDoNothing_MutateResult; |
| 142 | } |
| 143 | |
reed@google.com | d1e3c5f | 2011-10-10 19:36:25 +0000 | [diff] [blame] | 144 | bool SkRasterClip::setPath(const SkPath& path, const SkRegion& clip, bool doAA) { |
reed@google.com | 045e62d | 2011-10-24 12:19:46 +0000 | [diff] [blame] | 145 | AUTO_RASTERCLIP_VALIDATE(*this); |
| 146 | |
reed | d954498 | 2014-09-09 18:46:22 -0700 | [diff] [blame] | 147 | if (fForceConservativeRects) { |
| 148 | return this->setConservativeRect(path.getBounds(), clip.getBounds(), path.isInverseFillType()); |
| 149 | } |
| 150 | |
reed@google.com | d1e3c5f | 2011-10-10 19:36:25 +0000 | [diff] [blame] | 151 | if (this->isBW() && !doAA) { |
reed@google.com | a1c6ff4 | 2012-05-11 14:36:57 +0000 | [diff] [blame] | 152 | (void)fBW.setPath(path, clip); |
reed@google.com | d1e3c5f | 2011-10-10 19:36:25 +0000 | [diff] [blame] | 153 | } else { |
reed@google.com | 897fc41 | 2012-02-16 17:11:25 +0000 | [diff] [blame] | 154 | // TODO: since we are going to over-write fAA completely (aren't we?) |
| 155 | // we should just clear our BW data (if any) and set fIsAA=true |
reed@google.com | d1e3c5f | 2011-10-10 19:36:25 +0000 | [diff] [blame] | 156 | if (this->isBW()) { |
| 157 | this->convertToAA(); |
| 158 | } |
reed@google.com | a1c6ff4 | 2012-05-11 14:36:57 +0000 | [diff] [blame] | 159 | (void)fAA.setPath(path, &clip, doAA); |
reed@google.com | d1e3c5f | 2011-10-10 19:36:25 +0000 | [diff] [blame] | 160 | } |
reed@google.com | a1c6ff4 | 2012-05-11 14:36:57 +0000 | [diff] [blame] | 161 | return this->updateCacheAndReturnNonEmpty(); |
reed@google.com | d1e3c5f | 2011-10-10 19:36:25 +0000 | [diff] [blame] | 162 | } |
| 163 | |
senorblanco | afc7cce | 2016-02-02 18:44:15 -0800 | [diff] [blame] | 164 | bool SkRasterClip::op(const SkRRect& rrect, const SkIRect& bounds, SkRegion::Op op, bool doAA) { |
robertphillips | 125f19a | 2015-11-23 09:00:05 -0800 | [diff] [blame] | 165 | if (fForceConservativeRects) { |
senorblanco | afc7cce | 2016-02-02 18:44:15 -0800 | [diff] [blame] | 166 | return this->op(rrect.getBounds(), bounds, op, doAA); |
robertphillips | 125f19a | 2015-11-23 09:00:05 -0800 | [diff] [blame] | 167 | } |
| 168 | |
| 169 | SkPath path; |
| 170 | path.addRRect(rrect); |
| 171 | |
senorblanco | afc7cce | 2016-02-02 18:44:15 -0800 | [diff] [blame] | 172 | return this->op(path, bounds, op, doAA); |
robertphillips | 125f19a | 2015-11-23 09:00:05 -0800 | [diff] [blame] | 173 | } |
| 174 | |
senorblanco | afc7cce | 2016-02-02 18:44:15 -0800 | [diff] [blame] | 175 | bool SkRasterClip::op(const SkPath& path, const SkIRect& bounds, SkRegion::Op op, bool doAA) { |
robertphillips | 125f19a | 2015-11-23 09:00:05 -0800 | [diff] [blame] | 176 | AUTO_RASTERCLIP_VALIDATE(*this); |
reed | d954498 | 2014-09-09 18:46:22 -0700 | [diff] [blame] | 177 | |
| 178 | if (fForceConservativeRects) { |
| 179 | SkIRect ir; |
| 180 | switch (mutate_conservative_op(&op, path.isInverseFillType())) { |
| 181 | case kDoNothing_MutateResult: |
| 182 | return !this->isEmpty(); |
| 183 | case kReplaceClippedAgainstGlobalBounds_MutateResult: |
senorblanco | afc7cce | 2016-02-02 18:44:15 -0800 | [diff] [blame] | 184 | ir = bounds; |
reed | d954498 | 2014-09-09 18:46:22 -0700 | [diff] [blame] | 185 | break; |
| 186 | case kContinue_MutateResult: |
reed | b07a94f | 2014-11-19 05:03:18 -0800 | [diff] [blame] | 187 | ir = path.getBounds().roundOut(); |
reed | d954498 | 2014-09-09 18:46:22 -0700 | [diff] [blame] | 188 | break; |
| 189 | } |
| 190 | return this->op(ir, op); |
| 191 | } |
| 192 | |
robertphillips | 125f19a | 2015-11-23 09:00:05 -0800 | [diff] [blame] | 193 | // base is used to limit the size (and therefore memory allocation) of the |
| 194 | // region that results from scan converting devPath. |
| 195 | SkRegion base; |
| 196 | |
reed | d64c948 | 2014-09-05 17:37:38 -0700 | [diff] [blame] | 197 | if (SkRegion::kIntersect_Op == op) { |
| 198 | // since we are intersect, we can do better (tighter) with currRgn's |
| 199 | // bounds, than just using the device. However, if currRgn is complex, |
| 200 | // our region blitter may hork, so we do that case in two steps. |
| 201 | if (this->isRect()) { |
| 202 | // FIXME: we should also be able to do this when this->isBW(), |
| 203 | // but relaxing the test above triggers GM asserts in |
| 204 | // SkRgnBuilder::blitH(). We need to investigate what's going on. |
| 205 | return this->setPath(path, this->bwRgn(), doAA); |
| 206 | } else { |
| 207 | base.setRect(this->getBounds()); |
reed | d954498 | 2014-09-09 18:46:22 -0700 | [diff] [blame] | 208 | SkRasterClip clip(fForceConservativeRects); |
reed | d64c948 | 2014-09-05 17:37:38 -0700 | [diff] [blame] | 209 | clip.setPath(path, base, doAA); |
| 210 | return this->op(clip, op); |
| 211 | } |
| 212 | } else { |
senorblanco | afc7cce | 2016-02-02 18:44:15 -0800 | [diff] [blame] | 213 | base.setRect(bounds); |
reed | d64c948 | 2014-09-05 17:37:38 -0700 | [diff] [blame] | 214 | |
| 215 | if (SkRegion::kReplace_Op == op) { |
| 216 | return this->setPath(path, base, doAA); |
| 217 | } else { |
reed | d954498 | 2014-09-09 18:46:22 -0700 | [diff] [blame] | 218 | SkRasterClip clip(fForceConservativeRects); |
reed | d64c948 | 2014-09-05 17:37:38 -0700 | [diff] [blame] | 219 | clip.setPath(path, base, doAA); |
| 220 | return this->op(clip, op); |
| 221 | } |
| 222 | } |
| 223 | } |
| 224 | |
reed@google.com | d1e3c5f | 2011-10-10 19:36:25 +0000 | [diff] [blame] | 225 | bool SkRasterClip::setPath(const SkPath& path, const SkIRect& clip, bool doAA) { |
| 226 | SkRegion tmp; |
| 227 | tmp.setRect(clip); |
| 228 | return this->setPath(path, tmp, doAA); |
| 229 | } |
| 230 | |
reed@google.com | d1e3c5f | 2011-10-10 19:36:25 +0000 | [diff] [blame] | 231 | bool SkRasterClip::op(const SkIRect& rect, SkRegion::Op op) { |
reed@google.com | 045e62d | 2011-10-24 12:19:46 +0000 | [diff] [blame] | 232 | AUTO_RASTERCLIP_VALIDATE(*this); |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 233 | |
reed@google.com | a1c6ff4 | 2012-05-11 14:36:57 +0000 | [diff] [blame] | 234 | fIsBW ? fBW.op(rect, op) : fAA.op(rect, op); |
| 235 | return this->updateCacheAndReturnNonEmpty(); |
reed@google.com | d1e3c5f | 2011-10-10 19:36:25 +0000 | [diff] [blame] | 236 | } |
| 237 | |
reed@google.com | ba16da9 | 2011-10-11 13:15:03 +0000 | [diff] [blame] | 238 | bool SkRasterClip::op(const SkRegion& rgn, SkRegion::Op op) { |
reed@google.com | 045e62d | 2011-10-24 12:19:46 +0000 | [diff] [blame] | 239 | AUTO_RASTERCLIP_VALIDATE(*this); |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 240 | |
reed@google.com | ba16da9 | 2011-10-11 13:15:03 +0000 | [diff] [blame] | 241 | if (fIsBW) { |
reed@google.com | a1c6ff4 | 2012-05-11 14:36:57 +0000 | [diff] [blame] | 242 | (void)fBW.op(rgn, op); |
reed@google.com | ba16da9 | 2011-10-11 13:15:03 +0000 | [diff] [blame] | 243 | } else { |
| 244 | SkAAClip tmp; |
| 245 | tmp.setRegion(rgn); |
reed@google.com | a1c6ff4 | 2012-05-11 14:36:57 +0000 | [diff] [blame] | 246 | (void)fAA.op(tmp, op); |
reed@google.com | ba16da9 | 2011-10-11 13:15:03 +0000 | [diff] [blame] | 247 | } |
reed@google.com | a1c6ff4 | 2012-05-11 14:36:57 +0000 | [diff] [blame] | 248 | return this->updateCacheAndReturnNonEmpty(); |
reed@google.com | ba16da9 | 2011-10-11 13:15:03 +0000 | [diff] [blame] | 249 | } |
| 250 | |
reed@google.com | d1e3c5f | 2011-10-10 19:36:25 +0000 | [diff] [blame] | 251 | bool SkRasterClip::op(const SkRasterClip& clip, SkRegion::Op op) { |
reed@google.com | 045e62d | 2011-10-24 12:19:46 +0000 | [diff] [blame] | 252 | AUTO_RASTERCLIP_VALIDATE(*this); |
| 253 | clip.validate(); |
| 254 | |
reed@google.com | d1e3c5f | 2011-10-10 19:36:25 +0000 | [diff] [blame] | 255 | if (this->isBW() && clip.isBW()) { |
reed@google.com | a1c6ff4 | 2012-05-11 14:36:57 +0000 | [diff] [blame] | 256 | (void)fBW.op(clip.fBW, op); |
reed@google.com | d1e3c5f | 2011-10-10 19:36:25 +0000 | [diff] [blame] | 257 | } else { |
| 258 | SkAAClip tmp; |
| 259 | const SkAAClip* other; |
| 260 | |
| 261 | if (this->isBW()) { |
| 262 | this->convertToAA(); |
| 263 | } |
| 264 | if (clip.isBW()) { |
| 265 | tmp.setRegion(clip.bwRgn()); |
| 266 | other = &tmp; |
| 267 | } else { |
| 268 | other = &clip.aaRgn(); |
| 269 | } |
reed@google.com | a1c6ff4 | 2012-05-11 14:36:57 +0000 | [diff] [blame] | 270 | (void)fAA.op(*other, op); |
reed@google.com | d1e3c5f | 2011-10-10 19:36:25 +0000 | [diff] [blame] | 271 | } |
reed@google.com | a1c6ff4 | 2012-05-11 14:36:57 +0000 | [diff] [blame] | 272 | return this->updateCacheAndReturnNonEmpty(); |
reed@google.com | d1e3c5f | 2011-10-10 19:36:25 +0000 | [diff] [blame] | 273 | } |
| 274 | |
reed@google.com | 18c464b | 2012-05-11 20:57:25 +0000 | [diff] [blame] | 275 | /** |
| 276 | * Our antialiasing currently has a granularity of 1/4 of a pixel along each |
| 277 | * axis. Thus we can treat an axis coordinate as an integer if it differs |
| 278 | * from its nearest int by < half of that value (1.8 in this case). |
| 279 | */ |
| 280 | static bool nearly_integral(SkScalar x) { |
| 281 | static const SkScalar domain = SK_Scalar1 / 4; |
| 282 | static const SkScalar halfDomain = domain / 2; |
| 283 | |
| 284 | x += halfDomain; |
| 285 | return x - SkScalarFloorToScalar(x) < domain; |
reed@google.com | 0017708 | 2011-10-12 14:34:30 +0000 | [diff] [blame] | 286 | } |
| 287 | |
senorblanco | afc7cce | 2016-02-02 18:44:15 -0800 | [diff] [blame] | 288 | bool SkRasterClip::op(const SkRect& r, const SkIRect& bounds, SkRegion::Op op, bool doAA) { |
reed@google.com | 045e62d | 2011-10-24 12:19:46 +0000 | [diff] [blame] | 289 | AUTO_RASTERCLIP_VALIDATE(*this); |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 290 | |
reed | d954498 | 2014-09-09 18:46:22 -0700 | [diff] [blame] | 291 | if (fForceConservativeRects) { |
| 292 | SkIRect ir; |
| 293 | switch (mutate_conservative_op(&op, false)) { |
| 294 | case kDoNothing_MutateResult: |
| 295 | return !this->isEmpty(); |
| 296 | case kReplaceClippedAgainstGlobalBounds_MutateResult: |
senorblanco | afc7cce | 2016-02-02 18:44:15 -0800 | [diff] [blame] | 297 | ir = bounds; |
reed | d954498 | 2014-09-09 18:46:22 -0700 | [diff] [blame] | 298 | break; |
| 299 | case kContinue_MutateResult: |
reed | b07a94f | 2014-11-19 05:03:18 -0800 | [diff] [blame] | 300 | ir = r.roundOut(); |
reed | d954498 | 2014-09-09 18:46:22 -0700 | [diff] [blame] | 301 | break; |
| 302 | } |
| 303 | return this->op(ir, op); |
| 304 | } |
| 305 | |
reed@google.com | 420f74f | 2012-05-11 18:46:43 +0000 | [diff] [blame] | 306 | if (fIsBW && doAA) { |
reed@google.com | 18c464b | 2012-05-11 20:57:25 +0000 | [diff] [blame] | 307 | // check that the rect really needs aa, or is it close enought to |
| 308 | // integer boundaries that we can just treat it as a BW rect? |
| 309 | if (nearly_integral(r.fLeft) && nearly_integral(r.fTop) && |
| 310 | nearly_integral(r.fRight) && nearly_integral(r.fBottom)) { |
reed@google.com | 0017708 | 2011-10-12 14:34:30 +0000 | [diff] [blame] | 311 | doAA = false; |
| 312 | } |
| 313 | } |
| 314 | |
| 315 | if (fIsBW && !doAA) { |
| 316 | SkIRect ir; |
| 317 | r.round(&ir); |
reed@google.com | a1c6ff4 | 2012-05-11 14:36:57 +0000 | [diff] [blame] | 318 | (void)fBW.op(ir, op); |
reed@google.com | 0017708 | 2011-10-12 14:34:30 +0000 | [diff] [blame] | 319 | } else { |
| 320 | if (fIsBW) { |
| 321 | this->convertToAA(); |
| 322 | } |
reed@google.com | a1c6ff4 | 2012-05-11 14:36:57 +0000 | [diff] [blame] | 323 | (void)fAA.op(r, op, doAA); |
reed@google.com | 0017708 | 2011-10-12 14:34:30 +0000 | [diff] [blame] | 324 | } |
reed@google.com | a1c6ff4 | 2012-05-11 14:36:57 +0000 | [diff] [blame] | 325 | return this->updateCacheAndReturnNonEmpty(); |
reed@google.com | 0017708 | 2011-10-12 14:34:30 +0000 | [diff] [blame] | 326 | } |
| 327 | |
reed@google.com | 34f7e47 | 2011-10-13 15:11:59 +0000 | [diff] [blame] | 328 | void SkRasterClip::translate(int dx, int dy, SkRasterClip* dst) const { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 329 | if (nullptr == dst) { |
reed@google.com | 34f7e47 | 2011-10-13 15:11:59 +0000 | [diff] [blame] | 330 | return; |
| 331 | } |
| 332 | |
reed@google.com | 045e62d | 2011-10-24 12:19:46 +0000 | [diff] [blame] | 333 | AUTO_RASTERCLIP_VALIDATE(*this); |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 334 | |
reed@google.com | 34f7e47 | 2011-10-13 15:11:59 +0000 | [diff] [blame] | 335 | if (this->isEmpty()) { |
| 336 | dst->setEmpty(); |
| 337 | return; |
| 338 | } |
| 339 | if (0 == (dx | dy)) { |
| 340 | *dst = *this; |
| 341 | return; |
| 342 | } |
| 343 | |
| 344 | dst->fIsBW = fIsBW; |
| 345 | if (fIsBW) { |
| 346 | fBW.translate(dx, dy, &dst->fBW); |
| 347 | dst->fAA.setEmpty(); |
| 348 | } else { |
| 349 | fAA.translate(dx, dy, &dst->fAA); |
| 350 | dst->fBW.setEmpty(); |
| 351 | } |
reed@google.com | a1c6ff4 | 2012-05-11 14:36:57 +0000 | [diff] [blame] | 352 | dst->updateCacheAndReturnNonEmpty(); |
reed@google.com | 34f7e47 | 2011-10-13 15:11:59 +0000 | [diff] [blame] | 353 | } |
| 354 | |
reed@google.com | 045e62d | 2011-10-24 12:19:46 +0000 | [diff] [blame] | 355 | bool SkRasterClip::quickContains(const SkIRect& ir) const { |
| 356 | return fIsBW ? fBW.quickContains(ir) : fAA.quickContains(ir); |
| 357 | } |
| 358 | |
reed@google.com | 34f7e47 | 2011-10-13 15:11:59 +0000 | [diff] [blame] | 359 | /////////////////////////////////////////////////////////////////////////////// |
| 360 | |
reed@google.com | ba16da9 | 2011-10-11 13:15:03 +0000 | [diff] [blame] | 361 | const SkRegion& SkRasterClip::forceGetBW() { |
reed@google.com | 045e62d | 2011-10-24 12:19:46 +0000 | [diff] [blame] | 362 | AUTO_RASTERCLIP_VALIDATE(*this); |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 363 | |
reed@google.com | ba16da9 | 2011-10-11 13:15:03 +0000 | [diff] [blame] | 364 | if (!fIsBW) { |
| 365 | fBW.setRect(fAA.getBounds()); |
| 366 | } |
| 367 | return fBW; |
| 368 | } |
| 369 | |
reed@google.com | d1e3c5f | 2011-10-10 19:36:25 +0000 | [diff] [blame] | 370 | void SkRasterClip::convertToAA() { |
reed@google.com | 045e62d | 2011-10-24 12:19:46 +0000 | [diff] [blame] | 371 | AUTO_RASTERCLIP_VALIDATE(*this); |
reed | d954498 | 2014-09-09 18:46:22 -0700 | [diff] [blame] | 372 | |
| 373 | SkASSERT(!fForceConservativeRects); |
| 374 | |
reed@google.com | d1e3c5f | 2011-10-10 19:36:25 +0000 | [diff] [blame] | 375 | SkASSERT(fIsBW); |
| 376 | fAA.setRegion(fBW); |
| 377 | fIsBW = false; |
reed | 202ab2a | 2014-08-07 11:48:10 -0700 | [diff] [blame] | 378 | |
| 379 | // since we are being explicitly asked to convert-to-aa, we pass false so we don't "optimize" |
| 380 | // ourselves back to BW. |
| 381 | (void)this->updateCacheAndReturnNonEmpty(false); |
reed@google.com | d1e3c5f | 2011-10-10 19:36:25 +0000 | [diff] [blame] | 382 | } |
| 383 | |
reed@google.com | 045e62d | 2011-10-24 12:19:46 +0000 | [diff] [blame] | 384 | #ifdef SK_DEBUG |
| 385 | void SkRasterClip::validate() const { |
| 386 | // can't ever assert that fBW is empty, since we may have called forceGetBW |
| 387 | if (fIsBW) { |
| 388 | SkASSERT(fAA.isEmpty()); |
| 389 | } |
| 390 | |
| 391 | fBW.validate(); |
| 392 | fAA.validate(); |
reed@google.com | a1c6ff4 | 2012-05-11 14:36:57 +0000 | [diff] [blame] | 393 | |
| 394 | SkASSERT(this->computeIsEmpty() == fIsEmpty); |
| 395 | SkASSERT(this->computeIsRect() == fIsRect); |
reed@google.com | 045e62d | 2011-10-24 12:19:46 +0000 | [diff] [blame] | 396 | } |
| 397 | #endif |
| 398 | |
| 399 | /////////////////////////////////////////////////////////////////////////////// |
| 400 | |
| 401 | SkAAClipBlitterWrapper::SkAAClipBlitterWrapper() { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 402 | SkDEBUGCODE(fClipRgn = nullptr;) |
| 403 | SkDEBUGCODE(fBlitter = nullptr;) |
reed@google.com | 045e62d | 2011-10-24 12:19:46 +0000 | [diff] [blame] | 404 | } |
| 405 | |
| 406 | SkAAClipBlitterWrapper::SkAAClipBlitterWrapper(const SkRasterClip& clip, |
| 407 | SkBlitter* blitter) { |
| 408 | this->init(clip, blitter); |
| 409 | } |
| 410 | |
| 411 | SkAAClipBlitterWrapper::SkAAClipBlitterWrapper(const SkAAClip* aaclip, |
| 412 | SkBlitter* blitter) { |
| 413 | SkASSERT(blitter); |
| 414 | SkASSERT(aaclip); |
| 415 | fBWRgn.setRect(aaclip->getBounds()); |
| 416 | fAABlitter.init(blitter, aaclip); |
| 417 | // now our return values |
| 418 | fClipRgn = &fBWRgn; |
| 419 | fBlitter = &fAABlitter; |
| 420 | } |
| 421 | |
| 422 | void SkAAClipBlitterWrapper::init(const SkRasterClip& clip, SkBlitter* blitter) { |
| 423 | SkASSERT(blitter); |
| 424 | if (clip.isBW()) { |
| 425 | fClipRgn = &clip.bwRgn(); |
| 426 | fBlitter = blitter; |
| 427 | } else { |
| 428 | const SkAAClip& aaclip = clip.aaRgn(); |
| 429 | fBWRgn.setRect(aaclip.getBounds()); |
| 430 | fAABlitter.init(blitter, &aaclip); |
| 431 | // now our return values |
| 432 | fClipRgn = &fBWRgn; |
| 433 | fBlitter = &fAABlitter; |
| 434 | } |
| 435 | } |