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 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 25 | SkString onShortName() override { |
bsalomon@google.com | 82aa748 | 2012-08-13 14:22:17 +0000 | [diff] [blame] | 26 | return SkString("imagemagnifier"); |
| 27 | } |
| 28 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 29 | SkISize onISize() override { |
tfarina | f539318 | 2014-06-09 23:59:03 -0700 | [diff] [blame] | 30 | return SkISize::Make(WIDTH, HEIGHT); |
bsalomon@google.com | 82aa748 | 2012-08-13 14:22:17 +0000 | [diff] [blame] | 31 | } |
| 32 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 33 | void onDraw(SkCanvas* canvas) override { |
senorblanco | cbf6b6e | 2014-10-23 15:00:10 -0700 | [diff] [blame] | 34 | SkPaint filterPaint; |
| 35 | filterPaint.setImageFilter( |
commit-bot@chromium.org | cac5fd5 | 2014-03-10 10:51:58 +0000 | [diff] [blame] | 36 | SkMagnifierImageFilter::Create( |
commit-bot@chromium.org | f642f8c | 2013-10-21 15:59:26 +0000 | [diff] [blame] | 37 | SkRect::MakeXYWH(SkIntToScalar(100), SkIntToScalar(100), |
bsalomon@google.com | 82aa748 | 2012-08-13 14:22:17 +0000 | [diff] [blame] | 38 | SkIntToScalar(WIDTH / 2), |
| 39 | SkIntToScalar(HEIGHT / 2)), |
| 40 | 100))->unref(); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame^] | 41 | canvas->saveLayer(nullptr, &filterPaint); |
bsalomon@google.com | 82aa748 | 2012-08-13 14:22:17 +0000 | [diff] [blame] | 42 | 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] | 43 | SkRandom rand; |
bsalomon@google.com | 82aa748 | 2012-08-13 14:22:17 +0000 | [diff] [blame] | 44 | for (int i = 0; i < 25; ++i) { |
mtklein@google.com | cfa7ba7 | 2013-09-16 18:19:30 +0000 | [diff] [blame] | 45 | int x = rand.nextULessThan(WIDTH); |
| 46 | int y = rand.nextULessThan(HEIGHT); |
senorblanco | cbf6b6e | 2014-10-23 15:00:10 -0700 | [diff] [blame] | 47 | SkPaint paint; |
caryclark | 1818acb | 2015-07-24 12:09:25 -0700 | [diff] [blame] | 48 | sk_tool_utils::set_portable_typeface(&paint); |
caryclark | d2ce185 | 2015-07-16 12:35:58 -0700 | [diff] [blame] | 49 | paint.setColor(sk_tool_utils::color_to_565(rand.nextBits(24) | 0xFF000000)); |
mtklein@google.com | 26c6d58 | 2013-09-16 19:05:44 +0000 | [diff] [blame] | 50 | paint.setTextSize(rand.nextRangeScalar(0, 300)); |
senorblanco | cbf6b6e | 2014-10-23 15:00:10 -0700 | [diff] [blame] | 51 | paint.setAntiAlias(true); |
bsalomon@google.com | 82aa748 | 2012-08-13 14:22:17 +0000 | [diff] [blame] | 52 | canvas->drawText(str, strlen(str), SkIntToScalar(x), |
| 53 | SkIntToScalar(y), paint); |
| 54 | } |
| 55 | canvas->restore(); |
| 56 | } |
| 57 | |
| 58 | private: |
| 59 | typedef GM INHERITED; |
| 60 | }; |
| 61 | |
| 62 | ////////////////////////////////////////////////////////////////////////////// |
| 63 | |
| 64 | static GM* MyFactory(void*) { return new ImageMagnifierGM; } |
| 65 | static GMRegistry reg(MyFactory); |
| 66 | |
| 67 | } |