blob: a8bb52d123a13748cd28700f18d65dc730576a6d [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 {
37 const float blurRadii[kNumBlurs] = { 1,5,10,20 };
38
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,
Mike Reed1be1f8d2018-03-14 13:01:17 -040042 SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(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
commit-bot@chromium.orgd53b2272014-05-07 17:50:03 +000050 const int circleRadii[] = { 5,10,25,50 };
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);
54 canvas->translate(0, SkIntToScalar(150*i));
55 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
60 canvas->drawCircle(SkIntToScalar(50),SkIntToScalar(50),SkIntToScalar(circleRadii[j]),paint);
61 canvas->translate(SkIntToScalar(150), 0);
62 }
63 }
64 }
65private:
mtkleindbfd7ab2016-09-01 11:24:54 -070066 static constexpr int kNumBlurs = 4;
robertphillips30c4cae2015-09-15 10:20:55 -070067
reedefdfd512016-04-04 10:02:58 -070068 sk_sp<SkMaskFilter> fBlurFilters[kNumBlurs];
commit-bot@chromium.orgd53b2272014-05-07 17:50:03 +000069
70 typedef skiagm::GM INHERITED;
71};
72
73DEF_GM(return new BlurCirclesGM();)