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 | |
reed | d64c948 | 2014-09-05 17:37:38 -0700 | [diff] [blame] | 164 | bool SkRasterClip::op(const SkPath& path, const SkISize& size, SkRegion::Op op, bool doAA) { |
| 165 | // base is used to limit the size (and therefore memory allocation) of the |
| 166 | // region that results from scan converting devPath. |
| 167 | SkRegion base; |
reed | d954498 | 2014-09-09 18:46:22 -0700 | [diff] [blame] | 168 | |
| 169 | if (fForceConservativeRects) { |
| 170 | SkIRect ir; |
| 171 | switch (mutate_conservative_op(&op, path.isInverseFillType())) { |
| 172 | case kDoNothing_MutateResult: |
| 173 | return !this->isEmpty(); |
| 174 | case kReplaceClippedAgainstGlobalBounds_MutateResult: |
| 175 | ir = SkIRect::MakeSize(size); |
| 176 | break; |
| 177 | case kContinue_MutateResult: |
reed | b07a94f | 2014-11-19 05:03:18 -0800 | [diff] [blame^] | 178 | ir = path.getBounds().roundOut(); |
reed | d954498 | 2014-09-09 18:46:22 -0700 | [diff] [blame] | 179 | break; |
| 180 | } |
| 181 | return this->op(ir, op); |
| 182 | } |
| 183 | |
reed | d64c948 | 2014-09-05 17:37:38 -0700 | [diff] [blame] | 184 | if (SkRegion::kIntersect_Op == op) { |
| 185 | // since we are intersect, we can do better (tighter) with currRgn's |
| 186 | // bounds, than just using the device. However, if currRgn is complex, |
| 187 | // our region blitter may hork, so we do that case in two steps. |
| 188 | if (this->isRect()) { |
| 189 | // FIXME: we should also be able to do this when this->isBW(), |
| 190 | // but relaxing the test above triggers GM asserts in |
| 191 | // SkRgnBuilder::blitH(). We need to investigate what's going on. |
| 192 | return this->setPath(path, this->bwRgn(), doAA); |
| 193 | } else { |
| 194 | base.setRect(this->getBounds()); |
reed | d954498 | 2014-09-09 18:46:22 -0700 | [diff] [blame] | 195 | SkRasterClip clip(fForceConservativeRects); |
reed | d64c948 | 2014-09-05 17:37:38 -0700 | [diff] [blame] | 196 | clip.setPath(path, base, doAA); |
| 197 | return this->op(clip, op); |
| 198 | } |
| 199 | } else { |
| 200 | base.setRect(0, 0, size.width(), size.height()); |
| 201 | |
| 202 | if (SkRegion::kReplace_Op == op) { |
| 203 | return this->setPath(path, base, doAA); |
| 204 | } else { |
reed | d954498 | 2014-09-09 18:46:22 -0700 | [diff] [blame] | 205 | SkRasterClip clip(fForceConservativeRects); |
reed | d64c948 | 2014-09-05 17:37:38 -0700 | [diff] [blame] | 206 | clip.setPath(path, base, doAA); |
| 207 | return this->op(clip, op); |
| 208 | } |
| 209 | } |
| 210 | } |
| 211 | |
reed@google.com | d1e3c5f | 2011-10-10 19:36:25 +0000 | [diff] [blame] | 212 | bool SkRasterClip::setPath(const SkPath& path, const SkIRect& clip, bool doAA) { |
| 213 | SkRegion tmp; |
| 214 | tmp.setRect(clip); |
| 215 | return this->setPath(path, tmp, doAA); |
| 216 | } |
| 217 | |
reed@google.com | d1e3c5f | 2011-10-10 19:36:25 +0000 | [diff] [blame] | 218 | bool SkRasterClip::op(const SkIRect& rect, SkRegion::Op op) { |
reed@google.com | 045e62d | 2011-10-24 12:19:46 +0000 | [diff] [blame] | 219 | AUTO_RASTERCLIP_VALIDATE(*this); |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 220 | |
reed@google.com | a1c6ff4 | 2012-05-11 14:36:57 +0000 | [diff] [blame] | 221 | fIsBW ? fBW.op(rect, op) : fAA.op(rect, op); |
| 222 | return this->updateCacheAndReturnNonEmpty(); |
reed@google.com | d1e3c5f | 2011-10-10 19:36:25 +0000 | [diff] [blame] | 223 | } |
| 224 | |
reed@google.com | ba16da9 | 2011-10-11 13:15:03 +0000 | [diff] [blame] | 225 | bool SkRasterClip::op(const SkRegion& rgn, SkRegion::Op op) { |
reed@google.com | 045e62d | 2011-10-24 12:19:46 +0000 | [diff] [blame] | 226 | AUTO_RASTERCLIP_VALIDATE(*this); |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 227 | |
reed@google.com | ba16da9 | 2011-10-11 13:15:03 +0000 | [diff] [blame] | 228 | if (fIsBW) { |
reed@google.com | a1c6ff4 | 2012-05-11 14:36:57 +0000 | [diff] [blame] | 229 | (void)fBW.op(rgn, op); |
reed@google.com | ba16da9 | 2011-10-11 13:15:03 +0000 | [diff] [blame] | 230 | } else { |
| 231 | SkAAClip tmp; |
| 232 | tmp.setRegion(rgn); |
reed@google.com | a1c6ff4 | 2012-05-11 14:36:57 +0000 | [diff] [blame] | 233 | (void)fAA.op(tmp, op); |
reed@google.com | ba16da9 | 2011-10-11 13:15:03 +0000 | [diff] [blame] | 234 | } |
reed@google.com | a1c6ff4 | 2012-05-11 14:36:57 +0000 | [diff] [blame] | 235 | return this->updateCacheAndReturnNonEmpty(); |
reed@google.com | ba16da9 | 2011-10-11 13:15:03 +0000 | [diff] [blame] | 236 | } |
| 237 | |
reed@google.com | d1e3c5f | 2011-10-10 19:36:25 +0000 | [diff] [blame] | 238 | bool SkRasterClip::op(const SkRasterClip& clip, SkRegion::Op op) { |
reed@google.com | 045e62d | 2011-10-24 12:19:46 +0000 | [diff] [blame] | 239 | AUTO_RASTERCLIP_VALIDATE(*this); |
| 240 | clip.validate(); |
| 241 | |
reed@google.com | d1e3c5f | 2011-10-10 19:36:25 +0000 | [diff] [blame] | 242 | if (this->isBW() && clip.isBW()) { |
reed@google.com | a1c6ff4 | 2012-05-11 14:36:57 +0000 | [diff] [blame] | 243 | (void)fBW.op(clip.fBW, op); |
reed@google.com | d1e3c5f | 2011-10-10 19:36:25 +0000 | [diff] [blame] | 244 | } else { |
| 245 | SkAAClip tmp; |
| 246 | const SkAAClip* other; |
| 247 | |
| 248 | if (this->isBW()) { |
| 249 | this->convertToAA(); |
| 250 | } |
| 251 | if (clip.isBW()) { |
| 252 | tmp.setRegion(clip.bwRgn()); |
| 253 | other = &tmp; |
| 254 | } else { |
| 255 | other = &clip.aaRgn(); |
| 256 | } |
reed@google.com | a1c6ff4 | 2012-05-11 14:36:57 +0000 | [diff] [blame] | 257 | (void)fAA.op(*other, op); |
reed@google.com | d1e3c5f | 2011-10-10 19:36:25 +0000 | [diff] [blame] | 258 | } |
reed@google.com | a1c6ff4 | 2012-05-11 14:36:57 +0000 | [diff] [blame] | 259 | return this->updateCacheAndReturnNonEmpty(); |
reed@google.com | d1e3c5f | 2011-10-10 19:36:25 +0000 | [diff] [blame] | 260 | } |
| 261 | |
reed@google.com | 18c464b | 2012-05-11 20:57:25 +0000 | [diff] [blame] | 262 | /** |
| 263 | * Our antialiasing currently has a granularity of 1/4 of a pixel along each |
| 264 | * axis. Thus we can treat an axis coordinate as an integer if it differs |
| 265 | * from its nearest int by < half of that value (1.8 in this case). |
| 266 | */ |
| 267 | static bool nearly_integral(SkScalar x) { |
| 268 | static const SkScalar domain = SK_Scalar1 / 4; |
| 269 | static const SkScalar halfDomain = domain / 2; |
| 270 | |
| 271 | x += halfDomain; |
| 272 | return x - SkScalarFloorToScalar(x) < domain; |
reed@google.com | 0017708 | 2011-10-12 14:34:30 +0000 | [diff] [blame] | 273 | } |
| 274 | |
reed | d954498 | 2014-09-09 18:46:22 -0700 | [diff] [blame] | 275 | bool SkRasterClip::op(const SkRect& r, const SkISize& size, SkRegion::Op op, bool doAA) { |
reed@google.com | 045e62d | 2011-10-24 12:19:46 +0000 | [diff] [blame] | 276 | AUTO_RASTERCLIP_VALIDATE(*this); |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 277 | |
reed | d954498 | 2014-09-09 18:46:22 -0700 | [diff] [blame] | 278 | if (fForceConservativeRects) { |
| 279 | SkIRect ir; |
| 280 | switch (mutate_conservative_op(&op, false)) { |
| 281 | case kDoNothing_MutateResult: |
| 282 | return !this->isEmpty(); |
| 283 | case kReplaceClippedAgainstGlobalBounds_MutateResult: |
| 284 | ir = SkIRect::MakeSize(size); |
| 285 | break; |
| 286 | case kContinue_MutateResult: |
reed | b07a94f | 2014-11-19 05:03:18 -0800 | [diff] [blame^] | 287 | ir = r.roundOut(); |
reed | d954498 | 2014-09-09 18:46:22 -0700 | [diff] [blame] | 288 | break; |
| 289 | } |
| 290 | return this->op(ir, op); |
| 291 | } |
| 292 | |
reed@google.com | 420f74f | 2012-05-11 18:46:43 +0000 | [diff] [blame] | 293 | if (fIsBW && doAA) { |
reed@google.com | 18c464b | 2012-05-11 20:57:25 +0000 | [diff] [blame] | 294 | // check that the rect really needs aa, or is it close enought to |
| 295 | // integer boundaries that we can just treat it as a BW rect? |
| 296 | if (nearly_integral(r.fLeft) && nearly_integral(r.fTop) && |
| 297 | nearly_integral(r.fRight) && nearly_integral(r.fBottom)) { |
reed@google.com | 0017708 | 2011-10-12 14:34:30 +0000 | [diff] [blame] | 298 | doAA = false; |
| 299 | } |
| 300 | } |
| 301 | |
| 302 | if (fIsBW && !doAA) { |
| 303 | SkIRect ir; |
| 304 | r.round(&ir); |
reed@google.com | a1c6ff4 | 2012-05-11 14:36:57 +0000 | [diff] [blame] | 305 | (void)fBW.op(ir, op); |
reed@google.com | 0017708 | 2011-10-12 14:34:30 +0000 | [diff] [blame] | 306 | } else { |
| 307 | if (fIsBW) { |
| 308 | this->convertToAA(); |
| 309 | } |
reed@google.com | a1c6ff4 | 2012-05-11 14:36:57 +0000 | [diff] [blame] | 310 | (void)fAA.op(r, op, doAA); |
reed@google.com | 0017708 | 2011-10-12 14:34:30 +0000 | [diff] [blame] | 311 | } |
reed@google.com | a1c6ff4 | 2012-05-11 14:36:57 +0000 | [diff] [blame] | 312 | return this->updateCacheAndReturnNonEmpty(); |
reed@google.com | 0017708 | 2011-10-12 14:34:30 +0000 | [diff] [blame] | 313 | } |
| 314 | |
reed@google.com | 34f7e47 | 2011-10-13 15:11:59 +0000 | [diff] [blame] | 315 | void SkRasterClip::translate(int dx, int dy, SkRasterClip* dst) const { |
| 316 | if (NULL == dst) { |
| 317 | return; |
| 318 | } |
| 319 | |
reed@google.com | 045e62d | 2011-10-24 12:19:46 +0000 | [diff] [blame] | 320 | AUTO_RASTERCLIP_VALIDATE(*this); |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 321 | |
reed@google.com | 34f7e47 | 2011-10-13 15:11:59 +0000 | [diff] [blame] | 322 | if (this->isEmpty()) { |
| 323 | dst->setEmpty(); |
| 324 | return; |
| 325 | } |
| 326 | if (0 == (dx | dy)) { |
| 327 | *dst = *this; |
| 328 | return; |
| 329 | } |
| 330 | |
| 331 | dst->fIsBW = fIsBW; |
| 332 | if (fIsBW) { |
| 333 | fBW.translate(dx, dy, &dst->fBW); |
| 334 | dst->fAA.setEmpty(); |
| 335 | } else { |
| 336 | fAA.translate(dx, dy, &dst->fAA); |
| 337 | dst->fBW.setEmpty(); |
| 338 | } |
reed@google.com | a1c6ff4 | 2012-05-11 14:36:57 +0000 | [diff] [blame] | 339 | dst->updateCacheAndReturnNonEmpty(); |
reed@google.com | 34f7e47 | 2011-10-13 15:11:59 +0000 | [diff] [blame] | 340 | } |
| 341 | |
reed@google.com | 045e62d | 2011-10-24 12:19:46 +0000 | [diff] [blame] | 342 | bool SkRasterClip::quickContains(const SkIRect& ir) const { |
| 343 | return fIsBW ? fBW.quickContains(ir) : fAA.quickContains(ir); |
| 344 | } |
| 345 | |
reed@google.com | 34f7e47 | 2011-10-13 15:11:59 +0000 | [diff] [blame] | 346 | /////////////////////////////////////////////////////////////////////////////// |
| 347 | |
reed@google.com | ba16da9 | 2011-10-11 13:15:03 +0000 | [diff] [blame] | 348 | const SkRegion& SkRasterClip::forceGetBW() { |
reed@google.com | 045e62d | 2011-10-24 12:19:46 +0000 | [diff] [blame] | 349 | AUTO_RASTERCLIP_VALIDATE(*this); |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 350 | |
reed@google.com | ba16da9 | 2011-10-11 13:15:03 +0000 | [diff] [blame] | 351 | if (!fIsBW) { |
| 352 | fBW.setRect(fAA.getBounds()); |
| 353 | } |
| 354 | return fBW; |
| 355 | } |
| 356 | |
reed@google.com | d1e3c5f | 2011-10-10 19:36:25 +0000 | [diff] [blame] | 357 | void SkRasterClip::convertToAA() { |
reed@google.com | 045e62d | 2011-10-24 12:19:46 +0000 | [diff] [blame] | 358 | AUTO_RASTERCLIP_VALIDATE(*this); |
reed | d954498 | 2014-09-09 18:46:22 -0700 | [diff] [blame] | 359 | |
| 360 | SkASSERT(!fForceConservativeRects); |
| 361 | |
reed@google.com | d1e3c5f | 2011-10-10 19:36:25 +0000 | [diff] [blame] | 362 | SkASSERT(fIsBW); |
| 363 | fAA.setRegion(fBW); |
| 364 | fIsBW = false; |
reed | 202ab2a | 2014-08-07 11:48:10 -0700 | [diff] [blame] | 365 | |
| 366 | // since we are being explicitly asked to convert-to-aa, we pass false so we don't "optimize" |
| 367 | // ourselves back to BW. |
| 368 | (void)this->updateCacheAndReturnNonEmpty(false); |
reed@google.com | d1e3c5f | 2011-10-10 19:36:25 +0000 | [diff] [blame] | 369 | } |
| 370 | |
reed@google.com | 045e62d | 2011-10-24 12:19:46 +0000 | [diff] [blame] | 371 | #ifdef SK_DEBUG |
| 372 | void SkRasterClip::validate() const { |
| 373 | // can't ever assert that fBW is empty, since we may have called forceGetBW |
| 374 | if (fIsBW) { |
| 375 | SkASSERT(fAA.isEmpty()); |
| 376 | } |
| 377 | |
| 378 | fBW.validate(); |
| 379 | fAA.validate(); |
reed@google.com | a1c6ff4 | 2012-05-11 14:36:57 +0000 | [diff] [blame] | 380 | |
| 381 | SkASSERT(this->computeIsEmpty() == fIsEmpty); |
| 382 | SkASSERT(this->computeIsRect() == fIsRect); |
reed@google.com | 045e62d | 2011-10-24 12:19:46 +0000 | [diff] [blame] | 383 | } |
| 384 | #endif |
| 385 | |
| 386 | /////////////////////////////////////////////////////////////////////////////// |
| 387 | |
| 388 | SkAAClipBlitterWrapper::SkAAClipBlitterWrapper() { |
| 389 | SkDEBUGCODE(fClipRgn = NULL;) |
| 390 | SkDEBUGCODE(fBlitter = NULL;) |
| 391 | } |
| 392 | |
| 393 | SkAAClipBlitterWrapper::SkAAClipBlitterWrapper(const SkRasterClip& clip, |
| 394 | SkBlitter* blitter) { |
| 395 | this->init(clip, blitter); |
| 396 | } |
| 397 | |
| 398 | SkAAClipBlitterWrapper::SkAAClipBlitterWrapper(const SkAAClip* aaclip, |
| 399 | SkBlitter* blitter) { |
| 400 | SkASSERT(blitter); |
| 401 | SkASSERT(aaclip); |
| 402 | fBWRgn.setRect(aaclip->getBounds()); |
| 403 | fAABlitter.init(blitter, aaclip); |
| 404 | // now our return values |
| 405 | fClipRgn = &fBWRgn; |
| 406 | fBlitter = &fAABlitter; |
| 407 | } |
| 408 | |
| 409 | void SkAAClipBlitterWrapper::init(const SkRasterClip& clip, SkBlitter* blitter) { |
| 410 | SkASSERT(blitter); |
| 411 | if (clip.isBW()) { |
| 412 | fClipRgn = &clip.bwRgn(); |
| 413 | fBlitter = blitter; |
| 414 | } else { |
| 415 | const SkAAClip& aaclip = clip.aaRgn(); |
| 416 | fBWRgn.setRect(aaclip.getBounds()); |
| 417 | fAABlitter.init(blitter, &aaclip); |
| 418 | // now our return values |
| 419 | fClipRgn = &fBWRgn; |
| 420 | fBlitter = &fAABlitter; |
| 421 | } |
| 422 | } |