Chromium Code Reviews| 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 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 182 mode.reset(SkXfermode::Create(SkXfermode::kDarken_Mode)); | 182 mode.reset(SkXfermode::Create(SkXfermode::kDarken_Mode)); |
| 183 filter.reset(SkNEW_ARGS(SkXfermodeImageFilter, (mode, offsetBackground, offsetForeground))); | 183 filter.reset(SkNEW_ARGS(SkXfermodeImageFilter, (mode, offsetBackground, offsetForeground))); |
| 184 paint.setImageFilter(filter); | 184 paint.setImageFilter(filter); |
| 185 canvas->save(); | 185 canvas->save(); |
| 186 canvas->clipRect(SkRect::MakeXYWH(SkIntToScalar(x), | 186 canvas->clipRect(SkRect::MakeXYWH(SkIntToScalar(x), |
| 187 SkIntToScalar(y), | 187 SkIntToScalar(y), |
| 188 SkIntToScalar(fBitmap.width() + 4), | 188 SkIntToScalar(fBitmap.width() + 4), |
| 189 SkIntToScalar(fBitmap.height() + 4))); | 189 SkIntToScalar(fBitmap.height() + 4))); |
| 190 canvas->drawPaint(paint); | 190 canvas->drawPaint(paint); |
| 191 canvas->restore(); | 191 canvas->restore(); |
| 192 x += fBitmap.width() + MARGIN; | |
| 193 if (x + fBitmap.width() > WIDTH) { | |
| 194 x = 0; | |
| 195 y += fBitmap.height() + MARGIN; | |
| 196 } | |
| 197 // Test cropping | |
|
Stephen White
2013/09/25 18:11:50
Do you need to expand the HEIGHT to accommodate th
sugoi1
2013/09/25 18:21:27
No, the extra 3 bring the count to 36, so it's a 6
| |
| 198 static const size_t nbSamples = 3; | |
| 199 SkXfermode::Mode sampledModes[nbSamples] = {SkXfermode::kOverlay_Mode, | |
| 200 SkXfermode::kSrcOver_Mode, | |
| 201 SkXfermode::kPlus_Mode}; | |
| 202 int offsets[nbSamples][4] = {{ 10, 10, -16, -16}, | |
| 203 { 10, 10, 10, 10}, | |
| 204 {-10, -10, -6, -6}}; | |
| 205 for (size_t i = 0; i < nbSamples; ++i) { | |
| 206 SkIRect cropRect = SkIRect::MakeXYWH(x + offsets[i][0], | |
| 207 y + offsets[i][1], | |
| 208 fBitmap.width() + offsets[i][2 ], | |
| 209 fBitmap.height() + offsets[i][3 ]); | |
| 210 mode.reset(SkXfermode::Create(sampledModes[i])); | |
| 211 filter.reset(SkNEW_ARGS(SkXfermodeImageFilter, | |
| 212 (mode, offsetBackground, offsetForeground, & cropRect))); | |
| 213 paint.setImageFilter(filter); | |
| 214 canvas->save(); | |
| 215 canvas->clipRect(SkRect::MakeXYWH(SkIntToScalar(x), | |
| 216 SkIntToScalar(y), | |
| 217 SkIntToScalar(fBitmap.width() + 4) , | |
| 218 SkIntToScalar(fBitmap.height() + 4 ))); | |
| 219 canvas->drawPaint(paint); | |
| 220 canvas->restore(); | |
| 221 x += fBitmap.width() + MARGIN; | |
| 222 if (x + fBitmap.width() > WIDTH) { | |
| 223 x = 0; | |
| 224 y += fBitmap.height() + MARGIN; | |
| 225 } | |
| 226 } | |
| 192 } | 227 } |
| 193 private: | 228 private: |
| 194 typedef GM INHERITED; | 229 typedef GM INHERITED; |
| 195 SkBitmap fBitmap, fCheckerboard; | 230 SkBitmap fBitmap, fCheckerboard; |
| 196 bool fInitialized; | 231 bool fInitialized; |
| 197 }; | 232 }; |
| 198 | 233 |
| 199 ////////////////////////////////////////////////////////////////////////////// | 234 ////////////////////////////////////////////////////////////////////////////// |
| 200 | 235 |
| 201 static GM* MyFactory(void*) { return new XfermodeImageFilterGM; } | 236 static GM* MyFactory(void*) { return new XfermodeImageFilterGM; } |
| 202 static GMRegistry reg(MyFactory); | 237 static GMRegistry reg(MyFactory); |
| 203 | 238 |
| 204 } | 239 } |
| OLD | NEW |