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