diff options
author | mike@reedtribe.org <mike@reedtribe.org@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2013-04-30 02:14:58 +0000 |
---|---|---|
committer | mike@reedtribe.org <mike@reedtribe.org@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2013-04-30 02:14:58 +0000 |
commit | af5c506cd6b63f43a0ebee2fb171ea55ba98e09f (patch) | |
tree | 7596651f2dadbde52dabe449edb3add85891e1b1 /bench | |
parent | c56009118970d634cdb6c50ff4616c8eb446cda0 (diff) |
add routines to compute error between conic and quad
git-svn-id: http://skia.googlecode.com/svn/trunk@8916 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'bench')
-rw-r--r-- | bench/PathBench.cpp | 107 |
1 files changed, 104 insertions, 3 deletions
diff --git a/bench/PathBench.cpp b/bench/PathBench.cpp index dc95ea669b..6ef78ccdd7 100644 --- a/bench/PathBench.cpp +++ b/bench/PathBench.cpp @@ -15,7 +15,6 @@ #include "SkString.h" #include "SkTArray.h" - enum Flags { kStroke_Flag = 1 << 0, kBig_Flag = 1 << 1 @@ -908,22 +907,120 @@ public: 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 { SkConic dst[2]; for (int i = 0; i < N; ++i) { fRQ.chop(dst); } } + + typedef SkBenchmark INHERITED; +}; + +/////////////////////////////////////////////////////////////////////////////// +static void rand_conic(SkConic* conic, SkRandom& rand) { + for (int i = 0; i < 3; ++i) { + conic->fPts[i].set(rand.nextUScalar1() * 100, rand.nextUScalar1() * 100); + } + if (rand.nextUScalar1() > 0.5f) { + conic->fW = rand.nextUScalar1(); + } else { + conic->fW = 1 + rand.nextUScalar1() * 4; + } +} + +class ConicBench : public SkBenchmark { +public: + ConicBench(void* param) : INHERITED(param) { + SkRandom rand; + for (int i = 0; i < CONICS; ++i) { + rand_conic(&fConics[i], rand); + } + fIsRendering = false; + } + +protected: + enum { + N = 20000, + CONICS = 100 + }; + SkConic fConics[CONICS]; + +private: typedef SkBenchmark INHERITED; }; +class ConicBench_ComputeError : public ConicBench { +public: + ConicBench_ComputeError(void* param) : INHERITED(param) {} + +protected: + virtual const char* onGetName() SK_OVERRIDE { + return "conic-compute-error"; + } + + virtual void onDraw(SkCanvas*) SK_OVERRIDE { + SkVector err; + for (int i = 0; i < N; ++i) { + for (int j = 0; j < CONICS; ++j) { + fConics[j].computeAsQuadError(&err); + } + } + } + +private: + typedef ConicBench INHERITED; +}; + +class ConicBench_asQuadTol : public ConicBench { +public: + ConicBench_asQuadTol(void* param) : INHERITED(param) {} + +protected: + virtual const char* onGetName() SK_OVERRIDE { + return "conic-asQuadTol"; + } + + virtual void onDraw(SkCanvas*) SK_OVERRIDE { + for (int i = 0; i < N; ++i) { + for (int j = 0; j < CONICS; ++j) { + fConics[j].asQuadTol(SK_ScalarHalf); + } + } + } + +private: + typedef ConicBench INHERITED; +}; + +class ConicBench_quadPow2 : public ConicBench { +public: + ConicBench_quadPow2(void* param) : INHERITED(param) {} + +protected: + virtual const char* onGetName() SK_OVERRIDE { + return "conic-quadPow2"; + } + + virtual void onDraw(SkCanvas*) SK_OVERRIDE { + for (int i = 0; i < N; ++i) { + for (int j = 0; j < CONICS; ++j) { + fConics[j].computeQuadPOW2(SK_ScalarHalf); + } + } + } + +private: + typedef ConicBench INHERITED; +}; + /////////////////////////////////////////////////////////////////////////////// const SkRect ConservativelyContainsBench::kBounds = SkRect::MakeWH(SkIntToScalar(100), SkIntToScalar(100)); @@ -983,3 +1080,7 @@ DEF_BENCH( return new ConservativelyContainsBench(p, ConservativelyContainsBench DEF_BENCH( return new ConicBench_Chop5(p) ) DEF_BENCH( return new ConicBench_ChopHalf(p) ) +DEF_BENCH( return new ConicBench_ComputeError(p) ) +DEF_BENCH( return new ConicBench_asQuadTol(p) ) +DEF_BENCH( return new ConicBench_quadPow2(p) ) + |