epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2011 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 | */ |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 7 | #include "bench/Benchmark.h" |
| 8 | #include "include/core/SkCanvas.h" |
| 9 | #include "include/core/SkMaskFilter.h" |
| 10 | #include "include/core/SkPaint.h" |
| 11 | #include "include/core/SkShader.h" |
| 12 | #include "include/core/SkString.h" |
| 13 | #include "include/utils/SkRandom.h" |
| 14 | #include "src/core/SkBlurMask.h" |
reed@google.com | 25df888 | 2011-07-14 19:03:58 +0000 | [diff] [blame] | 15 | |
Robert Phillips | 15e60a4 | 2018-08-20 14:22:16 -0400 | [diff] [blame] | 16 | #define MINI 0.01f |
reed@google.com | 25df888 | 2011-07-14 19:03:58 +0000 | [diff] [blame] | 17 | #define SMALL SkIntToScalar(2) |
Herb Derby | 35c556f | 2017-11-16 21:43:26 +0000 | [diff] [blame] | 18 | #define REAL 0.5f |
reed@google.com | 25df888 | 2011-07-14 19:03:58 +0000 | [diff] [blame] | 19 | #define BIG SkIntToScalar(10) |
commit-bot@chromium.org | 4b413c8 | 2013-11-25 19:44:07 +0000 | [diff] [blame] | 20 | #define REALBIG 100.5f |
Herb Derby | 35c556f | 2017-11-16 21:43:26 +0000 | [diff] [blame] | 21 | // The value that produces a sigma of just over 2. |
| 22 | #define CUTOVER 2.6f |
reed@google.com | 25df888 | 2011-07-14 19:03:58 +0000 | [diff] [blame] | 23 | |
| 24 | static const char* gStyleName[] = { |
| 25 | "normal", |
| 26 | "solid", |
| 27 | "outer", |
| 28 | "inner" |
| 29 | }; |
| 30 | |
tfarina | f168b86 | 2014-06-19 12:32:29 -0700 | [diff] [blame] | 31 | class BlurBench : public Benchmark { |
reed@google.com | 25df888 | 2011-07-14 19:03:58 +0000 | [diff] [blame] | 32 | SkScalar fRadius; |
commit-bot@chromium.org | e396455 | 2014-04-28 16:25:35 +0000 | [diff] [blame] | 33 | SkBlurStyle fStyle; |
reed@google.com | 25df888 | 2011-07-14 19:03:58 +0000 | [diff] [blame] | 34 | SkString fName; |
| 35 | |
| 36 | public: |
Mike Reed | 1be1f8d | 2018-03-14 13:01:17 -0400 | [diff] [blame] | 37 | BlurBench(SkScalar rad, SkBlurStyle bs) { |
reed@google.com | 25df888 | 2011-07-14 19:03:58 +0000 | [diff] [blame] | 38 | fRadius = rad; |
| 39 | fStyle = bs; |
| 40 | const char* name = rad > 0 ? gStyleName[bs] : "none"; |
Mike Reed | 1be1f8d | 2018-03-14 13:01:17 -0400 | [diff] [blame] | 41 | const char* quality = "high_quality"; |
tomhudson@google.com | 8caac64 | 2011-11-22 15:58:06 +0000 | [diff] [blame] | 42 | if (SkScalarFraction(rad) != 0) { |
senorblanco@chromium.org | 91f489a | 2012-11-29 17:09:27 +0000 | [diff] [blame] | 43 | fName.printf("blur_%.2f_%s_%s", SkScalarToFloat(rad), name, quality); |
tomhudson@google.com | 8caac64 | 2011-11-22 15:58:06 +0000 | [diff] [blame] | 44 | } else { |
reed@google.com | e1ca705 | 2013-12-17 19:22:07 +0000 | [diff] [blame] | 45 | fName.printf("blur_%d_%s_%s", SkScalarRoundToInt(rad), name, quality); |
tomhudson@google.com | 8caac64 | 2011-11-22 15:58:06 +0000 | [diff] [blame] | 46 | } |
reed@google.com | 25df888 | 2011-07-14 19:03:58 +0000 | [diff] [blame] | 47 | } |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 48 | |
reed@google.com | 25df888 | 2011-07-14 19:03:58 +0000 | [diff] [blame] | 49 | protected: |
Robert Phillips | 15e60a4 | 2018-08-20 14:22:16 -0400 | [diff] [blame] | 50 | const char* onGetName() override { |
reed@google.com | 25df888 | 2011-07-14 19:03:58 +0000 | [diff] [blame] | 51 | return fName.c_str(); |
| 52 | } |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 53 | |
Robert Phillips | 15e60a4 | 2018-08-20 14:22:16 -0400 | [diff] [blame] | 54 | void onDraw(int loops, SkCanvas* canvas) override { |
reed@google.com | 25df888 | 2011-07-14 19:03:58 +0000 | [diff] [blame] | 55 | SkPaint paint; |
| 56 | this->setupPaint(&paint); |
| 57 | |
| 58 | paint.setAntiAlias(true); |
| 59 | |
commit-bot@chromium.org | e0e7cfe | 2013-09-09 20:09:12 +0000 | [diff] [blame] | 60 | SkRandom rand; |
commit-bot@chromium.org | 3361471 | 2013-12-03 18:17:16 +0000 | [diff] [blame] | 61 | for (int i = 0; i < loops; i++) { |
reed@google.com | 25df888 | 2011-07-14 19:03:58 +0000 | [diff] [blame] | 62 | SkRect r = SkRect::MakeWH(rand.nextUScalar1() * 400, |
| 63 | rand.nextUScalar1() * 400); |
| 64 | r.offset(fRadius, fRadius); |
| 65 | |
| 66 | if (fRadius > 0) { |
Mike Reed | 1be1f8d | 2018-03-14 13:01:17 -0400 | [diff] [blame] | 67 | paint.setMaskFilter(SkMaskFilter::MakeBlur(fStyle, |
| 68 | SkBlurMask::ConvertRadiusToSigma(fRadius))); |
reed@google.com | 25df888 | 2011-07-14 19:03:58 +0000 | [diff] [blame] | 69 | } |
| 70 | canvas->drawOval(r, paint); |
| 71 | } |
| 72 | } |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 73 | |
reed@google.com | 25df888 | 2011-07-14 19:03:58 +0000 | [diff] [blame] | 74 | private: |
John Stiles | 7571f9e | 2020-09-02 22:42:33 -0400 | [diff] [blame] | 75 | using INHERITED = Benchmark; |
reed@google.com | 25df888 | 2011-07-14 19:03:58 +0000 | [diff] [blame] | 76 | }; |
| 77 | |
joshualitt | 5acfea7 | 2014-08-11 13:55:34 -0700 | [diff] [blame] | 78 | DEF_BENCH(return new BlurBench(MINI, kNormal_SkBlurStyle);) |
| 79 | DEF_BENCH(return new BlurBench(MINI, kSolid_SkBlurStyle);) |
| 80 | DEF_BENCH(return new BlurBench(MINI, kOuter_SkBlurStyle);) |
| 81 | DEF_BENCH(return new BlurBench(MINI, kInner_SkBlurStyle);) |
| 82 | |
commit-bot@chromium.org | e396455 | 2014-04-28 16:25:35 +0000 | [diff] [blame] | 83 | DEF_BENCH(return new BlurBench(SMALL, kNormal_SkBlurStyle);) |
| 84 | DEF_BENCH(return new BlurBench(SMALL, kSolid_SkBlurStyle);) |
| 85 | DEF_BENCH(return new BlurBench(SMALL, kOuter_SkBlurStyle);) |
| 86 | DEF_BENCH(return new BlurBench(SMALL, kInner_SkBlurStyle);) |
reed@google.com | 25df888 | 2011-07-14 19:03:58 +0000 | [diff] [blame] | 87 | |
commit-bot@chromium.org | e396455 | 2014-04-28 16:25:35 +0000 | [diff] [blame] | 88 | DEF_BENCH(return new BlurBench(BIG, kNormal_SkBlurStyle);) |
| 89 | DEF_BENCH(return new BlurBench(BIG, kSolid_SkBlurStyle);) |
| 90 | DEF_BENCH(return new BlurBench(BIG, kOuter_SkBlurStyle);) |
| 91 | DEF_BENCH(return new BlurBench(BIG, kInner_SkBlurStyle);) |
reed@google.com | 25df888 | 2011-07-14 19:03:58 +0000 | [diff] [blame] | 92 | |
commit-bot@chromium.org | e396455 | 2014-04-28 16:25:35 +0000 | [diff] [blame] | 93 | DEF_BENCH(return new BlurBench(REALBIG, kNormal_SkBlurStyle);) |
| 94 | DEF_BENCH(return new BlurBench(REALBIG, kSolid_SkBlurStyle);) |
| 95 | DEF_BENCH(return new BlurBench(REALBIG, kOuter_SkBlurStyle);) |
| 96 | DEF_BENCH(return new BlurBench(REALBIG, kInner_SkBlurStyle);) |
senorblanco@chromium.org | 91f489a | 2012-11-29 17:09:27 +0000 | [diff] [blame] | 97 | |
commit-bot@chromium.org | e396455 | 2014-04-28 16:25:35 +0000 | [diff] [blame] | 98 | DEF_BENCH(return new BlurBench(REAL, kNormal_SkBlurStyle);) |
| 99 | DEF_BENCH(return new BlurBench(REAL, kSolid_SkBlurStyle);) |
| 100 | DEF_BENCH(return new BlurBench(REAL, kOuter_SkBlurStyle);) |
| 101 | DEF_BENCH(return new BlurBench(REAL, kInner_SkBlurStyle);) |
tomhudson@google.com | 8caac64 | 2011-11-22 15:58:06 +0000 | [diff] [blame] | 102 | |
commit-bot@chromium.org | e396455 | 2014-04-28 16:25:35 +0000 | [diff] [blame] | 103 | DEF_BENCH(return new BlurBench(0, kNormal_SkBlurStyle);) |