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 | |
| 8 | #include "SkBenchmark.h" |
| 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" |
| 17 | #include "SkRect.h" |
| 18 | #include "SkRRect.h" |
| 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. |
scroggo@google.com | 7b05659 | 2013-11-05 15:57:21 +0000 | [diff] [blame] | 24 | class BlurRoundRectBench : public SkBenchmark { |
| 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 | |
| 33 | virtual const char* onGetName() SK_OVERRIDE { |
| 34 | return fName.c_str(); |
| 35 | } |
| 36 | |
| 37 | virtual SkIPoint onGetSize() SK_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 | |
commit-bot@chromium.org | 3361471 | 2013-12-03 18:17:16 +0000 | [diff] [blame] | 42 | virtual void onDraw(const int loops, SkCanvas* canvas) SK_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); |
robertphillips@google.com | 6c1e49a | 2013-11-10 15:08:45 +0000 | [diff] [blame] | 52 | SkMaskFilter* maskFilter = SkBlurMaskFilter::Create( |
scroggo@google.com | 8610d2c | 2013-11-05 21:10:58 +0000 | [diff] [blame] | 53 | SkBlurMaskFilter::kNormal_BlurStyle, |
robertphillips@google.com | 6c1e49a | 2013-11-10 15:08:45 +0000 | [diff] [blame] | 54 | SkBlurMask::ConvertRadiusToSigma(SK_ScalarHalf), |
scroggo@google.com | 8610d2c | 2013-11-05 21:10:58 +0000 | [diff] [blame] | 55 | SkBlurMaskFilter::kHighQuality_BlurFlag); |
| 56 | paint->setMaskFilter(maskFilter)->unref(); |
| 57 | SkColorFilter* colorFilter = SkColorFilter::CreateModeFilter(SK_ColorLTGRAY, |
| 58 | SkXfermode::kSrcIn_Mode); |
| 59 | paint->setColorFilter(colorFilter)->unref(); |
| 60 | paint->setColor(SK_ColorGRAY); |
| 61 | } |
| 62 | { |
| 63 | SkLayerDrawLooper::LayerInfo info; |
commit-bot@chromium.org | 73cb153 | 2014-04-15 15:48:36 +0000 | [diff] [blame^] | 64 | looperBuilder.addLayerOnTop(info); |
scroggo@google.com | 8610d2c | 2013-11-05 21:10:58 +0000 | [diff] [blame] | 65 | } |
| 66 | SkPaint dullPaint; |
| 67 | dullPaint.setAntiAlias(true); |
| 68 | |
| 69 | SkPaint loopedPaint; |
commit-bot@chromium.org | 73cb153 | 2014-04-15 15:48:36 +0000 | [diff] [blame^] | 70 | loopedPaint.setLooper(looperBuilder.detachLooper())->unref(); |
scroggo@google.com | 8610d2c | 2013-11-05 21:10:58 +0000 | [diff] [blame] | 71 | loopedPaint.setAntiAlias(true); |
| 72 | loopedPaint.setColor(SK_ColorCYAN); |
| 73 | |
commit-bot@chromium.org | 3361471 | 2013-12-03 18:17:16 +0000 | [diff] [blame] | 74 | for (int i = 0; i < loops; i++) { |
scroggo@google.com | 8610d2c | 2013-11-05 21:10:58 +0000 | [diff] [blame] | 75 | canvas->drawRect(fRRect.rect(), dullPaint); |
| 76 | canvas->drawRRect(fRRect, loopedPaint); |
scroggo@google.com | 7b05659 | 2013-11-05 15:57:21 +0000 | [diff] [blame] | 77 | } |
| 78 | } |
| 79 | |
| 80 | private: |
scroggo@google.com | 8610d2c | 2013-11-05 21:10:58 +0000 | [diff] [blame] | 81 | SkString fName; |
| 82 | SkRRect fRRect; |
| 83 | |
| 84 | typedef SkBenchmark INHERITED; |
scroggo@google.com | 7b05659 | 2013-11-05 15:57:21 +0000 | [diff] [blame] | 85 | }; |
| 86 | |
| 87 | // Create one with dimensions/rounded corners based on the skp |
scroggo@google.com | 8610d2c | 2013-11-05 21:10:58 +0000 | [diff] [blame] | 88 | DEF_BENCH(return new BlurRoundRectBench(600, 5514, 6);) |
scroggo@google.com | 7b05659 | 2013-11-05 15:57:21 +0000 | [diff] [blame] | 89 | // Same radii, much smaller rectangle |
scroggo@google.com | 8610d2c | 2013-11-05 21:10:58 +0000 | [diff] [blame] | 90 | DEF_BENCH(return new BlurRoundRectBench(100, 100, 6);) |
| 91 | // Other radii options |
| 92 | DEF_BENCH(return new BlurRoundRectBench(100, 100, 30);) |
| 93 | DEF_BENCH(return new BlurRoundRectBench(100, 100, 90);) |