diff options
author | 2016-11-04 13:31:54 -0700 | |
---|---|---|
committer | 2016-11-04 13:31:54 -0700 | |
commit | 2fd58a29d305accdefdcd7c7dbf1b902cd758a84 (patch) | |
tree | 979d07cf7b1d4820ed0c09f9b65e263ff4a29203 /src | |
parent | fba14207154a54cd3286aca6edf02800e2007517 (diff) |
Revert of use reversePathTo in place of addPathReverse (patchset #1 id:1 of https://codereview.chromium.org/2481463002/ )
Reason for revert:
breqking some bots
Original issue's description:
> use reversePathTo in place of addPathReverse
>
> Path ops was using addPathReverse, instead of reversePathTo.
> The former adds a moveTo always, and the latter requires
> that the caller add the moveTo if needed.
>
> Simplify the reversePathTo implementation.
>
> R=reed@google.com
> GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2481463002
>
> Committed: https://skia.googlesource.com/skia/+/d8db392be9dd1887df04b10b5670991d6b098c17
TBR=reed@google.com
# Skipping CQ checks because original CL landed less than 1 days ago.
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
Review-Url: https://codereview.chromium.org/2478763003
Diffstat (limited to 'src')
-rw-r--r-- | src/core/SkPath.cpp | 45 | ||||
-rw-r--r-- | src/pathops/SkOpBuilder.cpp | 20 | ||||
-rw-r--r-- | src/pathops/SkPathWriter.cpp | 2 |
3 files changed, 36 insertions, 31 deletions
diff --git a/src/core/SkPath.cpp b/src/core/SkPath.cpp index 6dbcda2233..c1b6327193 100644 --- a/src/core/SkPath.cpp +++ b/src/core/SkPath.cpp @@ -1567,38 +1567,49 @@ static int pts_in_verb(unsigned verb) { // ignore the last point of the 1st contour void SkPath::reversePathTo(const SkPath& path) { - const uint8_t* verbs = path.fPathRef->verbsMemBegin(); // points at the last verb - if (!verbs) { // empty path returns nullptr + int i, vcount = path.fPathRef->countVerbs(); + // exit early if the path is empty, or just has a moveTo. + if (vcount < 2) { return; } - const uint8_t* verbsEnd = path.fPathRef->verbs() - 1; // points just past the first verb - SkASSERT(verbsEnd[0] == kMove_Verb); - const SkPoint* pts = path.fPathRef->pointsEnd() - 1; - const SkScalar* conicWeights = path.fPathRef->conicWeightsEnd(); - while (verbs < verbsEnd) { - uint8_t v = *verbs++; - pts -= pts_in_verb(v); - switch (v) { + SkPathRef::Editor(&fPathRef, vcount, path.countPoints()); + + const uint8_t* verbs = path.fPathRef->verbs(); + const SkPoint* pts = path.fPathRef->points(); + const SkScalar* conicWeights = path.fPathRef->conicWeights(); + + SkASSERT(verbs[~0] == kMove_Verb); + for (i = 1; i < vcount; ++i) { + unsigned v = verbs[~i]; + int n = pts_in_verb(v); + if (n == 0) { + break; + } + pts += n; + conicWeights += (SkPath::kConic_Verb == v); + } + + while (--i > 0) { + switch (verbs[~i]) { case kLine_Verb: - this->lineTo(pts[0]); + this->lineTo(pts[-1].fX, pts[-1].fY); break; case kQuad_Verb: - this->quadTo(pts[1], pts[0]); + this->quadTo(pts[-1].fX, pts[-1].fY, pts[-2].fX, pts[-2].fY); break; case kConic_Verb: - this->conicTo(pts[1], pts[0], *--conicWeights); + this->conicTo(pts[-1], pts[-2], *--conicWeights); break; case kCubic_Verb: - this->cubicTo(pts[2], pts[1], pts[0]); - break; - case kClose_Verb: - SkASSERT(verbs - path.fPathRef->verbsMemBegin() == 1); + this->cubicTo(pts[-1].fX, pts[-1].fY, pts[-2].fX, pts[-2].fY, + pts[-3].fX, pts[-3].fY); break; default: SkDEBUGFAIL("bad verb"); break; } + pts -= pts_in_verb(verbs[~i]); } } diff --git a/src/pathops/SkOpBuilder.cpp b/src/pathops/SkOpBuilder.cpp index 075520d2c1..011d6a6aba 100644 --- a/src/pathops/SkOpBuilder.cpp +++ b/src/pathops/SkOpBuilder.cpp @@ -25,17 +25,7 @@ static bool one_contour(const SkPath& path) { return true; } -void SkOpBuilder::ReversePath(SkPath* path) { - SkPath temp; - SkPoint lastPt; - SkAssertResult(path->getLastPt(&lastPt)); - temp.moveTo(lastPt); - temp.reversePathTo(*path); - temp.close(); - *path = temp; -} - -bool SkOpBuilder::FixWinding(SkPath* path) { +bool FixWinding(SkPath* path) { SkPath::FillType fillType = path->getFillType(); if (fillType == SkPath::kInverseEvenOdd_FillType) { fillType = SkPath::kInverseWinding_FillType; @@ -45,7 +35,9 @@ bool SkOpBuilder::FixWinding(SkPath* path) { SkPathPriv::FirstDirection dir; if (one_contour(*path) && SkPathPriv::CheapComputeFirstDirection(*path, &dir)) { if (dir != SkPathPriv::kCCW_FirstDirection) { - ReversePath(path); + SkPath temp; + temp.reverseAddPath(*path); + *path = temp; } path->setFillType(fillType); return true; @@ -141,7 +133,9 @@ bool SkOpBuilder::resolve(SkPath* result) { if (firstDir == SkPathPriv::kUnknown_FirstDirection) { firstDir = dir; } else if (firstDir != dir) { - ReversePath(test); + SkPath temp; + temp.reverseAddPath(*test); + *test = temp; } continue; } diff --git a/src/pathops/SkPathWriter.cpp b/src/pathops/SkPathWriter.cpp index 9893a502ca..c94809e8ec 100644 --- a/src/pathops/SkPathWriter.cpp +++ b/src/pathops/SkPathWriter.cpp @@ -306,7 +306,7 @@ void SkPathWriter::assemble() { first ? SkPath::kAppend_AddPathMode : SkPath::kExtend_AddPathMode); } else { SkASSERT(!first); - fPathPtr->reversePathTo(contour); + fPathPtr->reverseAddPath(contour); } if (first) { first = false; |