blob: e39aeeea80383e4769fd2326431bbdad5d31d5eb [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001/*
2 * Copyright 2011 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 */
fmalitac3b589a2014-06-05 12:40:07 -07007
herbb906daf2015-09-29 09:37:59 -07008#include "SkAtomics.h"
fmalitac3b589a2014-06-05 12:40:07 -07009#include "SkCanvas.h"
reed@google.com5c3d1472011-02-22 19:12:23 +000010#include "SkClipStack.h"
11#include "SkPath.h"
fmalita1a481fe2015-02-04 07:39:34 -080012#include "SkPathOps.h"
robertphillips@google.com46f93502012-08-07 15:38:08 +000013
reed@google.com5c3d1472011-02-22 19:12:23 +000014#include <new>
15
robertphillips@google.com607fe072012-07-24 13:54:00 +000016
robertphillips@google.com46f93502012-08-07 15:38:08 +000017// 0-2 are reserved for invalid, empty & wide-open
bsalomon@google.comedb26fd2012-11-28 14:42:41 +000018static const int32_t kFirstUnreservedGenID = 3;
19int32_t SkClipStack::gGenID = kFirstUnreservedGenID;
robertphillips@google.com46f93502012-08-07 15:38:08 +000020
commit-bot@chromium.org6f954b92014-02-27 17:39:46 +000021SkClipStack::Element::Element(const Element& that) {
22 switch (that.getType()) {
23 case kEmpty_Type:
cdaltonb893a4c2016-03-17 12:56:11 -070024 fRRect.setEmpty();
commit-bot@chromium.org6f954b92014-02-27 17:39:46 +000025 fPath.reset();
26 break;
27 case kRect_Type: // Rect uses rrect
28 case kRRect_Type:
29 fPath.reset();
30 fRRect = that.fRRect;
31 break;
32 case kPath_Type:
33 fPath.set(that.getPath());
34 break;
35 }
36
37 fSaveCount = that.fSaveCount;
38 fOp = that.fOp;
39 fType = that.fType;
40 fDoAA = that.fDoAA;
41 fFiniteBoundType = that.fFiniteBoundType;
42 fFiniteBound = that.fFiniteBound;
43 fIsIntersectionOfRects = that.fIsIntersectionOfRects;
44 fGenID = that.fGenID;
45}
46
commit-bot@chromium.orge5b2af92014-02-16 13:25:24 +000047bool SkClipStack::Element::operator== (const Element& element) const {
48 if (this == &element) {
49 return true;
50 }
51 if (fOp != element.fOp ||
52 fType != element.fType ||
53 fDoAA != element.fDoAA ||
54 fSaveCount != element.fSaveCount) {
55 return false;
56 }
57 switch (fType) {
58 case kPath_Type:
commit-bot@chromium.org6f954b92014-02-27 17:39:46 +000059 return this->getPath() == element.getPath();
commit-bot@chromium.orge5b2af92014-02-16 13:25:24 +000060 case kRRect_Type:
61 return fRRect == element.fRRect;
62 case kRect_Type:
commit-bot@chromium.org032a52f2014-02-21 20:09:13 +000063 return this->getRect() == element.getRect();
commit-bot@chromium.orge5b2af92014-02-16 13:25:24 +000064 case kEmpty_Type:
65 return true;
66 default:
67 SkDEBUGFAIL("Unexpected type.");
68 return false;
69 }
70}
71
fmalitac3b589a2014-06-05 12:40:07 -070072void SkClipStack::Element::replay(SkCanvasClipVisitor* visitor) const {
73 static const SkRect kEmptyRect = { 0, 0, 0, 0 };
74
75 switch (fType) {
76 case kPath_Type:
77 visitor->clipPath(this->getPath(), this->getOp(), this->isAA());
78 break;
79 case kRRect_Type:
80 visitor->clipRRect(this->getRRect(), this->getOp(), this->isAA());
81 break;
82 case kRect_Type:
83 visitor->clipRect(this->getRect(), this->getOp(), this->isAA());
84 break;
85 case kEmpty_Type:
86 visitor->clipRect(kEmptyRect, SkRegion::kIntersect_Op, false);
87 break;
88 }
89}
90
bsalomon@google.comc6b3e482012-12-07 20:43:52 +000091void SkClipStack::Element::invertShapeFillType() {
92 switch (fType) {
93 case kRect_Type:
commit-bot@chromium.org6f954b92014-02-27 17:39:46 +000094 fPath.init();
95 fPath.get()->addRect(this->getRect());
96 fPath.get()->setFillType(SkPath::kInverseEvenOdd_FillType);
commit-bot@chromium.orge5b2af92014-02-16 13:25:24 +000097 fType = kPath_Type;
98 break;
99 case kRRect_Type:
commit-bot@chromium.org6f954b92014-02-27 17:39:46 +0000100 fPath.init();
101 fPath.get()->addRRect(fRRect);
102 fPath.get()->setFillType(SkPath::kInverseEvenOdd_FillType);
bsalomon@google.comc6b3e482012-12-07 20:43:52 +0000103 fType = kPath_Type;
104 break;
105 case kPath_Type:
commit-bot@chromium.org6f954b92014-02-27 17:39:46 +0000106 fPath.get()->toggleInverseFillType();
commit-bot@chromium.orge5b2af92014-02-16 13:25:24 +0000107 break;
bsalomon@google.comc6b3e482012-12-07 20:43:52 +0000108 case kEmpty_Type:
commit-bot@chromium.orge5b2af92014-02-16 13:25:24 +0000109 // Should this set to an empty, inverse filled path?
110 break;
111 }
112}
113
114void SkClipStack::Element::initPath(int saveCount, const SkPath& path, SkRegion::Op op,
115 bool doAA) {
116 if (!path.isInverseFillType()) {
robertphillips2b6ab612015-01-05 12:22:14 -0800117 SkRect r;
118 if (path.isRect(&r)) {
119 this->initRect(saveCount, r, op, doAA);
commit-bot@chromium.orge5b2af92014-02-16 13:25:24 +0000120 return;
121 }
122 SkRect ovalRect;
123 if (path.isOval(&ovalRect)) {
124 SkRRect rrect;
125 rrect.setOval(ovalRect);
126 this->initRRect(saveCount, rrect, op, doAA);
127 return;
128 }
129 }
commit-bot@chromium.org6f954b92014-02-27 17:39:46 +0000130 fPath.set(path);
jvanverth0deb2d92014-10-24 12:41:32 -0700131 fPath.get()->setIsVolatile(true);
commit-bot@chromium.orge5b2af92014-02-16 13:25:24 +0000132 fType = kPath_Type;
133 this->initCommon(saveCount, op, doAA);
134}
135
136void SkClipStack::Element::asPath(SkPath* path) const {
137 switch (fType) {
138 case kEmpty_Type:
139 path->reset();
robertphillips4d8762f8b2015-10-26 14:37:03 -0700140 path->setIsVolatile(true);
commit-bot@chromium.orge5b2af92014-02-16 13:25:24 +0000141 break;
142 case kRect_Type:
143 path->reset();
commit-bot@chromium.org032a52f2014-02-21 20:09:13 +0000144 path->addRect(this->getRect());
robertphillips4d8762f8b2015-10-26 14:37:03 -0700145 path->setIsVolatile(true);
commit-bot@chromium.orge5b2af92014-02-16 13:25:24 +0000146 break;
147 case kRRect_Type:
148 path->reset();
149 path->addRRect(fRRect);
robertphillips4d8762f8b2015-10-26 14:37:03 -0700150 path->setIsVolatile(true);
commit-bot@chromium.orge5b2af92014-02-16 13:25:24 +0000151 break;
152 case kPath_Type:
commit-bot@chromium.org6f954b92014-02-27 17:39:46 +0000153 *path = *fPath.get();
bsalomon@google.comc6b3e482012-12-07 20:43:52 +0000154 break;
155 }
jvanverth0deb2d92014-10-24 12:41:32 -0700156 path->setIsVolatile(true);
bsalomon@google.comc6b3e482012-12-07 20:43:52 +0000157}
158
commit-bot@chromium.org9cb671a2014-02-16 14:45:45 +0000159void SkClipStack::Element::setEmpty() {
160 fType = kEmpty_Type;
161 fFiniteBound.setEmpty();
162 fFiniteBoundType = kNormal_BoundsType;
163 fIsIntersectionOfRects = false;
commit-bot@chromium.org9cb671a2014-02-16 14:45:45 +0000164 fRRect.setEmpty();
165 fPath.reset();
166 fGenID = kEmptyGenID;
167 SkDEBUGCODE(this->checkEmpty();)
168}
169
bsalomon@google.com8a98e3b2012-11-29 21:05:13 +0000170void SkClipStack::Element::checkEmpty() const {
171 SkASSERT(fFiniteBound.isEmpty());
172 SkASSERT(kNormal_BoundsType == fFiniteBoundType);
173 SkASSERT(!fIsIntersectionOfRects);
174 SkASSERT(kEmptyGenID == fGenID);
cdaltonb893a4c2016-03-17 12:56:11 -0700175 SkASSERT(fRRect.isEmpty());
commit-bot@chromium.org6f954b92014-02-27 17:39:46 +0000176 SkASSERT(!fPath.isValid());
bsalomon@google.com8a98e3b2012-11-29 21:05:13 +0000177}
reed@google.com5c3d1472011-02-22 19:12:23 +0000178
bsalomon@google.com8a98e3b2012-11-29 21:05:13 +0000179bool SkClipStack::Element::canBeIntersectedInPlace(int saveCount, SkRegion::Op op) const {
180 if (kEmpty_Type == fType &&
181 (SkRegion::kDifference_Op == op || SkRegion::kIntersect_Op == op)) {
182 return true;
183 }
184 // Only clips within the same save/restore frame (as captured by
185 // the save count) can be merged
186 return fSaveCount == saveCount &&
187 SkRegion::kIntersect_Op == op &&
188 (SkRegion::kIntersect_Op == fOp || SkRegion::kReplace_Op == fOp);
189}
robertphillips@google.com607fe072012-07-24 13:54:00 +0000190
bsalomon@google.com8a98e3b2012-11-29 21:05:13 +0000191bool SkClipStack::Element::rectRectIntersectAllowed(const SkRect& newR, bool newAA) const {
192 SkASSERT(kRect_Type == fType);
193
194 if (fDoAA == newAA) {
195 // if the AA setting is the same there is no issue
196 return true;
robertphillips@google.com607fe072012-07-24 13:54:00 +0000197 }
198
commit-bot@chromium.org032a52f2014-02-21 20:09:13 +0000199 if (!SkRect::Intersects(this->getRect(), newR)) {
bsalomon@google.com8a98e3b2012-11-29 21:05:13 +0000200 // The calling code will correctly set the result to the empty clip
201 return true;
robertphillips@google.com607fe072012-07-24 13:54:00 +0000202 }
203
commit-bot@chromium.org032a52f2014-02-21 20:09:13 +0000204 if (this->getRect().contains(newR)) {
bsalomon@google.com8a98e3b2012-11-29 21:05:13 +0000205 // if the new rect carves out a portion of the old one there is no
206 // issue
207 return true;
robertphillips@google.com607fe072012-07-24 13:54:00 +0000208 }
209
bsalomon@google.com8a98e3b2012-11-29 21:05:13 +0000210 // So either the two overlap in some complex manner or newR contains oldR.
211 // In the first, case the edges will require different AA. In the second,
212 // the AA setting that would be carried forward is incorrect (e.g., oldR
213 // is AA while newR is BW but since newR contains oldR, oldR will be
214 // drawn BW) since the new AA setting will predominate.
215 return false;
216}
robertphillips@google.com607fe072012-07-24 13:54:00 +0000217
bsalomon@google.com8a98e3b2012-11-29 21:05:13 +0000218// a mirror of combineBoundsRevDiff
219void SkClipStack::Element::combineBoundsDiff(FillCombo combination, const SkRect& prevFinite) {
220 switch (combination) {
221 case kInvPrev_InvCur_FillCombo:
222 // In this case the only pixels that can remain set
223 // are inside the current clip rect since the extensions
224 // to infinity of both clips cancel out and whatever
225 // is outside of the current clip is removed
robertphillips@google.com607fe072012-07-24 13:54:00 +0000226 fFiniteBoundType = kNormal_BoundsType;
bsalomon@google.com8a98e3b2012-11-29 21:05:13 +0000227 break;
228 case kInvPrev_Cur_FillCombo:
229 // In this case the current op is finite so the only pixels
230 // that aren't set are whatever isn't set in the previous
231 // clip and whatever this clip carves out
232 fFiniteBound.join(prevFinite);
233 fFiniteBoundType = kInsideOut_BoundsType;
234 break;
235 case kPrev_InvCur_FillCombo:
236 // In this case everything outside of this clip's bound
237 // is erased, so the only pixels that can remain set
238 // occur w/in the intersection of the two finite bounds
239 if (!fFiniteBound.intersect(prevFinite)) {
commit-bot@chromium.orge5b2af92014-02-16 13:25:24 +0000240 this->setEmpty();
241 } else {
242 fFiniteBoundType = kNormal_BoundsType;
robertphillips@google.com4c2a2f72012-07-24 22:07:50 +0000243 }
bsalomon@google.com8a98e3b2012-11-29 21:05:13 +0000244 break;
245 case kPrev_Cur_FillCombo:
246 // The most conservative result bound is that of the
247 // prior clip. This could be wildly incorrect if the
248 // second clip either exactly matches the first clip
249 // (which should yield the empty set) or reduces the
250 // size of the prior bound (e.g., if the second clip
251 // exactly matched the bottom half of the prior clip).
252 // We ignore these two possibilities.
253 fFiniteBound = prevFinite;
254 break;
255 default:
256 SkDEBUGFAIL("SkClipStack::Element::combineBoundsDiff Invalid fill combination");
257 break;
258 }
259}
robertphillips@google.com4c2a2f72012-07-24 22:07:50 +0000260
bsalomon@google.com8a98e3b2012-11-29 21:05:13 +0000261void SkClipStack::Element::combineBoundsXOR(int combination, const SkRect& prevFinite) {
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000262
bsalomon@google.com8a98e3b2012-11-29 21:05:13 +0000263 switch (combination) {
264 case kInvPrev_Cur_FillCombo: // fall through
265 case kPrev_InvCur_FillCombo:
266 // With only one of the clips inverted the result will always
267 // extend to infinity. The only pixels that may be un-writeable
268 // lie within the union of the two finite bounds
269 fFiniteBound.join(prevFinite);
270 fFiniteBoundType = kInsideOut_BoundsType;
271 break;
272 case kInvPrev_InvCur_FillCombo:
273 // The only pixels that can survive are within the
274 // union of the two bounding boxes since the extensions
275 // to infinity of both clips cancel out
276 // fall through!
277 case kPrev_Cur_FillCombo:
278 // The most conservative bound for xor is the
279 // union of the two bounds. If the two clips exactly overlapped
280 // the xor could yield the empty set. Similarly the xor
281 // could reduce the size of the original clip's bound (e.g.,
282 // if the second clip exactly matched the bottom half of the
283 // first clip). We ignore these two cases.
284 fFiniteBound.join(prevFinite);
285 fFiniteBoundType = kNormal_BoundsType;
286 break;
287 default:
288 SkDEBUGFAIL("SkClipStack::Element::combineBoundsXOR Invalid fill combination");
289 break;
290 }
291}
robertphillips@google.com607fe072012-07-24 13:54:00 +0000292
bsalomon@google.com8a98e3b2012-11-29 21:05:13 +0000293// a mirror of combineBoundsIntersection
294void SkClipStack::Element::combineBoundsUnion(int combination, const SkRect& prevFinite) {
295
296 switch (combination) {
297 case kInvPrev_InvCur_FillCombo:
298 if (!fFiniteBound.intersect(prevFinite)) {
299 fFiniteBound.setEmpty();
300 fGenID = kWideOpenGenID;
robertphillips@google.com607fe072012-07-24 13:54:00 +0000301 }
bsalomon@google.com8a98e3b2012-11-29 21:05:13 +0000302 fFiniteBoundType = kInsideOut_BoundsType;
303 break;
304 case kInvPrev_Cur_FillCombo:
305 // The only pixels that won't be drawable are inside
306 // the prior clip's finite bound
307 fFiniteBound = prevFinite;
308 fFiniteBoundType = kInsideOut_BoundsType;
309 break;
310 case kPrev_InvCur_FillCombo:
311 // The only pixels that won't be drawable are inside
312 // this clip's finite bound
313 break;
314 case kPrev_Cur_FillCombo:
315 fFiniteBound.join(prevFinite);
316 break;
317 default:
318 SkDEBUGFAIL("SkClipStack::Element::combineBoundsUnion Invalid fill combination");
319 break;
320 }
321}
322
323// a mirror of combineBoundsUnion
324void SkClipStack::Element::combineBoundsIntersection(int combination, const SkRect& prevFinite) {
325
326 switch (combination) {
327 case kInvPrev_InvCur_FillCombo:
328 // The only pixels that aren't writable in this case
329 // occur in the union of the two finite bounds
330 fFiniteBound.join(prevFinite);
331 fFiniteBoundType = kInsideOut_BoundsType;
332 break;
333 case kInvPrev_Cur_FillCombo:
334 // In this case the only pixels that will remain writeable
335 // are within the current clip
336 break;
337 case kPrev_InvCur_FillCombo:
338 // In this case the only pixels that will remain writeable
339 // are with the previous clip
340 fFiniteBound = prevFinite;
341 fFiniteBoundType = kNormal_BoundsType;
342 break;
343 case kPrev_Cur_FillCombo:
344 if (!fFiniteBound.intersect(prevFinite)) {
commit-bot@chromium.orge5b2af92014-02-16 13:25:24 +0000345 this->setEmpty();
bsalomon@google.com8a98e3b2012-11-29 21:05:13 +0000346 }
347 break;
348 default:
349 SkDEBUGFAIL("SkClipStack::Element::combineBoundsIntersection Invalid fill combination");
350 break;
351 }
352}
353
354// a mirror of combineBoundsDiff
355void SkClipStack::Element::combineBoundsRevDiff(int combination, const SkRect& prevFinite) {
356
357 switch (combination) {
358 case kInvPrev_InvCur_FillCombo:
359 // The only pixels that can survive are in the
360 // previous bound since the extensions to infinity in
361 // both clips cancel out
362 fFiniteBound = prevFinite;
363 fFiniteBoundType = kNormal_BoundsType;
364 break;
365 case kInvPrev_Cur_FillCombo:
366 if (!fFiniteBound.intersect(prevFinite)) {
commit-bot@chromium.orge5b2af92014-02-16 13:25:24 +0000367 this->setEmpty();
368 } else {
369 fFiniteBoundType = kNormal_BoundsType;
bsalomon@google.com8a98e3b2012-11-29 21:05:13 +0000370 }
bsalomon@google.com8a98e3b2012-11-29 21:05:13 +0000371 break;
372 case kPrev_InvCur_FillCombo:
373 fFiniteBound.join(prevFinite);
374 fFiniteBoundType = kInsideOut_BoundsType;
375 break;
376 case kPrev_Cur_FillCombo:
377 // Fall through - as with the kDifference_Op case, the
378 // most conservative result bound is the bound of the
379 // current clip. The prior clip could reduce the size of this
380 // bound (as in the kDifference_Op case) but we are ignoring
381 // those cases.
382 break;
383 default:
384 SkDEBUGFAIL("SkClipStack::Element::combineBoundsRevDiff Invalid fill combination");
385 break;
386 }
387}
388
389void SkClipStack::Element::updateBoundAndGenID(const Element* prior) {
390 // We set this first here but we may overwrite it later if we determine that the clip is
391 // either wide-open or empty.
392 fGenID = GetNextGenID();
393
394 // First, optimistically update the current Element's bound information
395 // with the current clip's bound
396 fIsIntersectionOfRects = false;
commit-bot@chromium.orge5b2af92014-02-16 13:25:24 +0000397 switch (fType) {
398 case kRect_Type:
commit-bot@chromium.org032a52f2014-02-21 20:09:13 +0000399 fFiniteBound = this->getRect();
bsalomon@google.com8a98e3b2012-11-29 21:05:13 +0000400 fFiniteBoundType = kNormal_BoundsType;
commit-bot@chromium.orge5b2af92014-02-16 13:25:24 +0000401
402 if (SkRegion::kReplace_Op == fOp ||
halcanary96fcdcc2015-08-27 07:41:13 -0700403 (SkRegion::kIntersect_Op == fOp && nullptr == prior) ||
commit-bot@chromium.orge5b2af92014-02-16 13:25:24 +0000404 (SkRegion::kIntersect_Op == fOp && prior->fIsIntersectionOfRects &&
commit-bot@chromium.org032a52f2014-02-21 20:09:13 +0000405 prior->rectRectIntersectAllowed(this->getRect(), fDoAA))) {
commit-bot@chromium.orge5b2af92014-02-16 13:25:24 +0000406 fIsIntersectionOfRects = true;
407 }
408 break;
409 case kRRect_Type:
410 fFiniteBound = fRRect.getBounds();
411 fFiniteBoundType = kNormal_BoundsType;
412 break;
413 case kPath_Type:
commit-bot@chromium.org6f954b92014-02-27 17:39:46 +0000414 fFiniteBound = fPath.get()->getBounds();
commit-bot@chromium.orge5b2af92014-02-16 13:25:24 +0000415
commit-bot@chromium.org6f954b92014-02-27 17:39:46 +0000416 if (fPath.get()->isInverseFillType()) {
commit-bot@chromium.orge5b2af92014-02-16 13:25:24 +0000417 fFiniteBoundType = kInsideOut_BoundsType;
418 } else {
419 fFiniteBoundType = kNormal_BoundsType;
420 }
421 break;
422 case kEmpty_Type:
423 SkDEBUGFAIL("We shouldn't get here with an empty element.");
424 break;
robertphillips@google.com607fe072012-07-24 13:54:00 +0000425 }
bsalomon@google.com8a98e3b2012-11-29 21:05:13 +0000426
robertphillipsff420212015-03-30 08:09:58 -0700427 if (!fDoAA) {
428 fFiniteBound.set(SkScalarFloorToScalar(fFiniteBound.fLeft+0.45f),
429 SkScalarRoundToScalar(fFiniteBound.fTop),
430 SkScalarRoundToScalar(fFiniteBound.fRight),
431 SkScalarRoundToScalar(fFiniteBound.fBottom));
432 }
433
bsalomon@google.com8a98e3b2012-11-29 21:05:13 +0000434 // Now determine the previous Element's bound information taking into
435 // account that there may be no previous clip
436 SkRect prevFinite;
437 SkClipStack::BoundsType prevType;
438
halcanary96fcdcc2015-08-27 07:41:13 -0700439 if (nullptr == prior) {
bsalomon@google.com8a98e3b2012-11-29 21:05:13 +0000440 // no prior clip means the entire plane is writable
441 prevFinite.setEmpty(); // there are no pixels that cannot be drawn to
442 prevType = kInsideOut_BoundsType;
443 } else {
444 prevFinite = prior->fFiniteBound;
445 prevType = prior->fFiniteBoundType;
446 }
447
448 FillCombo combination = kPrev_Cur_FillCombo;
449 if (kInsideOut_BoundsType == fFiniteBoundType) {
450 combination = (FillCombo) (combination | 0x01);
451 }
452 if (kInsideOut_BoundsType == prevType) {
453 combination = (FillCombo) (combination | 0x02);
454 }
455
456 SkASSERT(kInvPrev_InvCur_FillCombo == combination ||
457 kInvPrev_Cur_FillCombo == combination ||
458 kPrev_InvCur_FillCombo == combination ||
459 kPrev_Cur_FillCombo == combination);
460
461 // Now integrate with clip with the prior clips
462 switch (fOp) {
463 case SkRegion::kDifference_Op:
464 this->combineBoundsDiff(combination, prevFinite);
465 break;
466 case SkRegion::kXOR_Op:
467 this->combineBoundsXOR(combination, prevFinite);
468 break;
469 case SkRegion::kUnion_Op:
470 this->combineBoundsUnion(combination, prevFinite);
471 break;
472 case SkRegion::kIntersect_Op:
473 this->combineBoundsIntersection(combination, prevFinite);
474 break;
475 case SkRegion::kReverseDifference_Op:
476 this->combineBoundsRevDiff(combination, prevFinite);
477 break;
478 case SkRegion::kReplace_Op:
479 // Replace just ignores everything prior
480 // The current clip's bound information is already filled in
481 // so nothing to do
482 break;
483 default:
commit-bot@chromium.orge5b2af92014-02-16 13:25:24 +0000484 SkDebugf("SkRegion::Op error\n");
bsalomon@google.com8a98e3b2012-11-29 21:05:13 +0000485 SkASSERT(0);
486 break;
487 }
488}
reed@google.com5c3d1472011-02-22 19:12:23 +0000489
bsalomon@google.com9128edc2012-11-29 18:58:19 +0000490// This constant determines how many Element's are allocated together as a block in
robertphillips@google.comf9a90842012-08-17 14:25:43 +0000491// the deque. As such it needs to balance allocating too much memory vs.
492// incurring allocation/deallocation thrashing. It should roughly correspond to
493// the deepest save/restore stack we expect to see.
bsalomon@google.com9128edc2012-11-29 18:58:19 +0000494static const int kDefaultElementAllocCnt = 8;
robertphillips@google.com46f93502012-08-07 15:38:08 +0000495
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000496SkClipStack::SkClipStack()
bsalomon@google.com9128edc2012-11-29 18:58:19 +0000497 : fDeque(sizeof(Element), kDefaultElementAllocCnt)
robertphillips@google.com46f93502012-08-07 15:38:08 +0000498 , fSaveCount(0) {
reed@google.com5c3d1472011-02-22 19:12:23 +0000499}
500
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000501SkClipStack::SkClipStack(const SkClipStack& b)
bsalomon@google.com9128edc2012-11-29 18:58:19 +0000502 : fDeque(sizeof(Element), kDefaultElementAllocCnt) {
vandebo@chromium.org1e1c36f2011-05-03 16:26:09 +0000503 *this = b;
504}
505
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000506SkClipStack::SkClipStack(const SkRect& r)
bsalomon@google.com9128edc2012-11-29 18:58:19 +0000507 : fDeque(sizeof(Element), kDefaultElementAllocCnt)
robertphillips@google.com46f93502012-08-07 15:38:08 +0000508 , fSaveCount(0) {
robertphillips@google.comcc6493b2012-07-26 18:39:13 +0000509 if (!r.isEmpty()) {
510 this->clipDevRect(r, SkRegion::kReplace_Op, false);
511 }
512}
513
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000514SkClipStack::SkClipStack(const SkIRect& r)
bsalomon@google.com9128edc2012-11-29 18:58:19 +0000515 : fDeque(sizeof(Element), kDefaultElementAllocCnt)
robertphillips@google.com46f93502012-08-07 15:38:08 +0000516 , fSaveCount(0) {
robertphillips@google.com641f8b12012-07-31 19:15:58 +0000517 if (!r.isEmpty()) {
518 SkRect temp;
519 temp.set(r);
520 this->clipDevRect(temp, SkRegion::kReplace_Op, false);
521 }
522}
523
vandebo@chromium.org610f7162012-03-14 18:34:15 +0000524SkClipStack::~SkClipStack() {
525 reset();
526}
527
vandebo@chromium.org1e1c36f2011-05-03 16:26:09 +0000528SkClipStack& SkClipStack::operator=(const SkClipStack& b) {
529 if (this == &b) {
530 return *this;
531 }
532 reset();
533
534 fSaveCount = b.fSaveCount;
535 SkDeque::F2BIter recIter(b.fDeque);
bsalomon@google.com9128edc2012-11-29 18:58:19 +0000536 for (const Element* element = (const Element*)recIter.next();
halcanary96fcdcc2015-08-27 07:41:13 -0700537 element != nullptr;
bsalomon@google.com9128edc2012-11-29 18:58:19 +0000538 element = (const Element*)recIter.next()) {
539 new (fDeque.push_back()) Element(*element);
vandebo@chromium.org1e1c36f2011-05-03 16:26:09 +0000540 }
541
542 return *this;
543}
544
545bool SkClipStack::operator==(const SkClipStack& b) const {
commit-bot@chromium.org86b39f32014-01-06 16:54:20 +0000546 if (this->getTopmostGenID() == b.getTopmostGenID()) {
547 return true;
548 }
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000549 if (fSaveCount != b.fSaveCount ||
robertphillips@google.com46f93502012-08-07 15:38:08 +0000550 fDeque.count() != b.fDeque.count()) {
vandebo@chromium.org1e1c36f2011-05-03 16:26:09 +0000551 return false;
552 }
553 SkDeque::F2BIter myIter(fDeque);
554 SkDeque::F2BIter bIter(b.fDeque);
bsalomon@google.com9128edc2012-11-29 18:58:19 +0000555 const Element* myElement = (const Element*)myIter.next();
556 const Element* bElement = (const Element*)bIter.next();
vandebo@chromium.org1e1c36f2011-05-03 16:26:09 +0000557
halcanary96fcdcc2015-08-27 07:41:13 -0700558 while (myElement != nullptr && bElement != nullptr) {
bsalomon@google.com9128edc2012-11-29 18:58:19 +0000559 if (*myElement != *bElement) {
vandebo@chromium.org1e1c36f2011-05-03 16:26:09 +0000560 return false;
561 }
bsalomon@google.com9128edc2012-11-29 18:58:19 +0000562 myElement = (const Element*)myIter.next();
563 bElement = (const Element*)bIter.next();
vandebo@chromium.org1e1c36f2011-05-03 16:26:09 +0000564 }
halcanary96fcdcc2015-08-27 07:41:13 -0700565 return myElement == nullptr && bElement == nullptr;
vandebo@chromium.org1e1c36f2011-05-03 16:26:09 +0000566}
567
reed@google.com5c3d1472011-02-22 19:12:23 +0000568void SkClipStack::reset() {
vandebo@chromium.org610f7162012-03-14 18:34:15 +0000569 // We used a placement new for each object in fDeque, so we're responsible
570 // for calling the destructor on each of them as well.
571 while (!fDeque.empty()) {
bsalomon@google.com9128edc2012-11-29 18:58:19 +0000572 Element* element = (Element*)fDeque.back();
573 element->~Element();
vandebo@chromium.org610f7162012-03-14 18:34:15 +0000574 fDeque.pop_back();
575 }
reed@google.com5c3d1472011-02-22 19:12:23 +0000576
577 fSaveCount = 0;
578}
579
580void SkClipStack::save() {
581 fSaveCount += 1;
582}
583
584void SkClipStack::restore() {
585 fSaveCount -= 1;
commit-bot@chromium.org6fbe54c2013-06-11 11:01:48 +0000586 restoreTo(fSaveCount);
587}
588
589void SkClipStack::restoreTo(int saveCount) {
reed@google.com5c3d1472011-02-22 19:12:23 +0000590 while (!fDeque.empty()) {
bsalomon@google.com9128edc2012-11-29 18:58:19 +0000591 Element* element = (Element*)fDeque.back();
commit-bot@chromium.org6fbe54c2013-06-11 11:01:48 +0000592 if (element->fSaveCount <= saveCount) {
reed@google.com5c3d1472011-02-22 19:12:23 +0000593 break;
594 }
bsalomon@google.com9128edc2012-11-29 18:58:19 +0000595 element->~Element();
reed@google.com5c3d1472011-02-22 19:12:23 +0000596 fDeque.pop_back();
597 }
598}
599
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000600void SkClipStack::getBounds(SkRect* canvFiniteBound,
robertphillips@google.com4c2a2f72012-07-24 22:07:50 +0000601 BoundsType* boundType,
602 bool* isIntersectionOfRects) const {
bsalomon49f085d2014-09-05 13:34:00 -0700603 SkASSERT(canvFiniteBound && boundType);
robertphillips@google.com607fe072012-07-24 13:54:00 +0000604
bsalomon@google.com9128edc2012-11-29 18:58:19 +0000605 Element* element = (Element*)fDeque.back();
robertphillips@google.com607fe072012-07-24 13:54:00 +0000606
halcanary96fcdcc2015-08-27 07:41:13 -0700607 if (nullptr == element) {
robertphillips@google.com607fe072012-07-24 13:54:00 +0000608 // the clip is wide open - the infinite plane w/ no pixels un-writeable
robertphillips@google.com7b112892012-07-31 15:18:21 +0000609 canvFiniteBound->setEmpty();
robertphillips@google.com607fe072012-07-24 13:54:00 +0000610 *boundType = kInsideOut_BoundsType;
bsalomon49f085d2014-09-05 13:34:00 -0700611 if (isIntersectionOfRects) {
robertphillips@google.com4c2a2f72012-07-24 22:07:50 +0000612 *isIntersectionOfRects = false;
613 }
robertphillips@google.com607fe072012-07-24 13:54:00 +0000614 return;
615 }
616
bsalomon@google.com9128edc2012-11-29 18:58:19 +0000617 *canvFiniteBound = element->fFiniteBound;
618 *boundType = element->fFiniteBoundType;
bsalomon49f085d2014-09-05 13:34:00 -0700619 if (isIntersectionOfRects) {
bsalomon@google.com9128edc2012-11-29 18:58:19 +0000620 *isIntersectionOfRects = element->fIsIntersectionOfRects;
robertphillips@google.com4c2a2f72012-07-24 22:07:50 +0000621 }
robertphillips@google.com607fe072012-07-24 13:54:00 +0000622}
623
junov@chromium.org8cdf0f52012-12-12 17:58:15 +0000624bool SkClipStack::quickContains(const SkRect& rect) const {
625
626 Iter iter(*this, Iter::kTop_IterStart);
627 const Element* element = iter.prev();
halcanary96fcdcc2015-08-27 07:41:13 -0700628 while (element != nullptr) {
junov@chromium.org8cdf0f52012-12-12 17:58:15 +0000629 if (SkRegion::kIntersect_Op != element->getOp() && SkRegion::kReplace_Op != element->getOp())
630 return false;
631 if (element->isInverseFilled()) {
632 // Part of 'rect' could be trimmed off by the inverse-filled clip element
633 if (SkRect::Intersects(element->getBounds(), rect)) {
634 return false;
635 }
636 } else {
637 if (!element->contains(rect)) {
638 return false;
639 }
640 }
641 if (SkRegion::kReplace_Op == element->getOp()) {
642 break;
643 }
644 element = iter.prev();
645 }
646 return true;
647}
648
fmalita1a481fe2015-02-04 07:39:34 -0800649bool SkClipStack::asPath(SkPath *path) const {
650 bool isAA = false;
651
652 path->reset();
653 path->setFillType(SkPath::kInverseEvenOdd_FillType);
654
655 SkClipStack::Iter iter(*this, SkClipStack::Iter::kBottom_IterStart);
656 while (const SkClipStack::Element* element = iter.next()) {
657 SkPath operand;
658 if (element->getType() != SkClipStack::Element::kEmpty_Type) {
659 element->asPath(&operand);
660 }
661
662 SkRegion::Op elementOp = element->getOp();
663 if (elementOp == SkRegion::kReplace_Op) {
664 *path = operand;
665 } else {
666 Op(*path, operand, (SkPathOp)elementOp, path);
667 }
668
669 // if the prev and curr clips disagree about aa -vs- not, favor the aa request.
670 // perhaps we need an API change to avoid this sort of mixed-signals about
671 // clipping.
672 isAA = (isAA || element->isAA());
673 }
674
675 return isAA;
676}
677
commit-bot@chromium.orge5b2af92014-02-16 13:25:24 +0000678void SkClipStack::pushElement(const Element& element) {
robertphillips@google.com63ae1cf2012-08-17 13:53:05 +0000679 // Use reverse iterator instead of back because Rect path may need previous
robertphillips@google.com4c2a2f72012-07-24 22:07:50 +0000680 SkDeque::Iter iter(fDeque, SkDeque::Iter::kBack_IterStart);
commit-bot@chromium.orge5b2af92014-02-16 13:25:24 +0000681 Element* prior = (Element*) iter.prev();
robertphillips@google.com4c2a2f72012-07-24 22:07:50 +0000682
bsalomon49f085d2014-09-05 13:34:00 -0700683 if (prior) {
commit-bot@chromium.orge5b2af92014-02-16 13:25:24 +0000684 if (prior->canBeIntersectedInPlace(fSaveCount, element.getOp())) {
685 switch (prior->fType) {
commit-bot@chromium.org6fbe54c2013-06-11 11:01:48 +0000686 case Element::kEmpty_Type:
commit-bot@chromium.orge5b2af92014-02-16 13:25:24 +0000687 SkDEBUGCODE(prior->checkEmpty();)
commit-bot@chromium.org6fbe54c2013-06-11 11:01:48 +0000688 return;
689 case Element::kRect_Type:
commit-bot@chromium.orge5b2af92014-02-16 13:25:24 +0000690 if (Element::kRect_Type == element.getType()) {
691 if (prior->rectRectIntersectAllowed(element.getRect(), element.isAA())) {
commit-bot@chromium.org032a52f2014-02-21 20:09:13 +0000692 SkRect isectRect;
693 if (!isectRect.intersect(prior->getRect(), element.getRect())) {
commit-bot@chromium.orge5b2af92014-02-16 13:25:24 +0000694 prior->setEmpty();
695 return;
696 }
697
commit-bot@chromium.org032a52f2014-02-21 20:09:13 +0000698 prior->fRRect.setRect(isectRect);
commit-bot@chromium.orge5b2af92014-02-16 13:25:24 +0000699 prior->fDoAA = element.isAA();
700 Element* priorPrior = (Element*) iter.prev();
701 prior->updateBoundAndGenID(priorPrior);
commit-bot@chromium.org6fbe54c2013-06-11 11:01:48 +0000702 return;
703 }
commit-bot@chromium.orge5b2af92014-02-16 13:25:24 +0000704 break;
commit-bot@chromium.org6fbe54c2013-06-11 11:01:48 +0000705 }
commit-bot@chromium.orge5b2af92014-02-16 13:25:24 +0000706 // fallthrough
707 default:
708 if (!SkRect::Intersects(prior->getBounds(), element.getBounds())) {
709 prior->setEmpty();
robertphillips@google.com08eacc12012-08-02 12:49:00 +0000710 return;
711 }
commit-bot@chromium.org6fbe54c2013-06-11 11:01:48 +0000712 break;
713 }
commit-bot@chromium.orge5b2af92014-02-16 13:25:24 +0000714 } else if (SkRegion::kReplace_Op == element.getOp()) {
commit-bot@chromium.org6fbe54c2013-06-11 11:01:48 +0000715 this->restoreTo(fSaveCount - 1);
commit-bot@chromium.orge5b2af92014-02-16 13:25:24 +0000716 prior = (Element*) fDeque.back();
reed@google.com5c3d1472011-02-22 19:12:23 +0000717 }
718 }
halcanary385fe4d2015-08-26 13:07:48 -0700719 Element* newElement = new (fDeque.push_back()) Element(element);
commit-bot@chromium.orge5b2af92014-02-16 13:25:24 +0000720 newElement->updateBoundAndGenID(prior);
721}
722
723void SkClipStack::clipDevRRect(const SkRRect& rrect, SkRegion::Op op, bool doAA) {
724 Element element(fSaveCount, rrect, op, doAA);
725 this->pushElement(element);
726}
727
728void SkClipStack::clipDevRect(const SkRect& rect, SkRegion::Op op, bool doAA) {
729 Element element(fSaveCount, rect, op, doAA);
730 this->pushElement(element);
reed@google.com5c3d1472011-02-22 19:12:23 +0000731}
732
reed@google.com00177082011-10-12 14:34:30 +0000733void SkClipStack::clipDevPath(const SkPath& path, SkRegion::Op op, bool doAA) {
commit-bot@chromium.orge5b2af92014-02-16 13:25:24 +0000734 Element element(fSaveCount, path, op, doAA);
735 this->pushElement(element);
reed@google.com5c3d1472011-02-22 19:12:23 +0000736}
737
reed@google.com0557d9e2012-08-16 15:59:59 +0000738void SkClipStack::clipEmpty() {
bsalomon@google.com9128edc2012-11-29 18:58:19 +0000739 Element* element = (Element*) fDeque.back();
robertphillips@google.com63ae1cf2012-08-17 13:53:05 +0000740
bsalomon@google.com9128edc2012-11-29 18:58:19 +0000741 if (element && element->canBeIntersectedInPlace(fSaveCount, SkRegion::kIntersect_Op)) {
commit-bot@chromium.orge5b2af92014-02-16 13:25:24 +0000742 element->setEmpty();
reed@google.com0557d9e2012-08-16 15:59:59 +0000743 }
bsalomon@google.com9128edc2012-11-29 18:58:19 +0000744 new (fDeque.push_back()) Element(fSaveCount);
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000745
bsalomon@google.com9128edc2012-11-29 18:58:19 +0000746 ((Element*)fDeque.back())->fGenID = kEmptyGenID;
reed@google.com0557d9e2012-08-16 15:59:59 +0000747}
748
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000749bool SkClipStack::isWideOpen() const {
commit-bot@chromium.orgd3e58422013-11-05 15:03:08 +0000750 return this->getTopmostGenID() == kWideOpenGenID;
robertphillips@google.comcc6493b2012-07-26 18:39:13 +0000751}
752
reed@google.com5c3d1472011-02-22 19:12:23 +0000753///////////////////////////////////////////////////////////////////////////////
754
halcanary96fcdcc2015-08-27 07:41:13 -0700755SkClipStack::Iter::Iter() : fStack(nullptr) {
bsalomon@google.comd302f142011-03-03 13:54:13 +0000756}
757
robertphillips@google.com5836b6d2012-07-18 12:06:15 +0000758SkClipStack::Iter::Iter(const SkClipStack& stack, IterStart startLoc)
759 : fStack(&stack) {
robertphillips@google.com52cb2c72012-07-16 18:52:29 +0000760 this->reset(stack, startLoc);
reed@google.com5c3d1472011-02-22 19:12:23 +0000761}
762
bsalomon@google.com8182fa02012-12-04 14:06:06 +0000763const SkClipStack::Element* SkClipStack::Iter::next() {
764 return (const SkClipStack::Element*)fIter.next();
reed@google.com5c3d1472011-02-22 19:12:23 +0000765}
bsalomon@google.comd302f142011-03-03 13:54:13 +0000766
bsalomon@google.com8182fa02012-12-04 14:06:06 +0000767const SkClipStack::Element* SkClipStack::Iter::prev() {
768 return (const SkClipStack::Element*)fIter.prev();
robertphillips@google.com52cb2c72012-07-16 18:52:29 +0000769}
770
bsalomon@google.com8182fa02012-12-04 14:06:06 +0000771const SkClipStack::Element* SkClipStack::Iter::skipToTopmost(SkRegion::Op op) {
robertphillips@google.com5836b6d2012-07-18 12:06:15 +0000772
halcanary96fcdcc2015-08-27 07:41:13 -0700773 if (nullptr == fStack) {
774 return nullptr;
robertphillips@google.com5836b6d2012-07-18 12:06:15 +0000775 }
776
777 fIter.reset(fStack->fDeque, SkDeque::Iter::kBack_IterStart);
778
halcanary96fcdcc2015-08-27 07:41:13 -0700779 const SkClipStack::Element* element = nullptr;
robertphillips@google.com5836b6d2012-07-18 12:06:15 +0000780
bsalomon@google.com9128edc2012-11-29 18:58:19 +0000781 for (element = (const SkClipStack::Element*) fIter.prev();
bsalomon49f085d2014-09-05 13:34:00 -0700782 element;
bsalomon@google.com9128edc2012-11-29 18:58:19 +0000783 element = (const SkClipStack::Element*) fIter.prev()) {
robertphillips@google.com5836b6d2012-07-18 12:06:15 +0000784
bsalomon@google.com9128edc2012-11-29 18:58:19 +0000785 if (op == element->fOp) {
robertphillips@google.com5836b6d2012-07-18 12:06:15 +0000786 // The Deque's iterator is actually one pace ahead of the
bsalomon@google.com9128edc2012-11-29 18:58:19 +0000787 // returned value. So while "element" is the element we want to
robertphillips@google.com5836b6d2012-07-18 12:06:15 +0000788 // return, the iterator is actually pointing at (and will
789 // return on the next "next" or "prev" call) the element
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000790 // in front of it in the deque. Bump the iterator forward a
robertphillips@google.com5836b6d2012-07-18 12:06:15 +0000791 // step so we get the expected result.
halcanary96fcdcc2015-08-27 07:41:13 -0700792 if (nullptr == fIter.next()) {
robertphillips@google.com5836b6d2012-07-18 12:06:15 +0000793 // The reverse iterator has run off the front of the deque
794 // (i.e., the "op" clip is the first clip) and can't
795 // recover. Reset the iterator to start at the front.
796 fIter.reset(fStack->fDeque, SkDeque::Iter::kFront_IterStart);
797 }
798 break;
799 }
800 }
801
halcanary96fcdcc2015-08-27 07:41:13 -0700802 if (nullptr == element) {
robertphillips@google.com5836b6d2012-07-18 12:06:15 +0000803 // There were no "op" clips
804 fIter.reset(fStack->fDeque, SkDeque::Iter::kFront_IterStart);
805 }
806
807 return this->next();
808}
809
robertphillips@google.com52cb2c72012-07-16 18:52:29 +0000810void SkClipStack::Iter::reset(const SkClipStack& stack, IterStart startLoc) {
robertphillips@google.coma6f11c42012-07-23 17:39:44 +0000811 fStack = &stack;
robertphillips@google.com52cb2c72012-07-16 18:52:29 +0000812 fIter.reset(stack.fDeque, static_cast<SkDeque::Iter::IterStart>(startLoc));
bsalomon@google.comd302f142011-03-03 13:54:13 +0000813}
robertphillips@google.com607fe072012-07-24 13:54:00 +0000814
815// helper method
816void SkClipStack::getConservativeBounds(int offsetX,
817 int offsetY,
818 int maxWidth,
819 int maxHeight,
robertphillips@google.com7b112892012-07-31 15:18:21 +0000820 SkRect* devBounds,
robertphillips@google.com4c2a2f72012-07-24 22:07:50 +0000821 bool* isIntersectionOfRects) const {
bsalomon49f085d2014-09-05 13:34:00 -0700822 SkASSERT(devBounds);
robertphillips@google.com607fe072012-07-24 13:54:00 +0000823
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000824 devBounds->setLTRB(0, 0,
robertphillips@google.com7b112892012-07-31 15:18:21 +0000825 SkIntToScalar(maxWidth), SkIntToScalar(maxHeight));
robertphillips@google.com607fe072012-07-24 13:54:00 +0000826
827 SkRect temp;
828 SkClipStack::BoundsType boundType;
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000829
robertphillips@google.com7b112892012-07-31 15:18:21 +0000830 // temp starts off in canvas space here
robertphillips@google.com4c2a2f72012-07-24 22:07:50 +0000831 this->getBounds(&temp, &boundType, isIntersectionOfRects);
robertphillips@google.com607fe072012-07-24 13:54:00 +0000832 if (SkClipStack::kInsideOut_BoundsType == boundType) {
833 return;
834 }
835
robertphillips@google.com7b112892012-07-31 15:18:21 +0000836 // but is converted to device space here
robertphillips@google.com607fe072012-07-24 13:54:00 +0000837 temp.offset(SkIntToScalar(offsetX), SkIntToScalar(offsetY));
838
robertphillips@google.com7b112892012-07-31 15:18:21 +0000839 if (!devBounds->intersect(temp)) {
840 devBounds->setEmpty();
robertphillips@google.com607fe072012-07-24 13:54:00 +0000841 }
842}
robertphillips@google.com46f93502012-08-07 15:38:08 +0000843
robertphillips@google.com46f93502012-08-07 15:38:08 +0000844int32_t SkClipStack::GetNextGenID() {
bsalomon@google.comedb26fd2012-11-28 14:42:41 +0000845 // TODO: handle overflow.
robertphillips@google.com46f93502012-08-07 15:38:08 +0000846 return sk_atomic_inc(&gGenID);
847}
robertphillips@google.com73e71022012-08-09 18:10:49 +0000848
849int32_t SkClipStack::getTopmostGenID() const {
robertphillips@google.com73e71022012-08-09 18:10:49 +0000850 if (fDeque.empty()) {
commit-bot@chromium.orgd3e58422013-11-05 15:03:08 +0000851 return kWideOpenGenID;
robertphillips@google.com73e71022012-08-09 18:10:49 +0000852 }
853
commit-bot@chromium.orgd3e58422013-11-05 15:03:08 +0000854 const Element* back = static_cast<const Element*>(fDeque.back());
855 if (kInsideOut_BoundsType == back->fFiniteBoundType && back->fFiniteBound.isEmpty()) {
856 return kWideOpenGenID;
857 }
858
859 return back->getGenID();
robertphillips@google.com73e71022012-08-09 18:10:49 +0000860}
bsalomonb6b02522014-06-09 07:59:06 -0700861
djsollenefe46d22016-04-29 06:41:35 -0700862#ifdef SK_DEBUG
bsalomonb6b02522014-06-09 07:59:06 -0700863void SkClipStack::Element::dump() const {
864 static const char* kTypeStrings[] = {
865 "empty",
866 "rect",
867 "rrect",
868 "path"
869 };
bungeman99fe8222015-08-20 07:57:51 -0700870 static_assert(0 == kEmpty_Type, "type_str");
871 static_assert(1 == kRect_Type, "type_str");
872 static_assert(2 == kRRect_Type, "type_str");
873 static_assert(3 == kPath_Type, "type_str");
874 static_assert(SK_ARRAY_COUNT(kTypeStrings) == kTypeCnt, "type_str");
bsalomonb6b02522014-06-09 07:59:06 -0700875
876 static const char* kOpStrings[] = {
877 "difference",
878 "intersect",
879 "union",
880 "xor",
881 "reverse-difference",
882 "replace",
883 };
bungeman99fe8222015-08-20 07:57:51 -0700884 static_assert(0 == SkRegion::kDifference_Op, "op_str");
885 static_assert(1 == SkRegion::kIntersect_Op, "op_str");
886 static_assert(2 == SkRegion::kUnion_Op, "op_str");
887 static_assert(3 == SkRegion::kXOR_Op, "op_str");
888 static_assert(4 == SkRegion::kReverseDifference_Op, "op_str");
889 static_assert(5 == SkRegion::kReplace_Op, "op_str");
890 static_assert(SK_ARRAY_COUNT(kOpStrings) == SkRegion::kOpCnt, "op_str");
bsalomonb6b02522014-06-09 07:59:06 -0700891
892 SkDebugf("Type: %s, Op: %s, AA: %s, Save Count: %d\n", kTypeStrings[fType],
893 kOpStrings[fOp], (fDoAA ? "yes" : "no"), fSaveCount);
894 switch (fType) {
895 case kEmpty_Type:
896 SkDebugf("\n");
897 break;
898 case kRect_Type:
899 this->getRect().dump();
900 SkDebugf("\n");
901 break;
902 case kRRect_Type:
903 this->getRRect().dump();
904 SkDebugf("\n");
905 break;
906 case kPath_Type:
halcanary96fcdcc2015-08-27 07:41:13 -0700907 this->getPath().dump(nullptr, true, false);
bsalomonb6b02522014-06-09 07:59:06 -0700908 break;
909 }
910}
911
912void SkClipStack::dump() const {
913 B2TIter iter(*this);
914 const Element* e;
915 while ((e = iter.next())) {
916 e->dump();
917 SkDebugf("\n");
918 }
919}
920#endif