add special-case for chopping at exactly half for rational-quads (2-3x faster)
git-svn-id: http://skia.googlecode.com/svn/trunk@8672 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
parent
4af6280aa3
commit
8d55101196
@ -864,6 +864,68 @@ private:
|
||||
typedef SkBenchmark INHERITED;
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "SkGeometry.h"
|
||||
|
||||
class RationalQuadBench_Chop5 : public SkBenchmark {
|
||||
enum {
|
||||
N = 100000
|
||||
};
|
||||
SkRationalQuad fRQ;
|
||||
public:
|
||||
RationalQuadBench_Chop5(void* param) : INHERITED(param) {
|
||||
fRQ.fPts[0].set(0, 0);
|
||||
fRQ.fPts[1].set(100, 0);
|
||||
fRQ.fPts[2].set(100, 100);
|
||||
fRQ.fW = SkScalarCos(SK_ScalarPI/4);
|
||||
}
|
||||
|
||||
private:
|
||||
virtual const char* onGetName() SK_OVERRIDE {
|
||||
return "ratquad-chop-0.5";
|
||||
}
|
||||
|
||||
virtual void onDraw(SkCanvas*) SK_OVERRIDE {
|
||||
SkRationalQuad dst[2];
|
||||
for (int i = 0; i < N; ++i) {
|
||||
fRQ.chopAt(0.5f, dst);
|
||||
}
|
||||
}
|
||||
|
||||
typedef SkBenchmark INHERITED;
|
||||
};
|
||||
|
||||
class RationalQuadBench_ChopHalf : public SkBenchmark {
|
||||
enum {
|
||||
N = 100000
|
||||
};
|
||||
SkRationalQuad fRQ;
|
||||
public:
|
||||
RationalQuadBench_ChopHalf(void* param) : INHERITED(param) {
|
||||
fRQ.fPts[0].set(0, 0);
|
||||
fRQ.fPts[1].set(100, 0);
|
||||
fRQ.fPts[2].set(100, 100);
|
||||
fRQ.fW = SkScalarCos(SK_ScalarPI/4);
|
||||
}
|
||||
|
||||
private:
|
||||
virtual const char* onGetName() SK_OVERRIDE {
|
||||
return "ratquad-chop-half";
|
||||
}
|
||||
|
||||
virtual void onDraw(SkCanvas*) SK_OVERRIDE {
|
||||
SkRationalQuad dst[2];
|
||||
for (int i = 0; i < N; ++i) {
|
||||
fRQ.chop(dst);
|
||||
}
|
||||
}
|
||||
|
||||
typedef SkBenchmark INHERITED;
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
const SkRect ConservativelyContainsBench::kBounds = SkRect::MakeWH(SkIntToScalar(100), SkIntToScalar(100));
|
||||
const SkSize ConservativelyContainsBench::kQueryMin = SkSize::Make(SkIntToScalar(1), SkIntToScalar(1));
|
||||
const SkSize ConservativelyContainsBench::kQueryMax = SkSize::Make(SkIntToScalar(40), SkIntToScalar(40));
|
||||
@ -918,3 +980,6 @@ DEF_BENCH( return new ArbRoundRectBench(p, true); )
|
||||
DEF_BENCH( return new ConservativelyContainsBench(p, ConservativelyContainsBench::kRect_Type); )
|
||||
DEF_BENCH( return new ConservativelyContainsBench(p, ConservativelyContainsBench::kRoundRect_Type); )
|
||||
DEF_BENCH( return new ConservativelyContainsBench(p, ConservativelyContainsBench::kOval_Type); )
|
||||
|
||||
DEF_BENCH( return new RationalQuadBench_Chop5(p) )
|
||||
DEF_BENCH( return new RationalQuadBench_ChopHalf(p) )
|
||||
|
@ -218,6 +218,7 @@ struct SkRationalQuad {
|
||||
|
||||
void evalAt(SkScalar t, SkPoint* pt) const;
|
||||
void chopAt(SkScalar t, SkRationalQuad dst[2]) const;
|
||||
void chop(SkRationalQuad dst[2]) const;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -1464,3 +1464,24 @@ void SkRationalQuad::chopAt(SkScalar t, SkRationalQuad dst[2]) const {
|
||||
dst[0].fW = tmp2[0].fZ / root;
|
||||
dst[1].fW = tmp2[2].fZ / root;
|
||||
}
|
||||
|
||||
void SkRationalQuad::chop(SkRationalQuad dst[2]) const {
|
||||
SkScalar scale = SkScalarInvert(SK_Scalar1 + fW);
|
||||
SkScalar p1x = fW * fPts[1].fX;
|
||||
SkScalar p1y = fW * fPts[1].fY;
|
||||
SkScalar mx = (fPts[0].fX + 2 * p1x + fPts[2].fX) * scale * SK_ScalarHalf;
|
||||
SkScalar my = (fPts[0].fY + 2 * p1y + fPts[2].fY) * scale * SK_ScalarHalf;
|
||||
|
||||
dst[0].fPts[0] = fPts[0];
|
||||
dst[0].fPts[1].set((fPts[0].fX + p1x) * scale,
|
||||
(fPts[0].fY + p1y) * scale);
|
||||
dst[0].fPts[2].set(mx, my);
|
||||
|
||||
dst[1].fPts[0].set(mx, my);
|
||||
dst[1].fPts[1].set((p1x + fPts[2].fX) * scale,
|
||||
(p1y + fPts[2].fY) * scale);
|
||||
dst[1].fPts[2] = fPts[2];
|
||||
|
||||
dst[0].fW = dst[1].fW = SkScalarSqrt((1 + fW) * SK_ScalarHalf);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user