reed | 37a4736 | 2015-02-06 13:04:16 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015 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 "Benchmark.h" |
| 9 | #include "SkCanvas.h" |
| 10 | #include "SkPath.h" |
joshualitt | 98d2e2f | 2015-10-05 07:23:30 -0700 | [diff] [blame] | 11 | #include "sk_tool_utils.h" |
reed | 37a4736 | 2015-02-06 13:04:16 -0800 | [diff] [blame] | 12 | |
| 13 | enum Align { |
| 14 | kLeft_Align, |
| 15 | kMiddle_Align, |
| 16 | kRight_Align |
| 17 | }; |
| 18 | |
| 19 | const char* gAlignName[] = { "left", "middle", "right" }; |
| 20 | |
| 21 | // Inspired by crbug.com/455429 |
| 22 | class BigPathBench : public Benchmark { |
| 23 | SkPath fPath; |
| 24 | SkString fName; |
| 25 | Align fAlign; |
reed | 70a8ca8 | 2015-02-09 08:05:52 -0800 | [diff] [blame] | 26 | bool fRound; |
reed | 37a4736 | 2015-02-06 13:04:16 -0800 | [diff] [blame] | 27 | |
| 28 | public: |
reed | 70a8ca8 | 2015-02-09 08:05:52 -0800 | [diff] [blame] | 29 | BigPathBench(Align align, bool round) : fAlign(align), fRound(round) { |
reed | 37a4736 | 2015-02-06 13:04:16 -0800 | [diff] [blame] | 30 | fName.printf("bigpath_%s", gAlignName[fAlign]); |
reed | 70a8ca8 | 2015-02-09 08:05:52 -0800 | [diff] [blame] | 31 | if (round) { |
| 32 | fName.append("_round"); |
| 33 | } |
reed | 37a4736 | 2015-02-06 13:04:16 -0800 | [diff] [blame] | 34 | } |
| 35 | |
| 36 | protected: |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 37 | const char* onGetName() override { |
reed | 37a4736 | 2015-02-06 13:04:16 -0800 | [diff] [blame] | 38 | return fName.c_str(); |
| 39 | } |
| 40 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 41 | SkIPoint onGetSize() override { |
reed | 37a4736 | 2015-02-06 13:04:16 -0800 | [diff] [blame] | 42 | return SkIPoint::Make(640, 100); |
| 43 | } |
| 44 | |
joshualitt | 8a6697a | 2015-09-30 12:11:07 -0700 | [diff] [blame] | 45 | void onDelayedSetup() override { |
joshualitt | 98d2e2f | 2015-10-05 07:23:30 -0700 | [diff] [blame] | 46 | sk_tool_utils::make_big_path(fPath); |
reed | 37a4736 | 2015-02-06 13:04:16 -0800 | [diff] [blame] | 47 | } |
| 48 | |
mtklein | a1ebeb2 | 2015-10-01 09:43:39 -0700 | [diff] [blame] | 49 | void onDraw(int loops, SkCanvas* canvas) override { |
reed | 37a4736 | 2015-02-06 13:04:16 -0800 | [diff] [blame] | 50 | SkPaint paint; |
| 51 | paint.setAntiAlias(true); |
| 52 | paint.setStyle(SkPaint::kStroke_Style); |
| 53 | paint.setStrokeWidth(2); |
reed | 70a8ca8 | 2015-02-09 08:05:52 -0800 | [diff] [blame] | 54 | if (fRound) { |
| 55 | paint.setStrokeJoin(SkPaint::kRound_Join); |
| 56 | } |
reed | 37a4736 | 2015-02-06 13:04:16 -0800 | [diff] [blame] | 57 | this->setupPaint(&paint); |
| 58 | |
| 59 | const SkRect r = fPath.getBounds(); |
| 60 | switch (fAlign) { |
| 61 | case kLeft_Align: |
| 62 | canvas->translate(-r.left(), 0); |
| 63 | break; |
| 64 | case kMiddle_Align: |
| 65 | break; |
| 66 | case kRight_Align: |
| 67 | canvas->translate(640 - r.right(), 0); |
| 68 | break; |
| 69 | } |
| 70 | |
| 71 | for (int i = 0; i < loops; i++) { |
| 72 | canvas->drawPath(fPath, paint); |
| 73 | } |
| 74 | } |
| 75 | |
| 76 | private: |
| 77 | typedef Benchmark INHERITED; |
| 78 | }; |
| 79 | |
reed | 70a8ca8 | 2015-02-09 08:05:52 -0800 | [diff] [blame] | 80 | DEF_BENCH( return new BigPathBench(kLeft_Align, false); ) |
| 81 | DEF_BENCH( return new BigPathBench(kMiddle_Align, false); ) |
| 82 | DEF_BENCH( return new BigPathBench(kRight_Align, false); ) |
| 83 | |
| 84 | DEF_BENCH( return new BigPathBench(kLeft_Align, true); ) |
| 85 | DEF_BENCH( return new BigPathBench(kMiddle_Align, true); ) |
| 86 | DEF_BENCH( return new BigPathBench(kRight_Align, true); ) |