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
17 SkRasterClip(const SkIRect&);
18 SkRasterClip(const SkRasterClip&);
21 bool isBW() const { return fIsBW; }
22 bool isAA() const { return !fIsBW; }
23 const SkRegion& bwRgn() const { SkASSERT(fIsBW); return fBW; }
24 const SkAAClip& aaRgn() const { SkASSERT(!fIsBW); return fAA; }
26 bool isEmpty() const {
27 SkASSERT(this->computeIsEmpty() == fIsEmpty);
32 SkASSERT(this->computeIsRect() == fIsRect);
36 bool isComplex() const;
37 const SkIRect& getBounds() const;
40 bool setRect(const SkIRect&);
42 bool setPath(const SkPath& path, const SkRegion& clip, bool doAA);
43 bool setPath(const SkPath& path, const SkIRect& clip, bool doAA);
45 bool op(const SkIRect&, SkRegion::Op);
46 bool op(const SkRegion&, SkRegion::Op);
47 bool op(const SkRasterClip&, SkRegion::Op);
48 bool op(const SkRect&, SkRegion::Op, bool doAA);
50 void translate(int dx, int dy, SkRasterClip* dst) const;
51 void translate(int dx, int dy) {
52 this->translate(dx, dy, this);
55 bool quickContains(const SkIRect& rect) const;
56 bool quickContains(int left, int top, int right, int bottom) const {
57 return quickContains(SkIRect::MakeLTRB(left, top, right, bottom));
61 * Return true if this region is empty, or if the specified rectangle does
62 * not intersect the region. Returning false is not a guarantee that they
63 * intersect, but returning true is a guarantee that they do not.
65 bool quickReject(const SkIRect& rect) const {
66 return this->isEmpty() || rect.isEmpty() ||
67 !SkIRect::Intersects(this->getBounds(), rect);
70 // hack for SkCanvas::getTotalClip
71 const SkRegion& forceGetBW();
74 void validate() const;
76 void validate() const {}
83 // these 2 are caches based on querying the right obj based on fIsBW
87 bool computeIsEmpty() const {
88 return fIsBW ? fBW.isEmpty() : fAA.isEmpty();
91 bool computeIsRect() const {
92 return fIsBW ? fBW.isRect() : fAA.isRect();
95 bool updateCacheAndReturnNonEmpty(bool detectAARect = true) {
96 fIsEmpty = this->computeIsEmpty();
98 // detect that our computed AA is really just a (hard-edged) rect
99 if (detectAARect && !fIsEmpty && !fIsBW && fAA.isRect()) {
100 fBW.setRect(fAA.getBounds());
101 fAA.setEmpty(); // don't need this guy anymore
105 fIsRect = this->computeIsRect();
112 class SkAutoRasterClipValidate : SkNoncopyable {
114 SkAutoRasterClipValidate(const SkRasterClip& rc) : fRC(rc) {
117 ~SkAutoRasterClipValidate() {
121 const SkRasterClip& fRC;
123 #define SkAutoRasterClipValidate(...) SK_REQUIRE_LOCAL_VAR(SkAutoRasterClipValidate)
126 #define AUTO_RASTERCLIP_VALIDATE(rc) SkAutoRasterClipValidate arcv(rc)
128 #define AUTO_RASTERCLIP_VALIDATE(rc)
131 ///////////////////////////////////////////////////////////////////////////////
134 * Encapsulates the logic of deciding if we need to change/wrap the blitter
135 * for aaclipping. If so, getRgn and getBlitter return modified values. If
136 * not, they return the raw blitter and (bw) clip region.
138 * We need to keep the constructor/destructor cost as small as possible, so we
139 * can freely put this guy on the stack, and not pay too much for the case when
140 * we're really BW anyways.
142 class SkAAClipBlitterWrapper {
144 SkAAClipBlitterWrapper();
145 SkAAClipBlitterWrapper(const SkRasterClip&, SkBlitter*);
146 SkAAClipBlitterWrapper(const SkAAClip*, SkBlitter*);
148 void init(const SkRasterClip&, SkBlitter*);
150 const SkIRect& getBounds() const {
152 return fClipRgn->getBounds();
154 const SkRegion& getRgn() const {
158 SkBlitter* getBlitter() {
165 SkAAClipBlitter fAABlitter;
167 const SkRegion* fClipRgn;