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 #include "SampleCode.h" | 7 #include "SampleCode.h" |
8 #include "SkBicubicImageFilter.h" | 8 #include "SkBicubicImageFilter.h" |
9 #include "SkBitmapDevice.h" | 9 #include "SkBitmapDevice.h" |
10 #include "SkBitmapSource.h" | 10 #include "SkBitmapSource.h" |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 static SkBitmap bitmap[2]; | 177 static SkBitmap bitmap[2]; |
178 static bool initialized = false; | 178 static bool initialized = false; |
179 if (!initialized) { | 179 if (!initialized) { |
180 make_g_bitmap(bitmap[0]); | 180 make_g_bitmap(bitmap[0]); |
181 make_checkerboard_bitmap(bitmap[1]); | 181 make_checkerboard_bitmap(bitmap[1]); |
182 initialized = true; | 182 initialized = true; |
183 } | 183 } |
184 return bitmap[R(2)]; | 184 return bitmap[R(2)]; |
185 } | 185 } |
186 | 186 |
| 187 #ifdef SK_ALLOW_PICTUREIMAGEFILTER_SERIALIZATION |
| 188 static void drawSomething(SkCanvas* canvas) { |
| 189 SkPaint paint; |
| 190 |
| 191 canvas->save(); |
| 192 canvas->scale(0.5f, 0.5f); |
| 193 canvas->drawBitmap(make_bitmap(), 0, 0, NULL); |
| 194 canvas->restore(); |
| 195 |
| 196 const char beforeStr[] = "before circle"; |
| 197 const char afterStr[] = "after circle"; |
| 198 |
| 199 paint.setAntiAlias(true); |
| 200 |
| 201 paint.setColor(SK_ColorRED); |
| 202 canvas->drawData(beforeStr, sizeof(beforeStr)); |
| 203 canvas->drawCircle(SkIntToScalar(kBitmapSize/2), SkIntToScalar(kBitmapSize/2
), SkIntToScalar(kBitmapSize/3), paint); |
| 204 canvas->drawData(afterStr, sizeof(afterStr)); |
| 205 paint.setColor(SK_ColorBLACK); |
| 206 paint.setTextSize(SkIntToScalar(kBitmapSize/3)); |
| 207 canvas->drawText("Picture", 7, SkIntToScalar(kBitmapSize/2), SkIntToScalar(k
BitmapSize/4), paint); |
| 208 } |
| 209 #endif |
| 210 |
187 static SkImageFilter* make_image_filter(bool canBeNull = true) { | 211 static SkImageFilter* make_image_filter(bool canBeNull = true) { |
188 SkImageFilter* filter = 0; | 212 SkImageFilter* filter = 0; |
189 | 213 |
190 // Add a 1 in 3 chance to get a NULL input | 214 // Add a 1 in 3 chance to get a NULL input |
191 if (canBeNull && (R(3) == 1)) { return filter; } | 215 if (canBeNull && (R(3) == 1)) { return filter; } |
192 | 216 |
193 enum { BICUBIC, MERGE, COLOR, BLUR, MAGNIFIER, XFERMODE, OFFSET, COMPOSE, | 217 enum { BICUBIC, MERGE, COLOR, BLUR, MAGNIFIER, XFERMODE, OFFSET, COMPOSE, |
194 DISTANT_LIGHT, POINT_LIGHT, SPOT_LIGHT, NOISE, DROP_SHADOW, | 218 DISTANT_LIGHT, POINT_LIGHT, SPOT_LIGHT, NOISE, DROP_SHADOW, |
195 MORPHOLOGY, BITMAP, DISPLACE, TILE, PICTURE, NUM_FILTERS }; | 219 MORPHOLOGY, BITMAP, DISPLACE, TILE, PICTURE, NUM_FILTERS }; |
196 | 220 |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
287 break; | 311 break; |
288 case DISPLACE: | 312 case DISPLACE: |
289 filter = new SkDisplacementMapEffect(make_channel_selector_type(), | 313 filter = new SkDisplacementMapEffect(make_channel_selector_type(), |
290 make_channel_selector_type(), make_scalar(), | 314 make_channel_selector_type(), make_scalar(), |
291 make_image_filter(false), make_image_filter()); | 315 make_image_filter(false), make_image_filter()); |
292 break; | 316 break; |
293 case TILE: | 317 case TILE: |
294 filter = new SkTileImageFilter(make_rect(), make_rect(), make_image_filt
er(false)); | 318 filter = new SkTileImageFilter(make_rect(), make_rect(), make_image_filt
er(false)); |
295 break; | 319 break; |
296 case PICTURE: | 320 case PICTURE: |
297 filter = new SkPictureImageFilter(NULL, make_rect()); | 321 { |
| 322 SkPicture* pict = NULL; |
| 323 #ifdef SK_ALLOW_PICTUREIMAGEFILTER_SERIALIZATION |
| 324 pict = new SkPicture; |
| 325 SkAutoUnref aur(pict); |
| 326 drawSomething(pict->beginRecording(kBitmapSize, kBitmapSize)); |
| 327 pict->endRecording(); |
| 328 #endif |
| 329 filter = new SkPictureImageFilter(pict, make_rect()); |
| 330 } |
298 break; | 331 break; |
299 default: | 332 default: |
300 break; | 333 break; |
301 } | 334 } |
302 return (filter || canBeNull) ? filter : make_image_filter(canBeNull); | 335 return (filter || canBeNull) ? filter : make_image_filter(canBeNull); |
303 } | 336 } |
304 | 337 |
305 static SkImageFilter* make_serialized_image_filter() { | 338 static SkImageFilter* make_serialized_image_filter() { |
306 SkAutoTUnref<SkImageFilter> filter(make_image_filter(false)); | 339 SkAutoTUnref<SkImageFilter> filter(make_image_filter(false)); |
307 SkAutoTUnref<SkData> data(SkValidatingSerializeFlattenable(filter)); | 340 SkAutoTUnref<SkData> data(SkValidatingSerializeFlattenable(filter)); |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
392 } | 425 } |
393 | 426 |
394 private: | 427 private: |
395 typedef SkView INHERITED; | 428 typedef SkView INHERITED; |
396 }; | 429 }; |
397 | 430 |
398 ////////////////////////////////////////////////////////////////////////////// | 431 ////////////////////////////////////////////////////////////////////////////// |
399 | 432 |
400 static SkView* MyFactory() { return new ImageFilterFuzzView; } | 433 static SkView* MyFactory() { return new ImageFilterFuzzView; } |
401 static SkViewRegister reg(MyFactory); | 434 static SkViewRegister reg(MyFactory); |
OLD | NEW |