blob: 67dc5648be9db4f83443c9011c195d1e2cbb4472 [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
tfarinaf168b862014-06-19 12:32:29 -07008#include "Benchmark.h"
reed@google.com1ca015b2012-10-25 17:32:10 +00009#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
tfarinaf168b862014-06-19 12:32:29 -070019class LineBench : public Benchmark {
reed@google.com1ca015b2012-10-25 17:32:10 +000020 SkScalar fStrokeWidth;
21 bool fDoAA;
22 SkString fName;
23 enum {
reed6c0f5d92016-05-05 14:02:36 -070024 PTS = 500,
reed@google.com1ca015b2012-10-25 17:32:10 +000025 };
reed6c0f5d92016-05-05 14:02:36 -070026 SkPoint fPts[PTS];
reed@google.com1ca015b2012-10-25 17:32:10 +000027
28public:
reed6c0f5d92016-05-05 14:02:36 -070029 LineBench(SkScalar width, bool doAA) {
reed@google.com1ca015b2012-10-25 17:32:10 +000030 fStrokeWidth = width;
31 fDoAA = doAA;
reed6c0f5d92016-05-05 14:02:36 -070032 fName.printf("lines_%g_%s", width, doAA ? "AA" : "BW");
reed@google.com1ca015b2012-10-25 17:32:10 +000033
commit-bot@chromium.orge0e7cfe2013-09-09 20:09:12 +000034 SkRandom rand;
reed6c0f5d92016-05-05 14:02:36 -070035 for (int i = 0; i < PTS; ++i) {
36 fPts[i].set(rand.nextUScalar1() * 640, rand.nextUScalar1() * 480);
reed@google.com1ca015b2012-10-25 17:32:10 +000037 }
38 }
39
40protected:
mtklein36352bf2015-03-25 18:17:31 -070041 const char* onGetName() override {
reed@google.com1ca015b2012-10-25 17:32:10 +000042 return fName.c_str();
43 }
44
mtkleina1ebeb22015-10-01 09:43:39 -070045 void onDraw(int loops, SkCanvas* canvas) override {
reed@google.com1ca015b2012-10-25 17:32:10 +000046 SkPaint paint;
47 this->setupPaint(&paint);
48
49 paint.setStyle(SkPaint::kStroke_Style);
50 paint.setAntiAlias(fDoAA);
51 paint.setStrokeWidth(fStrokeWidth);
52
commit-bot@chromium.org33614712013-12-03 18:17:16 +000053 for (int i = 0; i < loops; i++) {
reed6c0f5d92016-05-05 14:02:36 -070054 canvas->drawPoints(SkCanvas::kLines_PointMode, PTS, fPts, paint);
reed@google.com1ca015b2012-10-25 17:32:10 +000055 }
56 }
57
58private:
tfarinaf168b862014-06-19 12:32:29 -070059 typedef Benchmark INHERITED;
reed@google.com1ca015b2012-10-25 17:32:10 +000060};
61
reed6c0f5d92016-05-05 14:02:36 -070062DEF_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);)