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 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 8 | #include "gm/gm.h" |
Ben Wagner | 7fde8e1 | 2019-05-01 17:28:53 -0400 | [diff] [blame] | 9 | #include "include/core/SkCanvas.h" |
| 10 | #include "include/core/SkFilterQuality.h" |
| 11 | #include "include/core/SkFont.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 12 | #include "include/core/SkImageFilter.h" |
Ben Wagner | 7fde8e1 | 2019-05-01 17:28:53 -0400 | [diff] [blame] | 13 | #include "include/core/SkMatrix.h" |
| 14 | #include "include/core/SkPaint.h" |
| 15 | #include "include/core/SkRect.h" |
| 16 | #include "include/core/SkScalar.h" |
| 17 | #include "include/core/SkTypeface.h" |
| 18 | #include "include/core/SkTypes.h" |
Michael Ludwig | 898bbfa | 2019-08-02 15:21:23 -0400 | [diff] [blame] | 19 | #include "include/effects/SkImageFilters.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 20 | #include "tools/ToolUtils.h" |
senorblanco@chromium.org | 897b73f | 2014-02-19 22:10:12 +0000 | [diff] [blame] | 21 | |
| 22 | #define WIDTH 640 |
| 23 | #define HEIGHT 480 |
| 24 | |
| 25 | #define RESIZE_FACTOR SkIntToScalar(2) |
| 26 | |
halcanary | 2a24338 | 2015-09-09 08:16:41 -0700 | [diff] [blame] | 27 | DEF_SIMPLE_GM(imageresizetiled, canvas, WIDTH, HEIGHT) { |
senorblanco@chromium.org | 897b73f | 2014-02-19 22:10:12 +0000 | [diff] [blame] | 28 | SkPaint paint; |
senorblanco@chromium.org | fd0ec2c | 2014-03-25 17:35:10 +0000 | [diff] [blame] | 29 | SkMatrix matrix; |
| 30 | matrix.setScale(RESIZE_FACTOR, RESIZE_FACTOR); |
Michael Ludwig | 898bbfa | 2019-08-02 15:21:23 -0400 | [diff] [blame] | 31 | paint.setImageFilter(SkImageFilters::MatrixTransform(matrix, |
robertphillips | ae8c933 | 2016-04-05 15:09:00 -0700 | [diff] [blame] | 32 | kNone_SkFilterQuality, |
| 33 | nullptr)); |
Hal Canary | 6ac0df8 | 2019-01-07 16:01:22 -0500 | [diff] [blame] | 34 | |
Mike Klein | ea3f014 | 2019-03-20 11:12:10 -0500 | [diff] [blame] | 35 | SkFont font(ToolUtils::create_portable_typeface(), 100); |
senorblanco@chromium.org | 897b73f | 2014-02-19 22:10:12 +0000 | [diff] [blame] | 36 | const SkScalar tile_size = SkIntToScalar(100); |
senorblanco@chromium.org | 897b73f | 2014-02-19 22:10:12 +0000 | [diff] [blame] | 37 | for (SkScalar y = 0; y < HEIGHT; y += tile_size) { |
| 38 | for (SkScalar x = 0; x < WIDTH; x += tile_size) { |
| 39 | canvas->save(); |
| 40 | canvas->clipRect(SkRect::MakeXYWH(x, y, tile_size, tile_size)); |
| 41 | canvas->scale(SkScalarInvert(RESIZE_FACTOR), |
| 42 | SkScalarInvert(RESIZE_FACTOR)); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 43 | canvas->saveLayer(nullptr, &paint); |
senorblanco@chromium.org | 897b73f | 2014-02-19 22:10:12 +0000 | [diff] [blame] | 44 | const char* str[] = { |
| 45 | "The quick", |
| 46 | "brown fox", |
| 47 | "jumped over", |
| 48 | "the lazy dog.", |
| 49 | }; |
Hal Canary | 6ac0df8 | 2019-01-07 16:01:22 -0500 | [diff] [blame] | 50 | float posY = 0; |
senorblanco@chromium.org | 897b73f | 2014-02-19 22:10:12 +0000 | [diff] [blame] | 51 | for (unsigned i = 0; i < SK_ARRAY_COUNT(str); i++) { |
Hal Canary | 6ac0df8 | 2019-01-07 16:01:22 -0500 | [diff] [blame] | 52 | posY += 100.0f; |
| 53 | canvas->drawString(str[i], 0.0f, posY, font, SkPaint()); |
senorblanco@chromium.org | 897b73f | 2014-02-19 22:10:12 +0000 | [diff] [blame] | 54 | } |
| 55 | canvas->restore(); |
| 56 | canvas->restore(); |
| 57 | } |
| 58 | } |
senorblanco@chromium.org | 897b73f | 2014-02-19 22:10:12 +0000 | [diff] [blame] | 59 | } |