blob: f1f44e72322c768b1386d6bc9fcb53eb07f6eeed [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001/*
2 * Copyright 2011 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
reed36e6e262014-11-14 08:27:40 -08007
reed@google.comc96e5c22011-02-16 21:50:04 +00008#include "gm.h"
Mike Klein33d20552017-03-22 13:47:51 -04009#include "sk_tool_utils.h"
robertphillips@google.comb7061172013-09-06 14:16:12 +000010#include "SkBlurMask.h"
reed@google.comc96e5c22011-02-16 21:50:04 +000011#include "SkBlurMaskFilter.h"
bungemand3ebb482015-08-05 13:57:49 -070012#include "SkPath.h"
reed@google.comc96e5c22011-02-16 21:50:04 +000013
halcanary2a243382015-09-09 08:16:41 -070014DEF_SIMPLE_GM_BG(blurs, canvas, 700, 500, sk_tool_utils::color_to_565(0xFFDDDDDD)) {
commit-bot@chromium.orge3964552014-04-28 16:25:35 +000015 SkBlurStyle NONE = SkBlurStyle(-999);
mtkleindbfd7ab2016-09-01 11:24:54 -070016 const struct {
commit-bot@chromium.orge3964552014-04-28 16:25:35 +000017 SkBlurStyle fStyle;
18 int fCx, fCy;
reed@google.comc96e5c22011-02-16 21:50:04 +000019 } gRecs[] = {
commit-bot@chromium.orge3964552014-04-28 16:25:35 +000020 { NONE, 0, 0 },
21 { kInner_SkBlurStyle, -1, 0 },
22 { kNormal_SkBlurStyle, 0, 1 },
23 { kSolid_SkBlurStyle, 0, -1 },
24 { kOuter_SkBlurStyle, 1, 0 },
reed@google.comc96e5c22011-02-16 21:50:04 +000025 };
26
27 SkPaint paint;
28 paint.setAntiAlias(true);
caryclark1818acb2015-07-24 12:09:25 -070029 sk_tool_utils::set_portable_typeface(&paint);
bungeman@google.com3c14d0f2011-05-20 14:05:03 +000030 paint.setTextSize(SkIntToScalar(25));
31 canvas->translate(SkIntToScalar(-40), SkIntToScalar(0));
reed@google.comc96e5c22011-02-16 21:50:04 +000032
33 SkBlurMaskFilter::BlurFlags flags = SkBlurMaskFilter::kNone_BlurFlag;
34 for (int j = 0; j < 2; j++) {
35 canvas->save();
36 paint.setColor(SK_ColorBLUE);
37 for (size_t i = 0; i < SK_ARRAY_COUNT(gRecs); i++) {
38 if (gRecs[i].fStyle != NONE) {
reedefdfd512016-04-04 10:02:58 -070039 paint.setMaskFilter(SkBlurMaskFilter::Make(gRecs[i].fStyle,
robertphillips@google.comb7061172013-09-06 14:16:12 +000040 SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(20)),
reedefdfd512016-04-04 10:02:58 -070041 flags));
reed@google.comc96e5c22011-02-16 21:50:04 +000042 } else {
halcanary96fcdcc2015-08-27 07:41:13 -070043 paint.setMaskFilter(nullptr);
reed@google.comc96e5c22011-02-16 21:50:04 +000044 }
robertphillips@google.com7ce661d2013-08-27 16:14:03 +000045 canvas->drawCircle(SkIntToScalar(200 + gRecs[i].fCx*100),
46 SkIntToScalar(200 + gRecs[i].fCy*100),
47 SkIntToScalar(50),
48 paint);
reed@google.comc96e5c22011-02-16 21:50:04 +000049 }
50 // draw text
51 {
reedefdfd512016-04-04 10:02:58 -070052 paint.setMaskFilter(SkBlurMaskFilter::Make(kNormal_SkBlurStyle,
robertphillips@google.comb7061172013-09-06 14:16:12 +000053 SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(4)),
reedefdfd512016-04-04 10:02:58 -070054 flags));
reed@google.comc96e5c22011-02-16 21:50:04 +000055 SkScalar x = SkIntToScalar(70);
56 SkScalar y = SkIntToScalar(400);
57 paint.setColor(SK_ColorBLACK);
58 canvas->drawText("Hamburgefons Style", 18, x, y, paint);
robertphillips@google.com7ce661d2013-08-27 16:14:03 +000059 canvas->drawText("Hamburgefons Style", 18,
60 x, y + SkIntToScalar(50), paint);
halcanary96fcdcc2015-08-27 07:41:13 -070061 paint.setMaskFilter(nullptr);
reed@google.comc96e5c22011-02-16 21:50:04 +000062 paint.setColor(SK_ColorWHITE);
63 x -= SkIntToScalar(2);
64 y -= SkIntToScalar(2);
65 canvas->drawText("Hamburgefons Style", 18, x, y, paint);
66 }
67 canvas->restore();
reed@google.com11a5ff32011-02-18 20:20:51 +000068 flags = SkBlurMaskFilter::kHighQuality_BlurFlag;
bungeman@google.com3c14d0f2011-05-20 14:05:03 +000069 canvas->translate(SkIntToScalar(350), SkIntToScalar(0));
reed@google.comc96e5c22011-02-16 21:50:04 +000070 }
halcanary2a243382015-09-09 08:16:41 -070071}
reed@google.comc96e5c22011-02-16 21:50:04 +000072
reed36e6e262014-11-14 08:27:40 -080073//////////////////////////////////////////////////////////////////////////////////////////////
reed@google.comc96e5c22011-02-16 21:50:04 +000074
reed36e6e262014-11-14 08:27:40 -080075// exercise a special-case of blurs, which is two nested rects. These are drawn specially,
76// and possibly cached.
77//
78// in particular, we want to notice that the 2nd rect draws slightly differently, since it
79// is translated a fractional amount.
80//
halcanary2a243382015-09-09 08:16:41 -070081DEF_SIMPLE_GM(blur2rects, canvas, 700, 500) {
reed36e6e262014-11-14 08:27:40 -080082 SkPaint paint;
83
reedefdfd512016-04-04 10:02:58 -070084 paint.setMaskFilter(SkBlurMaskFilter::Make(kNormal_SkBlurStyle, 2.3f));
reed36e6e262014-11-14 08:27:40 -080085
reed468b6b42014-11-17 07:41:35 -080086 SkRect outer = SkRect::MakeXYWH(10.125f, 10.125f, 100.125f, 100);
87 SkRect inner = SkRect::MakeXYWH(20.25f, 20.125f, 80, 80);
reed36e6e262014-11-14 08:27:40 -080088 SkPath path;
89 path.addRect(outer, SkPath::kCW_Direction);
90 path.addRect(inner, SkPath::kCCW_Direction);
91
92 canvas->drawPath(path, paint);
reedae760d52014-11-14 11:59:10 -080093 // important to translate by a factional amount to exercise a different "phase"
reed36e6e262014-11-14 08:27:40 -080094 // of the same path w.r.t. the pixel grid
reed468b6b42014-11-17 07:41:35 -080095 SkScalar dx = SkScalarRoundToScalar(path.getBounds().width()) + 14 + 0.25f;
reedae760d52014-11-14 11:59:10 -080096 canvas->translate(dx, 0);
reed36e6e262014-11-14 08:27:40 -080097 canvas->drawPath(path, paint);
halcanary2a243382015-09-09 08:16:41 -070098}
qiankun.miao28828d02014-12-10 07:40:36 -080099
halcanary2a243382015-09-09 08:16:41 -0700100DEF_SIMPLE_GM(blur2rectsnonninepatch, canvas, 700, 500) {
qiankun.miao28828d02014-12-10 07:40:36 -0800101 SkPaint paint;
reedefdfd512016-04-04 10:02:58 -0700102 paint.setMaskFilter(SkBlurMaskFilter::Make(kNormal_SkBlurStyle, 4.3f));
qiankun.miao28828d02014-12-10 07:40:36 -0800103
104 SkRect outer = SkRect::MakeXYWH(10, 110, 100, 100);
105 SkRect inner = SkRect::MakeXYWH(50, 150, 10, 10);
106 SkPath path;
107 path.addRect(outer, SkPath::kCW_Direction);
108 path.addRect(inner, SkPath::kCW_Direction);
109 canvas->drawPath(path, paint);
110
111 SkScalar dx = SkScalarRoundToScalar(path.getBounds().width()) + 40 + 0.25f;
112 canvas->translate(dx, 0);
113 canvas->drawPath(path, paint);
114
115 // Translate to outside of clip bounds.
116 canvas->translate(-dx, 0);
117 canvas->translate(-30, -150);
118 canvas->drawPath(path, paint);
halcanary2a243382015-09-09 08:16:41 -0700119}