Fix DrawFunctions fuzzer to initialize bitmaps
Patch by twsmith@mozilla.com
BUG=skia:5997
Change-Id: I3d4edd9fa5c8f5f2a5184d42b1c4944a1353556f
Reviewed-on: https://skia-review.googlesource.com/5304
Reviewed-by: twsmith@mozilla.com <twsmith@mozilla.com>
Commit-Queue: Kevin Lubick <kjlubick@google.com>
diff --git a/fuzz/FuzzDrawFunctions.cpp b/fuzz/FuzzDrawFunctions.cpp
index b73bbf9..c14b29a 100644
--- a/fuzz/FuzzDrawFunctions.cpp
+++ b/fuzz/FuzzDrawFunctions.cpp
@@ -20,29 +20,6 @@
static const int kPtsLen = 10;
static const int kTxtLen = 5;
-static void init_bitmap(Fuzz* fuzz, SkBitmap* bmp) {
- uint8_t colorType;
- fuzz->nextRange(&colorType, 0, (int)kLastEnum_SkColorType);
- SkImageInfo info = SkImageInfo::Make(kBmpSize,
- kBmpSize,
- (SkColorType)colorType,
- kPremul_SkAlphaType);
- if (!bmp->tryAllocPixels(info)) {
- SkDebugf("Bitmap not allocated\n");
- }
- bool b;
- fuzz->next(&b);
- if (b) { // initialize
- SkCanvas canvas(*bmp);
- canvas.clear(0);
- SkColor c;
- fuzz->next(&c);
- SkPaint p; // TODO: maybe init_paint?
- p.setColor(c);
- canvas.drawRect(SkRect::MakeXYWH(0, 0, kBmpSize, kBmpSize), p);
- }
-}
-
static void init_string(Fuzz* fuzz, char* str, size_t bufSize) {
for (size_t i = 0; i < bufSize-1; ++i) {
fuzz->nextRange(&str[i], 0x20, 0x7E); // printable ASCII
@@ -90,6 +67,32 @@
p->setStyle(static_cast<SkPaint::Style>(tmp_u8));
}
+static void init_bitmap(Fuzz* fuzz, SkBitmap* bmp) {
+ uint8_t colorType;
+ fuzz->nextRange(&colorType, 0, (int)kLastEnum_SkColorType);
+ SkImageInfo info = SkImageInfo::Make(kBmpSize,
+ kBmpSize,
+ (SkColorType)colorType,
+ kPremul_SkAlphaType);
+ if (!bmp->tryAllocPixels(info)) {
+ SkDebugf("Bitmap not allocated\n");
+ }
+ SkCanvas canvas(*bmp);
+ canvas.clear(0);
+
+ bool b;
+ fuzz->next(&b);
+ SkPaint p;
+ if (b) {
+ init_paint(fuzz, &p);
+ }
+ else {
+ SkColor c;
+ fuzz->next(&c);
+ p.setColor(c);
+ }
+ canvas.drawRect(SkRect::MakeXYWH(0, 0, kBmpSize, kBmpSize), p);
+}
static void init_surface(Fuzz* fuzz, sk_sp<SkSurface>* s) {
uint8_t x, y;