bsalomon@google.com | 82aa748 | 2012-08-13 14:22:17 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2012 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 "SkMagnifierImageFilter.h" |
| 10 | |
| 11 | #define WIDTH 500 |
| 12 | #define HEIGHT 500 |
| 13 | |
| 14 | namespace skiagm { |
| 15 | |
| 16 | class ImageMagnifierGM : public GM { |
| 17 | public: |
| 18 | ImageMagnifierGM() { |
| 19 | this->setBGColor(0xFF000000); |
| 20 | } |
| 21 | |
| 22 | protected: |
scroggo@google.com | 6325886 | 2012-08-15 16:32:19 +0000 | [diff] [blame] | 23 | virtual uint32_t onGetFlags() const SK_OVERRIDE { |
| 24 | // Skip tiled drawing until https://code.google.com/p/skia/issues/detail?id=781 is fixed. |
| 25 | return this->INHERITED::onGetFlags() | GM::kSkipTiled_Flag; |
| 26 | } |
| 27 | |
| 28 | virtual SkString onShortName() SK_OVERRIDE { |
bsalomon@google.com | 82aa748 | 2012-08-13 14:22:17 +0000 | [diff] [blame] | 29 | return SkString("imagemagnifier"); |
| 30 | } |
| 31 | |
scroggo@google.com | 6325886 | 2012-08-15 16:32:19 +0000 | [diff] [blame] | 32 | virtual SkISize onISize() SK_OVERRIDE { |
bsalomon@google.com | 82aa748 | 2012-08-13 14:22:17 +0000 | [diff] [blame] | 33 | return make_isize(WIDTH, HEIGHT); |
| 34 | } |
| 35 | |
scroggo@google.com | 6325886 | 2012-08-15 16:32:19 +0000 | [diff] [blame] | 36 | virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { |
bsalomon@google.com | 82aa748 | 2012-08-13 14:22:17 +0000 | [diff] [blame] | 37 | SkPaint paint; |
| 38 | paint.setImageFilter( |
| 39 | new SkMagnifierImageFilter( |
| 40 | SkRect::MakeXYWH(SkIntToScalar(125), SkIntToScalar(125), |
| 41 | SkIntToScalar(WIDTH / 2), |
| 42 | SkIntToScalar(HEIGHT / 2)), |
| 43 | 100))->unref(); |
| 44 | canvas->saveLayer(NULL, &paint); |
| 45 | paint.setAntiAlias(true); |
| 46 | const char* str = "The quick brown fox jumped over the lazy dog."; |
| 47 | srand(1234); |
| 48 | for (int i = 0; i < 25; ++i) { |
| 49 | int x = rand() % WIDTH; |
| 50 | int y = rand() % HEIGHT; |
| 51 | paint.setColor(rand() % 0x1000000 | 0xFF000000); |
| 52 | paint.setTextSize(SkIntToScalar(rand() % 300)); |
| 53 | canvas->drawText(str, strlen(str), SkIntToScalar(x), |
| 54 | SkIntToScalar(y), paint); |
| 55 | } |
| 56 | canvas->restore(); |
| 57 | } |
| 58 | |
| 59 | private: |
| 60 | typedef GM INHERITED; |
| 61 | }; |
| 62 | |
| 63 | ////////////////////////////////////////////////////////////////////////////// |
| 64 | |
| 65 | static GM* MyFactory(void*) { return new ImageMagnifierGM; } |
| 66 | static GMRegistry reg(MyFactory); |
| 67 | |
| 68 | } |