qiankun.miao | e18a530 | 2014-12-09 17:47:05 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2014 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 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 8 | #include "bench/Benchmark.h" |
| 9 | #include "include/core/SkCanvas.h" |
| 10 | #include "include/core/SkMaskFilter.h" |
| 11 | #include "include/core/SkPaint.h" |
| 12 | #include "include/core/SkPath.h" |
| 13 | #include "include/core/SkRect.h" |
| 14 | #include "include/core/SkString.h" |
qiankun.miao | e18a530 | 2014-12-09 17:47:05 -0800 | [diff] [blame] | 15 | |
| 16 | class BlurRectsBench : public Benchmark { |
| 17 | public: |
| 18 | BlurRectsBench(SkRect outer, SkRect inner, SkScalar radius) { |
| 19 | fRadius = radius; |
| 20 | fOuter = outer; |
| 21 | fInner = inner; |
| 22 | } |
| 23 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 24 | const char* onGetName() override { |
qiankun.miao | e18a530 | 2014-12-09 17:47:05 -0800 | [diff] [blame] | 25 | return fName.c_str(); |
| 26 | } |
| 27 | |
| 28 | void setName(const SkString& name) { |
| 29 | fName = name; |
| 30 | } |
| 31 | |
mtklein | a1ebeb2 | 2015-10-01 09:43:39 -0700 | [diff] [blame] | 32 | void onDraw(int loops, SkCanvas* canvas) override { |
qiankun.miao | e18a530 | 2014-12-09 17:47:05 -0800 | [diff] [blame] | 33 | SkPaint paint; |
Mike Reed | 1be1f8d | 2018-03-14 13:01:17 -0400 | [diff] [blame] | 34 | paint.setMaskFilter(SkMaskFilter::MakeBlur(kNormal_SkBlurStyle, fRadius)); |
qiankun.miao | e18a530 | 2014-12-09 17:47:05 -0800 | [diff] [blame] | 35 | |
| 36 | SkPath path; |
Mike Reed | 30bc527 | 2019-11-22 18:34:02 +0000 | [diff] [blame] | 37 | path.addRect(fOuter, SkPathDirection::kCW); |
| 38 | path.addRect(fInner, SkPathDirection::kCW); |
qiankun.miao | e18a530 | 2014-12-09 17:47:05 -0800 | [diff] [blame] | 39 | |
| 40 | for (int i = 0; i < loops; i++) { |
| 41 | canvas->drawPath(path, paint); |
| 42 | } |
| 43 | } |
| 44 | |
| 45 | private: |
| 46 | SkString fName; |
| 47 | SkRect fOuter; |
| 48 | SkRect fInner; |
| 49 | SkScalar fRadius; |
| 50 | |
John Stiles | 7571f9e | 2020-09-02 22:42:33 -0400 | [diff] [blame] | 51 | using INHERITED = Benchmark; |
qiankun.miao | e18a530 | 2014-12-09 17:47:05 -0800 | [diff] [blame] | 52 | }; |
| 53 | |
| 54 | class BlurRectsNinePatchBench: public BlurRectsBench { |
| 55 | public: |
| 56 | BlurRectsNinePatchBench(SkRect outer, SkRect inner, SkScalar radius) |
| 57 | : INHERITED(outer, inner, radius) { |
| 58 | this->setName(SkString("blurrectsninepatch")); |
| 59 | } |
| 60 | private: |
John Stiles | 7571f9e | 2020-09-02 22:42:33 -0400 | [diff] [blame] | 61 | using INHERITED = BlurRectsBench; |
qiankun.miao | e18a530 | 2014-12-09 17:47:05 -0800 | [diff] [blame] | 62 | }; |
| 63 | |
| 64 | class BlurRectsNonNinePatchBench: public BlurRectsBench { |
| 65 | public: |
| 66 | BlurRectsNonNinePatchBench(SkRect outer, SkRect inner, SkScalar radius) |
| 67 | : INHERITED(outer, inner, radius) { |
| 68 | SkString name; |
| 69 | this->setName(SkString("blurrectsnonninepatch")); |
| 70 | } |
| 71 | private: |
John Stiles | 7571f9e | 2020-09-02 22:42:33 -0400 | [diff] [blame] | 72 | using INHERITED = BlurRectsBench; |
qiankun.miao | e18a530 | 2014-12-09 17:47:05 -0800 | [diff] [blame] | 73 | }; |
| 74 | |
| 75 | DEF_BENCH(return new BlurRectsNinePatchBench(SkRect::MakeXYWH(10, 10, 100, 100), |
| 76 | SkRect::MakeXYWH(20, 20, 60, 60), |
| 77 | 2.3f);) |
| 78 | DEF_BENCH(return new BlurRectsNonNinePatchBench(SkRect::MakeXYWH(10, 10, 100, 100), |
| 79 | SkRect::MakeXYWH(50, 50, 10, 10), |
| 80 | 4.3f);) |