blob: e4f956fc43adb94b8a6b7f8f0c1d83c8e537836a [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:
17 BlurCirclesGM()
18 : fName("blurcircles") {
19 }
20
21protected:
commit-bot@chromium.orgd53b2272014-05-07 17:50:03 +000022
mtklein36352bf2015-03-25 18:17:31 -070023 SkString onShortName() override {
commit-bot@chromium.orgd53b2272014-05-07 17:50:03 +000024 return fName;
25 }
26
mtklein36352bf2015-03-25 18:17:31 -070027 SkISize onISize() override {
commit-bot@chromium.orgd53b2272014-05-07 17:50:03 +000028 return SkISize::Make(950, 950);
29 }
30
mtklein36352bf2015-03-25 18:17:31 -070031 void onDraw(SkCanvas* canvas) override {
commit-bot@chromium.orgd53b2272014-05-07 17:50:03 +000032 canvas->scale(1.5f, 1.5f);
33 canvas->translate(50,50);
34
35 const float blurRadii[] = { 1,5,10,20 };
36 const int circleRadii[] = { 5,10,25,50 };
37 for (size_t i = 0; i < SK_ARRAY_COUNT(blurRadii); ++i) {
38 SkAutoCanvasRestore autoRestore(canvas, true);
39 canvas->translate(0, SkIntToScalar(150*i));
40 for (size_t j = 0; j < SK_ARRAY_COUNT(circleRadii); ++j) {
41 SkMaskFilter* filter = SkBlurMaskFilter::Create(
42 kNormal_SkBlurStyle,
43 SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(blurRadii[i])),
44 SkBlurMaskFilter::kHighQuality_BlurFlag);
45 SkPaint paint;
46 paint.setColor(SK_ColorBLACK);
47 paint.setMaskFilter(filter)->unref();
48
49 canvas->drawCircle(SkIntToScalar(50),SkIntToScalar(50),SkIntToScalar(circleRadii[j]),paint);
50 canvas->translate(SkIntToScalar(150), 0);
51 }
52 }
53 }
54private:
55 const SkString fName;
56
57 typedef skiagm::GM INHERITED;
58};
59
60DEF_GM(return new BlurCirclesGM();)