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 | */ |
reed@google.com | 25df888 | 2011-07-14 19:03:58 +0000 | [diff] [blame] | 8 | #include "SkBenchmark.h" |
robertphillips@google.com | b706117 | 2013-09-06 14:16:12 +0000 | [diff] [blame] | 9 | #include "SkBlurMask.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" |
| 15 | #include "SkBlurMaskFilter.h" |
| 16 | |
| 17 | #define SMALL SkIntToScalar(2) |
tomhudson@google.com | 8caac64 | 2011-11-22 15:58:06 +0000 | [diff] [blame] | 18 | #define REAL SkFloatToScalar(1.5f) |
reed@google.com | 25df888 | 2011-07-14 19:03:58 +0000 | [diff] [blame] | 19 | #define BIG SkIntToScalar(10) |
senorblanco@chromium.org | 91f489a | 2012-11-29 17:09:27 +0000 | [diff] [blame] | 20 | #define REALBIG SkFloatToScalar(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 | |
| 29 | class BlurBench : public SkBenchmark { |
| 30 | SkScalar fRadius; |
| 31 | SkBlurMaskFilter::BlurStyle fStyle; |
senorblanco@chromium.org | 91f489a | 2012-11-29 17:09:27 +0000 | [diff] [blame] | 32 | uint32_t fFlags; |
reed@google.com | 25df888 | 2011-07-14 19:03:58 +0000 | [diff] [blame] | 33 | SkString fName; |
| 34 | |
| 35 | public: |
mtklein@google.com | 410e6e8 | 2013-09-13 19:52:27 +0000 | [diff] [blame] | 36 | BlurBench(SkScalar rad, SkBlurMaskFilter::BlurStyle 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 { |
senorblanco@chromium.org | 91f489a | 2012-11-29 17:09:27 +0000 | [diff] [blame] | 46 | fName.printf("blur_%d_%s_%s", SkScalarRound(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 | |
reed@google.com | 25df888 | 2011-07-14 19:03:58 +0000 | [diff] [blame] | 55 | virtual void onDraw(SkCanvas* canvas) { |
| 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; |
mtklein@google.com | c289743 | 2013-09-10 19:23:38 +0000 | [diff] [blame] | 62 | for (int i = 0; i < this->getLoops(); 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) { |
skia.committer@gmail.com | b3ec29d | 2013-09-07 07:01:16 +0000 | [diff] [blame] | 68 | SkMaskFilter* mf = SkBlurMaskFilter::Create(fStyle, |
| 69 | SkBlurMask::ConvertRadiusToSigma(fRadius), |
robertphillips@google.com | b706117 | 2013-09-06 14:16:12 +0000 | [diff] [blame] | 70 | fFlags); |
reed@google.com | 25df888 | 2011-07-14 19:03:58 +0000 | [diff] [blame] | 71 | paint.setMaskFilter(mf)->unref(); |
| 72 | } |
| 73 | canvas->drawOval(r, paint); |
| 74 | } |
| 75 | } |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 76 | |
reed@google.com | 25df888 | 2011-07-14 19:03:58 +0000 | [diff] [blame] | 77 | private: |
| 78 | typedef SkBenchmark INHERITED; |
| 79 | }; |
| 80 | |
mtklein@google.com | 410e6e8 | 2013-09-13 19:52:27 +0000 | [diff] [blame] | 81 | DEF_BENCH(return new BlurBench(SMALL, SkBlurMaskFilter::kNormal_BlurStyle);) |
| 82 | DEF_BENCH(return new BlurBench(SMALL, SkBlurMaskFilter::kSolid_BlurStyle);) |
| 83 | DEF_BENCH(return new BlurBench(SMALL, SkBlurMaskFilter::kOuter_BlurStyle);) |
| 84 | DEF_BENCH(return new BlurBench(SMALL, SkBlurMaskFilter::kInner_BlurStyle);) |
reed@google.com | 25df888 | 2011-07-14 19:03:58 +0000 | [diff] [blame] | 85 | |
mtklein@google.com | 410e6e8 | 2013-09-13 19:52:27 +0000 | [diff] [blame] | 86 | DEF_BENCH(return new BlurBench(BIG, SkBlurMaskFilter::kNormal_BlurStyle);) |
| 87 | DEF_BENCH(return new BlurBench(BIG, SkBlurMaskFilter::kSolid_BlurStyle);) |
| 88 | DEF_BENCH(return new BlurBench(BIG, SkBlurMaskFilter::kOuter_BlurStyle);) |
| 89 | DEF_BENCH(return new BlurBench(BIG, SkBlurMaskFilter::kInner_BlurStyle);) |
reed@google.com | 25df888 | 2011-07-14 19:03:58 +0000 | [diff] [blame] | 90 | |
mtklein@google.com | 410e6e8 | 2013-09-13 19:52:27 +0000 | [diff] [blame] | 91 | DEF_BENCH(return new BlurBench(REALBIG, SkBlurMaskFilter::kNormal_BlurStyle);) |
| 92 | DEF_BENCH(return new BlurBench(REALBIG, SkBlurMaskFilter::kSolid_BlurStyle);) |
| 93 | DEF_BENCH(return new BlurBench(REALBIG, SkBlurMaskFilter::kOuter_BlurStyle);) |
| 94 | DEF_BENCH(return new BlurBench(REALBIG, SkBlurMaskFilter::kInner_BlurStyle);) |
senorblanco@chromium.org | 91f489a | 2012-11-29 17:09:27 +0000 | [diff] [blame] | 95 | |
mtklein@google.com | 410e6e8 | 2013-09-13 19:52:27 +0000 | [diff] [blame] | 96 | DEF_BENCH(return new BlurBench(REAL, SkBlurMaskFilter::kNormal_BlurStyle);) |
| 97 | DEF_BENCH(return new BlurBench(REAL, SkBlurMaskFilter::kSolid_BlurStyle);) |
| 98 | DEF_BENCH(return new BlurBench(REAL, SkBlurMaskFilter::kOuter_BlurStyle);) |
| 99 | DEF_BENCH(return new BlurBench(REAL, SkBlurMaskFilter::kInner_BlurStyle);) |
tomhudson@google.com | 8caac64 | 2011-11-22 15:58:06 +0000 | [diff] [blame] | 100 | |
mtklein@google.com | 410e6e8 | 2013-09-13 19:52:27 +0000 | [diff] [blame] | 101 | DEF_BENCH(return new BlurBench(SMALL, SkBlurMaskFilter::kNormal_BlurStyle, SkBlurMaskFilter::kHighQuality_BlurFlag);) |
senorblanco@chromium.org | 91f489a | 2012-11-29 17:09:27 +0000 | [diff] [blame] | 102 | |
mtklein@google.com | 410e6e8 | 2013-09-13 19:52:27 +0000 | [diff] [blame] | 103 | DEF_BENCH(return new BlurBench(BIG, SkBlurMaskFilter::kNormal_BlurStyle, SkBlurMaskFilter::kHighQuality_BlurFlag);) |
senorblanco@chromium.org | 91f489a | 2012-11-29 17:09:27 +0000 | [diff] [blame] | 104 | |
mtklein@google.com | 410e6e8 | 2013-09-13 19:52:27 +0000 | [diff] [blame] | 105 | DEF_BENCH(return new BlurBench(REALBIG, SkBlurMaskFilter::kNormal_BlurStyle, SkBlurMaskFilter::kHighQuality_BlurFlag);) |
senorblanco@chromium.org | 91f489a | 2012-11-29 17:09:27 +0000 | [diff] [blame] | 106 | |
mtklein@google.com | 410e6e8 | 2013-09-13 19:52:27 +0000 | [diff] [blame] | 107 | DEF_BENCH(return new BlurBench(REAL, SkBlurMaskFilter::kNormal_BlurStyle, SkBlurMaskFilter::kHighQuality_BlurFlag);) |
senorblanco@chromium.org | 91f489a | 2012-11-29 17:09:27 +0000 | [diff] [blame] | 108 | |
mtklein@google.com | 410e6e8 | 2013-09-13 19:52:27 +0000 | [diff] [blame] | 109 | DEF_BENCH(return new BlurBench(0, SkBlurMaskFilter::kNormal_BlurStyle);) |