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