blob: 74490ce4240613ac967eafd2a8b386d21c93324d [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
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
15class BlurCirclesGM : public skiagm::GM {
16public:
robertphillips30c4cae2015-09-15 10:20:55 -070017 BlurCirclesGM() { }
commit-bot@chromium.orgd53b2272014-05-07 17:50:03 +000018
19protected:
robertphillips30c4cae2015-09-15 10:20:55 -070020 bool runAsBench() const override { return true; }
commit-bot@chromium.orgd53b2272014-05-07 17:50:03 +000021
mtklein36352bf2015-03-25 18:17:31 -070022 SkString onShortName() override {
robertphillips30c4cae2015-09-15 10:20:55 -070023 return SkString("blurcircles");
commit-bot@chromium.orgd53b2272014-05-07 17:50:03 +000024 }
25
mtklein36352bf2015-03-25 18:17:31 -070026 SkISize onISize() override {
commit-bot@chromium.orgd53b2272014-05-07 17:50:03 +000027 return SkISize::Make(950, 950);
28 }
29
robertphillips30c4cae2015-09-15 10:20:55 -070030 void onOnceBeforeDraw() override {
31 const float blurRadii[kNumBlurs] = { 1,5,10,20 };
32
33 for (int i = 0; i < kNumBlurs; ++i) {
34 fBlurFilters[i].reset(SkBlurMaskFilter::Create(
35 kNormal_SkBlurStyle,
36 SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(blurRadii[i])),
37 SkBlurMaskFilter::kHighQuality_BlurFlag));
38 }
39 }
40
mtklein36352bf2015-03-25 18:17:31 -070041 void onDraw(SkCanvas* canvas) override {
commit-bot@chromium.orgd53b2272014-05-07 17:50:03 +000042 canvas->scale(1.5f, 1.5f);
43 canvas->translate(50,50);
44
commit-bot@chromium.orgd53b2272014-05-07 17:50:03 +000045 const int circleRadii[] = { 5,10,25,50 };
robertphillips30c4cae2015-09-15 10:20:55 -070046
47 for (size_t i = 0; i < kNumBlurs; ++i) {
commit-bot@chromium.orgd53b2272014-05-07 17:50:03 +000048 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.orgd53b2272014-05-07 17:50:03 +000051 SkPaint paint;
52 paint.setColor(SK_ColorBLACK);
robertphillips30c4cae2015-09-15 10:20:55 -070053 paint.setMaskFilter(fBlurFilters[i]);
commit-bot@chromium.orgd53b2272014-05-07 17:50:03 +000054
55 canvas->drawCircle(SkIntToScalar(50),SkIntToScalar(50),SkIntToScalar(circleRadii[j]),paint);
56 canvas->translate(SkIntToScalar(150), 0);
57 }
58 }
59 }
60private:
robertphillips30c4cae2015-09-15 10:20:55 -070061 static const int kNumBlurs = 4;
62
63 SkAutoTUnref<SkMaskFilter> fBlurFilters[kNumBlurs];
commit-bot@chromium.orgd53b2272014-05-07 17:50:03 +000064
65 typedef skiagm::GM INHERITED;
66};
67
68DEF_GM(return new BlurCirclesGM();)