epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 1 | /* |
| 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 | */ |
reed | 36e6e26 | 2014-11-14 08:27:40 -0800 | [diff] [blame] | 7 | |
reed@google.com | c96e5c2 | 2011-02-16 21:50:04 +0000 | [diff] [blame] | 8 | #include "gm.h" |
robertphillips@google.com | b706117 | 2013-09-06 14:16:12 +0000 | [diff] [blame] | 9 | #include "SkBlurMask.h" |
reed@google.com | c96e5c2 | 2011-02-16 21:50:04 +0000 | [diff] [blame] | 10 | #include "SkBlurMaskFilter.h" |
bungeman | d3ebb48 | 2015-08-05 13:57:49 -0700 | [diff] [blame] | 11 | #include "SkPath.h" |
reed@google.com | c96e5c2 | 2011-02-16 21:50:04 +0000 | [diff] [blame] | 12 | |
halcanary | 2a24338 | 2015-09-09 08:16:41 -0700 | [diff] [blame] | 13 | DEF_SIMPLE_GM_BG(blurs, canvas, 700, 500, sk_tool_utils::color_to_565(0xFFDDDDDD)) { |
commit-bot@chromium.org | e396455 | 2014-04-28 16:25:35 +0000 | [diff] [blame] | 14 | SkBlurStyle NONE = SkBlurStyle(-999); |
mtklein | dbfd7ab | 2016-09-01 11:24:54 -0700 | [diff] [blame] | 15 | const struct { |
commit-bot@chromium.org | e396455 | 2014-04-28 16:25:35 +0000 | [diff] [blame] | 16 | SkBlurStyle fStyle; |
| 17 | int fCx, fCy; |
reed@google.com | c96e5c2 | 2011-02-16 21:50:04 +0000 | [diff] [blame] | 18 | } gRecs[] = { |
commit-bot@chromium.org | e396455 | 2014-04-28 16:25:35 +0000 | [diff] [blame] | 19 | { NONE, 0, 0 }, |
| 20 | { kInner_SkBlurStyle, -1, 0 }, |
| 21 | { kNormal_SkBlurStyle, 0, 1 }, |
| 22 | { kSolid_SkBlurStyle, 0, -1 }, |
| 23 | { kOuter_SkBlurStyle, 1, 0 }, |
reed@google.com | c96e5c2 | 2011-02-16 21:50:04 +0000 | [diff] [blame] | 24 | }; |
| 25 | |
| 26 | SkPaint paint; |
| 27 | paint.setAntiAlias(true); |
caryclark | 1818acb | 2015-07-24 12:09:25 -0700 | [diff] [blame] | 28 | sk_tool_utils::set_portable_typeface(&paint); |
bungeman@google.com | 3c14d0f | 2011-05-20 14:05:03 +0000 | [diff] [blame] | 29 | paint.setTextSize(SkIntToScalar(25)); |
| 30 | canvas->translate(SkIntToScalar(-40), SkIntToScalar(0)); |
reed@google.com | c96e5c2 | 2011-02-16 21:50:04 +0000 | [diff] [blame] | 31 | |
| 32 | SkBlurMaskFilter::BlurFlags flags = SkBlurMaskFilter::kNone_BlurFlag; |
| 33 | for (int j = 0; j < 2; j++) { |
| 34 | canvas->save(); |
| 35 | paint.setColor(SK_ColorBLUE); |
| 36 | for (size_t i = 0; i < SK_ARRAY_COUNT(gRecs); i++) { |
| 37 | if (gRecs[i].fStyle != NONE) { |
reed | efdfd51 | 2016-04-04 10:02:58 -0700 | [diff] [blame] | 38 | paint.setMaskFilter(SkBlurMaskFilter::Make(gRecs[i].fStyle, |
robertphillips@google.com | b706117 | 2013-09-06 14:16:12 +0000 | [diff] [blame] | 39 | SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(20)), |
reed | efdfd51 | 2016-04-04 10:02:58 -0700 | [diff] [blame] | 40 | flags)); |
reed@google.com | c96e5c2 | 2011-02-16 21:50:04 +0000 | [diff] [blame] | 41 | } else { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 42 | paint.setMaskFilter(nullptr); |
reed@google.com | c96e5c2 | 2011-02-16 21:50:04 +0000 | [diff] [blame] | 43 | } |
robertphillips@google.com | 7ce661d | 2013-08-27 16:14:03 +0000 | [diff] [blame] | 44 | canvas->drawCircle(SkIntToScalar(200 + gRecs[i].fCx*100), |
| 45 | SkIntToScalar(200 + gRecs[i].fCy*100), |
| 46 | SkIntToScalar(50), |
| 47 | paint); |
reed@google.com | c96e5c2 | 2011-02-16 21:50:04 +0000 | [diff] [blame] | 48 | } |
| 49 | // draw text |
| 50 | { |
reed | efdfd51 | 2016-04-04 10:02:58 -0700 | [diff] [blame] | 51 | paint.setMaskFilter(SkBlurMaskFilter::Make(kNormal_SkBlurStyle, |
robertphillips@google.com | b706117 | 2013-09-06 14:16:12 +0000 | [diff] [blame] | 52 | SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(4)), |
reed | efdfd51 | 2016-04-04 10:02:58 -0700 | [diff] [blame] | 53 | flags)); |
reed@google.com | c96e5c2 | 2011-02-16 21:50:04 +0000 | [diff] [blame] | 54 | SkScalar x = SkIntToScalar(70); |
| 55 | SkScalar y = SkIntToScalar(400); |
| 56 | paint.setColor(SK_ColorBLACK); |
| 57 | canvas->drawText("Hamburgefons Style", 18, x, y, paint); |
robertphillips@google.com | 7ce661d | 2013-08-27 16:14:03 +0000 | [diff] [blame] | 58 | canvas->drawText("Hamburgefons Style", 18, |
| 59 | x, y + SkIntToScalar(50), paint); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 60 | paint.setMaskFilter(nullptr); |
reed@google.com | c96e5c2 | 2011-02-16 21:50:04 +0000 | [diff] [blame] | 61 | paint.setColor(SK_ColorWHITE); |
| 62 | x -= SkIntToScalar(2); |
| 63 | y -= SkIntToScalar(2); |
| 64 | canvas->drawText("Hamburgefons Style", 18, x, y, paint); |
| 65 | } |
| 66 | canvas->restore(); |
reed@google.com | 11a5ff3 | 2011-02-18 20:20:51 +0000 | [diff] [blame] | 67 | flags = SkBlurMaskFilter::kHighQuality_BlurFlag; |
bungeman@google.com | 3c14d0f | 2011-05-20 14:05:03 +0000 | [diff] [blame] | 68 | canvas->translate(SkIntToScalar(350), SkIntToScalar(0)); |
reed@google.com | c96e5c2 | 2011-02-16 21:50:04 +0000 | [diff] [blame] | 69 | } |
halcanary | 2a24338 | 2015-09-09 08:16:41 -0700 | [diff] [blame] | 70 | } |
reed@google.com | c96e5c2 | 2011-02-16 21:50:04 +0000 | [diff] [blame] | 71 | |
reed | 36e6e26 | 2014-11-14 08:27:40 -0800 | [diff] [blame] | 72 | ////////////////////////////////////////////////////////////////////////////////////////////// |
reed@google.com | c96e5c2 | 2011-02-16 21:50:04 +0000 | [diff] [blame] | 73 | |
reed | 36e6e26 | 2014-11-14 08:27:40 -0800 | [diff] [blame] | 74 | // exercise a special-case of blurs, which is two nested rects. These are drawn specially, |
| 75 | // and possibly cached. |
| 76 | // |
| 77 | // in particular, we want to notice that the 2nd rect draws slightly differently, since it |
| 78 | // is translated a fractional amount. |
| 79 | // |
halcanary | 2a24338 | 2015-09-09 08:16:41 -0700 | [diff] [blame] | 80 | DEF_SIMPLE_GM(blur2rects, canvas, 700, 500) { |
reed | 36e6e26 | 2014-11-14 08:27:40 -0800 | [diff] [blame] | 81 | SkPaint paint; |
| 82 | |
reed | efdfd51 | 2016-04-04 10:02:58 -0700 | [diff] [blame] | 83 | paint.setMaskFilter(SkBlurMaskFilter::Make(kNormal_SkBlurStyle, 2.3f)); |
reed | 36e6e26 | 2014-11-14 08:27:40 -0800 | [diff] [blame] | 84 | |
reed | 468b6b4 | 2014-11-17 07:41:35 -0800 | [diff] [blame] | 85 | SkRect outer = SkRect::MakeXYWH(10.125f, 10.125f, 100.125f, 100); |
| 86 | SkRect inner = SkRect::MakeXYWH(20.25f, 20.125f, 80, 80); |
reed | 36e6e26 | 2014-11-14 08:27:40 -0800 | [diff] [blame] | 87 | SkPath path; |
| 88 | path.addRect(outer, SkPath::kCW_Direction); |
| 89 | path.addRect(inner, SkPath::kCCW_Direction); |
| 90 | |
| 91 | canvas->drawPath(path, paint); |
reed | ae760d5 | 2014-11-14 11:59:10 -0800 | [diff] [blame] | 92 | // important to translate by a factional amount to exercise a different "phase" |
reed | 36e6e26 | 2014-11-14 08:27:40 -0800 | [diff] [blame] | 93 | // of the same path w.r.t. the pixel grid |
reed | 468b6b4 | 2014-11-17 07:41:35 -0800 | [diff] [blame] | 94 | SkScalar dx = SkScalarRoundToScalar(path.getBounds().width()) + 14 + 0.25f; |
reed | ae760d5 | 2014-11-14 11:59:10 -0800 | [diff] [blame] | 95 | canvas->translate(dx, 0); |
reed | 36e6e26 | 2014-11-14 08:27:40 -0800 | [diff] [blame] | 96 | canvas->drawPath(path, paint); |
halcanary | 2a24338 | 2015-09-09 08:16:41 -0700 | [diff] [blame] | 97 | } |
qiankun.miao | 28828d0 | 2014-12-10 07:40:36 -0800 | [diff] [blame] | 98 | |
halcanary | 2a24338 | 2015-09-09 08:16:41 -0700 | [diff] [blame] | 99 | DEF_SIMPLE_GM(blur2rectsnonninepatch, canvas, 700, 500) { |
qiankun.miao | 28828d0 | 2014-12-10 07:40:36 -0800 | [diff] [blame] | 100 | SkPaint paint; |
reed | efdfd51 | 2016-04-04 10:02:58 -0700 | [diff] [blame] | 101 | paint.setMaskFilter(SkBlurMaskFilter::Make(kNormal_SkBlurStyle, 4.3f)); |
qiankun.miao | 28828d0 | 2014-12-10 07:40:36 -0800 | [diff] [blame] | 102 | |
| 103 | SkRect outer = SkRect::MakeXYWH(10, 110, 100, 100); |
| 104 | SkRect inner = SkRect::MakeXYWH(50, 150, 10, 10); |
| 105 | SkPath path; |
| 106 | path.addRect(outer, SkPath::kCW_Direction); |
| 107 | path.addRect(inner, SkPath::kCW_Direction); |
| 108 | canvas->drawPath(path, paint); |
| 109 | |
| 110 | SkScalar dx = SkScalarRoundToScalar(path.getBounds().width()) + 40 + 0.25f; |
| 111 | canvas->translate(dx, 0); |
| 112 | canvas->drawPath(path, paint); |
| 113 | |
| 114 | // Translate to outside of clip bounds. |
| 115 | canvas->translate(-dx, 0); |
| 116 | canvas->translate(-30, -150); |
| 117 | canvas->drawPath(path, paint); |
halcanary | 2a24338 | 2015-09-09 08:16:41 -0700 | [diff] [blame] | 118 | } |