Add bench to measure drawing a dashed grid
authoregdaniel <egdaniel@google.com>
Wed, 4 Jun 2014 15:15:31 +0000 (08:15 -0700)
committerCommit bot <commit-bot@chromium.org>
Wed, 4 Jun 2014 15:15:31 +0000 (08:15 -0700)
BUG=skia:
R=bsalomon@google.com

Author: egdaniel@google.com

Review URL: https://codereview.chromium.org/310083005

bench/DashBench.cpp

index 35b7242..bbe9512 100644 (file)
@@ -373,6 +373,72 @@ private:
     typedef SkBenchmark INHERITED;
 };
 
+// Want to test how we draw a dashed grid (like what is used in spreadsheets) of many
+// small dashed lines switching back and forth between horizontal and vertical
+class DashGridBench : public SkBenchmark {
+    SkString fName;
+    int      fStrokeWidth;
+    bool     fDoAA;
+
+    SkAutoTUnref<SkPathEffect> fPathEffect;
+
+public:
+    DashGridBench(int dashLength, int strokeWidth, bool doAA) {
+        fName.printf("dashgrid_%d_%d%s", dashLength, strokeWidth, doAA ? "_aa" : "_bw");
+        fStrokeWidth = strokeWidth;
+        fDoAA = doAA;
+
+        SkScalar vals[] = { SkIntToScalar(dashLength), SkIntToScalar(dashLength) };
+        fPathEffect.reset(SkDashPathEffect::Create(vals, 2, SK_Scalar1));
+    }
+
+protected:
+    virtual const char* onGetName() SK_OVERRIDE {
+        return fName.c_str();
+    }
+
+    virtual void onDraw(const int loops, SkCanvas* canvas) SK_OVERRIDE {
+        SkPaint p;
+        this->setupPaint(&p);
+        p.setColor(SK_ColorBLACK);
+        p.setStyle(SkPaint::kStroke_Style);
+        p.setStrokeWidth(SkIntToScalar(fStrokeWidth));
+        p.setPathEffect(fPathEffect);
+        p.setAntiAlias(fDoAA);
+
+        SkPoint pts[4] = {
+            { SkIntToScalar(0), 20.5f },
+            { SkIntToScalar(20), 20.5f },
+            { 20.5f, SkIntToScalar(0) },
+            { 20.5f, SkIntToScalar(20) }
+        };
+
+        for (int i = 0; i < loops; ++i) {
+            for (int j = 0; j < 10; ++j) {
+                for (int k = 0; k < 10; ++k) {
+                    // Horizontal line
+                    SkPoint horPts[2];
+                    horPts[0].fX = pts[0].fX + k * 22.f;
+                    horPts[0].fY = pts[0].fY + j * 22.f;
+                    horPts[1].fX = pts[1].fX + k * 22.f;
+                    horPts[1].fY = pts[1].fY + j * 22.f;
+                    canvas->drawPoints(SkCanvas::kLines_PointMode, 2, horPts, p);
+
+                    // Vertical line
+                    SkPoint vertPts[2];
+                    vertPts[0].fX = pts[2].fX + k * 22.f;
+                    vertPts[0].fY = pts[2].fY + j * 22.f;
+                    vertPts[1].fX = pts[3].fX + k * 22.f;
+                    vertPts[1].fY = pts[3].fY + j * 22.f;
+                    canvas->drawPoints(SkCanvas::kLines_PointMode, 2, vertPts, p);
+                }
+            }
+        }
+    }
+
+private:
+    typedef SkBenchmark INHERITED;
+};
 
 ///////////////////////////////////////////////////////////////////////////////
 
@@ -415,4 +481,9 @@ DEF_BENCH( return new GiantDashBench(GiantDashBench::kDiag_LineType, 0); )
 DEF_BENCH( return new GiantDashBench(GiantDashBench::kHori_LineType, 2); )
 DEF_BENCH( return new GiantDashBench(GiantDashBench::kVert_LineType, 2); )
 DEF_BENCH( return new GiantDashBench(GiantDashBench::kDiag_LineType, 2); )
+
+DEF_BENCH( return new DashGridBench(1, 1, true); )
+DEF_BENCH( return new DashGridBench(1, 1, false); )
+DEF_BENCH( return new DashGridBench(3, 1, true); )
+DEF_BENCH( return new DashGridBench(3, 1, false); )
 #endif