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" |
| 9 | |
| 10 | |
| 11 | SkRasterClip::SkRasterClip() { |
| 12 | fIsBW = true; |
| 13 | } |
| 14 | |
| 15 | bool SkRasterClip::isEmpty() const { |
| 16 | return fIsBW ? fBW.isEmpty() : fAA.isEmpty(); |
| 17 | } |
| 18 | |
| 19 | bool SkRasterClip::isRect() const { |
| 20 | return fIsBW ? fBW.isRect() : false; |
| 21 | } |
| 22 | |
| 23 | bool SkRasterClip::isComplex() const { |
| 24 | return fIsBW ? fBW.isComplex() : !fAA.isEmpty(); |
| 25 | } |
| 26 | |
| 27 | const SkIRect& SkRasterClip::getBounds() const { |
| 28 | return fIsBW ? fBW.getBounds() : fAA.getBounds(); |
| 29 | } |
| 30 | |
| 31 | bool SkRasterClip::setEmpty() { |
| 32 | fIsBW = true; |
| 33 | fBW.setEmpty(); |
| 34 | fAA.setEmpty(); |
| 35 | return false; |
| 36 | } |
| 37 | |
| 38 | bool SkRasterClip::setIRect(const SkIRect& rect) { |
| 39 | fIsBW = true; |
| 40 | fAA.setEmpty(); |
| 41 | return fBW.setRect(rect); |
| 42 | } |
| 43 | |
| 44 | bool SkRasterClip::setPath(const SkPath& path, const SkRegion& clip, bool doAA) { |
| 45 | if (this->isBW() && !doAA) { |
| 46 | return fBW.setPath(path, clip); |
| 47 | } else { |
| 48 | if (this->isBW()) { |
| 49 | this->convertToAA(); |
| 50 | } |
| 51 | return fAA.setPath(path, &clip, doAA); |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | bool SkRasterClip::setPath(const SkPath& path, const SkIRect& clip, bool doAA) { |
| 56 | SkRegion tmp; |
| 57 | tmp.setRect(clip); |
| 58 | return this->setPath(path, tmp, doAA); |
| 59 | } |
| 60 | |
| 61 | bool SkRasterClip::setPath(const SkPath& path, const SkRasterClip& clip, |
| 62 | bool doAA) { |
| 63 | if (clip.isBW()) { |
| 64 | return this->setPath(path, clip.bwRgn(), doAA); |
| 65 | } else { |
| 66 | SkRegion tmp; |
| 67 | tmp.setRect(clip.getBounds()); |
| 68 | if (!this->setPath(path, clip, doAA)) { |
| 69 | return false; |
| 70 | } |
| 71 | return this->op(clip, SkRegion::kIntersect_Op); |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | bool SkRasterClip::op(const SkIRect& rect, SkRegion::Op op) { |
| 76 | return fIsBW ? fBW.op(rect, op) : fAA.op(rect, op); |
| 77 | } |
| 78 | |
| 79 | bool SkRasterClip::op(const SkRasterClip& clip, SkRegion::Op op) { |
| 80 | if (this->isBW() && clip.isBW()) { |
| 81 | return fBW.op(clip.fBW, op); |
| 82 | } else { |
| 83 | SkAAClip tmp; |
| 84 | const SkAAClip* other; |
| 85 | |
| 86 | if (this->isBW()) { |
| 87 | this->convertToAA(); |
| 88 | } |
| 89 | if (clip.isBW()) { |
| 90 | tmp.setRegion(clip.bwRgn()); |
| 91 | other = &tmp; |
| 92 | } else { |
| 93 | other = &clip.aaRgn(); |
| 94 | } |
| 95 | return fAA.op(*other, op); |
| 96 | } |
| 97 | } |
| 98 | |
| 99 | void SkRasterClip::convertToAA() { |
| 100 | SkASSERT(fIsBW); |
| 101 | fAA.setRegion(fBW); |
| 102 | fIsBW = false; |
| 103 | } |
| 104 | |