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