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 "SkResizeImageFilter.h" | 9 #include "SkMatrixImageFilter.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 namespace skiagm { | 17 namespace skiagm { |
18 | 18 |
19 class ImageResizeTiledGM : public GM { | 19 class ImageResizeTiledGM : public GM { |
20 public: | 20 public: |
21 ImageResizeTiledGM() { | 21 ImageResizeTiledGM() { |
22 } | 22 } |
23 | 23 |
24 protected: | 24 protected: |
25 virtual SkString onShortName() SK_OVERRIDE { | 25 virtual SkString onShortName() SK_OVERRIDE { |
26 return SkString("imageresizetiled"); | 26 return SkString("imageresizetiled"); |
27 } | 27 } |
28 | 28 |
29 virtual SkISize onISize() SK_OVERRIDE { | 29 virtual SkISize onISize() SK_OVERRIDE { |
30 return make_isize(WIDTH, HEIGHT); | 30 return make_isize(WIDTH, HEIGHT); |
31 } | 31 } |
32 | 32 |
33 virtual uint32_t onGetFlags() const SK_OVERRIDE { | 33 virtual uint32_t onGetFlags() const SK_OVERRIDE { |
34 return kSkipTiled_Flag; | 34 return kSkipTiled_Flag; |
35 } | 35 } |
36 | 36 |
37 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { | 37 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { |
38 SkPaint paint; | 38 SkPaint paint; |
| 39 SkMatrix matrix; |
| 40 matrix.setScale(RESIZE_FACTOR, RESIZE_FACTOR); |
39 SkAutoTUnref<SkImageFilter> imageFilter( | 41 SkAutoTUnref<SkImageFilter> imageFilter( |
40 SkResizeImageFilter::Create(RESIZE_FACTOR, RESIZE_FACTOR, SkPaint::k
None_FilterLevel)); | 42 SkMatrixImageFilter::Create(matrix, SkPaint::kNone_FilterLevel)); |
41 paint.setImageFilter(imageFilter.get()); | 43 paint.setImageFilter(imageFilter.get()); |
42 const SkScalar tile_size = SkIntToScalar(100); | 44 const SkScalar tile_size = SkIntToScalar(100); |
43 SkRect bounds; | 45 SkRect bounds; |
44 canvas->getClipBounds(&bounds); | 46 canvas->getClipBounds(&bounds); |
45 for (SkScalar y = 0; y < HEIGHT; y += tile_size) { | 47 for (SkScalar y = 0; y < HEIGHT; y += tile_size) { |
46 for (SkScalar x = 0; x < WIDTH; x += tile_size) { | 48 for (SkScalar x = 0; x < WIDTH; x += tile_size) { |
47 canvas->save(); | 49 canvas->save(); |
48 canvas->clipRect(SkRect::MakeXYWH(x, y, tile_size, tile_size)); | 50 canvas->clipRect(SkRect::MakeXYWH(x, y, tile_size, tile_size)); |
49 canvas->scale(SkScalarInvert(RESIZE_FACTOR), | 51 canvas->scale(SkScalarInvert(RESIZE_FACTOR), |
50 SkScalarInvert(RESIZE_FACTOR)); | 52 SkScalarInvert(RESIZE_FACTOR)); |
(...skipping 21 matching lines...) Expand all Loading... |
72 | 74 |
73 private: | 75 private: |
74 typedef GM INHERITED; | 76 typedef GM INHERITED; |
75 }; | 77 }; |
76 | 78 |
77 ////////////////////////////////////////////////////////////////////////////// | 79 ////////////////////////////////////////////////////////////////////////////// |
78 | 80 |
79 DEF_GM(return new ImageResizeTiledGM(); ) | 81 DEF_GM(return new ImageResizeTiledGM(); ) |
80 | 82 |
81 } | 83 } |
OLD | NEW |