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 "SkAlphaThresholdFilter.h" | 8 #include "SkAlphaThresholdFilter.h" |
9 #include "SkAnnotation.h" | |
9 #include "SkBlurImageFilter.h" | 10 #include "SkBlurImageFilter.h" |
11 #include "SkBlurMaskFilter.h" | |
10 #include "SkCanvas.h" | 12 #include "SkCanvas.h" |
11 #include "SkColorCubeFilter.h" | 13 #include "SkColorCubeFilter.h" |
12 #include "SkColorFilter.h" | 14 #include "SkColorFilter.h" |
13 #include "SkColorFilterImageFilter.h" | 15 #include "SkColorFilterImageFilter.h" |
14 #include "SkComposeImageFilter.h" | 16 #include "SkComposeImageFilter.h" |
17 #include "SkCornerPathEffect.h" | |
15 #include "SkData.h" | 18 #include "SkData.h" |
16 #include "SkDisplacementMapEffect.h" | 19 #include "SkDisplacementMapEffect.h" |
17 #include "SkDropShadowImageFilter.h" | 20 #include "SkDropShadowImageFilter.h" |
18 #include "SkFlattenableSerialization.h" | 21 #include "SkFlattenableSerialization.h" |
19 #include "SkImageSource.h" | 22 #include "SkImageSource.h" |
23 #include "SkLayerRasterizer.h" | |
20 #include "SkLightingImageFilter.h" | 24 #include "SkLightingImageFilter.h" |
21 #include "SkMagnifierImageFilter.h" | 25 #include "SkMagnifierImageFilter.h" |
22 #include "SkMatrixConvolutionImageFilter.h" | 26 #include "SkMatrixConvolutionImageFilter.h" |
23 #include "SkMergeImageFilter.h" | 27 #include "SkMergeImageFilter.h" |
24 #include "SkMorphologyImageFilter.h" | 28 #include "SkMorphologyImageFilter.h" |
25 #include "SkOffsetImageFilter.h" | 29 #include "SkOffsetImageFilter.h" |
30 #include "SkPaintImageFilter.h" | |
26 #include "SkPerlinNoiseShader.h" | 31 #include "SkPerlinNoiseShader.h" |
27 #include "SkPictureImageFilter.h" | 32 #include "SkPictureImageFilter.h" |
28 #include "SkPictureRecorder.h" | 33 #include "SkPictureRecorder.h" |
29 #include "SkPoint3.h" | 34 #include "SkPoint3.h" |
30 #include "SkRandom.h" | 35 #include "SkRandom.h" |
31 #include "SkRectShaderImageFilter.h" | |
32 #include "SkTestImageFilters.h" | 36 #include "SkTestImageFilters.h" |
33 #include "SkTileImageFilter.h" | 37 #include "SkTileImageFilter.h" |
38 #include "SkTypeface.h" | |
34 #include "SkView.h" | 39 #include "SkView.h" |
35 #include "SkXfermodeImageFilter.h" | 40 #include "SkXfermodeImageFilter.h" |
41 #include "sk_tool_utils.h" | |
36 #include <stdio.h> | 42 #include <stdio.h> |
37 #include <time.h> | 43 #include <time.h> |
38 | 44 |
39 //#define SK_ADD_RANDOM_BIT_FLIPS | 45 //#define SK_ADD_RANDOM_BIT_FLIPS |
40 //#define SK_FUZZER_IS_VERBOSE | 46 //#define SK_FUZZER_IS_VERBOSE |
41 | 47 |
42 static const uint32_t kSeed = (uint32_t)(time(nullptr)); | 48 static const uint32_t kSeed = (uint32_t)(time(nullptr)); |
43 static SkRandom gRand(kSeed); | 49 static SkRandom gRand(kSeed); |
44 static bool return_large = false; | 50 static bool return_large = false; |
45 static bool return_undef = false; | 51 static bool return_undef = false; |
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
259 | 265 |
260 static SkImageFilter* make_image_filter(bool canBeNull = true) { | 266 static SkImageFilter* make_image_filter(bool canBeNull = true) { |
261 SkImageFilter* filter = 0; | 267 SkImageFilter* filter = 0; |
262 | 268 |
263 // Add a 1 in 3 chance to get a nullptr input | 269 // Add a 1 in 3 chance to get a nullptr input |
264 if (canBeNull && (R(3) == 1)) { return filter; } | 270 if (canBeNull && (R(3) == 1)) { return filter; } |
265 | 271 |
266 enum { ALPHA_THRESHOLD, MERGE, COLOR, LUT3D, BLUR, MAGNIFIER, | 272 enum { ALPHA_THRESHOLD, MERGE, COLOR, LUT3D, BLUR, MAGNIFIER, |
267 DOWN_SAMPLE, XFERMODE, OFFSET, MATRIX, MATRIX_CONVOLUTION, COMPOSE, | 273 DOWN_SAMPLE, XFERMODE, OFFSET, MATRIX, MATRIX_CONVOLUTION, COMPOSE, |
268 DISTANT_LIGHT, POINT_LIGHT, SPOT_LIGHT, NOISE, DROP_SHADOW, | 274 DISTANT_LIGHT, POINT_LIGHT, SPOT_LIGHT, NOISE, DROP_SHADOW, |
269 MORPHOLOGY, BITMAP, DISPLACE, TILE, PICTURE, NUM_FILTERS }; | 275 MORPHOLOGY, BITMAP, DISPLACE, TILE, PICTURE, PAINT, NUM_FILTERS }; |
270 | 276 |
271 switch (R(NUM_FILTERS)) { | 277 switch (R(NUM_FILTERS)) { |
272 case ALPHA_THRESHOLD: | 278 case ALPHA_THRESHOLD: |
273 filter = SkAlphaThresholdFilter::Create(make_region(), make_scalar(), ma ke_scalar()); | 279 filter = SkAlphaThresholdFilter::Create(make_region(), make_scalar(), ma ke_scalar()); |
274 break; | 280 break; |
275 case MERGE: | 281 case MERGE: |
276 filter = SkMergeImageFilter::Create(make_image_filter(), make_image_filt er(), make_xfermode()); | 282 filter = SkMergeImageFilter::Create(make_image_filter(), make_image_filt er(), make_xfermode()); |
277 break; | 283 break; |
278 case COLOR: | 284 case COLOR: |
279 { | 285 { |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
365 make_point(), make_scalar(), make_scalar(), make_color(), | 371 make_point(), make_scalar(), make_scalar(), make_color(), |
366 make_scalar(), make_scalar(), SkIntToScalar(R(10)), make_image_ filter()); | 372 make_scalar(), make_scalar(), SkIntToScalar(R(10)), make_image_ filter()); |
367 break; | 373 break; |
368 case NOISE: | 374 case NOISE: |
369 { | 375 { |
370 SkAutoTUnref<SkShader> shader((R(2) == 1) ? | 376 SkAutoTUnref<SkShader> shader((R(2) == 1) ? |
371 SkPerlinNoiseShader::CreateFractalNoise( | 377 SkPerlinNoiseShader::CreateFractalNoise( |
372 make_scalar(true), make_scalar(true), R(10.0f), make_scalar()) : | 378 make_scalar(true), make_scalar(true), R(10.0f), make_scalar()) : |
373 SkPerlinNoiseShader::CreateTurbulence( | 379 SkPerlinNoiseShader::CreateTurbulence( |
374 make_scalar(true), make_scalar(true), R(10.0f), make_scalar())); | 380 make_scalar(true), make_scalar(true), R(10.0f), make_scalar())); |
381 SkPaint paint; | |
382 paint.setShader(shader); | |
375 SkImageFilter::CropRect cropR(SkRect::MakeWH(SkIntToScalar(kBitmapSize), | 383 SkImageFilter::CropRect cropR(SkRect::MakeWH(SkIntToScalar(kBitmapSize), |
376 SkIntToScalar(kBitmapSize)) ); | 384 SkIntToScalar(kBitmapSize)) ); |
377 filter = SkRectShaderImageFilter::Create(shader, &cropR); | 385 filter = SkPaintImageFilter::Create(paint, &cropR); |
378 } | 386 } |
379 break; | 387 break; |
380 case DROP_SHADOW: | 388 case DROP_SHADOW: |
381 filter = SkDropShadowImageFilter::Create(make_scalar(), make_scalar(), m ake_scalar(true), | 389 filter = SkDropShadowImageFilter::Create(make_scalar(), make_scalar(), m ake_scalar(true), |
382 make_scalar(true), make_color(), make_shadow_mode(), make_im age_filter(), | 390 make_scalar(true), make_color(), make_shadow_mode(), make_im age_filter(), |
383 nullptr); | 391 nullptr); |
384 break; | 392 break; |
385 case MORPHOLOGY: | 393 case MORPHOLOGY: |
386 if (R(2) == 1) { | 394 if (R(2) == 1) { |
387 filter = SkDilateImageFilter::Create(R(static_cast<float>(kBitmapSiz e)), | 395 filter = SkDilateImageFilter::Create(R(static_cast<float>(kBitmapSiz e)), |
(...skipping 26 matching lines...) Expand all Loading... | |
414 SkRTreeFactory factory; | 422 SkRTreeFactory factory; |
415 SkPictureRecorder recorder; | 423 SkPictureRecorder recorder; |
416 SkCanvas* recordingCanvas = recorder.beginRecording(SkIntToScalar(kBitma pSize), | 424 SkCanvas* recordingCanvas = recorder.beginRecording(SkIntToScalar(kBitma pSize), |
417 SkIntToScalar(kBitma pSize), | 425 SkIntToScalar(kBitma pSize), |
418 &factory, 0); | 426 &factory, 0); |
419 drawSomething(recordingCanvas); | 427 drawSomething(recordingCanvas); |
420 SkAutoTUnref<SkPicture> pict(recorder.endRecording()); | 428 SkAutoTUnref<SkPicture> pict(recorder.endRecording()); |
421 filter = SkPictureImageFilter::Create(pict.get(), make_rect()); | 429 filter = SkPictureImageFilter::Create(pict.get(), make_rect()); |
422 } | 430 } |
423 break; | 431 break; |
432 case PAINT: | |
433 { | |
434 SkPaint paint; | |
435 paint.setHinting(SkPaint::kSlight_Hinting); | |
436 paint.setAntiAlias(true); | |
437 paint.setDither(true); | |
438 paint.setLinearText(true); | |
439 paint.setSubpixelText(false); | |
440 paint.setLCDRenderText(false); | |
441 paint.setEmbeddedBitmapText(true); | |
442 paint.setAutohinted(false); | |
443 paint.setVerticalText(true); | |
444 paint.setUnderlineText(false); | |
445 paint.setStrikeThruText(true); | |
446 paint.setFakeBoldText(true); | |
447 paint.setDevKernText(false); | |
448 paint.setFilterQuality(kLow_SkFilterQuality); | |
449 paint.setStyle(SkPaint::kStroke_Style); | |
450 paint.setColor(SK_ColorRED); | |
451 paint.setStrokeWidth(SkIntToScalar(3)); | |
452 paint.setStrokeMiter(SkIntToScalar(1)); | |
453 paint.setStrokeCap(SkPaint::kRound_Cap); | |
454 paint.setStrokeJoin(SkPaint::kBevel_Join); | |
455 SkAutoTUnref<SkColorFilter> colorFilter( | |
456 SkColorFilter::CreateLightingFilter(make_color(), make_color())); | |
457 paint.setColorFilter(colorFilter); | |
458 paint.setXfermodeMode(SkXfermode::kDstIn_Mode); | |
459 SkAutoTUnref<SkPathEffect> pathEffect(SkCornerPathEffect::Create(SkIntTo Scalar(3))); | |
460 paint.setPathEffect(pathEffect); | |
461 SkAutoTUnref<SkMaskFilter> maskFilter( | |
462 SkBlurMaskFilter::Create(kNormal_SkBlurStyle, | |
463 SkIntToScalar(25), | |
464 SkBlurMaskFilter::kHighQuality_BlurFlag)); | |
465 paint.setMaskFilter(maskFilter); | |
466 SkAutoTUnref<SkTypeface> typeface( | |
467 sk_tool_utils::create_portable_typeface("serif", SkTypeface::kBold)) ; | |
468 paint.setTypeface(typeface); | |
469 SkLayerRasterizer::Builder rasterizerBuilder; | |
470 SkPaint paintForRasterizer; | |
471 rasterizerBuilder.addLayer(paintForRasterizer); | |
472 SkAutoTUnref<SkRasterizer> rasterizer(rasterizerBuilder.detachRasterizer ()); | |
473 paint.setRasterizer(rasterizer); | |
474 SkAutoTUnref<SkImageFilter> imageFilter( | |
475 SkBlurImageFilter::Create(SkIntToScalar(2), SkIntToScalar(2))); | |
476 paint.setImageFilter(imageFilter); | |
477 SkAutoDataUnref data(SkData::NewWithCString("This is an annotation.")); | |
478 SkAutoTUnref<SkAnnotation> annotation( | |
479 SkAnnotation::Create(SkAnnotationKeys::Define_Named_Dest_Key(), data )); | |
480 paint.setAnnotation(annotation); | |
481 paint.setTextAlign(SkPaint::kCenter_Align); | |
482 paint.setTextSize(SkIntToScalar(8)); | |
483 paint.setTextScaleX(SkFloatToScalar(0.75)); | |
484 paint.setTextSkewX(SkFloatToScalar(-0.25)); | |
485 paint.setTextEncoding(SkPaint::kUTF16_TextEncoding); | |
486 SkImageFilter::CropRect cropR(SkRect::MakeWH(SkIntToScalar(kBitmapSize), | |
487 SkIntToScalar(kBitmapSize)) ); | |
ajuma
2016/01/04 22:39:46
Is it worthwhile also adding test cases that use s
sugoi1
2016/01/05 15:59:55
You could choose to use each of these functions ra
ajuma
2016/01/06 20:53:39
Thanks for the tips! (And also thanks for all the
| |
488 filter = SkPaintImageFilter::Create(paint, &cropR); | |
489 } | |
424 default: | 490 default: |
425 break; | 491 break; |
426 } | 492 } |
427 return (filter || canBeNull) ? filter : make_image_filter(canBeNull); | 493 return (filter || canBeNull) ? filter : make_image_filter(canBeNull); |
428 } | 494 } |
429 | 495 |
430 static SkImageFilter* make_serialized_image_filter() { | 496 static SkImageFilter* make_serialized_image_filter() { |
431 SkAutoTUnref<SkImageFilter> filter(make_image_filter(false)); | 497 SkAutoTUnref<SkImageFilter> filter(make_image_filter(false)); |
432 SkAutoTUnref<SkData> data(SkValidatingSerializeFlattenable(filter)); | 498 SkAutoTUnref<SkData> data(SkValidatingSerializeFlattenable(filter)); |
433 const unsigned char* ptr = static_cast<const unsigned char*>(data->data()); | 499 const unsigned char* ptr = static_cast<const unsigned char*>(data->data()); |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
517 } | 583 } |
518 | 584 |
519 private: | 585 private: |
520 typedef SkView INHERITED; | 586 typedef SkView INHERITED; |
521 }; | 587 }; |
522 | 588 |
523 ////////////////////////////////////////////////////////////////////////////// | 589 ////////////////////////////////////////////////////////////////////////////// |
524 | 590 |
525 static SkView* MyFactory() { return new ImageFilterFuzzView; } | 591 static SkView* MyFactory() { return new ImageFilterFuzzView; } |
526 static SkViewRegister reg(MyFactory); | 592 static SkViewRegister reg(MyFactory); |
OLD | NEW |