diff options
Diffstat (limited to 'src/core/SkClipStack.cpp')
-rw-r--r-- | src/core/SkClipStack.cpp | 269 |
1 files changed, 134 insertions, 135 deletions
diff --git a/src/core/SkClipStack.cpp b/src/core/SkClipStack.cpp index 2f0a4936a4..bf12a1391d 100644 --- a/src/core/SkClipStack.cpp +++ b/src/core/SkClipStack.cpp @@ -20,24 +20,24 @@ static const int32_t kFirstUnreservedGenID = 3; int32_t SkClipStack::gGenID = kFirstUnreservedGenID; SkClipStack::Element::Element(const Element& that) { - switch (that.getType()) { - case kEmpty_Type: - fRRect.setEmpty(); - fPath.reset(); + switch (that.getDeviceSpaceType()) { + case DeviceSpaceType::kEmpty: + fDeviceSpaceRRect.setEmpty(); + fDeviceSpacePath.reset(); break; - case kRect_Type: // Rect uses rrect - case kRRect_Type: - fPath.reset(); - fRRect = that.fRRect; + case DeviceSpaceType::kRect: // Rect uses rrect + case DeviceSpaceType::kRRect: + fDeviceSpacePath.reset(); + fDeviceSpaceRRect = that.fDeviceSpaceRRect; break; - case kPath_Type: - fPath.set(that.getPath()); + case DeviceSpaceType::kPath: + fDeviceSpacePath.set(that.getDeviceSpacePath()); break; } fSaveCount = that.fSaveCount; fOp = that.fOp; - fType = that.fType; + fDeviceSpaceType = that.fDeviceSpaceType; fDoAA = that.fDoAA; fFiniteBoundType = that.fFiniteBoundType; fFiniteBound = that.fFiniteBound; @@ -49,20 +49,18 @@ bool SkClipStack::Element::operator== (const Element& element) const { if (this == &element) { return true; } - if (fOp != element.fOp || - fType != element.fType || - fDoAA != element.fDoAA || - fSaveCount != element.fSaveCount) { + if (fOp != element.fOp || fDeviceSpaceType != element.fDeviceSpaceType || + fDoAA != element.fDoAA || fSaveCount != element.fSaveCount) { return false; } - switch (fType) { - case kPath_Type: - return this->getPath() == element.getPath(); - case kRRect_Type: - return fRRect == element.fRRect; - case kRect_Type: - return this->getRect() == element.getRect(); - case kEmpty_Type: + switch (fDeviceSpaceType) { + case DeviceSpaceType::kPath: + return this->getDeviceSpacePath() == element.getDeviceSpacePath(); + case DeviceSpaceType::kRRect: + return fDeviceSpaceRRect == element.fDeviceSpaceRRect; + case DeviceSpaceType::kRect: + return this->getDeviceSpaceRect() == element.getDeviceSpaceRect(); + case DeviceSpaceType::kEmpty: return true; default: SkDEBUGFAIL("Unexpected type."); @@ -72,13 +70,13 @@ bool SkClipStack::Element::operator== (const Element& element) const { const SkRect& SkClipStack::Element::getBounds() const { static const SkRect kEmpty = {0, 0, 0, 0}; - switch (fType) { - case kRect_Type: // fallthrough - case kRRect_Type: - return fRRect.getBounds(); - case kPath_Type: - return fPath.get()->getBounds(); - case kEmpty_Type: + switch (fDeviceSpaceType) { + case DeviceSpaceType::kRect: // fallthrough + case DeviceSpaceType::kRRect: + return fDeviceSpaceRRect.getBounds(); + case DeviceSpaceType::kPath: + return fDeviceSpacePath.get()->getBounds(); + case DeviceSpaceType::kEmpty: return kEmpty; default: SkDEBUGFAIL("Unexpected type."); @@ -87,14 +85,14 @@ const SkRect& SkClipStack::Element::getBounds() const { } bool SkClipStack::Element::contains(const SkRect& rect) const { - switch (fType) { - case kRect_Type: - return this->getRect().contains(rect); - case kRRect_Type: - return fRRect.contains(rect); - case kPath_Type: - return fPath.get()->conservativelyContainsRect(rect); - case kEmpty_Type: + switch (fDeviceSpaceType) { + case DeviceSpaceType::kRect: + return this->getDeviceSpaceRect().contains(rect); + case DeviceSpaceType::kRRect: + return fDeviceSpaceRRect.contains(rect); + case DeviceSpaceType::kPath: + return fDeviceSpacePath.get()->conservativelyContainsRect(rect); + case DeviceSpaceType::kEmpty: return false; default: SkDEBUGFAIL("Unexpected type."); @@ -103,15 +101,15 @@ bool SkClipStack::Element::contains(const SkRect& rect) const { } bool SkClipStack::Element::contains(const SkRRect& rrect) const { - switch (fType) { - case kRect_Type: - return this->getRect().contains(rrect.getBounds()); - case kRRect_Type: + switch (fDeviceSpaceType) { + case DeviceSpaceType::kRect: + return this->getDeviceSpaceRect().contains(rrect.getBounds()); + case DeviceSpaceType::kRRect: // We don't currently have a generalized rrect-rrect containment. - return fRRect.contains(rrect.getBounds()) || rrect == fRRect; - case kPath_Type: - return fPath.get()->conservativelyContainsRect(rrect.getBounds()); - case kEmpty_Type: + return fDeviceSpaceRRect.contains(rrect.getBounds()) || rrect == fDeviceSpaceRRect; + case DeviceSpaceType::kPath: + return fDeviceSpacePath.get()->conservativelyContainsRect(rrect.getBounds()); + case DeviceSpaceType::kEmpty: return false; default: SkDEBUGFAIL("Unexpected type."); @@ -120,23 +118,23 @@ bool SkClipStack::Element::contains(const SkRRect& rrect) const { } void SkClipStack::Element::invertShapeFillType() { - switch (fType) { - case kRect_Type: - fPath.init(); - fPath.get()->addRect(this->getRect()); - fPath.get()->setFillType(SkPath::kInverseEvenOdd_FillType); - fType = kPath_Type; + switch (fDeviceSpaceType) { + case DeviceSpaceType::kRect: + fDeviceSpacePath.init(); + fDeviceSpacePath.get()->addRect(this->getDeviceSpaceRect()); + fDeviceSpacePath.get()->setFillType(SkPath::kInverseEvenOdd_FillType); + fDeviceSpaceType = DeviceSpaceType::kPath; break; - case kRRect_Type: - fPath.init(); - fPath.get()->addRRect(fRRect); - fPath.get()->setFillType(SkPath::kInverseEvenOdd_FillType); - fType = kPath_Type; + case DeviceSpaceType::kRRect: + fDeviceSpacePath.init(); + fDeviceSpacePath.get()->addRRect(fDeviceSpaceRRect); + fDeviceSpacePath.get()->setFillType(SkPath::kInverseEvenOdd_FillType); + fDeviceSpaceType = DeviceSpaceType::kPath; break; - case kPath_Type: - fPath.get()->toggleInverseFillType(); + case DeviceSpaceType::kPath: + fDeviceSpacePath.get()->toggleInverseFillType(); break; - case kEmpty_Type: + case DeviceSpaceType::kEmpty: // Should this set to an empty, inverse filled path? break; } @@ -159,8 +157,8 @@ void SkClipStack::Element::initRect(int saveCount, const SkRect& rect, const SkM if (m.rectStaysRect()) { SkRect devRect; m.mapRect(&devRect, rect); - fRRect.setRect(devRect); - fType = kRect_Type; + fDeviceSpaceRRect.setRect(devRect); + fDeviceSpaceType = DeviceSpaceType::kRect; this->initCommon(saveCount, op, doAA); return; } @@ -172,12 +170,12 @@ void SkClipStack::Element::initRect(int saveCount, const SkRect& rect, const SkM void SkClipStack::Element::initRRect(int saveCount, const SkRRect& rrect, const SkMatrix& m, SkClipOp op, bool doAA) { - if (rrect.transform(m, &fRRect)) { - SkRRect::Type type = fRRect.getType(); + if (rrect.transform(m, &fDeviceSpaceRRect)) { + SkRRect::Type type = fDeviceSpaceRRect.getType(); if (SkRRect::kRect_Type == type || SkRRect::kEmpty_Type == type) { - fType = kRect_Type; + fDeviceSpaceType = DeviceSpaceType::kRect; } else { - fType = kRRect_Type; + fDeviceSpaceType = DeviceSpaceType::kRRect; } this->initCommon(saveCount, op, doAA); return; @@ -209,42 +207,42 @@ void SkClipStack::Element::initPath(int saveCount, const SkPath& path, const SkM void SkClipStack::Element::initAsPath(int saveCount, const SkPath& path, const SkMatrix& m, SkClipOp op, bool doAA) { - path.transform(m, fPath.init()); - fPath.get()->setIsVolatile(true); - fType = kPath_Type; + path.transform(m, fDeviceSpacePath.init()); + fDeviceSpacePath.get()->setIsVolatile(true); + fDeviceSpaceType = DeviceSpaceType::kPath; this->initCommon(saveCount, op, doAA); } -void SkClipStack::Element::asPath(SkPath* path) const { - switch (fType) { - case kEmpty_Type: +void SkClipStack::Element::asDeviceSpacePath(SkPath* path) const { + switch (fDeviceSpaceType) { + case DeviceSpaceType::kEmpty: path->reset(); path->setIsVolatile(true); break; - case kRect_Type: + case DeviceSpaceType::kRect: path->reset(); - path->addRect(this->getRect()); + path->addRect(this->getDeviceSpaceRect()); path->setIsVolatile(true); break; - case kRRect_Type: + case DeviceSpaceType::kRRect: path->reset(); - path->addRRect(fRRect); + path->addRRect(fDeviceSpaceRRect); path->setIsVolatile(true); break; - case kPath_Type: - *path = *fPath.get(); + case DeviceSpaceType::kPath: + *path = *fDeviceSpacePath.get(); break; } path->setIsVolatile(true); } void SkClipStack::Element::setEmpty() { - fType = kEmpty_Type; + fDeviceSpaceType = DeviceSpaceType::kEmpty; fFiniteBound.setEmpty(); fFiniteBoundType = kNormal_BoundsType; fIsIntersectionOfRects = false; - fRRect.setEmpty(); - fPath.reset(); + fDeviceSpaceRRect.setEmpty(); + fDeviceSpacePath.reset(); fGenID = kEmptyGenID; SkDEBUGCODE(this->checkEmpty();) } @@ -254,12 +252,12 @@ void SkClipStack::Element::checkEmpty() const { SkASSERT(kNormal_BoundsType == fFiniteBoundType); SkASSERT(!fIsIntersectionOfRects); SkASSERT(kEmptyGenID == fGenID); - SkASSERT(fRRect.isEmpty()); - SkASSERT(!fPath.isValid()); + SkASSERT(fDeviceSpaceRRect.isEmpty()); + SkASSERT(!fDeviceSpacePath.isValid()); } bool SkClipStack::Element::canBeIntersectedInPlace(int saveCount, SkClipOp op) const { - if (kEmpty_Type == fType && + if (DeviceSpaceType::kEmpty == fDeviceSpaceType && (kDifference_SkClipOp == op || kIntersect_SkClipOp == op)) { return true; } @@ -271,19 +269,19 @@ bool SkClipStack::Element::canBeIntersectedInPlace(int saveCount, SkClipOp op) c } bool SkClipStack::Element::rectRectIntersectAllowed(const SkRect& newR, bool newAA) const { - SkASSERT(kRect_Type == fType); + SkASSERT(DeviceSpaceType::kRect == fDeviceSpaceType); if (fDoAA == newAA) { // if the AA setting is the same there is no issue return true; } - if (!SkRect::Intersects(this->getRect(), newR)) { + if (!SkRect::Intersects(this->getDeviceSpaceRect(), newR)) { // The calling code will correctly set the result to the empty clip return true; } - if (this->getRect().contains(newR)) { + if (this->getDeviceSpaceRect().contains(newR)) { // if the new rect carves out a portion of the old one there is no // issue return true; @@ -476,32 +474,31 @@ void SkClipStack::Element::updateBoundAndGenID(const Element* prior) { // First, optimistically update the current Element's bound information // with the current clip's bound fIsIntersectionOfRects = false; - switch (fType) { - case kRect_Type: - fFiniteBound = this->getRect(); + switch (fDeviceSpaceType) { + case DeviceSpaceType::kRect: + fFiniteBound = this->getDeviceSpaceRect(); fFiniteBoundType = kNormal_BoundsType; - if (kReplace_SkClipOp == fOp || - (kIntersect_SkClipOp == fOp && nullptr == prior) || + if (kReplace_SkClipOp == fOp || (kIntersect_SkClipOp == fOp && nullptr == prior) || (kIntersect_SkClipOp == fOp && prior->fIsIntersectionOfRects && - prior->rectRectIntersectAllowed(this->getRect(), fDoAA))) { + prior->rectRectIntersectAllowed(this->getDeviceSpaceRect(), fDoAA))) { fIsIntersectionOfRects = true; } break; - case kRRect_Type: - fFiniteBound = fRRect.getBounds(); + case DeviceSpaceType::kRRect: + fFiniteBound = fDeviceSpaceRRect.getBounds(); fFiniteBoundType = kNormal_BoundsType; break; - case kPath_Type: - fFiniteBound = fPath.get()->getBounds(); + case DeviceSpaceType::kPath: + fFiniteBound = fDeviceSpacePath.get()->getBounds(); - if (fPath.get()->isInverseFillType()) { + if (fDeviceSpacePath.get()->isInverseFillType()) { fFiniteBoundType = kInsideOut_BoundsType; } else { fFiniteBoundType = kNormal_BoundsType; } break; - case kEmpty_Type: + case DeviceSpaceType::kEmpty: SkDEBUGFAIL("We shouldn't get here with an empty element."); break; } @@ -763,8 +760,8 @@ bool SkClipStack::asPath(SkPath *path) const { SkClipStack::Iter iter(*this, SkClipStack::Iter::kBottom_IterStart); while (const SkClipStack::Element* element = iter.next()) { SkPath operand; - if (element->getType() != SkClipStack::Element::kEmpty_Type) { - element->asPath(&operand); + if (element->getDeviceSpaceType() != SkClipStack::Element::DeviceSpaceType::kEmpty) { + element->asDeviceSpacePath(&operand); } SkClipOp elementOp = element->getOp(); @@ -790,20 +787,22 @@ void SkClipStack::pushElement(const Element& element) { if (prior) { if (prior->canBeIntersectedInPlace(fSaveCount, element.getOp())) { - switch (prior->fType) { - case Element::kEmpty_Type: + switch (prior->fDeviceSpaceType) { + case Element::DeviceSpaceType::kEmpty: SkDEBUGCODE(prior->checkEmpty();) return; - case Element::kRect_Type: - if (Element::kRect_Type == element.getType()) { - if (prior->rectRectIntersectAllowed(element.getRect(), element.isAA())) { + case Element::DeviceSpaceType::kRect: + if (Element::DeviceSpaceType::kRect == element.getDeviceSpaceType()) { + if (prior->rectRectIntersectAllowed(element.getDeviceSpaceRect(), + element.isAA())) { SkRect isectRect; - if (!isectRect.intersect(prior->getRect(), element.getRect())) { + if (!isectRect.intersect(prior->getDeviceSpaceRect(), + element.getDeviceSpaceRect())) { prior->setEmpty(); return; } - prior->fRRect.setRect(isectRect); + prior->fDeviceSpaceRRect.setRect(isectRect); prior->fDoAA = element.isAA(); Element* priorPrior = (Element*) iter.prev(); prior->updateBoundAndGenID(priorPrior); @@ -971,19 +970,19 @@ bool SkClipStack::isRRect(const SkRect& bounds, SkRRect* rrect, bool* aa) const return false; } const Element* back = static_cast<const Element*>(fDeque.back()); - if (back->getType() != SkClipStack::Element::kRect_Type && - back->getType() != SkClipStack::Element::kRRect_Type) { + if (back->getDeviceSpaceType() != SkClipStack::Element::DeviceSpaceType::kRect && + back->getDeviceSpaceType() != SkClipStack::Element::DeviceSpaceType::kRRect) { return false; } if (back->getOp() == kReplace_SkClipOp) { - *rrect = back->asRRect(); + *rrect = back->asDeviceSpaceRRect(); *aa = back->isAA(); return true; } if (back->getOp() == kIntersect_SkClipOp) { SkRect backBounds; - if (!backBounds.intersect(bounds, back->asRRect().rect())) { + if (!backBounds.intersect(bounds, back->asDeviceSpaceRRect().rect())) { return false; } if (cnt > 1) { @@ -1000,7 +999,7 @@ bool SkClipStack::isRRect(const SkRect& bounds, SkRRect* rrect, bool* aa) const } } } - *rrect = back->asRRect(); + *rrect = back->asDeviceSpaceRRect(); *aa = back->isAA(); return true; } @@ -1036,11 +1035,11 @@ void SkClipStack::Element::dump() const { "rrect", "path" }; - static_assert(0 == kEmpty_Type, "type_str"); - static_assert(1 == kRect_Type, "type_str"); - static_assert(2 == kRRect_Type, "type_str"); - static_assert(3 == kPath_Type, "type_str"); - static_assert(SK_ARRAY_COUNT(kTypeStrings) == kTypeCnt, "type_str"); + static_assert(0 == static_cast<int>(DeviceSpaceType::kEmpty), "enum mismatch"); + static_assert(1 == static_cast<int>(DeviceSpaceType::kRect), "enum mismatch"); + static_assert(2 == static_cast<int>(DeviceSpaceType::kRRect), "enum mismatch"); + static_assert(3 == static_cast<int>(DeviceSpaceType::kPath), "enum mismatch"); + static_assert(SK_ARRAY_COUNT(kTypeStrings) == kTypeCnt, "enum mismatch"); static const char* kOpStrings[] = { "difference", @@ -1050,30 +1049,30 @@ void SkClipStack::Element::dump() const { "reverse-difference", "replace", }; - static_assert(0 == static_cast<int>(kDifference_SkClipOp), "op_str"); - static_assert(1 == static_cast<int>(kIntersect_SkClipOp), "op_str"); - static_assert(2 == static_cast<int>(kUnion_SkClipOp), "op_str"); - static_assert(3 == static_cast<int>(kXOR_SkClipOp), "op_str"); - static_assert(4 == static_cast<int>(kReverseDifference_SkClipOp), "op_str"); - static_assert(5 == static_cast<int>(kReplace_SkClipOp), "op_str"); - static_assert(SK_ARRAY_COUNT(kOpStrings) == SkRegion::kOpCnt, "op_str"); - - SkDebugf("Type: %s, Op: %s, AA: %s, Save Count: %d\n", kTypeStrings[fType], + static_assert(0 == static_cast<int>(kDifference_SkClipOp), "enum mismatch"); + static_assert(1 == static_cast<int>(kIntersect_SkClipOp), "enum mismatch"); + static_assert(2 == static_cast<int>(kUnion_SkClipOp), "enum mismatch"); + static_assert(3 == static_cast<int>(kXOR_SkClipOp), "enum mismatch"); + static_assert(4 == static_cast<int>(kReverseDifference_SkClipOp), "enum mismatch"); + static_assert(5 == static_cast<int>(kReplace_SkClipOp), "enum mismatch"); + static_assert(SK_ARRAY_COUNT(kOpStrings) == SkRegion::kOpCnt, "enum mismatch"); + + SkDebugf("Type: %s, Op: %s, AA: %s, Save Count: %d\n", kTypeStrings[(int)fDeviceSpaceType], kOpStrings[static_cast<int>(fOp)], (fDoAA ? "yes" : "no"), fSaveCount); - switch (fType) { - case kEmpty_Type: + switch (fDeviceSpaceType) { + case DeviceSpaceType::kEmpty: SkDebugf("\n"); break; - case kRect_Type: - this->getRect().dump(); + case DeviceSpaceType::kRect: + this->getDeviceSpaceRect().dump(); SkDebugf("\n"); break; - case kRRect_Type: - this->getRRect().dump(); + case DeviceSpaceType::kRRect: + this->getDeviceSpaceRRect().dump(); SkDebugf("\n"); break; - case kPath_Type: - this->getPath().dump(nullptr, true, false); + case DeviceSpaceType::kPath: + this->getDeviceSpacePath().dump(nullptr, true, false); break; } } |