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 | b340cf7 | 2012-06-29 19:25:21 +0000 | [diff] [blame] | 20 | #ifdef SK_SCALAR_IS_FIXED |
scroggo@google.com | 3ab3175 | 2012-06-28 16:09:39 +0000 | [diff] [blame] | 21 | virtual uint32_t onGetFlags() const SK_OVERRIDE { |
scroggo@google.com | b340cf7 | 2012-06-29 19:25:21 +0000 | [diff] [blame] | 22 | // SkCanvas::drawCircle, used by this test, performs a quick reject. |
| 23 | // The large size given to the device used by SkGPipeCanvas means that |
| 24 | // the device clip will not be set properly and circles will be |
| 25 | // rejected when in FIXED. |
scroggo@google.com | 3ab3175 | 2012-06-28 16:09:39 +0000 | [diff] [blame] | 26 | return this->INHERITED::onGetFlags() | GM::kSkipPipe_Flag; |
| 27 | } |
scroggo@google.com | b340cf7 | 2012-06-29 19:25:21 +0000 | [diff] [blame] | 28 | #endif |
scroggo@google.com | 3ab3175 | 2012-06-28 16:09:39 +0000 | [diff] [blame] | 29 | |
reed@google.com | c96e5c2 | 2011-02-16 21:50:04 +0000 | [diff] [blame] | 30 | virtual SkString onShortName() { |
| 31 | return SkString("blurs"); |
| 32 | } |
| 33 | |
bungeman@google.com | 3c14d0f | 2011-05-20 14:05:03 +0000 | [diff] [blame] | 34 | virtual SkISize onISize() { |
reed@google.com | c96e5c2 | 2011-02-16 21:50:04 +0000 | [diff] [blame] | 35 | return make_isize(700, 500); |
| 36 | } |
| 37 | |
reed@google.com | c96e5c2 | 2011-02-16 21:50:04 +0000 | [diff] [blame] | 38 | virtual void onDraw(SkCanvas* canvas) { |
reed@google.com | c96e5c2 | 2011-02-16 21:50:04 +0000 | [diff] [blame] | 39 | SkBlurMaskFilter::BlurStyle NONE = SkBlurMaskFilter::BlurStyle(-999); |
| 40 | static const struct { |
| 41 | SkBlurMaskFilter::BlurStyle fStyle; |
| 42 | int fCx, fCy; |
| 43 | } gRecs[] = { |
| 44 | { NONE, 0, 0 }, |
| 45 | { SkBlurMaskFilter::kInner_BlurStyle, -1, 0 }, |
| 46 | { SkBlurMaskFilter::kNormal_BlurStyle, 0, 1 }, |
| 47 | { SkBlurMaskFilter::kSolid_BlurStyle, 0, -1 }, |
| 48 | { SkBlurMaskFilter::kOuter_BlurStyle, 1, 0 }, |
| 49 | }; |
| 50 | |
| 51 | SkPaint paint; |
| 52 | paint.setAntiAlias(true); |
bungeman@google.com | 3c14d0f | 2011-05-20 14:05:03 +0000 | [diff] [blame] | 53 | paint.setTextSize(SkIntToScalar(25)); |
| 54 | canvas->translate(SkIntToScalar(-40), SkIntToScalar(0)); |
reed@google.com | c96e5c2 | 2011-02-16 21:50:04 +0000 | [diff] [blame] | 55 | |
| 56 | SkBlurMaskFilter::BlurFlags flags = SkBlurMaskFilter::kNone_BlurFlag; |
| 57 | for (int j = 0; j < 2; j++) { |
| 58 | canvas->save(); |
| 59 | paint.setColor(SK_ColorBLUE); |
| 60 | for (size_t i = 0; i < SK_ARRAY_COUNT(gRecs); i++) { |
| 61 | if (gRecs[i].fStyle != NONE) { |
bungeman@google.com | 3c14d0f | 2011-05-20 14:05:03 +0000 | [diff] [blame] | 62 | SkMaskFilter* mf = SkBlurMaskFilter::Create( |
| 63 | SkIntToScalar(20), gRecs[i].fStyle, flags |
| 64 | ); |
reed@google.com | c96e5c2 | 2011-02-16 21:50:04 +0000 | [diff] [blame] | 65 | paint.setMaskFilter(mf)->unref(); |
| 66 | } else { |
| 67 | paint.setMaskFilter(NULL); |
| 68 | } |
bungeman@google.com | 3c14d0f | 2011-05-20 14:05:03 +0000 | [diff] [blame] | 69 | canvas->drawCircle(SkIntToScalar(200 + gRecs[i].fCx*100) |
| 70 | , SkIntToScalar(200 + gRecs[i].fCy*100) |
| 71 | , SkIntToScalar(50) |
| 72 | , paint); |
reed@google.com | c96e5c2 | 2011-02-16 21:50:04 +0000 | [diff] [blame] | 73 | } |
| 74 | // draw text |
| 75 | { |
bungeman@google.com | 3c14d0f | 2011-05-20 14:05:03 +0000 | [diff] [blame] | 76 | SkMaskFilter* mf = SkBlurMaskFilter::Create( |
| 77 | SkIntToScalar(4) |
| 78 | , SkBlurMaskFilter::kNormal_BlurStyle |
| 79 | , flags |
| 80 | ); |
reed@google.com | c96e5c2 | 2011-02-16 21:50:04 +0000 | [diff] [blame] | 81 | paint.setMaskFilter(mf)->unref(); |
| 82 | SkScalar x = SkIntToScalar(70); |
| 83 | SkScalar y = SkIntToScalar(400); |
| 84 | paint.setColor(SK_ColorBLACK); |
| 85 | canvas->drawText("Hamburgefons Style", 18, x, y, paint); |
bungeman@google.com | 3c14d0f | 2011-05-20 14:05:03 +0000 | [diff] [blame] | 86 | canvas->drawText("Hamburgefons Style", 18 |
| 87 | , x, y + SkIntToScalar(50), paint); |
reed@google.com | c96e5c2 | 2011-02-16 21:50:04 +0000 | [diff] [blame] | 88 | paint.setMaskFilter(NULL); |
| 89 | paint.setColor(SK_ColorWHITE); |
| 90 | x -= SkIntToScalar(2); |
| 91 | y -= SkIntToScalar(2); |
| 92 | canvas->drawText("Hamburgefons Style", 18, x, y, paint); |
| 93 | } |
| 94 | canvas->restore(); |
reed@google.com | 11a5ff3 | 2011-02-18 20:20:51 +0000 | [diff] [blame] | 95 | flags = SkBlurMaskFilter::kHighQuality_BlurFlag; |
bungeman@google.com | 3c14d0f | 2011-05-20 14:05:03 +0000 | [diff] [blame] | 96 | canvas->translate(SkIntToScalar(350), SkIntToScalar(0)); |
reed@google.com | c96e5c2 | 2011-02-16 21:50:04 +0000 | [diff] [blame] | 97 | } |
| 98 | } |
| 99 | |
| 100 | private: |
| 101 | typedef GM INHERITED; |
| 102 | }; |
| 103 | |
| 104 | ////////////////////////////////////////////////////////////////////////////// |
| 105 | |
| 106 | static GM* MyFactory(void*) { return new BlursGM; } |
| 107 | static GMRegistry reg(MyFactory); |
| 108 | |
| 109 | } |
| 110 | |