senorblanco@chromium.org | 897b73f | 2014-02-19 22:10:12 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2014 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" |
senorblanco | 8c874ee | 2015-03-20 06:38:17 -0700 | [diff] [blame] | 9 | #include "SkImageFilter.h" |
senorblanco@chromium.org | 897b73f | 2014-02-19 22:10:12 +0000 | [diff] [blame] | 10 | #include "SkRandom.h" |
| 11 | |
| 12 | #define WIDTH 640 |
| 13 | #define HEIGHT 480 |
| 14 | |
| 15 | #define RESIZE_FACTOR SkIntToScalar(2) |
| 16 | |
halcanary | 2a24338 | 2015-09-09 08:16:41 -0700 | [diff] [blame] | 17 | DEF_SIMPLE_GM(imageresizetiled, canvas, WIDTH, HEIGHT) { |
senorblanco@chromium.org | 897b73f | 2014-02-19 22:10:12 +0000 | [diff] [blame] | 18 | SkPaint paint; |
senorblanco@chromium.org | fd0ec2c | 2014-03-25 17:35:10 +0000 | [diff] [blame] | 19 | SkMatrix matrix; |
| 20 | matrix.setScale(RESIZE_FACTOR, RESIZE_FACTOR); |
robertphillips | ae8c933 | 2016-04-05 15:09:00 -0700 | [diff] [blame] | 21 | paint.setImageFilter(SkImageFilter::MakeMatrixFilter(matrix, |
| 22 | kNone_SkFilterQuality, |
| 23 | nullptr)); |
senorblanco@chromium.org | 897b73f | 2014-02-19 22:10:12 +0000 | [diff] [blame] | 24 | const SkScalar tile_size = SkIntToScalar(100); |
| 25 | SkRect bounds; |
| 26 | canvas->getClipBounds(&bounds); |
| 27 | for (SkScalar y = 0; y < HEIGHT; y += tile_size) { |
| 28 | for (SkScalar x = 0; x < WIDTH; x += tile_size) { |
| 29 | canvas->save(); |
| 30 | canvas->clipRect(SkRect::MakeXYWH(x, y, tile_size, tile_size)); |
| 31 | canvas->scale(SkScalarInvert(RESIZE_FACTOR), |
| 32 | SkScalarInvert(RESIZE_FACTOR)); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 33 | canvas->saveLayer(nullptr, &paint); |
senorblanco@chromium.org | 897b73f | 2014-02-19 22:10:12 +0000 | [diff] [blame] | 34 | const char* str[] = { |
| 35 | "The quick", |
| 36 | "brown fox", |
| 37 | "jumped over", |
| 38 | "the lazy dog.", |
| 39 | }; |
| 40 | SkPaint textPaint; |
| 41 | textPaint.setAntiAlias(true); |
caryclark | 1818acb | 2015-07-24 12:09:25 -0700 | [diff] [blame] | 42 | sk_tool_utils::set_portable_typeface(&textPaint); |
senorblanco@chromium.org | 897b73f | 2014-02-19 22:10:12 +0000 | [diff] [blame] | 43 | textPaint.setTextSize(SkIntToScalar(100)); |
| 44 | int posY = 0; |
| 45 | for (unsigned i = 0; i < SK_ARRAY_COUNT(str); i++) { |
| 46 | posY += 100; |
| 47 | canvas->drawText(str[i], strlen(str[i]), SkIntToScalar(0), |
| 48 | SkIntToScalar(posY), textPaint); |
| 49 | } |
| 50 | canvas->restore(); |
| 51 | canvas->restore(); |
| 52 | } |
| 53 | } |
senorblanco@chromium.org | 897b73f | 2014-02-19 22:10:12 +0000 | [diff] [blame] | 54 | } |