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" |
| 9 | #include "SkCanvas.h" |
| 10 | #include "SkPaint.h" |
| 11 | #include "SkRandom.h" |
| 12 | #include "SkShader.h" |
| 13 | #include "SkString.h" |
| 14 | #include "SkBlurMaskFilter.h" |
| 15 | |
| 16 | #define SMALL SkIntToScalar(2) |
tomhudson@google.com | 8caac64 | 2011-11-22 15:58:06 +0000 | [diff] [blame] | 17 | #define REAL SkFloatToScalar(1.5f) |
reed@google.com | 25df888 | 2011-07-14 19:03:58 +0000 | [diff] [blame] | 18 | #define BIG SkIntToScalar(10) |
senorblanco@chromium.org | 91f489a | 2012-11-29 17:09:27 +0000 | [diff] [blame] | 19 | #define REALBIG SkFloatToScalar(100.5f) |
reed@google.com | 25df888 | 2011-07-14 19:03:58 +0000 | [diff] [blame] | 20 | |
| 21 | static const char* gStyleName[] = { |
| 22 | "normal", |
| 23 | "solid", |
| 24 | "outer", |
| 25 | "inner" |
| 26 | }; |
| 27 | |
| 28 | class BlurBench : public SkBenchmark { |
| 29 | SkScalar fRadius; |
| 30 | SkBlurMaskFilter::BlurStyle fStyle; |
senorblanco@chromium.org | 91f489a | 2012-11-29 17:09:27 +0000 | [diff] [blame] | 31 | uint32_t fFlags; |
reed@google.com | 25df888 | 2011-07-14 19:03:58 +0000 | [diff] [blame] | 32 | SkString fName; |
| 33 | |
| 34 | public: |
senorblanco@chromium.org | 91f489a | 2012-11-29 17:09:27 +0000 | [diff] [blame] | 35 | BlurBench(void* param, SkScalar rad, SkBlurMaskFilter::BlurStyle bs, uint32_t flags = 0) : INHERITED(param) { |
reed@google.com | 25df888 | 2011-07-14 19:03:58 +0000 | [diff] [blame] | 36 | fRadius = rad; |
| 37 | fStyle = bs; |
senorblanco@chromium.org | 91f489a | 2012-11-29 17:09:27 +0000 | [diff] [blame] | 38 | fFlags = flags; |
reed@google.com | 25df888 | 2011-07-14 19:03:58 +0000 | [diff] [blame] | 39 | const char* name = rad > 0 ? gStyleName[bs] : "none"; |
senorblanco@chromium.org | 91f489a | 2012-11-29 17:09:27 +0000 | [diff] [blame] | 40 | const char* quality = flags & SkBlurMaskFilter::kHighQuality_BlurFlag ? "high_quality" : "low_quality"; |
tomhudson@google.com | 8caac64 | 2011-11-22 15:58:06 +0000 | [diff] [blame] | 41 | if (SkScalarFraction(rad) != 0) { |
senorblanco@chromium.org | 91f489a | 2012-11-29 17:09:27 +0000 | [diff] [blame] | 42 | fName.printf("blur_%.2f_%s_%s", SkScalarToFloat(rad), name, quality); |
tomhudson@google.com | 8caac64 | 2011-11-22 15:58:06 +0000 | [diff] [blame] | 43 | } else { |
senorblanco@chromium.org | 91f489a | 2012-11-29 17:09:27 +0000 | [diff] [blame] | 44 | fName.printf("blur_%d_%s_%s", SkScalarRound(rad), name, quality); |
tomhudson@google.com | 8caac64 | 2011-11-22 15:58:06 +0000 | [diff] [blame] | 45 | } |
reed@google.com | 25df888 | 2011-07-14 19:03:58 +0000 | [diff] [blame] | 46 | } |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 47 | |
reed@google.com | 25df888 | 2011-07-14 19:03:58 +0000 | [diff] [blame] | 48 | protected: |
| 49 | virtual const char* onGetName() { |
| 50 | return fName.c_str(); |
| 51 | } |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 52 | |
reed@google.com | 25df888 | 2011-07-14 19:03:58 +0000 | [diff] [blame] | 53 | virtual void onDraw(SkCanvas* canvas) { |
| 54 | SkPaint paint; |
| 55 | this->setupPaint(&paint); |
| 56 | |
| 57 | paint.setAntiAlias(true); |
| 58 | |
| 59 | SkRandom rand; |
tomhudson@google.com | ca529d3 | 2011-10-28 15:34:49 +0000 | [diff] [blame] | 60 | for (int i = 0; i < SkBENCHLOOP(10); i++) { |
reed@google.com | 25df888 | 2011-07-14 19:03:58 +0000 | [diff] [blame] | 61 | SkRect r = SkRect::MakeWH(rand.nextUScalar1() * 400, |
| 62 | rand.nextUScalar1() * 400); |
| 63 | r.offset(fRadius, fRadius); |
| 64 | |
| 65 | if (fRadius > 0) { |
senorblanco@chromium.org | 91f489a | 2012-11-29 17:09:27 +0000 | [diff] [blame] | 66 | SkMaskFilter* mf = SkBlurMaskFilter::Create(fRadius, fStyle, fFlags); |
reed@google.com | 25df888 | 2011-07-14 19:03:58 +0000 | [diff] [blame] | 67 | paint.setMaskFilter(mf)->unref(); |
| 68 | } |
| 69 | canvas->drawOval(r, paint); |
| 70 | } |
| 71 | } |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 72 | |
reed@google.com | 25df888 | 2011-07-14 19:03:58 +0000 | [diff] [blame] | 73 | private: |
| 74 | typedef SkBenchmark INHERITED; |
| 75 | }; |
| 76 | |
reed@google.com | fc5100a | 2012-11-08 20:51:57 +0000 | [diff] [blame] | 77 | DEF_BENCH(return new BlurBench(p, SMALL, SkBlurMaskFilter::kNormal_BlurStyle);) |
| 78 | DEF_BENCH(return new BlurBench(p, SMALL, SkBlurMaskFilter::kSolid_BlurStyle);) |
| 79 | DEF_BENCH(return new BlurBench(p, SMALL, SkBlurMaskFilter::kOuter_BlurStyle);) |
| 80 | DEF_BENCH(return new BlurBench(p, SMALL, SkBlurMaskFilter::kInner_BlurStyle);) |
reed@google.com | 25df888 | 2011-07-14 19:03:58 +0000 | [diff] [blame] | 81 | |
reed@google.com | fc5100a | 2012-11-08 20:51:57 +0000 | [diff] [blame] | 82 | DEF_BENCH(return new BlurBench(p, BIG, SkBlurMaskFilter::kNormal_BlurStyle);) |
| 83 | DEF_BENCH(return new BlurBench(p, BIG, SkBlurMaskFilter::kSolid_BlurStyle);) |
| 84 | DEF_BENCH(return new BlurBench(p, BIG, SkBlurMaskFilter::kOuter_BlurStyle);) |
| 85 | DEF_BENCH(return new BlurBench(p, BIG, SkBlurMaskFilter::kInner_BlurStyle);) |
reed@google.com | 25df888 | 2011-07-14 19:03:58 +0000 | [diff] [blame] | 86 | |
senorblanco@chromium.org | 91f489a | 2012-11-29 17:09:27 +0000 | [diff] [blame] | 87 | DEF_BENCH(return new BlurBench(p, REALBIG, SkBlurMaskFilter::kNormal_BlurStyle);) |
| 88 | DEF_BENCH(return new BlurBench(p, REALBIG, SkBlurMaskFilter::kSolid_BlurStyle);) |
| 89 | DEF_BENCH(return new BlurBench(p, REALBIG, SkBlurMaskFilter::kOuter_BlurStyle);) |
| 90 | DEF_BENCH(return new BlurBench(p, REALBIG, SkBlurMaskFilter::kInner_BlurStyle);) |
| 91 | |
reed@google.com | fc5100a | 2012-11-08 20:51:57 +0000 | [diff] [blame] | 92 | DEF_BENCH(return new BlurBench(p, REAL, SkBlurMaskFilter::kNormal_BlurStyle);) |
| 93 | DEF_BENCH(return new BlurBench(p, REAL, SkBlurMaskFilter::kSolid_BlurStyle);) |
| 94 | DEF_BENCH(return new BlurBench(p, REAL, SkBlurMaskFilter::kOuter_BlurStyle);) |
| 95 | DEF_BENCH(return new BlurBench(p, REAL, SkBlurMaskFilter::kInner_BlurStyle);) |
tomhudson@google.com | 8caac64 | 2011-11-22 15:58:06 +0000 | [diff] [blame] | 96 | |
senorblanco@chromium.org | 91f489a | 2012-11-29 17:09:27 +0000 | [diff] [blame] | 97 | DEF_BENCH(return new BlurBench(p, SMALL, SkBlurMaskFilter::kNormal_BlurStyle, SkBlurMaskFilter::kHighQuality_BlurFlag);) |
| 98 | |
| 99 | DEF_BENCH(return new BlurBench(p, BIG, SkBlurMaskFilter::kNormal_BlurStyle, SkBlurMaskFilter::kHighQuality_BlurFlag);) |
| 100 | |
| 101 | DEF_BENCH(return new BlurBench(p, REALBIG, SkBlurMaskFilter::kNormal_BlurStyle, SkBlurMaskFilter::kHighQuality_BlurFlag);) |
| 102 | |
| 103 | DEF_BENCH(return new BlurBench(p, REAL, SkBlurMaskFilter::kNormal_BlurStyle, SkBlurMaskFilter::kHighQuality_BlurFlag);) |
| 104 | |
reed@google.com | fc5100a | 2012-11-08 20:51:57 +0000 | [diff] [blame] | 105 | DEF_BENCH(return new BlurBench(p, 0, SkBlurMaskFilter::kNormal_BlurStyle);) |