remove slower scalar code in favor of vectors
BUG=skia: Review URL: https://codereview.chromium.org/1001833006
This commit is contained in:
parent
65cdb57ae8
commit
c08330f160
@ -212,9 +212,9 @@ DEF_BENCH( return new EvalQuadTangentAt1; )
|
||||
|
||||
////////
|
||||
|
||||
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 @@ protected:
|
||||
}
|
||||
}
|
||||
};
|
||||
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 @@ protected:
|
||||
}
|
||||
}
|
||||
};
|
||||
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; )
|
||||
|
||||
|
@ -179,29 +179,11 @@ SkVector SkEvalQuadTangentAt(const SkPoint src[3], SkScalar t) {
|
||||
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 SkChopQuadAt2(const SkPoint src[3], SkPoint dst[5], SkScalar t) {
|
||||
}
|
||||
|
||||
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 @@ int SkFindCubicExtrema(SkScalar a, SkScalar b, SkScalar c, SkScalar d,
|
||||
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 SkChopCubicAt(const SkPoint src[4], SkPoint dst[],
|
||||
}
|
||||
|
||||
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]) {
|
||||
|
@ -19,7 +19,6 @@ int SkFindUnitQuadRoots(SkScalar A, SkScalar B, SkScalar C, SkScalar roots[2]);
|
||||
|
||||
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 @@ void SkEvalCubicAt(const SkPoint src[4], SkScalar t, SkPoint* locOrNull,
|
||||
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:
|
||||
|
@ -63,38 +63,7 @@ static void test_evalquadat(skiatest::Reporter* reporter) {
|
||||
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 @@ DEF_TEST(Geometry, reporter) {
|
||||
testChopCubic(reporter);
|
||||
test_evalquadat(reporter);
|
||||
test_conic(reporter);
|
||||
test_cubicat(reporter);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user