OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "gm.h" | 8 #include "gm.h" |
9 #include "SkImageFilter.h" | 9 #include "SkImageFilter.h" |
10 #include "SkRandom.h" | 10 #include "SkRandom.h" |
11 | 11 |
12 #define WIDTH 640 | 12 #define WIDTH 640 |
13 #define HEIGHT 480 | 13 #define HEIGHT 480 |
14 | 14 |
15 #define RESIZE_FACTOR SkIntToScalar(2) | 15 #define RESIZE_FACTOR SkIntToScalar(2) |
16 | 16 |
17 DEF_SIMPLE_GM(imageresizetiled, canvas, WIDTH, HEIGHT) { | 17 DEF_SIMPLE_GM(imageresizetiled, canvas, WIDTH, HEIGHT) { |
18 SkPaint paint; | 18 SkPaint paint; |
19 SkMatrix matrix; | 19 SkMatrix matrix; |
20 matrix.setScale(RESIZE_FACTOR, RESIZE_FACTOR); | 20 matrix.setScale(RESIZE_FACTOR, RESIZE_FACTOR); |
21 SkAutoTUnref<SkImageFilter> imageFilter( | 21 paint.setImageFilter(SkImageFilter::MakeMatrixFilter(matrix, |
22 SkImageFilter::CreateMatrixFilter(matrix, kNone_SkFilterQuality)); | 22 kNone_SkFilterQuali
ty, |
23 paint.setImageFilter(imageFilter.get()); | 23 nullptr)); |
24 const SkScalar tile_size = SkIntToScalar(100); | 24 const SkScalar tile_size = SkIntToScalar(100); |
25 SkRect bounds; | 25 SkRect bounds; |
26 canvas->getClipBounds(&bounds); | 26 canvas->getClipBounds(&bounds); |
27 for (SkScalar y = 0; y < HEIGHT; y += tile_size) { | 27 for (SkScalar y = 0; y < HEIGHT; y += tile_size) { |
28 for (SkScalar x = 0; x < WIDTH; x += tile_size) { | 28 for (SkScalar x = 0; x < WIDTH; x += tile_size) { |
29 canvas->save(); | 29 canvas->save(); |
30 canvas->clipRect(SkRect::MakeXYWH(x, y, tile_size, tile_size)); | 30 canvas->clipRect(SkRect::MakeXYWH(x, y, tile_size, tile_size)); |
31 canvas->scale(SkScalarInvert(RESIZE_FACTOR), | 31 canvas->scale(SkScalarInvert(RESIZE_FACTOR), |
32 SkScalarInvert(RESIZE_FACTOR)); | 32 SkScalarInvert(RESIZE_FACTOR)); |
33 canvas->saveLayer(nullptr, &paint); | 33 canvas->saveLayer(nullptr, &paint); |
(...skipping 11 matching lines...) Expand all Loading... |
45 for (unsigned i = 0; i < SK_ARRAY_COUNT(str); i++) { | 45 for (unsigned i = 0; i < SK_ARRAY_COUNT(str); i++) { |
46 posY += 100; | 46 posY += 100; |
47 canvas->drawText(str[i], strlen(str[i]), SkIntToScalar(0), | 47 canvas->drawText(str[i], strlen(str[i]), SkIntToScalar(0), |
48 SkIntToScalar(posY), textPaint); | 48 SkIntToScalar(posY), textPaint); |
49 } | 49 } |
50 canvas->restore(); | 50 canvas->restore(); |
51 canvas->restore(); | 51 canvas->restore(); |
52 } | 52 } |
53 } | 53 } |
54 } | 54 } |
OLD | NEW |