From cdb4d3c81d167ecad5f2176499540097443a5b2b Mon Sep 17 00:00:00 2001 From: Kevin Lubick Date: Tue, 29 Nov 2016 11:14:39 -0500 Subject: [PATCH] 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 Commit-Queue: Kevin Lubick --- fuzz/FuzzDrawFunctions.cpp | 49 ++++++++++++++++++++++++---------------------- 1 file changed, 26 insertions(+), 23 deletions(-) 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 kMaxY = 250; 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 @@ static void init_paint(Fuzz* fuzz, SkPaint* p) { p->setStyle(static_cast(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* s) { uint8_t x, y; -- 2.7.4