Index: bench/RectBench.cpp |
diff --git a/bench/RectBench.cpp b/bench/RectBench.cpp |
index 46a515de299705f5c7ce77222057929aee28e5bc..0f757a2b5fc7ac261a563d2d695c0b7142eb833d 100644 |
--- a/bench/RectBench.cpp |
+++ b/bench/RectBench.cpp |
@@ -302,3 +302,93 @@ DEF_BENCH(return new BlitMaskBench(SkCanvas::kPoints_PointMode, |
DEF_BENCH(return new BlitMaskBench(SkCanvas::kPoints_PointMode, |
BlitMaskBench::KMaskShader, |
"maskshader");) |
+ |
+/////////////////////////////////////////////////////////////////////////////////////////////////// |
+ |
+typedef int (*RectMathProc)(const SkMatrix&, const SkRect[], const SkIRect[], int count); |
+ |
+class RectMathBench : public Benchmark { |
+ SkString fName; |
+ SkRandom fRand; |
+ SkString fSuffix; |
+ RectMathProc fProc; |
+ |
+public: |
+ enum { |
+ N = 300, |
+ OUTER = 10000, |
+ }; |
+ SkRect fRects[N]; |
+ SkIRect fIRects[N]; |
+ volatile int fCounter; |
+ |
+ RectMathBench(RectMathProc proc, const char* suffix) { |
+ fProc = proc; |
+ fSuffix.set(suffix); |
+ SkRandom rand; |
+ for (int i = 0; i < N; ++i) { |
+ fRects[i].setXYWH(rand.nextUScalar1() * 100, rand.nextUScalar1() * 100, |
+ rand.nextUScalar1() * 100, rand.nextUScalar1() * 100); |
+ fIRects[i].setXYWH(i, i, 10, 10); |
+ } |
+ } |
+ |
+ bool isVisual() override { return false; } |
+ |
+protected: |
+ const char* onGetName() override { |
+ fName.printf("rect_math_%s", fSuffix.c_str()); |
+ return fName.c_str(); |
+ } |
+ |
+ void onDraw(int loops, SkCanvas* canvas) override { |
+ SkMatrix mat; |
+ for (int j = 0; j < OUTER; ++j) { |
+ mat.setScaleTranslate(fRand.nextUScalar1(), fRand.nextUScalar1(), |
+ fRand.nextUScalar1(), fRand.nextUScalar1()); |
+ fCounter += fProc(mat, fRects, fIRects, N); |
+ } |
+ } |
+ |
+private: |
+ typedef Benchmark INHERITED; |
+}; |
+ |
+static int rectmath0(const SkMatrix& mat, const SkRect rr[], const SkIRect ir[], int count) { |
+ int counter = 0; |
+ for (int i = 0; i < count; ++i) { |
+ SkRect dst; |
+ mat.mapRectScaleTranslate(&dst, rr[i]); |
+ counter += dst.round().contains(ir[i]); |
+ } |
+ return counter; |
+} |
+ |
+static int rectmath1(const SkMatrix& mat, const SkRect rr[], const SkIRect ir[], int count) { |
+ int counter = 0; |
+ for (int i = 0; i < count; ++i) { |
+ SkRect dst; |
+ mat.mapRectScaleTranslate(&dst, rr[i]); |
+ counter += dst.round2i().contains(ir[i]); |
+ } |
+ return counter; |
+} |
+ |
+#if 0 |
+static bool contains(SkIRect outer, SkIRect inner) { |
+ Sk4i le(outer.fLeft, outer.fTop, inner.fRight, inner.fBottom); |
+ Sk4i ge(inner.fLeft, inner.fTop, outer.fRight, outer.fBottom); |
+ return (le <= ge).allTrue(); |
+} |
+ |
+static int rectmath3(const SkMatrix& mat, const SkRect rr[], const SkIRect ir[], int count) { |
+ int counter = 0; |
+ for (int i = 0; i < count; ++i) { |
+ counter += contains(mat.mapRectScaleTranslate(rr[i]).round2i(), ir[i]); |
+ } |
+ return counter; |
+} |
+#endif |
+ |
+DEF_BENCH(return new RectMathBench(rectmath0, "0");) |
+DEF_BENCH(return new RectMathBench(rectmath1, "1");) |