2 * Copyright 2010 Google Inc.
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
8 #ifndef SkRasterClip_DEFINED
9 #define SkRasterClip_DEFINED
16 SkRasterClip(bool forceConservativeRects = false);
17 SkRasterClip(const SkIRect&, bool forceConservativeRects = false);
18 SkRasterClip(const SkRasterClip&);
21 bool isForceConservativeRects() const { return fForceConservativeRects; }
23 bool isBW() const { return fIsBW; }
24 bool isAA() const { return !fIsBW; }
25 const SkRegion& bwRgn() const { SkASSERT(fIsBW); return fBW; }
26 const SkAAClip& aaRgn() const { SkASSERT(!fIsBW); return fAA; }
28 bool isEmpty() const {
29 SkASSERT(this->computeIsEmpty() == fIsEmpty);
34 SkASSERT(this->computeIsRect() == fIsRect);
38 bool isComplex() const;
39 const SkIRect& getBounds() const;
42 bool setRect(const SkIRect&);
44 bool op(const SkIRect&, SkRegion::Op);
45 bool op(const SkRegion&, SkRegion::Op);
46 bool op(const SkRect&, const SkISize&, SkRegion::Op, bool doAA);
47 bool op(const SkPath&, const SkISize&, SkRegion::Op, bool doAA);
49 void translate(int dx, int dy, SkRasterClip* dst) const;
50 void translate(int dx, int dy) {
51 this->translate(dx, dy, this);
54 bool quickContains(const SkIRect& rect) const;
55 bool quickContains(int left, int top, int right, int bottom) const {
56 return quickContains(SkIRect::MakeLTRB(left, top, right, bottom));
60 * Return true if this region is empty, or if the specified rectangle does
61 * not intersect the region. Returning false is not a guarantee that they
62 * intersect, but returning true is a guarantee that they do not.
64 bool quickReject(const SkIRect& rect) const {
65 return !SkIRect::Intersects(this->getBounds(), rect);
68 // hack for SkCanvas::getTotalClip
69 const SkRegion& forceGetBW();
72 void validate() const;
74 void validate() const {}
80 bool fForceConservativeRects;
82 // these 2 are caches based on querying the right obj based on fIsBW
86 bool computeIsEmpty() const {
87 return fIsBW ? fBW.isEmpty() : fAA.isEmpty();
90 bool computeIsRect() const {
91 return fIsBW ? fBW.isRect() : fAA.isRect();
94 bool updateCacheAndReturnNonEmpty(bool detectAARect = true) {
95 fIsEmpty = this->computeIsEmpty();
97 // detect that our computed AA is really just a (hard-edged) rect
98 if (detectAARect && !fIsEmpty && !fIsBW && fAA.isRect()) {
99 fBW.setRect(fAA.getBounds());
100 fAA.setEmpty(); // don't need this guy anymore
104 fIsRect = this->computeIsRect();
110 bool setPath(const SkPath& path, const SkRegion& clip, bool doAA);
111 bool setPath(const SkPath& path, const SkIRect& clip, bool doAA);
112 bool op(const SkRasterClip&, SkRegion::Op);
113 bool setConservativeRect(const SkRect& r, const SkIRect& clipR, bool isInverse);
116 class SkAutoRasterClipValidate : SkNoncopyable {
118 SkAutoRasterClipValidate(const SkRasterClip& rc) : fRC(rc) {
121 ~SkAutoRasterClipValidate() {
125 const SkRasterClip& fRC;
127 #define SkAutoRasterClipValidate(...) SK_REQUIRE_LOCAL_VAR(SkAutoRasterClipValidate)
130 #define AUTO_RASTERCLIP_VALIDATE(rc) SkAutoRasterClipValidate arcv(rc)
132 #define AUTO_RASTERCLIP_VALIDATE(rc)
135 ///////////////////////////////////////////////////////////////////////////////
138 * Encapsulates the logic of deciding if we need to change/wrap the blitter
139 * for aaclipping. If so, getRgn and getBlitter return modified values. If
140 * not, they return the raw blitter and (bw) clip region.
142 * We need to keep the constructor/destructor cost as small as possible, so we
143 * can freely put this guy on the stack, and not pay too much for the case when
144 * we're really BW anyways.
146 class SkAAClipBlitterWrapper {
148 SkAAClipBlitterWrapper();
149 SkAAClipBlitterWrapper(const SkRasterClip&, SkBlitter*);
150 SkAAClipBlitterWrapper(const SkAAClip*, SkBlitter*);
152 void init(const SkRasterClip&, SkBlitter*);
154 const SkIRect& getBounds() const {
156 return fClipRgn->getBounds();
158 const SkRegion& getRgn() const {
162 SkBlitter* getBlitter() {
169 SkAAClipBlitter fAABlitter;
171 const SkRegion* fClipRgn;