Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(7)

Unified Diff: bench/DashBench.cpp

Issue 310083005: Add bench to measure drawing a dashed grid (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Decrease grid size to reduce run time Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: bench/DashBench.cpp
diff --git a/bench/DashBench.cpp b/bench/DashBench.cpp
index 35b72422aaaad617dc5c637c2e7d642231d2f315..bbe95122452afd534c6f4cbb301645a75b398d6c 100644
--- a/bench/DashBench.cpp
+++ b/bench/DashBench.cpp
@@ -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
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698