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