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