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