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

Commit 1fc1bd3

Browse files
csmartdalton86Skia Commit-Bot
authored andcommitted
Don't modify the pts array in SkOpEdgeBuilder::preFetch
Change-Id: I2596986cb203e00b1d6d24c0086e98eb6373142b Reviewed-on: https://skia-review.googlesource.com/c/skia/+/288178 Reviewed-by: Mike Reed <[email protected]> Commit-Queue: Chris Dalton <[email protected]>
1 parent 61642b3 commit 1fc1bd3

File tree

1 file changed

+27
-32
lines changed

1 file changed

+27
-32
lines changed

src/pathops/SkOpEdgeBuilder.cpp

Lines changed: 27 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,23 @@ void SkOpEdgeBuilder::init() {
1717
}
1818

1919
// very tiny points cause numerical instability : don't allow them
20-
static void force_small_to_zero(SkPoint* pt) {
21-
if (SkScalarAbs(pt->fX) < FLT_EPSILON_ORDERABLE_ERR) {
22-
pt->fX = 0;
20+
static SkPoint force_small_to_zero(const SkPoint& pt) {
21+
SkPoint ret = pt;
22+
if (SkScalarAbs(ret.fX) < FLT_EPSILON_ORDERABLE_ERR) {
23+
ret.fX = 0;
2324
}
24-
if (SkScalarAbs(pt->fY) < FLT_EPSILON_ORDERABLE_ERR) {
25-
pt->fY = 0;
25+
if (SkScalarAbs(ret.fY) < FLT_EPSILON_ORDERABLE_ERR) {
26+
ret.fY = 0;
2627
}
28+
return ret;
2729
}
2830

2931
static bool can_add_curve(SkPath::Verb verb, SkPoint* curve) {
3032
if (SkPath::kMove_Verb == verb) {
3133
return false;
3234
}
3335
for (int index = 0; index <= SkPathOpsVerbToPoints(verb); ++index) {
34-
force_small_to_zero(&curve[index]);
36+
curve[index] = force_small_to_zero(curve[index]);
3537
}
3638
return SkPath::kLine_Verb != verb || !SkDPoint::ApproximatelyEqual(curve[0], curve[1]);
3739
}
@@ -95,51 +97,44 @@ int SkOpEdgeBuilder::preFetch() {
9597
closeContour(curve[0], curveStart);
9698
}
9799
*fPathVerbs.append() = verb;
98-
force_small_to_zero(&pts[0]);
99-
*fPathPts.append() = pts[0];
100-
curveStart = curve[0] = pts[0];
100+
curve[0] = force_small_to_zero(pts[0]);
101+
*fPathPts.append() = curve[0];
102+
curveStart = curve[0];
101103
lastCurve = false;
102104
continue;
103105
case SkPath::kLine_Verb:
104-
force_small_to_zero(&pts[1]);
105-
if (SkDPoint::ApproximatelyEqual(curve[0], pts[1])) {
106+
curve[1] = force_small_to_zero(pts[1]);
107+
if (SkDPoint::ApproximatelyEqual(curve[0], curve[1])) {
106108
uint8_t lastVerb = fPathVerbs.top();
107109
if (lastVerb != SkPath::kLine_Verb && lastVerb != SkPath::kMove_Verb) {
108-
fPathPts.top() = curve[0] = pts[1];
110+
fPathPts.top() = curve[0] = curve[1];
109111
}
110112
continue; // skip degenerate points
111113
}
112114
break;
113115
case SkPath::kQuad_Verb:
114-
force_small_to_zero(&pts[1]);
115-
force_small_to_zero(&pts[2]);
116-
curve[1] = pts[1];
117-
curve[2] = pts[2];
118-
verb = SkReduceOrder::Quad(curve, pts);
116+
curve[1] = force_small_to_zero(pts[1]);
117+
curve[2] = force_small_to_zero(pts[2]);
118+
verb = SkReduceOrder::Quad(curve, curve);
119119
if (verb == SkPath::kMove_Verb) {
120120
continue; // skip degenerate points
121121
}
122122
break;
123123
case SkPath::kConic_Verb:
124-
force_small_to_zero(&pts[1]);
125-
force_small_to_zero(&pts[2]);
126-
curve[1] = pts[1];
127-
curve[2] = pts[2];
128-
verb = SkReduceOrder::Quad(curve, pts);
124+
curve[1] = force_small_to_zero(pts[1]);
125+
curve[2] = force_small_to_zero(pts[2]);
126+
verb = SkReduceOrder::Quad(curve, curve);
129127
if (SkPath::kQuad_Verb == verb && 1 != iter.conicWeight()) {
130128
verb = SkPath::kConic_Verb;
131129
} else if (verb == SkPath::kMove_Verb) {
132130
continue; // skip degenerate points
133131
}
134132
break;
135133
case SkPath::kCubic_Verb:
136-
force_small_to_zero(&pts[1]);
137-
force_small_to_zero(&pts[2]);
138-
force_small_to_zero(&pts[3]);
139-
curve[1] = pts[1];
140-
curve[2] = pts[2];
141-
curve[3] = pts[3];
142-
verb = SkReduceOrder::Cubic(curve, pts);
134+
curve[1] = force_small_to_zero(pts[1]);
135+
curve[2] = force_small_to_zero(pts[2]);
136+
curve[3] = force_small_to_zero(pts[3]);
137+
verb = SkReduceOrder::Cubic(curve, curve);
143138
if (verb == SkPath::kMove_Verb) {
144139
continue; // skip degenerate points
145140
}
@@ -153,11 +148,11 @@ int SkOpEdgeBuilder::preFetch() {
153148
}
154149
*fPathVerbs.append() = verb;
155150
int ptCount = SkPathOpsVerbToPoints(verb);
156-
fPathPts.append(ptCount, &pts[1]);
151+
fPathPts.append(ptCount, &curve[1]);
157152
if (verb == SkPath::kConic_Verb) {
158153
*fWeights.append() = iter.conicWeight();
159154
}
160-
curve[0] = pts[ptCount];
155+
curve[0] = curve[ptCount];
161156
lastCurve = true;
162157
} while (verb != SkPath::kDone_Verb);
163158
if (!fAllowOpenContours && lastCurve) {
@@ -218,7 +213,7 @@ bool SkOpEdgeBuilder::walk() {
218213
return false;
219214
}
220215
for (unsigned index = 0; index < SK_ARRAY_COUNT(pair); ++index) {
221-
force_small_to_zero(&pair[index]);
216+
pair[index] = force_small_to_zero(pair[index]);
222217
}
223218
SkPoint cStorage[2][2];
224219
SkPath::Verb v1 = SkReduceOrder::Quad(&pair[0], cStorage[0]);

0 commit comments

Comments
 (0)