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" |
mtklein@google.com | cfa7ba7 | 2013-09-16 18:19:30 +0000 | [diff] [blame] | 10 | #include "SkRandom.h" |
bsalomon@google.com | 82aa748 | 2012-08-13 14:22:17 +0000 | [diff] [blame] | 11 | |
| 12 | #define WIDTH 500 |
| 13 | #define HEIGHT 500 |
| 14 | |
| 15 | namespace skiagm { |
| 16 | |
| 17 | class ImageMagnifierGM : public GM { |
| 18 | public: |
| 19 | ImageMagnifierGM() { |
| 20 | this->setBGColor(0xFF000000); |
| 21 | } |
| 22 | |
| 23 | protected: |
scroggo@google.com | 6325886 | 2012-08-15 16:32:19 +0000 | [diff] [blame] | 24 | virtual uint32_t onGetFlags() const SK_OVERRIDE { |
| 25 | // Skip tiled drawing until https://code.google.com/p/skia/issues/detail?id=781 is fixed. |
| 26 | return this->INHERITED::onGetFlags() | GM::kSkipTiled_Flag; |
| 27 | } |
| 28 | |
| 29 | virtual SkString onShortName() SK_OVERRIDE { |
bsalomon@google.com | 82aa748 | 2012-08-13 14:22:17 +0000 | [diff] [blame] | 30 | return SkString("imagemagnifier"); |
| 31 | } |
| 32 | |
scroggo@google.com | 6325886 | 2012-08-15 16:32:19 +0000 | [diff] [blame] | 33 | virtual SkISize onISize() SK_OVERRIDE { |
tfarina | f539318 | 2014-06-09 23:59:03 -0700 | [diff] [blame] | 34 | return SkISize::Make(WIDTH, HEIGHT); |
bsalomon@google.com | 82aa748 | 2012-08-13 14:22:17 +0000 | [diff] [blame] | 35 | } |
| 36 | |
scroggo@google.com | 6325886 | 2012-08-15 16:32:19 +0000 | [diff] [blame] | 37 | virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { |
senorblanco | cbf6b6e | 2014-10-23 15:00:10 -0700 | [diff] [blame] | 38 | SkPaint filterPaint; |
| 39 | filterPaint.setImageFilter( |
commit-bot@chromium.org | cac5fd5 | 2014-03-10 10:51:58 +0000 | [diff] [blame] | 40 | SkMagnifierImageFilter::Create( |
commit-bot@chromium.org | f642f8c | 2013-10-21 15:59:26 +0000 | [diff] [blame] | 41 | SkRect::MakeXYWH(SkIntToScalar(100), SkIntToScalar(100), |
bsalomon@google.com | 82aa748 | 2012-08-13 14:22:17 +0000 | [diff] [blame] | 42 | SkIntToScalar(WIDTH / 2), |
| 43 | SkIntToScalar(HEIGHT / 2)), |
| 44 | 100))->unref(); |
senorblanco | cbf6b6e | 2014-10-23 15:00:10 -0700 | [diff] [blame] | 45 | canvas->saveLayer(NULL, &filterPaint); |
bsalomon@google.com | 82aa748 | 2012-08-13 14:22:17 +0000 | [diff] [blame] | 46 | 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] | 47 | SkRandom rand; |
bsalomon@google.com | 82aa748 | 2012-08-13 14:22:17 +0000 | [diff] [blame] | 48 | for (int i = 0; i < 25; ++i) { |
mtklein@google.com | cfa7ba7 | 2013-09-16 18:19:30 +0000 | [diff] [blame] | 49 | int x = rand.nextULessThan(WIDTH); |
| 50 | int y = rand.nextULessThan(HEIGHT); |
senorblanco | cbf6b6e | 2014-10-23 15:00:10 -0700 | [diff] [blame] | 51 | SkPaint paint; |
| 52 | sk_tool_utils::set_portable_typeface(&paint); |
mtklein@google.com | cfa7ba7 | 2013-09-16 18:19:30 +0000 | [diff] [blame] | 53 | paint.setColor(rand.nextBits(24) | 0xFF000000); |
mtklein@google.com | 26c6d58 | 2013-09-16 19:05:44 +0000 | [diff] [blame] | 54 | paint.setTextSize(rand.nextRangeScalar(0, 300)); |
senorblanco | cbf6b6e | 2014-10-23 15:00:10 -0700 | [diff] [blame] | 55 | paint.setAntiAlias(true); |
bsalomon@google.com | 82aa748 | 2012-08-13 14:22:17 +0000 | [diff] [blame] | 56 | canvas->drawText(str, strlen(str), SkIntToScalar(x), |
| 57 | SkIntToScalar(y), paint); |
| 58 | } |
| 59 | canvas->restore(); |
| 60 | } |
| 61 | |
| 62 | private: |
| 63 | typedef GM INHERITED; |
| 64 | }; |
| 65 | |
| 66 | ////////////////////////////////////////////////////////////////////////////// |
| 67 | |
| 68 | static GM* MyFactory(void*) { return new ImageMagnifierGM; } |
| 69 | static GMRegistry reg(MyFactory); |
| 70 | |
| 71 | } |