blob: b741c8dfc6caedfe1438e8b2338e9c21935cca8e [file] [log] [blame]
reed@google.com4aa1a702012-05-04 16:37:45 +00001
2/*
3 * Copyright 2011 Google Inc.
4 *
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
7 */
8#include "SkBenchmark.h"
9#include "SkBitmap.h"
10#include "SkCanvas.h"
11#include "SkDashPathEffect.h"
12#include "SkPaint.h"
13#include "SkPath.h"
14#include "SkRandom.h"
15#include "SkString.h"
16#include "SkTDArray.h"
17
18/*
19 * Cases to consider:
20 *
21 * 1. antialiasing on/off (esp. width <= 1)
22 * 2. strokewidth == 0, 1, 2
23 * 3. hline, vline, diagonal, rect, oval
24 * 4. dots [1,1] ([N,N] where N=strokeWidth?) or arbitrary (e.g. [2,1] or [1,2,3,2])
25 */
26static void path_hline(SkPath* path) {
27 path->moveTo(SkIntToScalar(10), SkIntToScalar(10));
28 path->lineTo(SkIntToScalar(600), SkIntToScalar(10));
29}
30
31class DashBench : public SkBenchmark {
32 SkTDArray<SkScalar> fIntervals;
33
34 enum {
35 N = SkBENCHLOOP(100)
36 };
37public:
38 DashBench(void* param, const SkScalar intervals[], int count) : INHERITED(param) {
39 fIntervals.append(count, intervals);
40 }
41
42 virtual void makePath(SkPath* path) {
43 path_hline(path);
44 }
45
46protected:
47 virtual const char* onGetName() SK_OVERRIDE {
48 return "dash";
49 }
50
51 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE {
52 SkPaint paint;
53 this->setupPaint(&paint);
54 paint.setStyle(SkPaint::kStroke_Style);
55// paint.setStrokeWidth(SK_Scalar1);
56 paint.setAntiAlias(false);
57
58 SkPath path;
59 this->makePath(&path);
60
61 paint.setPathEffect(new SkDashPathEffect(fIntervals.begin(),
62 fIntervals.count(), 0))->unref();
63 for (int i = 0; i < N; ++i) {
64 canvas->drawPath(path, paint);
65 }
66 }
67
68private:
69 typedef SkBenchmark INHERITED;
70};
71
72///////////////////////////////////////////////////////////////////////////////
73
74static const SkScalar gDots[] = { SK_Scalar1, SK_Scalar1 };
75
76#define PARAM(array) array, SK_ARRAY_COUNT(array)
77
78static SkBenchmark* gF0(void* p) { return new DashBench(p, PARAM(gDots)); }
79
80static BenchRegistry gR0(gF0);