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: |
| 19 | ImageBlurGM() { |
| 20 | this->setBGColor(0xFF000000); |
| 21 | } |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 22 | |
senorblanco@chromium.org | 60014ca | 2011-11-09 16:05:58 +0000 | [diff] [blame] | 23 | protected: |
| 24 | virtual SkString onShortName() { |
| 25 | return SkString("imageblur"); |
| 26 | } |
| 27 | |
| 28 | virtual SkISize onISize() { |
senorblanco@chromium.org | 54e01b2 | 2011-11-16 18:20:47 +0000 | [diff] [blame] | 29 | return make_isize(WIDTH, HEIGHT); |
senorblanco@chromium.org | 60014ca | 2011-11-09 16:05:58 +0000 | [diff] [blame] | 30 | } |
| 31 | |
| 32 | virtual void onDraw(SkCanvas* canvas) { |
| 33 | SkPaint paint; |
| 34 | paint.setImageFilter(new SkBlurImageFilter(24.0f, 0.0f))->unref(); |
| 35 | canvas->saveLayer(NULL, &paint); |
senorblanco@chromium.org | 60014ca | 2011-11-09 16:05:58 +0000 | [diff] [blame] | 36 | 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] | 37 | |
| 38 | SkRandom rand; |
senorblanco@chromium.org | 1e95d71 | 2012-07-18 19:52:53 +0000 | [diff] [blame] | 39 | SkPaint textPaint; |
| 40 | textPaint.setAntiAlias(true); |
senorblanco@chromium.org | 60014ca | 2011-11-09 16:05:58 +0000 | [diff] [blame] | 41 | for (int i = 0; i < 25; ++i) { |
mtklein@google.com | cfa7ba7 | 2013-09-16 18:19:30 +0000 | [diff] [blame] | 42 | int x = rand.nextULessThan(WIDTH); |
| 43 | int y = rand.nextULessThan(HEIGHT); |
| 44 | textPaint.setColor(rand.nextBits(24) | 0xFF000000); |
mtklein@google.com | 26c6d58 | 2013-09-16 19:05:44 +0000 | [diff] [blame] | 45 | textPaint.setTextSize(rand.nextRangeScalar(0, 300)); |
tomhudson@google.com | 7558925 | 2012-04-10 17:42:21 +0000 | [diff] [blame] | 46 | canvas->drawText(str, strlen(str), SkIntToScalar(x), |
senorblanco@chromium.org | 1e95d71 | 2012-07-18 19:52:53 +0000 | [diff] [blame] | 47 | SkIntToScalar(y), textPaint); |
senorblanco@chromium.org | 60014ca | 2011-11-09 16:05:58 +0000 | [diff] [blame] | 48 | } |
| 49 | canvas->restore(); |
| 50 | } |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 51 | |
senorblanco@chromium.org | 60014ca | 2011-11-09 16:05:58 +0000 | [diff] [blame] | 52 | private: |
| 53 | typedef GM INHERITED; |
| 54 | }; |
| 55 | |
| 56 | ////////////////////////////////////////////////////////////////////////////// |
| 57 | |
| 58 | static GM* MyFactory(void*) { return new ImageBlurGM; } |
| 59 | static GMRegistry reg(MyFactory); |
| 60 | |
| 61 | } |