2017-02-14 18:35:14 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2017 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "Fuzz.h"
|
|
|
|
|
|
|
|
// CORE
|
|
|
|
#include "SkCanvas.h"
|
|
|
|
#include "SkColorFilter.h"
|
2017-03-01 15:42:45 +00:00
|
|
|
#include "SkDebugCanvas.h"
|
|
|
|
#include "SkDocument.h"
|
2017-02-27 18:36:38 +00:00
|
|
|
#include "SkFontMgr.h"
|
2017-02-14 18:35:14 +00:00
|
|
|
#include "SkImageFilter.h"
|
|
|
|
#include "SkMaskFilter.h"
|
2017-03-01 15:42:45 +00:00
|
|
|
#include "SkNullCanvas.h"
|
2017-02-14 18:35:14 +00:00
|
|
|
#include "SkPathEffect.h"
|
|
|
|
#include "SkPictureRecorder.h"
|
2017-03-08 21:52:18 +00:00
|
|
|
#include "SkRSXform.h"
|
2017-02-14 18:35:14 +00:00
|
|
|
#include "SkRegion.h"
|
2017-03-01 15:42:45 +00:00
|
|
|
#include "SkSurface.h"
|
2017-02-14 18:35:14 +00:00
|
|
|
#include "SkTypeface.h"
|
|
|
|
|
|
|
|
// EFFECTS
|
2017-03-08 21:52:18 +00:00
|
|
|
#include "Sk1DPathEffect.h"
|
|
|
|
#include "Sk2DPathEffect.h"
|
2017-03-09 16:33:35 +00:00
|
|
|
#include "SkAlphaThresholdFilter.h"
|
2017-03-08 21:52:18 +00:00
|
|
|
#include "SkArcToPathEffect.h"
|
2017-03-09 16:33:35 +00:00
|
|
|
#include "SkArithmeticImageFilter.h"
|
2017-03-08 21:52:18 +00:00
|
|
|
#include "SkBlurMaskFilter.h"
|
2017-03-09 16:33:35 +00:00
|
|
|
#include "SkColorFilterImageFilter.h"
|
2017-03-07 21:23:20 +00:00
|
|
|
#include "SkColorMatrixFilter.h"
|
2017-03-09 16:33:35 +00:00
|
|
|
#include "SkComposeImageFilter.h"
|
2017-03-08 21:52:18 +00:00
|
|
|
#include "SkCornerPathEffect.h"
|
|
|
|
#include "SkDashPathEffect.h"
|
|
|
|
#include "SkDiscretePathEffect.h"
|
2017-03-09 16:33:35 +00:00
|
|
|
#include "SkDisplacementMapEffect.h"
|
|
|
|
#include "SkDropShadowImageFilter.h"
|
2017-02-14 18:35:14 +00:00
|
|
|
#include "SkGradientShader.h"
|
2017-03-07 21:23:20 +00:00
|
|
|
#include "SkHighContrastFilter.h"
|
2017-03-09 16:33:35 +00:00
|
|
|
#include "SkImageSource.h"
|
|
|
|
#include "SkLightingImageFilter.h"
|
2017-03-07 21:23:20 +00:00
|
|
|
#include "SkLumaColorFilter.h"
|
2017-03-09 16:33:35 +00:00
|
|
|
#include "SkMagnifierImageFilter.h"
|
|
|
|
#include "SkMatrixConvolutionImageFilter.h"
|
|
|
|
#include "SkMergeImageFilter.h"
|
|
|
|
#include "SkMorphologyImageFilter.h"
|
|
|
|
#include "SkOffsetImageFilter.h"
|
|
|
|
#include "SkPaintImageFilter.h"
|
2017-02-14 18:35:14 +00:00
|
|
|
#include "SkPerlinNoiseShader.h"
|
2017-03-09 16:33:35 +00:00
|
|
|
#include "SkPictureImageFilter.h"
|
2017-03-08 21:52:18 +00:00
|
|
|
#include "SkRRectsGaussianEdgeMaskFilter.h"
|
2017-03-07 21:23:20 +00:00
|
|
|
#include "SkTableColorFilter.h"
|
2017-05-16 14:39:06 +00:00
|
|
|
#include "SkTextBlob.h"
|
2017-03-09 16:33:35 +00:00
|
|
|
#include "SkTileImageFilter.h"
|
|
|
|
#include "SkXfermodeImageFilter.h"
|
2017-02-14 18:35:14 +00:00
|
|
|
|
|
|
|
// SRC
|
|
|
|
#include "SkUtils.h"
|
|
|
|
|
2017-03-15 15:39:06 +00:00
|
|
|
#if SK_SUPPORT_GPU
|
|
|
|
#include "GrContextFactory.h"
|
|
|
|
#endif
|
|
|
|
|
2017-03-01 15:42:45 +00:00
|
|
|
// MISC
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
|
2017-02-14 18:35:14 +00:00
|
|
|
// TODO:
|
2017-03-08 21:52:18 +00:00
|
|
|
// SkTextBlob with Unicode
|
2017-03-15 15:39:06 +00:00
|
|
|
// SkImage: more types
|
2017-02-14 18:35:14 +00:00
|
|
|
|
2017-03-10 13:48:28 +00:00
|
|
|
template <typename T, typename Min, typename Max>
|
|
|
|
inline void fuzz_enum_range(Fuzz* fuzz, T* value, Min rmin, Max rmax) {
|
2017-02-14 18:35:14 +00:00
|
|
|
using U = skstd::underlying_type_t<T>;
|
2017-03-10 13:48:28 +00:00
|
|
|
fuzz->nextRange((U*)value, (U)rmin, (U)rmax);
|
|
|
|
}
|
|
|
|
|
2017-03-10 18:56:08 +00:00
|
|
|
// be careful: `foo(make_fuzz_t<T>(f), make_fuzz_t<U>(f))` is undefined.
|
|
|
|
// In fact, all make_fuzz_foo() functions have this potential problem.
|
|
|
|
// Use sequence points!
|
|
|
|
template <typename T>
|
|
|
|
inline T make_fuzz_t(Fuzz* fuzz) {
|
|
|
|
T t;
|
|
|
|
fuzz->next(&t);
|
|
|
|
return t;
|
2017-02-14 18:35:14 +00:00
|
|
|
}
|
|
|
|
|
2017-03-10 18:56:08 +00:00
|
|
|
// We don't always want to test NaNs and infinities.
|
2017-03-06 13:30:44 +00:00
|
|
|
static void fuzz_nice_float(Fuzz* fuzz, float* f) {
|
2017-03-10 18:56:08 +00:00
|
|
|
float v;
|
|
|
|
fuzz->next(&v);
|
|
|
|
constexpr float kLimit = 1.0e35f; // FLT_MAX?
|
|
|
|
*f = (v == v && v <= kLimit && v >= -kLimit) ? v : 0.0f;
|
2017-03-06 13:30:44 +00:00
|
|
|
}
|
2017-02-14 18:35:14 +00:00
|
|
|
|
2017-03-06 13:30:44 +00:00
|
|
|
template <typename... Args>
|
2017-03-10 18:56:08 +00:00
|
|
|
inline void fuzz_nice_float(Fuzz* fuzz, float* f, Args... rest) {
|
2017-03-06 13:30:44 +00:00
|
|
|
fuzz_nice_float(fuzz, f);
|
|
|
|
fuzz_nice_float(fuzz, rest...);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void fuzz_path(Fuzz* fuzz, SkPath* path, int maxOps) {
|
|
|
|
if (maxOps < 2) {
|
|
|
|
maxOps = 2;
|
|
|
|
}
|
2017-02-14 18:35:14 +00:00
|
|
|
uint8_t fillType;
|
|
|
|
fuzz->nextRange(&fillType, 0, (uint8_t)SkPath::kInverseEvenOdd_FillType);
|
|
|
|
path->setFillType((SkPath::FillType)fillType);
|
|
|
|
uint8_t numOps;
|
2017-03-06 13:30:44 +00:00
|
|
|
fuzz->nextRange(&numOps, 2, maxOps);
|
2017-02-14 18:35:14 +00:00
|
|
|
for (uint8_t i = 0; i < numOps; ++i) {
|
|
|
|
uint8_t op;
|
|
|
|
fuzz->nextRange(&op, 0, 6);
|
|
|
|
SkScalar a, b, c, d, e, f;
|
|
|
|
switch (op) {
|
|
|
|
case 0:
|
2017-03-06 13:30:44 +00:00
|
|
|
fuzz_nice_float(fuzz, &a, &b);
|
2017-02-14 18:35:14 +00:00
|
|
|
path->moveTo(a, b);
|
|
|
|
break;
|
|
|
|
case 1:
|
2017-03-06 13:30:44 +00:00
|
|
|
fuzz_nice_float(fuzz, &a, &b);
|
2017-02-14 18:35:14 +00:00
|
|
|
path->lineTo(a, b);
|
|
|
|
break;
|
|
|
|
case 2:
|
2017-03-06 13:30:44 +00:00
|
|
|
fuzz_nice_float(fuzz, &a, &b, &c, &d);
|
2017-02-14 18:35:14 +00:00
|
|
|
path->quadTo(a, b, c, d);
|
|
|
|
break;
|
|
|
|
case 3:
|
2017-03-06 13:30:44 +00:00
|
|
|
fuzz_nice_float(fuzz, &a, &b, &c, &d, &e);
|
2017-02-14 18:35:14 +00:00
|
|
|
path->conicTo(a, b, c, d, e);
|
|
|
|
break;
|
|
|
|
case 4:
|
2017-03-06 13:30:44 +00:00
|
|
|
fuzz_nice_float(fuzz, &a, &b, &c, &d, &e, &f);
|
2017-02-14 18:35:14 +00:00
|
|
|
path->cubicTo(a, b, c, d, e, f);
|
|
|
|
break;
|
|
|
|
case 5:
|
2017-03-06 13:30:44 +00:00
|
|
|
fuzz_nice_float(fuzz, &a, &b, &c, &d, &e);
|
2017-02-14 18:35:14 +00:00
|
|
|
path->arcTo(a, b, c, d, e);
|
|
|
|
break;
|
|
|
|
case 6:
|
|
|
|
path->close();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-09 16:33:35 +00:00
|
|
|
template <>
|
|
|
|
inline void Fuzz::next(SkRegion* region) {
|
2017-02-14 18:35:14 +00:00
|
|
|
uint8_t N;
|
2017-03-09 16:33:35 +00:00
|
|
|
this->nextRange(&N, 0, 10);
|
2017-02-14 18:35:14 +00:00
|
|
|
for (uint8_t i = 0; i < N; ++i) {
|
|
|
|
SkIRect r;
|
|
|
|
uint8_t op;
|
2017-03-09 16:33:35 +00:00
|
|
|
this->next(&r);
|
2017-02-14 18:35:14 +00:00
|
|
|
r.sort();
|
2017-03-09 16:33:35 +00:00
|
|
|
this->nextRange(&op, 0, (uint8_t)SkRegion::kLastOp);
|
2017-02-14 18:35:14 +00:00
|
|
|
if (!region->op(r, (SkRegion::Op)op)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-08 16:02:40 +00:00
|
|
|
template <>
|
|
|
|
inline void Fuzz::next(SkShader::TileMode* m) {
|
2017-03-10 13:48:28 +00:00
|
|
|
fuzz_enum_range(this, m, 0, SkShader::kTileModeCount - 1);
|
2017-02-14 18:35:14 +00:00
|
|
|
}
|
|
|
|
|
2017-03-09 16:33:35 +00:00
|
|
|
template <>
|
|
|
|
inline void Fuzz::next(SkFilterQuality* q) {
|
2017-03-10 13:48:28 +00:00
|
|
|
fuzz_enum_range(this, q, SkFilterQuality::kNone_SkFilterQuality,
|
|
|
|
SkFilterQuality::kLast_SkFilterQuality);
|
2017-03-09 16:33:35 +00:00
|
|
|
}
|
|
|
|
|
2017-03-08 16:02:40 +00:00
|
|
|
template <>
|
|
|
|
inline void Fuzz::next(SkMatrix* m) {
|
2017-02-14 18:35:14 +00:00
|
|
|
constexpr int kArrayLength = 9;
|
|
|
|
SkScalar buffer[kArrayLength];
|
|
|
|
int matrixType;
|
|
|
|
this->nextRange(&matrixType, 0, 4);
|
|
|
|
switch (matrixType) {
|
|
|
|
case 0: // identity
|
|
|
|
*m = SkMatrix::I();
|
|
|
|
return;
|
|
|
|
case 1: // translate
|
|
|
|
this->nextRange(&buffer[0], -4000.0f, 4000.0f);
|
|
|
|
this->nextRange(&buffer[1], -4000.0f, 4000.0f);
|
|
|
|
*m = SkMatrix::MakeTrans(buffer[0], buffer[1]);
|
|
|
|
return;
|
|
|
|
case 2: // translate + scale
|
|
|
|
this->nextRange(&buffer[0], -400.0f, 400.0f);
|
|
|
|
this->nextRange(&buffer[1], -400.0f, 400.0f);
|
|
|
|
this->nextRange(&buffer[2], -4000.0f, 4000.0f);
|
|
|
|
this->nextRange(&buffer[3], -4000.0f, 4000.0f);
|
|
|
|
*m = SkMatrix::MakeScale(buffer[0], buffer[1]);
|
|
|
|
m->postTranslate(buffer[2], buffer[3]);
|
|
|
|
return;
|
|
|
|
case 3: // affine
|
|
|
|
this->nextN(buffer, 6);
|
|
|
|
m->setAffine(buffer);
|
|
|
|
return;
|
|
|
|
case 4: // perspective
|
|
|
|
this->nextN(buffer, kArrayLength);
|
|
|
|
m->set9(buffer);
|
|
|
|
return;
|
|
|
|
default:
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-08 16:02:40 +00:00
|
|
|
template <>
|
|
|
|
inline void Fuzz::next(SkRRect* rr) {
|
2017-02-14 18:35:14 +00:00
|
|
|
SkRect r;
|
|
|
|
SkVector radii[4];
|
|
|
|
this->next(&r);
|
2017-03-07 21:23:20 +00:00
|
|
|
r.sort();
|
|
|
|
for (SkVector& vec : radii) {
|
|
|
|
this->nextRange(&vec.fX, 0.0f, 1.0f);
|
|
|
|
vec.fX *= 0.5f * r.width();
|
|
|
|
this->nextRange(&vec.fY, 0.0f, 1.0f);
|
|
|
|
vec.fY *= 0.5f * r.height();
|
|
|
|
}
|
2017-02-14 18:35:14 +00:00
|
|
|
rr->setRectRadii(r, radii);
|
|
|
|
}
|
|
|
|
|
2017-03-08 16:02:40 +00:00
|
|
|
template <>
|
|
|
|
inline void Fuzz::next(SkBlendMode* mode) {
|
2017-03-10 13:48:28 +00:00
|
|
|
fuzz_enum_range(this, mode, 0, SkBlendMode::kLastMode);
|
2017-02-14 18:35:14 +00:00
|
|
|
}
|
|
|
|
|
2017-03-10 18:56:08 +00:00
|
|
|
static sk_sp<SkImage> make_fuzz_image(Fuzz*);
|
2017-02-27 18:36:38 +00:00
|
|
|
|
2017-03-10 18:56:08 +00:00
|
|
|
static SkBitmap make_fuzz_bitmap(Fuzz*);
|
2017-02-14 18:35:14 +00:00
|
|
|
|
2017-03-10 18:56:08 +00:00
|
|
|
static sk_sp<SkPicture> make_fuzz_picture(Fuzz*, int depth);
|
2017-02-27 18:36:38 +00:00
|
|
|
|
2017-03-10 18:56:08 +00:00
|
|
|
static sk_sp<SkColorFilter> make_fuzz_colorfilter(Fuzz* fuzz, int depth) {
|
2017-03-07 21:23:20 +00:00
|
|
|
if (depth <= 0) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
int colorFilterType;
|
|
|
|
fuzz->nextRange(&colorFilterType, 0, 8);
|
|
|
|
switch (colorFilterType) {
|
|
|
|
case 0:
|
|
|
|
return nullptr;
|
|
|
|
case 1: {
|
|
|
|
SkColor color;
|
|
|
|
SkBlendMode mode;
|
|
|
|
fuzz->next(&color, &mode);
|
|
|
|
return SkColorFilter::MakeModeFilter(color, mode);
|
|
|
|
}
|
|
|
|
case 2: {
|
2017-03-10 18:56:08 +00:00
|
|
|
sk_sp<SkColorFilter> outer = make_fuzz_colorfilter(fuzz, depth - 1);
|
|
|
|
sk_sp<SkColorFilter> inner = make_fuzz_colorfilter(fuzz, depth - 1);
|
2017-03-07 21:23:20 +00:00
|
|
|
return SkColorFilter::MakeComposeFilter(std::move(outer), std::move(inner));
|
|
|
|
}
|
|
|
|
case 3: {
|
|
|
|
SkScalar array[20];
|
|
|
|
fuzz->nextN(array, SK_ARRAY_COUNT(array));
|
|
|
|
return SkColorFilter::MakeMatrixFilterRowMajor255(array);
|
|
|
|
}
|
|
|
|
case 4: {
|
|
|
|
SkColor mul, add;
|
|
|
|
fuzz->next(&mul, &add);
|
|
|
|
return SkColorMatrixFilter::MakeLightingFilter(mul, add);
|
|
|
|
}
|
|
|
|
case 5: {
|
|
|
|
bool grayscale;
|
|
|
|
int invertStyle;
|
|
|
|
float contrast;
|
|
|
|
fuzz->next(&grayscale);
|
|
|
|
fuzz->nextRange(&invertStyle, 0, 2);
|
|
|
|
fuzz->nextRange(&contrast, -1.0f, 1.0f);
|
|
|
|
return SkHighContrastFilter::Make(SkHighContrastConfig(
|
|
|
|
grayscale, SkHighContrastConfig::InvertStyle(invertStyle), contrast));
|
|
|
|
}
|
|
|
|
case 6:
|
|
|
|
return SkLumaColorFilter::Make();
|
|
|
|
case 7: {
|
|
|
|
uint8_t table[256];
|
|
|
|
fuzz->nextN(table, SK_ARRAY_COUNT(table));
|
|
|
|
return SkTableColorFilter::Make(table);
|
|
|
|
}
|
|
|
|
case 8: {
|
|
|
|
uint8_t tableA[256];
|
|
|
|
uint8_t tableR[256];
|
|
|
|
uint8_t tableG[256];
|
|
|
|
uint8_t tableB[256];
|
|
|
|
fuzz->nextN(tableA, SK_ARRAY_COUNT(tableA));
|
|
|
|
fuzz->nextN(tableR, SK_ARRAY_COUNT(tableR));
|
|
|
|
fuzz->nextN(tableG, SK_ARRAY_COUNT(tableG));
|
|
|
|
fuzz->nextN(tableB, SK_ARRAY_COUNT(tableB));
|
|
|
|
return SkTableColorFilter::MakeARGB(tableA, tableR, tableG, tableB);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
2017-02-14 18:35:14 +00:00
|
|
|
|
2017-03-10 18:56:08 +00:00
|
|
|
static void fuzz_gradient_stops(Fuzz* fuzz, SkScalar* pos, int colorCount) {
|
2017-02-14 18:35:14 +00:00
|
|
|
SkScalar totalPos = 0;
|
|
|
|
for (int i = 0; i < colorCount; ++i) {
|
|
|
|
fuzz->nextRange(&pos[i], 1.0f, 1024.0f);
|
|
|
|
totalPos += pos[i];
|
|
|
|
}
|
|
|
|
totalPos = 1.0f / totalPos;
|
|
|
|
for (int i = 0; i < colorCount; ++i) {
|
|
|
|
pos[i] *= totalPos;
|
|
|
|
}
|
2017-03-08 16:02:40 +00:00
|
|
|
// SkASSERT(fabs(pos[colorCount - 1] - 1.0f) < 0.00001f);
|
2017-02-14 18:35:14 +00:00
|
|
|
pos[colorCount - 1] = 1.0f;
|
|
|
|
}
|
|
|
|
|
2017-03-10 18:56:08 +00:00
|
|
|
static sk_sp<SkShader> make_fuzz_shader(Fuzz* fuzz, int depth) {
|
2017-02-14 18:35:14 +00:00
|
|
|
sk_sp<SkShader> shader1(nullptr), shader2(nullptr);
|
|
|
|
sk_sp<SkColorFilter> colorFilter(nullptr);
|
|
|
|
SkBitmap bitmap;
|
|
|
|
sk_sp<SkImage> img;
|
|
|
|
SkShader::TileMode tmX, tmY;
|
|
|
|
bool useMatrix;
|
|
|
|
SkColor color;
|
|
|
|
SkMatrix matrix;
|
|
|
|
SkBlendMode blendMode;
|
|
|
|
int shaderType;
|
|
|
|
if (depth <= 0) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2017-02-27 18:36:38 +00:00
|
|
|
fuzz->nextRange(&shaderType, 0, 14);
|
2017-02-14 18:35:14 +00:00
|
|
|
switch (shaderType) {
|
|
|
|
case 0:
|
|
|
|
return nullptr;
|
|
|
|
case 1:
|
|
|
|
return SkShader::MakeEmptyShader();
|
|
|
|
case 2:
|
|
|
|
fuzz->next(&color);
|
|
|
|
return SkShader::MakeColorShader(color);
|
|
|
|
case 3:
|
2017-03-10 18:56:08 +00:00
|
|
|
img = make_fuzz_image(fuzz);
|
2017-02-14 18:35:14 +00:00
|
|
|
fuzz->next(&tmX, &tmY, &useMatrix);
|
|
|
|
if (useMatrix) {
|
|
|
|
fuzz->next(&matrix);
|
|
|
|
}
|
|
|
|
return img->makeShader(tmX, tmY, useMatrix ? &matrix : nullptr);
|
|
|
|
case 4:
|
2017-03-10 18:56:08 +00:00
|
|
|
bitmap = make_fuzz_bitmap(fuzz);
|
2017-02-14 18:35:14 +00:00
|
|
|
fuzz->next(&tmX, &tmY, &useMatrix);
|
|
|
|
if (useMatrix) {
|
|
|
|
fuzz->next(&matrix);
|
|
|
|
}
|
|
|
|
return SkShader::MakeBitmapShader(bitmap, tmX, tmY, useMatrix ? &matrix : nullptr);
|
|
|
|
case 5:
|
2017-03-10 18:56:08 +00:00
|
|
|
shader1 = make_fuzz_shader(fuzz, depth - 1); // limit recursion.
|
2017-02-14 18:35:14 +00:00
|
|
|
fuzz->next(&matrix);
|
|
|
|
return shader1 ? shader1->makeWithLocalMatrix(matrix) : nullptr;
|
|
|
|
case 6:
|
2017-03-10 18:56:08 +00:00
|
|
|
shader1 = make_fuzz_shader(fuzz, depth - 1); // limit recursion.
|
|
|
|
colorFilter = make_fuzz_colorfilter(fuzz, depth - 1);
|
2017-02-14 18:35:14 +00:00
|
|
|
return shader1 ? shader1->makeWithColorFilter(std::move(colorFilter)) : nullptr;
|
|
|
|
case 7:
|
2017-03-10 18:56:08 +00:00
|
|
|
shader1 = make_fuzz_shader(fuzz, depth - 1); // limit recursion.
|
|
|
|
shader2 = make_fuzz_shader(fuzz, depth - 1);
|
2017-02-14 18:35:14 +00:00
|
|
|
fuzz->next(&blendMode);
|
|
|
|
return SkShader::MakeComposeShader(std::move(shader1), std::move(shader2), blendMode);
|
2017-03-08 16:02:40 +00:00
|
|
|
case 8: {
|
2017-03-10 18:56:08 +00:00
|
|
|
auto pic = make_fuzz_picture(fuzz, depth - 1);
|
2017-03-08 16:02:40 +00:00
|
|
|
bool useTile;
|
|
|
|
SkRect tile;
|
|
|
|
fuzz->next(&tmX, &tmY, &useMatrix, &useTile);
|
|
|
|
if (useMatrix) {
|
|
|
|
fuzz->next(&matrix);
|
|
|
|
}
|
|
|
|
if (useTile) {
|
|
|
|
fuzz->next(&tile);
|
2017-02-27 18:36:38 +00:00
|
|
|
}
|
2017-03-08 16:02:40 +00:00
|
|
|
return SkShader::MakePictureShader(std::move(pic), tmX, tmY,
|
|
|
|
useMatrix ? &matrix : nullptr,
|
|
|
|
useTile ? &tile : nullptr);
|
|
|
|
}
|
2017-02-27 18:36:38 +00:00
|
|
|
// EFFECTS:
|
2017-02-14 18:35:14 +00:00
|
|
|
case 9:
|
2017-05-31 14:20:12 +00:00
|
|
|
// Deprecated SkGaussianEdgeShader
|
|
|
|
return nullptr;
|
2017-03-08 16:02:40 +00:00
|
|
|
case 10: {
|
|
|
|
constexpr int kMaxColors = 12;
|
|
|
|
SkPoint pts[2];
|
|
|
|
SkColor colors[kMaxColors];
|
|
|
|
SkScalar pos[kMaxColors];
|
|
|
|
int colorCount;
|
|
|
|
bool usePos;
|
|
|
|
fuzz->nextN(pts, 2);
|
|
|
|
fuzz->nextRange(&colorCount, 2, kMaxColors);
|
|
|
|
fuzz->nextN(colors, colorCount);
|
|
|
|
fuzz->next(&tmX, &useMatrix, &usePos);
|
|
|
|
if (useMatrix) {
|
|
|
|
fuzz->next(&matrix);
|
2017-02-14 18:35:14 +00:00
|
|
|
}
|
2017-03-08 16:02:40 +00:00
|
|
|
if (usePos) {
|
2017-03-10 18:56:08 +00:00
|
|
|
fuzz_gradient_stops(fuzz, pos, colorCount);
|
2017-03-08 16:02:40 +00:00
|
|
|
}
|
|
|
|
return SkGradientShader::MakeLinear(pts, colors, usePos ? pos : nullptr, colorCount,
|
|
|
|
tmX, 0, useMatrix ? &matrix : nullptr);
|
|
|
|
}
|
|
|
|
case 11: {
|
|
|
|
constexpr int kMaxColors = 12;
|
|
|
|
SkPoint center;
|
|
|
|
SkScalar radius;
|
|
|
|
int colorCount;
|
|
|
|
bool usePos;
|
|
|
|
SkColor colors[kMaxColors];
|
|
|
|
SkScalar pos[kMaxColors];
|
|
|
|
fuzz->next(&tmX, &useMatrix, &usePos, ¢er, &radius);
|
|
|
|
fuzz->nextRange(&colorCount, 2, kMaxColors);
|
|
|
|
fuzz->nextN(colors, colorCount);
|
|
|
|
if (useMatrix) {
|
|
|
|
fuzz->next(&matrix);
|
|
|
|
}
|
|
|
|
if (usePos) {
|
2017-03-10 18:56:08 +00:00
|
|
|
fuzz_gradient_stops(fuzz, pos, colorCount);
|
2017-03-08 16:02:40 +00:00
|
|
|
}
|
|
|
|
return SkGradientShader::MakeRadial(center, radius, colors, usePos ? pos : nullptr,
|
|
|
|
colorCount, tmX, 0, useMatrix ? &matrix : nullptr);
|
|
|
|
}
|
|
|
|
case 12: {
|
|
|
|
constexpr int kMaxColors = 12;
|
|
|
|
SkPoint start, end;
|
|
|
|
SkScalar startRadius, endRadius;
|
|
|
|
int colorCount;
|
|
|
|
bool usePos;
|
|
|
|
SkColor colors[kMaxColors];
|
|
|
|
SkScalar pos[kMaxColors];
|
|
|
|
fuzz->next(&tmX, &useMatrix, &usePos, &startRadius, &endRadius, &start, &end);
|
|
|
|
fuzz->nextRange(&colorCount, 2, kMaxColors);
|
|
|
|
fuzz->nextN(colors, colorCount);
|
|
|
|
if (useMatrix) {
|
|
|
|
fuzz->next(&matrix);
|
|
|
|
}
|
|
|
|
if (usePos) {
|
2017-03-10 18:56:08 +00:00
|
|
|
fuzz_gradient_stops(fuzz, pos, colorCount);
|
2017-03-08 16:02:40 +00:00
|
|
|
}
|
|
|
|
return SkGradientShader::MakeTwoPointConical(start, startRadius, end, endRadius, colors,
|
|
|
|
usePos ? pos : nullptr, colorCount, tmX, 0,
|
|
|
|
useMatrix ? &matrix : nullptr);
|
|
|
|
}
|
|
|
|
case 13: {
|
|
|
|
constexpr int kMaxColors = 12;
|
|
|
|
SkScalar cx, cy;
|
|
|
|
int colorCount;
|
|
|
|
bool usePos;
|
|
|
|
SkColor colors[kMaxColors];
|
|
|
|
SkScalar pos[kMaxColors];
|
|
|
|
fuzz->next(&cx, &cy, &useMatrix, &usePos);
|
|
|
|
fuzz->nextRange(&colorCount, 2, kMaxColors);
|
|
|
|
fuzz->nextN(colors, colorCount);
|
|
|
|
if (useMatrix) {
|
|
|
|
fuzz->next(&matrix);
|
|
|
|
}
|
|
|
|
if (usePos) {
|
2017-03-10 18:56:08 +00:00
|
|
|
fuzz_gradient_stops(fuzz, pos, colorCount);
|
2017-03-08 16:02:40 +00:00
|
|
|
}
|
|
|
|
return SkGradientShader::MakeSweep(cx, cy, colors, usePos ? pos : nullptr, colorCount,
|
|
|
|
0, useMatrix ? &matrix : nullptr);
|
|
|
|
}
|
|
|
|
case 14: {
|
|
|
|
SkScalar baseFrequencyX, baseFrequencyY, seed;
|
|
|
|
int numOctaves;
|
|
|
|
SkISize tileSize;
|
|
|
|
bool useTileSize, turbulence;
|
|
|
|
fuzz->next(&baseFrequencyX, &baseFrequencyY, &seed, &useTileSize, &turbulence);
|
|
|
|
if (useTileSize) {
|
|
|
|
fuzz->next(&tileSize);
|
|
|
|
}
|
|
|
|
fuzz->nextRange(&numOctaves, 2, 7);
|
|
|
|
if (turbulence) {
|
|
|
|
return SkPerlinNoiseShader::MakeTurbulence(baseFrequencyX, baseFrequencyY,
|
|
|
|
numOctaves, seed,
|
|
|
|
useTileSize ? &tileSize : nullptr);
|
|
|
|
} else {
|
|
|
|
return SkPerlinNoiseShader::MakeFractalNoise(baseFrequencyX, baseFrequencyY,
|
|
|
|
numOctaves, seed,
|
|
|
|
useTileSize ? &tileSize : nullptr);
|
|
|
|
}
|
|
|
|
}
|
2017-02-14 18:35:14 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2017-02-27 21:45:32 +00:00
|
|
|
return nullptr;
|
2017-02-14 18:35:14 +00:00
|
|
|
}
|
|
|
|
|
2017-03-10 18:56:08 +00:00
|
|
|
static sk_sp<SkPathEffect> make_fuzz_patheffect(Fuzz* fuzz, int depth) {
|
2017-03-08 21:52:18 +00:00
|
|
|
if (depth <= 0) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
uint8_t pathEffectType;
|
|
|
|
fuzz->nextRange(&pathEffectType, 0, 9);
|
|
|
|
switch (pathEffectType) {
|
|
|
|
case 0: {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
case 1: {
|
2017-03-10 18:56:08 +00:00
|
|
|
sk_sp<SkPathEffect> first = make_fuzz_patheffect(fuzz, depth - 1);
|
|
|
|
sk_sp<SkPathEffect> second = make_fuzz_patheffect(fuzz, depth - 1);
|
2017-03-08 21:52:18 +00:00
|
|
|
return SkPathEffect::MakeSum(std::move(first), std::move(second));
|
|
|
|
}
|
|
|
|
case 2: {
|
2017-03-10 18:56:08 +00:00
|
|
|
sk_sp<SkPathEffect> first = make_fuzz_patheffect(fuzz, depth - 1);
|
|
|
|
sk_sp<SkPathEffect> second = make_fuzz_patheffect(fuzz, depth - 1);
|
2017-03-08 21:52:18 +00:00
|
|
|
return SkPathEffect::MakeCompose(std::move(first), std::move(second));
|
|
|
|
}
|
|
|
|
case 3: {
|
|
|
|
SkPath path;
|
|
|
|
fuzz_path(fuzz, &path, 20);
|
|
|
|
SkScalar advance, phase;
|
|
|
|
fuzz->next(&advance, &phase);
|
2017-03-10 13:48:28 +00:00
|
|
|
SkPath1DPathEffect::Style style;
|
|
|
|
fuzz_enum_range(fuzz, &style, 0, SkPath1DPathEffect::kLastEnum_Style);
|
|
|
|
return SkPath1DPathEffect::Make(path, advance, phase, style);
|
2017-03-08 21:52:18 +00:00
|
|
|
}
|
|
|
|
case 4: {
|
|
|
|
SkScalar width;
|
|
|
|
SkMatrix matrix;
|
|
|
|
fuzz->next(&width, &matrix);
|
|
|
|
return SkLine2DPathEffect::Make(width, matrix);
|
|
|
|
}
|
|
|
|
case 5: {
|
|
|
|
SkPath path;
|
|
|
|
fuzz_path(fuzz, &path, 20);
|
|
|
|
SkMatrix matrix;
|
|
|
|
fuzz->next(&matrix);
|
|
|
|
return SkPath2DPathEffect::Make(matrix, path);
|
|
|
|
}
|
|
|
|
case 6: {
|
|
|
|
SkScalar radius;
|
|
|
|
fuzz->next(&radius);
|
|
|
|
return SkArcToPathEffect::Make(radius);
|
|
|
|
}
|
|
|
|
case 7: {
|
|
|
|
SkScalar radius;
|
|
|
|
fuzz->next(&radius);
|
|
|
|
return SkCornerPathEffect::Make(radius);
|
|
|
|
}
|
|
|
|
case 8: {
|
|
|
|
SkScalar phase;
|
|
|
|
fuzz->next(&phase);
|
|
|
|
SkScalar intervals[20];
|
|
|
|
int count;
|
|
|
|
fuzz->nextRange(&count, 0, (int)SK_ARRAY_COUNT(intervals));
|
|
|
|
fuzz->nextN(intervals, count);
|
|
|
|
return SkDashPathEffect::Make(intervals, count, phase);
|
|
|
|
}
|
|
|
|
case 9: {
|
|
|
|
SkScalar segLength, dev;
|
|
|
|
uint32_t seed;
|
|
|
|
fuzz->next(&segLength, &dev, &seed);
|
|
|
|
return SkDiscretePathEffect::Make(segLength, dev, seed);
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
SkASSERT(false);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
}
|
2017-02-14 18:35:14 +00:00
|
|
|
|
2017-03-10 18:56:08 +00:00
|
|
|
static sk_sp<SkMaskFilter> make_fuzz_maskfilter(Fuzz* fuzz) {
|
2017-03-08 21:52:18 +00:00
|
|
|
int maskfilterType;
|
|
|
|
fuzz->nextRange(&maskfilterType, 0, 2);
|
|
|
|
switch (maskfilterType) {
|
|
|
|
case 0:
|
|
|
|
return nullptr;
|
|
|
|
case 1: {
|
2017-03-10 13:48:28 +00:00
|
|
|
SkBlurStyle blurStyle;
|
|
|
|
fuzz_enum_range(fuzz, &blurStyle, 0, kLastEnum_SkBlurStyle);
|
2017-03-08 21:52:18 +00:00
|
|
|
SkScalar sigma;
|
|
|
|
fuzz->next(&sigma);
|
|
|
|
SkRect occluder{0.0f, 0.0f, 0.0f, 0.0f};
|
2017-03-10 18:56:08 +00:00
|
|
|
if (make_fuzz_t<bool>(fuzz)) {
|
2017-03-08 21:52:18 +00:00
|
|
|
fuzz->next(&occluder);
|
|
|
|
}
|
|
|
|
uint32_t flags;
|
|
|
|
fuzz->nextRange(&flags, 0, 3);
|
2017-03-10 13:48:28 +00:00
|
|
|
return SkBlurMaskFilter::Make(blurStyle, sigma, occluder, flags);
|
2017-03-08 21:52:18 +00:00
|
|
|
}
|
|
|
|
case 2: {
|
|
|
|
SkRRect first, second;
|
|
|
|
SkScalar radius;
|
|
|
|
fuzz->next(&first, &second, &radius);
|
|
|
|
return SkRRectsGaussianEdgeMaskFilter::Make(first, second, radius);
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
SkASSERT(false);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
}
|
2017-02-14 18:35:14 +00:00
|
|
|
|
2017-03-10 18:56:08 +00:00
|
|
|
static sk_sp<SkTypeface> make_fuzz_typeface(Fuzz* fuzz) {
|
|
|
|
if (make_fuzz_t<bool>(fuzz)) {
|
2017-02-27 18:36:38 +00:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
auto fontMugger = SkFontMgr::RefDefault();
|
|
|
|
SkASSERT(fontMugger);
|
|
|
|
int familyCount = fontMugger->countFamilies();
|
|
|
|
int i, j;
|
|
|
|
fuzz->nextRange(&i, 0, familyCount - 1);
|
|
|
|
sk_sp<SkFontStyleSet> family(fontMugger->createStyleSet(i));
|
|
|
|
int styleCount = family->count();
|
|
|
|
fuzz->nextRange(&j, 0, styleCount - 1);
|
|
|
|
return sk_sp<SkTypeface>(family->createTypeface(j));
|
|
|
|
}
|
2017-02-14 18:35:14 +00:00
|
|
|
|
2017-03-09 16:33:35 +00:00
|
|
|
template <>
|
|
|
|
inline void Fuzz::next(SkImageFilter::CropRect* cropRect) {
|
|
|
|
SkRect rect;
|
|
|
|
uint8_t flags;
|
|
|
|
this->next(&rect);
|
|
|
|
this->nextRange(&flags, 0, 0xF);
|
|
|
|
*cropRect = SkImageFilter::CropRect(rect, flags);
|
|
|
|
}
|
|
|
|
|
2017-03-10 18:56:08 +00:00
|
|
|
static sk_sp<SkImageFilter> make_fuzz_imageFilter(Fuzz* fuzz, int depth);
|
2017-03-09 16:33:35 +00:00
|
|
|
|
|
|
|
static sk_sp<SkImageFilter> make_fuzz_lighting_imagefilter(Fuzz* fuzz, int depth) {
|
|
|
|
if (depth <= 0) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
uint8_t imageFilterType;
|
|
|
|
fuzz->nextRange(&imageFilterType, 1, 6);
|
|
|
|
SkPoint3 p, q;
|
|
|
|
SkColor lightColor;
|
|
|
|
SkScalar surfaceScale, k, specularExponent, cutoffAngle, shininess;
|
|
|
|
sk_sp<SkImageFilter> input;
|
|
|
|
SkImageFilter::CropRect cropRect;
|
|
|
|
bool useCropRect;
|
|
|
|
fuzz->next(&useCropRect);
|
|
|
|
if (useCropRect) {
|
|
|
|
fuzz->next(&cropRect);
|
|
|
|
}
|
|
|
|
switch (imageFilterType) {
|
|
|
|
case 1:
|
|
|
|
fuzz->next(&p, &lightColor, &surfaceScale, &k);
|
2017-03-10 18:56:08 +00:00
|
|
|
input = make_fuzz_imageFilter(fuzz, depth - 1);
|
2017-03-09 16:33:35 +00:00
|
|
|
return SkLightingImageFilter::MakeDistantLitDiffuse(p, lightColor, surfaceScale, k,
|
|
|
|
std::move(input),
|
|
|
|
useCropRect ? &cropRect : nullptr);
|
|
|
|
case 2:
|
|
|
|
fuzz->next(&p, &lightColor, &surfaceScale, &k);
|
2017-03-10 18:56:08 +00:00
|
|
|
input = make_fuzz_imageFilter(fuzz, depth - 1);
|
2017-03-09 16:33:35 +00:00
|
|
|
return SkLightingImageFilter::MakePointLitDiffuse(p, lightColor, surfaceScale, k,
|
|
|
|
std::move(input),
|
|
|
|
useCropRect ? &cropRect : nullptr);
|
|
|
|
case 3:
|
|
|
|
fuzz->next(&p, &q, &specularExponent, &cutoffAngle, &lightColor, &surfaceScale, &k);
|
2017-03-10 18:56:08 +00:00
|
|
|
input = make_fuzz_imageFilter(fuzz, depth - 1);
|
2017-03-09 16:33:35 +00:00
|
|
|
return SkLightingImageFilter::MakeSpotLitDiffuse(
|
|
|
|
p, q, specularExponent, cutoffAngle, lightColor, surfaceScale, k,
|
|
|
|
std::move(input), useCropRect ? &cropRect : nullptr);
|
|
|
|
case 4:
|
|
|
|
fuzz->next(&p, &lightColor, &surfaceScale, &k, &shininess);
|
2017-03-10 18:56:08 +00:00
|
|
|
input = make_fuzz_imageFilter(fuzz, depth - 1);
|
2017-03-09 16:33:35 +00:00
|
|
|
return SkLightingImageFilter::MakeDistantLitSpecular(p, lightColor, surfaceScale, k,
|
|
|
|
shininess, std::move(input),
|
|
|
|
useCropRect ? &cropRect : nullptr);
|
|
|
|
case 5:
|
|
|
|
fuzz->next(&p, &lightColor, &surfaceScale, &k, &shininess);
|
2017-03-10 18:56:08 +00:00
|
|
|
input = make_fuzz_imageFilter(fuzz, depth - 1);
|
2017-03-09 16:33:35 +00:00
|
|
|
return SkLightingImageFilter::MakePointLitSpecular(p, lightColor, surfaceScale, k,
|
|
|
|
shininess, std::move(input),
|
|
|
|
useCropRect ? &cropRect : nullptr);
|
|
|
|
case 6:
|
|
|
|
fuzz->next(&p, &q, &specularExponent, &cutoffAngle, &lightColor, &surfaceScale, &k,
|
|
|
|
&shininess);
|
2017-03-10 18:56:08 +00:00
|
|
|
input = make_fuzz_imageFilter(fuzz, depth - 1);
|
2017-03-09 16:33:35 +00:00
|
|
|
return SkLightingImageFilter::MakeSpotLitSpecular(
|
|
|
|
p, q, specularExponent, cutoffAngle, lightColor, surfaceScale, k, shininess,
|
|
|
|
std::move(input), useCropRect ? &cropRect : nullptr);
|
|
|
|
default:
|
|
|
|
SkASSERT(false);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-10 18:56:08 +00:00
|
|
|
static void fuzz_paint(Fuzz* fuzz, SkPaint* paint, int depth);
|
2017-03-09 16:33:35 +00:00
|
|
|
|
2017-03-10 18:56:08 +00:00
|
|
|
static sk_sp<SkImageFilter> make_fuzz_imageFilter(Fuzz* fuzz, int depth) {
|
2017-03-09 16:33:35 +00:00
|
|
|
if (depth <= 0) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
uint8_t imageFilterType;
|
|
|
|
fuzz->nextRange(&imageFilterType, 0, 24);
|
|
|
|
switch (imageFilterType) {
|
|
|
|
case 0:
|
|
|
|
return nullptr;
|
|
|
|
case 1: {
|
|
|
|
SkScalar sigmaX, sigmaY;
|
2017-03-10 18:56:08 +00:00
|
|
|
sk_sp<SkImageFilter> input = make_fuzz_imageFilter(fuzz, depth - 1);
|
2017-03-09 16:33:35 +00:00
|
|
|
bool useCropRect;
|
|
|
|
fuzz->next(&sigmaX, &sigmaY, &useCropRect);
|
2017-03-14 21:20:24 +00:00
|
|
|
SkImageFilter::CropRect cropRect;
|
2017-03-09 16:33:35 +00:00
|
|
|
if (useCropRect) {
|
2017-03-14 21:20:24 +00:00
|
|
|
fuzz->next(&cropRect);
|
2017-03-09 16:33:35 +00:00
|
|
|
}
|
|
|
|
return SkImageFilter::MakeBlur(sigmaX, sigmaY, std::move(input),
|
|
|
|
useCropRect ? &cropRect : nullptr);
|
|
|
|
}
|
|
|
|
case 2: {
|
|
|
|
SkMatrix matrix;
|
|
|
|
SkFilterQuality quality;
|
|
|
|
fuzz->next(&matrix, &quality);
|
2017-03-10 18:56:08 +00:00
|
|
|
sk_sp<SkImageFilter> input = make_fuzz_imageFilter(fuzz, depth - 1);
|
2017-03-09 16:33:35 +00:00
|
|
|
return SkImageFilter::MakeMatrixFilter(matrix, quality, std::move(input));
|
|
|
|
}
|
|
|
|
case 3: {
|
|
|
|
SkRegion region;
|
|
|
|
SkScalar innerMin, outerMax;
|
2017-03-10 18:56:08 +00:00
|
|
|
sk_sp<SkImageFilter> input = make_fuzz_imageFilter(fuzz, depth - 1);
|
2017-03-09 16:33:35 +00:00
|
|
|
bool useCropRect;
|
|
|
|
fuzz->next(®ion, &innerMin, &outerMax, &useCropRect);
|
2017-03-14 21:20:24 +00:00
|
|
|
SkImageFilter::CropRect cropRect;
|
2017-03-09 16:33:35 +00:00
|
|
|
if (useCropRect) {
|
2017-03-14 21:20:24 +00:00
|
|
|
fuzz->next(&cropRect);
|
2017-03-09 16:33:35 +00:00
|
|
|
}
|
|
|
|
return SkAlphaThresholdFilter::Make(region, innerMin, outerMax, std::move(input),
|
|
|
|
useCropRect ? &cropRect : nullptr);
|
|
|
|
}
|
|
|
|
case 4: {
|
|
|
|
float k1, k2, k3, k4;
|
|
|
|
bool enforcePMColor;
|
|
|
|
bool useCropRect;
|
|
|
|
fuzz->next(&k1, &k2, &k3, &k4, &enforcePMColor, &useCropRect);
|
2017-03-10 18:56:08 +00:00
|
|
|
sk_sp<SkImageFilter> background = make_fuzz_imageFilter(fuzz, depth - 1);
|
|
|
|
sk_sp<SkImageFilter> foreground = make_fuzz_imageFilter(fuzz, depth - 1);
|
2017-03-09 16:33:35 +00:00
|
|
|
SkImageFilter::CropRect cropRect;
|
|
|
|
if (useCropRect) {
|
2017-03-14 21:20:24 +00:00
|
|
|
fuzz->next(&cropRect);
|
2017-03-09 16:33:35 +00:00
|
|
|
}
|
|
|
|
return SkArithmeticImageFilter::Make(k1, k2, k3, k4, enforcePMColor,
|
|
|
|
std::move(background), std::move(foreground),
|
|
|
|
useCropRect ? &cropRect : nullptr);
|
|
|
|
}
|
|
|
|
case 5: {
|
2017-03-10 18:56:08 +00:00
|
|
|
sk_sp<SkColorFilter> cf = make_fuzz_colorfilter(fuzz, depth - 1);
|
|
|
|
sk_sp<SkImageFilter> input = make_fuzz_imageFilter(fuzz, depth - 1);
|
2017-03-09 16:33:35 +00:00
|
|
|
bool useCropRect;
|
|
|
|
SkImageFilter::CropRect cropRect;
|
|
|
|
fuzz->next(&useCropRect);
|
|
|
|
if (useCropRect) {
|
2017-03-14 21:20:24 +00:00
|
|
|
fuzz->next(&cropRect);
|
2017-03-09 16:33:35 +00:00
|
|
|
}
|
|
|
|
return SkColorFilterImageFilter::Make(std::move(cf), std::move(input),
|
|
|
|
useCropRect ? &cropRect : nullptr);
|
|
|
|
}
|
|
|
|
case 6: {
|
2017-03-10 18:56:08 +00:00
|
|
|
sk_sp<SkImageFilter> ifo = make_fuzz_imageFilter(fuzz, depth - 1);
|
|
|
|
sk_sp<SkImageFilter> ifi = make_fuzz_imageFilter(fuzz, depth - 1);
|
2017-03-09 16:33:35 +00:00
|
|
|
return SkComposeImageFilter::Make(std::move(ifo), std::move(ifi));
|
|
|
|
}
|
|
|
|
case 7: {
|
|
|
|
SkDisplacementMapEffect::ChannelSelectorType xChannelSelector, yChannelSelector;
|
2017-03-15 20:58:33 +00:00
|
|
|
fuzz_enum_range(fuzz, &xChannelSelector, 1, 4);
|
|
|
|
fuzz_enum_range(fuzz, &yChannelSelector, 1, 4);
|
2017-03-09 16:33:35 +00:00
|
|
|
SkScalar scale;
|
|
|
|
bool useCropRect;
|
|
|
|
fuzz->next(&scale, &useCropRect);
|
|
|
|
SkImageFilter::CropRect cropRect;
|
|
|
|
if (useCropRect) {
|
2017-03-14 21:20:24 +00:00
|
|
|
fuzz->next(&cropRect);
|
2017-03-09 16:33:35 +00:00
|
|
|
}
|
2017-03-10 18:56:08 +00:00
|
|
|
sk_sp<SkImageFilter> displacement = make_fuzz_imageFilter(fuzz, depth - 1);
|
|
|
|
sk_sp<SkImageFilter> color = make_fuzz_imageFilter(fuzz, depth - 1);
|
2017-03-09 16:33:35 +00:00
|
|
|
return SkDisplacementMapEffect::Make(xChannelSelector, yChannelSelector, scale,
|
|
|
|
std::move(displacement), std::move(color),
|
|
|
|
useCropRect ? &cropRect : nullptr);
|
|
|
|
}
|
|
|
|
case 8: {
|
|
|
|
SkScalar dx, dy, sigmaX, sigmaY;
|
|
|
|
SkColor color;
|
|
|
|
SkDropShadowImageFilter::ShadowMode shadowMode;
|
2017-03-10 13:48:28 +00:00
|
|
|
fuzz_enum_range(fuzz, &shadowMode, 0, 1);
|
2017-03-09 16:33:35 +00:00
|
|
|
bool useCropRect;
|
|
|
|
fuzz->next(&dx, &dy, &sigmaX, &sigmaY, &color, &useCropRect);
|
|
|
|
SkImageFilter::CropRect cropRect;
|
|
|
|
if (useCropRect) {
|
2017-03-14 21:20:24 +00:00
|
|
|
fuzz->next(&cropRect);
|
2017-03-09 16:33:35 +00:00
|
|
|
}
|
2017-03-10 18:56:08 +00:00
|
|
|
sk_sp<SkImageFilter> input = make_fuzz_imageFilter(fuzz, depth - 1);
|
2017-03-09 16:33:35 +00:00
|
|
|
return SkDropShadowImageFilter::Make(dx, dy, sigmaX, sigmaY, color, shadowMode,
|
|
|
|
std::move(input),
|
|
|
|
useCropRect ? &cropRect : nullptr);
|
|
|
|
}
|
|
|
|
case 9:
|
2017-03-10 18:56:08 +00:00
|
|
|
return SkImageSource::Make(make_fuzz_image(fuzz));
|
2017-03-09 16:33:35 +00:00
|
|
|
case 10: {
|
2017-03-10 18:56:08 +00:00
|
|
|
sk_sp<SkImage> image = make_fuzz_image(fuzz);
|
2017-03-09 16:33:35 +00:00
|
|
|
SkRect srcRect, dstRect;
|
|
|
|
SkFilterQuality filterQuality;
|
|
|
|
fuzz->next(&srcRect, &dstRect, &filterQuality);
|
|
|
|
return SkImageSource::Make(std::move(image), srcRect, dstRect, filterQuality);
|
|
|
|
}
|
|
|
|
case 11:
|
|
|
|
return make_fuzz_lighting_imagefilter(fuzz, depth - 1);
|
|
|
|
case 12: {
|
|
|
|
SkRect srcRect;
|
|
|
|
SkScalar inset;
|
|
|
|
bool useCropRect;
|
|
|
|
SkImageFilter::CropRect cropRect;
|
|
|
|
fuzz->next(&srcRect, &inset, &useCropRect);
|
|
|
|
if (useCropRect) {
|
2017-03-14 21:20:24 +00:00
|
|
|
fuzz->next(&cropRect);
|
2017-03-09 16:33:35 +00:00
|
|
|
}
|
2017-03-10 18:56:08 +00:00
|
|
|
sk_sp<SkImageFilter> input = make_fuzz_imageFilter(fuzz, depth - 1);
|
2017-03-09 16:33:35 +00:00
|
|
|
return SkMagnifierImageFilter::Make(srcRect, inset, std::move(input),
|
|
|
|
useCropRect ? &cropRect : nullptr);
|
|
|
|
}
|
|
|
|
case 13: {
|
|
|
|
constexpr int kMaxKernelSize = 5;
|
|
|
|
int32_t n, m;
|
|
|
|
fuzz->nextRange(&n, 1, kMaxKernelSize);
|
|
|
|
fuzz->nextRange(&m, 1, kMaxKernelSize);
|
|
|
|
SkScalar kernel[kMaxKernelSize * kMaxKernelSize];
|
|
|
|
fuzz->nextN(kernel, n * m);
|
|
|
|
int32_t offsetX, offsetY;
|
|
|
|
fuzz->nextRange(&offsetX, 0, n - 1);
|
|
|
|
fuzz->nextRange(&offsetY, 0, m - 1);
|
|
|
|
SkScalar gain, bias;
|
|
|
|
bool convolveAlpha, useCropRect;
|
|
|
|
fuzz->next(&gain, &bias, &convolveAlpha, &useCropRect);
|
|
|
|
SkMatrixConvolutionImageFilter::TileMode tileMode;
|
2017-03-10 13:48:28 +00:00
|
|
|
fuzz_enum_range(fuzz, &tileMode, 0, 2);
|
2017-03-09 16:33:35 +00:00
|
|
|
SkImageFilter::CropRect cropRect;
|
|
|
|
if (useCropRect) {
|
2017-03-14 21:20:24 +00:00
|
|
|
fuzz->next(&cropRect);
|
2017-03-09 16:33:35 +00:00
|
|
|
}
|
2017-03-10 18:56:08 +00:00
|
|
|
sk_sp<SkImageFilter> input = make_fuzz_imageFilter(fuzz, depth - 1);
|
2017-03-09 16:33:35 +00:00
|
|
|
return SkMatrixConvolutionImageFilter::Make(
|
|
|
|
SkISize{n, m}, kernel, gain, bias, SkIPoint{offsetX, offsetY}, tileMode,
|
|
|
|
convolveAlpha, std::move(input), useCropRect ? &cropRect : nullptr);
|
|
|
|
}
|
|
|
|
case 14: {
|
2017-03-10 18:56:08 +00:00
|
|
|
sk_sp<SkImageFilter> first = make_fuzz_imageFilter(fuzz, depth - 1);
|
|
|
|
sk_sp<SkImageFilter> second = make_fuzz_imageFilter(fuzz, depth - 1);
|
2017-03-09 16:33:35 +00:00
|
|
|
SkBlendMode blendMode;
|
|
|
|
bool useCropRect;
|
|
|
|
fuzz->next(&useCropRect, &blendMode);
|
|
|
|
SkImageFilter::CropRect cropRect;
|
|
|
|
if (useCropRect) {
|
2017-03-14 21:20:24 +00:00
|
|
|
fuzz->next(&cropRect);
|
2017-03-09 16:33:35 +00:00
|
|
|
}
|
|
|
|
return SkMergeImageFilter::Make(std::move(first), std::move(second), blendMode,
|
|
|
|
useCropRect ? &cropRect : nullptr);
|
|
|
|
}
|
|
|
|
case 15: {
|
|
|
|
constexpr int kMaxCount = 4;
|
|
|
|
sk_sp<SkImageFilter> ifs[kMaxCount];
|
|
|
|
SkBlendMode blendModes[kMaxCount];
|
|
|
|
int count;
|
|
|
|
fuzz->nextRange(&count, 1, kMaxCount);
|
|
|
|
for (int i = 0; i < count; ++i) {
|
2017-03-10 18:56:08 +00:00
|
|
|
ifs[i] = make_fuzz_imageFilter(fuzz, depth - 1);
|
2017-03-09 16:33:35 +00:00
|
|
|
}
|
|
|
|
fuzz->nextN(blendModes, count);
|
|
|
|
bool useCropRect;
|
|
|
|
fuzz->next(&useCropRect);
|
|
|
|
SkImageFilter::CropRect cropRect;
|
|
|
|
if (useCropRect) {
|
2017-03-14 21:20:24 +00:00
|
|
|
fuzz->next(&cropRect);
|
2017-03-09 16:33:35 +00:00
|
|
|
}
|
|
|
|
return SkMergeImageFilter::MakeN(ifs, count, blendModes,
|
|
|
|
useCropRect ? &cropRect : nullptr);
|
|
|
|
}
|
|
|
|
case 16: {
|
|
|
|
int rx, ry;
|
|
|
|
fuzz->next(&rx, &ry);
|
|
|
|
bool useCropRect;
|
|
|
|
fuzz->next(&useCropRect);
|
|
|
|
SkImageFilter::CropRect cropRect;
|
|
|
|
if (useCropRect) {
|
2017-03-14 21:20:24 +00:00
|
|
|
fuzz->next(&cropRect);
|
2017-03-09 16:33:35 +00:00
|
|
|
}
|
2017-03-10 18:56:08 +00:00
|
|
|
sk_sp<SkImageFilter> input = make_fuzz_imageFilter(fuzz, depth - 1);
|
2017-03-09 16:33:35 +00:00
|
|
|
return SkDilateImageFilter::Make(rx, ry, std::move(input),
|
|
|
|
useCropRect ? &cropRect : nullptr);
|
|
|
|
}
|
|
|
|
case 17: {
|
|
|
|
int rx, ry;
|
|
|
|
fuzz->next(&rx, &ry);
|
|
|
|
bool useCropRect;
|
|
|
|
fuzz->next(&useCropRect);
|
|
|
|
SkImageFilter::CropRect cropRect;
|
|
|
|
if (useCropRect) {
|
2017-03-14 21:20:24 +00:00
|
|
|
fuzz->next(&cropRect);
|
2017-03-09 16:33:35 +00:00
|
|
|
}
|
2017-03-10 18:56:08 +00:00
|
|
|
sk_sp<SkImageFilter> input = make_fuzz_imageFilter(fuzz, depth - 1);
|
2017-03-09 16:33:35 +00:00
|
|
|
return SkErodeImageFilter::Make(rx, ry, std::move(input),
|
|
|
|
useCropRect ? &cropRect : nullptr);
|
|
|
|
}
|
|
|
|
case 18: {
|
|
|
|
SkScalar dx, dy;
|
|
|
|
fuzz->next(&dx, &dy);
|
|
|
|
bool useCropRect;
|
|
|
|
fuzz->next(&useCropRect);
|
|
|
|
SkImageFilter::CropRect cropRect;
|
|
|
|
if (useCropRect) {
|
2017-03-14 21:20:24 +00:00
|
|
|
fuzz->next(&cropRect);
|
2017-03-09 16:33:35 +00:00
|
|
|
}
|
2017-03-10 18:56:08 +00:00
|
|
|
sk_sp<SkImageFilter> input = make_fuzz_imageFilter(fuzz, depth - 1);
|
2017-03-09 16:33:35 +00:00
|
|
|
return SkOffsetImageFilter::Make(dx, dy, std::move(input),
|
|
|
|
useCropRect ? &cropRect : nullptr);
|
|
|
|
}
|
|
|
|
case 19: {
|
|
|
|
SkPaint paint;
|
2017-03-10 18:56:08 +00:00
|
|
|
fuzz_paint(fuzz, &paint, depth - 1);
|
2017-03-09 16:33:35 +00:00
|
|
|
bool useCropRect;
|
|
|
|
fuzz->next(&useCropRect);
|
|
|
|
SkImageFilter::CropRect cropRect;
|
|
|
|
if (useCropRect) {
|
2017-03-14 21:20:24 +00:00
|
|
|
fuzz->next(&cropRect);
|
2017-03-09 16:33:35 +00:00
|
|
|
}
|
|
|
|
return SkPaintImageFilter::Make(paint, useCropRect ? &cropRect : nullptr);
|
|
|
|
}
|
|
|
|
case 20: {
|
2017-03-10 18:56:08 +00:00
|
|
|
sk_sp<SkPicture> picture = make_fuzz_picture(fuzz, depth - 1);
|
2017-03-09 16:33:35 +00:00
|
|
|
return SkPictureImageFilter::Make(std::move(picture));
|
|
|
|
}
|
|
|
|
case 21: {
|
|
|
|
SkRect cropRect;
|
|
|
|
fuzz->next(&cropRect);
|
2017-03-10 18:56:08 +00:00
|
|
|
sk_sp<SkPicture> picture = make_fuzz_picture(fuzz, depth - 1);
|
2017-03-09 16:33:35 +00:00
|
|
|
return SkPictureImageFilter::Make(std::move(picture), cropRect);
|
|
|
|
}
|
|
|
|
case 22: {
|
|
|
|
SkRect cropRect;
|
|
|
|
SkFilterQuality filterQuality;
|
|
|
|
fuzz->next(&cropRect, &filterQuality);
|
2017-03-10 18:56:08 +00:00
|
|
|
sk_sp<SkPicture> picture = make_fuzz_picture(fuzz, depth - 1);
|
2017-03-09 16:33:35 +00:00
|
|
|
return SkPictureImageFilter::MakeForLocalSpace(std::move(picture), cropRect,
|
|
|
|
filterQuality);
|
|
|
|
}
|
|
|
|
case 23: {
|
|
|
|
SkRect src, dst;
|
|
|
|
fuzz->next(&src, &dst);
|
2017-03-10 18:56:08 +00:00
|
|
|
sk_sp<SkImageFilter> input = make_fuzz_imageFilter(fuzz, depth - 1);
|
2017-03-09 16:33:35 +00:00
|
|
|
return SkTileImageFilter::Make(src, dst, std::move(input));
|
|
|
|
}
|
|
|
|
case 24: {
|
|
|
|
SkBlendMode blendMode;
|
|
|
|
bool useCropRect;
|
|
|
|
fuzz->next(&useCropRect, &blendMode);
|
|
|
|
SkImageFilter::CropRect cropRect;
|
|
|
|
if (useCropRect) {
|
2017-03-14 21:20:24 +00:00
|
|
|
fuzz->next(&cropRect);
|
2017-03-09 16:33:35 +00:00
|
|
|
}
|
2017-03-10 18:56:08 +00:00
|
|
|
sk_sp<SkImageFilter> bg = make_fuzz_imageFilter(fuzz, depth - 1);
|
|
|
|
sk_sp<SkImageFilter> fg = make_fuzz_imageFilter(fuzz, depth - 1);
|
2017-03-09 16:33:35 +00:00
|
|
|
return SkXfermodeImageFilter::Make(blendMode, std::move(bg), std::move(fg),
|
|
|
|
useCropRect ? &cropRect : nullptr);
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
SkASSERT(false);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
}
|
2017-02-14 18:35:14 +00:00
|
|
|
|
2017-03-10 18:56:08 +00:00
|
|
|
static sk_sp<SkImage> make_fuzz_image(Fuzz* fuzz) {
|
2017-02-14 18:35:14 +00:00
|
|
|
int w, h;
|
|
|
|
fuzz->nextRange(&w, 1, 1024);
|
|
|
|
fuzz->nextRange(&h, 1, 1024);
|
|
|
|
SkAutoTMalloc<SkPMColor> data(w * h);
|
|
|
|
SkPixmap pixmap(SkImageInfo::MakeN32Premul(w, h), data.get(), w * sizeof(SkPMColor));
|
|
|
|
int n = w * h;
|
|
|
|
for (int i = 0; i < n; ++i) {
|
|
|
|
SkColor c;
|
|
|
|
fuzz->next(&c);
|
|
|
|
data[i] = SkPreMultiplyColor(c);
|
|
|
|
}
|
|
|
|
(void)data.release();
|
2017-03-08 16:02:40 +00:00
|
|
|
return SkImage::MakeFromRaster(pixmap, [](const void* p, void*) { sk_free((void*)p); },
|
|
|
|
nullptr);
|
2017-02-14 18:35:14 +00:00
|
|
|
}
|
|
|
|
|
2017-03-10 18:56:08 +00:00
|
|
|
static SkBitmap make_fuzz_bitmap(Fuzz* fuzz) {
|
2017-02-14 18:35:14 +00:00
|
|
|
SkBitmap bitmap;
|
|
|
|
int w, h;
|
|
|
|
fuzz->nextRange(&w, 1, 1024);
|
|
|
|
fuzz->nextRange(&h, 1, 1024);
|
|
|
|
bitmap.allocN32Pixels(w, h);
|
|
|
|
for (int y = 0; y < h; ++y) {
|
|
|
|
for (int x = 0; x < w; ++x) {
|
|
|
|
SkColor c;
|
|
|
|
fuzz->next(&c);
|
|
|
|
*bitmap.getAddr32(x, y) = SkPreMultiplyColor(c);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return bitmap;
|
|
|
|
}
|
|
|
|
|
2017-03-10 18:56:08 +00:00
|
|
|
template <typename T, typename Min, typename Max>
|
|
|
|
inline T make_fuzz_t_range(Fuzz* fuzz, Min minv, Max maxv) {
|
|
|
|
T value;
|
|
|
|
fuzz_enum_range(fuzz, &value, minv, maxv);
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void fuzz_paint(Fuzz* fuzz, SkPaint* paint, int depth) {
|
2017-02-14 18:35:14 +00:00
|
|
|
if (!fuzz || !paint || depth <= 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-03-10 18:56:08 +00:00
|
|
|
paint->setAntiAlias( make_fuzz_t<bool>(fuzz));
|
|
|
|
paint->setDither( make_fuzz_t<bool>(fuzz));
|
|
|
|
paint->setColor( make_fuzz_t<SkColor>(fuzz));
|
|
|
|
paint->setBlendMode( make_fuzz_t_range<SkBlendMode>(fuzz, 0, SkBlendMode::kLastMode));
|
|
|
|
paint->setFilterQuality(make_fuzz_t_range<SkFilterQuality>(fuzz, 0, kLast_SkFilterQuality));
|
|
|
|
paint->setStyle( make_fuzz_t_range<SkPaint::Style>(fuzz, 0, 2));
|
|
|
|
paint->setShader( make_fuzz_shader(fuzz, depth - 1));
|
|
|
|
paint->setPathEffect( make_fuzz_patheffect(fuzz, depth - 1));
|
|
|
|
paint->setMaskFilter( make_fuzz_maskfilter(fuzz));
|
|
|
|
paint->setImageFilter( make_fuzz_imageFilter(fuzz, depth - 1));
|
|
|
|
paint->setColorFilter( make_fuzz_colorfilter(fuzz, depth - 1));
|
2017-02-14 18:35:14 +00:00
|
|
|
|
|
|
|
if (paint->getStyle() != SkPaint::kFill_Style) {
|
2017-03-10 18:56:08 +00:00
|
|
|
paint->setStrokeWidth(make_fuzz_t<SkScalar>(fuzz));
|
|
|
|
paint->setStrokeMiter(make_fuzz_t<SkScalar>(fuzz));
|
|
|
|
paint->setStrokeCap( make_fuzz_t_range<SkPaint::Cap>(fuzz, 0, SkPaint::kLast_Cap));
|
|
|
|
paint->setStrokeJoin( make_fuzz_t_range<SkPaint::Join>(fuzz, 0, SkPaint::kLast_Join));
|
2017-02-14 18:35:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-10 18:56:08 +00:00
|
|
|
static void fuzz_paint_text(Fuzz* fuzz, SkPaint* paint) {
|
|
|
|
paint->setTypeface( make_fuzz_typeface(fuzz));
|
|
|
|
paint->setTextSize( make_fuzz_t<SkScalar>(fuzz));
|
|
|
|
paint->setTextScaleX( make_fuzz_t<SkScalar>(fuzz));
|
|
|
|
paint->setTextSkewX( make_fuzz_t<SkScalar>(fuzz));
|
|
|
|
paint->setLinearText( make_fuzz_t<bool>(fuzz));
|
|
|
|
paint->setSubpixelText( make_fuzz_t<bool>(fuzz));
|
|
|
|
paint->setLCDRenderText( make_fuzz_t<bool>(fuzz));
|
|
|
|
paint->setEmbeddedBitmapText(make_fuzz_t<bool>(fuzz));
|
|
|
|
paint->setAutohinted( make_fuzz_t<bool>(fuzz));
|
|
|
|
paint->setVerticalText( make_fuzz_t<bool>(fuzz));
|
|
|
|
paint->setFakeBoldText( make_fuzz_t<bool>(fuzz));
|
|
|
|
paint->setDevKernText( make_fuzz_t<bool>(fuzz));
|
|
|
|
paint->setHinting( make_fuzz_t_range<SkPaint::Hinting>(fuzz, 0,
|
|
|
|
SkPaint::kFull_Hinting));
|
|
|
|
paint->setTextAlign( make_fuzz_t_range<SkPaint::Align>(fuzz, 0, 2));
|
2017-03-08 21:52:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void fuzz_paint_text_encoding(Fuzz* fuzz, SkPaint* paint) {
|
2017-03-10 18:56:08 +00:00
|
|
|
paint->setTextEncoding(make_fuzz_t_range<SkPaint::TextEncoding>(fuzz, 0, 3));
|
2017-02-27 18:36:38 +00:00
|
|
|
}
|
|
|
|
|
2017-03-08 21:52:18 +00:00
|
|
|
constexpr int kMaxGlyphCount = 30;
|
|
|
|
|
2017-03-10 18:56:08 +00:00
|
|
|
static SkTDArray<uint8_t> make_fuzz_text(Fuzz* fuzz, const SkPaint& paint) {
|
2017-02-27 18:36:38 +00:00
|
|
|
SkTDArray<uint8_t> array;
|
|
|
|
if (SkPaint::kGlyphID_TextEncoding == paint.getTextEncoding()) {
|
2017-03-08 16:02:40 +00:00
|
|
|
int glyphRange = paint.getTypeface() ? paint.getTypeface()->countGlyphs()
|
|
|
|
: SkTypeface::MakeDefault()->countGlyphs();
|
2017-02-27 18:36:38 +00:00
|
|
|
int glyphCount;
|
2017-03-08 21:52:18 +00:00
|
|
|
fuzz->nextRange(&glyphCount, 1, kMaxGlyphCount);
|
2017-02-27 18:36:38 +00:00
|
|
|
SkGlyphID* glyphs = (SkGlyphID*)array.append(glyphCount * sizeof(SkGlyphID));
|
|
|
|
for (int i = 0; i < glyphCount; ++i) {
|
|
|
|
fuzz->nextRange(&glyphs[i], 0, glyphRange - 1);
|
|
|
|
}
|
|
|
|
return array;
|
|
|
|
}
|
|
|
|
static const SkUnichar ranges[][2] = {
|
|
|
|
{0x0020, 0x007F},
|
|
|
|
{0x00A1, 0x0250},
|
|
|
|
{0x0400, 0x0500},
|
|
|
|
};
|
|
|
|
int32_t count = 0;
|
2017-03-08 16:02:40 +00:00
|
|
|
for (size_t i = 0; i < SK_ARRAY_COUNT(ranges); ++i) {
|
2017-02-27 18:36:38 +00:00
|
|
|
count += (ranges[i][1] - ranges[i][0]);
|
|
|
|
}
|
2017-03-08 21:52:18 +00:00
|
|
|
constexpr int kMaxLength = kMaxGlyphCount;
|
2017-02-27 18:36:38 +00:00
|
|
|
SkUnichar buffer[kMaxLength];
|
|
|
|
int length;
|
|
|
|
fuzz->nextRange(&length, 1, kMaxLength);
|
|
|
|
for (int j = 0; j < length; ++j) {
|
|
|
|
int32_t value;
|
|
|
|
fuzz->nextRange(&value, 0, count - 1);
|
2017-03-08 16:02:40 +00:00
|
|
|
for (size_t i = 0; i < SK_ARRAY_COUNT(ranges); ++i) {
|
2017-02-27 18:36:38 +00:00
|
|
|
if (value + ranges[i][0] < ranges[i][1]) {
|
|
|
|
buffer[j] = value + ranges[i][0];
|
|
|
|
break;
|
|
|
|
} else {
|
|
|
|
value -= (ranges[i][1] - ranges[i][0]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
switch (paint.getTextEncoding()) {
|
2017-03-08 16:02:40 +00:00
|
|
|
case SkPaint::kUTF8_TextEncoding: {
|
|
|
|
size_t utf8len = 0;
|
|
|
|
for (int j = 0; j < length; ++j) {
|
|
|
|
utf8len += SkUTF8_FromUnichar(buffer[j], nullptr);
|
2017-02-27 18:36:38 +00:00
|
|
|
}
|
2017-03-08 16:02:40 +00:00
|
|
|
char* ptr = (char*)array.append(utf8len);
|
|
|
|
for (int j = 0; j < length; ++j) {
|
|
|
|
ptr += SkUTF8_FromUnichar(buffer[j], ptr);
|
2017-02-27 18:36:38 +00:00
|
|
|
}
|
2017-03-08 16:02:40 +00:00
|
|
|
} break;
|
|
|
|
case SkPaint::kUTF16_TextEncoding: {
|
|
|
|
size_t utf16len = 0;
|
|
|
|
for (int j = 0; j < length; ++j) {
|
|
|
|
utf16len += SkUTF16_FromUnichar(buffer[j]);
|
|
|
|
}
|
|
|
|
uint16_t* ptr = (uint16_t*)array.append(utf16len * sizeof(uint16_t));
|
|
|
|
for (int j = 0; j < length; ++j) {
|
|
|
|
ptr += SkUTF16_FromUnichar(buffer[j], ptr);
|
|
|
|
}
|
|
|
|
} break;
|
2017-02-27 18:36:38 +00:00
|
|
|
case SkPaint::kUTF32_TextEncoding:
|
|
|
|
memcpy(array.append(length * sizeof(SkUnichar)), buffer, length * sizeof(SkUnichar));
|
2017-03-01 20:40:46 +00:00
|
|
|
break;
|
2017-02-27 18:36:38 +00:00
|
|
|
default:
|
2017-03-08 16:02:40 +00:00
|
|
|
SkASSERT(false);
|
2017-02-27 18:36:38 +00:00
|
|
|
}
|
|
|
|
return array;
|
2017-02-14 18:35:14 +00:00
|
|
|
}
|
|
|
|
|
2017-03-08 21:52:18 +00:00
|
|
|
static sk_sp<SkTextBlob> make_fuzz_textblob(Fuzz* fuzz) {
|
|
|
|
SkTextBlobBuilder textBlobBuilder;
|
|
|
|
int8_t runCount;
|
|
|
|
fuzz->nextRange(&runCount, (int8_t)1, (int8_t)8);
|
|
|
|
while (runCount-- > 0) {
|
|
|
|
SkPaint paint;
|
|
|
|
fuzz_paint_text_encoding(fuzz, &paint);
|
2017-03-10 18:56:08 +00:00
|
|
|
paint.setAntiAlias(make_fuzz_t<bool>(fuzz));
|
2017-03-08 21:52:18 +00:00
|
|
|
paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding);
|
|
|
|
SkTDArray<uint8_t> text = make_fuzz_text(fuzz, paint);
|
|
|
|
int glyphCount = paint.countText(text.begin(), SkToSizeT(text.count()));
|
|
|
|
SkASSERT(glyphCount <= kMaxGlyphCount);
|
|
|
|
SkScalar x, y;
|
|
|
|
const SkTextBlobBuilder::RunBuffer* buffer;
|
|
|
|
uint8_t runType;
|
|
|
|
fuzz->nextRange(&runType, (uint8_t)0, (uint8_t)2);
|
|
|
|
switch (runType) {
|
|
|
|
case 0:
|
|
|
|
fuzz->next(&x, &y);
|
|
|
|
// TODO: Test other variations of this.
|
|
|
|
buffer = &textBlobBuilder.allocRun(paint, glyphCount, x, y);
|
|
|
|
memcpy(buffer->glyphs, text.begin(), SkToSizeT(text.count()));
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
fuzz->next(&y);
|
|
|
|
// TODO: Test other variations of this.
|
|
|
|
buffer = &textBlobBuilder.allocRunPosH(paint, glyphCount, y);
|
|
|
|
memcpy(buffer->glyphs, text.begin(), SkToSizeT(text.count()));
|
|
|
|
fuzz->nextN(buffer->pos, glyphCount);
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
// TODO: Test other variations of this.
|
|
|
|
buffer = &textBlobBuilder.allocRunPos(paint, glyphCount);
|
|
|
|
memcpy(buffer->glyphs, text.begin(), SkToSizeT(text.count()));
|
|
|
|
fuzz->nextN(buffer->pos, glyphCount * 2);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
SkASSERT(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return textBlobBuilder.make();
|
|
|
|
}
|
|
|
|
|
2017-03-10 18:56:08 +00:00
|
|
|
static void fuzz_canvas(Fuzz* fuzz, SkCanvas* canvas, int depth = 9) {
|
2017-02-14 18:35:14 +00:00
|
|
|
if (!fuzz || !canvas || depth <= 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
SkAutoCanvasRestore autoCanvasRestore(canvas, false);
|
|
|
|
unsigned N;
|
|
|
|
fuzz->nextRange(&N, 0, 2000);
|
|
|
|
for (unsigned i = 0; i < N; ++i) {
|
|
|
|
if (fuzz->exhausted()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
SkPaint paint;
|
|
|
|
SkMatrix matrix;
|
|
|
|
unsigned drawCommand;
|
2017-03-09 19:10:36 +00:00
|
|
|
fuzz->nextRange(&drawCommand, 0, 53);
|
2017-02-14 18:35:14 +00:00
|
|
|
switch (drawCommand) {
|
|
|
|
case 0:
|
|
|
|
canvas->flush();
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
canvas->save();
|
|
|
|
break;
|
|
|
|
case 2: {
|
|
|
|
SkRect bounds;
|
|
|
|
fuzz->next(&bounds);
|
2017-03-10 18:56:08 +00:00
|
|
|
fuzz_paint(fuzz, &paint, depth - 1);
|
2017-02-14 18:35:14 +00:00
|
|
|
canvas->saveLayer(&bounds, &paint);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 3: {
|
|
|
|
SkRect bounds;
|
|
|
|
fuzz->next(&bounds);
|
|
|
|
canvas->saveLayer(&bounds, nullptr);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 4:
|
2017-03-10 18:56:08 +00:00
|
|
|
fuzz_paint(fuzz, &paint, depth - 1);
|
2017-02-14 18:35:14 +00:00
|
|
|
canvas->saveLayer(nullptr, &paint);
|
|
|
|
break;
|
|
|
|
case 5:
|
|
|
|
canvas->saveLayer(nullptr, nullptr);
|
|
|
|
break;
|
|
|
|
case 6: {
|
|
|
|
uint8_t alpha;
|
|
|
|
fuzz->next(&alpha);
|
|
|
|
canvas->saveLayerAlpha(nullptr, (U8CPU)alpha);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 7: {
|
|
|
|
SkRect bounds;
|
|
|
|
uint8_t alpha;
|
|
|
|
fuzz->next(&bounds, &alpha);
|
|
|
|
canvas->saveLayerAlpha(&bounds, (U8CPU)alpha);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 8: {
|
|
|
|
SkCanvas::SaveLayerRec saveLayerRec;
|
|
|
|
SkRect bounds;
|
2017-03-10 18:56:08 +00:00
|
|
|
if (make_fuzz_t<bool>(fuzz)) {
|
2017-02-14 18:35:14 +00:00
|
|
|
fuzz->next(&bounds);
|
|
|
|
saveLayerRec.fBounds = &bounds;
|
|
|
|
}
|
2017-03-10 18:56:08 +00:00
|
|
|
if (make_fuzz_t<bool>(fuzz)) {
|
|
|
|
fuzz_paint(fuzz, &paint, depth - 1);
|
2017-02-14 18:35:14 +00:00
|
|
|
saveLayerRec.fPaint = &paint;
|
|
|
|
}
|
|
|
|
sk_sp<SkImageFilter> imageFilter;
|
2017-03-10 18:56:08 +00:00
|
|
|
if (make_fuzz_t<bool>(fuzz)) {
|
|
|
|
imageFilter = make_fuzz_imageFilter(fuzz, depth - 1);
|
2017-02-14 18:35:14 +00:00
|
|
|
saveLayerRec.fBackdrop = imageFilter.get();
|
|
|
|
}
|
2017-03-08 21:52:18 +00:00
|
|
|
// _DumpCanvas can't handle this.
|
2017-03-10 18:56:08 +00:00
|
|
|
// if (make_fuzz_t<bool>(fuzz)) {
|
2017-03-08 21:52:18 +00:00
|
|
|
// saveLayerRec.fSaveLayerFlags |= SkCanvas::kIsOpaque_SaveLayerFlag;
|
|
|
|
// }
|
2017-03-10 18:56:08 +00:00
|
|
|
// if (make_fuzz_t<bool>(fuzz)) {
|
2017-03-08 21:52:18 +00:00
|
|
|
// saveLayerRec.fSaveLayerFlags |= SkCanvas::kPreserveLCDText_SaveLayerFlag;
|
|
|
|
// }
|
|
|
|
|
2017-02-14 18:35:14 +00:00
|
|
|
canvas->saveLayer(saveLayerRec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 9:
|
|
|
|
canvas->restore();
|
|
|
|
break;
|
|
|
|
case 10: {
|
|
|
|
int saveCount;
|
|
|
|
fuzz->next(&saveCount);
|
|
|
|
canvas->restoreToCount(saveCount);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 11: {
|
|
|
|
SkScalar x, y;
|
|
|
|
fuzz->next(&x, &y);
|
|
|
|
canvas->translate(x, y);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 12: {
|
|
|
|
SkScalar x, y;
|
|
|
|
fuzz->next(&x, &y);
|
|
|
|
canvas->scale(x, y);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 13: {
|
|
|
|
SkScalar v;
|
|
|
|
fuzz->next(&v);
|
|
|
|
canvas->rotate(v);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 14: {
|
|
|
|
SkScalar x, y, v;
|
|
|
|
fuzz->next(&x, &y, &v);
|
|
|
|
canvas->rotate(v, x, y);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 15: {
|
|
|
|
SkScalar x, y;
|
|
|
|
fuzz->next(&x, &y);
|
|
|
|
canvas->skew(x, y);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 16: {
|
|
|
|
SkMatrix mat;
|
|
|
|
fuzz->next(&mat);
|
|
|
|
canvas->concat(mat);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 17: {
|
|
|
|
SkMatrix mat;
|
|
|
|
fuzz->next(&mat);
|
|
|
|
canvas->setMatrix(mat);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 18:
|
|
|
|
canvas->resetMatrix();
|
|
|
|
break;
|
|
|
|
case 19: {
|
|
|
|
SkRect r;
|
|
|
|
int op;
|
|
|
|
bool doAntiAlias;
|
|
|
|
fuzz->next(&r, &doAntiAlias);
|
|
|
|
fuzz->nextRange(&op, 0, 1);
|
|
|
|
r.sort();
|
|
|
|
canvas->clipRect(r, (SkClipOp)op, doAntiAlias);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 20: {
|
|
|
|
SkRRect rr;
|
|
|
|
int op;
|
|
|
|
bool doAntiAlias;
|
|
|
|
fuzz->next(&rr);
|
|
|
|
fuzz->next(&doAntiAlias);
|
|
|
|
fuzz->nextRange(&op, 0, 1);
|
|
|
|
canvas->clipRRect(rr, (SkClipOp)op, doAntiAlias);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 21: {
|
|
|
|
SkPath path;
|
2017-03-06 13:30:44 +00:00
|
|
|
fuzz_path(fuzz, &path, 30);
|
2017-02-14 18:35:14 +00:00
|
|
|
int op;
|
|
|
|
bool doAntiAlias;
|
|
|
|
fuzz->next(&doAntiAlias);
|
|
|
|
fuzz->nextRange(&op, 0, 1);
|
|
|
|
canvas->clipPath(path, (SkClipOp)op, doAntiAlias);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 22: {
|
|
|
|
SkRegion region;
|
|
|
|
int op;
|
2017-03-09 16:33:35 +00:00
|
|
|
fuzz->next(®ion);
|
2017-02-14 18:35:14 +00:00
|
|
|
fuzz->nextRange(&op, 0, 1);
|
|
|
|
canvas->clipRegion(region, (SkClipOp)op);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 23:
|
2017-03-10 18:56:08 +00:00
|
|
|
fuzz_paint(fuzz, &paint, depth - 1);
|
2017-02-14 18:35:14 +00:00
|
|
|
canvas->drawPaint(paint);
|
|
|
|
break;
|
|
|
|
case 24: {
|
2017-03-10 18:56:08 +00:00
|
|
|
fuzz_paint(fuzz, &paint, depth - 1);
|
2017-02-14 18:35:14 +00:00
|
|
|
uint8_t pointMode;
|
|
|
|
fuzz->nextRange(&pointMode, 0, 3);
|
|
|
|
size_t count;
|
|
|
|
constexpr int kMaxCount = 30;
|
|
|
|
fuzz->nextRange(&count, 0, kMaxCount);
|
|
|
|
SkPoint pts[kMaxCount];
|
|
|
|
fuzz->nextN(pts, count);
|
|
|
|
canvas->drawPoints((SkCanvas::PointMode)pointMode, count, pts, paint);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 25: {
|
2017-03-10 18:56:08 +00:00
|
|
|
fuzz_paint(fuzz, &paint, depth - 1);
|
2017-02-14 18:35:14 +00:00
|
|
|
SkRect r;
|
|
|
|
fuzz->next(&r);
|
|
|
|
canvas->drawRect(r, paint);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 26: {
|
2017-03-10 18:56:08 +00:00
|
|
|
fuzz_paint(fuzz, &paint, depth - 1);
|
2017-02-14 18:35:14 +00:00
|
|
|
SkRegion region;
|
2017-03-09 16:33:35 +00:00
|
|
|
fuzz->next(®ion);
|
2017-02-14 18:35:14 +00:00
|
|
|
canvas->drawRegion(region, paint);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 27: {
|
2017-03-10 18:56:08 +00:00
|
|
|
fuzz_paint(fuzz, &paint, depth - 1);
|
2017-02-14 18:35:14 +00:00
|
|
|
SkRect r;
|
|
|
|
fuzz->next(&r);
|
|
|
|
canvas->drawOval(r, paint);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 29: {
|
2017-03-10 18:56:08 +00:00
|
|
|
fuzz_paint(fuzz, &paint, depth - 1);
|
2017-02-14 18:35:14 +00:00
|
|
|
SkRRect rr;
|
|
|
|
fuzz->next(&rr);
|
|
|
|
canvas->drawRRect(rr, paint);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 30: {
|
2017-03-10 18:56:08 +00:00
|
|
|
fuzz_paint(fuzz, &paint, depth - 1);
|
2017-02-14 18:35:14 +00:00
|
|
|
SkRRect orr, irr;
|
|
|
|
fuzz->next(&orr);
|
|
|
|
fuzz->next(&irr);
|
2017-03-07 21:23:20 +00:00
|
|
|
if (orr.getBounds().contains(irr.getBounds())) {
|
|
|
|
canvas->drawDRRect(orr, irr, paint);
|
|
|
|
}
|
2017-02-14 18:35:14 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 31: {
|
2017-03-10 18:56:08 +00:00
|
|
|
fuzz_paint(fuzz, &paint, depth - 1);
|
2017-02-14 18:35:14 +00:00
|
|
|
SkRect r;
|
|
|
|
SkScalar start, sweep;
|
|
|
|
bool useCenter;
|
|
|
|
fuzz->next(&r, &start, &sweep, &useCenter);
|
|
|
|
canvas->drawArc(r, start, sweep, useCenter, paint);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 32: {
|
|
|
|
SkPath path;
|
2017-03-06 13:30:44 +00:00
|
|
|
fuzz_path(fuzz, &path, 60);
|
2017-02-14 18:35:14 +00:00
|
|
|
canvas->drawPath(path, paint);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 33: {
|
2017-03-10 18:56:08 +00:00
|
|
|
sk_sp<SkImage> img = make_fuzz_image(fuzz);
|
2017-02-14 18:35:14 +00:00
|
|
|
SkScalar left, top;
|
|
|
|
bool usePaint;
|
|
|
|
fuzz->next(&left, &top, &usePaint);
|
|
|
|
if (usePaint) {
|
2017-03-10 18:56:08 +00:00
|
|
|
fuzz_paint(fuzz, &paint, depth - 1);
|
2017-02-14 18:35:14 +00:00
|
|
|
}
|
|
|
|
canvas->drawImage(img.get(), left, top, usePaint ? &paint : nullptr);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 34: {
|
2017-03-10 18:56:08 +00:00
|
|
|
auto img = make_fuzz_image(fuzz);
|
2017-02-14 18:35:14 +00:00
|
|
|
SkRect src, dst;
|
|
|
|
bool usePaint;
|
|
|
|
fuzz->next(&src, &dst, &usePaint);
|
|
|
|
if (usePaint) {
|
2017-03-10 18:56:08 +00:00
|
|
|
fuzz_paint(fuzz, &paint, depth - 1);
|
2017-02-14 18:35:14 +00:00
|
|
|
}
|
2017-03-08 16:02:40 +00:00
|
|
|
SkCanvas::SrcRectConstraint constraint =
|
2017-03-10 18:56:08 +00:00
|
|
|
make_fuzz_t<bool>(fuzz) ? SkCanvas::kStrict_SrcRectConstraint
|
|
|
|
: SkCanvas::kFast_SrcRectConstraint;
|
2017-02-14 18:35:14 +00:00
|
|
|
canvas->drawImageRect(img, src, dst, usePaint ? &paint : nullptr, constraint);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 35: {
|
2017-03-10 18:56:08 +00:00
|
|
|
auto img = make_fuzz_image(fuzz);
|
2017-02-14 18:35:14 +00:00
|
|
|
SkIRect src;
|
|
|
|
SkRect dst;
|
|
|
|
bool usePaint;
|
|
|
|
fuzz->next(&src, &dst, &usePaint);
|
|
|
|
if (usePaint) {
|
2017-03-10 18:56:08 +00:00
|
|
|
fuzz_paint(fuzz, &paint, depth - 1);
|
2017-02-14 18:35:14 +00:00
|
|
|
}
|
2017-03-08 16:02:40 +00:00
|
|
|
SkCanvas::SrcRectConstraint constraint =
|
2017-03-10 18:56:08 +00:00
|
|
|
make_fuzz_t<bool>(fuzz) ? SkCanvas::kStrict_SrcRectConstraint
|
|
|
|
: SkCanvas::kFast_SrcRectConstraint;
|
2017-02-14 18:35:14 +00:00
|
|
|
canvas->drawImageRect(img, src, dst, usePaint ? &paint : nullptr, constraint);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 36: {
|
|
|
|
bool usePaint;
|
2017-03-10 18:56:08 +00:00
|
|
|
auto img = make_fuzz_image(fuzz);
|
2017-02-14 18:35:14 +00:00
|
|
|
SkRect dst;
|
|
|
|
fuzz->next(&dst, &usePaint);
|
|
|
|
if (usePaint) {
|
2017-03-10 18:56:08 +00:00
|
|
|
fuzz_paint(fuzz, &paint, depth - 1);
|
2017-02-14 18:35:14 +00:00
|
|
|
}
|
2017-03-08 16:02:40 +00:00
|
|
|
SkCanvas::SrcRectConstraint constraint =
|
2017-03-10 18:56:08 +00:00
|
|
|
make_fuzz_t<bool>(fuzz) ? SkCanvas::kStrict_SrcRectConstraint
|
|
|
|
: SkCanvas::kFast_SrcRectConstraint;
|
2017-02-14 18:35:14 +00:00
|
|
|
canvas->drawImageRect(img, dst, usePaint ? &paint : nullptr, constraint);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 37: {
|
2017-03-10 18:56:08 +00:00
|
|
|
auto img = make_fuzz_image(fuzz);
|
2017-02-14 18:35:14 +00:00
|
|
|
SkIRect center;
|
|
|
|
SkRect dst;
|
|
|
|
bool usePaint;
|
2017-03-15 16:58:15 +00:00
|
|
|
fuzz->next(&usePaint);
|
2017-02-14 18:35:14 +00:00
|
|
|
if (usePaint) {
|
2017-03-10 18:56:08 +00:00
|
|
|
fuzz_paint(fuzz, &paint, depth - 1);
|
2017-02-14 18:35:14 +00:00
|
|
|
}
|
2017-03-15 16:58:15 +00:00
|
|
|
if (make_fuzz_t<bool>(fuzz)) {
|
|
|
|
fuzz->next(¢er);
|
|
|
|
} else { // Make valid center, see SkLatticeIter::Valid().
|
|
|
|
fuzz->nextRange(¢er.fLeft, 0, img->width() - 1);
|
|
|
|
fuzz->nextRange(¢er.fTop, 0, img->height() - 1);
|
|
|
|
fuzz->nextRange(¢er.fRight, center.fLeft + 1, img->width());
|
|
|
|
fuzz->nextRange(¢er.fBottom, center.fTop + 1, img->height());
|
|
|
|
}
|
|
|
|
fuzz->next(&dst);
|
2017-02-14 18:35:14 +00:00
|
|
|
canvas->drawImageNine(img, center, dst, usePaint ? &paint : nullptr);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 38: {
|
2017-03-10 18:56:08 +00:00
|
|
|
SkBitmap bitmap = make_fuzz_bitmap(fuzz);
|
2017-02-14 18:35:14 +00:00
|
|
|
SkScalar left, top;
|
|
|
|
bool usePaint;
|
|
|
|
fuzz->next(&left, &top, &usePaint);
|
|
|
|
if (usePaint) {
|
2017-03-10 18:56:08 +00:00
|
|
|
fuzz_paint(fuzz, &paint, depth - 1);
|
2017-02-14 18:35:14 +00:00
|
|
|
}
|
|
|
|
canvas->drawBitmap(bitmap, left, top, usePaint ? &paint : nullptr);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 39: {
|
2017-03-10 18:56:08 +00:00
|
|
|
SkBitmap bitmap = make_fuzz_bitmap(fuzz);
|
2017-02-14 18:35:14 +00:00
|
|
|
SkRect src, dst;
|
|
|
|
bool usePaint;
|
|
|
|
fuzz->next(&src, &dst, &usePaint);
|
|
|
|
if (usePaint) {
|
2017-03-10 18:56:08 +00:00
|
|
|
fuzz_paint(fuzz, &paint, depth - 1);
|
2017-02-14 18:35:14 +00:00
|
|
|
}
|
2017-03-08 16:02:40 +00:00
|
|
|
SkCanvas::SrcRectConstraint constraint =
|
2017-03-10 18:56:08 +00:00
|
|
|
make_fuzz_t<bool>(fuzz) ? SkCanvas::kStrict_SrcRectConstraint
|
|
|
|
: SkCanvas::kFast_SrcRectConstraint;
|
2017-02-14 18:35:14 +00:00
|
|
|
canvas->drawBitmapRect(bitmap, src, dst, usePaint ? &paint : nullptr, constraint);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 40: {
|
2017-03-10 18:56:08 +00:00
|
|
|
SkBitmap img = make_fuzz_bitmap(fuzz);
|
2017-02-14 18:35:14 +00:00
|
|
|
SkIRect src;
|
|
|
|
SkRect dst;
|
|
|
|
bool usePaint;
|
|
|
|
fuzz->next(&src, &dst, &usePaint);
|
|
|
|
if (usePaint) {
|
2017-03-10 18:56:08 +00:00
|
|
|
fuzz_paint(fuzz, &paint, depth - 1);
|
2017-02-14 18:35:14 +00:00
|
|
|
}
|
2017-03-08 16:02:40 +00:00
|
|
|
SkCanvas::SrcRectConstraint constraint =
|
2017-03-10 18:56:08 +00:00
|
|
|
make_fuzz_t<bool>(fuzz) ? SkCanvas::kStrict_SrcRectConstraint
|
|
|
|
: SkCanvas::kFast_SrcRectConstraint;
|
2017-02-14 18:35:14 +00:00
|
|
|
canvas->drawBitmapRect(img, src, dst, usePaint ? &paint : nullptr, constraint);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 41: {
|
2017-03-10 18:56:08 +00:00
|
|
|
SkBitmap img = make_fuzz_bitmap(fuzz);
|
2017-02-14 18:35:14 +00:00
|
|
|
SkRect dst;
|
|
|
|
bool usePaint;
|
|
|
|
fuzz->next(&dst, &usePaint);
|
|
|
|
if (usePaint) {
|
2017-03-10 18:56:08 +00:00
|
|
|
fuzz_paint(fuzz, &paint, depth - 1);
|
2017-02-14 18:35:14 +00:00
|
|
|
}
|
2017-03-08 16:02:40 +00:00
|
|
|
SkCanvas::SrcRectConstraint constraint =
|
2017-03-10 18:56:08 +00:00
|
|
|
make_fuzz_t<bool>(fuzz) ? SkCanvas::kStrict_SrcRectConstraint
|
|
|
|
: SkCanvas::kFast_SrcRectConstraint;
|
2017-02-14 18:35:14 +00:00
|
|
|
canvas->drawBitmapRect(img, dst, usePaint ? &paint : nullptr, constraint);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 42: {
|
2017-03-10 18:56:08 +00:00
|
|
|
SkBitmap img = make_fuzz_bitmap(fuzz);
|
2017-02-14 18:35:14 +00:00
|
|
|
SkIRect center;
|
|
|
|
SkRect dst;
|
|
|
|
bool usePaint;
|
2017-03-15 16:58:15 +00:00
|
|
|
fuzz->next(&usePaint);
|
2017-02-14 18:35:14 +00:00
|
|
|
if (usePaint) {
|
2017-03-10 18:56:08 +00:00
|
|
|
fuzz_paint(fuzz, &paint, depth - 1);
|
2017-02-14 18:35:14 +00:00
|
|
|
}
|
2017-03-15 16:58:15 +00:00
|
|
|
if (make_fuzz_t<bool>(fuzz)) {
|
|
|
|
fuzz->next(¢er);
|
|
|
|
} else { // Make valid center, see SkLatticeIter::Valid().
|
|
|
|
fuzz->nextRange(¢er.fLeft, 0, img.width() - 1);
|
|
|
|
fuzz->nextRange(¢er.fTop, 0, img.height() - 1);
|
|
|
|
fuzz->nextRange(¢er.fRight, center.fLeft + 1, img.width());
|
|
|
|
fuzz->nextRange(¢er.fBottom, center.fTop + 1, img.height());
|
|
|
|
}
|
|
|
|
fuzz->next(&dst);
|
2017-02-14 18:35:14 +00:00
|
|
|
canvas->drawBitmapNine(img, center, dst, usePaint ? &paint : nullptr);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 43: {
|
2017-03-10 18:56:08 +00:00
|
|
|
SkBitmap img = make_fuzz_bitmap(fuzz);
|
2017-02-14 18:35:14 +00:00
|
|
|
bool usePaint;
|
|
|
|
SkRect dst;
|
|
|
|
fuzz->next(&usePaint, &dst);
|
|
|
|
if (usePaint) {
|
2017-03-10 18:56:08 +00:00
|
|
|
fuzz_paint(fuzz, &paint, depth - 1);
|
2017-02-14 18:35:14 +00:00
|
|
|
}
|
|
|
|
constexpr int kMax = 6;
|
|
|
|
int xDivs[kMax], yDivs[kMax];
|
|
|
|
SkCanvas::Lattice lattice{xDivs, yDivs, nullptr, 0, 0, nullptr};
|
|
|
|
fuzz->nextRange(&lattice.fXCount, 2, kMax);
|
|
|
|
fuzz->nextRange(&lattice.fYCount, 2, kMax);
|
|
|
|
fuzz->nextN(xDivs, lattice.fXCount);
|
|
|
|
fuzz->nextN(yDivs, lattice.fYCount);
|
|
|
|
canvas->drawBitmapLattice(img, lattice, dst, usePaint ? &paint : nullptr);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 44: {
|
2017-03-10 18:56:08 +00:00
|
|
|
auto img = make_fuzz_image(fuzz);
|
2017-02-14 18:35:14 +00:00
|
|
|
bool usePaint;
|
|
|
|
SkRect dst;
|
|
|
|
fuzz->next(&usePaint, &dst);
|
|
|
|
if (usePaint) {
|
2017-03-10 18:56:08 +00:00
|
|
|
fuzz_paint(fuzz, &paint, depth - 1);
|
2017-02-14 18:35:14 +00:00
|
|
|
}
|
|
|
|
constexpr int kMax = 6;
|
|
|
|
int xDivs[kMax], yDivs[kMax];
|
|
|
|
SkCanvas::Lattice lattice{xDivs, yDivs, nullptr, 0, 0, nullptr};
|
|
|
|
fuzz->nextRange(&lattice.fXCount, 2, kMax);
|
|
|
|
fuzz->nextRange(&lattice.fYCount, 2, kMax);
|
|
|
|
fuzz->nextN(xDivs, lattice.fXCount);
|
|
|
|
fuzz->nextN(yDivs, lattice.fYCount);
|
|
|
|
canvas->drawImageLattice(img.get(), lattice, dst, usePaint ? &paint : nullptr);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 45: {
|
2017-03-10 18:56:08 +00:00
|
|
|
fuzz_paint(fuzz, &paint, depth - 1);
|
|
|
|
fuzz_paint_text(fuzz, &paint);
|
2017-03-08 21:52:18 +00:00
|
|
|
fuzz_paint_text_encoding(fuzz, &paint);
|
2017-02-14 18:35:14 +00:00
|
|
|
SkScalar x, y;
|
|
|
|
fuzz->next(&x, &y);
|
2017-03-08 21:52:18 +00:00
|
|
|
SkTDArray<uint8_t> text = make_fuzz_text(fuzz, paint);
|
2017-02-27 18:36:38 +00:00
|
|
|
canvas->drawText(text.begin(), SkToSizeT(text.count()), x, y, paint);
|
2017-02-14 18:35:14 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 46: {
|
2017-03-10 18:56:08 +00:00
|
|
|
fuzz_paint(fuzz, &paint, depth - 1);
|
|
|
|
fuzz_paint_text(fuzz, &paint);
|
2017-03-08 21:52:18 +00:00
|
|
|
fuzz_paint_text_encoding(fuzz, &paint);
|
|
|
|
SkTDArray<uint8_t> text = make_fuzz_text(fuzz, paint);
|
2017-02-27 18:36:38 +00:00
|
|
|
int glyphCount = paint.countText(text.begin(), SkToSizeT(text.count()));
|
2017-02-14 18:35:14 +00:00
|
|
|
if (glyphCount < 1) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
SkAutoTMalloc<SkPoint> pos(glyphCount);
|
|
|
|
SkAutoTMalloc<SkScalar> widths(glyphCount);
|
2017-02-27 18:36:38 +00:00
|
|
|
paint.getTextWidths(text.begin(), SkToSizeT(text.count()), widths.get());
|
2017-02-14 18:35:14 +00:00
|
|
|
pos[0] = {0, 0};
|
|
|
|
for (int i = 1; i < glyphCount; ++i) {
|
|
|
|
float y;
|
2017-03-08 16:02:40 +00:00
|
|
|
fuzz->nextRange(&y, -0.5f * paint.getTextSize(), 0.5f * paint.getTextSize());
|
2017-02-14 18:35:14 +00:00
|
|
|
pos[i] = {pos[i - 1].x() + widths[i - 1], y};
|
|
|
|
}
|
2017-02-27 18:36:38 +00:00
|
|
|
canvas->drawPosText(text.begin(), SkToSizeT(text.count()), pos.get(), paint);
|
2017-02-14 18:35:14 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 47: {
|
2017-03-10 18:56:08 +00:00
|
|
|
fuzz_paint(fuzz, &paint, depth - 1);
|
|
|
|
fuzz_paint_text(fuzz, &paint);
|
2017-03-08 21:52:18 +00:00
|
|
|
fuzz_paint_text_encoding(fuzz, &paint);
|
|
|
|
SkTDArray<uint8_t> text = make_fuzz_text(fuzz, paint);
|
2017-02-27 18:36:38 +00:00
|
|
|
int glyphCount = paint.countText(text.begin(), SkToSizeT(text.count()));
|
2017-02-14 18:35:14 +00:00
|
|
|
SkAutoTMalloc<SkScalar> widths(glyphCount);
|
|
|
|
if (glyphCount < 1) {
|
|
|
|
break;
|
|
|
|
}
|
2017-02-27 18:36:38 +00:00
|
|
|
paint.getTextWidths(text.begin(), SkToSizeT(text.count()), widths.get());
|
2017-02-14 18:35:14 +00:00
|
|
|
SkScalar x = widths[0];
|
|
|
|
for (int i = 0; i < glyphCount; ++i) {
|
|
|
|
SkTSwap(x, widths[i]);
|
|
|
|
x += widths[i];
|
|
|
|
SkScalar offset;
|
|
|
|
fuzz->nextRange(&offset, -0.125f * paint.getTextSize(),
|
2017-03-08 16:02:40 +00:00
|
|
|
0.125f * paint.getTextSize());
|
2017-02-14 18:35:14 +00:00
|
|
|
widths[i] += offset;
|
|
|
|
}
|
|
|
|
SkScalar y;
|
|
|
|
fuzz->next(&y);
|
2017-03-08 16:02:40 +00:00
|
|
|
canvas->drawPosTextH(text.begin(), SkToSizeT(text.count()), widths.get(), y, paint);
|
2017-02-14 18:35:14 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 48: {
|
2017-03-10 18:56:08 +00:00
|
|
|
fuzz_paint(fuzz, &paint, depth - 1);
|
|
|
|
fuzz_paint_text(fuzz, &paint);
|
2017-03-08 21:52:18 +00:00
|
|
|
fuzz_paint_text_encoding(fuzz, &paint);
|
|
|
|
SkTDArray<uint8_t> text = make_fuzz_text(fuzz, paint);
|
2017-02-14 18:35:14 +00:00
|
|
|
SkPath path;
|
2017-03-06 13:30:44 +00:00
|
|
|
fuzz_path(fuzz, &path, 20);
|
2017-02-14 18:35:14 +00:00
|
|
|
SkScalar hOffset, vOffset;
|
|
|
|
fuzz->next(&hOffset, &vOffset);
|
2017-03-08 16:02:40 +00:00
|
|
|
canvas->drawTextOnPathHV(text.begin(), SkToSizeT(text.count()), path, hOffset,
|
|
|
|
vOffset, paint);
|
2017-02-14 18:35:14 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 49: {
|
|
|
|
SkMatrix matrix;
|
2017-03-10 18:56:08 +00:00
|
|
|
bool useMatrix = make_fuzz_t<bool>(fuzz);
|
2017-02-14 18:35:14 +00:00
|
|
|
if (useMatrix) {
|
|
|
|
fuzz->next(&matrix);
|
|
|
|
}
|
2017-03-10 18:56:08 +00:00
|
|
|
fuzz_paint(fuzz, &paint, depth - 1);
|
|
|
|
fuzz_paint_text(fuzz, &paint);
|
2017-03-08 21:52:18 +00:00
|
|
|
fuzz_paint_text_encoding(fuzz, &paint);
|
|
|
|
SkTDArray<uint8_t> text = make_fuzz_text(fuzz, paint);
|
2017-02-14 18:35:14 +00:00
|
|
|
SkPath path;
|
2017-03-06 13:30:44 +00:00
|
|
|
fuzz_path(fuzz, &path, 20);
|
2017-02-27 18:36:38 +00:00
|
|
|
canvas->drawTextOnPath(text.begin(), SkToSizeT(text.count()), path,
|
2017-02-14 18:35:14 +00:00
|
|
|
useMatrix ? &matrix : nullptr, paint);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 50: {
|
2017-03-10 18:56:08 +00:00
|
|
|
fuzz_paint(fuzz, &paint, depth - 1);
|
|
|
|
fuzz_paint_text(fuzz, &paint);
|
2017-03-08 21:52:18 +00:00
|
|
|
fuzz_paint_text_encoding(fuzz, &paint);
|
|
|
|
SkTDArray<uint8_t> text = make_fuzz_text(fuzz, paint);
|
|
|
|
SkRSXform rSXform[kMaxGlyphCount];
|
|
|
|
int glyphCount = paint.countText(text.begin(), SkToSizeT(text.count()));
|
|
|
|
SkASSERT(glyphCount <= kMaxGlyphCount);
|
|
|
|
fuzz->nextN(rSXform, glyphCount);
|
|
|
|
SkRect cullRect;
|
|
|
|
bool useCullRect;
|
|
|
|
fuzz->next(&useCullRect);
|
|
|
|
if (useCullRect) {
|
|
|
|
fuzz->next(&cullRect);
|
|
|
|
}
|
|
|
|
canvas->drawTextRSXform(text.begin(), SkToSizeT(text.count()), rSXform,
|
|
|
|
useCullRect ? &cullRect : nullptr, paint);
|
2017-02-14 18:35:14 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 51: {
|
2017-03-08 21:52:18 +00:00
|
|
|
sk_sp<SkTextBlob> blob = make_fuzz_textblob(fuzz);
|
2017-03-10 18:56:08 +00:00
|
|
|
fuzz_paint(fuzz, &paint, depth - 1);
|
2017-03-08 21:52:18 +00:00
|
|
|
SkScalar x, y;
|
|
|
|
fuzz->next(&x, &y);
|
|
|
|
canvas->drawTextBlob(blob, x, y, paint);
|
2017-02-14 18:35:14 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 52: {
|
|
|
|
bool usePaint, useMatrix;
|
|
|
|
fuzz->next(&usePaint, &useMatrix);
|
|
|
|
if (usePaint) {
|
2017-03-10 18:56:08 +00:00
|
|
|
fuzz_paint(fuzz, &paint, depth - 1);
|
2017-02-14 18:35:14 +00:00
|
|
|
}
|
|
|
|
if (useMatrix) {
|
|
|
|
fuzz->next(&matrix);
|
|
|
|
}
|
2017-03-10 18:56:08 +00:00
|
|
|
auto pic = make_fuzz_picture(fuzz, depth - 1);
|
2017-02-14 18:35:14 +00:00
|
|
|
canvas->drawPicture(pic, useMatrix ? &matrix : nullptr,
|
|
|
|
usePaint ? &paint : nullptr);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 53: {
|
2017-03-10 18:56:08 +00:00
|
|
|
fuzz_paint(fuzz, &paint, depth - 1);
|
2017-04-03 15:11:09 +00:00
|
|
|
SkVertices::VertexMode vertexMode;
|
2017-03-09 19:10:36 +00:00
|
|
|
SkBlendMode blendMode;
|
2017-04-03 15:11:09 +00:00
|
|
|
fuzz_enum_range(fuzz, &vertexMode, 0, SkVertices::kTriangleFan_VertexMode);
|
2017-03-09 19:10:36 +00:00
|
|
|
fuzz->next(&blendMode);
|
2017-02-14 18:35:14 +00:00
|
|
|
constexpr int kMaxCount = 100;
|
|
|
|
int vertexCount;
|
|
|
|
SkPoint vertices[kMaxCount];
|
|
|
|
SkPoint texs[kMaxCount];
|
|
|
|
SkColor colors[kMaxCount];
|
|
|
|
fuzz->nextRange(&vertexCount, 3, kMaxCount);
|
|
|
|
fuzz->nextN(vertices, vertexCount);
|
|
|
|
bool useTexs, useColors;
|
|
|
|
fuzz->next(&useTexs, &useColors);
|
|
|
|
if (useTexs) {
|
|
|
|
fuzz->nextN(texs, vertexCount);
|
|
|
|
}
|
|
|
|
if (useColors) {
|
|
|
|
fuzz->nextN(colors, vertexCount);
|
|
|
|
}
|
|
|
|
int indexCount = 0;
|
2017-03-02 20:27:23 +00:00
|
|
|
uint16_t indices[kMaxCount * 2];
|
2017-03-10 18:56:08 +00:00
|
|
|
if (make_fuzz_t<bool>(fuzz)) {
|
2017-03-02 20:27:23 +00:00
|
|
|
fuzz->nextRange(&indexCount, vertexCount, vertexCount + kMaxCount);
|
|
|
|
for (int i = 0; i < indexCount; ++i) {
|
|
|
|
fuzz->nextRange(&indices[i], 0, vertexCount - 1);
|
|
|
|
}
|
2017-02-14 18:35:14 +00:00
|
|
|
}
|
2017-04-03 15:11:09 +00:00
|
|
|
canvas->drawVertices(SkVertices::MakeCopy(vertexMode, vertexCount, vertices,
|
|
|
|
useTexs ? texs : nullptr,
|
|
|
|
useColors ? colors : nullptr,
|
|
|
|
indexCount, indices),
|
|
|
|
blendMode, paint);
|
2017-02-14 18:35:14 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-10 18:56:08 +00:00
|
|
|
static sk_sp<SkPicture> make_fuzz_picture(Fuzz* fuzz, int depth) {
|
2017-02-14 18:35:14 +00:00
|
|
|
SkScalar w, h;
|
|
|
|
fuzz->next(&w, &h);
|
|
|
|
SkPictureRecorder pictureRecorder;
|
|
|
|
fuzz_canvas(fuzz, pictureRecorder.beginRecording(w, h), depth - 1);
|
|
|
|
return pictureRecorder.finishRecordingAsPicture();
|
|
|
|
}
|
|
|
|
|
2017-03-01 15:42:45 +00:00
|
|
|
DEF_FUZZ(NullCanvas, fuzz) {
|
|
|
|
fuzz_canvas(fuzz, SkMakeNullCanvas().get());
|
|
|
|
}
|
|
|
|
|
2017-03-15 15:39:06 +00:00
|
|
|
// 8.5x11 letter paper at 72ppi.
|
|
|
|
constexpr SkISize kCanvasSize = {612, 792};
|
|
|
|
|
2017-03-01 15:42:45 +00:00
|
|
|
DEF_FUZZ(RasterN32Canvas, fuzz) {
|
2017-03-15 15:39:06 +00:00
|
|
|
auto surface = SkSurface::MakeRasterN32Premul(kCanvasSize.width(), kCanvasSize.height());
|
|
|
|
SkASSERT(surface && surface->getCanvas());
|
|
|
|
fuzz_canvas(fuzz, surface->getCanvas());
|
|
|
|
}
|
|
|
|
|
|
|
|
#if SK_SUPPORT_GPU
|
2017-03-21 18:11:44 +00:00
|
|
|
static void fuzz_ganesh(Fuzz* fuzz, GrContext* context) {
|
|
|
|
SkASSERT(context);
|
|
|
|
auto surface = SkSurface::MakeRenderTarget(
|
|
|
|
context,
|
|
|
|
SkBudgeted::kNo,
|
|
|
|
SkImageInfo::Make(kCanvasSize.width(), kCanvasSize.height(), kRGBA_8888_SkColorType, kPremul_SkAlphaType));
|
|
|
|
SkASSERT(surface && surface->getCanvas());
|
|
|
|
fuzz_canvas(fuzz, surface->getCanvas());
|
|
|
|
}
|
|
|
|
|
2017-03-15 15:39:06 +00:00
|
|
|
DEF_FUZZ(NativeGLCanvas, fuzz) {
|
2017-03-20 12:54:16 +00:00
|
|
|
GrContext* context = sk_gpu_test::GrContextFactory().get(
|
|
|
|
sk_gpu_test::GrContextFactory::kGL_ContextType);
|
|
|
|
if (!context) {
|
|
|
|
context = sk_gpu_test::GrContextFactory().get(
|
|
|
|
sk_gpu_test::GrContextFactory::kGLES_ContextType);
|
|
|
|
}
|
2017-03-21 18:11:44 +00:00
|
|
|
fuzz_ganesh(fuzz, context);
|
|
|
|
}
|
|
|
|
|
|
|
|
DEF_FUZZ(NullGLCanvas, fuzz) {
|
|
|
|
fuzz_ganesh(fuzz, sk_gpu_test::GrContextFactory().get(
|
|
|
|
sk_gpu_test::GrContextFactory::kNullGL_ContextType));
|
|
|
|
}
|
|
|
|
|
|
|
|
DEF_FUZZ(DebugGLCanvas, fuzz) {
|
|
|
|
fuzz_ganesh(fuzz, sk_gpu_test::GrContextFactory().get(
|
|
|
|
sk_gpu_test::GrContextFactory::kDebugGL_ContextType));
|
2017-02-14 18:35:14 +00:00
|
|
|
}
|
2017-03-15 15:39:06 +00:00
|
|
|
#endif
|
2017-02-14 18:35:14 +00:00
|
|
|
|
2017-03-01 15:42:45 +00:00
|
|
|
DEF_FUZZ(PDFCanvas, fuzz) {
|
|
|
|
struct final : public SkWStream {
|
|
|
|
bool write(const void*, size_t n) override { fN += n; return true; }
|
|
|
|
size_t bytesWritten() const override { return fN; }
|
|
|
|
size_t fN = 0;
|
|
|
|
} stream;
|
|
|
|
auto doc = SkDocument::MakePDF(&stream);
|
2017-03-15 15:39:06 +00:00
|
|
|
fuzz_canvas(fuzz, doc->beginPage(SkIntToScalar(kCanvasSize.width()),
|
|
|
|
SkIntToScalar(kCanvasSize.height())));
|
2017-03-01 15:42:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// not a "real" thing to fuzz, used to debug errors found while fuzzing.
|
|
|
|
DEF_FUZZ(_DumpCanvas, fuzz) {
|
2017-03-15 15:39:06 +00:00
|
|
|
SkDebugCanvas debugCanvas(kCanvasSize.width(), kCanvasSize.height());
|
2017-03-01 15:42:45 +00:00
|
|
|
fuzz_canvas(fuzz, &debugCanvas);
|
|
|
|
std::unique_ptr<SkCanvas> nullCanvas = SkMakeNullCanvas();
|
|
|
|
UrlDataManager dataManager(SkString("data"));
|
|
|
|
Json::Value json = debugCanvas.toJSON(dataManager, debugCanvas.getSize(), nullCanvas.get());
|
|
|
|
Json::StyledStreamWriter(" ").write(std::cout, json);
|
|
|
|
}
|