Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(587)

Side by Side Diff: fuzz/FilterFuzz.cpp

Issue 1710183002: Do an in-place replacement of SkRandom with Fuzz for FilterFuzz (Closed) Base URL: https://skia.googlesource.com/skia@master
Patch Set: add comment Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | fuzz/Fuzz.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "Fuzz.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"
11 #include "SkArcToPathEffect.h" 11 #include "SkArcToPathEffect.h"
12 #include "SkBlurImageFilter.h" 12 #include "SkBlurImageFilter.h"
13 #include "SkBlurMaskFilter.h" 13 #include "SkBlurMaskFilter.h"
14 #include "SkCanvas.h" 14 #include "SkCanvas.h"
15 #include "SkColorCubeFilter.h" 15 #include "SkColorCubeFilter.h"
16 #include "SkColorFilter.h" 16 #include "SkColorFilter.h"
17 #include "SkColorFilterImageFilter.h" 17 #include "SkColorFilterImageFilter.h"
(...skipping 19 matching lines...) Expand all
37 #include "SkPaintImageFilter.h" 37 #include "SkPaintImageFilter.h"
38 #include "SkPerlinNoiseShader.h" 38 #include "SkPerlinNoiseShader.h"
39 #include "SkPictureImageFilter.h" 39 #include "SkPictureImageFilter.h"
40 #include "SkPictureRecorder.h" 40 #include "SkPictureRecorder.h"
41 #include "SkPoint3.h" 41 #include "SkPoint3.h"
42 #include "SkRandom.h" 42 #include "SkRandom.h"
43 #include "SkTableColorFilter.h" 43 #include "SkTableColorFilter.h"
44 #include "SkTestImageFilters.h" 44 #include "SkTestImageFilters.h"
45 #include "SkTileImageFilter.h" 45 #include "SkTileImageFilter.h"
46 #include "SkTypeface.h" 46 #include "SkTypeface.h"
47 #include "SkView.h"
48 #include "SkXfermodeImageFilter.h" 47 #include "SkXfermodeImageFilter.h"
49 #include <stdio.h> 48 #include <stdio.h>
50 #include <time.h> 49 #include <time.h>
51 50
52 //#define SK_ADD_RANDOM_BIT_FLIPS 51 #define SK_ADD_RANDOM_BIT_FLIPS
53 //#define SK_FUZZER_IS_VERBOSE
54 52
55 static const uint32_t kSeed = (uint32_t)(time(nullptr)); 53 static Fuzz* fuzz;
56 static SkRandom gRand(kSeed); 54 static const int kBitmapSize = 24;
55
57 static bool return_large = false; 56 static bool return_large = false;
58 static bool return_undef = false; 57 static bool return_undef = false;
59 58
60 static const int kBitmapSize = 24;
61
62 static int R(float x) { 59 static int R(float x) {
63 return (int)floor(SkScalarToFloat(gRand.nextUScalar1()) * x); 60 return (int)floor(SkScalarToFloat(fuzz->nextF1()) * x);
64 } 61 }
65 62
66 #if defined _WIN32 63 #if defined _WIN32
67 #pragma warning ( push ) 64 #pragma warning ( push )
68 // we are intentionally causing an overflow here 65 // we are intentionally causing an overflow here
69 // (warning C4756: overflow in constant arithmetic) 66 // (warning C4756: overflow in constant arithmetic)
70 #pragma warning ( disable : 4756 ) 67 #pragma warning ( disable : 4756 )
71 #endif 68 #endif
72 69
73 static float huge() { 70 static float huge() {
(...skipping 501 matching lines...) Expand 10 before | Expand all | Expand 10 after
575 filter = cf ? SkColorFilterImageFilter::Make(std::move(cf), make_image_f ilter()) 572 filter = cf ? SkColorFilterImageFilter::Make(std::move(cf), make_image_f ilter())
576 : nullptr; 573 : nullptr;
577 break; 574 break;
578 } 575 }
579 case BLUR: 576 case BLUR:
580 filter = SkBlurImageFilter::Make(make_scalar(true), 577 filter = SkBlurImageFilter::Make(make_scalar(true),
581 make_scalar(true), 578 make_scalar(true),
582 make_image_filter()); 579 make_image_filter());
583 break; 580 break;
584 case MAGNIFIER: 581 case MAGNIFIER:
585 filter = sk_sp<SkImageFilter>(SkMagnifierImageFilter::Create(make_rect() , 582 filter = sk_sp<SkImageFilter>(SkMagnifierImageFilter::Create(make_rect() ,
586 make_scalar (true))); 583 make_scalar (true)));
587 break; 584 break;
588 case DOWN_SAMPLE: 585 case DOWN_SAMPLE:
589 filter = sk_sp<SkImageFilter>(SkDownSampleImageFilter::Create(make_scala r())); 586 filter = sk_sp<SkImageFilter>(SkDownSampleImageFilter::Create(make_scala r()));
590 break; 587 break;
591 case XFERMODE: { 588 case XFERMODE: {
592 sk_sp<SkImageFilter> subFilter1(make_image_filter()); 589 sk_sp<SkImageFilter> subFilter1(make_image_filter());
593 sk_sp<SkImageFilter> subFilter2(make_image_filter()); 590 sk_sp<SkImageFilter> subFilter2(make_image_filter());
594 filter = SkXfermodeImageFilter::Make(SkXfermode::Make(make_xfermode()), 591 filter = SkXfermodeImageFilter::Make(SkXfermode::Make(make_xfermode()),
595 subFilter1.get(), 592 subFilter1.get(),
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
798 } 795 }
799 796
800 static void drawClippedBitmap(SkCanvas* canvas, int x, int y, const SkPaint& pai nt) { 797 static void drawClippedBitmap(SkCanvas* canvas, int x, int y, const SkPaint& pai nt) {
801 canvas->save(); 798 canvas->save();
802 canvas->clipRect(SkRect::MakeXYWH(SkIntToScalar(x), SkIntToScalar(y), 799 canvas->clipRect(SkRect::MakeXYWH(SkIntToScalar(x), SkIntToScalar(y),
803 SkIntToScalar(kBitmapSize), SkIntToScalar(kBitmapSize))); 800 SkIntToScalar(kBitmapSize), SkIntToScalar(kBitmapSize)));
804 canvas->drawBitmap(make_bitmap(), SkIntToScalar(x), SkIntToScalar(y), &paint ); 801 canvas->drawBitmap(make_bitmap(), SkIntToScalar(x), SkIntToScalar(y), &paint );
805 canvas->restore(); 802 canvas->restore();
806 } 803 }
807 804
808 static void do_fuzz(SkCanvas* canvas) { 805 DEF_FUZZ(SerializedImageFilter, f) {
806 fuzz = f;
809 SkImageFilter* filter = make_serialized_image_filter(); 807 SkImageFilter* filter = make_serialized_image_filter();
810 808
811 #ifdef SK_FUZZER_IS_VERBOSE
812 static uint32_t numFilters = 0;
813 static uint32_t numValidFilters = 0;
814 if (0 == numFilters) {
815 printf("Fuzzing with %u\n", kSeed);
816 }
817 numFilters++;
818 if (filter) {
819 numValidFilters++;
820 }
821 printf("Filter no : %u. Valid filters so far : %u\r", numFilters, numValidFi lters);
822 fflush(stdout);
823 #endif
824
825 SkPaint paint; 809 SkPaint paint;
826 SkSafeUnref(paint.setImageFilter(filter)); 810 SkSafeUnref(paint.setImageFilter(filter));
827 drawClippedBitmap(canvas, 0, 0, paint); 811 SkBitmap bitmap;
812 SkCanvas canvas(bitmap);
813 drawClippedBitmap(&canvas, 0, 0, paint);
828 } 814 }
829
830 //////////////////////////////////////////////////////////////////////////////
831
832 class ImageFilterFuzzView : public SampleView {
833 public:
834 ImageFilterFuzzView() {
835 this->setBGColor(0xFFDDDDDD);
836 }
837
838 protected:
839 // overrides from SkEventSink
840 virtual bool onQuery(SkEvent* evt) {
841 if (SampleCode::TitleQ(*evt)) {
842 SampleCode::TitleR(evt, "ImageFilterFuzzer");
843 return true;
844 }
845 return this->INHERITED::onQuery(evt);
846 }
847
848 void drawBG(SkCanvas* canvas) {
849 canvas->drawColor(0xFFDDDDDD);
850 }
851
852 virtual void onDrawContent(SkCanvas* canvas) {
853 do_fuzz(canvas);
854 this->inval(0);
855 }
856
857 private:
858 typedef SkView INHERITED;
859 };
860
861 //////////////////////////////////////////////////////////////////////////////
862
863 static SkView* MyFactory() { return new ImageFilterFuzzView; }
864 static SkViewRegister reg(MyFactory);
OLDNEW
« no previous file with comments | « no previous file | fuzz/Fuzz.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698