| 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 | |
| 11 | namespace skiagm { |
| 12 | |
| 13 | class ImageBlurGM : public GM { |
| 14 | public: |
| 15 | ImageBlurGM() { |
| 16 | this->setBGColor(0xFF000000); |
| 17 | } |
| 18 | |
| 19 | protected: |
| 20 | virtual SkString onShortName() { |
| 21 | return SkString("imageblur"); |
| 22 | } |
| 23 | |
| 24 | virtual SkISize onISize() { |
| 25 | return make_isize(500, 500); |
| 26 | } |
| 27 | |
| 28 | virtual void onDraw(SkCanvas* canvas) { |
| 29 | SkPaint paint; |
| 30 | paint.setImageFilter(new SkBlurImageFilter(24.0f, 0.0f))->unref(); |
| 31 | canvas->saveLayer(NULL, &paint); |
| 32 | paint.setColor(0xFFFFFFFF); |
| 33 | paint.setTextSize(100); |
| 34 | paint.setAntiAlias(true); |
| 35 | const char* str = "The quick brown fox jumped over the lazy dog."; |
| 36 | srand(1234); |
| 37 | SkISize size = canvas->getDeviceSize(); |
| 38 | for (int i = 0; i < 25; ++i) { |
| 39 | int x = rand() % size.fWidth; |
| 40 | int y = rand() % size.fHeight; |
| 41 | paint.setColor(rand() % 0x1000000 | 0xFF000000); |
| 42 | paint.setTextSize(rand() % 300); |
| 43 | canvas->drawText(str, strlen(str), x, y, paint); |
| 44 | } |
| 45 | canvas->restore(); |
| 46 | } |
| 47 | |
| 48 | private: |
| 49 | typedef GM INHERITED; |
| 50 | }; |
| 51 | |
| 52 | ////////////////////////////////////////////////////////////////////////////// |
| 53 | |
| 54 | static GM* MyFactory(void*) { return new ImageBlurGM; } |
| 55 | static GMRegistry reg(MyFactory); |
| 56 | |
| 57 | } |