blob: 2d8c94f0f713197667d1ae78a3095db86560904f [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"
fmalita1a481fe2015-02-04 07:39:34 -080011#include "SkPathOps.h"
robertphillips@google.com46f93502012-08-07 15:38:08 +000012#include "SkThread.h"
13
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 ||
398 (SkRegion::kIntersect_Op == fOp && NULL == prior) ||
399 (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
robertphillips7f14c9b2015-01-30 14:44:22 -0800422 if (!fDoAA) {
423 // Here we mimic a non-anti-aliased scanline system. If there is
424 // no anti-aliasing we can integerize the bounding box to exclude
425 // fractional parts that won't be rendered.
426 // Note: the left edge is handled slightly differently below. We
427 // are a bit more generous in the rounding since we don't want to
428 // risk missing the left pixels when fLeft is very close to .5
429 fFiniteBound.set(SkScalarFloorToScalar(fFiniteBound.fLeft+0.45f),
430 SkScalarRoundToScalar(fFiniteBound.fTop),
431 SkScalarRoundToScalar(fFiniteBound.fRight),
432 SkScalarRoundToScalar(fFiniteBound.fBottom));
433 }
434
bsalomon@google.com8a98e3b2012-11-29 21:05:13 +0000435 // Now determine the previous Element's bound information taking into
436 // account that there may be no previous clip
437 SkRect prevFinite;
438 SkClipStack::BoundsType prevType;
439
440 if (NULL == prior) {
441 // no prior clip means the entire plane is writable
442 prevFinite.setEmpty(); // there are no pixels that cannot be drawn to
443 prevType = kInsideOut_BoundsType;
444 } else {
445 prevFinite = prior->fFiniteBound;
446 prevType = prior->fFiniteBoundType;
447 }
448
449 FillCombo combination = kPrev_Cur_FillCombo;
450 if (kInsideOut_BoundsType == fFiniteBoundType) {
451 combination = (FillCombo) (combination | 0x01);
452 }
453 if (kInsideOut_BoundsType == prevType) {
454 combination = (FillCombo) (combination | 0x02);
455 }
456
457 SkASSERT(kInvPrev_InvCur_FillCombo == combination ||
458 kInvPrev_Cur_FillCombo == combination ||
459 kPrev_InvCur_FillCombo == combination ||
460 kPrev_Cur_FillCombo == combination);
461
462 // Now integrate with clip with the prior clips
463 switch (fOp) {
464 case SkRegion::kDifference_Op:
465 this->combineBoundsDiff(combination, prevFinite);
466 break;
467 case SkRegion::kXOR_Op:
468 this->combineBoundsXOR(combination, prevFinite);
469 break;
470 case SkRegion::kUnion_Op:
471 this->combineBoundsUnion(combination, prevFinite);
472 break;
473 case SkRegion::kIntersect_Op:
474 this->combineBoundsIntersection(combination, prevFinite);
475 break;
476 case SkRegion::kReverseDifference_Op:
477 this->combineBoundsRevDiff(combination, prevFinite);
478 break;
479 case SkRegion::kReplace_Op:
480 // Replace just ignores everything prior
481 // The current clip's bound information is already filled in
482 // so nothing to do
483 break;
484 default:
commit-bot@chromium.orge5b2af92014-02-16 13:25:24 +0000485 SkDebugf("SkRegion::Op error\n");
bsalomon@google.com8a98e3b2012-11-29 21:05:13 +0000486 SkASSERT(0);
487 break;
488 }
489}
reed@google.com5c3d1472011-02-22 19:12:23 +0000490
bsalomon@google.com9128edc2012-11-29 18:58:19 +0000491// This constant determines how many Element's are allocated together as a block in
robertphillips@google.comf9a90842012-08-17 14:25:43 +0000492// the deque. As such it needs to balance allocating too much memory vs.
493// incurring allocation/deallocation thrashing. It should roughly correspond to
494// the deepest save/restore stack we expect to see.
bsalomon@google.com9128edc2012-11-29 18:58:19 +0000495static const int kDefaultElementAllocCnt = 8;
robertphillips@google.com46f93502012-08-07 15:38:08 +0000496
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000497SkClipStack::SkClipStack()
bsalomon@google.com9128edc2012-11-29 18:58:19 +0000498 : fDeque(sizeof(Element), kDefaultElementAllocCnt)
robertphillips@google.com46f93502012-08-07 15:38:08 +0000499 , fSaveCount(0) {
reed@google.com5c3d1472011-02-22 19:12:23 +0000500}
501
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000502SkClipStack::SkClipStack(const SkClipStack& b)
bsalomon@google.com9128edc2012-11-29 18:58:19 +0000503 : fDeque(sizeof(Element), kDefaultElementAllocCnt) {
vandebo@chromium.org1e1c36f2011-05-03 16:26:09 +0000504 *this = b;
505}
506
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000507SkClipStack::SkClipStack(const SkRect& r)
bsalomon@google.com9128edc2012-11-29 18:58:19 +0000508 : fDeque(sizeof(Element), kDefaultElementAllocCnt)
robertphillips@google.com46f93502012-08-07 15:38:08 +0000509 , fSaveCount(0) {
robertphillips@google.comcc6493b2012-07-26 18:39:13 +0000510 if (!r.isEmpty()) {
511 this->clipDevRect(r, SkRegion::kReplace_Op, false);
512 }
513}
514
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000515SkClipStack::SkClipStack(const SkIRect& r)
bsalomon@google.com9128edc2012-11-29 18:58:19 +0000516 : fDeque(sizeof(Element), kDefaultElementAllocCnt)
robertphillips@google.com46f93502012-08-07 15:38:08 +0000517 , fSaveCount(0) {
robertphillips@google.com641f8b12012-07-31 19:15:58 +0000518 if (!r.isEmpty()) {
519 SkRect temp;
520 temp.set(r);
521 this->clipDevRect(temp, SkRegion::kReplace_Op, false);
522 }
523}
524
vandebo@chromium.org610f7162012-03-14 18:34:15 +0000525SkClipStack::~SkClipStack() {
526 reset();
527}
528
vandebo@chromium.org1e1c36f2011-05-03 16:26:09 +0000529SkClipStack& SkClipStack::operator=(const SkClipStack& b) {
530 if (this == &b) {
531 return *this;
532 }
533 reset();
534
535 fSaveCount = b.fSaveCount;
536 SkDeque::F2BIter recIter(b.fDeque);
bsalomon@google.com9128edc2012-11-29 18:58:19 +0000537 for (const Element* element = (const Element*)recIter.next();
538 element != NULL;
539 element = (const Element*)recIter.next()) {
540 new (fDeque.push_back()) Element(*element);
vandebo@chromium.org1e1c36f2011-05-03 16:26:09 +0000541 }
542
543 return *this;
544}
545
546bool SkClipStack::operator==(const SkClipStack& b) const {
commit-bot@chromium.org86b39f32014-01-06 16:54:20 +0000547 if (this->getTopmostGenID() == b.getTopmostGenID()) {
548 return true;
549 }
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000550 if (fSaveCount != b.fSaveCount ||
robertphillips@google.com46f93502012-08-07 15:38:08 +0000551 fDeque.count() != b.fDeque.count()) {
vandebo@chromium.org1e1c36f2011-05-03 16:26:09 +0000552 return false;
553 }
554 SkDeque::F2BIter myIter(fDeque);
555 SkDeque::F2BIter bIter(b.fDeque);
bsalomon@google.com9128edc2012-11-29 18:58:19 +0000556 const Element* myElement = (const Element*)myIter.next();
557 const Element* bElement = (const Element*)bIter.next();
vandebo@chromium.org1e1c36f2011-05-03 16:26:09 +0000558
bsalomon@google.com9128edc2012-11-29 18:58:19 +0000559 while (myElement != NULL && bElement != NULL) {
560 if (*myElement != *bElement) {
vandebo@chromium.org1e1c36f2011-05-03 16:26:09 +0000561 return false;
562 }
bsalomon@google.com9128edc2012-11-29 18:58:19 +0000563 myElement = (const Element*)myIter.next();
564 bElement = (const Element*)bIter.next();
vandebo@chromium.org1e1c36f2011-05-03 16:26:09 +0000565 }
bsalomon@google.com9128edc2012-11-29 18:58:19 +0000566 return myElement == NULL && bElement == NULL;
vandebo@chromium.org1e1c36f2011-05-03 16:26:09 +0000567}
568
reed@google.com5c3d1472011-02-22 19:12:23 +0000569void SkClipStack::reset() {
vandebo@chromium.org610f7162012-03-14 18:34:15 +0000570 // We used a placement new for each object in fDeque, so we're responsible
571 // for calling the destructor on each of them as well.
572 while (!fDeque.empty()) {
bsalomon@google.com9128edc2012-11-29 18:58:19 +0000573 Element* element = (Element*)fDeque.back();
574 element->~Element();
vandebo@chromium.org610f7162012-03-14 18:34:15 +0000575 fDeque.pop_back();
576 }
reed@google.com5c3d1472011-02-22 19:12:23 +0000577
578 fSaveCount = 0;
579}
580
581void SkClipStack::save() {
582 fSaveCount += 1;
583}
584
585void SkClipStack::restore() {
586 fSaveCount -= 1;
commit-bot@chromium.org6fbe54c2013-06-11 11:01:48 +0000587 restoreTo(fSaveCount);
588}
589
590void SkClipStack::restoreTo(int saveCount) {
reed@google.com5c3d1472011-02-22 19:12:23 +0000591 while (!fDeque.empty()) {
bsalomon@google.com9128edc2012-11-29 18:58:19 +0000592 Element* element = (Element*)fDeque.back();
commit-bot@chromium.org6fbe54c2013-06-11 11:01:48 +0000593 if (element->fSaveCount <= saveCount) {
reed@google.com5c3d1472011-02-22 19:12:23 +0000594 break;
595 }
bsalomon@google.com9128edc2012-11-29 18:58:19 +0000596 element->~Element();
reed@google.com5c3d1472011-02-22 19:12:23 +0000597 fDeque.pop_back();
598 }
599}
600
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000601void SkClipStack::getBounds(SkRect* canvFiniteBound,
robertphillips@google.com4c2a2f72012-07-24 22:07:50 +0000602 BoundsType* boundType,
603 bool* isIntersectionOfRects) const {
bsalomon49f085d2014-09-05 13:34:00 -0700604 SkASSERT(canvFiniteBound && boundType);
robertphillips@google.com607fe072012-07-24 13:54:00 +0000605
bsalomon@google.com9128edc2012-11-29 18:58:19 +0000606 Element* element = (Element*)fDeque.back();
robertphillips@google.com607fe072012-07-24 13:54:00 +0000607
bsalomon@google.com9128edc2012-11-29 18:58:19 +0000608 if (NULL == element) {
robertphillips@google.com607fe072012-07-24 13:54:00 +0000609 // the clip is wide open - the infinite plane w/ no pixels un-writeable
robertphillips@google.com7b112892012-07-31 15:18:21 +0000610 canvFiniteBound->setEmpty();
robertphillips@google.com607fe072012-07-24 13:54:00 +0000611 *boundType = kInsideOut_BoundsType;
bsalomon49f085d2014-09-05 13:34:00 -0700612 if (isIntersectionOfRects) {
robertphillips@google.com4c2a2f72012-07-24 22:07:50 +0000613 *isIntersectionOfRects = false;
614 }
robertphillips@google.com607fe072012-07-24 13:54:00 +0000615 return;
616 }
617
bsalomon@google.com9128edc2012-11-29 18:58:19 +0000618 *canvFiniteBound = element->fFiniteBound;
619 *boundType = element->fFiniteBoundType;
bsalomon49f085d2014-09-05 13:34:00 -0700620 if (isIntersectionOfRects) {
bsalomon@google.com9128edc2012-11-29 18:58:19 +0000621 *isIntersectionOfRects = element->fIsIntersectionOfRects;
robertphillips@google.com4c2a2f72012-07-24 22:07:50 +0000622 }
robertphillips@google.com607fe072012-07-24 13:54:00 +0000623}
624
bsalomon@google.com3ab43d52012-10-11 19:39:09 +0000625bool SkClipStack::intersectRectWithClip(SkRect* rect) const {
bsalomon49f085d2014-09-05 13:34:00 -0700626 SkASSERT(rect);
bsalomon@google.com3ab43d52012-10-11 19:39:09 +0000627
628 SkRect bounds;
629 SkClipStack::BoundsType bt;
630 this->getBounds(&bounds, &bt);
631 if (bt == SkClipStack::kInsideOut_BoundsType) {
632 if (bounds.contains(*rect)) {
633 return false;
634 } else {
635 // If rect's x values are both within bound's x range we
636 // could clip here. Same for y. But we don't bother to check.
637 return true;
638 }
skia.committer@gmail.com5b6f9162012-10-12 02:01:15 +0000639 } else {
bsalomon@google.com3ab43d52012-10-11 19:39:09 +0000640 return rect->intersect(bounds);
641 }
642}
643
junov@chromium.org8cdf0f52012-12-12 17:58:15 +0000644bool SkClipStack::quickContains(const SkRect& rect) const {
645
646 Iter iter(*this, Iter::kTop_IterStart);
647 const Element* element = iter.prev();
648 while (element != NULL) {
649 if (SkRegion::kIntersect_Op != element->getOp() && SkRegion::kReplace_Op != element->getOp())
650 return false;
651 if (element->isInverseFilled()) {
652 // Part of 'rect' could be trimmed off by the inverse-filled clip element
653 if (SkRect::Intersects(element->getBounds(), rect)) {
654 return false;
655 }
656 } else {
657 if (!element->contains(rect)) {
658 return false;
659 }
660 }
661 if (SkRegion::kReplace_Op == element->getOp()) {
662 break;
663 }
664 element = iter.prev();
665 }
666 return true;
667}
668
fmalita1a481fe2015-02-04 07:39:34 -0800669bool SkClipStack::asPath(SkPath *path) const {
670 bool isAA = false;
671
672 path->reset();
673 path->setFillType(SkPath::kInverseEvenOdd_FillType);
674
675 SkClipStack::Iter iter(*this, SkClipStack::Iter::kBottom_IterStart);
676 while (const SkClipStack::Element* element = iter.next()) {
677 SkPath operand;
678 if (element->getType() != SkClipStack::Element::kEmpty_Type) {
679 element->asPath(&operand);
680 }
681
682 SkRegion::Op elementOp = element->getOp();
683 if (elementOp == SkRegion::kReplace_Op) {
684 *path = operand;
685 } else {
686 Op(*path, operand, (SkPathOp)elementOp, path);
687 }
688
689 // if the prev and curr clips disagree about aa -vs- not, favor the aa request.
690 // perhaps we need an API change to avoid this sort of mixed-signals about
691 // clipping.
692 isAA = (isAA || element->isAA());
693 }
694
695 return isAA;
696}
697
commit-bot@chromium.orge5b2af92014-02-16 13:25:24 +0000698void SkClipStack::pushElement(const Element& element) {
robertphillips@google.com63ae1cf2012-08-17 13:53:05 +0000699 // Use reverse iterator instead of back because Rect path may need previous
robertphillips@google.com4c2a2f72012-07-24 22:07:50 +0000700 SkDeque::Iter iter(fDeque, SkDeque::Iter::kBack_IterStart);
commit-bot@chromium.orge5b2af92014-02-16 13:25:24 +0000701 Element* prior = (Element*) iter.prev();
robertphillips@google.com4c2a2f72012-07-24 22:07:50 +0000702
bsalomon49f085d2014-09-05 13:34:00 -0700703 if (prior) {
commit-bot@chromium.orge5b2af92014-02-16 13:25:24 +0000704 if (prior->canBeIntersectedInPlace(fSaveCount, element.getOp())) {
705 switch (prior->fType) {
commit-bot@chromium.org6fbe54c2013-06-11 11:01:48 +0000706 case Element::kEmpty_Type:
commit-bot@chromium.orge5b2af92014-02-16 13:25:24 +0000707 SkDEBUGCODE(prior->checkEmpty();)
commit-bot@chromium.org6fbe54c2013-06-11 11:01:48 +0000708 return;
709 case Element::kRect_Type:
commit-bot@chromium.orge5b2af92014-02-16 13:25:24 +0000710 if (Element::kRect_Type == element.getType()) {
711 if (prior->rectRectIntersectAllowed(element.getRect(), element.isAA())) {
commit-bot@chromium.org032a52f2014-02-21 20:09:13 +0000712 SkRect isectRect;
713 if (!isectRect.intersect(prior->getRect(), element.getRect())) {
commit-bot@chromium.orge5b2af92014-02-16 13:25:24 +0000714 prior->setEmpty();
715 return;
716 }
717
commit-bot@chromium.org032a52f2014-02-21 20:09:13 +0000718 prior->fRRect.setRect(isectRect);
commit-bot@chromium.orge5b2af92014-02-16 13:25:24 +0000719 prior->fDoAA = element.isAA();
720 Element* priorPrior = (Element*) iter.prev();
721 prior->updateBoundAndGenID(priorPrior);
commit-bot@chromium.org6fbe54c2013-06-11 11:01:48 +0000722 return;
723 }
commit-bot@chromium.orge5b2af92014-02-16 13:25:24 +0000724 break;
commit-bot@chromium.org6fbe54c2013-06-11 11:01:48 +0000725 }
commit-bot@chromium.orge5b2af92014-02-16 13:25:24 +0000726 // fallthrough
727 default:
728 if (!SkRect::Intersects(prior->getBounds(), element.getBounds())) {
729 prior->setEmpty();
robertphillips@google.com08eacc12012-08-02 12:49:00 +0000730 return;
731 }
commit-bot@chromium.org6fbe54c2013-06-11 11:01:48 +0000732 break;
733 }
commit-bot@chromium.orge5b2af92014-02-16 13:25:24 +0000734 } else if (SkRegion::kReplace_Op == element.getOp()) {
commit-bot@chromium.org6fbe54c2013-06-11 11:01:48 +0000735 this->restoreTo(fSaveCount - 1);
commit-bot@chromium.orge5b2af92014-02-16 13:25:24 +0000736 prior = (Element*) fDeque.back();
reed@google.com5c3d1472011-02-22 19:12:23 +0000737 }
738 }
commit-bot@chromium.orge5b2af92014-02-16 13:25:24 +0000739 Element* newElement = SkNEW_PLACEMENT_ARGS(fDeque.push_back(), Element, (element));
740 newElement->updateBoundAndGenID(prior);
741}
742
743void SkClipStack::clipDevRRect(const SkRRect& rrect, SkRegion::Op op, bool doAA) {
744 Element element(fSaveCount, rrect, op, doAA);
745 this->pushElement(element);
746}
747
748void SkClipStack::clipDevRect(const SkRect& rect, SkRegion::Op op, bool doAA) {
749 Element element(fSaveCount, rect, op, doAA);
750 this->pushElement(element);
reed@google.com5c3d1472011-02-22 19:12:23 +0000751}
752
reed@google.com00177082011-10-12 14:34:30 +0000753void SkClipStack::clipDevPath(const SkPath& path, SkRegion::Op op, bool doAA) {
commit-bot@chromium.orge5b2af92014-02-16 13:25:24 +0000754 Element element(fSaveCount, path, op, doAA);
755 this->pushElement(element);
reed@google.com5c3d1472011-02-22 19:12:23 +0000756}
757
reed@google.com0557d9e2012-08-16 15:59:59 +0000758void SkClipStack::clipEmpty() {
bsalomon@google.com9128edc2012-11-29 18:58:19 +0000759 Element* element = (Element*) fDeque.back();
robertphillips@google.com63ae1cf2012-08-17 13:53:05 +0000760
bsalomon@google.com9128edc2012-11-29 18:58:19 +0000761 if (element && element->canBeIntersectedInPlace(fSaveCount, SkRegion::kIntersect_Op)) {
commit-bot@chromium.orge5b2af92014-02-16 13:25:24 +0000762 element->setEmpty();
reed@google.com0557d9e2012-08-16 15:59:59 +0000763 }
bsalomon@google.com9128edc2012-11-29 18:58:19 +0000764 new (fDeque.push_back()) Element(fSaveCount);
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000765
bsalomon@google.com9128edc2012-11-29 18:58:19 +0000766 ((Element*)fDeque.back())->fGenID = kEmptyGenID;
reed@google.com0557d9e2012-08-16 15:59:59 +0000767}
768
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000769bool SkClipStack::isWideOpen() const {
commit-bot@chromium.orgd3e58422013-11-05 15:03:08 +0000770 return this->getTopmostGenID() == kWideOpenGenID;
robertphillips@google.comcc6493b2012-07-26 18:39:13 +0000771}
772
reed@google.com5c3d1472011-02-22 19:12:23 +0000773///////////////////////////////////////////////////////////////////////////////
774
robertphillips@google.com5836b6d2012-07-18 12:06:15 +0000775SkClipStack::Iter::Iter() : fStack(NULL) {
bsalomon@google.comd302f142011-03-03 13:54:13 +0000776}
777
robertphillips@google.com5836b6d2012-07-18 12:06:15 +0000778SkClipStack::Iter::Iter(const SkClipStack& stack, IterStart startLoc)
779 : fStack(&stack) {
robertphillips@google.com52cb2c72012-07-16 18:52:29 +0000780 this->reset(stack, startLoc);
reed@google.com5c3d1472011-02-22 19:12:23 +0000781}
782
bsalomon@google.com8182fa02012-12-04 14:06:06 +0000783const SkClipStack::Element* SkClipStack::Iter::next() {
784 return (const SkClipStack::Element*)fIter.next();
reed@google.com5c3d1472011-02-22 19:12:23 +0000785}
bsalomon@google.comd302f142011-03-03 13:54:13 +0000786
bsalomon@google.com8182fa02012-12-04 14:06:06 +0000787const SkClipStack::Element* SkClipStack::Iter::prev() {
788 return (const SkClipStack::Element*)fIter.prev();
robertphillips@google.com52cb2c72012-07-16 18:52:29 +0000789}
790
bsalomon@google.com8182fa02012-12-04 14:06:06 +0000791const SkClipStack::Element* SkClipStack::Iter::skipToTopmost(SkRegion::Op op) {
robertphillips@google.com5836b6d2012-07-18 12:06:15 +0000792
793 if (NULL == fStack) {
794 return NULL;
795 }
796
797 fIter.reset(fStack->fDeque, SkDeque::Iter::kBack_IterStart);
798
bsalomon@google.com9128edc2012-11-29 18:58:19 +0000799 const SkClipStack::Element* element = NULL;
robertphillips@google.com5836b6d2012-07-18 12:06:15 +0000800
bsalomon@google.com9128edc2012-11-29 18:58:19 +0000801 for (element = (const SkClipStack::Element*) fIter.prev();
bsalomon49f085d2014-09-05 13:34:00 -0700802 element;
bsalomon@google.com9128edc2012-11-29 18:58:19 +0000803 element = (const SkClipStack::Element*) fIter.prev()) {
robertphillips@google.com5836b6d2012-07-18 12:06:15 +0000804
bsalomon@google.com9128edc2012-11-29 18:58:19 +0000805 if (op == element->fOp) {
robertphillips@google.com5836b6d2012-07-18 12:06:15 +0000806 // The Deque's iterator is actually one pace ahead of the
bsalomon@google.com9128edc2012-11-29 18:58:19 +0000807 // returned value. So while "element" is the element we want to
robertphillips@google.com5836b6d2012-07-18 12:06:15 +0000808 // return, the iterator is actually pointing at (and will
809 // return on the next "next" or "prev" call) the element
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000810 // in front of it in the deque. Bump the iterator forward a
robertphillips@google.com5836b6d2012-07-18 12:06:15 +0000811 // step so we get the expected result.
812 if (NULL == fIter.next()) {
813 // The reverse iterator has run off the front of the deque
814 // (i.e., the "op" clip is the first clip) and can't
815 // recover. Reset the iterator to start at the front.
816 fIter.reset(fStack->fDeque, SkDeque::Iter::kFront_IterStart);
817 }
818 break;
819 }
820 }
821
bsalomon@google.com9128edc2012-11-29 18:58:19 +0000822 if (NULL == element) {
robertphillips@google.com5836b6d2012-07-18 12:06:15 +0000823 // There were no "op" clips
824 fIter.reset(fStack->fDeque, SkDeque::Iter::kFront_IterStart);
825 }
826
827 return this->next();
828}
829
robertphillips@google.com52cb2c72012-07-16 18:52:29 +0000830void SkClipStack::Iter::reset(const SkClipStack& stack, IterStart startLoc) {
robertphillips@google.coma6f11c42012-07-23 17:39:44 +0000831 fStack = &stack;
robertphillips@google.com52cb2c72012-07-16 18:52:29 +0000832 fIter.reset(stack.fDeque, static_cast<SkDeque::Iter::IterStart>(startLoc));
bsalomon@google.comd302f142011-03-03 13:54:13 +0000833}
robertphillips@google.com607fe072012-07-24 13:54:00 +0000834
835// helper method
836void SkClipStack::getConservativeBounds(int offsetX,
837 int offsetY,
838 int maxWidth,
839 int maxHeight,
robertphillips@google.com7b112892012-07-31 15:18:21 +0000840 SkRect* devBounds,
robertphillips@google.com4c2a2f72012-07-24 22:07:50 +0000841 bool* isIntersectionOfRects) const {
bsalomon49f085d2014-09-05 13:34:00 -0700842 SkASSERT(devBounds);
robertphillips@google.com607fe072012-07-24 13:54:00 +0000843
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000844 devBounds->setLTRB(0, 0,
robertphillips@google.com7b112892012-07-31 15:18:21 +0000845 SkIntToScalar(maxWidth), SkIntToScalar(maxHeight));
robertphillips@google.com607fe072012-07-24 13:54:00 +0000846
847 SkRect temp;
848 SkClipStack::BoundsType boundType;
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000849
robertphillips@google.com7b112892012-07-31 15:18:21 +0000850 // temp starts off in canvas space here
robertphillips@google.com4c2a2f72012-07-24 22:07:50 +0000851 this->getBounds(&temp, &boundType, isIntersectionOfRects);
robertphillips@google.com607fe072012-07-24 13:54:00 +0000852 if (SkClipStack::kInsideOut_BoundsType == boundType) {
853 return;
854 }
855
robertphillips@google.com7b112892012-07-31 15:18:21 +0000856 // but is converted to device space here
robertphillips@google.com607fe072012-07-24 13:54:00 +0000857 temp.offset(SkIntToScalar(offsetX), SkIntToScalar(offsetY));
858
robertphillips@google.com7b112892012-07-31 15:18:21 +0000859 if (!devBounds->intersect(temp)) {
860 devBounds->setEmpty();
robertphillips@google.com607fe072012-07-24 13:54:00 +0000861 }
862}
robertphillips@google.com46f93502012-08-07 15:38:08 +0000863
robertphillips@google.com46f93502012-08-07 15:38:08 +0000864int32_t SkClipStack::GetNextGenID() {
bsalomon@google.comedb26fd2012-11-28 14:42:41 +0000865 // TODO: handle overflow.
robertphillips@google.com46f93502012-08-07 15:38:08 +0000866 return sk_atomic_inc(&gGenID);
867}
robertphillips@google.com73e71022012-08-09 18:10:49 +0000868
869int32_t SkClipStack::getTopmostGenID() const {
robertphillips@google.com73e71022012-08-09 18:10:49 +0000870 if (fDeque.empty()) {
commit-bot@chromium.orgd3e58422013-11-05 15:03:08 +0000871 return kWideOpenGenID;
robertphillips@google.com73e71022012-08-09 18:10:49 +0000872 }
873
commit-bot@chromium.orgd3e58422013-11-05 15:03:08 +0000874 const Element* back = static_cast<const Element*>(fDeque.back());
875 if (kInsideOut_BoundsType == back->fFiniteBoundType && back->fFiniteBound.isEmpty()) {
876 return kWideOpenGenID;
877 }
878
879 return back->getGenID();
robertphillips@google.com73e71022012-08-09 18:10:49 +0000880}
bsalomonb6b02522014-06-09 07:59:06 -0700881
882#ifdef SK_DEVELOPER
883void SkClipStack::Element::dump() const {
884 static const char* kTypeStrings[] = {
885 "empty",
886 "rect",
887 "rrect",
888 "path"
889 };
890 SK_COMPILE_ASSERT(0 == kEmpty_Type, type_str);
891 SK_COMPILE_ASSERT(1 == kRect_Type, type_str);
892 SK_COMPILE_ASSERT(2 == kRRect_Type, type_str);
893 SK_COMPILE_ASSERT(3 == kPath_Type, type_str);
894 SK_COMPILE_ASSERT(SK_ARRAY_COUNT(kTypeStrings) == kTypeCnt, type_str);
895
896 static const char* kOpStrings[] = {
897 "difference",
898 "intersect",
899 "union",
900 "xor",
901 "reverse-difference",
902 "replace",
903 };
904 SK_COMPILE_ASSERT(0 == SkRegion::kDifference_Op, op_str);
905 SK_COMPILE_ASSERT(1 == SkRegion::kIntersect_Op, op_str);
906 SK_COMPILE_ASSERT(2 == SkRegion::kUnion_Op, op_str);
907 SK_COMPILE_ASSERT(3 == SkRegion::kXOR_Op, op_str);
908 SK_COMPILE_ASSERT(4 == SkRegion::kReverseDifference_Op, op_str);
909 SK_COMPILE_ASSERT(5 == SkRegion::kReplace_Op, op_str);
910 SK_COMPILE_ASSERT(SK_ARRAY_COUNT(kOpStrings) == SkRegion::kOpCnt, op_str);
911
912 SkDebugf("Type: %s, Op: %s, AA: %s, Save Count: %d\n", kTypeStrings[fType],
913 kOpStrings[fOp], (fDoAA ? "yes" : "no"), fSaveCount);
914 switch (fType) {
915 case kEmpty_Type:
916 SkDebugf("\n");
917 break;
918 case kRect_Type:
919 this->getRect().dump();
920 SkDebugf("\n");
921 break;
922 case kRRect_Type:
923 this->getRRect().dump();
924 SkDebugf("\n");
925 break;
926 case kPath_Type:
caryclarke9562592014-09-15 09:26:09 -0700927 this->getPath().dump(NULL, true, false);
bsalomonb6b02522014-06-09 07:59:06 -0700928 break;
929 }
930}
931
932void SkClipStack::dump() const {
933 B2TIter iter(*this);
934 const Element* e;
935 while ((e = iter.next())) {
936 e->dump();
937 SkDebugf("\n");
938 }
939}
940#endif