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 "sk_tool_utils.h"
10 #include "SkBlurMask.h"
11 #include "SkBlurMaskFilter.h"
14 DEF_SIMPLE_GM_BG(blurs, canvas, 700, 500, sk_tool_utils::color_to_565(0xFFDDDDDD)) {
15 SkBlurStyle NONE = SkBlurStyle(-999);
21 { kInner_SkBlurStyle, -1, 0 },
22 { kNormal_SkBlurStyle, 0, 1 },
23 { kSolid_SkBlurStyle, 0, -1 },
24 { kOuter_SkBlurStyle, 1, 0 },
28 paint.setAntiAlias(true);
29 sk_tool_utils::set_portable_typeface(&paint);
30 paint.setTextSize(SkIntToScalar(25));
31 canvas->translate(SkIntToScalar(-40), SkIntToScalar(0));
33 SkBlurMaskFilter::BlurFlags flags = SkBlurMaskFilter::kNone_BlurFlag;
34 for (int j = 0; j < 2; j++) {
36 paint.setColor(SK_ColorBLUE);
37 for (size_t i = 0; i < SK_ARRAY_COUNT(gRecs); i++) {
38 if (gRecs[i].fStyle != NONE) {
39 paint.setMaskFilter(SkBlurMaskFilter::Make(gRecs[i].fStyle,
40 SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(20)),
43 paint.setMaskFilter(nullptr);
45 canvas->drawCircle(SkIntToScalar(200 + gRecs[i].fCx*100),
46 SkIntToScalar(200 + gRecs[i].fCy*100),
52 paint.setMaskFilter(SkBlurMaskFilter::Make(kNormal_SkBlurStyle,
53 SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(4)),
55 SkScalar x = SkIntToScalar(70);
56 SkScalar y = SkIntToScalar(400);
57 paint.setColor(SK_ColorBLACK);
58 canvas->drawString("Hamburgefons Style", x, y, paint);
59 canvas->drawString("Hamburgefons Style",
60 x, y + SkIntToScalar(50), paint);
61 paint.setMaskFilter(nullptr);
62 paint.setColor(SK_ColorWHITE);
63 x -= SkIntToScalar(2);
64 y -= SkIntToScalar(2);
65 canvas->drawString("Hamburgefons Style", x, y, paint);
68 flags = SkBlurMaskFilter::kHighQuality_BlurFlag;
69 canvas->translate(SkIntToScalar(350), SkIntToScalar(0));
73 //////////////////////////////////////////////////////////////////////////////////////////////
75 // exercise a special-case of blurs, which is two nested rects. These are drawn specially,
76 // and possibly cached.
78 // in particular, we want to notice that the 2nd rect draws slightly differently, since it
79 // is translated a fractional amount.
81 DEF_SIMPLE_GM(blur2rects, canvas, 700, 500) {
84 paint.setMaskFilter(SkBlurMaskFilter::Make(kNormal_SkBlurStyle, 2.3f));
86 SkRect outer = SkRect::MakeXYWH(10.125f, 10.125f, 100.125f, 100);
87 SkRect inner = SkRect::MakeXYWH(20.25f, 20.125f, 80, 80);
89 path.addRect(outer, SkPath::kCW_Direction);
90 path.addRect(inner, SkPath::kCCW_Direction);
92 canvas->drawPath(path, paint);
93 // important to translate by a factional amount to exercise a different "phase"
94 // of the same path w.r.t. the pixel grid
95 SkScalar dx = SkScalarRoundToScalar(path.getBounds().width()) + 14 + 0.25f;
96 canvas->translate(dx, 0);
97 canvas->drawPath(path, paint);
100 DEF_SIMPLE_GM(blur2rectsnonninepatch, canvas, 700, 500) {
102 paint.setMaskFilter(SkBlurMaskFilter::Make(kNormal_SkBlurStyle, 4.3f));
104 SkRect outer = SkRect::MakeXYWH(10, 110, 100, 100);
105 SkRect inner = SkRect::MakeXYWH(50, 150, 10, 10);
107 path.addRect(outer, SkPath::kCW_Direction);
108 path.addRect(inner, SkPath::kCW_Direction);
109 canvas->drawPath(path, paint);
111 SkScalar dx = SkScalarRoundToScalar(path.getBounds().width()) + 40 + 0.25f;
112 canvas->translate(dx, 0);
113 canvas->drawPath(path, paint);
115 // Translate to outside of clip bounds.
116 canvas->translate(-dx, 0);
117 canvas->translate(-30, -150);
118 canvas->drawPath(path, paint);