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 "Benchmark.h" 9 #include "SkBlurMask.h" 10 #include "SkCanvas.h" 11 #include "SkColorFilter.h" 12 #include "SkLayerDrawLooper.h" 13 #include "SkMaskFilter.h" 14 #include "SkPaint.h" 15 #include "SkPath.h" 16 #include "SkPoint.h" 17 #include "SkRRect.h" 18 #include "SkRect.h" 19 #include "SkString.h" 20 21 // Large blurred RR appear frequently on web pages. This benchmark measures our 22 // performance in this case. 23 class BlurRoundRectBench : public Benchmark { 24 public: 25 BlurRoundRectBench(int width, int height, int cornerRadius) 26 : fName("blurroundrect") { 27 fName.appendf("_WH_%ix%i_cr_%i", width, height, cornerRadius); 28 SkRect r = SkRect::MakeWH(SkIntToScalar(width), SkIntToScalar(height)); 29 fRRect.setRectXY(r, SkIntToScalar(cornerRadius), SkIntToScalar(cornerRadius)); 30 } 31 32 const char* onGetName() override { 33 return fName.c_str(); 34 } 35 36 SkIPoint onGetSize() override { 37 return SkIPoint::Make(SkScalarCeilToInt(fRRect.rect().width()), 38 SkScalarCeilToInt(fRRect.rect().height())); 39 } 40 41 void onDraw(int loops, SkCanvas* canvas) override { 42 SkLayerDrawLooper::Builder looperBuilder; 43 { 44 SkLayerDrawLooper::LayerInfo info; 45 info.fPaintBits = SkLayerDrawLooper::kMaskFilter_Bit 46 | SkLayerDrawLooper::kColorFilter_Bit; 47 info.fColorMode = SkBlendMode::kSrc; 48 info.fOffset = SkPoint::Make(SkIntToScalar(-1), SkIntToScalar(0)); 49 info.fPostTranslate = false; 50 SkPaint* paint = looperBuilder.addLayerOnTop(info); 51 paint->setMaskFilter(SkMaskFilter::MakeBlur(kNormal_SkBlurStyle, 52 SkBlurMask::ConvertRadiusToSigma(0.5))); 53 paint->setColorFilter(SkColorFilter::MakeModeFilter(SK_ColorLTGRAY, 54 SkBlendMode::kSrcIn)); 55 paint->setColor(SK_ColorGRAY); 56 } 57 { 58 SkLayerDrawLooper::LayerInfo info; 59 looperBuilder.addLayerOnTop(info); 60 } 61 SkPaint dullPaint; 62 dullPaint.setAntiAlias(true); 63 64 SkPaint loopedPaint; 65 loopedPaint.setLooper(looperBuilder.detach()); 66 loopedPaint.setAntiAlias(true); 67 loopedPaint.setColor(SK_ColorCYAN); 68 69 for (int i = 0; i < loops; i++) { 70 canvas->drawRect(fRRect.rect(), dullPaint); 71 canvas->drawRRect(fRRect, loopedPaint); 72 } 73 } 74 75 private: 76 SkString fName; 77 SkRRect fRRect; 78 79 typedef Benchmark INHERITED; 80 }; 81 82 // Create one with dimensions/rounded corners based on the skp 83 DEF_BENCH(return new BlurRoundRectBench(600, 5514, 6);) 84 // Same radii, much smaller rectangle 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);) 89