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 | |
halcanary | 2a24338 | 2015-09-09 08:16:41 -0700 | [diff] [blame] | 15 | DEF_SIMPLE_GM_BG(imagemagnifier, canvas, WIDTH, HEIGHT, SK_ColorBLACK) { |
senorblanco | cbf6b6e | 2014-10-23 15:00:10 -0700 | [diff] [blame] | 16 | SkPaint filterPaint; |
| 17 | filterPaint.setImageFilter( |
commit-bot@chromium.org | cac5fd5 | 2014-03-10 10:51:58 +0000 | [diff] [blame] | 18 | SkMagnifierImageFilter::Create( |
commit-bot@chromium.org | f642f8c | 2013-10-21 15:59:26 +0000 | [diff] [blame] | 19 | SkRect::MakeXYWH(SkIntToScalar(100), SkIntToScalar(100), |
bsalomon@google.com | 82aa748 | 2012-08-13 14:22:17 +0000 | [diff] [blame] | 20 | SkIntToScalar(WIDTH / 2), |
| 21 | SkIntToScalar(HEIGHT / 2)), |
| 22 | 100))->unref(); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 23 | canvas->saveLayer(nullptr, &filterPaint); |
bsalomon@google.com | 82aa748 | 2012-08-13 14:22:17 +0000 | [diff] [blame] | 24 | 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] | 25 | SkRandom rand; |
bsalomon@google.com | 82aa748 | 2012-08-13 14:22:17 +0000 | [diff] [blame] | 26 | for (int i = 0; i < 25; ++i) { |
mtklein@google.com | cfa7ba7 | 2013-09-16 18:19:30 +0000 | [diff] [blame] | 27 | int x = rand.nextULessThan(WIDTH); |
| 28 | int y = rand.nextULessThan(HEIGHT); |
senorblanco | cbf6b6e | 2014-10-23 15:00:10 -0700 | [diff] [blame] | 29 | SkPaint paint; |
caryclark | 1818acb | 2015-07-24 12:09:25 -0700 | [diff] [blame] | 30 | sk_tool_utils::set_portable_typeface(&paint); |
caryclark | d2ce185 | 2015-07-16 12:35:58 -0700 | [diff] [blame] | 31 | 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] | 32 | paint.setTextSize(rand.nextRangeScalar(0, 300)); |
senorblanco | cbf6b6e | 2014-10-23 15:00:10 -0700 | [diff] [blame] | 33 | paint.setAntiAlias(true); |
bsalomon@google.com | 82aa748 | 2012-08-13 14:22:17 +0000 | [diff] [blame] | 34 | canvas->drawText(str, strlen(str), SkIntToScalar(x), |
| 35 | SkIntToScalar(y), paint); |
| 36 | } |
| 37 | canvas->restore(); |
bsalomon@google.com | 82aa748 | 2012-08-13 14:22:17 +0000 | [diff] [blame] | 38 | } |