Index: gm/blurcircles.cpp |
diff --git a/gm/blurcircles.cpp b/gm/blurcircles.cpp |
index e4f956fc43adb94b8a6b7f8f0c1d83c8e537836a..74490ce4240613ac967eafd2a8b386d21c93324d 100644 |
--- a/gm/blurcircles.cpp |
+++ b/gm/blurcircles.cpp |
@@ -14,37 +14,43 @@ |
class BlurCirclesGM : public skiagm::GM { |
public: |
- BlurCirclesGM() |
- : fName("blurcircles") { |
- } |
+ BlurCirclesGM() { } |
protected: |
+ bool runAsBench() const override { return true; } |
SkString onShortName() override { |
- return fName; |
+ return SkString("blurcircles"); |
} |
SkISize onISize() override { |
return SkISize::Make(950, 950); |
} |
+ void onOnceBeforeDraw() override { |
+ const float blurRadii[kNumBlurs] = { 1,5,10,20 }; |
+ |
+ for (int i = 0; i < kNumBlurs; ++i) { |
+ fBlurFilters[i].reset(SkBlurMaskFilter::Create( |
+ kNormal_SkBlurStyle, |
+ SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(blurRadii[i])), |
+ SkBlurMaskFilter::kHighQuality_BlurFlag)); |
+ } |
+ } |
+ |
void onDraw(SkCanvas* canvas) override { |
canvas->scale(1.5f, 1.5f); |
canvas->translate(50,50); |
- const float blurRadii[] = { 1,5,10,20 }; |
const int circleRadii[] = { 5,10,25,50 }; |
- for (size_t i = 0; i < SK_ARRAY_COUNT(blurRadii); ++i) { |
+ |
+ for (size_t i = 0; i < kNumBlurs; ++i) { |
SkAutoCanvasRestore autoRestore(canvas, true); |
canvas->translate(0, SkIntToScalar(150*i)); |
for (size_t j = 0; j < SK_ARRAY_COUNT(circleRadii); ++j) { |
- SkMaskFilter* filter = SkBlurMaskFilter::Create( |
- kNormal_SkBlurStyle, |
- SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(blurRadii[i])), |
- SkBlurMaskFilter::kHighQuality_BlurFlag); |
SkPaint paint; |
paint.setColor(SK_ColorBLACK); |
- paint.setMaskFilter(filter)->unref(); |
+ paint.setMaskFilter(fBlurFilters[i]); |
canvas->drawCircle(SkIntToScalar(50),SkIntToScalar(50),SkIntToScalar(circleRadii[j]),paint); |
canvas->translate(SkIntToScalar(150), 0); |
@@ -52,7 +58,9 @@ protected: |
} |
} |
private: |
- const SkString fName; |
+ static const int kNumBlurs = 4; |
+ |
+ SkAutoTUnref<SkMaskFilter> fBlurFilters[kNumBlurs]; |
typedef skiagm::GM INHERITED; |
}; |