Skip to content
This repository has been archived by the owner on Feb 25, 2025. It is now read-only.

Commit

Permalink
Don't modify the pts array in SkOpEdgeBuilder::preFetch
Browse files Browse the repository at this point in the history
Change-Id: I2596986cb203e00b1d6d24c0086e98eb6373142b
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/288178
Reviewed-by: Mike Reed <reed@google.com>
Commit-Queue: Chris Dalton <csmartdalton@google.com>
  • Loading branch information
csmartdalton86 authored and Skia Commit-Bot committed May 7, 2020
1 parent 61642b3 commit 1fc1bd3
Showing 1 changed file with 27 additions and 32 deletions.
59 changes: 27 additions & 32 deletions src/pathops/SkOpEdgeBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,23 @@ void SkOpEdgeBuilder::init() {
}

// very tiny points cause numerical instability : don't allow them
static void force_small_to_zero(SkPoint* pt) {
if (SkScalarAbs(pt->fX) < FLT_EPSILON_ORDERABLE_ERR) {
pt->fX = 0;
static SkPoint force_small_to_zero(const SkPoint& pt) {
SkPoint ret = pt;
if (SkScalarAbs(ret.fX) < FLT_EPSILON_ORDERABLE_ERR) {
ret.fX = 0;
}
if (SkScalarAbs(pt->fY) < FLT_EPSILON_ORDERABLE_ERR) {
pt->fY = 0;
if (SkScalarAbs(ret.fY) < FLT_EPSILON_ORDERABLE_ERR) {
ret.fY = 0;
}
return ret;
}

static bool can_add_curve(SkPath::Verb verb, SkPoint* curve) {
if (SkPath::kMove_Verb == verb) {
return false;
}
for (int index = 0; index <= SkPathOpsVerbToPoints(verb); ++index) {
force_small_to_zero(&curve[index]);
curve[index] = force_small_to_zero(curve[index]);
}
return SkPath::kLine_Verb != verb || !SkDPoint::ApproximatelyEqual(curve[0], curve[1]);
}
Expand Down Expand Up @@ -95,51 +97,44 @@ int SkOpEdgeBuilder::preFetch() {
closeContour(curve[0], curveStart);
}
*fPathVerbs.append() = verb;
force_small_to_zero(&pts[0]);
*fPathPts.append() = pts[0];
curveStart = curve[0] = pts[0];
curve[0] = force_small_to_zero(pts[0]);
*fPathPts.append() = curve[0];
curveStart = curve[0];
lastCurve = false;
continue;
case SkPath::kLine_Verb:
force_small_to_zero(&pts[1]);
if (SkDPoint::ApproximatelyEqual(curve[0], pts[1])) {
curve[1] = force_small_to_zero(pts[1]);
if (SkDPoint::ApproximatelyEqual(curve[0], curve[1])) {
uint8_t lastVerb = fPathVerbs.top();
if (lastVerb != SkPath::kLine_Verb && lastVerb != SkPath::kMove_Verb) {
fPathPts.top() = curve[0] = pts[1];
fPathPts.top() = curve[0] = curve[1];
}
continue; // skip degenerate points
}
break;
case SkPath::kQuad_Verb:
force_small_to_zero(&pts[1]);
force_small_to_zero(&pts[2]);
curve[1] = pts[1];
curve[2] = pts[2];
verb = SkReduceOrder::Quad(curve, pts);
curve[1] = force_small_to_zero(pts[1]);
curve[2] = force_small_to_zero(pts[2]);
verb = SkReduceOrder::Quad(curve, curve);
if (verb == SkPath::kMove_Verb) {
continue; // skip degenerate points
}
break;
case SkPath::kConic_Verb:
force_small_to_zero(&pts[1]);
force_small_to_zero(&pts[2]);
curve[1] = pts[1];
curve[2] = pts[2];
verb = SkReduceOrder::Quad(curve, pts);
curve[1] = force_small_to_zero(pts[1]);
curve[2] = force_small_to_zero(pts[2]);
verb = SkReduceOrder::Quad(curve, curve);
if (SkPath::kQuad_Verb == verb && 1 != iter.conicWeight()) {
verb = SkPath::kConic_Verb;
} else if (verb == SkPath::kMove_Verb) {
continue; // skip degenerate points
}
break;
case SkPath::kCubic_Verb:
force_small_to_zero(&pts[1]);
force_small_to_zero(&pts[2]);
force_small_to_zero(&pts[3]);
curve[1] = pts[1];
curve[2] = pts[2];
curve[3] = pts[3];
verb = SkReduceOrder::Cubic(curve, pts);
curve[1] = force_small_to_zero(pts[1]);
curve[2] = force_small_to_zero(pts[2]);
curve[3] = force_small_to_zero(pts[3]);
verb = SkReduceOrder::Cubic(curve, curve);
if (verb == SkPath::kMove_Verb) {
continue; // skip degenerate points
}
Expand All @@ -153,11 +148,11 @@ int SkOpEdgeBuilder::preFetch() {
}
*fPathVerbs.append() = verb;
int ptCount = SkPathOpsVerbToPoints(verb);
fPathPts.append(ptCount, &pts[1]);
fPathPts.append(ptCount, &curve[1]);
if (verb == SkPath::kConic_Verb) {
*fWeights.append() = iter.conicWeight();
}
curve[0] = pts[ptCount];
curve[0] = curve[ptCount];
lastCurve = true;
} while (verb != SkPath::kDone_Verb);
if (!fAllowOpenContours && lastCurve) {
Expand Down Expand Up @@ -218,7 +213,7 @@ bool SkOpEdgeBuilder::walk() {
return false;
}
for (unsigned index = 0; index < SK_ARRAY_COUNT(pair); ++index) {
force_small_to_zero(&pair[index]);
pair[index] = force_small_to_zero(pair[index]);
}
SkPoint cStorage[2][2];
SkPath::Verb v1 = SkReduceOrder::Quad(&pair[0], cStorage[0]);
Expand Down

0 comments on commit 1fc1bd3

Please sign in to comment.