blob: 44f4d6d072bcf3d101df9b0747d7b904fb0fbfa6 [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:
22 virtual uint32_t onGetFlags() const SK_OVERRIDE {
23 return kSkipTiled_Flag;
24 }
25
26 virtual SkString onShortName() SK_OVERRIDE {
27 return fName;
28 }
29
30 virtual SkISize onISize() SK_OVERRIDE {
31 return SkISize::Make(950, 950);
32 }
33
34 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE {
35 canvas->scale(1.5f, 1.5f);
36 canvas->translate(50,50);
37
38 const float blurRadii[] = { 1,5,10,20 };
39 const int circleRadii[] = { 5,10,25,50 };
40 for (size_t i = 0; i < SK_ARRAY_COUNT(blurRadii); ++i) {
41 SkAutoCanvasRestore autoRestore(canvas, true);
42 canvas->translate(0, SkIntToScalar(150*i));
43 for (size_t j = 0; j < SK_ARRAY_COUNT(circleRadii); ++j) {
44 SkMaskFilter* filter = SkBlurMaskFilter::Create(
45 kNormal_SkBlurStyle,
46 SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(blurRadii[i])),
47 SkBlurMaskFilter::kHighQuality_BlurFlag);
48 SkPaint paint;
49 paint.setColor(SK_ColorBLACK);
50 paint.setMaskFilter(filter)->unref();
51
52 canvas->drawCircle(SkIntToScalar(50),SkIntToScalar(50),SkIntToScalar(circleRadii[j]),paint);
53 canvas->translate(SkIntToScalar(150), 0);
54 }
55 }
56 }
57private:
58 const SkString fName;
59
60 typedef skiagm::GM INHERITED;
61};
62
63DEF_GM(return new BlurCirclesGM();)