Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
SkRasterClip.h
Go to the documentation of this file.
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#ifndef SkRasterClip_DEFINED
9#define SkRasterClip_DEFINED
10
11#include "include/core/SkRect.h"
17#include "src/core/SkAAClip.h"
18
19class SkBlitter;
20class SkMatrix;
21class SkPath;
22class SkRRect;
23enum class SkClipOp;
24
25/**
26 * Wraps a SkRegion and SkAAClip, so we have a single object that can represent either our
27 * BW or antialiased clips.
28 */
30public:
32 explicit SkRasterClip(const SkIRect&);
33 explicit SkRasterClip(const SkRegion&);
34 explicit SkRasterClip(const SkRasterClip&);
35 SkRasterClip(const SkPath& path, const SkIRect& bounds, bool doAA);
36
38
40
41 bool isBW() const { return fIsBW; }
42 bool isAA() const { return !fIsBW; }
43 const SkRegion& bwRgn() const { SkASSERT(fIsBW); return fBW; }
44 const SkAAClip& aaRgn() const { SkASSERT(!fIsBW); return fAA; }
45
46 bool isEmpty() const {
47 SkASSERT(this->computeIsEmpty() == fIsEmpty);
48 return fIsEmpty;
49 }
50
51 bool isRect() const {
52 SkASSERT(this->computeIsRect() == fIsRect);
53 return fIsRect;
54 }
55
56 bool isComplex() const {
57 return fIsBW ? fBW.isComplex() : !fAA.isEmpty();
58 }
59 const SkIRect& getBounds() const {
60 return fIsBW ? fBW.getBounds() : fAA.getBounds();
61 }
62
63 bool setEmpty();
64 bool setRect(const SkIRect&);
65
66 bool op(const SkIRect&, SkClipOp);
67 bool op(const SkRegion&, SkClipOp);
68 bool op(const SkRect&, const SkMatrix& matrix, SkClipOp, bool doAA);
69 bool op(const SkRRect&, const SkMatrix& matrix, SkClipOp, bool doAA);
70 bool op(const SkPath&, const SkMatrix& matrix, SkClipOp, bool doAA);
71 bool op(sk_sp<SkShader>);
72
73 void translate(int dx, int dy, SkRasterClip* dst) const;
74
75 bool quickContains(const SkIRect& rect) const {
76 return fIsBW ? fBW.quickContains(rect) : fAA.quickContains(rect);
77 }
78
79 /**
80 * Return true if this region is empty, or if the specified rectangle does
81 * not intersect the region. Returning false is not a guarantee that they
82 * intersect, but returning true is a guarantee that they do not.
83 */
84 bool quickReject(const SkIRect& rect) const {
85 return !SkIRect::Intersects(this->getBounds(), rect);
86 }
87
88#ifdef SK_DEBUG
89 void validate() const;
90#else
91 void validate() const {}
92#endif
93
94 sk_sp<SkShader> clipShader() const { return fShader; }
95
96private:
97 SkRegion fBW;
98 SkAAClip fAA;
99 bool fIsBW;
100 // these 2 are caches based on querying the right obj based on fIsBW
101 bool fIsEmpty;
102 bool fIsRect;
103 // if present, this augments the clip, not replaces it
104 sk_sp<SkShader> fShader;
105
106 bool computeIsEmpty() const {
107 return fIsBW ? fBW.isEmpty() : fAA.isEmpty();
108 }
109
110 bool computeIsRect() const {
111 return fIsBW ? fBW.isRect() : fAA.isRect();
112 }
113
114 bool updateCacheAndReturnNonEmpty(bool detectAARect = true) {
115 fIsEmpty = this->computeIsEmpty();
116
117 // detect that our computed AA is really just a (hard-edged) rect
118 if (detectAARect && !fIsEmpty && !fIsBW && fAA.isRect()) {
119 fBW.setRect(fAA.getBounds());
120 fAA.setEmpty(); // don't need this anymore
121 fIsBW = true;
122 }
123
124 fIsRect = this->computeIsRect();
125 return !fIsEmpty;
126 }
127
128 void convertToAA();
129
130 bool op(const SkRasterClip&, SkClipOp);
131};
132
134public:
136 fRC.validate();
137 }
141private:
142 const SkRasterClip& fRC;
143};
144
145#ifdef SK_DEBUG
146 #define AUTO_RASTERCLIP_VALIDATE(rc) SkAutoRasterClipValidate arcv(rc)
147#else
148 #define AUTO_RASTERCLIP_VALIDATE(rc)
149#endif
150
151///////////////////////////////////////////////////////////////////////////////
152
153/**
154 * Encapsulates the logic of deciding if we need to change/wrap the blitter
155 * for aaclipping. If so, getRgn and getBlitter return modified values. If
156 * not, they return the raw blitter and (bw) clip region.
157 *
158 * We need to keep the constructor/destructor cost as small as possible, so we
159 * can freely put this on the stack, and not pay too much for the case when
160 * we're really BW anyways.
161 */
163public:
167
168 void init(const SkRasterClip&, SkBlitter*);
169
170 const SkIRect& getBounds() const {
171 SkASSERT(fClipRgn);
172 return fClipRgn->getBounds();
173 }
174 const SkRegion& getRgn() const {
175 SkASSERT(fClipRgn);
176 return *fClipRgn;
177 }
179 SkASSERT(fBlitter);
180 return fBlitter;
181 }
182
183private:
184 SkRegion fBWRgn;
185 SkAAClipBlitter fAABlitter;
186 // what we return
187 const SkRegion* fClipRgn;
188 SkBlitter* fBlitter;
189};
190
191#endif
#define SkASSERT(cond)
Definition SkAssert.h:116
SkClipOp
Definition SkClipOp.h:13
void init(const SkRasterClip &, SkBlitter *)
const SkRegion & getRgn() const
const SkIRect & getBounds() const
SkBlitter * getBlitter()
bool setEmpty()
const SkIRect & getBounds() const
Definition SkAAClip.h:33
bool quickContains(const SkIRect &r) const
Definition SkAAClip.h:56
bool isEmpty() const
Definition SkAAClip.h:32
bool isRect() const
SkAutoRasterClipValidate(const SkRasterClip &rc)
const SkIRect & getBounds() const
const SkAAClip & aaRgn() const
void validate() const
const SkRegion & bwRgn() const
sk_sp< SkShader > clipShader() const
SkRasterClip & operator=(const SkRasterClip &)
void translate(int dx, int dy, SkRasterClip *dst) const
bool quickContains(const SkIRect &rect) const
bool isRect() const
bool isBW() const
bool setRect(const SkIRect &)
bool isEmpty() const
bool op(const SkIRect &, SkClipOp)
bool quickReject(const SkIRect &rect) const
bool isAA() const
bool isComplex() const
bool isComplex() const
Definition SkRegion.h:158
bool isRect() const
Definition SkRegion.h:152
bool quickContains(const SkIRect &r) const
Definition SkRegion.h:310
const SkIRect & getBounds() const
Definition SkRegion.h:165
bool setRect(const SkIRect &rect)
Definition SkRegion.cpp:192
bool isEmpty() const
Definition SkRegion.h:146
static bool Intersects(const SkIRect &a, const SkIRect &b)
Definition SkRect.h:535