aboutsummaryrefslogtreecommitdiffhomepage
path: root/bench/DashBench.cpp
diff options
context:
space:
mode:
authorGravatar reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2012-05-04 16:37:45 +0000
committerGravatar reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2012-05-04 16:37:45 +0000
commit4aa1a70ab74e841def84367d771ac2b2202f41d2 (patch)
treef33782382a99d952d1e64f544cca0528af1a3c12 /bench/DashBench.cpp
parent28b4bce1b13bf2e2b2e27d293a319133c17831cf (diff)
add initial bench for dashing (more work to do)
git-svn-id: http://skia.googlecode.com/svn/trunk@3841 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'bench/DashBench.cpp')
-rw-r--r--bench/DashBench.cpp80
1 files changed, 80 insertions, 0 deletions
diff --git a/bench/DashBench.cpp b/bench/DashBench.cpp
new file mode 100644
index 0000000000..b741c8dfc6
--- /dev/null
+++ b/bench/DashBench.cpp
@@ -0,0 +1,80 @@
+
+/*
+ * Copyright 2011 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+#include "SkBenchmark.h"
+#include "SkBitmap.h"
+#include "SkCanvas.h"
+#include "SkDashPathEffect.h"
+#include "SkPaint.h"
+#include "SkPath.h"
+#include "SkRandom.h"
+#include "SkString.h"
+#include "SkTDArray.h"
+
+/*
+ * Cases to consider:
+ *
+ * 1. antialiasing on/off (esp. width <= 1)
+ * 2. strokewidth == 0, 1, 2
+ * 3. hline, vline, diagonal, rect, oval
+ * 4. dots [1,1] ([N,N] where N=strokeWidth?) or arbitrary (e.g. [2,1] or [1,2,3,2])
+ */
+static void path_hline(SkPath* path) {
+ path->moveTo(SkIntToScalar(10), SkIntToScalar(10));
+ path->lineTo(SkIntToScalar(600), SkIntToScalar(10));
+}
+
+class DashBench : public SkBenchmark {
+ SkTDArray<SkScalar> fIntervals;
+
+ enum {
+ N = SkBENCHLOOP(100)
+ };
+public:
+ DashBench(void* param, const SkScalar intervals[], int count) : INHERITED(param) {
+ fIntervals.append(count, intervals);
+ }
+
+ virtual void makePath(SkPath* path) {
+ path_hline(path);
+ }
+
+protected:
+ virtual const char* onGetName() SK_OVERRIDE {
+ return "dash";
+ }
+
+ virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE {
+ SkPaint paint;
+ this->setupPaint(&paint);
+ paint.setStyle(SkPaint::kStroke_Style);
+// paint.setStrokeWidth(SK_Scalar1);
+ paint.setAntiAlias(false);
+
+ SkPath path;
+ this->makePath(&path);
+
+ paint.setPathEffect(new SkDashPathEffect(fIntervals.begin(),
+ fIntervals.count(), 0))->unref();
+ for (int i = 0; i < N; ++i) {
+ canvas->drawPath(path, paint);
+ }
+ }
+
+private:
+ typedef SkBenchmark INHERITED;
+};
+
+///////////////////////////////////////////////////////////////////////////////
+
+static const SkScalar gDots[] = { SK_Scalar1, SK_Scalar1 };
+
+#define PARAM(array) array, SK_ARRAY_COUNT(array)
+
+static SkBenchmark* gF0(void* p) { return new DashBench(p, PARAM(gDots)); }
+
+static BenchRegistry gR0(gF0);