1 /* 2 * Copyright 2014 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 "gm.h" 9 #include "SkBlurMask.h" 10 #include "SkBlurMaskFilter.h" 11 #include "SkCanvas.h" 12 #include "SkPaint.h" 13 #include "SkString.h" 14 15 class BlurCirclesGM : public skiagm::GM { 16 public: 17 BlurCirclesGM() { } 18 19 protected: 20 bool runAsBench() const override { return true; } 21 22 SkString onShortName() override { 23 return SkString("blurcircles"); 24 } 25 26 SkISize onISize() override { 27 return SkISize::Make(950, 950); 28 } 29 30 void onOnceBeforeDraw() override { 31 const float blurRadii[kNumBlurs] = { 1,5,10,20 }; 32 33 for (int i = 0; i < kNumBlurs; ++i) { 34 fBlurFilters[i].reset(SkBlurMaskFilter::Create( 35 kNormal_SkBlurStyle, 36 SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(blurRadii[i])), 37 SkBlurMaskFilter::kHighQuality_BlurFlag)); 38 } 39 } 40 41 void onDraw(SkCanvas* canvas) override { 42 canvas->scale(1.5f, 1.5f); 43 canvas->translate(50,50); 44 45 const int circleRadii[] = { 5,10,25,50 }; 46 47 for (size_t i = 0; i < kNumBlurs; ++i) { 48 SkAutoCanvasRestore autoRestore(canvas, true); 49 canvas->translate(0, SkIntToScalar(150*i)); 50 for (size_t j = 0; j < SK_ARRAY_COUNT(circleRadii); ++j) { 51 SkPaint paint; 52 paint.setColor(SK_ColorBLACK); 53 paint.setMaskFilter(fBlurFilters[i]); 54 55 canvas->drawCircle(SkIntToScalar(50),SkIntToScalar(50),SkIntToScalar(circleRadii[j]),paint); 56 canvas->translate(SkIntToScalar(150), 0); 57 } 58 } 59 } 60 private: 61 static const int kNumBlurs = 4; 62 63 SkAutoTUnref<SkMaskFilter> fBlurFilters[kNumBlurs]; 64 65 typedef skiagm::GM INHERITED; 66 }; 67 68 DEF_GM(return new BlurCirclesGM();) 69