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