Index: fuzz/FilterFuzz.cpp |
diff --git a/samplecode/SampleFilterFuzz.cpp b/fuzz/FilterFuzz.cpp |
similarity index 94% |
copy from samplecode/SampleFilterFuzz.cpp |
copy to fuzz/FilterFuzz.cpp |
index 2be6c318891c4239673e8621a01749770660fad0..7a50b8a85e3653637e6fa67fe9b04b9457b8fe21 100644 |
--- a/samplecode/SampleFilterFuzz.cpp |
+++ b/fuzz/FilterFuzz.cpp |
@@ -4,7 +4,7 @@ |
* Use of this source code is governed by a BSD-style license that can be |
* found in the LICENSE file. |
*/ |
-#include "SampleCode.h" |
+#include "Fuzz.h" |
#include "Sk1DPathEffect.h" |
#include "Sk2DPathEffect.h" |
#include "SkAlphaThresholdFilter.h" |
@@ -44,23 +44,20 @@ |
#include "SkTestImageFilters.h" |
#include "SkTileImageFilter.h" |
#include "SkTypeface.h" |
-#include "SkView.h" |
#include "SkXfermodeImageFilter.h" |
#include <stdio.h> |
#include <time.h> |
-//#define SK_ADD_RANDOM_BIT_FLIPS |
-//#define SK_FUZZER_IS_VERBOSE |
+#define SK_ADD_RANDOM_BIT_FLIPS |
+ |
+static Fuzz* fuzz; |
+static const int kBitmapSize = 24; |
-static const uint32_t kSeed = (uint32_t)(time(nullptr)); |
-static SkRandom gRand(kSeed); |
static bool return_large = false; |
static bool return_undef = false; |
-static const int kBitmapSize = 24; |
- |
static int R(float x) { |
- return (int)floor(SkScalarToFloat(gRand.nextUScalar1()) * x); |
+ return (int)floor(SkScalarToFloat(fuzz->nextF1()) * x); |
} |
#if defined _WIN32 |
@@ -582,7 +579,7 @@ static sk_sp<SkImageFilter> make_image_filter(bool canBeNull) { |
make_image_filter()); |
break; |
case MAGNIFIER: |
- filter = sk_sp<SkImageFilter>(SkMagnifierImageFilter::Create(make_rect(), |
+ filter = sk_sp<SkImageFilter>(SkMagnifierImageFilter::Create(make_rect(), |
make_scalar(true))); |
break; |
case DOWN_SAMPLE: |
@@ -805,60 +802,13 @@ static void drawClippedBitmap(SkCanvas* canvas, int x, int y, const SkPaint& pai |
canvas->restore(); |
} |
-static void do_fuzz(SkCanvas* canvas) { |
+DEF_FUZZ(SerializedImageFilter, f) { |
+ fuzz = f; |
SkImageFilter* filter = make_serialized_image_filter(); |
-#ifdef SK_FUZZER_IS_VERBOSE |
- static uint32_t numFilters = 0; |
- static uint32_t numValidFilters = 0; |
- if (0 == numFilters) { |
- printf("Fuzzing with %u\n", kSeed); |
- } |
- numFilters++; |
- if (filter) { |
- numValidFilters++; |
- } |
- printf("Filter no : %u. Valid filters so far : %u\r", numFilters, numValidFilters); |
- fflush(stdout); |
-#endif |
- |
SkPaint paint; |
SkSafeUnref(paint.setImageFilter(filter)); |
- drawClippedBitmap(canvas, 0, 0, paint); |
+ SkBitmap bitmap; |
+ SkCanvas canvas(bitmap); |
+ drawClippedBitmap(&canvas, 0, 0, paint); |
} |
- |
-////////////////////////////////////////////////////////////////////////////// |
- |
-class ImageFilterFuzzView : public SampleView { |
-public: |
- ImageFilterFuzzView() { |
- this->setBGColor(0xFFDDDDDD); |
- } |
- |
-protected: |
- // overrides from SkEventSink |
- virtual bool onQuery(SkEvent* evt) { |
- if (SampleCode::TitleQ(*evt)) { |
- SampleCode::TitleR(evt, "ImageFilterFuzzer"); |
- return true; |
- } |
- return this->INHERITED::onQuery(evt); |
- } |
- |
- void drawBG(SkCanvas* canvas) { |
- canvas->drawColor(0xFFDDDDDD); |
- } |
- |
- virtual void onDrawContent(SkCanvas* canvas) { |
- do_fuzz(canvas); |
- this->inval(0); |
- } |
- |
-private: |
- typedef SkView INHERITED; |
-}; |
- |
-////////////////////////////////////////////////////////////////////////////// |
- |
-static SkView* MyFactory() { return new ImageFilterFuzzView; } |
-static SkViewRegister reg(MyFactory); |