blob: ad363e425d6011fc62033cc777cc0f591c47c891 [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:
commit-bot@chromium.orga90c6802014-04-30 13:20:45 +000021 virtual uint32_t onGetFlags() const SK_OVERRIDE {
22 return kSkipTiled_Flag;
23 }
24
reed@google.comc96e5c22011-02-16 21:50:04 +000025 virtual SkString onShortName() {
26 return SkString("blurs");
27 }
28
bungeman@google.com3c14d0f2011-05-20 14:05:03 +000029 virtual SkISize onISize() {
tfarinaf5393182014-06-09 23:59:03 -070030 return SkISize::Make(700, 500);
reed@google.comc96e5c22011-02-16 21:50:04 +000031 }
32
reed@google.comc96e5c22011-02-16 21:50:04 +000033 virtual void onDraw(SkCanvas* canvas) {
commit-bot@chromium.orge3964552014-04-28 16:25:35 +000034 SkBlurStyle NONE = SkBlurStyle(-999);
reed@google.comc96e5c22011-02-16 21:50:04 +000035 static const struct {
commit-bot@chromium.orge3964552014-04-28 16:25:35 +000036 SkBlurStyle fStyle;
37 int fCx, fCy;
reed@google.comc96e5c22011-02-16 21:50:04 +000038 } gRecs[] = {
commit-bot@chromium.orge3964552014-04-28 16:25:35 +000039 { NONE, 0, 0 },
40 { kInner_SkBlurStyle, -1, 0 },
41 { kNormal_SkBlurStyle, 0, 1 },
42 { kSolid_SkBlurStyle, 0, -1 },
43 { kOuter_SkBlurStyle, 1, 0 },
reed@google.comc96e5c22011-02-16 21:50:04 +000044 };
45
46 SkPaint paint;
47 paint.setAntiAlias(true);
caryclark5fb6bd42014-06-23 11:25:00 -070048 sk_tool_utils::set_portable_typeface(&paint);
bungeman@google.com3c14d0f2011-05-20 14:05:03 +000049 paint.setTextSize(SkIntToScalar(25));
50 canvas->translate(SkIntToScalar(-40), SkIntToScalar(0));
reed@google.comc96e5c22011-02-16 21:50:04 +000051
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) {
robertphillips@google.comb7061172013-09-06 14:16:12 +000058 SkMaskFilter* mf = SkBlurMaskFilter::Create(gRecs[i].fStyle,
59 SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(20)),
60 flags);
reed@google.comc96e5c22011-02-16 21:50:04 +000061 paint.setMaskFilter(mf)->unref();
62 } else {
63 paint.setMaskFilter(NULL);
64 }
robertphillips@google.com7ce661d2013-08-27 16:14:03 +000065 canvas->drawCircle(SkIntToScalar(200 + gRecs[i].fCx*100),
66 SkIntToScalar(200 + gRecs[i].fCy*100),
67 SkIntToScalar(50),
68 paint);
reed@google.comc96e5c22011-02-16 21:50:04 +000069 }
70 // draw text
71 {
commit-bot@chromium.orge3964552014-04-28 16:25:35 +000072 SkMaskFilter* mf = SkBlurMaskFilter::Create(kNormal_SkBlurStyle,
robertphillips@google.comb7061172013-09-06 14:16:12 +000073 SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(4)),
74 flags);
reed@google.comc96e5c22011-02-16 21:50:04 +000075 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);
robertphillips@google.com7ce661d2013-08-27 16:14:03 +000080 canvas->drawText("Hamburgefons Style", 18,
81 x, y + SkIntToScalar(50), paint);
reed@google.comc96e5c22011-02-16 21:50:04 +000082 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();
reed@google.com11a5ff32011-02-18 20:20:51 +000089 flags = SkBlurMaskFilter::kHighQuality_BlurFlag;
bungeman@google.com3c14d0f2011-05-20 14:05:03 +000090 canvas->translate(SkIntToScalar(350), SkIntToScalar(0));
reed@google.comc96e5c22011-02-16 21:50:04 +000091 }
92 }
93
94private:
95 typedef GM INHERITED;
96};
97
98//////////////////////////////////////////////////////////////////////////////
99
100static GM* MyFactory(void*) { return new BlursGM; }
101static GMRegistry reg(MyFactory);
102
103}