blob: 515596a9693451f3a8bc05b932405ef20ac975b4 [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
8#include "SkCanvas.h"
reed@google.com5c3d1472011-02-22 19:12:23 +00009#include "SkClipStack.h"
10#include "SkPath.h"
robertphillips@google.com46f93502012-08-07 15:38:08 +000011#include "SkThread.h"
12
reed@google.com5c3d1472011-02-22 19:12:23 +000013#include <new>
14
robertphillips@google.com607fe072012-07-24 13:54:00 +000015
robertphillips@google.com46f93502012-08-07 15:38:08 +000016// 0-2 are reserved for invalid, empty & wide-open
bsalomon@google.comedb26fd2012-11-28 14:42:41 +000017static const int32_t kFirstUnreservedGenID = 3;
18int32_t SkClipStack::gGenID = kFirstUnreservedGenID;
robertphillips@google.com46f93502012-08-07 15:38:08 +000019
commit-bot@chromium.org6f954b92014-02-27 17:39:46 +000020SkClipStack::Element::Element(const Element& that) {
21 switch (that.getType()) {
22 case kEmpty_Type:
23 fPath.reset();
24 break;
25 case kRect_Type: // Rect uses rrect
26 case kRRect_Type:
27 fPath.reset();
28 fRRect = that.fRRect;
29 break;
30 case kPath_Type:
31 fPath.set(that.getPath());
32 break;
33 }
34
35 fSaveCount = that.fSaveCount;
36 fOp = that.fOp;
37 fType = that.fType;
38 fDoAA = that.fDoAA;
39 fFiniteBoundType = that.fFiniteBoundType;
40 fFiniteBound = that.fFiniteBound;
41 fIsIntersectionOfRects = that.fIsIntersectionOfRects;
42 fGenID = that.fGenID;
43}
44
commit-bot@chromium.orge5b2af92014-02-16 13:25:24 +000045bool SkClipStack::Element::operator== (const Element& element) const {
46 if (this == &element) {
47 return true;
48 }
49 if (fOp != element.fOp ||
50 fType != element.fType ||
51 fDoAA != element.fDoAA ||
52 fSaveCount != element.fSaveCount) {
53 return false;
54 }
55 switch (fType) {
56 case kPath_Type:
commit-bot@chromium.org6f954b92014-02-27 17:39:46 +000057 return this->getPath() == element.getPath();
commit-bot@chromium.orge5b2af92014-02-16 13:25:24 +000058 case kRRect_Type:
59 return fRRect == element.fRRect;
60 case kRect_Type:
commit-bot@chromium.org032a52f2014-02-21 20:09:13 +000061 return this->getRect() == element.getRect();
commit-bot@chromium.orge5b2af92014-02-16 13:25:24 +000062 case kEmpty_Type:
63 return true;
64 default:
65 SkDEBUGFAIL("Unexpected type.");
66 return false;
67 }
68}
69
fmalitac3b589a2014-06-05 12:40:07 -070070void SkClipStack::Element::replay(SkCanvasClipVisitor* visitor) const {
71 static const SkRect kEmptyRect = { 0, 0, 0, 0 };
72
73 switch (fType) {
74 case kPath_Type:
75 visitor->clipPath(this->getPath(), this->getOp(), this->isAA());
76 break;
77 case kRRect_Type:
78 visitor->clipRRect(this->getRRect(), this->getOp(), this->isAA());
79 break;
80 case kRect_Type:
81 visitor->clipRect(this->getRect(), this->getOp(), this->isAA());
82 break;
83 case kEmpty_Type:
84 visitor->clipRect(kEmptyRect, SkRegion::kIntersect_Op, false);
85 break;
86 }
87}
88
bsalomon@google.comc6b3e482012-12-07 20:43:52 +000089void SkClipStack::Element::invertShapeFillType() {
90 switch (fType) {
91 case kRect_Type:
commit-bot@chromium.org6f954b92014-02-27 17:39:46 +000092 fPath.init();
93 fPath.get()->addRect(this->getRect());
94 fPath.get()->setFillType(SkPath::kInverseEvenOdd_FillType);
commit-bot@chromium.orge5b2af92014-02-16 13:25:24 +000095 fType = kPath_Type;
96 break;
97 case kRRect_Type:
commit-bot@chromium.org6f954b92014-02-27 17:39:46 +000098 fPath.init();
99 fPath.get()->addRRect(fRRect);
100 fPath.get()->setFillType(SkPath::kInverseEvenOdd_FillType);
bsalomon@google.comc6b3e482012-12-07 20:43:52 +0000101 fType = kPath_Type;
102 break;
103 case kPath_Type:
commit-bot@chromium.org6f954b92014-02-27 17:39:46 +0000104 fPath.get()->toggleInverseFillType();
commit-bot@chromium.orge5b2af92014-02-16 13:25:24 +0000105 break;
bsalomon@google.comc6b3e482012-12-07 20:43:52 +0000106 case kEmpty_Type:
commit-bot@chromium.orge5b2af92014-02-16 13:25:24 +0000107 // Should this set to an empty, inverse filled path?
108 break;
109 }
110}
111
112void SkClipStack::Element::initPath(int saveCount, const SkPath& path, SkRegion::Op op,
113 bool doAA) {
114 if (!path.isInverseFillType()) {
robertphillips2b6ab612015-01-05 12:22:14 -0800115 SkRect r;
116 if (path.isRect(&r)) {
117 this->initRect(saveCount, r, op, doAA);
commit-bot@chromium.orge5b2af92014-02-16 13:25:24 +0000118 return;
119 }
120 SkRect ovalRect;
121 if (path.isOval(&ovalRect)) {
122 SkRRect rrect;
123 rrect.setOval(ovalRect);
124 this->initRRect(saveCount, rrect, op, doAA);
125 return;
126 }
127 }
commit-bot@chromium.org6f954b92014-02-27 17:39:46 +0000128 fPath.set(path);
jvanverth0deb2d92014-10-24 12:41:32 -0700129 fPath.get()->setIsVolatile(true);
commit-bot@chromium.orge5b2af92014-02-16 13:25:24 +0000130 fType = kPath_Type;
131 this->initCommon(saveCount, op, doAA);
132}
133
134void SkClipStack::Element::asPath(SkPath* path) const {
135 switch (fType) {
136 case kEmpty_Type:
137 path->reset();
138 break;
139 case kRect_Type:
140 path->reset();
commit-bot@chromium.org032a52f2014-02-21 20:09:13 +0000141 path->addRect(this->getRect());
commit-bot@chromium.orge5b2af92014-02-16 13:25:24 +0000142 break;
143 case kRRect_Type:
144 path->reset();
145 path->addRRect(fRRect);
146 break;
147 case kPath_Type:
commit-bot@chromium.org6f954b92014-02-27 17:39:46 +0000148 *path = *fPath.get();
bsalomon@google.comc6b3e482012-12-07 20:43:52 +0000149 break;
150 }
jvanverth0deb2d92014-10-24 12:41:32 -0700151 path->setIsVolatile(true);
bsalomon@google.comc6b3e482012-12-07 20:43:52 +0000152}
153
commit-bot@chromium.org9cb671a2014-02-16 14:45:45 +0000154void SkClipStack::Element::setEmpty() {
155 fType = kEmpty_Type;
156 fFiniteBound.setEmpty();
157 fFiniteBoundType = kNormal_BoundsType;
158 fIsIntersectionOfRects = false;
commit-bot@chromium.org9cb671a2014-02-16 14:45:45 +0000159 fRRect.setEmpty();
160 fPath.reset();
161 fGenID = kEmptyGenID;
162 SkDEBUGCODE(this->checkEmpty();)
163}
164
bsalomon@google.com8a98e3b2012-11-29 21:05:13 +0000165void SkClipStack::Element::checkEmpty() const {
166 SkASSERT(fFiniteBound.isEmpty());
167 SkASSERT(kNormal_BoundsType == fFiniteBoundType);
168 SkASSERT(!fIsIntersectionOfRects);
169 SkASSERT(kEmptyGenID == fGenID);
commit-bot@chromium.org6f954b92014-02-27 17:39:46 +0000170 SkASSERT(!fPath.isValid());
bsalomon@google.com8a98e3b2012-11-29 21:05:13 +0000171}
reed@google.com5c3d1472011-02-22 19:12:23 +0000172
bsalomon@google.com8a98e3b2012-11-29 21:05:13 +0000173bool SkClipStack::Element::canBeIntersectedInPlace(int saveCount, SkRegion::Op op) const {
174 if (kEmpty_Type == fType &&
175 (SkRegion::kDifference_Op == op || SkRegion::kIntersect_Op == op)) {
176 return true;
177 }
178 // Only clips within the same save/restore frame (as captured by
179 // the save count) can be merged
180 return fSaveCount == saveCount &&
181 SkRegion::kIntersect_Op == op &&
182 (SkRegion::kIntersect_Op == fOp || SkRegion::kReplace_Op == fOp);
183}
robertphillips@google.com607fe072012-07-24 13:54:00 +0000184
bsalomon@google.com8a98e3b2012-11-29 21:05:13 +0000185bool SkClipStack::Element::rectRectIntersectAllowed(const SkRect& newR, bool newAA) const {
186 SkASSERT(kRect_Type == fType);
187
188 if (fDoAA == newAA) {
189 // if the AA setting is the same there is no issue
190 return true;
robertphillips@google.com607fe072012-07-24 13:54:00 +0000191 }
192
commit-bot@chromium.org032a52f2014-02-21 20:09:13 +0000193 if (!SkRect::Intersects(this->getRect(), newR)) {
bsalomon@google.com8a98e3b2012-11-29 21:05:13 +0000194 // The calling code will correctly set the result to the empty clip
195 return true;
robertphillips@google.com607fe072012-07-24 13:54:00 +0000196 }
197
commit-bot@chromium.org032a52f2014-02-21 20:09:13 +0000198 if (this->getRect().contains(newR)) {
bsalomon@google.com8a98e3b2012-11-29 21:05:13 +0000199 // if the new rect carves out a portion of the old one there is no
200 // issue
201 return true;
robertphillips@google.com607fe072012-07-24 13:54:00 +0000202 }
203
bsalomon@google.com8a98e3b2012-11-29 21:05:13 +0000204 // So either the two overlap in some complex manner or newR contains oldR.
205 // In the first, case the edges will require different AA. In the second,
206 // the AA setting that would be carried forward is incorrect (e.g., oldR
207 // is AA while newR is BW but since newR contains oldR, oldR will be
208 // drawn BW) since the new AA setting will predominate.
209 return false;
210}
robertphillips@google.com607fe072012-07-24 13:54:00 +0000211
bsalomon@google.com8a98e3b2012-11-29 21:05:13 +0000212// a mirror of combineBoundsRevDiff
213void SkClipStack::Element::combineBoundsDiff(FillCombo combination, const SkRect& prevFinite) {
214 switch (combination) {
215 case kInvPrev_InvCur_FillCombo:
216 // In this case the only pixels that can remain set
217 // are inside the current clip rect since the extensions
218 // to infinity of both clips cancel out and whatever
219 // is outside of the current clip is removed
robertphillips@google.com607fe072012-07-24 13:54:00 +0000220 fFiniteBoundType = kNormal_BoundsType;
bsalomon@google.com8a98e3b2012-11-29 21:05:13 +0000221 break;
222 case kInvPrev_Cur_FillCombo:
223 // In this case the current op is finite so the only pixels
224 // that aren't set are whatever isn't set in the previous
225 // clip and whatever this clip carves out
226 fFiniteBound.join(prevFinite);
227 fFiniteBoundType = kInsideOut_BoundsType;
228 break;
229 case kPrev_InvCur_FillCombo:
230 // In this case everything outside of this clip's bound
231 // is erased, so the only pixels that can remain set
232 // occur w/in the intersection of the two finite bounds
233 if (!fFiniteBound.intersect(prevFinite)) {
commit-bot@chromium.orge5b2af92014-02-16 13:25:24 +0000234 this->setEmpty();
235 } else {
236 fFiniteBoundType = kNormal_BoundsType;
robertphillips@google.com4c2a2f72012-07-24 22:07:50 +0000237 }
bsalomon@google.com8a98e3b2012-11-29 21:05:13 +0000238 break;
239 case kPrev_Cur_FillCombo:
240 // The most conservative result bound is that of the
241 // prior clip. This could be wildly incorrect if the
242 // second clip either exactly matches the first clip
243 // (which should yield the empty set) or reduces the
244 // size of the prior bound (e.g., if the second clip
245 // exactly matched the bottom half of the prior clip).
246 // We ignore these two possibilities.
247 fFiniteBound = prevFinite;
248 break;
249 default:
250 SkDEBUGFAIL("SkClipStack::Element::combineBoundsDiff Invalid fill combination");
251 break;
252 }
253}
robertphillips@google.com4c2a2f72012-07-24 22:07:50 +0000254
bsalomon@google.com8a98e3b2012-11-29 21:05:13 +0000255void SkClipStack::Element::combineBoundsXOR(int combination, const SkRect& prevFinite) {
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000256
bsalomon@google.com8a98e3b2012-11-29 21:05:13 +0000257 switch (combination) {
258 case kInvPrev_Cur_FillCombo: // fall through
259 case kPrev_InvCur_FillCombo:
260 // With only one of the clips inverted the result will always
261 // extend to infinity. The only pixels that may be un-writeable
262 // lie within the union of the two finite bounds
263 fFiniteBound.join(prevFinite);
264 fFiniteBoundType = kInsideOut_BoundsType;
265 break;
266 case kInvPrev_InvCur_FillCombo:
267 // The only pixels that can survive are within the
268 // union of the two bounding boxes since the extensions
269 // to infinity of both clips cancel out
270 // fall through!
271 case kPrev_Cur_FillCombo:
272 // The most conservative bound for xor is the
273 // union of the two bounds. If the two clips exactly overlapped
274 // the xor could yield the empty set. Similarly the xor
275 // could reduce the size of the original clip's bound (e.g.,
276 // if the second clip exactly matched the bottom half of the
277 // first clip). We ignore these two cases.
278 fFiniteBound.join(prevFinite);
279 fFiniteBoundType = kNormal_BoundsType;
280 break;
281 default:
282 SkDEBUGFAIL("SkClipStack::Element::combineBoundsXOR Invalid fill combination");
283 break;
284 }
285}
robertphillips@google.com607fe072012-07-24 13:54:00 +0000286
bsalomon@google.com8a98e3b2012-11-29 21:05:13 +0000287// a mirror of combineBoundsIntersection
288void SkClipStack::Element::combineBoundsUnion(int combination, const SkRect& prevFinite) {
289
290 switch (combination) {
291 case kInvPrev_InvCur_FillCombo:
292 if (!fFiniteBound.intersect(prevFinite)) {
293 fFiniteBound.setEmpty();
294 fGenID = kWideOpenGenID;
robertphillips@google.com607fe072012-07-24 13:54:00 +0000295 }
bsalomon@google.com8a98e3b2012-11-29 21:05:13 +0000296 fFiniteBoundType = kInsideOut_BoundsType;
297 break;
298 case kInvPrev_Cur_FillCombo:
299 // The only pixels that won't be drawable are inside
300 // the prior clip's finite bound
301 fFiniteBound = prevFinite;
302 fFiniteBoundType = kInsideOut_BoundsType;
303 break;
304 case kPrev_InvCur_FillCombo:
305 // The only pixels that won't be drawable are inside
306 // this clip's finite bound
307 break;
308 case kPrev_Cur_FillCombo:
309 fFiniteBound.join(prevFinite);
310 break;
311 default:
312 SkDEBUGFAIL("SkClipStack::Element::combineBoundsUnion Invalid fill combination");
313 break;
314 }
315}
316
317// a mirror of combineBoundsUnion
318void SkClipStack::Element::combineBoundsIntersection(int combination, const SkRect& prevFinite) {
319
320 switch (combination) {
321 case kInvPrev_InvCur_FillCombo:
322 // The only pixels that aren't writable in this case
323 // occur in the union of the two finite bounds
324 fFiniteBound.join(prevFinite);
325 fFiniteBoundType = kInsideOut_BoundsType;
326 break;
327 case kInvPrev_Cur_FillCombo:
328 // In this case the only pixels that will remain writeable
329 // are within the current clip
330 break;
331 case kPrev_InvCur_FillCombo:
332 // In this case the only pixels that will remain writeable
333 // are with the previous clip
334 fFiniteBound = prevFinite;
335 fFiniteBoundType = kNormal_BoundsType;
336 break;
337 case kPrev_Cur_FillCombo:
338 if (!fFiniteBound.intersect(prevFinite)) {
commit-bot@chromium.orge5b2af92014-02-16 13:25:24 +0000339 this->setEmpty();
bsalomon@google.com8a98e3b2012-11-29 21:05:13 +0000340 }
341 break;
342 default:
343 SkDEBUGFAIL("SkClipStack::Element::combineBoundsIntersection Invalid fill combination");
344 break;
345 }
346}
347
348// a mirror of combineBoundsDiff
349void SkClipStack::Element::combineBoundsRevDiff(int combination, const SkRect& prevFinite) {
350
351 switch (combination) {
352 case kInvPrev_InvCur_FillCombo:
353 // The only pixels that can survive are in the
354 // previous bound since the extensions to infinity in
355 // both clips cancel out
356 fFiniteBound = prevFinite;
357 fFiniteBoundType = kNormal_BoundsType;
358 break;
359 case kInvPrev_Cur_FillCombo:
360 if (!fFiniteBound.intersect(prevFinite)) {
commit-bot@chromium.orge5b2af92014-02-16 13:25:24 +0000361 this->setEmpty();
362 } else {
363 fFiniteBoundType = kNormal_BoundsType;
bsalomon@google.com8a98e3b2012-11-29 21:05:13 +0000364 }
bsalomon@google.com8a98e3b2012-11-29 21:05:13 +0000365 break;
366 case kPrev_InvCur_FillCombo:
367 fFiniteBound.join(prevFinite);
368 fFiniteBoundType = kInsideOut_BoundsType;
369 break;
370 case kPrev_Cur_FillCombo:
371 // Fall through - as with the kDifference_Op case, the
372 // most conservative result bound is the bound of the
373 // current clip. The prior clip could reduce the size of this
374 // bound (as in the kDifference_Op case) but we are ignoring
375 // those cases.
376 break;
377 default:
378 SkDEBUGFAIL("SkClipStack::Element::combineBoundsRevDiff Invalid fill combination");
379 break;
380 }
381}
382
383void SkClipStack::Element::updateBoundAndGenID(const Element* prior) {
384 // We set this first here but we may overwrite it later if we determine that the clip is
385 // either wide-open or empty.
386 fGenID = GetNextGenID();
387
388 // First, optimistically update the current Element's bound information
389 // with the current clip's bound
390 fIsIntersectionOfRects = false;
commit-bot@chromium.orge5b2af92014-02-16 13:25:24 +0000391 switch (fType) {
392 case kRect_Type:
commit-bot@chromium.org032a52f2014-02-21 20:09:13 +0000393 fFiniteBound = this->getRect();
bsalomon@google.com8a98e3b2012-11-29 21:05:13 +0000394 fFiniteBoundType = kNormal_BoundsType;
commit-bot@chromium.orge5b2af92014-02-16 13:25:24 +0000395
396 if (SkRegion::kReplace_Op == fOp ||
397 (SkRegion::kIntersect_Op == fOp && NULL == prior) ||
398 (SkRegion::kIntersect_Op == fOp && prior->fIsIntersectionOfRects &&
commit-bot@chromium.org032a52f2014-02-21 20:09:13 +0000399 prior->rectRectIntersectAllowed(this->getRect(), fDoAA))) {
commit-bot@chromium.orge5b2af92014-02-16 13:25:24 +0000400 fIsIntersectionOfRects = true;
401 }
402 break;
403 case kRRect_Type:
404 fFiniteBound = fRRect.getBounds();
405 fFiniteBoundType = kNormal_BoundsType;
406 break;
407 case kPath_Type:
commit-bot@chromium.org6f954b92014-02-27 17:39:46 +0000408 fFiniteBound = fPath.get()->getBounds();
commit-bot@chromium.orge5b2af92014-02-16 13:25:24 +0000409
commit-bot@chromium.org6f954b92014-02-27 17:39:46 +0000410 if (fPath.get()->isInverseFillType()) {
commit-bot@chromium.orge5b2af92014-02-16 13:25:24 +0000411 fFiniteBoundType = kInsideOut_BoundsType;
412 } else {
413 fFiniteBoundType = kNormal_BoundsType;
414 }
415 break;
416 case kEmpty_Type:
417 SkDEBUGFAIL("We shouldn't get here with an empty element.");
418 break;
robertphillips@google.com607fe072012-07-24 13:54:00 +0000419 }
bsalomon@google.com8a98e3b2012-11-29 21:05:13 +0000420
421 if (!fDoAA) {
422 // Here we mimic a non-anti-aliased scanline system. If there is
423 // no anti-aliasing we can integerize the bounding box to exclude
424 // fractional parts that won't be rendered.
425 // Note: the left edge is handled slightly differently below. We
426 // are a bit more generous in the rounding since we don't want to
427 // risk missing the left pixels when fLeft is very close to .5
reed@google.come1ca7052013-12-17 19:22:07 +0000428 fFiniteBound.set(SkScalarFloorToScalar(fFiniteBound.fLeft+0.45f),
429 SkScalarRoundToScalar(fFiniteBound.fTop),
430 SkScalarRoundToScalar(fFiniteBound.fRight),
431 SkScalarRoundToScalar(fFiniteBound.fBottom));
bsalomon@google.com8a98e3b2012-11-29 21:05:13 +0000432 }
433
434 // 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
439 if (NULL == prior) {
440 // 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();
537 element != NULL;
538 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
bsalomon@google.com9128edc2012-11-29 18:58:19 +0000558 while (myElement != NULL && bElement != NULL) {
559 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 }
bsalomon@google.com9128edc2012-11-29 18:58:19 +0000565 return myElement == NULL && bElement == NULL;
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
bsalomon@google.com9128edc2012-11-29 18:58:19 +0000607 if (NULL == 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
bsalomon@google.com3ab43d52012-10-11 19:39:09 +0000624bool SkClipStack::intersectRectWithClip(SkRect* rect) const {
bsalomon49f085d2014-09-05 13:34:00 -0700625 SkASSERT(rect);
bsalomon@google.com3ab43d52012-10-11 19:39:09 +0000626
627 SkRect bounds;
628 SkClipStack::BoundsType bt;
629 this->getBounds(&bounds, &bt);
630 if (bt == SkClipStack::kInsideOut_BoundsType) {
631 if (bounds.contains(*rect)) {
632 return false;
633 } else {
634 // If rect's x values are both within bound's x range we
635 // could clip here. Same for y. But we don't bother to check.
636 return true;
637 }
skia.committer@gmail.com5b6f9162012-10-12 02:01:15 +0000638 } else {
bsalomon@google.com3ab43d52012-10-11 19:39:09 +0000639 return rect->intersect(bounds);
640 }
641}
642
junov@chromium.org8cdf0f52012-12-12 17:58:15 +0000643bool SkClipStack::quickContains(const SkRect& rect) const {
644
645 Iter iter(*this, Iter::kTop_IterStart);
646 const Element* element = iter.prev();
647 while (element != NULL) {
648 if (SkRegion::kIntersect_Op != element->getOp() && SkRegion::kReplace_Op != element->getOp())
649 return false;
650 if (element->isInverseFilled()) {
651 // Part of 'rect' could be trimmed off by the inverse-filled clip element
652 if (SkRect::Intersects(element->getBounds(), rect)) {
653 return false;
654 }
655 } else {
656 if (!element->contains(rect)) {
657 return false;
658 }
659 }
660 if (SkRegion::kReplace_Op == element->getOp()) {
661 break;
662 }
663 element = iter.prev();
664 }
665 return true;
666}
667
commit-bot@chromium.orge5b2af92014-02-16 13:25:24 +0000668void SkClipStack::pushElement(const Element& element) {
robertphillips@google.com63ae1cf2012-08-17 13:53:05 +0000669 // Use reverse iterator instead of back because Rect path may need previous
robertphillips@google.com4c2a2f72012-07-24 22:07:50 +0000670 SkDeque::Iter iter(fDeque, SkDeque::Iter::kBack_IterStart);
commit-bot@chromium.orge5b2af92014-02-16 13:25:24 +0000671 Element* prior = (Element*) iter.prev();
robertphillips@google.com4c2a2f72012-07-24 22:07:50 +0000672
bsalomon49f085d2014-09-05 13:34:00 -0700673 if (prior) {
commit-bot@chromium.orge5b2af92014-02-16 13:25:24 +0000674 if (prior->canBeIntersectedInPlace(fSaveCount, element.getOp())) {
675 switch (prior->fType) {
commit-bot@chromium.org6fbe54c2013-06-11 11:01:48 +0000676 case Element::kEmpty_Type:
commit-bot@chromium.orge5b2af92014-02-16 13:25:24 +0000677 SkDEBUGCODE(prior->checkEmpty();)
commit-bot@chromium.org6fbe54c2013-06-11 11:01:48 +0000678 return;
679 case Element::kRect_Type:
commit-bot@chromium.orge5b2af92014-02-16 13:25:24 +0000680 if (Element::kRect_Type == element.getType()) {
681 if (prior->rectRectIntersectAllowed(element.getRect(), element.isAA())) {
commit-bot@chromium.org032a52f2014-02-21 20:09:13 +0000682 SkRect isectRect;
683 if (!isectRect.intersect(prior->getRect(), element.getRect())) {
commit-bot@chromium.orge5b2af92014-02-16 13:25:24 +0000684 prior->setEmpty();
685 return;
686 }
687
commit-bot@chromium.org032a52f2014-02-21 20:09:13 +0000688 prior->fRRect.setRect(isectRect);
commit-bot@chromium.orge5b2af92014-02-16 13:25:24 +0000689 prior->fDoAA = element.isAA();
690 Element* priorPrior = (Element*) iter.prev();
691 prior->updateBoundAndGenID(priorPrior);
commit-bot@chromium.org6fbe54c2013-06-11 11:01:48 +0000692 return;
693 }
commit-bot@chromium.orge5b2af92014-02-16 13:25:24 +0000694 break;
commit-bot@chromium.org6fbe54c2013-06-11 11:01:48 +0000695 }
commit-bot@chromium.orge5b2af92014-02-16 13:25:24 +0000696 // fallthrough
697 default:
698 if (!SkRect::Intersects(prior->getBounds(), element.getBounds())) {
699 prior->setEmpty();
robertphillips@google.com08eacc12012-08-02 12:49:00 +0000700 return;
701 }
commit-bot@chromium.org6fbe54c2013-06-11 11:01:48 +0000702 break;
703 }
commit-bot@chromium.orge5b2af92014-02-16 13:25:24 +0000704 } else if (SkRegion::kReplace_Op == element.getOp()) {
commit-bot@chromium.org6fbe54c2013-06-11 11:01:48 +0000705 this->restoreTo(fSaveCount - 1);
commit-bot@chromium.orge5b2af92014-02-16 13:25:24 +0000706 prior = (Element*) fDeque.back();
reed@google.com5c3d1472011-02-22 19:12:23 +0000707 }
708 }
commit-bot@chromium.orge5b2af92014-02-16 13:25:24 +0000709 Element* newElement = SkNEW_PLACEMENT_ARGS(fDeque.push_back(), Element, (element));
710 newElement->updateBoundAndGenID(prior);
711}
712
713void SkClipStack::clipDevRRect(const SkRRect& rrect, SkRegion::Op op, bool doAA) {
714 Element element(fSaveCount, rrect, op, doAA);
715 this->pushElement(element);
716}
717
718void SkClipStack::clipDevRect(const SkRect& rect, SkRegion::Op op, bool doAA) {
719 Element element(fSaveCount, rect, op, doAA);
720 this->pushElement(element);
reed@google.com5c3d1472011-02-22 19:12:23 +0000721}
722
reed@google.com00177082011-10-12 14:34:30 +0000723void SkClipStack::clipDevPath(const SkPath& path, SkRegion::Op op, bool doAA) {
commit-bot@chromium.orge5b2af92014-02-16 13:25:24 +0000724 Element element(fSaveCount, path, op, doAA);
725 this->pushElement(element);
reed@google.com5c3d1472011-02-22 19:12:23 +0000726}
727
reed@google.com0557d9e2012-08-16 15:59:59 +0000728void SkClipStack::clipEmpty() {
bsalomon@google.com9128edc2012-11-29 18:58:19 +0000729 Element* element = (Element*) fDeque.back();
robertphillips@google.com63ae1cf2012-08-17 13:53:05 +0000730
bsalomon@google.com9128edc2012-11-29 18:58:19 +0000731 if (element && element->canBeIntersectedInPlace(fSaveCount, SkRegion::kIntersect_Op)) {
commit-bot@chromium.orge5b2af92014-02-16 13:25:24 +0000732 element->setEmpty();
reed@google.com0557d9e2012-08-16 15:59:59 +0000733 }
bsalomon@google.com9128edc2012-11-29 18:58:19 +0000734 new (fDeque.push_back()) Element(fSaveCount);
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000735
bsalomon@google.com9128edc2012-11-29 18:58:19 +0000736 ((Element*)fDeque.back())->fGenID = kEmptyGenID;
reed@google.com0557d9e2012-08-16 15:59:59 +0000737}
738
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000739bool SkClipStack::isWideOpen() const {
commit-bot@chromium.orgd3e58422013-11-05 15:03:08 +0000740 return this->getTopmostGenID() == kWideOpenGenID;
robertphillips@google.comcc6493b2012-07-26 18:39:13 +0000741}
742
reed@google.com5c3d1472011-02-22 19:12:23 +0000743///////////////////////////////////////////////////////////////////////////////
744
robertphillips@google.com5836b6d2012-07-18 12:06:15 +0000745SkClipStack::Iter::Iter() : fStack(NULL) {
bsalomon@google.comd302f142011-03-03 13:54:13 +0000746}
747
robertphillips@google.com5836b6d2012-07-18 12:06:15 +0000748SkClipStack::Iter::Iter(const SkClipStack& stack, IterStart startLoc)
749 : fStack(&stack) {
robertphillips@google.com52cb2c72012-07-16 18:52:29 +0000750 this->reset(stack, startLoc);
reed@google.com5c3d1472011-02-22 19:12:23 +0000751}
752
bsalomon@google.com8182fa02012-12-04 14:06:06 +0000753const SkClipStack::Element* SkClipStack::Iter::next() {
754 return (const SkClipStack::Element*)fIter.next();
reed@google.com5c3d1472011-02-22 19:12:23 +0000755}
bsalomon@google.comd302f142011-03-03 13:54:13 +0000756
bsalomon@google.com8182fa02012-12-04 14:06:06 +0000757const SkClipStack::Element* SkClipStack::Iter::prev() {
758 return (const SkClipStack::Element*)fIter.prev();
robertphillips@google.com52cb2c72012-07-16 18:52:29 +0000759}
760
bsalomon@google.com8182fa02012-12-04 14:06:06 +0000761const SkClipStack::Element* SkClipStack::Iter::skipToTopmost(SkRegion::Op op) {
robertphillips@google.com5836b6d2012-07-18 12:06:15 +0000762
763 if (NULL == fStack) {
764 return NULL;
765 }
766
767 fIter.reset(fStack->fDeque, SkDeque::Iter::kBack_IterStart);
768
bsalomon@google.com9128edc2012-11-29 18:58:19 +0000769 const SkClipStack::Element* element = NULL;
robertphillips@google.com5836b6d2012-07-18 12:06:15 +0000770
bsalomon@google.com9128edc2012-11-29 18:58:19 +0000771 for (element = (const SkClipStack::Element*) fIter.prev();
bsalomon49f085d2014-09-05 13:34:00 -0700772 element;
bsalomon@google.com9128edc2012-11-29 18:58:19 +0000773 element = (const SkClipStack::Element*) fIter.prev()) {
robertphillips@google.com5836b6d2012-07-18 12:06:15 +0000774
bsalomon@google.com9128edc2012-11-29 18:58:19 +0000775 if (op == element->fOp) {
robertphillips@google.com5836b6d2012-07-18 12:06:15 +0000776 // The Deque's iterator is actually one pace ahead of the
bsalomon@google.com9128edc2012-11-29 18:58:19 +0000777 // returned value. So while "element" is the element we want to
robertphillips@google.com5836b6d2012-07-18 12:06:15 +0000778 // return, the iterator is actually pointing at (and will
779 // return on the next "next" or "prev" call) the element
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000780 // in front of it in the deque. Bump the iterator forward a
robertphillips@google.com5836b6d2012-07-18 12:06:15 +0000781 // step so we get the expected result.
782 if (NULL == fIter.next()) {
783 // The reverse iterator has run off the front of the deque
784 // (i.e., the "op" clip is the first clip) and can't
785 // recover. Reset the iterator to start at the front.
786 fIter.reset(fStack->fDeque, SkDeque::Iter::kFront_IterStart);
787 }
788 break;
789 }
790 }
791
bsalomon@google.com9128edc2012-11-29 18:58:19 +0000792 if (NULL == element) {
robertphillips@google.com5836b6d2012-07-18 12:06:15 +0000793 // There were no "op" clips
794 fIter.reset(fStack->fDeque, SkDeque::Iter::kFront_IterStart);
795 }
796
797 return this->next();
798}
799
robertphillips@google.com52cb2c72012-07-16 18:52:29 +0000800void SkClipStack::Iter::reset(const SkClipStack& stack, IterStart startLoc) {
robertphillips@google.coma6f11c42012-07-23 17:39:44 +0000801 fStack = &stack;
robertphillips@google.com52cb2c72012-07-16 18:52:29 +0000802 fIter.reset(stack.fDeque, static_cast<SkDeque::Iter::IterStart>(startLoc));
bsalomon@google.comd302f142011-03-03 13:54:13 +0000803}
robertphillips@google.com607fe072012-07-24 13:54:00 +0000804
805// helper method
806void SkClipStack::getConservativeBounds(int offsetX,
807 int offsetY,
808 int maxWidth,
809 int maxHeight,
robertphillips@google.com7b112892012-07-31 15:18:21 +0000810 SkRect* devBounds,
robertphillips@google.com4c2a2f72012-07-24 22:07:50 +0000811 bool* isIntersectionOfRects) const {
bsalomon49f085d2014-09-05 13:34:00 -0700812 SkASSERT(devBounds);
robertphillips@google.com607fe072012-07-24 13:54:00 +0000813
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000814 devBounds->setLTRB(0, 0,
robertphillips@google.com7b112892012-07-31 15:18:21 +0000815 SkIntToScalar(maxWidth), SkIntToScalar(maxHeight));
robertphillips@google.com607fe072012-07-24 13:54:00 +0000816
817 SkRect temp;
818 SkClipStack::BoundsType boundType;
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000819
robertphillips@google.com7b112892012-07-31 15:18:21 +0000820 // temp starts off in canvas space here
robertphillips@google.com4c2a2f72012-07-24 22:07:50 +0000821 this->getBounds(&temp, &boundType, isIntersectionOfRects);
robertphillips@google.com607fe072012-07-24 13:54:00 +0000822 if (SkClipStack::kInsideOut_BoundsType == boundType) {
823 return;
824 }
825
robertphillips@google.com7b112892012-07-31 15:18:21 +0000826 // but is converted to device space here
robertphillips@google.com607fe072012-07-24 13:54:00 +0000827 temp.offset(SkIntToScalar(offsetX), SkIntToScalar(offsetY));
828
robertphillips@google.com7b112892012-07-31 15:18:21 +0000829 if (!devBounds->intersect(temp)) {
830 devBounds->setEmpty();
robertphillips@google.com607fe072012-07-24 13:54:00 +0000831 }
832}
robertphillips@google.com46f93502012-08-07 15:38:08 +0000833
robertphillips@google.com46f93502012-08-07 15:38:08 +0000834int32_t SkClipStack::GetNextGenID() {
bsalomon@google.comedb26fd2012-11-28 14:42:41 +0000835 // TODO: handle overflow.
robertphillips@google.com46f93502012-08-07 15:38:08 +0000836 return sk_atomic_inc(&gGenID);
837}
robertphillips@google.com73e71022012-08-09 18:10:49 +0000838
839int32_t SkClipStack::getTopmostGenID() const {
robertphillips@google.com73e71022012-08-09 18:10:49 +0000840 if (fDeque.empty()) {
commit-bot@chromium.orgd3e58422013-11-05 15:03:08 +0000841 return kWideOpenGenID;
robertphillips@google.com73e71022012-08-09 18:10:49 +0000842 }
843
commit-bot@chromium.orgd3e58422013-11-05 15:03:08 +0000844 const Element* back = static_cast<const Element*>(fDeque.back());
845 if (kInsideOut_BoundsType == back->fFiniteBoundType && back->fFiniteBound.isEmpty()) {
846 return kWideOpenGenID;
847 }
848
849 return back->getGenID();
robertphillips@google.com73e71022012-08-09 18:10:49 +0000850}
bsalomonb6b02522014-06-09 07:59:06 -0700851
852#ifdef SK_DEVELOPER
853void SkClipStack::Element::dump() const {
854 static const char* kTypeStrings[] = {
855 "empty",
856 "rect",
857 "rrect",
858 "path"
859 };
860 SK_COMPILE_ASSERT(0 == kEmpty_Type, type_str);
861 SK_COMPILE_ASSERT(1 == kRect_Type, type_str);
862 SK_COMPILE_ASSERT(2 == kRRect_Type, type_str);
863 SK_COMPILE_ASSERT(3 == kPath_Type, type_str);
864 SK_COMPILE_ASSERT(SK_ARRAY_COUNT(kTypeStrings) == kTypeCnt, type_str);
865
866 static const char* kOpStrings[] = {
867 "difference",
868 "intersect",
869 "union",
870 "xor",
871 "reverse-difference",
872 "replace",
873 };
874 SK_COMPILE_ASSERT(0 == SkRegion::kDifference_Op, op_str);
875 SK_COMPILE_ASSERT(1 == SkRegion::kIntersect_Op, op_str);
876 SK_COMPILE_ASSERT(2 == SkRegion::kUnion_Op, op_str);
877 SK_COMPILE_ASSERT(3 == SkRegion::kXOR_Op, op_str);
878 SK_COMPILE_ASSERT(4 == SkRegion::kReverseDifference_Op, op_str);
879 SK_COMPILE_ASSERT(5 == SkRegion::kReplace_Op, op_str);
880 SK_COMPILE_ASSERT(SK_ARRAY_COUNT(kOpStrings) == SkRegion::kOpCnt, op_str);
881
882 SkDebugf("Type: %s, Op: %s, AA: %s, Save Count: %d\n", kTypeStrings[fType],
883 kOpStrings[fOp], (fDoAA ? "yes" : "no"), fSaveCount);
884 switch (fType) {
885 case kEmpty_Type:
886 SkDebugf("\n");
887 break;
888 case kRect_Type:
889 this->getRect().dump();
890 SkDebugf("\n");
891 break;
892 case kRRect_Type:
893 this->getRRect().dump();
894 SkDebugf("\n");
895 break;
896 case kPath_Type:
caryclarke9562592014-09-15 09:26:09 -0700897 this->getPath().dump(NULL, true, false);
bsalomonb6b02522014-06-09 07:59:06 -0700898 break;
899 }
900}
901
902void SkClipStack::dump() const {
903 B2TIter iter(*this);
904 const Element* e;
905 while ((e = iter.next())) {
906 e->dump();
907 SkDebugf("\n");
908 }
909}
910#endif