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 "SkArithmeticMode.h" | 9 #include "SkArithmeticMode.h" |
10 #include "SkOffsetImageFilter.h" | 10 #include "SkOffsetImageFilter.h" |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
200 SkXfermode::kSrcOver_Mode, | 200 SkXfermode::kSrcOver_Mode, |
201 SkXfermode::kPlus_Mode}; | 201 SkXfermode::kPlus_Mode}; |
202 int offsets[nbSamples][4] = {{ 10, 10, -16, -16}, | 202 int offsets[nbSamples][4] = {{ 10, 10, -16, -16}, |
203 { 10, 10, 10, 10}, | 203 { 10, 10, 10, 10}, |
204 {-10, -10, -6, -6}}; | 204 {-10, -10, -6, -6}}; |
205 for (size_t i = 0; i < nbSamples; ++i) { | 205 for (size_t i = 0; i < nbSamples; ++i) { |
206 SkIRect cropRect = SkIRect::MakeXYWH(x + offsets[i][0], | 206 SkIRect cropRect = SkIRect::MakeXYWH(x + offsets[i][0], |
207 y + offsets[i][1], | 207 y + offsets[i][1], |
208 fBitmap.width() + offsets[i][2
], | 208 fBitmap.width() + offsets[i][2
], |
209 fBitmap.height() + offsets[i][3
]); | 209 fBitmap.height() + offsets[i][3
]); |
| 210 #ifdef SK_CROP_RECT_IS_INT |
| 211 SkIRect rect = cropRect; |
| 212 #else |
| 213 SkImageFilter::CropRect rect(SkRect::Make(cropRect)); |
| 214 #endif |
210 mode.reset(SkXfermode::Create(sampledModes[i])); | 215 mode.reset(SkXfermode::Create(sampledModes[i])); |
211 filter.reset(SkNEW_ARGS(SkXfermodeImageFilter, | 216 filter.reset(SkNEW_ARGS(SkXfermodeImageFilter, |
212 (mode, offsetBackground, offsetForeground, &
cropRect))); | 217 (mode, offsetBackground, offsetForeground, &
rect))); |
213 paint.setImageFilter(filter); | 218 paint.setImageFilter(filter); |
214 canvas->save(); | 219 canvas->save(); |
215 canvas->clipRect(SkRect::MakeXYWH(SkIntToScalar(x), | 220 canvas->clipRect(SkRect::MakeXYWH(SkIntToScalar(x), |
216 SkIntToScalar(y), | 221 SkIntToScalar(y), |
217 SkIntToScalar(fBitmap.width() + 4)
, | 222 SkIntToScalar(fBitmap.width() + 4)
, |
218 SkIntToScalar(fBitmap.height() + 4
))); | 223 SkIntToScalar(fBitmap.height() + 4
))); |
219 canvas->drawPaint(paint); | 224 canvas->drawPaint(paint); |
220 canvas->restore(); | 225 canvas->restore(); |
221 x += fBitmap.width() + MARGIN; | 226 x += fBitmap.width() + MARGIN; |
222 if (x + fBitmap.width() > WIDTH) { | 227 if (x + fBitmap.width() > WIDTH) { |
223 x = 0; | 228 x = 0; |
224 y += fBitmap.height() + MARGIN; | 229 y += fBitmap.height() + MARGIN; |
225 } | 230 } |
226 } | 231 } |
227 } | 232 } |
228 private: | 233 private: |
229 typedef GM INHERITED; | 234 typedef GM INHERITED; |
230 SkBitmap fBitmap, fCheckerboard; | 235 SkBitmap fBitmap, fCheckerboard; |
231 bool fInitialized; | 236 bool fInitialized; |
232 }; | 237 }; |
233 | 238 |
234 ////////////////////////////////////////////////////////////////////////////// | 239 ////////////////////////////////////////////////////////////////////////////// |
235 | 240 |
236 static GM* MyFactory(void*) { return new XfermodeImageFilterGM; } | 241 static GM* MyFactory(void*) { return new XfermodeImageFilterGM; } |
237 static GMRegistry reg(MyFactory); | 242 static GMRegistry reg(MyFactory); |
238 | 243 |
239 } | 244 } |
OLD | NEW |