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 | */ |
tfarina | f168b86 | 2014-06-19 12:32:29 -0700 | [diff] [blame] | 7 | #include "Benchmark.h" |
robertphillips@google.com | b706117 | 2013-09-06 14:16:12 +0000 | [diff] [blame] | 8 | #include "SkBlurMask.h" |
tfarina | f168b86 | 2014-06-19 12:32:29 -0700 | [diff] [blame] | 9 | #include "SkBlurMaskFilter.h" |
reed@google.com | 25df888 | 2011-07-14 19:03:58 +0000 | [diff] [blame] | 10 | #include "SkCanvas.h" |
| 11 | #include "SkPaint.h" |
| 12 | #include "SkRandom.h" |
| 13 | #include "SkShader.h" |
| 14 | #include "SkString.h" |
reed@google.com | 25df888 | 2011-07-14 19:03:58 +0000 | [diff] [blame] | 15 | |
joshualitt | 5acfea7 | 2014-08-11 13:55:34 -0700 | [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) |
commit-bot@chromium.org | 4b413c8 | 2013-11-25 19:44:07 +0000 | [diff] [blame] | 18 | #define REAL 1.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 |
reed@google.com | 25df888 | 2011-07-14 19:03:58 +0000 | [diff] [blame] | 21 | |
| 22 | static const char* gStyleName[] = { |
| 23 | "normal", |
| 24 | "solid", |
| 25 | "outer", |
| 26 | "inner" |
| 27 | }; |
| 28 | |
tfarina | f168b86 | 2014-06-19 12:32:29 -0700 | [diff] [blame] | 29 | class BlurBench : public Benchmark { |
reed@google.com | 25df888 | 2011-07-14 19:03:58 +0000 | [diff] [blame] | 30 | SkScalar fRadius; |
commit-bot@chromium.org | e396455 | 2014-04-28 16:25:35 +0000 | [diff] [blame] | 31 | SkBlurStyle fStyle; |
| 32 | uint32_t fFlags; |
reed@google.com | 25df888 | 2011-07-14 19:03:58 +0000 | [diff] [blame] | 33 | SkString fName; |
| 34 | |
| 35 | public: |
commit-bot@chromium.org | e396455 | 2014-04-28 16:25:35 +0000 | [diff] [blame] | 36 | BlurBench(SkScalar rad, SkBlurStyle bs, uint32_t flags = 0) { |
reed@google.com | 25df888 | 2011-07-14 19:03:58 +0000 | [diff] [blame] | 37 | fRadius = rad; |
| 38 | fStyle = bs; |
senorblanco@chromium.org | 91f489a | 2012-11-29 17:09:27 +0000 | [diff] [blame] | 39 | fFlags = flags; |
reed@google.com | 25df888 | 2011-07-14 19:03:58 +0000 | [diff] [blame] | 40 | const char* name = rad > 0 ? gStyleName[bs] : "none"; |
skia.committer@gmail.com | b3ec29d | 2013-09-07 07:01:16 +0000 | [diff] [blame] | 41 | const char* quality = flags & SkBlurMaskFilter::kHighQuality_BlurFlag ? "high_quality" |
robertphillips@google.com | b706117 | 2013-09-06 14:16:12 +0000 | [diff] [blame] | 42 | : "low_quality"; |
tomhudson@google.com | 8caac64 | 2011-11-22 15:58:06 +0000 | [diff] [blame] | 43 | if (SkScalarFraction(rad) != 0) { |
senorblanco@chromium.org | 91f489a | 2012-11-29 17:09:27 +0000 | [diff] [blame] | 44 | fName.printf("blur_%.2f_%s_%s", SkScalarToFloat(rad), name, quality); |
tomhudson@google.com | 8caac64 | 2011-11-22 15:58:06 +0000 | [diff] [blame] | 45 | } else { |
reed@google.com | e1ca705 | 2013-12-17 19:22:07 +0000 | [diff] [blame] | 46 | fName.printf("blur_%d_%s_%s", SkScalarRoundToInt(rad), name, quality); |
tomhudson@google.com | 8caac64 | 2011-11-22 15:58:06 +0000 | [diff] [blame] | 47 | } |
reed@google.com | 25df888 | 2011-07-14 19:03:58 +0000 | [diff] [blame] | 48 | } |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 49 | |
reed@google.com | 25df888 | 2011-07-14 19:03:58 +0000 | [diff] [blame] | 50 | protected: |
| 51 | virtual const char* onGetName() { |
| 52 | return fName.c_str(); |
| 53 | } |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 54 | |
mtklein | a1ebeb2 | 2015-10-01 09:43:39 -0700 | [diff] [blame] | 55 | virtual void onDraw(int loops, SkCanvas* canvas) { |
reed@google.com | 25df888 | 2011-07-14 19:03:58 +0000 | [diff] [blame] | 56 | SkPaint paint; |
| 57 | this->setupPaint(&paint); |
| 58 | |
| 59 | paint.setAntiAlias(true); |
| 60 | |
commit-bot@chromium.org | e0e7cfe | 2013-09-09 20:09:12 +0000 | [diff] [blame] | 61 | SkRandom rand; |
commit-bot@chromium.org | 3361471 | 2013-12-03 18:17:16 +0000 | [diff] [blame] | 62 | for (int i = 0; i < loops; i++) { |
reed@google.com | 25df888 | 2011-07-14 19:03:58 +0000 | [diff] [blame] | 63 | SkRect r = SkRect::MakeWH(rand.nextUScalar1() * 400, |
| 64 | rand.nextUScalar1() * 400); |
| 65 | r.offset(fRadius, fRadius); |
| 66 | |
| 67 | if (fRadius > 0) { |
reed | efdfd51 | 2016-04-04 10:02:58 -0700 | [diff] [blame] | 68 | paint.setMaskFilter(SkBlurMaskFilter::Make(fStyle, |
| 69 | SkBlurMask::ConvertRadiusToSigma(fRadius), |
| 70 | fFlags)); |
reed@google.com | 25df888 | 2011-07-14 19:03:58 +0000 | [diff] [blame] | 71 | } |
| 72 | canvas->drawOval(r, paint); |
| 73 | } |
| 74 | } |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 75 | |
reed@google.com | 25df888 | 2011-07-14 19:03:58 +0000 | [diff] [blame] | 76 | private: |
tfarina | f168b86 | 2014-06-19 12:32:29 -0700 | [diff] [blame] | 77 | typedef Benchmark INHERITED; |
reed@google.com | 25df888 | 2011-07-14 19:03:58 +0000 | [diff] [blame] | 78 | }; |
| 79 | |
joshualitt | 5acfea7 | 2014-08-11 13:55:34 -0700 | [diff] [blame] | 80 | DEF_BENCH(return new BlurBench(MINI, kNormal_SkBlurStyle);) |
| 81 | DEF_BENCH(return new BlurBench(MINI, kSolid_SkBlurStyle);) |
| 82 | DEF_BENCH(return new BlurBench(MINI, kOuter_SkBlurStyle);) |
| 83 | DEF_BENCH(return new BlurBench(MINI, kInner_SkBlurStyle);) |
| 84 | |
commit-bot@chromium.org | e396455 | 2014-04-28 16:25:35 +0000 | [diff] [blame] | 85 | DEF_BENCH(return new BlurBench(SMALL, kNormal_SkBlurStyle);) |
| 86 | DEF_BENCH(return new BlurBench(SMALL, kSolid_SkBlurStyle);) |
| 87 | DEF_BENCH(return new BlurBench(SMALL, kOuter_SkBlurStyle);) |
| 88 | DEF_BENCH(return new BlurBench(SMALL, kInner_SkBlurStyle);) |
reed@google.com | 25df888 | 2011-07-14 19:03:58 +0000 | [diff] [blame] | 89 | |
commit-bot@chromium.org | e396455 | 2014-04-28 16:25:35 +0000 | [diff] [blame] | 90 | DEF_BENCH(return new BlurBench(BIG, kNormal_SkBlurStyle);) |
| 91 | DEF_BENCH(return new BlurBench(BIG, kSolid_SkBlurStyle);) |
| 92 | DEF_BENCH(return new BlurBench(BIG, kOuter_SkBlurStyle);) |
| 93 | DEF_BENCH(return new BlurBench(BIG, kInner_SkBlurStyle);) |
reed@google.com | 25df888 | 2011-07-14 19:03:58 +0000 | [diff] [blame] | 94 | |
commit-bot@chromium.org | e396455 | 2014-04-28 16:25:35 +0000 | [diff] [blame] | 95 | DEF_BENCH(return new BlurBench(REALBIG, kNormal_SkBlurStyle);) |
| 96 | DEF_BENCH(return new BlurBench(REALBIG, kSolid_SkBlurStyle);) |
| 97 | DEF_BENCH(return new BlurBench(REALBIG, kOuter_SkBlurStyle);) |
| 98 | DEF_BENCH(return new BlurBench(REALBIG, kInner_SkBlurStyle);) |
senorblanco@chromium.org | 91f489a | 2012-11-29 17:09:27 +0000 | [diff] [blame] | 99 | |
commit-bot@chromium.org | e396455 | 2014-04-28 16:25:35 +0000 | [diff] [blame] | 100 | DEF_BENCH(return new BlurBench(REAL, kNormal_SkBlurStyle);) |
| 101 | DEF_BENCH(return new BlurBench(REAL, kSolid_SkBlurStyle);) |
| 102 | DEF_BENCH(return new BlurBench(REAL, kOuter_SkBlurStyle);) |
| 103 | DEF_BENCH(return new BlurBench(REAL, kInner_SkBlurStyle);) |
tomhudson@google.com | 8caac64 | 2011-11-22 15:58:06 +0000 | [diff] [blame] | 104 | |
joshualitt | 5acfea7 | 2014-08-11 13:55:34 -0700 | [diff] [blame] | 105 | DEF_BENCH(return new BlurBench(MINI, kNormal_SkBlurStyle, SkBlurMaskFilter::kHighQuality_BlurFlag);) |
| 106 | |
commit-bot@chromium.org | e396455 | 2014-04-28 16:25:35 +0000 | [diff] [blame] | 107 | DEF_BENCH(return new BlurBench(SMALL, kNormal_SkBlurStyle, SkBlurMaskFilter::kHighQuality_BlurFlag);) |
senorblanco@chromium.org | 91f489a | 2012-11-29 17:09:27 +0000 | [diff] [blame] | 108 | |
commit-bot@chromium.org | e396455 | 2014-04-28 16:25:35 +0000 | [diff] [blame] | 109 | DEF_BENCH(return new BlurBench(BIG, kNormal_SkBlurStyle, SkBlurMaskFilter::kHighQuality_BlurFlag);) |
senorblanco@chromium.org | 91f489a | 2012-11-29 17:09:27 +0000 | [diff] [blame] | 110 | |
commit-bot@chromium.org | e396455 | 2014-04-28 16:25:35 +0000 | [diff] [blame] | 111 | DEF_BENCH(return new BlurBench(REALBIG, kNormal_SkBlurStyle, SkBlurMaskFilter::kHighQuality_BlurFlag);) |
senorblanco@chromium.org | 91f489a | 2012-11-29 17:09:27 +0000 | [diff] [blame] | 112 | |
commit-bot@chromium.org | e396455 | 2014-04-28 16:25:35 +0000 | [diff] [blame] | 113 | DEF_BENCH(return new BlurBench(REAL, kNormal_SkBlurStyle, SkBlurMaskFilter::kHighQuality_BlurFlag);) |
senorblanco@chromium.org | 91f489a | 2012-11-29 17:09:27 +0000 | [diff] [blame] | 114 | |
commit-bot@chromium.org | e396455 | 2014-04-28 16:25:35 +0000 | [diff] [blame] | 115 | DEF_BENCH(return new BlurBench(0, kNormal_SkBlurStyle);) |