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: |
| 21 | virtual SkString onShortName() { |
| 22 | return SkString("blurs"); |
| 23 | } |
| 24 | |
bungeman@google.com | 3c14d0f | 2011-05-20 14:05:03 +0000 | [diff] [blame] | 25 | virtual SkISize onISize() { |
reed@google.com | c96e5c2 | 2011-02-16 21:50:04 +0000 | [diff] [blame] | 26 | return make_isize(700, 500); |
| 27 | } |
| 28 | |
reed@google.com | c96e5c2 | 2011-02-16 21:50:04 +0000 | [diff] [blame] | 29 | virtual void onDraw(SkCanvas* canvas) { |
reed@google.com | c96e5c2 | 2011-02-16 21:50:04 +0000 | [diff] [blame] | 30 | SkBlurMaskFilter::BlurStyle NONE = SkBlurMaskFilter::BlurStyle(-999); |
| 31 | static const struct { |
| 32 | SkBlurMaskFilter::BlurStyle fStyle; |
| 33 | int fCx, fCy; |
| 34 | } gRecs[] = { |
| 35 | { NONE, 0, 0 }, |
| 36 | { SkBlurMaskFilter::kInner_BlurStyle, -1, 0 }, |
| 37 | { SkBlurMaskFilter::kNormal_BlurStyle, 0, 1 }, |
| 38 | { SkBlurMaskFilter::kSolid_BlurStyle, 0, -1 }, |
| 39 | { SkBlurMaskFilter::kOuter_BlurStyle, 1, 0 }, |
| 40 | }; |
| 41 | |
| 42 | SkPaint paint; |
| 43 | paint.setAntiAlias(true); |
bungeman@google.com | 3c14d0f | 2011-05-20 14:05:03 +0000 | [diff] [blame] | 44 | paint.setTextSize(SkIntToScalar(25)); |
| 45 | canvas->translate(SkIntToScalar(-40), SkIntToScalar(0)); |
reed@google.com | c96e5c2 | 2011-02-16 21:50:04 +0000 | [diff] [blame] | 46 | |
| 47 | SkBlurMaskFilter::BlurFlags flags = SkBlurMaskFilter::kNone_BlurFlag; |
| 48 | for (int j = 0; j < 2; j++) { |
| 49 | canvas->save(); |
| 50 | paint.setColor(SK_ColorBLUE); |
| 51 | for (size_t i = 0; i < SK_ARRAY_COUNT(gRecs); i++) { |
| 52 | if (gRecs[i].fStyle != NONE) { |
robertphillips@google.com | b706117 | 2013-09-06 14:16:12 +0000 | [diff] [blame] | 53 | SkMaskFilter* mf = SkBlurMaskFilter::Create(gRecs[i].fStyle, |
| 54 | SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(20)), |
| 55 | flags); |
reed@google.com | c96e5c2 | 2011-02-16 21:50:04 +0000 | [diff] [blame] | 56 | paint.setMaskFilter(mf)->unref(); |
| 57 | } else { |
| 58 | paint.setMaskFilter(NULL); |
| 59 | } |
robertphillips@google.com | 7ce661d | 2013-08-27 16:14:03 +0000 | [diff] [blame] | 60 | canvas->drawCircle(SkIntToScalar(200 + gRecs[i].fCx*100), |
| 61 | SkIntToScalar(200 + gRecs[i].fCy*100), |
| 62 | SkIntToScalar(50), |
| 63 | paint); |
reed@google.com | c96e5c2 | 2011-02-16 21:50:04 +0000 | [diff] [blame] | 64 | } |
| 65 | // draw text |
| 66 | { |
robertphillips@google.com | b706117 | 2013-09-06 14:16:12 +0000 | [diff] [blame] | 67 | SkMaskFilter* mf = SkBlurMaskFilter::Create(SkBlurMaskFilter::kNormal_BlurStyle, |
| 68 | SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(4)), |
| 69 | flags); |
reed@google.com | c96e5c2 | 2011-02-16 21:50:04 +0000 | [diff] [blame] | 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); |
robertphillips@google.com | 7ce661d | 2013-08-27 16:14:03 +0000 | [diff] [blame] | 75 | canvas->drawText("Hamburgefons Style", 18, |
| 76 | x, y + SkIntToScalar(50), paint); |
reed@google.com | c96e5c2 | 2011-02-16 21:50:04 +0000 | [diff] [blame] | 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); |
| 82 | } |
| 83 | canvas->restore(); |
reed@google.com | 11a5ff3 | 2011-02-18 20:20:51 +0000 | [diff] [blame] | 84 | flags = SkBlurMaskFilter::kHighQuality_BlurFlag; |
bungeman@google.com | 3c14d0f | 2011-05-20 14:05:03 +0000 | [diff] [blame] | 85 | canvas->translate(SkIntToScalar(350), SkIntToScalar(0)); |
reed@google.com | c96e5c2 | 2011-02-16 21:50:04 +0000 | [diff] [blame] | 86 | } |
| 87 | } |
| 88 | |
| 89 | private: |
| 90 | typedef GM INHERITED; |
| 91 | }; |
| 92 | |
| 93 | ////////////////////////////////////////////////////////////////////////////// |
| 94 | |
| 95 | static GM* MyFactory(void*) { return new BlursGM; } |
| 96 | static GMRegistry reg(MyFactory); |
| 97 | |
| 98 | } |