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 "Sk1DPathEffect.h" | 8 #include "Sk1DPathEffect.h" |
9 #include "Sk2DPathEffect.h" | 9 #include "Sk2DPathEffect.h" |
10 #include "SkAlphaThresholdFilter.h" | 10 #include "SkAlphaThresholdFilter.h" |
(...skipping 469 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
480 light); | 480 light); |
481 } | 481 } |
482 case 2: | 482 case 2: |
483 default: | 483 default: |
484 maskFilter = nullptr; | 484 maskFilter = nullptr; |
485 break; | 485 break; |
486 } | 486 } |
487 return maskFilter; | 487 return maskFilter; |
488 } | 488 } |
489 | 489 |
490 static SkImageFilter* make_image_filter(bool canBeNull = true); | 490 static sk_sp<SkImageFilter> make_image_filter(bool canBeNull = true); |
491 | 491 |
492 static SkPaint make_paint() { | 492 static SkPaint make_paint() { |
493 SkPaint paint; | 493 SkPaint paint; |
494 paint.setHinting(make_paint_hinting()); | 494 paint.setHinting(make_paint_hinting()); |
495 paint.setAntiAlias(make_bool()); | 495 paint.setAntiAlias(make_bool()); |
496 paint.setDither(make_bool()); | 496 paint.setDither(make_bool()); |
497 paint.setLinearText(make_bool()); | 497 paint.setLinearText(make_bool()); |
498 paint.setSubpixelText(make_bool()); | 498 paint.setSubpixelText(make_bool()); |
499 paint.setLCDRenderText(make_bool()); | 499 paint.setLCDRenderText(make_bool()); |
500 paint.setEmbeddedBitmapText(make_bool()); | 500 paint.setEmbeddedBitmapText(make_bool()); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
533 paint.setImageFilter(make_image_filter()); | 533 paint.setImageFilter(make_image_filter()); |
534 sk_sp<SkData> data(make_3Dlut(nullptr, make_bool(), make_bool(), make_bool()
)); | 534 sk_sp<SkData> data(make_3Dlut(nullptr, make_bool(), make_bool(), make_bool()
)); |
535 paint.setTextAlign(make_paint_align()); | 535 paint.setTextAlign(make_paint_align()); |
536 paint.setTextSize(make_scalar()); | 536 paint.setTextSize(make_scalar()); |
537 paint.setTextScaleX(make_scalar()); | 537 paint.setTextScaleX(make_scalar()); |
538 paint.setTextSkewX(make_scalar()); | 538 paint.setTextSkewX(make_scalar()); |
539 paint.setTextEncoding(make_paint_text_encoding()); | 539 paint.setTextEncoding(make_paint_text_encoding()); |
540 return paint; | 540 return paint; |
541 } | 541 } |
542 | 542 |
543 static SkImageFilter* make_image_filter(bool canBeNull) { | 543 static sk_sp<SkImageFilter> make_image_filter(bool canBeNull) { |
544 SkImageFilter* filter = 0; | 544 sk_sp<SkImageFilter> filter; |
545 | 545 |
546 // Add a 1 in 3 chance to get a nullptr input | 546 // Add a 1 in 3 chance to get a nullptr input |
547 if (canBeNull && (R(3) == 1)) { return filter; } | 547 if (canBeNull && (R(3) == 1)) { |
| 548 return filter; |
| 549 } |
548 | 550 |
549 enum { ALPHA_THRESHOLD, MERGE, COLOR, LUT3D, BLUR, MAGNIFIER, | 551 enum { ALPHA_THRESHOLD, MERGE, COLOR, LUT3D, BLUR, MAGNIFIER, |
550 DOWN_SAMPLE, XFERMODE, OFFSET, MATRIX, MATRIX_CONVOLUTION, COMPOSE, | 552 DOWN_SAMPLE, XFERMODE, OFFSET, MATRIX, MATRIX_CONVOLUTION, COMPOSE, |
551 DISTANT_LIGHT, POINT_LIGHT, SPOT_LIGHT, NOISE, DROP_SHADOW, | 553 DISTANT_LIGHT, POINT_LIGHT, SPOT_LIGHT, NOISE, DROP_SHADOW, |
552 MORPHOLOGY, BITMAP, DISPLACE, TILE, PICTURE, PAINT, NUM_FILTERS }; | 554 MORPHOLOGY, BITMAP, DISPLACE, TILE, PICTURE, PAINT, NUM_FILTERS }; |
553 | 555 |
554 switch (R(NUM_FILTERS)) { | 556 switch (R(NUM_FILTERS)) { |
555 case ALPHA_THRESHOLD: | 557 case ALPHA_THRESHOLD: |
556 filter = SkAlphaThresholdFilter::Create(make_region(), make_scalar(), ma
ke_scalar()); | 558 filter = sk_sp<SkImageFilter>(SkAlphaThresholdFilter::Create(make_region
(), |
| 559 make_scalar
(), |
| 560 make_scalar
())); |
557 break; | 561 break; |
558 case MERGE: | 562 case MERGE: { |
559 filter = SkMergeImageFilter::Create(make_image_filter(), make_image_filt
er(), make_xfermode()); | 563 sk_sp<SkImageFilter> subFilter1(make_image_filter()); |
| 564 sk_sp<SkImageFilter> subFilter2(make_image_filter()); |
| 565 filter = sk_sp<SkImageFilter>(SkMergeImageFilter::Create(subFilter1.get(
), |
| 566 subFilter2.get(
), |
| 567 make_xfermode()
)); |
560 break; | 568 break; |
561 case COLOR: | 569 } |
562 { | 570 case COLOR: { |
563 sk_sp<SkColorFilter> cf(make_color_filter()); | 571 sk_sp<SkColorFilter> cf(make_color_filter()); |
564 filter = cf ? SkColorFilterImageFilter::Create(cf.get(), make_image_filt
er()) : 0; | 572 sk_sp<SkImageFilter> subFilter(make_image_filter()); |
| 573 filter = cf ? sk_sp<SkImageFilter>(SkColorFilterImageFilter::Create(cf.g
et(), |
| 574 subF
ilter.get())) |
| 575 : nullptr; |
| 576 break; |
565 } | 577 } |
566 break; | 578 case LUT3D: { |
567 case LUT3D: | |
568 { | |
569 int cubeDimension; | 579 int cubeDimension; |
570 sk_sp<SkData> lut3D(make_3Dlut(&cubeDimension, (R(2) == 1), (R(2) == 1),
(R(2) == 1))); | 580 sk_sp<SkData> lut3D(make_3Dlut(&cubeDimension, (R(2) == 1), (R(2) == 1),
(R(2) == 1))); |
571 sk_sp<SkColorFilter> cf(SkColorCubeFilter::Make(lut3D, cubeDimension)); | 581 sk_sp<SkColorFilter> cf(SkColorCubeFilter::Make(lut3D, cubeDimension)); |
572 filter = cf ? SkColorFilterImageFilter::Create(cf.get(), make_image_filt
er()) : 0; | 582 sk_sp<SkImageFilter> subFilter(make_image_filter()); |
| 583 filter = cf ? sk_sp<SkImageFilter>(SkColorFilterImageFilter::Create(cf.g
et(), |
| 584 subF
ilter.get())) |
| 585 : nullptr; |
| 586 break; |
573 } | 587 } |
| 588 case BLUR: { |
| 589 sk_sp<SkImageFilter> subFilter(make_image_filter()); |
| 590 filter = sk_sp<SkImageFilter>(SkBlurImageFilter::Create(make_scalar(true
), |
| 591 make_scalar(true
), |
| 592 subFilter.get())
); |
574 break; | 593 break; |
575 case BLUR: | 594 } |
576 filter = SkBlurImageFilter::Create(make_scalar(true), make_scalar(true),
make_image_filter()); | |
577 break; | |
578 case MAGNIFIER: | 595 case MAGNIFIER: |
579 filter = SkMagnifierImageFilter::Create(make_rect(), make_scalar(true)); | 596 filter = sk_sp<SkImageFilter>(SkMagnifierImageFilter::Create(make_rect()
, |
| 597 make_scalar
(true))); |
580 break; | 598 break; |
581 case DOWN_SAMPLE: | 599 case DOWN_SAMPLE: |
582 filter = SkDownSampleImageFilter::Create(make_scalar()); | 600 filter = sk_sp<SkImageFilter>(SkDownSampleImageFilter::Create(make_scala
r())); |
583 break; | 601 break; |
584 case XFERMODE: | 602 case XFERMODE: { |
| 603 sk_sp<SkImageFilter> subFilter1(make_image_filter()); |
| 604 sk_sp<SkImageFilter> subFilter2(make_image_filter()); |
585 filter = SkXfermodeImageFilter::Make(SkXfermode::Make(make_xfermode()), | 605 filter = SkXfermodeImageFilter::Make(SkXfermode::Make(make_xfermode()), |
586 make_image_filter(), make_image_fil
ter(), | 606 subFilter1.get(), |
587 nullptr).release(); | 607 subFilter2.get(), |
| 608 nullptr); |
588 break; | 609 break; |
589 case OFFSET: | 610 } |
590 filter = SkOffsetImageFilter::Create(make_scalar(), make_scalar(), make_
image_filter()); | 611 case OFFSET: { |
| 612 sk_sp<SkImageFilter> subFilter(make_image_filter()); |
| 613 filter = sk_sp<SkImageFilter>(SkOffsetImageFilter::Create(make_scalar(),
make_scalar(), |
| 614 subFilter.get(
))); |
591 break; | 615 break; |
592 case MATRIX: | 616 } |
593 filter = SkImageFilter::CreateMatrixFilter(make_matrix(), | 617 case MATRIX: { |
594 (SkFilterQuality)R(4), | 618 sk_sp<SkImageFilter> subFilter(make_image_filter()); |
595 make_image_filter()); | 619 filter = sk_sp<SkImageFilter>(SkImageFilter::CreateMatrixFilter(make_mat
rix(), |
| 620 (SkFilte
rQuality)R(4), |
| 621 subFilte
r.get())); |
596 break; | 622 break; |
597 case MATRIX_CONVOLUTION: | 623 } |
598 { | 624 case MATRIX_CONVOLUTION: { |
599 SkImageFilter::CropRect cropR(SkRect::MakeWH(SkIntToScalar(kBitmapSize), | 625 SkImageFilter::CropRect cropR(SkRect::MakeWH(SkIntToScalar(kBitmapSize), |
600 SkIntToScalar(kBitmapSize))
); | 626 SkIntToScalar(kBitmapSize))
); |
601 SkISize size = SkISize::Make(R(10)+1, R(10)+1); | 627 SkISize size = SkISize::Make(R(10)+1, R(10)+1); |
602 int arraySize = size.width() * size.height(); | 628 int arraySize = size.width() * size.height(); |
603 SkTArray<SkScalar> kernel(arraySize); | 629 SkTArray<SkScalar> kernel(arraySize); |
604 for (int i = 0; i < arraySize; ++i) { | 630 for (int i = 0; i < arraySize; ++i) { |
605 kernel.push_back() = make_scalar(); | 631 kernel.push_back() = make_scalar(); |
606 } | 632 } |
607 SkIPoint kernelOffset = SkIPoint::Make(R(SkIntToScalar(size.width())), | 633 SkIPoint kernelOffset = SkIPoint::Make(R(SkIntToScalar(size.width())), |
608 R(SkIntToScalar(size.height()))); | 634 R(SkIntToScalar(size.height()))); |
609 filter = SkMatrixConvolutionImageFilter::Create(size, | 635 sk_sp<SkImageFilter> subFilter(make_image_filter()); |
| 636 |
| 637 filter = sk_sp<SkImageFilter>(SkMatrixConvolutionImageFilter::Create( |
| 638 size, |
610 kernel.begin(), | 639 kernel.begin(), |
611 make_scalar(), | 640 make_scalar(), |
612 make_scalar(), | 641 make_scalar(), |
613 kernelOffset, | 642 kernelOffset, |
614 (SkMatrixConvolutionImag
eFilter::TileMode)R(3), | 643 (SkMatrixConvolutionImag
eFilter::TileMode)R(3), |
615 R(2) == 1, | 644 R(2) == 1, |
616 make_image_filter(), | 645 subFilter.get(), |
617 &cropR); | 646 &cropR)); |
| 647 break; |
618 } | 648 } |
| 649 case COMPOSE: { |
| 650 sk_sp<SkImageFilter> subFilter1(make_image_filter()); |
| 651 sk_sp<SkImageFilter> subFilter2(make_image_filter()); |
| 652 filter = sk_sp<SkImageFilter>(SkComposeImageFilter::Create(subFilter1.ge
t(), |
| 653 subFilter2.ge
t())); |
619 break; | 654 break; |
620 case COMPOSE: | 655 } |
621 filter = SkComposeImageFilter::Create(make_image_filter(), make_image_fi
lter()); | 656 case DISTANT_LIGHT: { |
| 657 sk_sp<SkImageFilter> subFilter(make_image_filter()); |
| 658 |
| 659 filter = (R(2) == 1) |
| 660 ? sk_sp<SkImageFilter>(SkLightingImageFilter::CreateDistantLitD
iffuse(make_point(), |
| 661 make_color(), make_scalar(), mak
e_scalar(), |
| 662 subFilter.get())) |
| 663 : sk_sp<SkImageFilter>(SkLightingImageFilter::CreateDistantLitS
pecular(make_point(), |
| 664 make_color(), make_scalar(), |
| 665 make_scalar(), SkIntToScalar(R(1
0)), |
| 666 subFilter.get())); |
622 break; | 667 break; |
623 case DISTANT_LIGHT: | 668 } |
624 filter = (R(2) == 1) ? | 669 case POINT_LIGHT: { |
625 SkLightingImageFilter::CreateDistantLitDiffuse(make_point(), | 670 sk_sp<SkImageFilter> subFilter(make_image_filter()); |
626 make_color(), make_scalar(), make_scalar(), make_image_filter()
) : | 671 |
627 SkLightingImageFilter::CreateDistantLitSpecular(make_point(), | 672 filter = (R(2) == 1) |
628 make_color(), make_scalar(), make_scalar(), SkIntToScalar(R(10)
), | 673 ? sk_sp<SkImageFilter>(SkLightingImageFilter::CreatePointLitDif
fuse(make_point(), |
629 make_image_filter()); | 674 make_color(), make_scalar(), mak
e_scalar(), |
| 675 subFilter.get())) |
| 676 : sk_sp<SkImageFilter>(SkLightingImageFilter::CreatePointLitSpe
cular(make_point(), |
| 677 make_color(), make_scalar(), mak
e_scalar(), |
| 678 SkIntToScalar(R(10)), |
| 679 subFilter.get())); |
630 break; | 680 break; |
631 case POINT_LIGHT: | 681 } |
632 filter = (R(2) == 1) ? | 682 case SPOT_LIGHT: { |
633 SkLightingImageFilter::CreatePointLitDiffuse(make_point(), | 683 sk_sp<SkImageFilter> subFilter(make_image_filter()); |
634 make_color(), make_scalar(), make_scalar(), make_image_filter()
) : | 684 |
635 SkLightingImageFilter::CreatePointLitSpecular(make_point(), | 685 filter = (R(2) == 1) |
636 make_color(), make_scalar(), make_scalar(), SkIntToScalar(R(10)
), | 686 ? sk_sp<SkImageFilter>(SkLightingImageFilter::CreateSpotLitDiff
use(SkPoint3::Make(0, 0, 0), |
637 make_image_filter()); | 687 make_point(), make_scalar(), ma
ke_scalar(), |
| 688 make_color(), make_scalar(), ma
ke_scalar(), |
| 689 subFilter.get())) |
| 690 : sk_sp<SkImageFilter>(SkLightingImageFilter::CreateSpotLitSpec
ular(SkPoint3::Make(0, 0, 0), |
| 691 make_point(), make_scalar(), ma
ke_scalar(), |
| 692 make_color(), make_scalar(), ma
ke_scalar(), |
| 693 SkIntToScalar(R(10)), subFilter
.get())); |
638 break; | 694 break; |
639 case SPOT_LIGHT: | 695 } |
640 filter = (R(2) == 1) ? | 696 case NOISE: { |
641 SkLightingImageFilter::CreateSpotLitDiffuse(SkPoint3::Make(0, 0
, 0), | |
642 make_point(), make_scalar(), make_scalar(), make_color(), | |
643 make_scalar(), make_scalar(), make_image_filter()) : | |
644 SkLightingImageFilter::CreateSpotLitSpecular(SkPoint3::Make(0,
0, 0), | |
645 make_point(), make_scalar(), make_scalar(), make_color(), | |
646 make_scalar(), make_scalar(), SkIntToScalar(R(10)), make_image_
filter()); | |
647 break; | |
648 case NOISE: | |
649 { | |
650 sk_sp<SkShader> shader((R(2) == 1) ? | 697 sk_sp<SkShader> shader((R(2) == 1) ? |
651 SkPerlinNoiseShader::MakeFractalNoise( | 698 SkPerlinNoiseShader::MakeFractalNoise( |
652 make_scalar(true), make_scalar(true), R(10.0f), make_scalar()) : | 699 make_scalar(true), make_scalar(true), R(10.0f), make_scalar()) : |
653 SkPerlinNoiseShader::MakeTurbulence( | 700 SkPerlinNoiseShader::MakeTurbulence( |
654 make_scalar(true), make_scalar(true), R(10.0f), make_scalar())); | 701 make_scalar(true), make_scalar(true), R(10.0f), make_scalar())); |
655 SkPaint paint; | 702 SkPaint paint; |
656 paint.setShader(shader); | 703 paint.setShader(shader); |
657 SkImageFilter::CropRect cropR(SkRect::MakeWH(SkIntToScalar(kBitmapSize), | 704 SkImageFilter::CropRect cropR(SkRect::MakeWH(SkIntToScalar(kBitmapSize), |
658 SkIntToScalar(kBitmapSize))
); | 705 SkIntToScalar(kBitmapSize))
); |
659 filter = SkPaintImageFilter::Create(paint, &cropR); | 706 filter = SkPaintImageFilter::Make(paint, &cropR); |
| 707 break; |
660 } | 708 } |
| 709 case DROP_SHADOW: { |
| 710 sk_sp<SkImageFilter> subFilter(make_image_filter()); |
| 711 |
| 712 filter = sk_sp<SkImageFilter>(SkDropShadowImageFilter::Create(make_scala
r(), |
| 713 make_scala
r(), |
| 714 make_scala
r(true), |
| 715 make_scala
r(true), |
| 716 make_color
(), |
| 717 make_shado
w_mode(), |
| 718 subFilter.
get(), |
| 719 nullptr)); |
661 break; | 720 break; |
662 case DROP_SHADOW: | 721 } |
663 filter = SkDropShadowImageFilter::Create(make_scalar(), make_scalar(), m
ake_scalar(true), | 722 case MORPHOLOGY: { |
664 make_scalar(true), make_color(), make_shadow_mode(), make_im
age_filter(), | 723 sk_sp<SkImageFilter> subFilter(make_image_filter()); |
665 nullptr); | 724 |
666 break; | |
667 case MORPHOLOGY: | |
668 if (R(2) == 1) { | 725 if (R(2) == 1) { |
669 filter = SkDilateImageFilter::Create(R(static_cast<float>(kBitmapSiz
e)), | 726 filter = sk_sp<SkImageFilter>(SkDilateImageFilter::Create(R(static_c
ast<float>(kBitmapSize)), |
670 R(static_cast<float>(kBitmapSize)), make_image_filter()); | 727 R(static_cast<float>(kBitmapSize
)), |
| 728 subFilter.get())); |
671 } else { | 729 } else { |
672 filter = SkErodeImageFilter::Create(R(static_cast<float>(kBitmapSize
)), | 730 filter = sk_sp<SkImageFilter>(SkErodeImageFilter::Create(R(static_ca
st<float>(kBitmapSize)), |
673 R(static_cast<float>(kBitmapSize)), make_image_filter()); | 731 R(static_cast<float>(kBitmapSize
)), |
| 732 subFilter.get())); |
674 } | 733 } |
675 break; | 734 break; |
676 case BITMAP: | 735 } |
677 { | 736 case BITMAP: { |
678 sk_sp<SkImage> image(SkImage::MakeFromBitmap(make_bitmap())); | 737 sk_sp<SkImage> image(SkImage::MakeFromBitmap(make_bitmap())); |
679 if (R(2) == 1) { | 738 if (R(2) == 1) { |
680 filter = SkImageSource::Create(image.get(), make_rect(), make_rect()
, kHigh_SkFilterQuality); | 739 filter = sk_sp<SkImageFilter>(SkImageSource::Create(image.get(), |
| 740 make_rect(), |
| 741 make_rect(), |
| 742 kHigh_SkFilterQu
ality)); |
681 } else { | 743 } else { |
682 filter = SkImageSource::Create(image.get()); | 744 filter = sk_sp<SkImageFilter>(SkImageSource::Create(image.get())); |
683 } | 745 } |
| 746 break; |
684 } | 747 } |
| 748 case DISPLACE: { |
| 749 sk_sp<SkImageFilter> subFilter1(make_image_filter(false)); |
| 750 sk_sp<SkImageFilter> subFilter2(make_image_filter()); |
| 751 |
| 752 filter = sk_sp<SkImageFilter>(SkDisplacementMapEffect::Create(make_chann
el_selector_type(), |
| 753 make_chann
el_selector_type(), |
| 754 make_scala
r(), |
| 755 subFilter1
.get(), |
| 756 subFilter2
.get())); |
685 break; | 757 break; |
686 case DISPLACE: | 758 } |
687 filter = SkDisplacementMapEffect::Create(make_channel_selector_type(), | 759 case TILE: { |
688 make_channel_selector_type(), m
ake_scalar(), | 760 sk_sp<SkImageFilter> subFilter(make_image_filter(false)); |
689 make_image_filter(false), make_
image_filter()); | 761 |
| 762 filter = sk_sp<SkImageFilter>(SkTileImageFilter::Create(make_rect(), |
| 763 make_rect(), |
| 764 subFilter.get())
); |
690 break; | 765 break; |
691 case TILE: | 766 } |
692 filter = SkTileImageFilter::Create(make_rect(), make_rect(), make_image_
filter(false)); | 767 case PICTURE: { |
693 break; | |
694 case PICTURE: | |
695 { | |
696 SkRTreeFactory factory; | 768 SkRTreeFactory factory; |
697 SkPictureRecorder recorder; | 769 SkPictureRecorder recorder; |
698 SkCanvas* recordingCanvas = recorder.beginRecording(SkIntToScalar(kBitma
pSize), | 770 SkCanvas* recordingCanvas = recorder.beginRecording(SkIntToScalar(kBitma
pSize), |
699 SkIntToScalar(kBitma
pSize), | 771 SkIntToScalar(kBitma
pSize), |
700 &factory, 0); | 772 &factory, 0); |
701 drawSomething(recordingCanvas); | 773 drawSomething(recordingCanvas); |
702 sk_sp<SkPicture> pict(recorder.finishRecordingAsPicture()); | 774 sk_sp<SkPicture> pict(recorder.finishRecordingAsPicture()); |
703 filter = SkPictureImageFilter::Make(pict, make_rect()).release(); | 775 filter = SkPictureImageFilter::Make(pict, make_rect()); |
| 776 break; |
704 } | 777 } |
| 778 case PAINT: { |
| 779 SkImageFilter::CropRect cropR(make_rect()); |
| 780 filter = SkPaintImageFilter::Make(make_paint(), &cropR); |
705 break; | 781 break; |
706 case PAINT: | |
707 { | |
708 SkImageFilter::CropRect cropR(make_rect()); | |
709 filter = SkPaintImageFilter::Create(make_paint(), &cropR); | |
710 } | 782 } |
711 default: | 783 default: |
712 break; | 784 break; |
713 } | 785 } |
714 return (filter || canBeNull) ? filter : make_image_filter(canBeNull); | 786 return (filter || canBeNull) ? filter : make_image_filter(canBeNull); |
715 } | 787 } |
716 | 788 |
717 static SkImageFilter* make_serialized_image_filter() { | 789 static SkImageFilter* make_serialized_image_filter() { |
718 SkAutoTUnref<SkImageFilter> filter(make_image_filter(false)); | 790 sk_sp<SkImageFilter> filter(make_image_filter(false)); |
719 SkAutoTUnref<SkData> data(SkValidatingSerializeFlattenable(filter)); | 791 SkAutoTUnref<SkData> data(SkValidatingSerializeFlattenable(filter.get())); |
720 const unsigned char* ptr = static_cast<const unsigned char*>(data->data()); | 792 const unsigned char* ptr = static_cast<const unsigned char*>(data->data()); |
721 size_t len = data->size(); | 793 size_t len = data->size(); |
722 #ifdef SK_ADD_RANDOM_BIT_FLIPS | 794 #ifdef SK_ADD_RANDOM_BIT_FLIPS |
723 unsigned char* p = const_cast<unsigned char*>(ptr); | 795 unsigned char* p = const_cast<unsigned char*>(ptr); |
724 for (size_t i = 0; i < len; ++i, ++p) { | 796 for (size_t i = 0; i < len; ++i, ++p) { |
725 if (R(250) == 1) { // 0.4% of the time, flip a bit or byte | 797 if (R(250) == 1) { // 0.4% of the time, flip a bit or byte |
726 if (R(10) == 1) { // Then 10% of the time, change a whole byte | 798 if (R(10) == 1) { // Then 10% of the time, change a whole byte |
727 switch(R(3)) { | 799 switch(R(3)) { |
728 case 0: | 800 case 0: |
729 *p ^= 0xFF; // Flip entire byte | 801 *p ^= 0xFF; // Flip entire byte |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
804 } | 876 } |
805 | 877 |
806 private: | 878 private: |
807 typedef SkView INHERITED; | 879 typedef SkView INHERITED; |
808 }; | 880 }; |
809 | 881 |
810 ////////////////////////////////////////////////////////////////////////////// | 882 ////////////////////////////////////////////////////////////////////////////// |
811 | 883 |
812 static SkView* MyFactory() { return new ImageFilterFuzzView; } | 884 static SkView* MyFactory() { return new ImageFilterFuzzView; } |
813 static SkViewRegister reg(MyFactory); | 885 static SkViewRegister reg(MyFactory); |
OLD | NEW |