From 317d540409bc1d246a272b7f61ffba0097c4bd29 Mon Sep 17 00:00:00 2001 From: "tomhudson@google.com" Date: Fri, 24 Jun 2011 18:30:49 +0000 Subject: [PATCH] New benchmark for SkMatrix::computeType(). Utility function in SkMatrix to make benchmarking more accurate. git-svn-id: http://skia.googlecode.com/svn/trunk@1710 2bbb7eff-a529-9590-31e7-b0007b416f81 --- bench/MatrixBench.cpp | 51 ++++++++++++++++++++++++++++++++++++++++++++++--- include/core/SkMatrix.h | 9 ++++++++- 2 files changed, 56 insertions(+), 4 deletions(-) diff --git a/bench/MatrixBench.cpp b/bench/MatrixBench.cpp index dce0358..865e6f2 100644 --- a/bench/MatrixBench.cpp +++ b/bench/MatrixBench.cpp @@ -56,9 +56,6 @@ protected: always_do(m0 == m1); always_do(m1 == m2); always_do(m2 == m0); - always_do(m0.getType()); - always_do(m1.getType()); - always_do(m2.getType()); } private: typedef MatrixBench INHERITED; @@ -214,6 +211,51 @@ private: typedef MatrixBench INHERITED; }; +class GetTypeMatrixBench : public MatrixBench { +public: + GetTypeMatrixBench(void* param) + : INHERITED(param, "gettype") { + fArray[0] = fRnd.nextS(); + fArray[1] = fRnd.nextS(); + fArray[2] = fRnd.nextS(); + fArray[3] = fRnd.nextS(); + fArray[4] = fRnd.nextS(); + fArray[5] = fRnd.nextS(); + fArray[6] = fRnd.nextS(); + fArray[7] = fRnd.nextS(); + fArray[8] = fRnd.nextS(); + } +protected: + // Putting random generation of the matrix inside performTest() + // would help us avoid anomalous runs, but takes up 25% or + // more of the function time. + virtual void performTest() { + fMatrix.setAll(fArray[0], fArray[1], fArray[2], + fArray[3], fArray[4], fArray[5], + fArray[6], fArray[7], fArray[8]); + always_do(fMatrix.getType()); + fMatrix.dirtyMatrixTypeCache(); + always_do(fMatrix.getType()); + fMatrix.dirtyMatrixTypeCache(); + always_do(fMatrix.getType()); + fMatrix.dirtyMatrixTypeCache(); + always_do(fMatrix.getType()); + fMatrix.dirtyMatrixTypeCache(); + always_do(fMatrix.getType()); + fMatrix.dirtyMatrixTypeCache(); + always_do(fMatrix.getType()); + fMatrix.dirtyMatrixTypeCache(); + always_do(fMatrix.getType()); + fMatrix.dirtyMatrixTypeCache(); + always_do(fMatrix.getType()); + } +private: + SkMatrix fMatrix; + float fArray[9]; + SkRandom fRnd; + typedef MatrixBench INHERITED; +}; + #ifdef SK_SCALAR_IS_FLOAT class ScaleTransMixedMatrixBench : public MatrixBench { public: @@ -253,6 +295,7 @@ class ScaleTransMixedMatrixBench : public MatrixBench { SkRandom fRandom; typedef MatrixBench INHERITED; }; +>>>>>>> .r1709 class ScaleTransDoubleMatrixBench : public MatrixBench { @@ -303,12 +346,14 @@ static SkBenchmark* M1(void* p) { return new ScaleMatrixBench(p); } static SkBenchmark* M2(void* p) { return new FloatConcatMatrixBench(p); } static SkBenchmark* M3(void* p) { return new FloatDoubleConcatMatrixBench(p); } static SkBenchmark* M4(void* p) { return new DoubleConcatMatrixBench(p); } +static SkBenchmark* M5(void* p) { return new GetTypeMatrixBench(p); } static BenchRegistry gReg0(M0); static BenchRegistry gReg1(M1); static BenchRegistry gReg2(M2); static BenchRegistry gReg3(M3); static BenchRegistry gReg4(M4); +static BenchRegistry gReg5(M5); #ifdef SK_SCALAR_IS_FLOAT static SkBenchmark* FlM0(void* p) { return new ScaleTransMixedMatrixBench(p); } diff --git a/include/core/SkMatrix.h b/include/core/SkMatrix.h index 480e077..533e534 100644 --- a/include/core/SkMatrix.h +++ b/include/core/SkMatrix.h @@ -484,6 +484,14 @@ public: */ static const SkMatrix& InvalidMatrix(); + /** + * Testing routine; the matrix's type cache should never need to be + * manually invalidated during normal use. + */ + void dirtyMatrixTypeCache() { + this->setTypeMask(kUnknown_Mask); + } + private: enum { /** Set if the matrix will map a rectangle to another rectangle. This @@ -560,4 +568,3 @@ private: }; #endif - -- 2.7.4