static void fuzz_drawImage(Fuzz* fuzz) { SkPaint p; init_paint(fuzz, &p); sk_sp<SkSurface> surface; init_surface(fuzz, &surface); SkBitmap bmp; init_bitmap(fuzz, &bmp); sk_sp<SkImage> image(SkImage::MakeFromBitmap(bmp)); bool bl; fuzz->next(&bl); SkScalar a, b; fuzz->next(&a, &b); if (bl) { surface->getCanvas()->drawImage(image, a, b, &p); } else { SkRect dst = SkRect::MakeWH(a, b); fuzz->next(&a, &b); SkRect src = SkRect::MakeWH(a, b); uint8_t x; fuzz->nextRange(&x, 0, 1); SkCanvas::SrcRectConstraint cst = (SkCanvas::SrcRectConstraint)x; surface->getCanvas()->drawImageRect(image, src, dst, &p, cst); } }
static void init_bitmap(Fuzz* fuzz, SkBitmap* bmp) { uint8_t colorType; fuzz->nextRange(&colorType, 0, (int)kLastEnum_SkColorType); // ColorType needs to match what the system configuration is. if (colorType == kRGBA_8888_SkColorType || colorType == kBGRA_8888_SkColorType) { colorType = kN32_SkColorType; } bool b; fuzz->next(&b); SkImageInfo info = SkImageInfo::Make(kBmpSize, kBmpSize, (SkColorType)colorType, b ? kOpaque_SkAlphaType : kPremul_SkAlphaType); if (!bmp->tryAllocPixels(info)) { SkDEBUGF("Bitmap not allocated\n"); } SkColor c; fuzz->next(&c); bmp->eraseColor(c); fuzz->next(&b); SkPaint p; if (b) { init_paint(fuzz, &p); } else { fuzz->next(&c); p.setColor(c); } }
static void fuzz_drawPaint(Fuzz* fuzz) { SkPaint l, p; init_paint(fuzz, &p); sk_sp<SkSurface> surface; init_surface(fuzz, &surface); surface->getCanvas()->drawPaint(p); }
static void fuzz_drawLine(Fuzz* fuzz) { SkPaint p; init_paint(fuzz, &p); sk_sp<SkSurface> surface; init_surface(fuzz, &surface); SkScalar a, b, c, d; fuzz->next(&a, &b, &c, &d); surface->getCanvas()->drawLine(a, b, c, d, p); }
static void fuzz_drawBitmap(Fuzz* fuzz) { SkPaint p; init_paint(fuzz, &p); sk_sp<SkSurface> surface; init_surface(fuzz, &surface); SkBitmap bmp; init_bitmap(fuzz, &bmp); SkScalar a, b; fuzz->next(&a, &b); surface->getCanvas()->drawBitmap(bmp, a, b, &p); }
static void fuzz_drawText(Fuzz* fuzz, sk_sp<SkTypeface> font) { SkPaint p; init_paint(fuzz, &p); sk_sp<SkSurface> surface; init_surface(fuzz, &surface); char text[kTxtLen]; init_string(fuzz, text, kTxtLen); SkScalar x, y; fuzz->next(&x, &y); // populate pts array SkPoint pts[kPtsLen]; for (uint8_t i = 0; i < kPtsLen; ++i) { pts[i].set(x, y); x += p.getTextSize(); } p.setTypeface(font); // set text related attributes bool b; fuzz->next(&b); p.setAutohinted(b); fuzz->next(&b); p.setDevKernText(b); fuzz->next(&b); p.setEmbeddedBitmapText(b); fuzz->next(&b); p.setFakeBoldText(b); fuzz->next(&b); p.setLCDRenderText(b); fuzz->next(&b); p.setLinearText(b); fuzz->next(&b); p.setSubpixelText(b); fuzz->next(&x); p.setTextScaleX(x); fuzz->next(&x); p.setTextSkewX(x); fuzz->next(&x); p.setTextSize(x); fuzz->next(&b); p.setVerticalText(b); SkCanvas* cnv = surface->getCanvas(); cnv->drawPosText(text, (kTxtLen-1), pts, p); fuzz->next(&x); fuzz->next(&y); cnv->drawText(text, (kTxtLen-1), x, y, p); }
static void fuzz_drawPath(Fuzz* fuzz) { SkPaint p; init_paint(fuzz, &p); sk_sp<SkSurface> surface; init_surface(fuzz, &surface); // TODO(kjlubick): put the ability to fuzz a path in shared file, with // other common things (e.g. rects, lines) uint8_t i, j; fuzz->nextRange(&i, 0, 10); // set i to number of operations to perform SkPath path; SkScalar a, b, c, d, e, f; for (int k = 0; k < i; ++k) { fuzz->nextRange(&j, 0, 5); // set j to choose operation to perform switch (j) { case 0: fuzz->next(&a, &b); path.moveTo(a, b); break; case 1: fuzz->next(&a, &b); path.lineTo(a, b); break; case 2: fuzz->next(&a, &b, &c, &d); path.quadTo(a, b, c, d); break; case 3: fuzz->next(&a, &b, &c, &d, &e); path.conicTo(a, b, c, d, e); break; case 4: fuzz->next(&a, &b, &c, &d, &e, &f); path.cubicTo(a, b, c, d, e, f); break; case 5: fuzz->next(&a, &b, &c, &d, &e); path.arcTo(a, b, c, d, e); break; } } path.close(); SkCanvas* cnv = surface->getCanvas(); cnv->drawPath(path, p); bool bl; fuzz->next(&bl); cnv->clipPath(path, kIntersect_SkClipOp, bl); }
static void fuzz_drawText(Fuzz* fuzz, sk_sp<SkTypeface> typeface) { SkFont font(typeface); SkPaint p; init_paint(fuzz, &p); sk_sp<SkSurface> surface; init_surface(fuzz, &surface); char text[kTxtLen]; init_string(fuzz, text, kTxtLen); SkScalar x, y; fuzz->next(&x, &y); // populate pts array SkPoint pts[kPtsLen]; for (uint8_t i = 0; i < kPtsLen; ++i) { pts[i].set(x, y); x += font.getSize(); } bool b; fuzz->next(&b); font.setForceAutoHinting(b); fuzz->next(&b); font.setEmbeddedBitmaps(b); fuzz->next(&b); font.setEmbolden(b); fuzz->next(&b); font.setEdging(b ? SkFont::Edging::kAntiAlias : SkFont::Edging::kSubpixelAntiAlias); fuzz->next(&b); font.setLinearMetrics(b); fuzz->next(&b); font.setSubpixel(b); fuzz->next(&x); font.setScaleX(x); fuzz->next(&x); font.setSkewX(x); fuzz->next(&x); font.setSize(x); SkCanvas* cnv = surface->getCanvas(); fuzz->next(&x); fuzz->next(&y); cnv->drawTextBlob(SkTextBlob::MakeFromPosText(text, kTxtLen-1, pts, font), x, y, p); }
static void fuzz_drawRect(Fuzz* fuzz) { SkPaint p; init_paint(fuzz, &p); sk_sp<SkSurface> surface; init_surface(fuzz, &surface); SkScalar a, b, c, d; fuzz->next(&a, &b, &c, &d); SkRect r; r = SkRect::MakeXYWH(a, b, c, d); SkCanvas* cnv = surface->getCanvas(); cnv->drawRect(r, p); bool bl; fuzz->next(&bl); fuzz->next(&a, &b, &c, &d); r = SkRect::MakeXYWH(a, b, c, d); cnv->clipRect(r, kIntersect_SkClipOp, bl); }