scroggo@google.com | 7b05659 | 2013-11-05 15:57:21 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2013 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 | */ |
| 7 | |
tfarina | f168b86 | 2014-06-19 12:32:29 -0700 | [diff] [blame] | 8 | #include "Benchmark.h" |
scroggo@google.com | 7b05659 | 2013-11-05 15:57:21 +0000 | [diff] [blame] | 9 | #include "SkBlurMask.h" |
| 10 | #include "SkBlurMaskFilter.h" |
| 11 | #include "SkCanvas.h" |
| 12 | #include "SkColorFilter.h" |
| 13 | #include "SkLayerDrawLooper.h" |
| 14 | #include "SkPaint.h" |
| 15 | #include "SkPath.h" |
| 16 | #include "SkPoint.h" |
scroggo@google.com | 7b05659 | 2013-11-05 15:57:21 +0000 | [diff] [blame] | 17 | #include "SkRRect.h" |
tfarina | f168b86 | 2014-06-19 12:32:29 -0700 | [diff] [blame] | 18 | #include "SkRect.h" |
scroggo@google.com | 7b05659 | 2013-11-05 15:57:21 +0000 | [diff] [blame] | 19 | #include "SkString.h" |
scroggo@google.com | 7b05659 | 2013-11-05 15:57:21 +0000 | [diff] [blame] | 20 | |
scroggo@google.com | 8610d2c | 2013-11-05 21:10:58 +0000 | [diff] [blame] | 21 | // Large blurred RR appear frequently on web pages. This benchmark measures our |
| 22 | // performance in this case. |
tfarina | f168b86 | 2014-06-19 12:32:29 -0700 | [diff] [blame] | 23 | class BlurRoundRectBench : public Benchmark { |
scroggo@google.com | 7b05659 | 2013-11-05 15:57:21 +0000 | [diff] [blame] | 24 | public: |
scroggo@google.com | 8610d2c | 2013-11-05 21:10:58 +0000 | [diff] [blame] | 25 | BlurRoundRectBench(int width, int height, int cornerRadius) |
| 26 | : fName("blurroundrect") { |
jcgregorio | 1703bd1 | 2016-08-29 13:33:04 -0700 | [diff] [blame] | 27 | fName.appendf("_WH_%ix%i_cr_%i", width, height, cornerRadius); |
scroggo@google.com | 8610d2c | 2013-11-05 21:10:58 +0000 | [diff] [blame] | 28 | SkRect r = SkRect::MakeWH(SkIntToScalar(width), SkIntToScalar(height)); |
| 29 | fRRect.setRectXY(r, SkIntToScalar(cornerRadius), SkIntToScalar(cornerRadius)); |
scroggo@google.com | 7b05659 | 2013-11-05 15:57:21 +0000 | [diff] [blame] | 30 | } |
| 31 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 32 | const char* onGetName() override { |
scroggo@google.com | 7b05659 | 2013-11-05 15:57:21 +0000 | [diff] [blame] | 33 | return fName.c_str(); |
| 34 | } |
| 35 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 36 | SkIPoint onGetSize() override { |
scroggo@google.com | 8610d2c | 2013-11-05 21:10:58 +0000 | [diff] [blame] | 37 | return SkIPoint::Make(SkScalarCeilToInt(fRRect.rect().width()), |
| 38 | SkScalarCeilToInt(fRRect.rect().height())); |
scroggo@google.com | 7b05659 | 2013-11-05 15:57:21 +0000 | [diff] [blame] | 39 | } |
| 40 | |
mtklein | a1ebeb2 | 2015-10-01 09:43:39 -0700 | [diff] [blame] | 41 | void onDraw(int loops, SkCanvas* canvas) override { |
commit-bot@chromium.org | 73cb153 | 2014-04-15 15:48:36 +0000 | [diff] [blame] | 42 | SkLayerDrawLooper::Builder looperBuilder; |
scroggo@google.com | 8610d2c | 2013-11-05 21:10:58 +0000 | [diff] [blame] | 43 | { |
| 44 | SkLayerDrawLooper::LayerInfo info; |
scroggo@google.com | 8610d2c | 2013-11-05 21:10:58 +0000 | [diff] [blame] | 45 | info.fPaintBits = SkLayerDrawLooper::kMaskFilter_Bit |
| 46 | | SkLayerDrawLooper::kColorFilter_Bit; |
Mike Reed | faba371 | 2016-11-03 14:45:31 -0400 | [diff] [blame] | 47 | info.fColorMode = SkBlendMode::kSrc; |
scroggo@google.com | 8610d2c | 2013-11-05 21:10:58 +0000 | [diff] [blame] | 48 | info.fOffset = SkPoint::Make(SkIntToScalar(-1), SkIntToScalar(0)); |
| 49 | info.fPostTranslate = false; |
commit-bot@chromium.org | 73cb153 | 2014-04-15 15:48:36 +0000 | [diff] [blame] | 50 | SkPaint* paint = looperBuilder.addLayerOnTop(info); |
reed | efdfd51 | 2016-04-04 10:02:58 -0700 | [diff] [blame] | 51 | paint->setMaskFilter(SkBlurMaskFilter::Make(kNormal_SkBlurStyle, |
| 52 | SkBlurMask::ConvertRadiusToSigma(0.5), |
| 53 | SkBlurMaskFilter::kHighQuality_BlurFlag)); |
reed | d053ce9 | 2016-03-22 10:17:23 -0700 | [diff] [blame] | 54 | paint->setColorFilter(SkColorFilter::MakeModeFilter(SK_ColorLTGRAY, |
Mike Reed | 7d954ad | 2016-10-28 15:42:34 -0400 | [diff] [blame] | 55 | SkBlendMode::kSrcIn)); |
scroggo@google.com | 8610d2c | 2013-11-05 21:10:58 +0000 | [diff] [blame] | 56 | paint->setColor(SK_ColorGRAY); |
| 57 | } |
| 58 | { |
| 59 | SkLayerDrawLooper::LayerInfo info; |
commit-bot@chromium.org | 73cb153 | 2014-04-15 15:48:36 +0000 | [diff] [blame] | 60 | looperBuilder.addLayerOnTop(info); |
scroggo@google.com | 8610d2c | 2013-11-05 21:10:58 +0000 | [diff] [blame] | 61 | } |
| 62 | SkPaint dullPaint; |
| 63 | dullPaint.setAntiAlias(true); |
| 64 | |
| 65 | SkPaint loopedPaint; |
reed | 7b380d0 | 2016-03-21 13:25:16 -0700 | [diff] [blame] | 66 | loopedPaint.setLooper(looperBuilder.detach()); |
scroggo@google.com | 8610d2c | 2013-11-05 21:10:58 +0000 | [diff] [blame] | 67 | loopedPaint.setAntiAlias(true); |
| 68 | loopedPaint.setColor(SK_ColorCYAN); |
| 69 | |
commit-bot@chromium.org | 3361471 | 2013-12-03 18:17:16 +0000 | [diff] [blame] | 70 | for (int i = 0; i < loops; i++) { |
scroggo@google.com | 8610d2c | 2013-11-05 21:10:58 +0000 | [diff] [blame] | 71 | canvas->drawRect(fRRect.rect(), dullPaint); |
| 72 | canvas->drawRRect(fRRect, loopedPaint); |
scroggo@google.com | 7b05659 | 2013-11-05 15:57:21 +0000 | [diff] [blame] | 73 | } |
| 74 | } |
| 75 | |
| 76 | private: |
scroggo@google.com | 8610d2c | 2013-11-05 21:10:58 +0000 | [diff] [blame] | 77 | SkString fName; |
| 78 | SkRRect fRRect; |
| 79 | |
tfarina | f168b86 | 2014-06-19 12:32:29 -0700 | [diff] [blame] | 80 | typedef Benchmark INHERITED; |
scroggo@google.com | 7b05659 | 2013-11-05 15:57:21 +0000 | [diff] [blame] | 81 | }; |
| 82 | |
| 83 | // Create one with dimensions/rounded corners based on the skp |
scroggo@google.com | 8610d2c | 2013-11-05 21:10:58 +0000 | [diff] [blame] | 84 | DEF_BENCH(return new BlurRoundRectBench(600, 5514, 6);) |
scroggo@google.com | 7b05659 | 2013-11-05 15:57:21 +0000 | [diff] [blame] | 85 | // Same radii, much smaller rectangle |
scroggo@google.com | 8610d2c | 2013-11-05 21:10:58 +0000 | [diff] [blame] | 86 | DEF_BENCH(return new BlurRoundRectBench(100, 100, 6);) |
| 87 | // Other radii options |
| 88 | DEF_BENCH(return new BlurRoundRectBench(100, 100, 30);) |
| 89 | DEF_BENCH(return new BlurRoundRectBench(100, 100, 90);) |