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 | |
| 17 | namespace skiagm { |
| 18 | |
| 19 | class ImageResizeTiledGM : public GM { |
| 20 | public: |
| 21 | ImageResizeTiledGM() { |
| 22 | } |
| 23 | |
| 24 | protected: |
mtklein | e4636aa | 2014-07-09 13:10:58 -0700 | [diff] [blame] | 25 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 26 | SkString onShortName() override { |
senorblanco@chromium.org | 897b73f | 2014-02-19 22:10:12 +0000 | [diff] [blame] | 27 | return SkString("imageresizetiled"); |
| 28 | } |
| 29 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 30 | SkISize onISize() override { |
tfarina | f539318 | 2014-06-09 23:59:03 -0700 | [diff] [blame] | 31 | return SkISize::Make(WIDTH, HEIGHT); |
senorblanco@chromium.org | 897b73f | 2014-02-19 22:10:12 +0000 | [diff] [blame] | 32 | } |
| 33 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 34 | void onDraw(SkCanvas* canvas) override { |
senorblanco@chromium.org | 897b73f | 2014-02-19 22:10:12 +0000 | [diff] [blame] | 35 | SkPaint paint; |
senorblanco@chromium.org | fd0ec2c | 2014-03-25 17:35:10 +0000 | [diff] [blame] | 36 | SkMatrix matrix; |
| 37 | matrix.setScale(RESIZE_FACTOR, RESIZE_FACTOR); |
senorblanco@chromium.org | 897b73f | 2014-02-19 22:10:12 +0000 | [diff] [blame] | 38 | SkAutoTUnref<SkImageFilter> imageFilter( |
senorblanco | 8c874ee | 2015-03-20 06:38:17 -0700 | [diff] [blame] | 39 | SkImageFilter::CreateMatrixFilter(matrix, kNone_SkFilterQuality)); |
senorblanco@chromium.org | 897b73f | 2014-02-19 22:10:12 +0000 | [diff] [blame] | 40 | paint.setImageFilter(imageFilter.get()); |
| 41 | const SkScalar tile_size = SkIntToScalar(100); |
| 42 | SkRect bounds; |
| 43 | canvas->getClipBounds(&bounds); |
| 44 | for (SkScalar y = 0; y < HEIGHT; y += tile_size) { |
| 45 | for (SkScalar x = 0; x < WIDTH; x += tile_size) { |
| 46 | canvas->save(); |
| 47 | canvas->clipRect(SkRect::MakeXYWH(x, y, tile_size, tile_size)); |
| 48 | canvas->scale(SkScalarInvert(RESIZE_FACTOR), |
| 49 | SkScalarInvert(RESIZE_FACTOR)); |
| 50 | canvas->saveLayer(NULL, &paint); |
| 51 | const char* str[] = { |
| 52 | "The quick", |
| 53 | "brown fox", |
| 54 | "jumped over", |
| 55 | "the lazy dog.", |
| 56 | }; |
| 57 | SkPaint textPaint; |
| 58 | textPaint.setAntiAlias(true); |
Cary Clark | 992c7b0 | 2014-07-31 08:58:44 -0400 | [diff] [blame] | 59 | sk_tool_utils::set_portable_typeface(&textPaint); |
senorblanco@chromium.org | 897b73f | 2014-02-19 22:10:12 +0000 | [diff] [blame] | 60 | textPaint.setTextSize(SkIntToScalar(100)); |
| 61 | int posY = 0; |
| 62 | for (unsigned i = 0; i < SK_ARRAY_COUNT(str); i++) { |
| 63 | posY += 100; |
| 64 | canvas->drawText(str[i], strlen(str[i]), SkIntToScalar(0), |
| 65 | SkIntToScalar(posY), textPaint); |
| 66 | } |
| 67 | canvas->restore(); |
| 68 | canvas->restore(); |
| 69 | } |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | private: |
| 74 | typedef GM INHERITED; |
| 75 | }; |
| 76 | |
| 77 | ////////////////////////////////////////////////////////////////////////////// |
| 78 | |
| 79 | DEF_GM(return new ImageResizeTiledGM(); ) |
| 80 | |
| 81 | } |