blob: f54d57fd0ba5f9e8cae84155b43b33af09175ce9 [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
mtklein1b249332015-07-07 12:21:21 -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:
24 fPath.reset();
25 break;
26 case kRect_Type: // Rect uses rrect
27 case kRRect_Type:
28 fPath.reset();
29 fRRect = that.fRRect;
30 break;
31 case kPath_Type:
32 fPath.set(that.getPath());
33 break;
34 }
35
36 fSaveCount = that.fSaveCount;
37 fOp = that.fOp;
38 fType = that.fType;
39 fDoAA = that.fDoAA;
40 fFiniteBoundType = that.fFiniteBoundType;
41 fFiniteBound = that.fFiniteBound;
42 fIsIntersectionOfRects = that.fIsIntersectionOfRects;
43 fGenID = that.fGenID;
44}
45
commit-bot@chromium.orge5b2af92014-02-16 13:25:24 +000046bool SkClipStack::Element::operator== (const Element& element) const {
47 if (this == &element) {
48 return true;
49 }
50 if (fOp != element.fOp ||
51 fType != element.fType ||
52 fDoAA != element.fDoAA ||
53 fSaveCount != element.fSaveCount) {
54 return false;
55 }
56 switch (fType) {
57 case kPath_Type:
commit-bot@chromium.org6f954b92014-02-27 17:39:46 +000058 return this->getPath() == element.getPath();
commit-bot@chromium.orge5b2af92014-02-16 13:25:24 +000059 case kRRect_Type:
60 return fRRect == element.fRRect;
61 case kRect_Type:
commit-bot@chromium.org032a52f2014-02-21 20:09:13 +000062 return this->getRect() == element.getRect();
commit-bot@chromium.orge5b2af92014-02-16 13:25:24 +000063 case kEmpty_Type:
64 return true;
65 default:
66 SkDEBUGFAIL("Unexpected type.");
67 return false;
68 }
69}
70
fmalitac3b589a2014-06-05 12:40:07 -070071void SkClipStack::Element::replay(SkCanvasClipVisitor* visitor) const {
72 static const SkRect kEmptyRect = { 0, 0, 0, 0 };
73
74 switch (fType) {
75 case kPath_Type:
76 visitor->clipPath(this->getPath(), this->getOp(), this->isAA());
77 break;
78 case kRRect_Type:
79 visitor->clipRRect(this->getRRect(), this->getOp(), this->isAA());
80 break;
81 case kRect_Type:
82 visitor->clipRect(this->getRect(), this->getOp(), this->isAA());
83 break;
84 case kEmpty_Type:
85 visitor->clipRect(kEmptyRect, SkRegion::kIntersect_Op, false);
86 break;
87 }
88}
89
bsalomon@google.comc6b3e482012-12-07 20:43:52 +000090void SkClipStack::Element::invertShapeFillType() {
91 switch (fType) {
92 case kRect_Type:
commit-bot@chromium.org6f954b92014-02-27 17:39:46 +000093 fPath.init();
94 fPath.get()->addRect(this->getRect());
95 fPath.get()->setFillType(SkPath::kInverseEvenOdd_FillType);
commit-bot@chromium.orge5b2af92014-02-16 13:25:24 +000096 fType = kPath_Type;
97 break;
98 case kRRect_Type:
commit-bot@chromium.org6f954b92014-02-27 17:39:46 +000099 fPath.init();
100 fPath.get()->addRRect(fRRect);
101 fPath.get()->setFillType(SkPath::kInverseEvenOdd_FillType);
bsalomon@google.comc6b3e482012-12-07 20:43:52 +0000102 fType = kPath_Type;
103 break;
104 case kPath_Type:
commit-bot@chromium.org6f954b92014-02-27 17:39:46 +0000105 fPath.get()->toggleInverseFillType();
commit-bot@chromium.orge5b2af92014-02-16 13:25:24 +0000106 break;
bsalomon@google.comc6b3e482012-12-07 20:43:52 +0000107 case kEmpty_Type:
commit-bot@chromium.orge5b2af92014-02-16 13:25:24 +0000108 // Should this set to an empty, inverse filled path?
109 break;
110 }
111}
112
113void SkClipStack::Element::initPath(int saveCount, const SkPath& path, SkRegion::Op op,
114 bool doAA) {
115 if (!path.isInverseFillType()) {
robertphillips2b6ab612015-01-05 12:22:14 -0800116 SkRect r;
117 if (path.isRect(&r)) {
118 this->initRect(saveCount, r, op, doAA);
commit-bot@chromium.orge5b2af92014-02-16 13:25:24 +0000119 return;
120 }
121 SkRect ovalRect;
122 if (path.isOval(&ovalRect)) {
123 SkRRect rrect;
124 rrect.setOval(ovalRect);
125 this->initRRect(saveCount, rrect, op, doAA);
126 return;
127 }
128 }
commit-bot@chromium.org6f954b92014-02-27 17:39:46 +0000129 fPath.set(path);
jvanverth0deb2d92014-10-24 12:41:32 -0700130 fPath.get()->setIsVolatile(true);
commit-bot@chromium.orge5b2af92014-02-16 13:25:24 +0000131 fType = kPath_Type;
132 this->initCommon(saveCount, op, doAA);
133}
134
135void SkClipStack::Element::asPath(SkPath* path) const {
136 switch (fType) {
137 case kEmpty_Type:
138 path->reset();
139 break;
140 case kRect_Type:
141 path->reset();
commit-bot@chromium.org032a52f2014-02-21 20:09:13 +0000142 path->addRect(this->getRect());
commit-bot@chromium.orge5b2af92014-02-16 13:25:24 +0000143 break;
144 case kRRect_Type:
145 path->reset();
146 path->addRRect(fRRect);
147 break;
148 case kPath_Type:
commit-bot@chromium.org6f954b92014-02-27 17:39:46 +0000149 *path = *fPath.get();
bsalomon@google.comc6b3e482012-12-07 20:43:52 +0000150 break;
151 }
jvanverth0deb2d92014-10-24 12:41:32 -0700152 path->setIsVolatile(true);
bsalomon@google.comc6b3e482012-12-07 20:43:52 +0000153}
154
commit-bot@chromium.org9cb671a2014-02-16 14:45:45 +0000155void SkClipStack::Element::setEmpty() {
156 fType = kEmpty_Type;
157 fFiniteBound.setEmpty();
158 fFiniteBoundType = kNormal_BoundsType;
159 fIsIntersectionOfRects = false;
commit-bot@chromium.org9cb671a2014-02-16 14:45:45 +0000160 fRRect.setEmpty();
161 fPath.reset();
162 fGenID = kEmptyGenID;
163 SkDEBUGCODE(this->checkEmpty();)
164}
165
bsalomon@google.com8a98e3b2012-11-29 21:05:13 +0000166void SkClipStack::Element::checkEmpty() const {
167 SkASSERT(fFiniteBound.isEmpty());
168 SkASSERT(kNormal_BoundsType == fFiniteBoundType);
169 SkASSERT(!fIsIntersectionOfRects);
170 SkASSERT(kEmptyGenID == fGenID);
commit-bot@chromium.org6f954b92014-02-27 17:39:46 +0000171 SkASSERT(!fPath.isValid());
bsalomon@google.com8a98e3b2012-11-29 21:05:13 +0000172}
reed@google.com5c3d1472011-02-22 19:12:23 +0000173
bsalomon@google.com8a98e3b2012-11-29 21:05:13 +0000174bool SkClipStack::Element::canBeIntersectedInPlace(int saveCount, SkRegion::Op op) const {
175 if (kEmpty_Type == fType &&
176 (SkRegion::kDifference_Op == op || SkRegion::kIntersect_Op == op)) {
177 return true;
178 }
179 // Only clips within the same save/restore frame (as captured by
180 // the save count) can be merged
181 return fSaveCount == saveCount &&
182 SkRegion::kIntersect_Op == op &&
183 (SkRegion::kIntersect_Op == fOp || SkRegion::kReplace_Op == fOp);
184}
robertphillips@google.com607fe072012-07-24 13:54:00 +0000185
bsalomon@google.com8a98e3b2012-11-29 21:05:13 +0000186bool SkClipStack::Element::rectRectIntersectAllowed(const SkRect& newR, bool newAA) const {
187 SkASSERT(kRect_Type == fType);
188
189 if (fDoAA == newAA) {
190 // if the AA setting is the same there is no issue
191 return true;
robertphillips@google.com607fe072012-07-24 13:54:00 +0000192 }
193
commit-bot@chromium.org032a52f2014-02-21 20:09:13 +0000194 if (!SkRect::Intersects(this->getRect(), newR)) {
bsalomon@google.com8a98e3b2012-11-29 21:05:13 +0000195 // The calling code will correctly set the result to the empty clip
196 return true;
robertphillips@google.com607fe072012-07-24 13:54:00 +0000197 }
198
commit-bot@chromium.org032a52f2014-02-21 20:09:13 +0000199 if (this->getRect().contains(newR)) {
bsalomon@google.com8a98e3b2012-11-29 21:05:13 +0000200 // if the new rect carves out a portion of the old one there is no
201 // issue
202 return true;
robertphillips@google.com607fe072012-07-24 13:54:00 +0000203 }
204
bsalomon@google.com8a98e3b2012-11-29 21:05:13 +0000205 // So either the two overlap in some complex manner or newR contains oldR.
206 // In the first, case the edges will require different AA. In the second,
207 // the AA setting that would be carried forward is incorrect (e.g., oldR
208 // is AA while newR is BW but since newR contains oldR, oldR will be
209 // drawn BW) since the new AA setting will predominate.
210 return false;
211}
robertphillips@google.com607fe072012-07-24 13:54:00 +0000212
bsalomon@google.com8a98e3b2012-11-29 21:05:13 +0000213// a mirror of combineBoundsRevDiff
214void SkClipStack::Element::combineBoundsDiff(FillCombo combination, const SkRect& prevFinite) {
215 switch (combination) {
216 case kInvPrev_InvCur_FillCombo:
217 // In this case the only pixels that can remain set
218 // are inside the current clip rect since the extensions
219 // to infinity of both clips cancel out and whatever
220 // is outside of the current clip is removed
robertphillips@google.com607fe072012-07-24 13:54:00 +0000221 fFiniteBoundType = kNormal_BoundsType;
bsalomon@google.com8a98e3b2012-11-29 21:05:13 +0000222 break;
223 case kInvPrev_Cur_FillCombo:
224 // In this case the current op is finite so the only pixels
225 // that aren't set are whatever isn't set in the previous
226 // clip and whatever this clip carves out
227 fFiniteBound.join(prevFinite);
228 fFiniteBoundType = kInsideOut_BoundsType;
229 break;
230 case kPrev_InvCur_FillCombo:
231 // In this case everything outside of this clip's bound
232 // is erased, so the only pixels that can remain set
233 // occur w/in the intersection of the two finite bounds
234 if (!fFiniteBound.intersect(prevFinite)) {
commit-bot@chromium.orge5b2af92014-02-16 13:25:24 +0000235 this->setEmpty();
236 } else {
237 fFiniteBoundType = kNormal_BoundsType;
robertphillips@google.com4c2a2f72012-07-24 22:07:50 +0000238 }
bsalomon@google.com8a98e3b2012-11-29 21:05:13 +0000239 break;
240 case kPrev_Cur_FillCombo:
241 // The most conservative result bound is that of the
242 // prior clip. This could be wildly incorrect if the
243 // second clip either exactly matches the first clip
244 // (which should yield the empty set) or reduces the
245 // size of the prior bound (e.g., if the second clip
246 // exactly matched the bottom half of the prior clip).
247 // We ignore these two possibilities.
248 fFiniteBound = prevFinite;
249 break;
250 default:
251 SkDEBUGFAIL("SkClipStack::Element::combineBoundsDiff Invalid fill combination");
252 break;
253 }
254}
robertphillips@google.com4c2a2f72012-07-24 22:07:50 +0000255
bsalomon@google.com8a98e3b2012-11-29 21:05:13 +0000256void SkClipStack::Element::combineBoundsXOR(int combination, const SkRect& prevFinite) {
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000257
bsalomon@google.com8a98e3b2012-11-29 21:05:13 +0000258 switch (combination) {
259 case kInvPrev_Cur_FillCombo: // fall through
260 case kPrev_InvCur_FillCombo:
261 // With only one of the clips inverted the result will always
262 // extend to infinity. The only pixels that may be un-writeable
263 // lie within the union of the two finite bounds
264 fFiniteBound.join(prevFinite);
265 fFiniteBoundType = kInsideOut_BoundsType;
266 break;
267 case kInvPrev_InvCur_FillCombo:
268 // The only pixels that can survive are within the
269 // union of the two bounding boxes since the extensions
270 // to infinity of both clips cancel out
271 // fall through!
272 case kPrev_Cur_FillCombo:
273 // The most conservative bound for xor is the
274 // union of the two bounds. If the two clips exactly overlapped
275 // the xor could yield the empty set. Similarly the xor
276 // could reduce the size of the original clip's bound (e.g.,
277 // if the second clip exactly matched the bottom half of the
278 // first clip). We ignore these two cases.
279 fFiniteBound.join(prevFinite);
280 fFiniteBoundType = kNormal_BoundsType;
281 break;
282 default:
283 SkDEBUGFAIL("SkClipStack::Element::combineBoundsXOR Invalid fill combination");
284 break;
285 }
286}
robertphillips@google.com607fe072012-07-24 13:54:00 +0000287
bsalomon@google.com8a98e3b2012-11-29 21:05:13 +0000288// a mirror of combineBoundsIntersection
289void SkClipStack::Element::combineBoundsUnion(int combination, const SkRect& prevFinite) {
290
291 switch (combination) {
292 case kInvPrev_InvCur_FillCombo:
293 if (!fFiniteBound.intersect(prevFinite)) {
294 fFiniteBound.setEmpty();
295 fGenID = kWideOpenGenID;
robertphillips@google.com607fe072012-07-24 13:54:00 +0000296 }
bsalomon@google.com8a98e3b2012-11-29 21:05:13 +0000297 fFiniteBoundType = kInsideOut_BoundsType;
298 break;
299 case kInvPrev_Cur_FillCombo:
300 // The only pixels that won't be drawable are inside
301 // the prior clip's finite bound
302 fFiniteBound = prevFinite;
303 fFiniteBoundType = kInsideOut_BoundsType;
304 break;
305 case kPrev_InvCur_FillCombo:
306 // The only pixels that won't be drawable are inside
307 // this clip's finite bound
308 break;
309 case kPrev_Cur_FillCombo:
310 fFiniteBound.join(prevFinite);
311 break;
312 default:
313 SkDEBUGFAIL("SkClipStack::Element::combineBoundsUnion Invalid fill combination");
314 break;
315 }
316}
317
318// a mirror of combineBoundsUnion
319void SkClipStack::Element::combineBoundsIntersection(int combination, const SkRect& prevFinite) {
320
321 switch (combination) {
322 case kInvPrev_InvCur_FillCombo:
323 // The only pixels that aren't writable in this case
324 // occur in the union of the two finite bounds
325 fFiniteBound.join(prevFinite);
326 fFiniteBoundType = kInsideOut_BoundsType;
327 break;
328 case kInvPrev_Cur_FillCombo:
329 // In this case the only pixels that will remain writeable
330 // are within the current clip
331 break;
332 case kPrev_InvCur_FillCombo:
333 // In this case the only pixels that will remain writeable
334 // are with the previous clip
335 fFiniteBound = prevFinite;
336 fFiniteBoundType = kNormal_BoundsType;
337 break;
338 case kPrev_Cur_FillCombo:
339 if (!fFiniteBound.intersect(prevFinite)) {
commit-bot@chromium.orge5b2af92014-02-16 13:25:24 +0000340 this->setEmpty();
bsalomon@google.com8a98e3b2012-11-29 21:05:13 +0000341 }
342 break;
343 default:
344 SkDEBUGFAIL("SkClipStack::Element::combineBoundsIntersection Invalid fill combination");
345 break;
346 }
347}
348
349// a mirror of combineBoundsDiff
350void SkClipStack::Element::combineBoundsRevDiff(int combination, const SkRect& prevFinite) {
351
352 switch (combination) {
353 case kInvPrev_InvCur_FillCombo:
354 // The only pixels that can survive are in the
355 // previous bound since the extensions to infinity in
356 // both clips cancel out
357 fFiniteBound = prevFinite;
358 fFiniteBoundType = kNormal_BoundsType;
359 break;
360 case kInvPrev_Cur_FillCombo:
361 if (!fFiniteBound.intersect(prevFinite)) {
commit-bot@chromium.orge5b2af92014-02-16 13:25:24 +0000362 this->setEmpty();
363 } else {
364 fFiniteBoundType = kNormal_BoundsType;
bsalomon@google.com8a98e3b2012-11-29 21:05:13 +0000365 }
bsalomon@google.com8a98e3b2012-11-29 21:05:13 +0000366 break;
367 case kPrev_InvCur_FillCombo:
368 fFiniteBound.join(prevFinite);
369 fFiniteBoundType = kInsideOut_BoundsType;
370 break;
371 case kPrev_Cur_FillCombo:
372 // Fall through - as with the kDifference_Op case, the
373 // most conservative result bound is the bound of the
374 // current clip. The prior clip could reduce the size of this
375 // bound (as in the kDifference_Op case) but we are ignoring
376 // those cases.
377 break;
378 default:
379 SkDEBUGFAIL("SkClipStack::Element::combineBoundsRevDiff Invalid fill combination");
380 break;
381 }
382}
383
384void SkClipStack::Element::updateBoundAndGenID(const Element* prior) {
385 // We set this first here but we may overwrite it later if we determine that the clip is
386 // either wide-open or empty.
387 fGenID = GetNextGenID();
388
389 // First, optimistically update the current Element's bound information
390 // with the current clip's bound
391 fIsIntersectionOfRects = false;
commit-bot@chromium.orge5b2af92014-02-16 13:25:24 +0000392 switch (fType) {
393 case kRect_Type:
commit-bot@chromium.org032a52f2014-02-21 20:09:13 +0000394 fFiniteBound = this->getRect();
bsalomon@google.com8a98e3b2012-11-29 21:05:13 +0000395 fFiniteBoundType = kNormal_BoundsType;
commit-bot@chromium.orge5b2af92014-02-16 13:25:24 +0000396
397 if (SkRegion::kReplace_Op == fOp ||
halcanary96fcdcc2015-08-27 07:41:13 -0700398 (SkRegion::kIntersect_Op == fOp && nullptr == prior) ||
commit-bot@chromium.orge5b2af92014-02-16 13:25:24 +0000399 (SkRegion::kIntersect_Op == fOp && prior->fIsIntersectionOfRects &&
commit-bot@chromium.org032a52f2014-02-21 20:09:13 +0000400 prior->rectRectIntersectAllowed(this->getRect(), fDoAA))) {
commit-bot@chromium.orge5b2af92014-02-16 13:25:24 +0000401 fIsIntersectionOfRects = true;
402 }
403 break;
404 case kRRect_Type:
405 fFiniteBound = fRRect.getBounds();
406 fFiniteBoundType = kNormal_BoundsType;
407 break;
408 case kPath_Type:
commit-bot@chromium.org6f954b92014-02-27 17:39:46 +0000409 fFiniteBound = fPath.get()->getBounds();
commit-bot@chromium.orge5b2af92014-02-16 13:25:24 +0000410
commit-bot@chromium.org6f954b92014-02-27 17:39:46 +0000411 if (fPath.get()->isInverseFillType()) {
commit-bot@chromium.orge5b2af92014-02-16 13:25:24 +0000412 fFiniteBoundType = kInsideOut_BoundsType;
413 } else {
414 fFiniteBoundType = kNormal_BoundsType;
415 }
416 break;
417 case kEmpty_Type:
418 SkDEBUGFAIL("We shouldn't get here with an empty element.");
419 break;
robertphillips@google.com607fe072012-07-24 13:54:00 +0000420 }
bsalomon@google.com8a98e3b2012-11-29 21:05:13 +0000421
robertphillipsff420212015-03-30 08:09:58 -0700422 if (!fDoAA) {
423 fFiniteBound.set(SkScalarFloorToScalar(fFiniteBound.fLeft+0.45f),
424 SkScalarRoundToScalar(fFiniteBound.fTop),
425 SkScalarRoundToScalar(fFiniteBound.fRight),
426 SkScalarRoundToScalar(fFiniteBound.fBottom));
427 }
428
bsalomon@google.com8a98e3b2012-11-29 21:05:13 +0000429 // Now determine the previous Element's bound information taking into
430 // account that there may be no previous clip
431 SkRect prevFinite;
432 SkClipStack::BoundsType prevType;
433
halcanary96fcdcc2015-08-27 07:41:13 -0700434 if (nullptr == prior) {
bsalomon@google.com8a98e3b2012-11-29 21:05:13 +0000435 // no prior clip means the entire plane is writable
436 prevFinite.setEmpty(); // there are no pixels that cannot be drawn to
437 prevType = kInsideOut_BoundsType;
438 } else {
439 prevFinite = prior->fFiniteBound;
440 prevType = prior->fFiniteBoundType;
441 }
442
443 FillCombo combination = kPrev_Cur_FillCombo;
444 if (kInsideOut_BoundsType == fFiniteBoundType) {
445 combination = (FillCombo) (combination | 0x01);
446 }
447 if (kInsideOut_BoundsType == prevType) {
448 combination = (FillCombo) (combination | 0x02);
449 }
450
451 SkASSERT(kInvPrev_InvCur_FillCombo == combination ||
452 kInvPrev_Cur_FillCombo == combination ||
453 kPrev_InvCur_FillCombo == combination ||
454 kPrev_Cur_FillCombo == combination);
455
456 // Now integrate with clip with the prior clips
457 switch (fOp) {
458 case SkRegion::kDifference_Op:
459 this->combineBoundsDiff(combination, prevFinite);
460 break;
461 case SkRegion::kXOR_Op:
462 this->combineBoundsXOR(combination, prevFinite);
463 break;
464 case SkRegion::kUnion_Op:
465 this->combineBoundsUnion(combination, prevFinite);
466 break;
467 case SkRegion::kIntersect_Op:
468 this->combineBoundsIntersection(combination, prevFinite);
469 break;
470 case SkRegion::kReverseDifference_Op:
471 this->combineBoundsRevDiff(combination, prevFinite);
472 break;
473 case SkRegion::kReplace_Op:
474 // Replace just ignores everything prior
475 // The current clip's bound information is already filled in
476 // so nothing to do
477 break;
478 default:
commit-bot@chromium.orge5b2af92014-02-16 13:25:24 +0000479 SkDebugf("SkRegion::Op error\n");
bsalomon@google.com8a98e3b2012-11-29 21:05:13 +0000480 SkASSERT(0);
481 break;
482 }
483}
reed@google.com5c3d1472011-02-22 19:12:23 +0000484
bsalomon@google.com9128edc2012-11-29 18:58:19 +0000485// This constant determines how many Element's are allocated together as a block in
robertphillips@google.comf9a90842012-08-17 14:25:43 +0000486// the deque. As such it needs to balance allocating too much memory vs.
487// incurring allocation/deallocation thrashing. It should roughly correspond to
488// the deepest save/restore stack we expect to see.
bsalomon@google.com9128edc2012-11-29 18:58:19 +0000489static const int kDefaultElementAllocCnt = 8;
robertphillips@google.com46f93502012-08-07 15:38:08 +0000490
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000491SkClipStack::SkClipStack()
bsalomon@google.com9128edc2012-11-29 18:58:19 +0000492 : fDeque(sizeof(Element), kDefaultElementAllocCnt)
robertphillips@google.com46f93502012-08-07 15:38:08 +0000493 , fSaveCount(0) {
reed@google.com5c3d1472011-02-22 19:12:23 +0000494}
495
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000496SkClipStack::SkClipStack(const SkClipStack& b)
bsalomon@google.com9128edc2012-11-29 18:58:19 +0000497 : fDeque(sizeof(Element), kDefaultElementAllocCnt) {
vandebo@chromium.org1e1c36f2011-05-03 16:26:09 +0000498 *this = b;
499}
500
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000501SkClipStack::SkClipStack(const SkRect& r)
bsalomon@google.com9128edc2012-11-29 18:58:19 +0000502 : fDeque(sizeof(Element), kDefaultElementAllocCnt)
robertphillips@google.com46f93502012-08-07 15:38:08 +0000503 , fSaveCount(0) {
robertphillips@google.comcc6493b2012-07-26 18:39:13 +0000504 if (!r.isEmpty()) {
505 this->clipDevRect(r, SkRegion::kReplace_Op, false);
506 }
507}
508
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000509SkClipStack::SkClipStack(const SkIRect& r)
bsalomon@google.com9128edc2012-11-29 18:58:19 +0000510 : fDeque(sizeof(Element), kDefaultElementAllocCnt)
robertphillips@google.com46f93502012-08-07 15:38:08 +0000511 , fSaveCount(0) {
robertphillips@google.com641f8b12012-07-31 19:15:58 +0000512 if (!r.isEmpty()) {
513 SkRect temp;
514 temp.set(r);
515 this->clipDevRect(temp, SkRegion::kReplace_Op, false);
516 }
517}
518
vandebo@chromium.org610f7162012-03-14 18:34:15 +0000519SkClipStack::~SkClipStack() {
520 reset();
521}
522
vandebo@chromium.org1e1c36f2011-05-03 16:26:09 +0000523SkClipStack& SkClipStack::operator=(const SkClipStack& b) {
524 if (this == &b) {
525 return *this;
526 }
527 reset();
528
529 fSaveCount = b.fSaveCount;
530 SkDeque::F2BIter recIter(b.fDeque);
bsalomon@google.com9128edc2012-11-29 18:58:19 +0000531 for (const Element* element = (const Element*)recIter.next();
halcanary96fcdcc2015-08-27 07:41:13 -0700532 element != nullptr;
bsalomon@google.com9128edc2012-11-29 18:58:19 +0000533 element = (const Element*)recIter.next()) {
534 new (fDeque.push_back()) Element(*element);
vandebo@chromium.org1e1c36f2011-05-03 16:26:09 +0000535 }
536
537 return *this;
538}
539
540bool SkClipStack::operator==(const SkClipStack& b) const {
commit-bot@chromium.org86b39f32014-01-06 16:54:20 +0000541 if (this->getTopmostGenID() == b.getTopmostGenID()) {
542 return true;
543 }
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000544 if (fSaveCount != b.fSaveCount ||
robertphillips@google.com46f93502012-08-07 15:38:08 +0000545 fDeque.count() != b.fDeque.count()) {
vandebo@chromium.org1e1c36f2011-05-03 16:26:09 +0000546 return false;
547 }
548 SkDeque::F2BIter myIter(fDeque);
549 SkDeque::F2BIter bIter(b.fDeque);
bsalomon@google.com9128edc2012-11-29 18:58:19 +0000550 const Element* myElement = (const Element*)myIter.next();
551 const Element* bElement = (const Element*)bIter.next();
vandebo@chromium.org1e1c36f2011-05-03 16:26:09 +0000552
halcanary96fcdcc2015-08-27 07:41:13 -0700553 while (myElement != nullptr && bElement != nullptr) {
bsalomon@google.com9128edc2012-11-29 18:58:19 +0000554 if (*myElement != *bElement) {
vandebo@chromium.org1e1c36f2011-05-03 16:26:09 +0000555 return false;
556 }
bsalomon@google.com9128edc2012-11-29 18:58:19 +0000557 myElement = (const Element*)myIter.next();
558 bElement = (const Element*)bIter.next();
vandebo@chromium.org1e1c36f2011-05-03 16:26:09 +0000559 }
halcanary96fcdcc2015-08-27 07:41:13 -0700560 return myElement == nullptr && bElement == nullptr;
vandebo@chromium.org1e1c36f2011-05-03 16:26:09 +0000561}
562
reed@google.com5c3d1472011-02-22 19:12:23 +0000563void SkClipStack::reset() {
vandebo@chromium.org610f7162012-03-14 18:34:15 +0000564 // We used a placement new for each object in fDeque, so we're responsible
565 // for calling the destructor on each of them as well.
566 while (!fDeque.empty()) {
bsalomon@google.com9128edc2012-11-29 18:58:19 +0000567 Element* element = (Element*)fDeque.back();
568 element->~Element();
vandebo@chromium.org610f7162012-03-14 18:34:15 +0000569 fDeque.pop_back();
570 }
reed@google.com5c3d1472011-02-22 19:12:23 +0000571
572 fSaveCount = 0;
573}
574
575void SkClipStack::save() {
576 fSaveCount += 1;
577}
578
579void SkClipStack::restore() {
580 fSaveCount -= 1;
commit-bot@chromium.org6fbe54c2013-06-11 11:01:48 +0000581 restoreTo(fSaveCount);
582}
583
584void SkClipStack::restoreTo(int saveCount) {
reed@google.com5c3d1472011-02-22 19:12:23 +0000585 while (!fDeque.empty()) {
bsalomon@google.com9128edc2012-11-29 18:58:19 +0000586 Element* element = (Element*)fDeque.back();
commit-bot@chromium.org6fbe54c2013-06-11 11:01:48 +0000587 if (element->fSaveCount <= saveCount) {
reed@google.com5c3d1472011-02-22 19:12:23 +0000588 break;
589 }
bsalomon@google.com9128edc2012-11-29 18:58:19 +0000590 element->~Element();
reed@google.com5c3d1472011-02-22 19:12:23 +0000591 fDeque.pop_back();
592 }
593}
594
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000595void SkClipStack::getBounds(SkRect* canvFiniteBound,
robertphillips@google.com4c2a2f72012-07-24 22:07:50 +0000596 BoundsType* boundType,
597 bool* isIntersectionOfRects) const {
bsalomon49f085d2014-09-05 13:34:00 -0700598 SkASSERT(canvFiniteBound && boundType);
robertphillips@google.com607fe072012-07-24 13:54:00 +0000599
bsalomon@google.com9128edc2012-11-29 18:58:19 +0000600 Element* element = (Element*)fDeque.back();
robertphillips@google.com607fe072012-07-24 13:54:00 +0000601
halcanary96fcdcc2015-08-27 07:41:13 -0700602 if (nullptr == element) {
robertphillips@google.com607fe072012-07-24 13:54:00 +0000603 // the clip is wide open - the infinite plane w/ no pixels un-writeable
robertphillips@google.com7b112892012-07-31 15:18:21 +0000604 canvFiniteBound->setEmpty();
robertphillips@google.com607fe072012-07-24 13:54:00 +0000605 *boundType = kInsideOut_BoundsType;
bsalomon49f085d2014-09-05 13:34:00 -0700606 if (isIntersectionOfRects) {
robertphillips@google.com4c2a2f72012-07-24 22:07:50 +0000607 *isIntersectionOfRects = false;
608 }
robertphillips@google.com607fe072012-07-24 13:54:00 +0000609 return;
610 }
611
bsalomon@google.com9128edc2012-11-29 18:58:19 +0000612 *canvFiniteBound = element->fFiniteBound;
613 *boundType = element->fFiniteBoundType;
bsalomon49f085d2014-09-05 13:34:00 -0700614 if (isIntersectionOfRects) {
bsalomon@google.com9128edc2012-11-29 18:58:19 +0000615 *isIntersectionOfRects = element->fIsIntersectionOfRects;
robertphillips@google.com4c2a2f72012-07-24 22:07:50 +0000616 }
robertphillips@google.com607fe072012-07-24 13:54:00 +0000617}
618
junov@chromium.org8cdf0f52012-12-12 17:58:15 +0000619bool SkClipStack::quickContains(const SkRect& rect) const {
620
621 Iter iter(*this, Iter::kTop_IterStart);
622 const Element* element = iter.prev();
halcanary96fcdcc2015-08-27 07:41:13 -0700623 while (element != nullptr) {
junov@chromium.org8cdf0f52012-12-12 17:58:15 +0000624 if (SkRegion::kIntersect_Op != element->getOp() && SkRegion::kReplace_Op != element->getOp())
625 return false;
626 if (element->isInverseFilled()) {
627 // Part of 'rect' could be trimmed off by the inverse-filled clip element
628 if (SkRect::Intersects(element->getBounds(), rect)) {
629 return false;
630 }
631 } else {
632 if (!element->contains(rect)) {
633 return false;
634 }
635 }
636 if (SkRegion::kReplace_Op == element->getOp()) {
637 break;
638 }
639 element = iter.prev();
640 }
641 return true;
642}
643
fmalita1a481fe2015-02-04 07:39:34 -0800644bool SkClipStack::asPath(SkPath *path) const {
645 bool isAA = false;
646
647 path->reset();
648 path->setFillType(SkPath::kInverseEvenOdd_FillType);
649
650 SkClipStack::Iter iter(*this, SkClipStack::Iter::kBottom_IterStart);
651 while (const SkClipStack::Element* element = iter.next()) {
652 SkPath operand;
653 if (element->getType() != SkClipStack::Element::kEmpty_Type) {
654 element->asPath(&operand);
655 }
656
657 SkRegion::Op elementOp = element->getOp();
658 if (elementOp == SkRegion::kReplace_Op) {
659 *path = operand;
660 } else {
661 Op(*path, operand, (SkPathOp)elementOp, path);
662 }
663
664 // if the prev and curr clips disagree about aa -vs- not, favor the aa request.
665 // perhaps we need an API change to avoid this sort of mixed-signals about
666 // clipping.
667 isAA = (isAA || element->isAA());
668 }
669
670 return isAA;
671}
672
commit-bot@chromium.orge5b2af92014-02-16 13:25:24 +0000673void SkClipStack::pushElement(const Element& element) {
robertphillips@google.com63ae1cf2012-08-17 13:53:05 +0000674 // Use reverse iterator instead of back because Rect path may need previous
robertphillips@google.com4c2a2f72012-07-24 22:07:50 +0000675 SkDeque::Iter iter(fDeque, SkDeque::Iter::kBack_IterStart);
commit-bot@chromium.orge5b2af92014-02-16 13:25:24 +0000676 Element* prior = (Element*) iter.prev();
robertphillips@google.com4c2a2f72012-07-24 22:07:50 +0000677
bsalomon49f085d2014-09-05 13:34:00 -0700678 if (prior) {
commit-bot@chromium.orge5b2af92014-02-16 13:25:24 +0000679 if (prior->canBeIntersectedInPlace(fSaveCount, element.getOp())) {
680 switch (prior->fType) {
commit-bot@chromium.org6fbe54c2013-06-11 11:01:48 +0000681 case Element::kEmpty_Type:
commit-bot@chromium.orge5b2af92014-02-16 13:25:24 +0000682 SkDEBUGCODE(prior->checkEmpty();)
commit-bot@chromium.org6fbe54c2013-06-11 11:01:48 +0000683 return;
684 case Element::kRect_Type:
commit-bot@chromium.orge5b2af92014-02-16 13:25:24 +0000685 if (Element::kRect_Type == element.getType()) {
686 if (prior->rectRectIntersectAllowed(element.getRect(), element.isAA())) {
commit-bot@chromium.org032a52f2014-02-21 20:09:13 +0000687 SkRect isectRect;
688 if (!isectRect.intersect(prior->getRect(), element.getRect())) {
commit-bot@chromium.orge5b2af92014-02-16 13:25:24 +0000689 prior->setEmpty();
690 return;
691 }
692
commit-bot@chromium.org032a52f2014-02-21 20:09:13 +0000693 prior->fRRect.setRect(isectRect);
commit-bot@chromium.orge5b2af92014-02-16 13:25:24 +0000694 prior->fDoAA = element.isAA();
695 Element* priorPrior = (Element*) iter.prev();
696 prior->updateBoundAndGenID(priorPrior);
commit-bot@chromium.org6fbe54c2013-06-11 11:01:48 +0000697 return;
698 }
commit-bot@chromium.orge5b2af92014-02-16 13:25:24 +0000699 break;
commit-bot@chromium.org6fbe54c2013-06-11 11:01:48 +0000700 }
commit-bot@chromium.orge5b2af92014-02-16 13:25:24 +0000701 // fallthrough
702 default:
703 if (!SkRect::Intersects(prior->getBounds(), element.getBounds())) {
704 prior->setEmpty();
robertphillips@google.com08eacc12012-08-02 12:49:00 +0000705 return;
706 }
commit-bot@chromium.org6fbe54c2013-06-11 11:01:48 +0000707 break;
708 }
commit-bot@chromium.orge5b2af92014-02-16 13:25:24 +0000709 } else if (SkRegion::kReplace_Op == element.getOp()) {
commit-bot@chromium.org6fbe54c2013-06-11 11:01:48 +0000710 this->restoreTo(fSaveCount - 1);
commit-bot@chromium.orge5b2af92014-02-16 13:25:24 +0000711 prior = (Element*) fDeque.back();
reed@google.com5c3d1472011-02-22 19:12:23 +0000712 }
713 }
halcanary385fe4d2015-08-26 13:07:48 -0700714 Element* newElement = new (fDeque.push_back()) Element(element);
commit-bot@chromium.orge5b2af92014-02-16 13:25:24 +0000715 newElement->updateBoundAndGenID(prior);
716}
717
718void SkClipStack::clipDevRRect(const SkRRect& rrect, SkRegion::Op op, bool doAA) {
719 Element element(fSaveCount, rrect, op, doAA);
720 this->pushElement(element);
721}
722
723void SkClipStack::clipDevRect(const SkRect& rect, SkRegion::Op op, bool doAA) {
724 Element element(fSaveCount, rect, op, doAA);
725 this->pushElement(element);
reed@google.com5c3d1472011-02-22 19:12:23 +0000726}
727
reed@google.com00177082011-10-12 14:34:30 +0000728void SkClipStack::clipDevPath(const SkPath& path, SkRegion::Op op, bool doAA) {
commit-bot@chromium.orge5b2af92014-02-16 13:25:24 +0000729 Element element(fSaveCount, path, op, doAA);
730 this->pushElement(element);
reed@google.com5c3d1472011-02-22 19:12:23 +0000731}
732
reed@google.com0557d9e2012-08-16 15:59:59 +0000733void SkClipStack::clipEmpty() {
bsalomon@google.com9128edc2012-11-29 18:58:19 +0000734 Element* element = (Element*) fDeque.back();
robertphillips@google.com63ae1cf2012-08-17 13:53:05 +0000735
bsalomon@google.com9128edc2012-11-29 18:58:19 +0000736 if (element && element->canBeIntersectedInPlace(fSaveCount, SkRegion::kIntersect_Op)) {
commit-bot@chromium.orge5b2af92014-02-16 13:25:24 +0000737 element->setEmpty();
reed@google.com0557d9e2012-08-16 15:59:59 +0000738 }
bsalomon@google.com9128edc2012-11-29 18:58:19 +0000739 new (fDeque.push_back()) Element(fSaveCount);
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000740
bsalomon@google.com9128edc2012-11-29 18:58:19 +0000741 ((Element*)fDeque.back())->fGenID = kEmptyGenID;
reed@google.com0557d9e2012-08-16 15:59:59 +0000742}
743
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000744bool SkClipStack::isWideOpen() const {
commit-bot@chromium.orgd3e58422013-11-05 15:03:08 +0000745 return this->getTopmostGenID() == kWideOpenGenID;
robertphillips@google.comcc6493b2012-07-26 18:39:13 +0000746}
747
reed@google.com5c3d1472011-02-22 19:12:23 +0000748///////////////////////////////////////////////////////////////////////////////
749
halcanary96fcdcc2015-08-27 07:41:13 -0700750SkClipStack::Iter::Iter() : fStack(nullptr) {
bsalomon@google.comd302f142011-03-03 13:54:13 +0000751}
752
robertphillips@google.com5836b6d2012-07-18 12:06:15 +0000753SkClipStack::Iter::Iter(const SkClipStack& stack, IterStart startLoc)
754 : fStack(&stack) {
robertphillips@google.com52cb2c72012-07-16 18:52:29 +0000755 this->reset(stack, startLoc);
reed@google.com5c3d1472011-02-22 19:12:23 +0000756}
757
bsalomon@google.com8182fa02012-12-04 14:06:06 +0000758const SkClipStack::Element* SkClipStack::Iter::next() {
759 return (const SkClipStack::Element*)fIter.next();
reed@google.com5c3d1472011-02-22 19:12:23 +0000760}
bsalomon@google.comd302f142011-03-03 13:54:13 +0000761
bsalomon@google.com8182fa02012-12-04 14:06:06 +0000762const SkClipStack::Element* SkClipStack::Iter::prev() {
763 return (const SkClipStack::Element*)fIter.prev();
robertphillips@google.com52cb2c72012-07-16 18:52:29 +0000764}
765
bsalomon@google.com8182fa02012-12-04 14:06:06 +0000766const SkClipStack::Element* SkClipStack::Iter::skipToTopmost(SkRegion::Op op) {
robertphillips@google.com5836b6d2012-07-18 12:06:15 +0000767
halcanary96fcdcc2015-08-27 07:41:13 -0700768 if (nullptr == fStack) {
769 return nullptr;
robertphillips@google.com5836b6d2012-07-18 12:06:15 +0000770 }
771
772 fIter.reset(fStack->fDeque, SkDeque::Iter::kBack_IterStart);
773
halcanary96fcdcc2015-08-27 07:41:13 -0700774 const SkClipStack::Element* element = nullptr;
robertphillips@google.com5836b6d2012-07-18 12:06:15 +0000775
bsalomon@google.com9128edc2012-11-29 18:58:19 +0000776 for (element = (const SkClipStack::Element*) fIter.prev();
bsalomon49f085d2014-09-05 13:34:00 -0700777 element;
bsalomon@google.com9128edc2012-11-29 18:58:19 +0000778 element = (const SkClipStack::Element*) fIter.prev()) {
robertphillips@google.com5836b6d2012-07-18 12:06:15 +0000779
bsalomon@google.com9128edc2012-11-29 18:58:19 +0000780 if (op == element->fOp) {
robertphillips@google.com5836b6d2012-07-18 12:06:15 +0000781 // The Deque's iterator is actually one pace ahead of the
bsalomon@google.com9128edc2012-11-29 18:58:19 +0000782 // returned value. So while "element" is the element we want to
robertphillips@google.com5836b6d2012-07-18 12:06:15 +0000783 // return, the iterator is actually pointing at (and will
784 // return on the next "next" or "prev" call) the element
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000785 // in front of it in the deque. Bump the iterator forward a
robertphillips@google.com5836b6d2012-07-18 12:06:15 +0000786 // step so we get the expected result.
halcanary96fcdcc2015-08-27 07:41:13 -0700787 if (nullptr == fIter.next()) {
robertphillips@google.com5836b6d2012-07-18 12:06:15 +0000788 // The reverse iterator has run off the front of the deque
789 // (i.e., the "op" clip is the first clip) and can't
790 // recover. Reset the iterator to start at the front.
791 fIter.reset(fStack->fDeque, SkDeque::Iter::kFront_IterStart);
792 }
793 break;
794 }
795 }
796
halcanary96fcdcc2015-08-27 07:41:13 -0700797 if (nullptr == element) {
robertphillips@google.com5836b6d2012-07-18 12:06:15 +0000798 // There were no "op" clips
799 fIter.reset(fStack->fDeque, SkDeque::Iter::kFront_IterStart);
800 }
801
802 return this->next();
803}
804
robertphillips@google.com52cb2c72012-07-16 18:52:29 +0000805void SkClipStack::Iter::reset(const SkClipStack& stack, IterStart startLoc) {
robertphillips@google.coma6f11c42012-07-23 17:39:44 +0000806 fStack = &stack;
robertphillips@google.com52cb2c72012-07-16 18:52:29 +0000807 fIter.reset(stack.fDeque, static_cast<SkDeque::Iter::IterStart>(startLoc));
bsalomon@google.comd302f142011-03-03 13:54:13 +0000808}
robertphillips@google.com607fe072012-07-24 13:54:00 +0000809
810// helper method
811void SkClipStack::getConservativeBounds(int offsetX,
812 int offsetY,
813 int maxWidth,
814 int maxHeight,
robertphillips@google.com7b112892012-07-31 15:18:21 +0000815 SkRect* devBounds,
robertphillips@google.com4c2a2f72012-07-24 22:07:50 +0000816 bool* isIntersectionOfRects) const {
bsalomon49f085d2014-09-05 13:34:00 -0700817 SkASSERT(devBounds);
robertphillips@google.com607fe072012-07-24 13:54:00 +0000818
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000819 devBounds->setLTRB(0, 0,
robertphillips@google.com7b112892012-07-31 15:18:21 +0000820 SkIntToScalar(maxWidth), SkIntToScalar(maxHeight));
robertphillips@google.com607fe072012-07-24 13:54:00 +0000821
822 SkRect temp;
823 SkClipStack::BoundsType boundType;
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000824
robertphillips@google.com7b112892012-07-31 15:18:21 +0000825 // temp starts off in canvas space here
robertphillips@google.com4c2a2f72012-07-24 22:07:50 +0000826 this->getBounds(&temp, &boundType, isIntersectionOfRects);
robertphillips@google.com607fe072012-07-24 13:54:00 +0000827 if (SkClipStack::kInsideOut_BoundsType == boundType) {
828 return;
829 }
830
robertphillips@google.com7b112892012-07-31 15:18:21 +0000831 // but is converted to device space here
robertphillips@google.com607fe072012-07-24 13:54:00 +0000832 temp.offset(SkIntToScalar(offsetX), SkIntToScalar(offsetY));
833
robertphillips@google.com7b112892012-07-31 15:18:21 +0000834 if (!devBounds->intersect(temp)) {
835 devBounds->setEmpty();
robertphillips@google.com607fe072012-07-24 13:54:00 +0000836 }
837}
robertphillips@google.com46f93502012-08-07 15:38:08 +0000838
robertphillips@google.com46f93502012-08-07 15:38:08 +0000839int32_t SkClipStack::GetNextGenID() {
bsalomon@google.comedb26fd2012-11-28 14:42:41 +0000840 // TODO: handle overflow.
robertphillips@google.com46f93502012-08-07 15:38:08 +0000841 return sk_atomic_inc(&gGenID);
842}
robertphillips@google.com73e71022012-08-09 18:10:49 +0000843
844int32_t SkClipStack::getTopmostGenID() const {
robertphillips@google.com73e71022012-08-09 18:10:49 +0000845 if (fDeque.empty()) {
commit-bot@chromium.orgd3e58422013-11-05 15:03:08 +0000846 return kWideOpenGenID;
robertphillips@google.com73e71022012-08-09 18:10:49 +0000847 }
848
commit-bot@chromium.orgd3e58422013-11-05 15:03:08 +0000849 const Element* back = static_cast<const Element*>(fDeque.back());
850 if (kInsideOut_BoundsType == back->fFiniteBoundType && back->fFiniteBound.isEmpty()) {
851 return kWideOpenGenID;
852 }
853
854 return back->getGenID();
robertphillips@google.com73e71022012-08-09 18:10:49 +0000855}
bsalomonb6b02522014-06-09 07:59:06 -0700856
857#ifdef SK_DEVELOPER
858void SkClipStack::Element::dump() const {
859 static const char* kTypeStrings[] = {
860 "empty",
861 "rect",
862 "rrect",
863 "path"
864 };
bungeman99fe8222015-08-20 07:57:51 -0700865 static_assert(0 == kEmpty_Type, "type_str");
866 static_assert(1 == kRect_Type, "type_str");
867 static_assert(2 == kRRect_Type, "type_str");
868 static_assert(3 == kPath_Type, "type_str");
869 static_assert(SK_ARRAY_COUNT(kTypeStrings) == kTypeCnt, "type_str");
bsalomonb6b02522014-06-09 07:59:06 -0700870
871 static const char* kOpStrings[] = {
872 "difference",
873 "intersect",
874 "union",
875 "xor",
876 "reverse-difference",
877 "replace",
878 };
bungeman99fe8222015-08-20 07:57:51 -0700879 static_assert(0 == SkRegion::kDifference_Op, "op_str");
880 static_assert(1 == SkRegion::kIntersect_Op, "op_str");
881 static_assert(2 == SkRegion::kUnion_Op, "op_str");
882 static_assert(3 == SkRegion::kXOR_Op, "op_str");
883 static_assert(4 == SkRegion::kReverseDifference_Op, "op_str");
884 static_assert(5 == SkRegion::kReplace_Op, "op_str");
885 static_assert(SK_ARRAY_COUNT(kOpStrings) == SkRegion::kOpCnt, "op_str");
bsalomonb6b02522014-06-09 07:59:06 -0700886
887 SkDebugf("Type: %s, Op: %s, AA: %s, Save Count: %d\n", kTypeStrings[fType],
888 kOpStrings[fOp], (fDoAA ? "yes" : "no"), fSaveCount);
889 switch (fType) {
890 case kEmpty_Type:
891 SkDebugf("\n");
892 break;
893 case kRect_Type:
894 this->getRect().dump();
895 SkDebugf("\n");
896 break;
897 case kRRect_Type:
898 this->getRRect().dump();
899 SkDebugf("\n");
900 break;
901 case kPath_Type:
halcanary96fcdcc2015-08-27 07:41:13 -0700902 this->getPath().dump(nullptr, true, false);
bsalomonb6b02522014-06-09 07:59:06 -0700903 break;
904 }
905}
906
907void SkClipStack::dump() const {
908 B2TIter iter(*this);
909 const Element* e;
910 while ((e = iter.next())) {
911 e->dump();
912 SkDebugf("\n");
913 }
914}
915#endif