blob: c2a1c170c77ff4f3589a22ebd58648b8d13af351 [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001
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 */
reed@google.comc96e5c22011-02-16 21:50:04 +00008#include "gm.h"
robertphillips@google.comb7061172013-09-06 14:16:12 +00009#include "SkBlurMask.h"
reed@google.comc96e5c22011-02-16 21:50:04 +000010#include "SkBlurMaskFilter.h"
11
12namespace skiagm {
13
14class BlursGM : public GM {
15public:
bsalomon@google.com48dd1a22011-10-31 14:18:20 +000016 BlursGM() {
17 this->setBGColor(0xFFDDDDDD);
18 }
reed@google.comc96e5c22011-02-16 21:50:04 +000019
20protected:
21 virtual SkString onShortName() {
22 return SkString("blurs");
23 }
24
bungeman@google.com3c14d0f2011-05-20 14:05:03 +000025 virtual SkISize onISize() {
reed@google.comc96e5c22011-02-16 21:50:04 +000026 return make_isize(700, 500);
27 }
28
reed@google.comc96e5c22011-02-16 21:50:04 +000029 virtual void onDraw(SkCanvas* canvas) {
reed@google.comc96e5c22011-02-16 21:50:04 +000030 SkBlurMaskFilter::BlurStyle NONE = SkBlurMaskFilter::BlurStyle(-999);
31 static const struct {
32 SkBlurMaskFilter::BlurStyle fStyle;
33 int fCx, fCy;
34 } gRecs[] = {
35 { NONE, 0, 0 },
36 { SkBlurMaskFilter::kInner_BlurStyle, -1, 0 },
37 { SkBlurMaskFilter::kNormal_BlurStyle, 0, 1 },
38 { SkBlurMaskFilter::kSolid_BlurStyle, 0, -1 },
39 { SkBlurMaskFilter::kOuter_BlurStyle, 1, 0 },
40 };
41
42 SkPaint paint;
43 paint.setAntiAlias(true);
bungeman@google.com3c14d0f2011-05-20 14:05:03 +000044 paint.setTextSize(SkIntToScalar(25));
45 canvas->translate(SkIntToScalar(-40), SkIntToScalar(0));
reed@google.comc96e5c22011-02-16 21:50:04 +000046
47 SkBlurMaskFilter::BlurFlags flags = SkBlurMaskFilter::kNone_BlurFlag;
48 for (int j = 0; j < 2; j++) {
49 canvas->save();
50 paint.setColor(SK_ColorBLUE);
51 for (size_t i = 0; i < SK_ARRAY_COUNT(gRecs); i++) {
52 if (gRecs[i].fStyle != NONE) {
robertphillips@google.comb7061172013-09-06 14:16:12 +000053 SkMaskFilter* mf = SkBlurMaskFilter::Create(gRecs[i].fStyle,
54 SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(20)),
55 flags);
reed@google.comc96e5c22011-02-16 21:50:04 +000056 paint.setMaskFilter(mf)->unref();
57 } else {
58 paint.setMaskFilter(NULL);
59 }
robertphillips@google.com7ce661d2013-08-27 16:14:03 +000060 canvas->drawCircle(SkIntToScalar(200 + gRecs[i].fCx*100),
61 SkIntToScalar(200 + gRecs[i].fCy*100),
62 SkIntToScalar(50),
63 paint);
reed@google.comc96e5c22011-02-16 21:50:04 +000064 }
65 // draw text
66 {
robertphillips@google.comb7061172013-09-06 14:16:12 +000067 SkMaskFilter* mf = SkBlurMaskFilter::Create(SkBlurMaskFilter::kNormal_BlurStyle,
68 SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(4)),
69 flags);
reed@google.comc96e5c22011-02-16 21:50:04 +000070 paint.setMaskFilter(mf)->unref();
71 SkScalar x = SkIntToScalar(70);
72 SkScalar y = SkIntToScalar(400);
73 paint.setColor(SK_ColorBLACK);
74 canvas->drawText("Hamburgefons Style", 18, x, y, paint);
robertphillips@google.com7ce661d2013-08-27 16:14:03 +000075 canvas->drawText("Hamburgefons Style", 18,
76 x, y + SkIntToScalar(50), paint);
reed@google.comc96e5c22011-02-16 21:50:04 +000077 paint.setMaskFilter(NULL);
78 paint.setColor(SK_ColorWHITE);
79 x -= SkIntToScalar(2);
80 y -= SkIntToScalar(2);
81 canvas->drawText("Hamburgefons Style", 18, x, y, paint);
82 }
83 canvas->restore();
reed@google.com11a5ff32011-02-18 20:20:51 +000084 flags = SkBlurMaskFilter::kHighQuality_BlurFlag;
bungeman@google.com3c14d0f2011-05-20 14:05:03 +000085 canvas->translate(SkIntToScalar(350), SkIntToScalar(0));
reed@google.comc96e5c22011-02-16 21:50:04 +000086 }
87 }
88
89private:
90 typedef GM INHERITED;
91};
92
93//////////////////////////////////////////////////////////////////////////////
94
95static GM* MyFactory(void*) { return new BlursGM; }
96static GMRegistry reg(MyFactory);
97
98}