senorblanco@chromium.org | 60014ca | 2011-11-09 16:05:58 +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 | */ |
| 7 | |
| 8 | #include "gm.h" |
| 9 | #include "SkBlurImageFilter.h" |
mtklein@google.com | cfa7ba7 | 2013-09-16 18:19:30 +0000 | [diff] [blame] | 10 | #include "SkRandom.h" |
senorblanco@chromium.org | 60014ca | 2011-11-09 16:05:58 +0000 | [diff] [blame] | 11 | |
senorblanco@chromium.org | 54e01b2 | 2011-11-16 18:20:47 +0000 | [diff] [blame] | 12 | #define WIDTH 500 |
| 13 | #define HEIGHT 500 |
| 14 | |
senorblanco@chromium.org | 60014ca | 2011-11-09 16:05:58 +0000 | [diff] [blame] | 15 | namespace skiagm { |
| 16 | |
| 17 | class ImageBlurGM : public GM { |
| 18 | public: |
commit-bot@chromium.org | c45ece5 | 2014-01-13 08:16:45 +0000 | [diff] [blame] | 19 | ImageBlurGM(SkScalar sigmaX, SkScalar sigmaY, const char* suffix) |
| 20 | : fSigmaX(sigmaX), fSigmaY(sigmaY) { |
senorblanco@chromium.org | 60014ca | 2011-11-09 16:05:58 +0000 | [diff] [blame] | 21 | this->setBGColor(0xFF000000); |
commit-bot@chromium.org | c45ece5 | 2014-01-13 08:16:45 +0000 | [diff] [blame] | 22 | fName.printf("imageblur%s", suffix); |
senorblanco@chromium.org | 60014ca | 2011-11-09 16:05:58 +0000 | [diff] [blame] | 23 | } |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 24 | |
senorblanco@chromium.org | 60014ca | 2011-11-09 16:05:58 +0000 | [diff] [blame] | 25 | protected: |
commit-bot@chromium.org | a90c680 | 2014-04-30 13:20:45 +0000 | [diff] [blame] | 26 | virtual uint32_t onGetFlags() const SK_OVERRIDE { |
| 27 | return kSkipTiled_Flag; |
| 28 | } |
| 29 | |
senorblanco@chromium.org | 60014ca | 2011-11-09 16:05:58 +0000 | [diff] [blame] | 30 | virtual SkString onShortName() { |
commit-bot@chromium.org | c45ece5 | 2014-01-13 08:16:45 +0000 | [diff] [blame] | 31 | return fName; |
senorblanco@chromium.org | 60014ca | 2011-11-09 16:05:58 +0000 | [diff] [blame] | 32 | } |
| 33 | |
| 34 | virtual SkISize onISize() { |
senorblanco@chromium.org | 54e01b2 | 2011-11-16 18:20:47 +0000 | [diff] [blame] | 35 | return make_isize(WIDTH, HEIGHT); |
senorblanco@chromium.org | 60014ca | 2011-11-09 16:05:58 +0000 | [diff] [blame] | 36 | } |
| 37 | |
| 38 | virtual void onDraw(SkCanvas* canvas) { |
| 39 | SkPaint paint; |
commit-bot@chromium.org | cac5fd5 | 2014-03-10 10:51:58 +0000 | [diff] [blame] | 40 | paint.setImageFilter(SkBlurImageFilter::Create(fSigmaX, fSigmaY))->unref(); |
senorblanco@chromium.org | 60014ca | 2011-11-09 16:05:58 +0000 | [diff] [blame] | 41 | canvas->saveLayer(NULL, &paint); |
senorblanco@chromium.org | 60014ca | 2011-11-09 16:05:58 +0000 | [diff] [blame] | 42 | const char* str = "The quick brown fox jumped over the lazy dog."; |
mtklein@google.com | cfa7ba7 | 2013-09-16 18:19:30 +0000 | [diff] [blame] | 43 | |
| 44 | SkRandom rand; |
senorblanco@chromium.org | 1e95d71 | 2012-07-18 19:52:53 +0000 | [diff] [blame] | 45 | SkPaint textPaint; |
| 46 | textPaint.setAntiAlias(true); |
senorblanco@chromium.org | 60014ca | 2011-11-09 16:05:58 +0000 | [diff] [blame] | 47 | for (int i = 0; i < 25; ++i) { |
mtklein@google.com | cfa7ba7 | 2013-09-16 18:19:30 +0000 | [diff] [blame] | 48 | int x = rand.nextULessThan(WIDTH); |
| 49 | int y = rand.nextULessThan(HEIGHT); |
| 50 | textPaint.setColor(rand.nextBits(24) | 0xFF000000); |
mtklein@google.com | 26c6d58 | 2013-09-16 19:05:44 +0000 | [diff] [blame] | 51 | textPaint.setTextSize(rand.nextRangeScalar(0, 300)); |
tomhudson@google.com | 7558925 | 2012-04-10 17:42:21 +0000 | [diff] [blame] | 52 | canvas->drawText(str, strlen(str), SkIntToScalar(x), |
senorblanco@chromium.org | 1e95d71 | 2012-07-18 19:52:53 +0000 | [diff] [blame] | 53 | SkIntToScalar(y), textPaint); |
senorblanco@chromium.org | 60014ca | 2011-11-09 16:05:58 +0000 | [diff] [blame] | 54 | } |
| 55 | canvas->restore(); |
| 56 | } |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 57 | |
senorblanco@chromium.org | 60014ca | 2011-11-09 16:05:58 +0000 | [diff] [blame] | 58 | private: |
commit-bot@chromium.org | c45ece5 | 2014-01-13 08:16:45 +0000 | [diff] [blame] | 59 | SkScalar fSigmaX; |
| 60 | SkScalar fSigmaY; |
| 61 | SkString fName; |
| 62 | |
senorblanco@chromium.org | 60014ca | 2011-11-09 16:05:58 +0000 | [diff] [blame] | 63 | typedef GM INHERITED; |
| 64 | }; |
| 65 | |
| 66 | ////////////////////////////////////////////////////////////////////////////// |
| 67 | |
commit-bot@chromium.org | c45ece5 | 2014-01-13 08:16:45 +0000 | [diff] [blame] | 68 | static GM* MyFactory1(void*) { return new ImageBlurGM(24.0f, 0.0f, ""); } |
| 69 | static GMRegistry reg1(MyFactory1); |
| 70 | |
| 71 | static GM* MyFactory2(void*) { return new ImageBlurGM(80.0f, 80.0f, "_large"); } |
| 72 | static GMRegistry reg2(MyFactory2); |
senorblanco@chromium.org | 60014ca | 2011-11-09 16:05:58 +0000 | [diff] [blame] | 73 | |
| 74 | } |