blob: e69a40a94c7fca73930602003550060e9eaee20b [file] [log] [blame]
reed@google.com1ca015b2012-10-25 17:32:10 +00001/*
2 * Copyright 2012 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8#include "SkBenchmark.h"
9#include "SkBitmap.h"
10#include "SkCanvas.h"
11#include "SkColorPriv.h"
12#include "SkPaint.h"
13#include "SkRandom.h"
14#include "SkShader.h"
15#include "SkString.h"
16#include "SkTArray.h"
17
18
19class LineBench : public SkBenchmark {
20 SkScalar fStrokeWidth;
21 bool fDoAA;
22 SkString fName;
23 enum {
24 PTS = 500,
reed@google.com1ca015b2012-10-25 17:32:10 +000025 };
26 SkPoint fPts[PTS];
27
28public:
mtklein@google.com410e6e82013-09-13 19:52:27 +000029 LineBench(SkScalar width, bool doAA) {
reed@google.com1ca015b2012-10-25 17:32:10 +000030 fStrokeWidth = width;
31 fDoAA = doAA;
32 fName.printf("lines_%g_%s", width, doAA ? "AA" : "BW");
33
commit-bot@chromium.orge0e7cfe2013-09-09 20:09:12 +000034 SkRandom rand;
reed@google.com1ca015b2012-10-25 17:32:10 +000035 for (int i = 0; i < PTS; ++i) {
36 fPts[i].set(rand.nextUScalar1() * 640, rand.nextUScalar1() * 480);
37 }
38 }
39
40protected:
41 virtual const char* onGetName() SK_OVERRIDE {
42 return fName.c_str();
43 }
44
45 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE {
46 SkPaint paint;
47 this->setupPaint(&paint);
48
49 paint.setStyle(SkPaint::kStroke_Style);
50 paint.setAntiAlias(fDoAA);
51 paint.setStrokeWidth(fStrokeWidth);
52
mtklein@google.comc2897432013-09-10 19:23:38 +000053 for (int i = 0; i < this->getLoops(); i++) {
reed@google.com1ca015b2012-10-25 17:32:10 +000054 canvas->drawPoints(SkCanvas::kLines_PointMode, PTS, fPts, paint);
55 }
56 }
57
58private:
59 typedef SkBenchmark INHERITED;
60};
61
mtklein@google.com410e6e82013-09-13 19:52:27 +000062DEF_BENCH(return new LineBench(0, false);)
63DEF_BENCH(return new LineBench(SK_Scalar1, false);)
64DEF_BENCH(return new LineBench(0, true);)
65DEF_BENCH(return new LineBench(SK_Scalar1/2, true);)
66DEF_BENCH(return new LineBench(SK_Scalar1, true);)