OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 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 "SkOffsetImageFilter.h" | 9 #include "SkOffsetImageFilter.h" |
10 #include "SkBitmapSource.h" | 10 #include "SkBitmapSource.h" |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 } | 63 } |
64 } | 64 } |
65 | 65 |
66 virtual SkISize onISize() { | 66 virtual SkISize onISize() { |
67 return make_isize(WIDTH, HEIGHT); | 67 return make_isize(WIDTH, HEIGHT); |
68 } | 68 } |
69 | 69 |
70 void drawClippedBitmap(SkCanvas* canvas, const SkBitmap& bitmap, const SkPai
nt& paint, | 70 void drawClippedBitmap(SkCanvas* canvas, const SkBitmap& bitmap, const SkPai
nt& paint, |
71 SkScalar x, SkScalar y) { | 71 SkScalar x, SkScalar y) { |
72 canvas->save(); | 72 canvas->save(); |
73 canvas->clipRect(SkRect::MakeXYWH(x, y, | 73 canvas->translate(x, y); |
| 74 canvas->clipRect(SkRect::MakeXYWH(0, 0, |
74 SkIntToScalar(bitmap.width()), SkIntToScalar(bitmap.height()))); | 75 SkIntToScalar(bitmap.width()), SkIntToScalar(bitmap.height()))); |
75 canvas->drawBitmap(bitmap, x, y, &paint); | 76 canvas->drawBitmap(bitmap, 0, 0, &paint); |
76 canvas->restore(); | 77 canvas->restore(); |
77 } | 78 } |
78 | 79 |
79 virtual void onDraw(SkCanvas* canvas) { | 80 virtual void onDraw(SkCanvas* canvas) { |
80 if (!fInitialized) { | 81 if (!fInitialized) { |
81 make_bitmap(); | 82 make_bitmap(); |
82 make_checkerboard(); | 83 make_checkerboard(); |
83 fInitialized = true; | 84 fInitialized = true; |
84 } | 85 } |
85 canvas->clear(0x00000000); | 86 canvas->clear(0x00000000); |
86 SkPaint paint; | 87 SkPaint paint; |
87 | 88 |
88 int x = 0, y = 0; | 89 int x = 0, y = 0; |
89 for (size_t i = 0; i < 4; i++) { | 90 for (size_t i = 0; i < 4; i++) { |
90 SkBitmap* bitmap = (i & 0x01) ? &fCheckerboard : &fBitmap; | 91 SkBitmap* bitmap = (i & 0x01) ? &fCheckerboard : &fBitmap; |
91 SkIRect cropRect = SkIRect::MakeXYWH(x + i * 12, | 92 SkIRect cropRect = SkIRect::MakeXYWH(i * 12, |
92 y + i * 8, | 93 i * 8, |
93 bitmap->width() - i * 8, | 94 bitmap->width() - i * 8, |
94 bitmap->height() - i * 12); | 95 bitmap->height() - i * 12); |
95 SkImageFilter::CropRect rect(SkRect::Make(cropRect)); | 96 SkImageFilter::CropRect rect(SkRect::Make(cropRect)); |
96 SkAutoTUnref<SkImageFilter> tileInput(SkNEW_ARGS(SkBitmapSource, (*b
itmap))); | 97 SkAutoTUnref<SkImageFilter> tileInput(SkNEW_ARGS(SkBitmapSource, (*b
itmap))); |
97 SkScalar dx = SkIntToScalar(i*5); | 98 SkScalar dx = SkIntToScalar(i*5); |
98 SkScalar dy = SkIntToScalar(i*10); | 99 SkScalar dy = SkIntToScalar(i*10); |
99 SkAutoTUnref<SkImageFilter> filter(SkNEW_ARGS( | 100 SkAutoTUnref<SkImageFilter> filter(SkNEW_ARGS( |
100 SkOffsetImageFilter, (dx, dy, tileInput, &rect))); | 101 SkOffsetImageFilter, (dx, dy, tileInput, &rect))); |
101 paint.setImageFilter(filter); | 102 paint.setImageFilter(filter); |
102 drawClippedBitmap(canvas, *bitmap, paint, SkIntToScalar(x), SkIntToS
calar(y)); | 103 drawClippedBitmap(canvas, *bitmap, paint, SkIntToScalar(x), SkIntToS
calar(y)); |
103 x += bitmap->width() + MARGIN; | 104 x += bitmap->width() + MARGIN; |
104 if (x + bitmap->width() > WIDTH) { | 105 if (x + bitmap->width() > WIDTH) { |
105 x = 0; | 106 x = 0; |
106 y += bitmap->height() + MARGIN; | 107 y += bitmap->height() + MARGIN; |
107 } | 108 } |
108 } | 109 } |
109 } | 110 } |
110 private: | 111 private: |
111 typedef GM INHERITED; | 112 typedef GM INHERITED; |
112 SkBitmap fBitmap, fCheckerboard; | 113 SkBitmap fBitmap, fCheckerboard; |
113 bool fInitialized; | 114 bool fInitialized; |
114 }; | 115 }; |
115 | 116 |
116 ////////////////////////////////////////////////////////////////////////////// | 117 ////////////////////////////////////////////////////////////////////////////// |
117 | 118 |
118 static GM* MyFactory(void*) { return new OffsetImageFilterGM; } | 119 static GM* MyFactory(void*) { return new OffsetImageFilterGM; } |
119 static GMRegistry reg(MyFactory); | 120 static GMRegistry reg(MyFactory); |
120 | 121 |
121 } | 122 } |
OLD | NEW |