commit-bot@chromium.org | d53b227 | 2014-05-07 17:50:03 +0000 | [diff] [blame] | 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: |
robertphillips | 30c4cae | 2015-09-15 10:20:55 -0700 | [diff] [blame] | 17 | BlurCirclesGM() { } |
commit-bot@chromium.org | d53b227 | 2014-05-07 17:50:03 +0000 | [diff] [blame] | 18 | |
| 19 | protected: |
robertphillips | 30c4cae | 2015-09-15 10:20:55 -0700 | [diff] [blame] | 20 | bool runAsBench() const override { return true; } |
commit-bot@chromium.org | d53b227 | 2014-05-07 17:50:03 +0000 | [diff] [blame] | 21 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 22 | SkString onShortName() override { |
robertphillips | 30c4cae | 2015-09-15 10:20:55 -0700 | [diff] [blame] | 23 | return SkString("blurcircles"); |
commit-bot@chromium.org | d53b227 | 2014-05-07 17:50:03 +0000 | [diff] [blame] | 24 | } |
| 25 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 26 | SkISize onISize() override { |
commit-bot@chromium.org | d53b227 | 2014-05-07 17:50:03 +0000 | [diff] [blame] | 27 | return SkISize::Make(950, 950); |
| 28 | } |
| 29 | |
robertphillips | 30c4cae | 2015-09-15 10:20:55 -0700 | [diff] [blame] | 30 | void onOnceBeforeDraw() override { |
| 31 | const float blurRadii[kNumBlurs] = { 1,5,10,20 }; |
| 32 | |
| 33 | for (int i = 0; i < kNumBlurs; ++i) { |
reed | efdfd51 | 2016-04-04 10:02:58 -0700 | [diff] [blame] | 34 | fBlurFilters[i] = SkBlurMaskFilter::Make( |
robertphillips | 30c4cae | 2015-09-15 10:20:55 -0700 | [diff] [blame] | 35 | kNormal_SkBlurStyle, |
| 36 | SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(blurRadii[i])), |
reed | efdfd51 | 2016-04-04 10:02:58 -0700 | [diff] [blame] | 37 | SkBlurMaskFilter::kHighQuality_BlurFlag); |
robertphillips | 30c4cae | 2015-09-15 10:20:55 -0700 | [diff] [blame] | 38 | } |
| 39 | } |
| 40 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 41 | void onDraw(SkCanvas* canvas) override { |
commit-bot@chromium.org | d53b227 | 2014-05-07 17:50:03 +0000 | [diff] [blame] | 42 | canvas->scale(1.5f, 1.5f); |
| 43 | canvas->translate(50,50); |
| 44 | |
commit-bot@chromium.org | d53b227 | 2014-05-07 17:50:03 +0000 | [diff] [blame] | 45 | const int circleRadii[] = { 5,10,25,50 }; |
robertphillips | 30c4cae | 2015-09-15 10:20:55 -0700 | [diff] [blame] | 46 | |
| 47 | for (size_t i = 0; i < kNumBlurs; ++i) { |
commit-bot@chromium.org | d53b227 | 2014-05-07 17:50:03 +0000 | [diff] [blame] | 48 | SkAutoCanvasRestore autoRestore(canvas, true); |
| 49 | canvas->translate(0, SkIntToScalar(150*i)); |
| 50 | for (size_t j = 0; j < SK_ARRAY_COUNT(circleRadii); ++j) { |
commit-bot@chromium.org | d53b227 | 2014-05-07 17:50:03 +0000 | [diff] [blame] | 51 | SkPaint paint; |
| 52 | paint.setColor(SK_ColorBLACK); |
robertphillips | 30c4cae | 2015-09-15 10:20:55 -0700 | [diff] [blame] | 53 | paint.setMaskFilter(fBlurFilters[i]); |
commit-bot@chromium.org | d53b227 | 2014-05-07 17:50:03 +0000 | [diff] [blame] | 54 | |
| 55 | canvas->drawCircle(SkIntToScalar(50),SkIntToScalar(50),SkIntToScalar(circleRadii[j]),paint); |
| 56 | canvas->translate(SkIntToScalar(150), 0); |
| 57 | } |
| 58 | } |
| 59 | } |
| 60 | private: |
mtklein | dbfd7ab | 2016-09-01 11:24:54 -0700 | [diff] [blame] | 61 | static constexpr int kNumBlurs = 4; |
robertphillips | 30c4cae | 2015-09-15 10:20:55 -0700 | [diff] [blame] | 62 | |
reed | efdfd51 | 2016-04-04 10:02:58 -0700 | [diff] [blame] | 63 | sk_sp<SkMaskFilter> fBlurFilters[kNumBlurs]; |
commit-bot@chromium.org | d53b227 | 2014-05-07 17:50:03 +0000 | [diff] [blame] | 64 | |
| 65 | typedef skiagm::GM INHERITED; |
| 66 | }; |
| 67 | |
| 68 | DEF_GM(return new BlurCirclesGM();) |