remove slower scalar code in favor of vectors
BUG=skia:
Review URL: https://codereview.chromium.org/1001833006
diff --git a/bench/GeometryBench.cpp b/bench/GeometryBench.cpp
index 501c7b8..6cd9ca2 100644
--- a/bench/GeometryBench.cpp
+++ b/bench/GeometryBench.cpp
@@ -212,9 +212,9 @@
////////
-class ChopQuadAt0 : public QuadBenchBase {
+class ChopQuadAt : public QuadBenchBase {
public:
- ChopQuadAt0() : QuadBenchBase("chopquadat0") {}
+ ChopQuadAt() : QuadBenchBase("chopquadat") {}
protected:
void onDraw(const int loops, SkCanvas* canvas) override {
SkPoint dst[5];
@@ -226,27 +226,11 @@
}
}
};
-DEF_BENCH( return new ChopQuadAt0; )
+DEF_BENCH( return new ChopQuadAt; )
-class ChopQuadAt1 : public QuadBenchBase {
+class ChopCubicAt : public QuadBenchBase {
public:
- ChopQuadAt1() : QuadBenchBase("chopquadat1") {}
-protected:
- void onDraw(const int loops, SkCanvas* canvas) override {
- SkPoint dst[5];
- for (int outer = 0; outer < loops; ++outer) {
- SkChopQuadAt2(fPts, dst, 0.5f);
- SkChopQuadAt2(fPts, dst, 0.5f);
- SkChopQuadAt2(fPts, dst, 0.5f);
- SkChopQuadAt2(fPts, dst, 0.5f);
- }
- }
-};
-DEF_BENCH( return new ChopQuadAt1; )
-
-class ChopCubicAt0 : public QuadBenchBase {
-public:
- ChopCubicAt0() : QuadBenchBase("chopcubicat0") {}
+ ChopCubicAt() : QuadBenchBase("chopcubicat0") {}
protected:
void onDraw(const int loops, SkCanvas* canvas) override {
SkPoint dst[7];
@@ -258,21 +242,5 @@
}
}
};
-DEF_BENCH( return new ChopCubicAt0; )
-
-class ChopCubicAt1 : public QuadBenchBase {
-public:
- ChopCubicAt1() : QuadBenchBase("chopcubicat1") {}
-protected:
- void onDraw(const int loops, SkCanvas* canvas) override {
- SkPoint dst[7];
- for (int outer = 0; outer < loops; ++outer) {
- SkChopCubicAt2(fPts, dst, 0.5f);
- SkChopCubicAt2(fPts, dst, 0.5f);
- SkChopCubicAt2(fPts, dst, 0.5f);
- SkChopCubicAt2(fPts, dst, 0.5f);
- }
- }
-};
-DEF_BENCH( return new ChopCubicAt1; )
+DEF_BENCH( return new ChopCubicAt; )
diff --git a/src/core/SkGeometry.cpp b/src/core/SkGeometry.cpp
index 62c5903..24946b9 100644
--- a/src/core/SkGeometry.cpp
+++ b/src/core/SkGeometry.cpp
@@ -179,29 +179,11 @@
return to_vector(T + T);
}
-static void interp_quad_coords(const SkScalar* src, SkScalar* dst, SkScalar t) {
- SkScalar ab = SkScalarInterp(src[0], src[2], t);
- SkScalar bc = SkScalarInterp(src[2], src[4], t);
-
- dst[0] = src[0];
- dst[2] = ab;
- dst[4] = SkScalarInterp(ab, bc, t);
- dst[6] = bc;
- dst[8] = src[4];
-}
-
-void SkChopQuadAt(const SkPoint src[3], SkPoint dst[5], SkScalar t) {
- SkASSERT(t > 0 && t < SK_Scalar1);
-
- interp_quad_coords(&src[0].fX, &dst[0].fX, t);
- interp_quad_coords(&src[0].fY, &dst[0].fY, t);
-}
-
static inline Sk2s interp(const Sk2s& v0, const Sk2s& v1, const Sk2s& t) {
return v0 + (v1 - v0) * t;
}
-void SkChopQuadAt2(const SkPoint src[3], SkPoint dst[5], SkScalar t) {
+void SkChopQuadAt(const SkPoint src[3], SkPoint dst[5], SkScalar t) {
SkASSERT(t > 0 && t < SK_Scalar1);
Sk2s p0 = from_point(src[0]);
@@ -220,16 +202,7 @@
}
void SkChopQuadAtHalf(const SkPoint src[3], SkPoint dst[5]) {
- SkScalar x01 = SkScalarAve(src[0].fX, src[1].fX);
- SkScalar y01 = SkScalarAve(src[0].fY, src[1].fY);
- SkScalar x12 = SkScalarAve(src[1].fX, src[2].fX);
- SkScalar y12 = SkScalarAve(src[1].fY, src[2].fY);
-
- dst[0] = src[0];
- dst[1].set(x01, y01);
- dst[2].set(SkScalarAve(x01, x12), SkScalarAve(y01, y12));
- dst[3].set(x12, y12);
- dst[4] = src[2];
+ SkChopQuadAt(src, dst, 0.5f); return;
}
/** Quad'(t) = At + B, where
@@ -454,34 +427,9 @@
return SkFindUnitQuadRoots(A, B, C, tValues);
}
-static void interp_cubic_coords(const SkScalar* src, SkScalar* dst,
- SkScalar t) {
- SkScalar ab = SkScalarInterp(src[0], src[2], t);
- SkScalar bc = SkScalarInterp(src[2], src[4], t);
- SkScalar cd = SkScalarInterp(src[4], src[6], t);
- SkScalar abc = SkScalarInterp(ab, bc, t);
- SkScalar bcd = SkScalarInterp(bc, cd, t);
- SkScalar abcd = SkScalarInterp(abc, bcd, t);
-
- dst[0] = src[0];
- dst[2] = ab;
- dst[4] = abc;
- dst[6] = abcd;
- dst[8] = bcd;
- dst[10] = cd;
- dst[12] = src[6];
-}
-
void SkChopCubicAt(const SkPoint src[4], SkPoint dst[7], SkScalar t) {
SkASSERT(t > 0 && t < SK_Scalar1);
- interp_cubic_coords(&src[0].fX, &dst[0].fX, t);
- interp_cubic_coords(&src[0].fY, &dst[0].fY, t);
-}
-
-void SkChopCubicAt2(const SkPoint src[4], SkPoint dst[7], SkScalar t) {
- SkASSERT(t > 0 && t < SK_Scalar1);
-
Sk2s p0 = from_point(src[0]);
Sk2s p1 = from_point(src[1]);
Sk2s p2 = from_point(src[2]);
@@ -571,25 +519,7 @@
}
void SkChopCubicAtHalf(const SkPoint src[4], SkPoint dst[7]) {
- SkScalar x01 = SkScalarAve(src[0].fX, src[1].fX);
- SkScalar y01 = SkScalarAve(src[0].fY, src[1].fY);
- SkScalar x12 = SkScalarAve(src[1].fX, src[2].fX);
- SkScalar y12 = SkScalarAve(src[1].fY, src[2].fY);
- SkScalar x23 = SkScalarAve(src[2].fX, src[3].fX);
- SkScalar y23 = SkScalarAve(src[2].fY, src[3].fY);
-
- SkScalar x012 = SkScalarAve(x01, x12);
- SkScalar y012 = SkScalarAve(y01, y12);
- SkScalar x123 = SkScalarAve(x12, x23);
- SkScalar y123 = SkScalarAve(y12, y23);
-
- dst[0] = src[0];
- dst[1].set(x01, y01);
- dst[2].set(x012, y012);
- dst[3].set(SkScalarAve(x012, x123), SkScalarAve(y012, y123));
- dst[4].set(x123, y123);
- dst[5].set(x23, y23);
- dst[6] = src[3];
+ SkChopCubicAt(src, dst, 0.5f);
}
static void flatten_double_cubic_extrema(SkScalar coords[14]) {
diff --git a/src/core/SkGeometry.h b/src/core/SkGeometry.h
index c8c41f9..a87a19f 100644
--- a/src/core/SkGeometry.h
+++ b/src/core/SkGeometry.h
@@ -19,7 +19,6 @@
SkPoint SkEvalQuadAt(const SkPoint src[3], SkScalar t);
SkPoint SkEvalQuadTangentAt(const SkPoint src[3], SkScalar t);
-void SkChopQuadAt2(const SkPoint src[3], SkPoint dst[5], SkScalar t);
/** Set pt to the point on the src quadratic specified by t. t must be
0 <= t <= 1.0
@@ -95,7 +94,6 @@
dst[0..3] and dst[3..6]
*/
void SkChopCubicAt(const SkPoint src[4], SkPoint dst[7], SkScalar t);
-void SkChopCubicAt2(const SkPoint src[4], SkPoint dst[7], SkScalar t);
/** Given a src cubic bezier, chop it at the specified t values,
where 0 < t < 1, and return the new cubics in dst:
diff --git a/tests/GeometryTest.cpp b/tests/GeometryTest.cpp
index 4109c0a..846afae 100644
--- a/tests/GeometryTest.cpp
+++ b/tests/GeometryTest.cpp
@@ -63,38 +63,7 @@
SkEvalQuadAt(pts, t, NULL, &v0);
SkVector v1 = SkEvalQuadTangentAt(pts, t);
check_pairs(reporter, i, t, "quad-tan", v0.fX, v0.fY, v1.fX, v1.fY);
-
- SkPoint dst0[5], dst1[5];
- SkChopQuadAt(pts, dst0, t);
- SkChopQuadAt2(pts, dst1, t);
- for (int k = 0; k < 5; ++k) {
- check_pairs(reporter, i, t, "chop-quad",
- dst0[k].fX, dst0[k].fY, dst1[k].fX, dst1[k].fY);
- }
-
- t += dt;
- }
- }
-}
-static void test_cubicat(skiatest::Reporter* reporter) {
- SkRandom rand;
- for (int i = 0; i < 1000; ++i) {
- SkPoint pts[4];
- for (int j = 0; j < 4; ++j) {
- pts[j].set(rand.nextSScalar1() * 100, rand.nextSScalar1() * 100);
- }
- const SkScalar dt = SK_Scalar1 / 128;
- SkScalar t = dt;
- for (int j = 1; j < 128; ++j) {
- SkPoint dst0[7], dst1[7];
- SkChopCubicAt(pts, dst0, t);
- SkChopCubicAt2(pts, dst1, t);
- for (int k = 0; k < 7; ++k) {
- check_pairs(reporter, i, t, "chop-cubic",
- dst0[k].fX, dst0[k].fY, dst1[k].fX, dst1[k].fY);
- }
-
t += dt;
}
}
@@ -179,5 +148,4 @@
testChopCubic(reporter);
test_evalquadat(reporter);
test_conic(reporter);
- test_cubicat(reporter);
}