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 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 8 | #include "gm/gm.h" |
Ben Wagner | 6a34f3a | 2019-05-01 10:59:30 -0400 | [diff] [blame] | 9 | #include "include/core/SkBlurTypes.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 10 | #include "include/core/SkCanvas.h" |
Ben Wagner | 6a34f3a | 2019-05-01 10:59:30 -0400 | [diff] [blame] | 11 | #include "include/core/SkColor.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 12 | #include "include/core/SkMaskFilter.h" |
| 13 | #include "include/core/SkPaint.h" |
Ben Wagner | 6a34f3a | 2019-05-01 10:59:30 -0400 | [diff] [blame] | 14 | #include "include/core/SkRefCnt.h" |
| 15 | #include "include/core/SkScalar.h" |
| 16 | #include "include/core/SkSize.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 17 | #include "include/core/SkString.h" |
Ben Wagner | 6a34f3a | 2019-05-01 10:59:30 -0400 | [diff] [blame] | 18 | #include "include/core/SkTypes.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 19 | #include "src/core/SkBlurMask.h" |
commit-bot@chromium.org | d53b227 | 2014-05-07 17:50:03 +0000 | [diff] [blame] | 20 | |
| 21 | class BlurCirclesGM : public skiagm::GM { |
| 22 | public: |
robertphillips | 30c4cae | 2015-09-15 10:20:55 -0700 | [diff] [blame] | 23 | BlurCirclesGM() { } |
commit-bot@chromium.org | d53b227 | 2014-05-07 17:50:03 +0000 | [diff] [blame] | 24 | |
| 25 | protected: |
robertphillips | 30c4cae | 2015-09-15 10:20:55 -0700 | [diff] [blame] | 26 | bool runAsBench() const override { return true; } |
commit-bot@chromium.org | d53b227 | 2014-05-07 17:50:03 +0000 | [diff] [blame] | 27 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 28 | SkString onShortName() override { |
robertphillips | 30c4cae | 2015-09-15 10:20:55 -0700 | [diff] [blame] | 29 | return SkString("blurcircles"); |
commit-bot@chromium.org | d53b227 | 2014-05-07 17:50:03 +0000 | [diff] [blame] | 30 | } |
| 31 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 32 | SkISize onISize() override { |
commit-bot@chromium.org | d53b227 | 2014-05-07 17:50:03 +0000 | [diff] [blame] | 33 | return SkISize::Make(950, 950); |
| 34 | } |
| 35 | |
robertphillips | 30c4cae | 2015-09-15 10:20:55 -0700 | [diff] [blame] | 36 | void onOnceBeforeDraw() override { |
| 37 | const float blurRadii[kNumBlurs] = { 1,5,10,20 }; |
| 38 | |
| 39 | for (int i = 0; i < kNumBlurs; ++i) { |
Mike Reed | 1be1f8d | 2018-03-14 13:01:17 -0400 | [diff] [blame] | 40 | fBlurFilters[i] = SkMaskFilter::MakeBlur( |
robertphillips | 30c4cae | 2015-09-15 10:20:55 -0700 | [diff] [blame] | 41 | kNormal_SkBlurStyle, |
Mike Reed | 1be1f8d | 2018-03-14 13:01:17 -0400 | [diff] [blame] | 42 | SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(blurRadii[i]))); |
robertphillips | 30c4cae | 2015-09-15 10:20:55 -0700 | [diff] [blame] | 43 | } |
| 44 | } |
| 45 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 46 | void onDraw(SkCanvas* canvas) override { |
commit-bot@chromium.org | d53b227 | 2014-05-07 17:50:03 +0000 | [diff] [blame] | 47 | canvas->scale(1.5f, 1.5f); |
| 48 | canvas->translate(50,50); |
| 49 | |
commit-bot@chromium.org | d53b227 | 2014-05-07 17:50:03 +0000 | [diff] [blame] | 50 | const int circleRadii[] = { 5,10,25,50 }; |
robertphillips | 30c4cae | 2015-09-15 10:20:55 -0700 | [diff] [blame] | 51 | |
| 52 | for (size_t i = 0; i < kNumBlurs; ++i) { |
commit-bot@chromium.org | d53b227 | 2014-05-07 17:50:03 +0000 | [diff] [blame] | 53 | SkAutoCanvasRestore autoRestore(canvas, true); |
| 54 | canvas->translate(0, SkIntToScalar(150*i)); |
| 55 | 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] | 56 | SkPaint paint; |
| 57 | paint.setColor(SK_ColorBLACK); |
robertphillips | 30c4cae | 2015-09-15 10:20:55 -0700 | [diff] [blame] | 58 | paint.setMaskFilter(fBlurFilters[i]); |
commit-bot@chromium.org | d53b227 | 2014-05-07 17:50:03 +0000 | [diff] [blame] | 59 | |
| 60 | canvas->drawCircle(SkIntToScalar(50),SkIntToScalar(50),SkIntToScalar(circleRadii[j]),paint); |
| 61 | canvas->translate(SkIntToScalar(150), 0); |
| 62 | } |
| 63 | } |
| 64 | } |
| 65 | private: |
mtklein | dbfd7ab | 2016-09-01 11:24:54 -0700 | [diff] [blame] | 66 | static constexpr int kNumBlurs = 4; |
robertphillips | 30c4cae | 2015-09-15 10:20:55 -0700 | [diff] [blame] | 67 | |
reed | efdfd51 | 2016-04-04 10:02:58 -0700 | [diff] [blame] | 68 | sk_sp<SkMaskFilter> fBlurFilters[kNumBlurs]; |
commit-bot@chromium.org | d53b227 | 2014-05-07 17:50:03 +0000 | [diff] [blame] | 69 | |
| 70 | typedef skiagm::GM INHERITED; |
| 71 | }; |
| 72 | |
| 73 | DEF_GM(return new BlurCirclesGM();) |