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 { |
Brian Salomon | 96c8aeb | 2020-09-23 11:37:13 -0400 | [diff] [blame] | 37 | const float blurRadii[kNumBlurs] = {1.f, 5.f, 10.f, 20.f}; |
robertphillips | 30c4cae | 2015-09-15 10:20:55 -0700 | [diff] [blame] | 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, |
Brian Salomon | 96c8aeb | 2020-09-23 11:37:13 -0400 | [diff] [blame] | 42 | SkBlurMask::ConvertRadiusToSigma(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 | |
Brian Salomon | 96c8aeb | 2020-09-23 11:37:13 -0400 | [diff] [blame] | 50 | const float circleRadii[] = {5.f, 10.f, 25.f, 50.f}; |
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); |
Brian Salomon | 96c8aeb | 2020-09-23 11:37:13 -0400 | [diff] [blame] | 54 | canvas->translate(0, 150.f*i); |
commit-bot@chromium.org | d53b227 | 2014-05-07 17:50:03 +0000 | [diff] [blame] | 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 | |
Brian Salomon | 96c8aeb | 2020-09-23 11:37:13 -0400 | [diff] [blame] | 60 | static constexpr SkPoint kCenter = {50.f, 50.f}; |
| 61 | // Throw a rotation in the mix to make sure GPU fast path handles it correctly. |
| 62 | canvas->save(); |
| 63 | canvas->rotate(j*22.f, kCenter.fX, kCenter.fY); |
| 64 | canvas->drawCircle(kCenter, circleRadii[j], paint); |
| 65 | canvas->restore(); |
| 66 | canvas->translate(150.f, 0.f); |
commit-bot@chromium.org | d53b227 | 2014-05-07 17:50:03 +0000 | [diff] [blame] | 67 | } |
| 68 | } |
| 69 | } |
| 70 | private: |
mtklein | dbfd7ab | 2016-09-01 11:24:54 -0700 | [diff] [blame] | 71 | static constexpr int kNumBlurs = 4; |
robertphillips | 30c4cae | 2015-09-15 10:20:55 -0700 | [diff] [blame] | 72 | |
reed | efdfd51 | 2016-04-04 10:02:58 -0700 | [diff] [blame] | 73 | sk_sp<SkMaskFilter> fBlurFilters[kNumBlurs]; |
commit-bot@chromium.org | d53b227 | 2014-05-07 17:50:03 +0000 | [diff] [blame] | 74 | |
John Stiles | 7571f9e | 2020-09-02 22:42:33 -0400 | [diff] [blame] | 75 | using INHERITED = skiagm::GM; |
commit-bot@chromium.org | d53b227 | 2014-05-07 17:50:03 +0000 | [diff] [blame] | 76 | }; |
| 77 | |
| 78 | DEF_GM(return new BlurCirclesGM();) |