Index: bench/BlurRoundRectBench.cpp |
diff --git a/bench/BlurRoundRectBench.cpp b/bench/BlurRoundRectBench.cpp |
index 4fe4902255e19e069d818f885a62f01c9048e797..a138b40a3ce106f940aeb544a61c215b06345052 100644 |
--- a/bench/BlurRoundRectBench.cpp |
+++ b/bench/BlurRoundRectBench.cpp |
@@ -19,30 +19,15 @@ |
#include "SkString.h" |
#include "SkXfermode.h" |
+// Large blurred RR appear frequently on web pages. This benchmark measures our |
+// performance in this case. |
class BlurRoundRectBench : public SkBenchmark { |
public: |
- BlurRoundRectBench(int width, int height, |
- // X and Y radii for the upper left corner |
- int ulX, int ulY, |
- // X and Y radii for the upper right corner |
- int urX, int urY, |
- // X and Y radii for the lower right corner |
- int lrX, int lrY, |
- // X and Y radii for the lower left corner |
- int llX, int llY) |
- : fName("blurroundrect") |
- , fWidth(width) |
- , fHeight(height) { |
- fName.appendf("_WH[%ix%i]_UL[%ix%i]_UR[%ix%i]_LR[%ix%i]_LL[%ix%i]", |
- width, height, |
- ulX, ulY, |
- urX, urY, |
- lrX, lrY, |
- llX, llY); |
- fRadii[0].set(SkIntToScalar(ulX), SkIntToScalar(ulY)); |
- fRadii[1].set(SkIntToScalar(urX), SkIntToScalar(urY)); |
- fRadii[2].set(SkIntToScalar(lrX), SkIntToScalar(lrY)); |
- fRadii[3].set(SkIntToScalar(llX), SkIntToScalar(llY)); |
+ BlurRoundRectBench(int width, int height, int cornerRadius) |
+ : fName("blurroundrect") { |
+ fName.appendf("_WH[%ix%i]_cr[%i]", width, height, cornerRadius); |
+ SkRect r = SkRect::MakeWH(SkIntToScalar(width), SkIntToScalar(height)); |
+ fRRect.setRectXY(r, SkIntToScalar(cornerRadius), SkIntToScalar(cornerRadius)); |
} |
virtual const char* onGetName() SK_OVERRIDE { |
@@ -50,60 +35,60 @@ public: |
} |
virtual SkIPoint onGetSize() SK_OVERRIDE { |
- return SkIPoint::Make(fWidth, fHeight); |
+ return SkIPoint::Make(SkScalarCeilToInt(fRRect.rect().width()), |
+ SkScalarCeilToInt(fRRect.rect().height())); |
} |
virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { |
- for (int i = 0; i < this->getLoops(); i++) { |
- SkLayerDrawLooper* looper = new SkLayerDrawLooper; |
- { |
- SkLayerDrawLooper::LayerInfo info; |
- info.fFlagsMask = 0; |
- info.fPaintBits = 40; |
- info.fColorMode = SkXfermode::kSrc_Mode; |
- info.fOffset = SkPoint::Make(SkIntToScalar(-1), SkIntToScalar(0)); |
- info.fPostTranslate = false; |
- SkPaint* paint = looper->addLayerOnTop(info); |
- SkMaskFilter* maskFilter = SkBlurMaskFilter::Create(SK_ScalarHalf, |
- SkBlurMaskFilter::kNormal_BlurStyle, |
- SkBlurMaskFilter::kHighQuality_BlurFlag); |
- paint->setMaskFilter(maskFilter)->unref(); |
- SkColorFilter* colorFilter = SkColorFilter::CreateModeFilter(SK_ColorLTGRAY, |
- SkXfermode::kSrcIn_Mode); |
- paint->setColorFilter(colorFilter)->unref(); |
- paint->setColor(SK_ColorGRAY); |
- } |
- { |
- SkLayerDrawLooper::LayerInfo info; |
- looper->addLayerOnTop(info); |
- } |
- SkPaint paint; |
- SkRect rect = SkRect::MakeWH(SkIntToScalar(fWidth), SkIntToScalar(fHeight)); |
- canvas->drawRect(rect, paint); |
+ SkLayerDrawLooper* looper = new SkLayerDrawLooper; |
+ { |
+ SkLayerDrawLooper::LayerInfo info; |
+ info.fFlagsMask = 0; |
+ info.fPaintBits = SkLayerDrawLooper::kMaskFilter_Bit |
+ | SkLayerDrawLooper::kColorFilter_Bit; |
+ info.fColorMode = SkXfermode::kSrc_Mode; |
+ info.fOffset = SkPoint::Make(SkIntToScalar(-1), SkIntToScalar(0)); |
+ info.fPostTranslate = false; |
+ SkPaint* paint = looper->addLayerOnTop(info); |
+ SkMaskFilter* maskFilter = SkBlurMaskFilter::Create(SK_ScalarHalf, |
+ SkBlurMaskFilter::kNormal_BlurStyle, |
+ SkBlurMaskFilter::kHighQuality_BlurFlag); |
+ paint->setMaskFilter(maskFilter)->unref(); |
+ SkColorFilter* colorFilter = SkColorFilter::CreateModeFilter(SK_ColorLTGRAY, |
+ SkXfermode::kSrcIn_Mode); |
+ paint->setColorFilter(colorFilter)->unref(); |
+ paint->setColor(SK_ColorGRAY); |
+ } |
+ { |
+ SkLayerDrawLooper::LayerInfo info; |
+ looper->addLayerOnTop(info); |
+ } |
+ SkPaint dullPaint; |
+ dullPaint.setAntiAlias(true); |
- paint.setLooper(looper)->unref(); |
- paint.setAntiAlias(true); |
- paint.setColor(SK_ColorCYAN); |
+ SkPaint loopedPaint; |
+ loopedPaint.setLooper(looper)->unref(); |
+ loopedPaint.setAntiAlias(true); |
+ loopedPaint.setColor(SK_ColorCYAN); |
- SkRRect rrect; |
- rrect.setRectRadii(rect, fRadii); |
- canvas->drawRRect(rrect, paint); |
+ for (int i = 0; i < this->getLoops(); i++) { |
+ canvas->drawRect(fRRect.rect(), dullPaint); |
+ canvas->drawRRect(fRRect, loopedPaint); |
} |
} |
private: |
- SkString fName; |
- const int fWidth; |
- const int fHeight; |
- SkVector fRadii[4]; |
- typedef SkBenchmark INHERITED; |
+ SkString fName; |
+ SkRRect fRRect; |
+ |
+ typedef SkBenchmark INHERITED; |
}; |
// Create one with dimensions/rounded corners based on the skp |
-DEF_BENCH(return new BlurRoundRectBench(600, 5514, 6, 6, 6, 6, 6, 6, 6, 6);) |
+DEF_BENCH(return new BlurRoundRectBench(600, 5514, 6);) |
// Same radii, much smaller rectangle |
-DEF_BENCH(return new BlurRoundRectBench(100, 100, 6, 6, 6, 6, 6, 6, 6, 6);) |
+DEF_BENCH(return new BlurRoundRectBench(100, 100, 6);) |
robertphillips
2013/11/05 21:07:04
Fix comment
|
// Rounded rect with two opposite corners with large radii, the other two |
// small. |
-DEF_BENCH(return new BlurRoundRectBench(100, 100, 30, 30, 10, 10, 30, 30, 10, 10);) |
-DEF_BENCH(return new BlurRoundRectBench(100, 100, 90, 90, 90, 90, 90, 90, 90, 90);) |
+DEF_BENCH(return new BlurRoundRectBench(100, 100, 30);) |
+DEF_BENCH(return new BlurRoundRectBench(100, 100, 90);) |