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" |
scroggo@google.com | 7b05659 | 2013-11-05 15:57:21 +0000 | [diff] [blame] | 10 | #include "SkCanvas.h" |
| 11 | #include "SkColorFilter.h" |
| 12 | #include "SkLayerDrawLooper.h" |
Mike Reed | 1be1f8d | 2018-03-14 13:01:17 -0400 | [diff] [blame] | 13 | #include "SkMaskFilter.h" |
scroggo@google.com | 7b05659 | 2013-11-05 15:57:21 +0000 | [diff] [blame] | 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); |
Mike Reed | 1be1f8d | 2018-03-14 13:01:17 -0400 | [diff] [blame] | 51 | paint->setMaskFilter(SkMaskFilter::MakeBlur(kNormal_SkBlurStyle, |
| 52 | SkBlurMask::ConvertRadiusToSigma(0.5))); |
reed | d053ce9 | 2016-03-22 10:17:23 -0700 | [diff] [blame] | 53 | paint->setColorFilter(SkColorFilter::MakeModeFilter(SK_ColorLTGRAY, |
Mike Reed | 7d954ad | 2016-10-28 15:42:34 -0400 | [diff] [blame] | 54 | SkBlendMode::kSrcIn)); |
scroggo@google.com | 8610d2c | 2013-11-05 21:10:58 +0000 | [diff] [blame] | 55 | paint->setColor(SK_ColorGRAY); |
| 56 | } |
| 57 | { |
| 58 | SkLayerDrawLooper::LayerInfo info; |
commit-bot@chromium.org | 73cb153 | 2014-04-15 15:48:36 +0000 | [diff] [blame] | 59 | looperBuilder.addLayerOnTop(info); |
scroggo@google.com | 8610d2c | 2013-11-05 21:10:58 +0000 | [diff] [blame] | 60 | } |
| 61 | SkPaint dullPaint; |
| 62 | dullPaint.setAntiAlias(true); |
| 63 | |
| 64 | SkPaint loopedPaint; |
reed | 7b380d0 | 2016-03-21 13:25:16 -0700 | [diff] [blame] | 65 | loopedPaint.setLooper(looperBuilder.detach()); |
scroggo@google.com | 8610d2c | 2013-11-05 21:10:58 +0000 | [diff] [blame] | 66 | loopedPaint.setAntiAlias(true); |
| 67 | loopedPaint.setColor(SK_ColorCYAN); |
| 68 | |
commit-bot@chromium.org | 3361471 | 2013-12-03 18:17:16 +0000 | [diff] [blame] | 69 | for (int i = 0; i < loops; i++) { |
scroggo@google.com | 8610d2c | 2013-11-05 21:10:58 +0000 | [diff] [blame] | 70 | canvas->drawRect(fRRect.rect(), dullPaint); |
| 71 | canvas->drawRRect(fRRect, loopedPaint); |
scroggo@google.com | 7b05659 | 2013-11-05 15:57:21 +0000 | [diff] [blame] | 72 | } |
| 73 | } |
| 74 | |
| 75 | private: |
scroggo@google.com | 8610d2c | 2013-11-05 21:10:58 +0000 | [diff] [blame] | 76 | SkString fName; |
| 77 | SkRRect fRRect; |
| 78 | |
tfarina | f168b86 | 2014-06-19 12:32:29 -0700 | [diff] [blame] | 79 | typedef Benchmark INHERITED; |
scroggo@google.com | 7b05659 | 2013-11-05 15:57:21 +0000 | [diff] [blame] | 80 | }; |
| 81 | |
| 82 | // Create one with dimensions/rounded corners based on the skp |
scroggo@google.com | 8610d2c | 2013-11-05 21:10:58 +0000 | [diff] [blame] | 83 | DEF_BENCH(return new BlurRoundRectBench(600, 5514, 6);) |
scroggo@google.com | 7b05659 | 2013-11-05 15:57:21 +0000 | [diff] [blame] | 84 | // Same radii, much smaller rectangle |
scroggo@google.com | 8610d2c | 2013-11-05 21:10:58 +0000 | [diff] [blame] | 85 | DEF_BENCH(return new BlurRoundRectBench(100, 100, 6);) |
| 86 | // Other radii options |
| 87 | DEF_BENCH(return new BlurRoundRectBench(100, 100, 30);) |
| 88 | DEF_BENCH(return new BlurRoundRectBench(100, 100, 90);) |