1
2 /*
3 * Copyright 2011 Google Inc.
4 *
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
7 */
8 #include "gm.h"
9 #include "SkBlurMask.h"
10 #include "SkBlurMaskFilter.h"
11
12 namespace skiagm {
13
14 class BlursGM : public GM {
15 public:
BlursGM()16 BlursGM() {
17 this->setBGColor(0xFFDDDDDD);
18 }
19
20 protected:
onGetFlags() const21 virtual uint32_t onGetFlags() const SK_OVERRIDE {
22 return kSkipTiled_Flag;
23 }
24
onShortName()25 virtual SkString onShortName() {
26 return SkString("blurs");
27 }
28
onISize()29 virtual SkISize onISize() {
30 return SkISize::Make(700, 500);
31 }
32
onDraw(SkCanvas * canvas)33 virtual void onDraw(SkCanvas* canvas) {
34 SkBlurStyle NONE = SkBlurStyle(-999);
35 static const struct {
36 SkBlurStyle fStyle;
37 int fCx, fCy;
38 } gRecs[] = {
39 { NONE, 0, 0 },
40 { kInner_SkBlurStyle, -1, 0 },
41 { kNormal_SkBlurStyle, 0, 1 },
42 { kSolid_SkBlurStyle, 0, -1 },
43 { kOuter_SkBlurStyle, 1, 0 },
44 };
45
46 SkPaint paint;
47 paint.setAntiAlias(true);
48 sk_tool_utils::set_portable_typeface(&paint);
49 paint.setTextSize(SkIntToScalar(25));
50 canvas->translate(SkIntToScalar(-40), SkIntToScalar(0));
51
52 SkBlurMaskFilter::BlurFlags flags = SkBlurMaskFilter::kNone_BlurFlag;
53 for (int j = 0; j < 2; j++) {
54 canvas->save();
55 paint.setColor(SK_ColorBLUE);
56 for (size_t i = 0; i < SK_ARRAY_COUNT(gRecs); i++) {
57 if (gRecs[i].fStyle != NONE) {
58 SkMaskFilter* mf = SkBlurMaskFilter::Create(gRecs[i].fStyle,
59 SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(20)),
60 flags);
61 paint.setMaskFilter(mf)->unref();
62 } else {
63 paint.setMaskFilter(NULL);
64 }
65 canvas->drawCircle(SkIntToScalar(200 + gRecs[i].fCx*100),
66 SkIntToScalar(200 + gRecs[i].fCy*100),
67 SkIntToScalar(50),
68 paint);
69 }
70 // draw text
71 {
72 SkMaskFilter* mf = SkBlurMaskFilter::Create(kNormal_SkBlurStyle,
73 SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(4)),
74 flags);
75 paint.setMaskFilter(mf)->unref();
76 SkScalar x = SkIntToScalar(70);
77 SkScalar y = SkIntToScalar(400);
78 paint.setColor(SK_ColorBLACK);
79 canvas->drawText("Hamburgefons Style", 18, x, y, paint);
80 canvas->drawText("Hamburgefons Style", 18,
81 x, y + SkIntToScalar(50), paint);
82 paint.setMaskFilter(NULL);
83 paint.setColor(SK_ColorWHITE);
84 x -= SkIntToScalar(2);
85 y -= SkIntToScalar(2);
86 canvas->drawText("Hamburgefons Style", 18, x, y, paint);
87 }
88 canvas->restore();
89 flags = SkBlurMaskFilter::kHighQuality_BlurFlag;
90 canvas->translate(SkIntToScalar(350), SkIntToScalar(0));
91 }
92 }
93
94 private:
95 typedef GM INHERITED;
96 };
97
98 //////////////////////////////////////////////////////////////////////////////
99
MyFactory(void *)100 static GM* MyFactory(void*) { return new BlursGM; }
101 static GMRegistry reg(MyFactory);
102
103 }
104