epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 1 | |
| 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.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" |
| 11 | |
| 12 | namespace skiagm { |
| 13 | |
| 14 | class BlursGM : public GM { |
| 15 | public: |
bsalomon@google.com | 48dd1a2 | 2011-10-31 14:18:20 +0000 | [diff] [blame] | 16 | BlursGM() { |
| 17 | this->setBGColor(0xFFDDDDDD); |
| 18 | } |
reed@google.com | c96e5c2 | 2011-02-16 21:50:04 +0000 | [diff] [blame] | 19 | |
| 20 | protected: |
commit-bot@chromium.org | a90c680 | 2014-04-30 13:20:45 +0000 | [diff] [blame] | 21 | virtual uint32_t onGetFlags() const SK_OVERRIDE { |
| 22 | return kSkipTiled_Flag; |
| 23 | } |
| 24 | |
reed@google.com | c96e5c2 | 2011-02-16 21:50:04 +0000 | [diff] [blame] | 25 | virtual SkString onShortName() { |
| 26 | return SkString("blurs"); |
| 27 | } |
| 28 | |
bungeman@google.com | 3c14d0f | 2011-05-20 14:05:03 +0000 | [diff] [blame] | 29 | virtual SkISize onISize() { |
tfarina | f539318 | 2014-06-09 23:59:03 -0700 | [diff] [blame] | 30 | return SkISize::Make(700, 500); |
reed@google.com | c96e5c2 | 2011-02-16 21:50:04 +0000 | [diff] [blame] | 31 | } |
| 32 | |
reed@google.com | c96e5c2 | 2011-02-16 21:50:04 +0000 | [diff] [blame] | 33 | virtual void onDraw(SkCanvas* canvas) { |
commit-bot@chromium.org | e396455 | 2014-04-28 16:25:35 +0000 | [diff] [blame] | 34 | SkBlurStyle NONE = SkBlurStyle(-999); |
reed@google.com | c96e5c2 | 2011-02-16 21:50:04 +0000 | [diff] [blame] | 35 | static const struct { |
commit-bot@chromium.org | e396455 | 2014-04-28 16:25:35 +0000 | [diff] [blame] | 36 | SkBlurStyle fStyle; |
| 37 | int fCx, fCy; |
reed@google.com | c96e5c2 | 2011-02-16 21:50:04 +0000 | [diff] [blame] | 38 | } gRecs[] = { |
commit-bot@chromium.org | e396455 | 2014-04-28 16:25:35 +0000 | [diff] [blame] | 39 | { 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.com | c96e5c2 | 2011-02-16 21:50:04 +0000 | [diff] [blame] | 44 | }; |
| 45 | |
| 46 | SkPaint paint; |
| 47 | paint.setAntiAlias(true); |
bungeman@google.com | 3c14d0f | 2011-05-20 14:05:03 +0000 | [diff] [blame] | 48 | paint.setTextSize(SkIntToScalar(25)); |
| 49 | canvas->translate(SkIntToScalar(-40), SkIntToScalar(0)); |
reed@google.com | c96e5c2 | 2011-02-16 21:50:04 +0000 | [diff] [blame] | 50 | |
| 51 | SkBlurMaskFilter::BlurFlags flags = SkBlurMaskFilter::kNone_BlurFlag; |
| 52 | for (int j = 0; j < 2; j++) { |
| 53 | canvas->save(); |
| 54 | paint.setColor(SK_ColorBLUE); |
| 55 | for (size_t i = 0; i < SK_ARRAY_COUNT(gRecs); i++) { |
| 56 | if (gRecs[i].fStyle != NONE) { |
robertphillips@google.com | b706117 | 2013-09-06 14:16:12 +0000 | [diff] [blame] | 57 | SkMaskFilter* mf = SkBlurMaskFilter::Create(gRecs[i].fStyle, |
| 58 | SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(20)), |
| 59 | flags); |
reed@google.com | c96e5c2 | 2011-02-16 21:50:04 +0000 | [diff] [blame] | 60 | paint.setMaskFilter(mf)->unref(); |
| 61 | } else { |
| 62 | paint.setMaskFilter(NULL); |
| 63 | } |
robertphillips@google.com | 7ce661d | 2013-08-27 16:14:03 +0000 | [diff] [blame] | 64 | canvas->drawCircle(SkIntToScalar(200 + gRecs[i].fCx*100), |
| 65 | SkIntToScalar(200 + gRecs[i].fCy*100), |
| 66 | SkIntToScalar(50), |
| 67 | paint); |
reed@google.com | c96e5c2 | 2011-02-16 21:50:04 +0000 | [diff] [blame] | 68 | } |
| 69 | // draw text |
| 70 | { |
commit-bot@chromium.org | e396455 | 2014-04-28 16:25:35 +0000 | [diff] [blame] | 71 | SkMaskFilter* mf = SkBlurMaskFilter::Create(kNormal_SkBlurStyle, |
robertphillips@google.com | b706117 | 2013-09-06 14:16:12 +0000 | [diff] [blame] | 72 | SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(4)), |
| 73 | flags); |
reed@google.com | c96e5c2 | 2011-02-16 21:50:04 +0000 | [diff] [blame] | 74 | paint.setMaskFilter(mf)->unref(); |
| 75 | SkScalar x = SkIntToScalar(70); |
| 76 | SkScalar y = SkIntToScalar(400); |
| 77 | paint.setColor(SK_ColorBLACK); |
| 78 | canvas->drawText("Hamburgefons Style", 18, x, y, paint); |
robertphillips@google.com | 7ce661d | 2013-08-27 16:14:03 +0000 | [diff] [blame] | 79 | canvas->drawText("Hamburgefons Style", 18, |
| 80 | x, y + SkIntToScalar(50), paint); |
reed@google.com | c96e5c2 | 2011-02-16 21:50:04 +0000 | [diff] [blame] | 81 | paint.setMaskFilter(NULL); |
| 82 | paint.setColor(SK_ColorWHITE); |
| 83 | x -= SkIntToScalar(2); |
| 84 | y -= SkIntToScalar(2); |
| 85 | canvas->drawText("Hamburgefons Style", 18, x, y, paint); |
| 86 | } |
| 87 | canvas->restore(); |
reed@google.com | 11a5ff3 | 2011-02-18 20:20:51 +0000 | [diff] [blame] | 88 | flags = SkBlurMaskFilter::kHighQuality_BlurFlag; |
bungeman@google.com | 3c14d0f | 2011-05-20 14:05:03 +0000 | [diff] [blame] | 89 | canvas->translate(SkIntToScalar(350), SkIntToScalar(0)); |
reed@google.com | c96e5c2 | 2011-02-16 21:50:04 +0000 | [diff] [blame] | 90 | } |
| 91 | } |
| 92 | |
| 93 | private: |
| 94 | typedef GM INHERITED; |
| 95 | }; |
| 96 | |
| 97 | ////////////////////////////////////////////////////////////////////////////// |
| 98 | |
| 99 | static GM* MyFactory(void*) { return new BlursGM; } |
| 100 | static GMRegistry reg(MyFactory); |
| 101 | |
| 102 | } |