2 * Copyright 2011 Google Inc.
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
9 #include "SkBlurMask.h"
10 #include "SkBlurMaskFilter.h"
12 class BlursGM : public skiagm::GM {
15 this->setBGColor(0xFFDDDDDD);
20 SkString onShortName() SK_OVERRIDE {
21 return SkString("blurs");
24 SkISize onISize() SK_OVERRIDE {
25 return SkISize::Make(700, 500);
28 void onDraw(SkCanvas* canvas) SK_OVERRIDE {
29 SkBlurStyle NONE = SkBlurStyle(-999);
35 { kInner_SkBlurStyle, -1, 0 },
36 { kNormal_SkBlurStyle, 0, 1 },
37 { kSolid_SkBlurStyle, 0, -1 },
38 { kOuter_SkBlurStyle, 1, 0 },
42 paint.setAntiAlias(true);
43 sk_tool_utils::set_portable_typeface(&paint);
44 paint.setTextSize(SkIntToScalar(25));
45 canvas->translate(SkIntToScalar(-40), SkIntToScalar(0));
47 SkBlurMaskFilter::BlurFlags flags = SkBlurMaskFilter::kNone_BlurFlag;
48 for (int j = 0; j < 2; j++) {
50 paint.setColor(SK_ColorBLUE);
51 for (size_t i = 0; i < SK_ARRAY_COUNT(gRecs); i++) {
52 if (gRecs[i].fStyle != NONE) {
53 SkMaskFilter* mf = SkBlurMaskFilter::Create(gRecs[i].fStyle,
54 SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(20)),
56 paint.setMaskFilter(mf)->unref();
58 paint.setMaskFilter(NULL);
60 canvas->drawCircle(SkIntToScalar(200 + gRecs[i].fCx*100),
61 SkIntToScalar(200 + gRecs[i].fCy*100),
67 SkMaskFilter* mf = SkBlurMaskFilter::Create(kNormal_SkBlurStyle,
68 SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(4)),
70 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);
75 canvas->drawText("Hamburgefons Style", 18,
76 x, y + SkIntToScalar(50), paint);
77 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);
84 flags = SkBlurMaskFilter::kHighQuality_BlurFlag;
85 canvas->translate(SkIntToScalar(350), SkIntToScalar(0));
90 typedef skiagm::GM INHERITED;
92 DEF_GM( return new BlursGM; )
94 //////////////////////////////////////////////////////////////////////////////////////////////
96 // exercise a special-case of blurs, which is two nested rects. These are drawn specially,
97 // and possibly cached.
99 // in particular, we want to notice that the 2nd rect draws slightly differently, since it
100 // is translated a fractional amount.
102 class Blur2RectsGM : public skiagm::GM {
104 SkString onShortName() SK_OVERRIDE {
105 return SkString("blur2rects");
108 SkISize onISize() SK_OVERRIDE {
109 return SkISize::Make(700, 500);
112 void onDraw(SkCanvas* canvas) SK_OVERRIDE {
115 paint.setMaskFilter(SkBlurMaskFilter::Create(kNormal_SkBlurStyle,
118 SkRect outer = SkRect::MakeXYWH(10.125f, 10.125f, 100.125f, 100);
119 SkRect inner = SkRect::MakeXYWH(20.25f, 20.125f, 80, 80);
121 path.addRect(outer, SkPath::kCW_Direction);
122 path.addRect(inner, SkPath::kCCW_Direction);
124 canvas->drawPath(path, paint);
125 // important to translate by a factional amount to exercise a different "phase"
126 // of the same path w.r.t. the pixel grid
127 SkScalar dx = SkScalarRoundToScalar(path.getBounds().width()) + 14 + 0.25f;
128 canvas->translate(dx, 0);
129 canvas->drawPath(path, paint);
132 DEF_GM( return new Blur2RectsGM; )
134 class Blur2RectsNonNinePatchGM : public skiagm::GM {
136 SkString onShortName() SK_OVERRIDE {
137 return SkString("blur2rectsnonninepatch");
140 SkISize onISize() SK_OVERRIDE {
141 return SkISize::Make(700, 500);
144 void onDraw(SkCanvas* canvas) SK_OVERRIDE {
146 paint.setMaskFilter(SkBlurMaskFilter::Create(kNormal_SkBlurStyle,
149 SkRect outer = SkRect::MakeXYWH(10, 110, 100, 100);
150 SkRect inner = SkRect::MakeXYWH(50, 150, 10, 10);
152 path.addRect(outer, SkPath::kCW_Direction);
153 path.addRect(inner, SkPath::kCW_Direction);
154 canvas->drawPath(path, paint);
156 SkScalar dx = SkScalarRoundToScalar(path.getBounds().width()) + 40 + 0.25f;
157 canvas->translate(dx, 0);
158 canvas->drawPath(path, paint);
160 // Translate to outside of clip bounds.
161 canvas->translate(-dx, 0);
162 canvas->translate(-30, -150);
163 canvas->drawPath(path, paint);
166 DEF_GM( return new Blur2RectsNonNinePatchGM; )