blob: 449fc49f1a8a129c66b14d164387effd97c4c269 [file] [log] [blame]
commit-bot@chromium.orgd53b2272014-05-07 17:50:03 +00001/*
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 Kleinc0bd9f92019-04-23 12:05:21 -05008#include "gm/gm.h"
Ben Wagner6a34f3a2019-05-01 10:59:30 -04009#include "include/core/SkBlurTypes.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050010#include "include/core/SkCanvas.h"
Ben Wagner6a34f3a2019-05-01 10:59:30 -040011#include "include/core/SkColor.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050012#include "include/core/SkMaskFilter.h"
13#include "include/core/SkPaint.h"
Ben Wagner6a34f3a2019-05-01 10:59:30 -040014#include "include/core/SkRefCnt.h"
15#include "include/core/SkScalar.h"
16#include "include/core/SkSize.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050017#include "include/core/SkString.h"
Ben Wagner6a34f3a2019-05-01 10:59:30 -040018#include "include/core/SkTypes.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050019#include "src/core/SkBlurMask.h"
commit-bot@chromium.orgd53b2272014-05-07 17:50:03 +000020
21class BlurCirclesGM : public skiagm::GM {
22public:
robertphillips30c4cae2015-09-15 10:20:55 -070023 BlurCirclesGM() { }
commit-bot@chromium.orgd53b2272014-05-07 17:50:03 +000024
25protected:
robertphillips30c4cae2015-09-15 10:20:55 -070026 bool runAsBench() const override { return true; }
commit-bot@chromium.orgd53b2272014-05-07 17:50:03 +000027
mtklein36352bf2015-03-25 18:17:31 -070028 SkString onShortName() override {
robertphillips30c4cae2015-09-15 10:20:55 -070029 return SkString("blurcircles");
commit-bot@chromium.orgd53b2272014-05-07 17:50:03 +000030 }
31
mtklein36352bf2015-03-25 18:17:31 -070032 SkISize onISize() override {
commit-bot@chromium.orgd53b2272014-05-07 17:50:03 +000033 return SkISize::Make(950, 950);
34 }
35
robertphillips30c4cae2015-09-15 10:20:55 -070036 void onOnceBeforeDraw() override {
Brian Salomon96c8aeb2020-09-23 11:37:13 -040037 const float blurRadii[kNumBlurs] = {1.f, 5.f, 10.f, 20.f};
robertphillips30c4cae2015-09-15 10:20:55 -070038
39 for (int i = 0; i < kNumBlurs; ++i) {
Mike Reed1be1f8d2018-03-14 13:01:17 -040040 fBlurFilters[i] = SkMaskFilter::MakeBlur(
robertphillips30c4cae2015-09-15 10:20:55 -070041 kNormal_SkBlurStyle,
Brian Salomon96c8aeb2020-09-23 11:37:13 -040042 SkBlurMask::ConvertRadiusToSigma(blurRadii[i]));
robertphillips30c4cae2015-09-15 10:20:55 -070043 }
44 }
45
mtklein36352bf2015-03-25 18:17:31 -070046 void onDraw(SkCanvas* canvas) override {
commit-bot@chromium.orgd53b2272014-05-07 17:50:03 +000047 canvas->scale(1.5f, 1.5f);
48 canvas->translate(50,50);
49
Brian Salomon96c8aeb2020-09-23 11:37:13 -040050 const float circleRadii[] = {5.f, 10.f, 25.f, 50.f};
robertphillips30c4cae2015-09-15 10:20:55 -070051
52 for (size_t i = 0; i < kNumBlurs; ++i) {
commit-bot@chromium.orgd53b2272014-05-07 17:50:03 +000053 SkAutoCanvasRestore autoRestore(canvas, true);
Brian Salomon96c8aeb2020-09-23 11:37:13 -040054 canvas->translate(0, 150.f*i);
commit-bot@chromium.orgd53b2272014-05-07 17:50:03 +000055 for (size_t j = 0; j < SK_ARRAY_COUNT(circleRadii); ++j) {
commit-bot@chromium.orgd53b2272014-05-07 17:50:03 +000056 SkPaint paint;
57 paint.setColor(SK_ColorBLACK);
robertphillips30c4cae2015-09-15 10:20:55 -070058 paint.setMaskFilter(fBlurFilters[i]);
commit-bot@chromium.orgd53b2272014-05-07 17:50:03 +000059
Brian Salomon96c8aeb2020-09-23 11:37:13 -040060 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.orgd53b2272014-05-07 17:50:03 +000067 }
68 }
69 }
70private:
mtkleindbfd7ab2016-09-01 11:24:54 -070071 static constexpr int kNumBlurs = 4;
robertphillips30c4cae2015-09-15 10:20:55 -070072
reedefdfd512016-04-04 10:02:58 -070073 sk_sp<SkMaskFilter> fBlurFilters[kNumBlurs];
commit-bot@chromium.orgd53b2272014-05-07 17:50:03 +000074
John Stiles7571f9e2020-09-02 22:42:33 -040075 using INHERITED = skiagm::GM;
commit-bot@chromium.orgd53b2272014-05-07 17:50:03 +000076};
77
78DEF_GM(return new BlurCirclesGM();)