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

Unified Diff: bench/StraightLineBench.cpp

Issue 1936153002: Modify LineBench for drawing straight line (Closed) Base URL: https://chromium.googlesource.com/skia.git@master
Patch Set: Created 4 years, 8 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/StraightLineBench.cpp
diff --git a/bench/StraightLineBench.cpp b/bench/StraightLineBench.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..183f0548f160f41ca917bb645d060c754ed77711
--- /dev/null
+++ b/bench/StraightLineBench.cpp
@@ -0,0 +1,73 @@
+/*
+ * Copyright 2016 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "Benchmark.h"
+#include "SkBitmap.h"
+#include "SkCanvas.h"
+#include "SkColorPriv.h"
+#include "SkPaint.h"
+#include "SkRandom.h"
+#include "SkShader.h"
+#include "SkString.h"
+#include "SkTArray.h"
+
+
+class StraightLineBench : public Benchmark {
+ SkScalar fStrokeWidth;
+ bool fDoAA;
+ SkString fName;
+ enum {
+ LINES = 500;
+ };
+ SkPoint fStartPts[LINES];
+ SkPoint fEndPts[LINES];
+
+public:
+ StraightLineBench(SkScalar width, bool doAA) {
+ fStrokeWidth = width;
+ fDoAA = doAA;
robertphillips 2016/05/02 15:33:40 I think you want this to be: straightline_%g_%s
xidachen 2016/05/02 15:54:10 Thank you, changed to straightline, and compilatio
+ fName.printf("lines_%g_%s", width, doAA ? "AA" : "BW");
+
+ SkRandom rand;
+ for (int i = 0; i < LINES; ++i) {
+ fStartPts[i].set(rand.nextUScalar1() * 640, rand.nextUScalar1() * 480);
+ // Half of lines start straight horizontally and half of them vertically
+ if (i < LINES / 2) {
+ fEndPts[i].set(fStartPts[i].x(), rand.nextUScalar1() * 480);
+ } else {
+ fEndPts[i].set(rand.nextUScalar1() * 640, fStartPts[i].y());
+ }
+ }
+ }
+
+protected:
+ const char* onGetName() override {
+ return fName.c_str();
+ }
+
+ void onDraw(int loops, SkCanvas* canvas) override {
+ SkPaint paint;
+ this->setupPaint(&paint);
+
+ paint.setStyle(SkPaint::kStroke_Style);
+ paint.setAntiAlias(fDoAA);
+ paint.setStrokeWidth(fStrokeWidth);
+
+ for (int i = 0; i < loops; i++) {
+ canvas->drawLine(fStartPts[i].x(), fStartPts[i].y(), fEndPts[i].x(), fEndPts[i].y(), paint);
+ }
+ }
+
+private:
+ typedef Benchmark INHERITED;
+};
+
+DEF_BENCH(return new StraightLineBench(0, false);)
+DEF_BENCH(return new StraightLineBench(SK_Scalar1, false);)
+DEF_BENCH(return new StraightLineBench(0, true);)
+DEF_BENCH(return new StraightLineBench(SK_Scalar1/2, true);)
+DEF_BENCH(return new StraightLineBench(SK_Scalar1, true);)
« 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