reed@google.com | 1ca015b | 2012-10-25 17:32:10 +0000 | [diff] [blame] | 1 | /* |
| 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 | |
tfarina | f168b86 | 2014-06-19 12:32:29 -0700 | [diff] [blame] | 8 | #include "Benchmark.h" |
reed@google.com | 1ca015b | 2012-10-25 17:32:10 +0000 | [diff] [blame] | 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 | |
tfarina | f168b86 | 2014-06-19 12:32:29 -0700 | [diff] [blame] | 19 | class LineBench : public Benchmark { |
reed@google.com | 1ca015b | 2012-10-25 17:32:10 +0000 | [diff] [blame] | 20 | SkScalar fStrokeWidth; |
| 21 | bool fDoAA; |
| 22 | SkString fName; |
| 23 | enum { |
| 24 | PTS = 500, |
reed@google.com | 1ca015b | 2012-10-25 17:32:10 +0000 | [diff] [blame] | 25 | }; |
| 26 | SkPoint fPts[PTS]; |
| 27 | |
| 28 | public: |
mtklein@google.com | 410e6e8 | 2013-09-13 19:52:27 +0000 | [diff] [blame] | 29 | LineBench(SkScalar width, bool doAA) { |
reed@google.com | 1ca015b | 2012-10-25 17:32:10 +0000 | [diff] [blame] | 30 | fStrokeWidth = width; |
| 31 | fDoAA = doAA; |
| 32 | fName.printf("lines_%g_%s", width, doAA ? "AA" : "BW"); |
| 33 | |
commit-bot@chromium.org | e0e7cfe | 2013-09-09 20:09:12 +0000 | [diff] [blame] | 34 | SkRandom rand; |
reed@google.com | 1ca015b | 2012-10-25 17:32:10 +0000 | [diff] [blame] | 35 | for (int i = 0; i < PTS; ++i) { |
| 36 | fPts[i].set(rand.nextUScalar1() * 640, rand.nextUScalar1() * 480); |
| 37 | } |
| 38 | } |
| 39 | |
| 40 | protected: |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 41 | const char* onGetName() override { |
reed@google.com | 1ca015b | 2012-10-25 17:32:10 +0000 | [diff] [blame] | 42 | return fName.c_str(); |
| 43 | } |
| 44 | |
mtklein | a1ebeb2 | 2015-10-01 09:43:39 -0700 | [diff] [blame] | 45 | void onDraw(int loops, SkCanvas* canvas) override { |
reed@google.com | 1ca015b | 2012-10-25 17:32:10 +0000 | [diff] [blame] | 46 | 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.org | 3361471 | 2013-12-03 18:17:16 +0000 | [diff] [blame] | 53 | for (int i = 0; i < loops; i++) { |
reed@google.com | 1ca015b | 2012-10-25 17:32:10 +0000 | [diff] [blame] | 54 | canvas->drawPoints(SkCanvas::kLines_PointMode, PTS, fPts, paint); |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | private: |
tfarina | f168b86 | 2014-06-19 12:32:29 -0700 | [diff] [blame] | 59 | typedef Benchmark INHERITED; |
reed@google.com | 1ca015b | 2012-10-25 17:32:10 +0000 | [diff] [blame] | 60 | }; |
| 61 | |
mtklein@google.com | 410e6e8 | 2013-09-13 19:52:27 +0000 | [diff] [blame] | 62 | DEF_BENCH(return new LineBench(0, false);) |
| 63 | DEF_BENCH(return new LineBench(SK_Scalar1, false);) |
| 64 | DEF_BENCH(return new LineBench(0, true);) |
| 65 | DEF_BENCH(return new LineBench(SK_Scalar1/2, true);) |
| 66 | DEF_BENCH(return new LineBench(SK_Scalar1, true);) |