| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2006 The Android Open Source Project | 2 * Copyright 2006 The Android Open Source Project |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #include "SkBuffer.h" | 8 #include "SkBuffer.h" |
| 9 #include "SkErrorInternals.h" | 9 #include "SkErrorInternals.h" |
| 10 #include "SkGeometry.h" | 10 #include "SkGeometry.h" |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 } | 130 } |
| 131 | 131 |
| 132 void SkPath::resetFields() { | 132 void SkPath::resetFields() { |
| 133 //fPathRef is assumed to have been emptied by the caller. | 133 //fPathRef is assumed to have been emptied by the caller. |
| 134 fLastMoveToIndex = INITIAL_LASTMOVETOINDEX_VALUE; | 134 fLastMoveToIndex = INITIAL_LASTMOVETOINDEX_VALUE; |
| 135 fFillType = kWinding_FillType; | 135 fFillType = kWinding_FillType; |
| 136 fConvexity = kUnknown_Convexity; | 136 fConvexity = kUnknown_Convexity; |
| 137 fFirstDirection = SkPathPriv::kUnknown_FirstDirection; | 137 fFirstDirection = SkPathPriv::kUnknown_FirstDirection; |
| 138 | 138 |
| 139 // We don't touch Android's fSourcePath. It's used to track texture garbage
collection, so we | 139 // We don't touch Android's fSourcePath. It's used to track texture garbage
collection, so we |
| 140 // don't want to muck with it if it's been set to something non-NULL. | 140 // don't want to muck with it if it's been set to something non-nullptr. |
| 141 } | 141 } |
| 142 | 142 |
| 143 SkPath::SkPath(const SkPath& that) | 143 SkPath::SkPath(const SkPath& that) |
| 144 : fPathRef(SkRef(that.fPathRef.get())) { | 144 : fPathRef(SkRef(that.fPathRef.get())) { |
| 145 this->copyFields(that); | 145 this->copyFields(that); |
| 146 SkDEBUGCODE(that.validate();) | 146 SkDEBUGCODE(that.validate();) |
| 147 } | 147 } |
| 148 | 148 |
| 149 SkPath::~SkPath() { | 149 SkPath::~SkPath() { |
| 150 SkDEBUGCODE(this->validate();) | 150 SkDEBUGCODE(this->validate();) |
| (...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 378 | 378 |
| 379 */ | 379 */ |
| 380 static int rect_make_dir(SkScalar dx, SkScalar dy) { | 380 static int rect_make_dir(SkScalar dx, SkScalar dy) { |
| 381 return ((0 != dx) << 0) | ((dx > 0 || dy > 0) << 1); | 381 return ((0 != dx) << 0) | ((dx > 0 || dy > 0) << 1); |
| 382 } | 382 } |
| 383 bool SkPath::isRectContour(bool allowPartial, int* currVerb, const SkPoint** pts
Ptr, | 383 bool SkPath::isRectContour(bool allowPartial, int* currVerb, const SkPoint** pts
Ptr, |
| 384 bool* isClosed, Direction* direction) const { | 384 bool* isClosed, Direction* direction) const { |
| 385 int corners = 0; | 385 int corners = 0; |
| 386 SkPoint first, last; | 386 SkPoint first, last; |
| 387 const SkPoint* pts = *ptsPtr; | 387 const SkPoint* pts = *ptsPtr; |
| 388 const SkPoint* savePts = NULL; | 388 const SkPoint* savePts = nullptr; |
| 389 first.set(0, 0); | 389 first.set(0, 0); |
| 390 last.set(0, 0); | 390 last.set(0, 0); |
| 391 int firstDirection = 0; | 391 int firstDirection = 0; |
| 392 int lastDirection = 0; | 392 int lastDirection = 0; |
| 393 int nextDirection = 0; | 393 int nextDirection = 0; |
| 394 bool closedOrMoved = false; | 394 bool closedOrMoved = false; |
| 395 bool autoClose = false; | 395 bool autoClose = false; |
| 396 bool insertClose = false; | 396 bool insertClose = false; |
| 397 int verbCnt = fPathRef->countVerbs(); | 397 int verbCnt = fPathRef->countVerbs(); |
| 398 while (*currVerb < verbCnt && (!allowPartial || !autoClose)) { | 398 while (*currVerb < verbCnt && (!allowPartial || !autoClose)) { |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 524 } | 524 } |
| 525 return true; | 525 return true; |
| 526 } | 526 } |
| 527 | 527 |
| 528 bool SkPath::isNestedFillRects(SkRect rects[2], Direction dirs[2]) const { | 528 bool SkPath::isNestedFillRects(SkRect rects[2], Direction dirs[2]) const { |
| 529 SkDEBUGCODE(this->validate();) | 529 SkDEBUGCODE(this->validate();) |
| 530 int currVerb = 0; | 530 int currVerb = 0; |
| 531 const SkPoint* pts = fPathRef->points(); | 531 const SkPoint* pts = fPathRef->points(); |
| 532 const SkPoint* first = pts; | 532 const SkPoint* first = pts; |
| 533 Direction testDirs[2]; | 533 Direction testDirs[2]; |
| 534 if (!isRectContour(true, &currVerb, &pts, NULL, &testDirs[0])) { | 534 if (!isRectContour(true, &currVerb, &pts, nullptr, &testDirs[0])) { |
| 535 return false; | 535 return false; |
| 536 } | 536 } |
| 537 const SkPoint* last = pts; | 537 const SkPoint* last = pts; |
| 538 SkRect testRects[2]; | 538 SkRect testRects[2]; |
| 539 bool isClosed; | 539 bool isClosed; |
| 540 if (isRectContour(false, &currVerb, &pts, &isClosed, &testDirs[1])) { | 540 if (isRectContour(false, &currVerb, &pts, &isClosed, &testDirs[1])) { |
| 541 testRects[0].set(first, SkToS32(last - first)); | 541 testRects[0].set(first, SkToS32(last - first)); |
| 542 if (!isClosed) { | 542 if (!isClosed) { |
| 543 pts = fPathRef->points() + fPathRef->countPoints(); | 543 pts = fPathRef->points() + fPathRef->countPoints(); |
| 544 } | 544 } |
| (...skipping 882 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1427 SkChopCubicAtHalf(pts, tmp); | 1427 SkChopCubicAtHalf(pts, tmp); |
| 1428 subdivide_cubic_to(path, &tmp[0], level); | 1428 subdivide_cubic_to(path, &tmp[0], level); |
| 1429 subdivide_cubic_to(path, &tmp[3], level); | 1429 subdivide_cubic_to(path, &tmp[3], level); |
| 1430 } else { | 1430 } else { |
| 1431 path->cubicTo(pts[1], pts[2], pts[3]); | 1431 path->cubicTo(pts[1], pts[2], pts[3]); |
| 1432 } | 1432 } |
| 1433 } | 1433 } |
| 1434 | 1434 |
| 1435 void SkPath::transform(const SkMatrix& matrix, SkPath* dst) const { | 1435 void SkPath::transform(const SkMatrix& matrix, SkPath* dst) const { |
| 1436 SkDEBUGCODE(this->validate();) | 1436 SkDEBUGCODE(this->validate();) |
| 1437 if (dst == NULL) { | 1437 if (dst == nullptr) { |
| 1438 dst = (SkPath*)this; | 1438 dst = (SkPath*)this; |
| 1439 } | 1439 } |
| 1440 | 1440 |
| 1441 if (matrix.hasPerspective()) { | 1441 if (matrix.hasPerspective()) { |
| 1442 SkPath tmp; | 1442 SkPath tmp; |
| 1443 tmp.fFillType = fFillType; | 1443 tmp.fFillType = fFillType; |
| 1444 | 1444 |
| 1445 SkPath::Iter iter(*this, false); | 1445 SkPath::Iter iter(*this, false); |
| 1446 SkPoint pts[4]; | 1446 SkPoint pts[4]; |
| 1447 SkPath::Verb verb; | 1447 SkPath::Verb verb; |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1515 kEmptyContour_SegmentState, // The current contour is empty. We may be | 1515 kEmptyContour_SegmentState, // The current contour is empty. We may be |
| 1516 // starting processing or we may have just | 1516 // starting processing or we may have just |
| 1517 // closed a contour. | 1517 // closed a contour. |
| 1518 kAfterMove_SegmentState, // We have seen a move, but nothing else. | 1518 kAfterMove_SegmentState, // We have seen a move, but nothing else. |
| 1519 kAfterPrimitive_SegmentState // We have seen a primitive but not yet | 1519 kAfterPrimitive_SegmentState // We have seen a primitive but not yet |
| 1520 // closed the path. Also the initial state. | 1520 // closed the path. Also the initial state. |
| 1521 }; | 1521 }; |
| 1522 | 1522 |
| 1523 SkPath::Iter::Iter() { | 1523 SkPath::Iter::Iter() { |
| 1524 #ifdef SK_DEBUG | 1524 #ifdef SK_DEBUG |
| 1525 fPts = NULL; | 1525 fPts = nullptr; |
| 1526 fConicWeights = NULL; | 1526 fConicWeights = nullptr; |
| 1527 fMoveTo.fX = fMoveTo.fY = fLastPt.fX = fLastPt.fY = 0; | 1527 fMoveTo.fX = fMoveTo.fY = fLastPt.fX = fLastPt.fY = 0; |
| 1528 fForceClose = fCloseLine = false; | 1528 fForceClose = fCloseLine = false; |
| 1529 fSegmentState = kEmptyContour_SegmentState; | 1529 fSegmentState = kEmptyContour_SegmentState; |
| 1530 #endif | 1530 #endif |
| 1531 // need to init enough to make next() harmlessly return kDone_Verb | 1531 // need to init enough to make next() harmlessly return kDone_Verb |
| 1532 fVerbs = NULL; | 1532 fVerbs = nullptr; |
| 1533 fVerbStop = NULL; | 1533 fVerbStop = nullptr; |
| 1534 fNeedClose = false; | 1534 fNeedClose = false; |
| 1535 } | 1535 } |
| 1536 | 1536 |
| 1537 SkPath::Iter::Iter(const SkPath& path, bool forceClose) { | 1537 SkPath::Iter::Iter(const SkPath& path, bool forceClose) { |
| 1538 this->setPath(path, forceClose); | 1538 this->setPath(path, forceClose); |
| 1539 } | 1539 } |
| 1540 | 1540 |
| 1541 void SkPath::Iter::setPath(const SkPath& path, bool forceClose) { | 1541 void SkPath::Iter::setPath(const SkPath& path, bool forceClose) { |
| 1542 fPts = path.fPathRef->points(); | 1542 fPts = path.fPathRef->points(); |
| 1543 fVerbs = path.fPathRef->verbs(); | 1543 fVerbs = path.fPathRef->verbs(); |
| 1544 fVerbStop = path.fPathRef->verbsMemBegin(); | 1544 fVerbStop = path.fPathRef->verbsMemBegin(); |
| 1545 fConicWeights = path.fPathRef->conicWeights() - 1; // begin one behind | 1545 fConicWeights = path.fPathRef->conicWeights() - 1; // begin one behind |
| 1546 fLastPt.fX = fLastPt.fY = 0; | 1546 fLastPt.fX = fLastPt.fY = 0; |
| 1547 fMoveTo.fX = fMoveTo.fY = 0; | 1547 fMoveTo.fX = fMoveTo.fY = 0; |
| 1548 fForceClose = SkToU8(forceClose); | 1548 fForceClose = SkToU8(forceClose); |
| 1549 fNeedClose = false; | 1549 fNeedClose = false; |
| 1550 fSegmentState = kEmptyContour_SegmentState; | 1550 fSegmentState = kEmptyContour_SegmentState; |
| 1551 } | 1551 } |
| 1552 | 1552 |
| 1553 bool SkPath::Iter::isClosedContour() const { | 1553 bool SkPath::Iter::isClosedContour() const { |
| 1554 if (fVerbs == NULL || fVerbs == fVerbStop) { | 1554 if (fVerbs == nullptr || fVerbs == fVerbStop) { |
| 1555 return false; | 1555 return false; |
| 1556 } | 1556 } |
| 1557 if (fForceClose) { | 1557 if (fForceClose) { |
| 1558 return true; | 1558 return true; |
| 1559 } | 1559 } |
| 1560 | 1560 |
| 1561 const uint8_t* verbs = fVerbs; | 1561 const uint8_t* verbs = fVerbs; |
| 1562 const uint8_t* stop = fVerbStop; | 1562 const uint8_t* stop = fVerbStop; |
| 1563 | 1563 |
| 1564 if (kMove_Verb == *(verbs - 1)) { | 1564 if (kMove_Verb == *(verbs - 1)) { |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1610 // Set the first return pt to the last pt of the previous primitive. | 1610 // Set the first return pt to the last pt of the previous primitive. |
| 1611 return fPts[-1]; | 1611 return fPts[-1]; |
| 1612 } | 1612 } |
| 1613 } | 1613 } |
| 1614 | 1614 |
| 1615 void SkPath::Iter::consumeDegenerateSegments(bool exact) { | 1615 void SkPath::Iter::consumeDegenerateSegments(bool exact) { |
| 1616 // We need to step over anything that will not move the current draw point | 1616 // We need to step over anything that will not move the current draw point |
| 1617 // forward before the next move is seen | 1617 // forward before the next move is seen |
| 1618 const uint8_t* lastMoveVerb = 0; | 1618 const uint8_t* lastMoveVerb = 0; |
| 1619 const SkPoint* lastMovePt = 0; | 1619 const SkPoint* lastMovePt = 0; |
| 1620 const SkScalar* lastMoveWeight = NULL; | 1620 const SkScalar* lastMoveWeight = nullptr; |
| 1621 SkPoint lastPt = fLastPt; | 1621 SkPoint lastPt = fLastPt; |
| 1622 while (fVerbs != fVerbStop) { | 1622 while (fVerbs != fVerbStop) { |
| 1623 unsigned verb = *(fVerbs - 1); // fVerbs is one beyond the current verb | 1623 unsigned verb = *(fVerbs - 1); // fVerbs is one beyond the current verb |
| 1624 switch (verb) { | 1624 switch (verb) { |
| 1625 case kMove_Verb: | 1625 case kMove_Verb: |
| 1626 // Keep a record of this most recent move | 1626 // Keep a record of this most recent move |
| 1627 lastMoveVerb = fVerbs; | 1627 lastMoveVerb = fVerbs; |
| 1628 lastMovePt = fPts; | 1628 lastMovePt = fPts; |
| 1629 lastMoveWeight = fConicWeights; | 1629 lastMoveWeight = fConicWeights; |
| 1630 lastPt = fPts[0]; | 1630 lastPt = fPts[0]; |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1769 break; | 1769 break; |
| 1770 } | 1770 } |
| 1771 fPts = srcPts; | 1771 fPts = srcPts; |
| 1772 return (Verb)verb; | 1772 return (Verb)verb; |
| 1773 } | 1773 } |
| 1774 | 1774 |
| 1775 /////////////////////////////////////////////////////////////////////////////// | 1775 /////////////////////////////////////////////////////////////////////////////// |
| 1776 | 1776 |
| 1777 SkPath::RawIter::RawIter() { | 1777 SkPath::RawIter::RawIter() { |
| 1778 #ifdef SK_DEBUG | 1778 #ifdef SK_DEBUG |
| 1779 fPts = NULL; | 1779 fPts = nullptr; |
| 1780 fConicWeights = NULL; | 1780 fConicWeights = nullptr; |
| 1781 #endif | 1781 #endif |
| 1782 // need to init enough to make next() harmlessly return kDone_Verb | 1782 // need to init enough to make next() harmlessly return kDone_Verb |
| 1783 fVerbs = NULL; | 1783 fVerbs = nullptr; |
| 1784 fVerbStop = NULL; | 1784 fVerbStop = nullptr; |
| 1785 } | 1785 } |
| 1786 | 1786 |
| 1787 SkPath::RawIter::RawIter(const SkPath& path) { | 1787 SkPath::RawIter::RawIter(const SkPath& path) { |
| 1788 this->setPath(path); | 1788 this->setPath(path); |
| 1789 } | 1789 } |
| 1790 | 1790 |
| 1791 void SkPath::RawIter::setPath(const SkPath& path) { | 1791 void SkPath::RawIter::setPath(const SkPath& path) { |
| 1792 fPts = path.fPathRef->points(); | 1792 fPts = path.fPathRef->points(); |
| 1793 fVerbs = path.fPathRef->verbs(); | 1793 fVerbs = path.fPathRef->verbs(); |
| 1794 fVerbStop = path.fPathRef->verbsMemBegin(); | 1794 fVerbStop = path.fPathRef->verbsMemBegin(); |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1843 | 1843 |
| 1844 /////////////////////////////////////////////////////////////////////////////// | 1844 /////////////////////////////////////////////////////////////////////////////// |
| 1845 | 1845 |
| 1846 /* | 1846 /* |
| 1847 Format in compressed buffer: [ptCount, verbCount, pts[], verbs[]] | 1847 Format in compressed buffer: [ptCount, verbCount, pts[], verbs[]] |
| 1848 */ | 1848 */ |
| 1849 | 1849 |
| 1850 size_t SkPath::writeToMemory(void* storage) const { | 1850 size_t SkPath::writeToMemory(void* storage) const { |
| 1851 SkDEBUGCODE(this->validate();) | 1851 SkDEBUGCODE(this->validate();) |
| 1852 | 1852 |
| 1853 if (NULL == storage) { | 1853 if (nullptr == storage) { |
| 1854 const int byteCount = sizeof(int32_t) + fPathRef->writeSize(); | 1854 const int byteCount = sizeof(int32_t) + fPathRef->writeSize(); |
| 1855 return SkAlign4(byteCount); | 1855 return SkAlign4(byteCount); |
| 1856 } | 1856 } |
| 1857 | 1857 |
| 1858 SkWBuffer buffer(storage); | 1858 SkWBuffer buffer(storage); |
| 1859 | 1859 |
| 1860 int32_t packed = (fConvexity << kConvexity_SerializationShift) | | 1860 int32_t packed = (fConvexity << kConvexity_SerializationShift) | |
| 1861 (fFillType << kFillType_SerializationShift) | | 1861 (fFillType << kFillType_SerializationShift) | |
| 1862 (fFirstDirection << kDirection_SerializationShift) | | 1862 (fFirstDirection << kDirection_SerializationShift) | |
| 1863 (fIsVolatile << kIsVolatile_SerializationShift) | | 1863 (fIsVolatile << kIsVolatile_SerializationShift) | |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1906 fFirstDirection = dir; | 1906 fFirstDirection = dir; |
| 1907 } | 1907 } |
| 1908 | 1908 |
| 1909 size_t sizeRead = 0; | 1909 size_t sizeRead = 0; |
| 1910 if (buffer.isValid()) { | 1910 if (buffer.isValid()) { |
| 1911 fPathRef.reset(pathRef); | 1911 fPathRef.reset(pathRef); |
| 1912 SkDEBUGCODE(this->validate();) | 1912 SkDEBUGCODE(this->validate();) |
| 1913 buffer.skipToAlign4(); | 1913 buffer.skipToAlign4(); |
| 1914 sizeRead = buffer.pos(); | 1914 sizeRead = buffer.pos(); |
| 1915 } else if (pathRef) { | 1915 } else if (pathRef) { |
| 1916 // If the buffer is not valid, pathRef should be NULL | 1916 // If the buffer is not valid, pathRef should be nullptr |
| 1917 sk_throw(); | 1917 sk_throw(); |
| 1918 } | 1918 } |
| 1919 return sizeRead; | 1919 return sizeRead; |
| 1920 } | 1920 } |
| 1921 | 1921 |
| 1922 /////////////////////////////////////////////////////////////////////////////// | 1922 /////////////////////////////////////////////////////////////////////////////// |
| 1923 | 1923 |
| 1924 #include "SkStringUtils.h" | 1924 #include "SkStringUtils.h" |
| 1925 #include "SkStream.h" | 1925 #include "SkStream.h" |
| 1926 | 1926 |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1999 SkDebugf("%s", builder.c_str()); | 1999 SkDebugf("%s", builder.c_str()); |
| 2000 builder.reset(); | 2000 builder.reset(); |
| 2001 } | 2001 } |
| 2002 } | 2002 } |
| 2003 if (wStream) { | 2003 if (wStream) { |
| 2004 wStream->writeText(builder.c_str()); | 2004 wStream->writeText(builder.c_str()); |
| 2005 } | 2005 } |
| 2006 } | 2006 } |
| 2007 | 2007 |
| 2008 void SkPath::dump() const { | 2008 void SkPath::dump() const { |
| 2009 this->dump(NULL, false, false); | 2009 this->dump(nullptr, false, false); |
| 2010 } | 2010 } |
| 2011 | 2011 |
| 2012 void SkPath::dumpHex() const { | 2012 void SkPath::dumpHex() const { |
| 2013 this->dump(NULL, false, true); | 2013 this->dump(nullptr, false, true); |
| 2014 } | 2014 } |
| 2015 | 2015 |
| 2016 #ifdef SK_DEBUG | 2016 #ifdef SK_DEBUG |
| 2017 void SkPath::validate() const { | 2017 void SkPath::validate() const { |
| 2018 SkASSERT((fFillType & ~3) == 0); | 2018 SkASSERT((fFillType & ~3) == 0); |
| 2019 | 2019 |
| 2020 #ifdef SK_DEBUG_PATH | 2020 #ifdef SK_DEBUG_PATH |
| 2021 if (!fBoundsIsDirty) { | 2021 if (!fBoundsIsDirty) { |
| 2022 SkRect bounds; | 2022 SkRect bounds; |
| 2023 | 2023 |
| (...skipping 784 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2808 switch (this->getFillType()) { | 2808 switch (this->getFillType()) { |
| 2809 case SkPath::kEvenOdd_FillType: | 2809 case SkPath::kEvenOdd_FillType: |
| 2810 case SkPath::kInverseEvenOdd_FillType: | 2810 case SkPath::kInverseEvenOdd_FillType: |
| 2811 w &= 1; | 2811 w &= 1; |
| 2812 break; | 2812 break; |
| 2813 default: | 2813 default: |
| 2814 break; | 2814 break; |
| 2815 } | 2815 } |
| 2816 return SkToBool(w); | 2816 return SkToBool(w); |
| 2817 } | 2817 } |
| OLD | NEW |