Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2017 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
| 8 | #include "Fuzz.h" |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 9 | |
| 10 | // CORE |
| 11 | #include "SkCanvas.h" |
| 12 | #include "SkColorFilter.h" |
Kevin Lubick | 1ac8fd2 | 2017-03-01 10:42:45 -0500 | [diff] [blame] | 13 | #include "SkDebugCanvas.h" |
| 14 | #include "SkDocument.h" |
Hal Canary | 671e442 | 2017-02-27 13:36:38 -0500 | [diff] [blame] | 15 | #include "SkFontMgr.h" |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 16 | #include "SkImageFilter.h" |
| 17 | #include "SkMaskFilter.h" |
Kevin Lubick | 1ac8fd2 | 2017-03-01 10:42:45 -0500 | [diff] [blame] | 18 | #include "SkNullCanvas.h" |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 19 | #include "SkPathEffect.h" |
| 20 | #include "SkPictureRecorder.h" |
Hal Canary | 5395c59 | 2017-03-08 16:52:18 -0500 | [diff] [blame] | 21 | #include "SkRSXform.h" |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 22 | #include "SkRegion.h" |
Kevin Lubick | 1ac8fd2 | 2017-03-01 10:42:45 -0500 | [diff] [blame] | 23 | #include "SkSurface.h" |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 24 | #include "SkTypeface.h" |
| 25 | |
| 26 | // EFFECTS |
Hal Canary | 5395c59 | 2017-03-08 16:52:18 -0500 | [diff] [blame] | 27 | #include "Sk1DPathEffect.h" |
| 28 | #include "Sk2DPathEffect.h" |
Hal Canary | e03c3e5 | 2017-03-09 11:33:35 -0500 | [diff] [blame] | 29 | #include "SkAlphaThresholdFilter.h" |
Hal Canary | 5395c59 | 2017-03-08 16:52:18 -0500 | [diff] [blame] | 30 | #include "SkArcToPathEffect.h" |
Hal Canary | e03c3e5 | 2017-03-09 11:33:35 -0500 | [diff] [blame] | 31 | #include "SkArithmeticImageFilter.h" |
Hal Canary | 5395c59 | 2017-03-08 16:52:18 -0500 | [diff] [blame] | 32 | #include "SkBlurMaskFilter.h" |
Hal Canary | e03c3e5 | 2017-03-09 11:33:35 -0500 | [diff] [blame] | 33 | #include "SkColorFilterImageFilter.h" |
Hal Canary | 27bece8 | 2017-03-07 16:23:20 -0500 | [diff] [blame] | 34 | #include "SkColorMatrixFilter.h" |
Hal Canary | e03c3e5 | 2017-03-09 11:33:35 -0500 | [diff] [blame] | 35 | #include "SkComposeImageFilter.h" |
Hal Canary | 5395c59 | 2017-03-08 16:52:18 -0500 | [diff] [blame] | 36 | #include "SkCornerPathEffect.h" |
| 37 | #include "SkDashPathEffect.h" |
| 38 | #include "SkDiscretePathEffect.h" |
Hal Canary | e03c3e5 | 2017-03-09 11:33:35 -0500 | [diff] [blame] | 39 | #include "SkDisplacementMapEffect.h" |
| 40 | #include "SkDropShadowImageFilter.h" |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 41 | #include "SkGaussianEdgeShader.h" |
| 42 | #include "SkGradientShader.h" |
Hal Canary | 27bece8 | 2017-03-07 16:23:20 -0500 | [diff] [blame] | 43 | #include "SkHighContrastFilter.h" |
Hal Canary | e03c3e5 | 2017-03-09 11:33:35 -0500 | [diff] [blame] | 44 | #include "SkImageSource.h" |
| 45 | #include "SkLightingImageFilter.h" |
Hal Canary | 27bece8 | 2017-03-07 16:23:20 -0500 | [diff] [blame] | 46 | #include "SkLumaColorFilter.h" |
Hal Canary | e03c3e5 | 2017-03-09 11:33:35 -0500 | [diff] [blame] | 47 | #include "SkMagnifierImageFilter.h" |
| 48 | #include "SkMatrixConvolutionImageFilter.h" |
| 49 | #include "SkMergeImageFilter.h" |
| 50 | #include "SkMorphologyImageFilter.h" |
| 51 | #include "SkOffsetImageFilter.h" |
| 52 | #include "SkPaintImageFilter.h" |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 53 | #include "SkPerlinNoiseShader.h" |
Hal Canary | e03c3e5 | 2017-03-09 11:33:35 -0500 | [diff] [blame] | 54 | #include "SkPictureImageFilter.h" |
Hal Canary | 5395c59 | 2017-03-08 16:52:18 -0500 | [diff] [blame] | 55 | #include "SkRRectsGaussianEdgeMaskFilter.h" |
Hal Canary | 27bece8 | 2017-03-07 16:23:20 -0500 | [diff] [blame] | 56 | #include "SkTableColorFilter.h" |
Hal Canary | e03c3e5 | 2017-03-09 11:33:35 -0500 | [diff] [blame] | 57 | #include "SkTileImageFilter.h" |
| 58 | #include "SkXfermodeImageFilter.h" |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 59 | |
| 60 | // SRC |
| 61 | #include "SkUtils.h" |
| 62 | |
Hal Canary | 44801ca | 2017-03-15 11:39:06 -0400 | [diff] [blame] | 63 | #if SK_SUPPORT_GPU |
| 64 | #include "GrContextFactory.h" |
| 65 | #endif |
| 66 | |
Kevin Lubick | 1ac8fd2 | 2017-03-01 10:42:45 -0500 | [diff] [blame] | 67 | // MISC |
| 68 | |
| 69 | #include <iostream> |
| 70 | |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 71 | // TODO: |
Hal Canary | 5395c59 | 2017-03-08 16:52:18 -0500 | [diff] [blame] | 72 | // SkTextBlob with Unicode |
Hal Canary | 44801ca | 2017-03-15 11:39:06 -0400 | [diff] [blame] | 73 | // SkImage: more types |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 74 | |
Hal Canary | f700520 | 2017-03-10 08:48:28 -0500 | [diff] [blame] | 75 | template <typename T, typename Min, typename Max> |
| 76 | inline void fuzz_enum_range(Fuzz* fuzz, T* value, Min rmin, Max rmax) { |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 77 | using U = skstd::underlying_type_t<T>; |
Hal Canary | f700520 | 2017-03-10 08:48:28 -0500 | [diff] [blame] | 78 | fuzz->nextRange((U*)value, (U)rmin, (U)rmax); |
| 79 | } |
| 80 | |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 81 | // be careful: `foo(make_fuzz_t<T>(f), make_fuzz_t<U>(f))` is undefined. |
| 82 | // In fact, all make_fuzz_foo() functions have this potential problem. |
| 83 | // Use sequence points! |
| 84 | template <typename T> |
| 85 | inline T make_fuzz_t(Fuzz* fuzz) { |
| 86 | T t; |
| 87 | fuzz->next(&t); |
| 88 | return t; |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 89 | } |
| 90 | |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 91 | // We don't always want to test NaNs and infinities. |
Hal Canary | ce540ea | 2017-03-06 08:30:44 -0500 | [diff] [blame] | 92 | static void fuzz_nice_float(Fuzz* fuzz, float* f) { |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 93 | float v; |
| 94 | fuzz->next(&v); |
| 95 | constexpr float kLimit = 1.0e35f; // FLT_MAX? |
| 96 | *f = (v == v && v <= kLimit && v >= -kLimit) ? v : 0.0f; |
Hal Canary | ce540ea | 2017-03-06 08:30:44 -0500 | [diff] [blame] | 97 | } |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 98 | |
Hal Canary | ce540ea | 2017-03-06 08:30:44 -0500 | [diff] [blame] | 99 | template <typename... Args> |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 100 | inline void fuzz_nice_float(Fuzz* fuzz, float* f, Args... rest) { |
Hal Canary | ce540ea | 2017-03-06 08:30:44 -0500 | [diff] [blame] | 101 | fuzz_nice_float(fuzz, f); |
| 102 | fuzz_nice_float(fuzz, rest...); |
| 103 | } |
| 104 | |
| 105 | static void fuzz_path(Fuzz* fuzz, SkPath* path, int maxOps) { |
| 106 | if (maxOps < 2) { |
| 107 | maxOps = 2; |
| 108 | } |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 109 | uint8_t fillType; |
| 110 | fuzz->nextRange(&fillType, 0, (uint8_t)SkPath::kInverseEvenOdd_FillType); |
| 111 | path->setFillType((SkPath::FillType)fillType); |
| 112 | uint8_t numOps; |
Hal Canary | ce540ea | 2017-03-06 08:30:44 -0500 | [diff] [blame] | 113 | fuzz->nextRange(&numOps, 2, maxOps); |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 114 | for (uint8_t i = 0; i < numOps; ++i) { |
| 115 | uint8_t op; |
| 116 | fuzz->nextRange(&op, 0, 6); |
| 117 | SkScalar a, b, c, d, e, f; |
| 118 | switch (op) { |
| 119 | case 0: |
Hal Canary | ce540ea | 2017-03-06 08:30:44 -0500 | [diff] [blame] | 120 | fuzz_nice_float(fuzz, &a, &b); |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 121 | path->moveTo(a, b); |
| 122 | break; |
| 123 | case 1: |
Hal Canary | ce540ea | 2017-03-06 08:30:44 -0500 | [diff] [blame] | 124 | fuzz_nice_float(fuzz, &a, &b); |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 125 | path->lineTo(a, b); |
| 126 | break; |
| 127 | case 2: |
Hal Canary | ce540ea | 2017-03-06 08:30:44 -0500 | [diff] [blame] | 128 | fuzz_nice_float(fuzz, &a, &b, &c, &d); |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 129 | path->quadTo(a, b, c, d); |
| 130 | break; |
| 131 | case 3: |
Hal Canary | ce540ea | 2017-03-06 08:30:44 -0500 | [diff] [blame] | 132 | fuzz_nice_float(fuzz, &a, &b, &c, &d, &e); |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 133 | path->conicTo(a, b, c, d, e); |
| 134 | break; |
| 135 | case 4: |
Hal Canary | ce540ea | 2017-03-06 08:30:44 -0500 | [diff] [blame] | 136 | fuzz_nice_float(fuzz, &a, &b, &c, &d, &e, &f); |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 137 | path->cubicTo(a, b, c, d, e, f); |
| 138 | break; |
| 139 | case 5: |
Hal Canary | ce540ea | 2017-03-06 08:30:44 -0500 | [diff] [blame] | 140 | fuzz_nice_float(fuzz, &a, &b, &c, &d, &e); |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 141 | path->arcTo(a, b, c, d, e); |
| 142 | break; |
| 143 | case 6: |
| 144 | path->close(); |
| 145 | break; |
| 146 | default: |
| 147 | break; |
| 148 | } |
| 149 | } |
| 150 | } |
| 151 | |
Hal Canary | e03c3e5 | 2017-03-09 11:33:35 -0500 | [diff] [blame] | 152 | template <> |
| 153 | inline void Fuzz::next(SkRegion* region) { |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 154 | uint8_t N; |
Hal Canary | e03c3e5 | 2017-03-09 11:33:35 -0500 | [diff] [blame] | 155 | this->nextRange(&N, 0, 10); |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 156 | for (uint8_t i = 0; i < N; ++i) { |
| 157 | SkIRect r; |
| 158 | uint8_t op; |
Hal Canary | e03c3e5 | 2017-03-09 11:33:35 -0500 | [diff] [blame] | 159 | this->next(&r); |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 160 | r.sort(); |
Hal Canary | e03c3e5 | 2017-03-09 11:33:35 -0500 | [diff] [blame] | 161 | this->nextRange(&op, 0, (uint8_t)SkRegion::kLastOp); |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 162 | if (!region->op(r, (SkRegion::Op)op)) { |
| 163 | return; |
| 164 | } |
| 165 | } |
| 166 | } |
| 167 | |
Hal Canary | b69c4b8 | 2017-03-08 11:02:40 -0500 | [diff] [blame] | 168 | template <> |
| 169 | inline void Fuzz::next(SkShader::TileMode* m) { |
Hal Canary | f700520 | 2017-03-10 08:48:28 -0500 | [diff] [blame] | 170 | fuzz_enum_range(this, m, 0, SkShader::kTileModeCount - 1); |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 171 | } |
| 172 | |
Hal Canary | b69c4b8 | 2017-03-08 11:02:40 -0500 | [diff] [blame] | 173 | template <> |
Hal Canary | e03c3e5 | 2017-03-09 11:33:35 -0500 | [diff] [blame] | 174 | inline void Fuzz::next(SkFilterQuality* q) { |
Hal Canary | f700520 | 2017-03-10 08:48:28 -0500 | [diff] [blame] | 175 | fuzz_enum_range(this, q, SkFilterQuality::kNone_SkFilterQuality, |
| 176 | SkFilterQuality::kLast_SkFilterQuality); |
Hal Canary | e03c3e5 | 2017-03-09 11:33:35 -0500 | [diff] [blame] | 177 | } |
| 178 | |
| 179 | template <> |
Hal Canary | b69c4b8 | 2017-03-08 11:02:40 -0500 | [diff] [blame] | 180 | inline void Fuzz::next(SkMatrix* m) { |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 181 | constexpr int kArrayLength = 9; |
| 182 | SkScalar buffer[kArrayLength]; |
| 183 | int matrixType; |
| 184 | this->nextRange(&matrixType, 0, 4); |
| 185 | switch (matrixType) { |
| 186 | case 0: // identity |
| 187 | *m = SkMatrix::I(); |
| 188 | return; |
| 189 | case 1: // translate |
| 190 | this->nextRange(&buffer[0], -4000.0f, 4000.0f); |
| 191 | this->nextRange(&buffer[1], -4000.0f, 4000.0f); |
| 192 | *m = SkMatrix::MakeTrans(buffer[0], buffer[1]); |
| 193 | return; |
| 194 | case 2: // translate + scale |
| 195 | this->nextRange(&buffer[0], -400.0f, 400.0f); |
| 196 | this->nextRange(&buffer[1], -400.0f, 400.0f); |
| 197 | this->nextRange(&buffer[2], -4000.0f, 4000.0f); |
| 198 | this->nextRange(&buffer[3], -4000.0f, 4000.0f); |
| 199 | *m = SkMatrix::MakeScale(buffer[0], buffer[1]); |
| 200 | m->postTranslate(buffer[2], buffer[3]); |
| 201 | return; |
| 202 | case 3: // affine |
| 203 | this->nextN(buffer, 6); |
| 204 | m->setAffine(buffer); |
| 205 | return; |
| 206 | case 4: // perspective |
| 207 | this->nextN(buffer, kArrayLength); |
| 208 | m->set9(buffer); |
| 209 | return; |
| 210 | default: |
| 211 | return; |
| 212 | } |
| 213 | } |
| 214 | |
Hal Canary | b69c4b8 | 2017-03-08 11:02:40 -0500 | [diff] [blame] | 215 | template <> |
| 216 | inline void Fuzz::next(SkRRect* rr) { |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 217 | SkRect r; |
| 218 | SkVector radii[4]; |
| 219 | this->next(&r); |
Hal Canary | 27bece8 | 2017-03-07 16:23:20 -0500 | [diff] [blame] | 220 | r.sort(); |
| 221 | for (SkVector& vec : radii) { |
| 222 | this->nextRange(&vec.fX, 0.0f, 1.0f); |
| 223 | vec.fX *= 0.5f * r.width(); |
| 224 | this->nextRange(&vec.fY, 0.0f, 1.0f); |
| 225 | vec.fY *= 0.5f * r.height(); |
| 226 | } |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 227 | rr->setRectRadii(r, radii); |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 228 | } |
| 229 | |
Hal Canary | b69c4b8 | 2017-03-08 11:02:40 -0500 | [diff] [blame] | 230 | template <> |
| 231 | inline void Fuzz::next(SkBlendMode* mode) { |
Hal Canary | f700520 | 2017-03-10 08:48:28 -0500 | [diff] [blame] | 232 | fuzz_enum_range(this, mode, 0, SkBlendMode::kLastMode); |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 233 | } |
| 234 | |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 235 | static sk_sp<SkImage> make_fuzz_image(Fuzz*); |
Hal Canary | 671e442 | 2017-02-27 13:36:38 -0500 | [diff] [blame] | 236 | |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 237 | static SkBitmap make_fuzz_bitmap(Fuzz*); |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 238 | |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 239 | static sk_sp<SkPicture> make_fuzz_picture(Fuzz*, int depth); |
Hal Canary | 671e442 | 2017-02-27 13:36:38 -0500 | [diff] [blame] | 240 | |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 241 | static sk_sp<SkColorFilter> make_fuzz_colorfilter(Fuzz* fuzz, int depth) { |
Hal Canary | 27bece8 | 2017-03-07 16:23:20 -0500 | [diff] [blame] | 242 | if (depth <= 0) { |
| 243 | return nullptr; |
| 244 | } |
| 245 | int colorFilterType; |
| 246 | fuzz->nextRange(&colorFilterType, 0, 8); |
| 247 | switch (colorFilterType) { |
| 248 | case 0: |
| 249 | return nullptr; |
| 250 | case 1: { |
| 251 | SkColor color; |
| 252 | SkBlendMode mode; |
| 253 | fuzz->next(&color, &mode); |
| 254 | return SkColorFilter::MakeModeFilter(color, mode); |
| 255 | } |
| 256 | case 2: { |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 257 | sk_sp<SkColorFilter> outer = make_fuzz_colorfilter(fuzz, depth - 1); |
| 258 | sk_sp<SkColorFilter> inner = make_fuzz_colorfilter(fuzz, depth - 1); |
Hal Canary | 27bece8 | 2017-03-07 16:23:20 -0500 | [diff] [blame] | 259 | return SkColorFilter::MakeComposeFilter(std::move(outer), std::move(inner)); |
| 260 | } |
| 261 | case 3: { |
| 262 | SkScalar array[20]; |
| 263 | fuzz->nextN(array, SK_ARRAY_COUNT(array)); |
| 264 | return SkColorFilter::MakeMatrixFilterRowMajor255(array); |
| 265 | } |
| 266 | case 4: { |
| 267 | SkColor mul, add; |
| 268 | fuzz->next(&mul, &add); |
| 269 | return SkColorMatrixFilter::MakeLightingFilter(mul, add); |
| 270 | } |
| 271 | case 5: { |
| 272 | bool grayscale; |
| 273 | int invertStyle; |
| 274 | float contrast; |
| 275 | fuzz->next(&grayscale); |
| 276 | fuzz->nextRange(&invertStyle, 0, 2); |
| 277 | fuzz->nextRange(&contrast, -1.0f, 1.0f); |
| 278 | return SkHighContrastFilter::Make(SkHighContrastConfig( |
| 279 | grayscale, SkHighContrastConfig::InvertStyle(invertStyle), contrast)); |
| 280 | } |
| 281 | case 6: |
| 282 | return SkLumaColorFilter::Make(); |
| 283 | case 7: { |
| 284 | uint8_t table[256]; |
| 285 | fuzz->nextN(table, SK_ARRAY_COUNT(table)); |
| 286 | return SkTableColorFilter::Make(table); |
| 287 | } |
| 288 | case 8: { |
| 289 | uint8_t tableA[256]; |
| 290 | uint8_t tableR[256]; |
| 291 | uint8_t tableG[256]; |
| 292 | uint8_t tableB[256]; |
| 293 | fuzz->nextN(tableA, SK_ARRAY_COUNT(tableA)); |
| 294 | fuzz->nextN(tableR, SK_ARRAY_COUNT(tableR)); |
| 295 | fuzz->nextN(tableG, SK_ARRAY_COUNT(tableG)); |
| 296 | fuzz->nextN(tableB, SK_ARRAY_COUNT(tableB)); |
| 297 | return SkTableColorFilter::MakeARGB(tableA, tableR, tableG, tableB); |
| 298 | } |
| 299 | } |
| 300 | return nullptr; |
| 301 | } |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 302 | |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 303 | static void fuzz_gradient_stops(Fuzz* fuzz, SkScalar* pos, int colorCount) { |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 304 | SkScalar totalPos = 0; |
| 305 | for (int i = 0; i < colorCount; ++i) { |
| 306 | fuzz->nextRange(&pos[i], 1.0f, 1024.0f); |
| 307 | totalPos += pos[i]; |
| 308 | } |
| 309 | totalPos = 1.0f / totalPos; |
| 310 | for (int i = 0; i < colorCount; ++i) { |
| 311 | pos[i] *= totalPos; |
| 312 | } |
Hal Canary | b69c4b8 | 2017-03-08 11:02:40 -0500 | [diff] [blame] | 313 | // SkASSERT(fabs(pos[colorCount - 1] - 1.0f) < 0.00001f); |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 314 | pos[colorCount - 1] = 1.0f; |
| 315 | } |
| 316 | |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 317 | static sk_sp<SkShader> make_fuzz_shader(Fuzz* fuzz, int depth) { |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 318 | sk_sp<SkShader> shader1(nullptr), shader2(nullptr); |
| 319 | sk_sp<SkColorFilter> colorFilter(nullptr); |
| 320 | SkBitmap bitmap; |
| 321 | sk_sp<SkImage> img; |
| 322 | SkShader::TileMode tmX, tmY; |
| 323 | bool useMatrix; |
| 324 | SkColor color; |
| 325 | SkMatrix matrix; |
| 326 | SkBlendMode blendMode; |
| 327 | int shaderType; |
| 328 | if (depth <= 0) { |
| 329 | return nullptr; |
| 330 | } |
Hal Canary | 671e442 | 2017-02-27 13:36:38 -0500 | [diff] [blame] | 331 | fuzz->nextRange(&shaderType, 0, 14); |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 332 | switch (shaderType) { |
| 333 | case 0: |
| 334 | return nullptr; |
| 335 | case 1: |
| 336 | return SkShader::MakeEmptyShader(); |
| 337 | case 2: |
| 338 | fuzz->next(&color); |
| 339 | return SkShader::MakeColorShader(color); |
| 340 | case 3: |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 341 | img = make_fuzz_image(fuzz); |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 342 | fuzz->next(&tmX, &tmY, &useMatrix); |
| 343 | if (useMatrix) { |
| 344 | fuzz->next(&matrix); |
| 345 | } |
| 346 | return img->makeShader(tmX, tmY, useMatrix ? &matrix : nullptr); |
| 347 | case 4: |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 348 | bitmap = make_fuzz_bitmap(fuzz); |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 349 | fuzz->next(&tmX, &tmY, &useMatrix); |
| 350 | if (useMatrix) { |
| 351 | fuzz->next(&matrix); |
| 352 | } |
| 353 | return SkShader::MakeBitmapShader(bitmap, tmX, tmY, useMatrix ? &matrix : nullptr); |
| 354 | case 5: |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 355 | shader1 = make_fuzz_shader(fuzz, depth - 1); // limit recursion. |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 356 | fuzz->next(&matrix); |
| 357 | return shader1 ? shader1->makeWithLocalMatrix(matrix) : nullptr; |
| 358 | case 6: |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 359 | shader1 = make_fuzz_shader(fuzz, depth - 1); // limit recursion. |
| 360 | colorFilter = make_fuzz_colorfilter(fuzz, depth - 1); |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 361 | return shader1 ? shader1->makeWithColorFilter(std::move(colorFilter)) : nullptr; |
| 362 | case 7: |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 363 | shader1 = make_fuzz_shader(fuzz, depth - 1); // limit recursion. |
| 364 | shader2 = make_fuzz_shader(fuzz, depth - 1); |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 365 | fuzz->next(&blendMode); |
| 366 | return SkShader::MakeComposeShader(std::move(shader1), std::move(shader2), blendMode); |
Hal Canary | b69c4b8 | 2017-03-08 11:02:40 -0500 | [diff] [blame] | 367 | case 8: { |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 368 | auto pic = make_fuzz_picture(fuzz, depth - 1); |
Hal Canary | b69c4b8 | 2017-03-08 11:02:40 -0500 | [diff] [blame] | 369 | bool useTile; |
| 370 | SkRect tile; |
| 371 | fuzz->next(&tmX, &tmY, &useMatrix, &useTile); |
| 372 | if (useMatrix) { |
| 373 | fuzz->next(&matrix); |
Hal Canary | 671e442 | 2017-02-27 13:36:38 -0500 | [diff] [blame] | 374 | } |
Hal Canary | b69c4b8 | 2017-03-08 11:02:40 -0500 | [diff] [blame] | 375 | if (useTile) { |
| 376 | fuzz->next(&tile); |
| 377 | } |
| 378 | return SkShader::MakePictureShader(std::move(pic), tmX, tmY, |
| 379 | useMatrix ? &matrix : nullptr, |
| 380 | useTile ? &tile : nullptr); |
| 381 | } |
Hal Canary | 671e442 | 2017-02-27 13:36:38 -0500 | [diff] [blame] | 382 | // EFFECTS: |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 383 | case 9: |
Hal Canary | 671e442 | 2017-02-27 13:36:38 -0500 | [diff] [blame] | 384 | return SkGaussianEdgeShader::Make(); |
Hal Canary | b69c4b8 | 2017-03-08 11:02:40 -0500 | [diff] [blame] | 385 | case 10: { |
| 386 | constexpr int kMaxColors = 12; |
| 387 | SkPoint pts[2]; |
| 388 | SkColor colors[kMaxColors]; |
| 389 | SkScalar pos[kMaxColors]; |
| 390 | int colorCount; |
| 391 | bool usePos; |
| 392 | fuzz->nextN(pts, 2); |
| 393 | fuzz->nextRange(&colorCount, 2, kMaxColors); |
| 394 | fuzz->nextN(colors, colorCount); |
| 395 | fuzz->next(&tmX, &useMatrix, &usePos); |
| 396 | if (useMatrix) { |
| 397 | fuzz->next(&matrix); |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 398 | } |
Hal Canary | b69c4b8 | 2017-03-08 11:02:40 -0500 | [diff] [blame] | 399 | if (usePos) { |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 400 | fuzz_gradient_stops(fuzz, pos, colorCount); |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 401 | } |
Hal Canary | b69c4b8 | 2017-03-08 11:02:40 -0500 | [diff] [blame] | 402 | return SkGradientShader::MakeLinear(pts, colors, usePos ? pos : nullptr, colorCount, |
| 403 | tmX, 0, useMatrix ? &matrix : nullptr); |
| 404 | } |
| 405 | case 11: { |
| 406 | constexpr int kMaxColors = 12; |
| 407 | SkPoint center; |
| 408 | SkScalar radius; |
| 409 | int colorCount; |
| 410 | bool usePos; |
| 411 | SkColor colors[kMaxColors]; |
| 412 | SkScalar pos[kMaxColors]; |
| 413 | fuzz->next(&tmX, &useMatrix, &usePos, ¢er, &radius); |
| 414 | fuzz->nextRange(&colorCount, 2, kMaxColors); |
| 415 | fuzz->nextN(colors, colorCount); |
| 416 | if (useMatrix) { |
| 417 | fuzz->next(&matrix); |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 418 | } |
Hal Canary | b69c4b8 | 2017-03-08 11:02:40 -0500 | [diff] [blame] | 419 | if (usePos) { |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 420 | fuzz_gradient_stops(fuzz, pos, colorCount); |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 421 | } |
Hal Canary | b69c4b8 | 2017-03-08 11:02:40 -0500 | [diff] [blame] | 422 | return SkGradientShader::MakeRadial(center, radius, colors, usePos ? pos : nullptr, |
| 423 | colorCount, tmX, 0, useMatrix ? &matrix : nullptr); |
| 424 | } |
| 425 | case 12: { |
| 426 | constexpr int kMaxColors = 12; |
| 427 | SkPoint start, end; |
| 428 | SkScalar startRadius, endRadius; |
| 429 | int colorCount; |
| 430 | bool usePos; |
| 431 | SkColor colors[kMaxColors]; |
| 432 | SkScalar pos[kMaxColors]; |
| 433 | fuzz->next(&tmX, &useMatrix, &usePos, &startRadius, &endRadius, &start, &end); |
| 434 | fuzz->nextRange(&colorCount, 2, kMaxColors); |
| 435 | fuzz->nextN(colors, colorCount); |
| 436 | if (useMatrix) { |
| 437 | fuzz->next(&matrix); |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 438 | } |
Hal Canary | b69c4b8 | 2017-03-08 11:02:40 -0500 | [diff] [blame] | 439 | if (usePos) { |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 440 | fuzz_gradient_stops(fuzz, pos, colorCount); |
Hal Canary | b69c4b8 | 2017-03-08 11:02:40 -0500 | [diff] [blame] | 441 | } |
| 442 | return SkGradientShader::MakeTwoPointConical(start, startRadius, end, endRadius, colors, |
| 443 | usePos ? pos : nullptr, colorCount, tmX, 0, |
| 444 | useMatrix ? &matrix : nullptr); |
| 445 | } |
| 446 | case 13: { |
| 447 | constexpr int kMaxColors = 12; |
| 448 | SkScalar cx, cy; |
| 449 | int colorCount; |
| 450 | bool usePos; |
| 451 | SkColor colors[kMaxColors]; |
| 452 | SkScalar pos[kMaxColors]; |
| 453 | fuzz->next(&cx, &cy, &useMatrix, &usePos); |
| 454 | fuzz->nextRange(&colorCount, 2, kMaxColors); |
| 455 | fuzz->nextN(colors, colorCount); |
| 456 | if (useMatrix) { |
| 457 | fuzz->next(&matrix); |
| 458 | } |
| 459 | if (usePos) { |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 460 | fuzz_gradient_stops(fuzz, pos, colorCount); |
Hal Canary | b69c4b8 | 2017-03-08 11:02:40 -0500 | [diff] [blame] | 461 | } |
| 462 | return SkGradientShader::MakeSweep(cx, cy, colors, usePos ? pos : nullptr, colorCount, |
| 463 | 0, useMatrix ? &matrix : nullptr); |
| 464 | } |
| 465 | case 14: { |
| 466 | SkScalar baseFrequencyX, baseFrequencyY, seed; |
| 467 | int numOctaves; |
| 468 | SkISize tileSize; |
| 469 | bool useTileSize, turbulence; |
| 470 | fuzz->next(&baseFrequencyX, &baseFrequencyY, &seed, &useTileSize, &turbulence); |
| 471 | if (useTileSize) { |
| 472 | fuzz->next(&tileSize); |
| 473 | } |
| 474 | fuzz->nextRange(&numOctaves, 2, 7); |
| 475 | if (turbulence) { |
| 476 | return SkPerlinNoiseShader::MakeTurbulence(baseFrequencyX, baseFrequencyY, |
| 477 | numOctaves, seed, |
| 478 | useTileSize ? &tileSize : nullptr); |
| 479 | } else { |
| 480 | return SkPerlinNoiseShader::MakeFractalNoise(baseFrequencyX, baseFrequencyY, |
| 481 | numOctaves, seed, |
| 482 | useTileSize ? &tileSize : nullptr); |
| 483 | } |
| 484 | } |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 485 | default: |
| 486 | break; |
| 487 | } |
Kevin Lubick | edbeb8b | 2017-02-27 16:45:32 -0500 | [diff] [blame] | 488 | return nullptr; |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 489 | } |
| 490 | |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 491 | static sk_sp<SkPathEffect> make_fuzz_patheffect(Fuzz* fuzz, int depth) { |
Hal Canary | 5395c59 | 2017-03-08 16:52:18 -0500 | [diff] [blame] | 492 | if (depth <= 0) { |
| 493 | return nullptr; |
| 494 | } |
| 495 | uint8_t pathEffectType; |
| 496 | fuzz->nextRange(&pathEffectType, 0, 9); |
| 497 | switch (pathEffectType) { |
| 498 | case 0: { |
| 499 | return nullptr; |
| 500 | } |
| 501 | case 1: { |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 502 | sk_sp<SkPathEffect> first = make_fuzz_patheffect(fuzz, depth - 1); |
| 503 | sk_sp<SkPathEffect> second = make_fuzz_patheffect(fuzz, depth - 1); |
Hal Canary | 5395c59 | 2017-03-08 16:52:18 -0500 | [diff] [blame] | 504 | return SkPathEffect::MakeSum(std::move(first), std::move(second)); |
| 505 | } |
| 506 | case 2: { |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 507 | sk_sp<SkPathEffect> first = make_fuzz_patheffect(fuzz, depth - 1); |
| 508 | sk_sp<SkPathEffect> second = make_fuzz_patheffect(fuzz, depth - 1); |
Hal Canary | 5395c59 | 2017-03-08 16:52:18 -0500 | [diff] [blame] | 509 | return SkPathEffect::MakeCompose(std::move(first), std::move(second)); |
| 510 | } |
| 511 | case 3: { |
| 512 | SkPath path; |
| 513 | fuzz_path(fuzz, &path, 20); |
| 514 | SkScalar advance, phase; |
| 515 | fuzz->next(&advance, &phase); |
Hal Canary | f700520 | 2017-03-10 08:48:28 -0500 | [diff] [blame] | 516 | SkPath1DPathEffect::Style style; |
| 517 | fuzz_enum_range(fuzz, &style, 0, SkPath1DPathEffect::kLastEnum_Style); |
| 518 | return SkPath1DPathEffect::Make(path, advance, phase, style); |
Hal Canary | 5395c59 | 2017-03-08 16:52:18 -0500 | [diff] [blame] | 519 | } |
| 520 | case 4: { |
| 521 | SkScalar width; |
| 522 | SkMatrix matrix; |
| 523 | fuzz->next(&width, &matrix); |
| 524 | return SkLine2DPathEffect::Make(width, matrix); |
| 525 | } |
| 526 | case 5: { |
| 527 | SkPath path; |
| 528 | fuzz_path(fuzz, &path, 20); |
| 529 | SkMatrix matrix; |
| 530 | fuzz->next(&matrix); |
| 531 | return SkPath2DPathEffect::Make(matrix, path); |
| 532 | } |
| 533 | case 6: { |
| 534 | SkScalar radius; |
| 535 | fuzz->next(&radius); |
| 536 | return SkArcToPathEffect::Make(radius); |
| 537 | } |
| 538 | case 7: { |
| 539 | SkScalar radius; |
| 540 | fuzz->next(&radius); |
| 541 | return SkCornerPathEffect::Make(radius); |
| 542 | } |
| 543 | case 8: { |
| 544 | SkScalar phase; |
| 545 | fuzz->next(&phase); |
| 546 | SkScalar intervals[20]; |
| 547 | int count; |
| 548 | fuzz->nextRange(&count, 0, (int)SK_ARRAY_COUNT(intervals)); |
| 549 | fuzz->nextN(intervals, count); |
| 550 | return SkDashPathEffect::Make(intervals, count, phase); |
| 551 | } |
| 552 | case 9: { |
| 553 | SkScalar segLength, dev; |
| 554 | uint32_t seed; |
| 555 | fuzz->next(&segLength, &dev, &seed); |
| 556 | return SkDiscretePathEffect::Make(segLength, dev, seed); |
| 557 | } |
| 558 | default: |
| 559 | SkASSERT(false); |
| 560 | return nullptr; |
| 561 | } |
| 562 | } |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 563 | |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 564 | static sk_sp<SkMaskFilter> make_fuzz_maskfilter(Fuzz* fuzz) { |
Hal Canary | 5395c59 | 2017-03-08 16:52:18 -0500 | [diff] [blame] | 565 | int maskfilterType; |
| 566 | fuzz->nextRange(&maskfilterType, 0, 2); |
| 567 | switch (maskfilterType) { |
| 568 | case 0: |
| 569 | return nullptr; |
| 570 | case 1: { |
Hal Canary | f700520 | 2017-03-10 08:48:28 -0500 | [diff] [blame] | 571 | SkBlurStyle blurStyle; |
| 572 | fuzz_enum_range(fuzz, &blurStyle, 0, kLastEnum_SkBlurStyle); |
Hal Canary | 5395c59 | 2017-03-08 16:52:18 -0500 | [diff] [blame] | 573 | SkScalar sigma; |
| 574 | fuzz->next(&sigma); |
| 575 | SkRect occluder{0.0f, 0.0f, 0.0f, 0.0f}; |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 576 | if (make_fuzz_t<bool>(fuzz)) { |
Hal Canary | 5395c59 | 2017-03-08 16:52:18 -0500 | [diff] [blame] | 577 | fuzz->next(&occluder); |
| 578 | } |
| 579 | uint32_t flags; |
| 580 | fuzz->nextRange(&flags, 0, 3); |
Hal Canary | f700520 | 2017-03-10 08:48:28 -0500 | [diff] [blame] | 581 | return SkBlurMaskFilter::Make(blurStyle, sigma, occluder, flags); |
Hal Canary | 5395c59 | 2017-03-08 16:52:18 -0500 | [diff] [blame] | 582 | } |
| 583 | case 2: { |
| 584 | SkRRect first, second; |
| 585 | SkScalar radius; |
| 586 | fuzz->next(&first, &second, &radius); |
| 587 | return SkRRectsGaussianEdgeMaskFilter::Make(first, second, radius); |
| 588 | } |
| 589 | default: |
| 590 | SkASSERT(false); |
| 591 | return nullptr; |
| 592 | } |
| 593 | } |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 594 | |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 595 | static sk_sp<SkTypeface> make_fuzz_typeface(Fuzz* fuzz) { |
| 596 | if (make_fuzz_t<bool>(fuzz)) { |
Hal Canary | 671e442 | 2017-02-27 13:36:38 -0500 | [diff] [blame] | 597 | return nullptr; |
| 598 | } |
| 599 | auto fontMugger = SkFontMgr::RefDefault(); |
| 600 | SkASSERT(fontMugger); |
| 601 | int familyCount = fontMugger->countFamilies(); |
| 602 | int i, j; |
| 603 | fuzz->nextRange(&i, 0, familyCount - 1); |
| 604 | sk_sp<SkFontStyleSet> family(fontMugger->createStyleSet(i)); |
| 605 | int styleCount = family->count(); |
| 606 | fuzz->nextRange(&j, 0, styleCount - 1); |
| 607 | return sk_sp<SkTypeface>(family->createTypeface(j)); |
| 608 | } |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 609 | |
Hal Canary | e03c3e5 | 2017-03-09 11:33:35 -0500 | [diff] [blame] | 610 | template <> |
| 611 | inline void Fuzz::next(SkImageFilter::CropRect* cropRect) { |
| 612 | SkRect rect; |
| 613 | uint8_t flags; |
| 614 | this->next(&rect); |
| 615 | this->nextRange(&flags, 0, 0xF); |
| 616 | *cropRect = SkImageFilter::CropRect(rect, flags); |
| 617 | } |
| 618 | |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 619 | static sk_sp<SkImageFilter> make_fuzz_imageFilter(Fuzz* fuzz, int depth); |
Hal Canary | e03c3e5 | 2017-03-09 11:33:35 -0500 | [diff] [blame] | 620 | |
| 621 | static sk_sp<SkImageFilter> make_fuzz_lighting_imagefilter(Fuzz* fuzz, int depth) { |
| 622 | if (depth <= 0) { |
| 623 | return nullptr; |
| 624 | } |
| 625 | uint8_t imageFilterType; |
| 626 | fuzz->nextRange(&imageFilterType, 1, 6); |
| 627 | SkPoint3 p, q; |
| 628 | SkColor lightColor; |
| 629 | SkScalar surfaceScale, k, specularExponent, cutoffAngle, shininess; |
| 630 | sk_sp<SkImageFilter> input; |
| 631 | SkImageFilter::CropRect cropRect; |
| 632 | bool useCropRect; |
| 633 | fuzz->next(&useCropRect); |
| 634 | if (useCropRect) { |
| 635 | fuzz->next(&cropRect); |
| 636 | } |
| 637 | switch (imageFilterType) { |
| 638 | case 1: |
| 639 | fuzz->next(&p, &lightColor, &surfaceScale, &k); |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 640 | input = make_fuzz_imageFilter(fuzz, depth - 1); |
Hal Canary | e03c3e5 | 2017-03-09 11:33:35 -0500 | [diff] [blame] | 641 | return SkLightingImageFilter::MakeDistantLitDiffuse(p, lightColor, surfaceScale, k, |
| 642 | std::move(input), |
| 643 | useCropRect ? &cropRect : nullptr); |
| 644 | case 2: |
| 645 | fuzz->next(&p, &lightColor, &surfaceScale, &k); |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 646 | input = make_fuzz_imageFilter(fuzz, depth - 1); |
Hal Canary | e03c3e5 | 2017-03-09 11:33:35 -0500 | [diff] [blame] | 647 | return SkLightingImageFilter::MakePointLitDiffuse(p, lightColor, surfaceScale, k, |
| 648 | std::move(input), |
| 649 | useCropRect ? &cropRect : nullptr); |
| 650 | case 3: |
| 651 | fuzz->next(&p, &q, &specularExponent, &cutoffAngle, &lightColor, &surfaceScale, &k); |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 652 | input = make_fuzz_imageFilter(fuzz, depth - 1); |
Hal Canary | e03c3e5 | 2017-03-09 11:33:35 -0500 | [diff] [blame] | 653 | return SkLightingImageFilter::MakeSpotLitDiffuse( |
| 654 | p, q, specularExponent, cutoffAngle, lightColor, surfaceScale, k, |
| 655 | std::move(input), useCropRect ? &cropRect : nullptr); |
| 656 | case 4: |
| 657 | fuzz->next(&p, &lightColor, &surfaceScale, &k, &shininess); |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 658 | input = make_fuzz_imageFilter(fuzz, depth - 1); |
Hal Canary | e03c3e5 | 2017-03-09 11:33:35 -0500 | [diff] [blame] | 659 | return SkLightingImageFilter::MakeDistantLitSpecular(p, lightColor, surfaceScale, k, |
| 660 | shininess, std::move(input), |
| 661 | useCropRect ? &cropRect : nullptr); |
| 662 | case 5: |
| 663 | fuzz->next(&p, &lightColor, &surfaceScale, &k, &shininess); |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 664 | input = make_fuzz_imageFilter(fuzz, depth - 1); |
Hal Canary | e03c3e5 | 2017-03-09 11:33:35 -0500 | [diff] [blame] | 665 | return SkLightingImageFilter::MakePointLitSpecular(p, lightColor, surfaceScale, k, |
| 666 | shininess, std::move(input), |
| 667 | useCropRect ? &cropRect : nullptr); |
| 668 | case 6: |
| 669 | fuzz->next(&p, &q, &specularExponent, &cutoffAngle, &lightColor, &surfaceScale, &k, |
| 670 | &shininess); |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 671 | input = make_fuzz_imageFilter(fuzz, depth - 1); |
Hal Canary | e03c3e5 | 2017-03-09 11:33:35 -0500 | [diff] [blame] | 672 | return SkLightingImageFilter::MakeSpotLitSpecular( |
| 673 | p, q, specularExponent, cutoffAngle, lightColor, surfaceScale, k, shininess, |
| 674 | std::move(input), useCropRect ? &cropRect : nullptr); |
| 675 | default: |
| 676 | SkASSERT(false); |
| 677 | return nullptr; |
| 678 | } |
| 679 | } |
| 680 | |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 681 | static void fuzz_paint(Fuzz* fuzz, SkPaint* paint, int depth); |
Hal Canary | e03c3e5 | 2017-03-09 11:33:35 -0500 | [diff] [blame] | 682 | |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 683 | static sk_sp<SkImageFilter> make_fuzz_imageFilter(Fuzz* fuzz, int depth) { |
Hal Canary | e03c3e5 | 2017-03-09 11:33:35 -0500 | [diff] [blame] | 684 | if (depth <= 0) { |
| 685 | return nullptr; |
| 686 | } |
| 687 | uint8_t imageFilterType; |
| 688 | fuzz->nextRange(&imageFilterType, 0, 24); |
| 689 | switch (imageFilterType) { |
| 690 | case 0: |
| 691 | return nullptr; |
| 692 | case 1: { |
| 693 | SkScalar sigmaX, sigmaY; |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 694 | sk_sp<SkImageFilter> input = make_fuzz_imageFilter(fuzz, depth - 1); |
Hal Canary | e03c3e5 | 2017-03-09 11:33:35 -0500 | [diff] [blame] | 695 | bool useCropRect; |
| 696 | fuzz->next(&sigmaX, &sigmaY, &useCropRect); |
Kevin Lubick | dad29a0 | 2017-03-14 17:20:24 -0400 | [diff] [blame] | 697 | SkImageFilter::CropRect cropRect; |
Hal Canary | e03c3e5 | 2017-03-09 11:33:35 -0500 | [diff] [blame] | 698 | if (useCropRect) { |
Kevin Lubick | dad29a0 | 2017-03-14 17:20:24 -0400 | [diff] [blame] | 699 | fuzz->next(&cropRect); |
Hal Canary | e03c3e5 | 2017-03-09 11:33:35 -0500 | [diff] [blame] | 700 | } |
| 701 | return SkImageFilter::MakeBlur(sigmaX, sigmaY, std::move(input), |
| 702 | useCropRect ? &cropRect : nullptr); |
| 703 | } |
| 704 | case 2: { |
| 705 | SkMatrix matrix; |
| 706 | SkFilterQuality quality; |
| 707 | fuzz->next(&matrix, &quality); |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 708 | sk_sp<SkImageFilter> input = make_fuzz_imageFilter(fuzz, depth - 1); |
Hal Canary | e03c3e5 | 2017-03-09 11:33:35 -0500 | [diff] [blame] | 709 | return SkImageFilter::MakeMatrixFilter(matrix, quality, std::move(input)); |
| 710 | } |
| 711 | case 3: { |
| 712 | SkRegion region; |
| 713 | SkScalar innerMin, outerMax; |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 714 | sk_sp<SkImageFilter> input = make_fuzz_imageFilter(fuzz, depth - 1); |
Hal Canary | e03c3e5 | 2017-03-09 11:33:35 -0500 | [diff] [blame] | 715 | bool useCropRect; |
| 716 | fuzz->next(®ion, &innerMin, &outerMax, &useCropRect); |
Kevin Lubick | dad29a0 | 2017-03-14 17:20:24 -0400 | [diff] [blame] | 717 | SkImageFilter::CropRect cropRect; |
Hal Canary | e03c3e5 | 2017-03-09 11:33:35 -0500 | [diff] [blame] | 718 | if (useCropRect) { |
Kevin Lubick | dad29a0 | 2017-03-14 17:20:24 -0400 | [diff] [blame] | 719 | fuzz->next(&cropRect); |
Hal Canary | e03c3e5 | 2017-03-09 11:33:35 -0500 | [diff] [blame] | 720 | } |
| 721 | return SkAlphaThresholdFilter::Make(region, innerMin, outerMax, std::move(input), |
| 722 | useCropRect ? &cropRect : nullptr); |
| 723 | } |
| 724 | case 4: { |
| 725 | float k1, k2, k3, k4; |
| 726 | bool enforcePMColor; |
| 727 | bool useCropRect; |
| 728 | fuzz->next(&k1, &k2, &k3, &k4, &enforcePMColor, &useCropRect); |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 729 | sk_sp<SkImageFilter> background = make_fuzz_imageFilter(fuzz, depth - 1); |
| 730 | sk_sp<SkImageFilter> foreground = make_fuzz_imageFilter(fuzz, depth - 1); |
Hal Canary | e03c3e5 | 2017-03-09 11:33:35 -0500 | [diff] [blame] | 731 | SkImageFilter::CropRect cropRect; |
| 732 | if (useCropRect) { |
Kevin Lubick | dad29a0 | 2017-03-14 17:20:24 -0400 | [diff] [blame] | 733 | fuzz->next(&cropRect); |
Hal Canary | e03c3e5 | 2017-03-09 11:33:35 -0500 | [diff] [blame] | 734 | } |
| 735 | return SkArithmeticImageFilter::Make(k1, k2, k3, k4, enforcePMColor, |
| 736 | std::move(background), std::move(foreground), |
| 737 | useCropRect ? &cropRect : nullptr); |
| 738 | } |
| 739 | case 5: { |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 740 | sk_sp<SkColorFilter> cf = make_fuzz_colorfilter(fuzz, depth - 1); |
| 741 | sk_sp<SkImageFilter> input = make_fuzz_imageFilter(fuzz, depth - 1); |
Hal Canary | e03c3e5 | 2017-03-09 11:33:35 -0500 | [diff] [blame] | 742 | bool useCropRect; |
| 743 | SkImageFilter::CropRect cropRect; |
| 744 | fuzz->next(&useCropRect); |
| 745 | if (useCropRect) { |
Kevin Lubick | dad29a0 | 2017-03-14 17:20:24 -0400 | [diff] [blame] | 746 | fuzz->next(&cropRect); |
Hal Canary | e03c3e5 | 2017-03-09 11:33:35 -0500 | [diff] [blame] | 747 | } |
| 748 | return SkColorFilterImageFilter::Make(std::move(cf), std::move(input), |
| 749 | useCropRect ? &cropRect : nullptr); |
| 750 | } |
| 751 | case 6: { |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 752 | sk_sp<SkImageFilter> ifo = make_fuzz_imageFilter(fuzz, depth - 1); |
| 753 | sk_sp<SkImageFilter> ifi = make_fuzz_imageFilter(fuzz, depth - 1); |
Hal Canary | e03c3e5 | 2017-03-09 11:33:35 -0500 | [diff] [blame] | 754 | return SkComposeImageFilter::Make(std::move(ifo), std::move(ifi)); |
| 755 | } |
| 756 | case 7: { |
| 757 | SkDisplacementMapEffect::ChannelSelectorType xChannelSelector, yChannelSelector; |
Hal Canary | f49b1e0 | 2017-03-15 16:58:33 -0400 | [diff] [blame] | 758 | fuzz_enum_range(fuzz, &xChannelSelector, 1, 4); |
| 759 | fuzz_enum_range(fuzz, &yChannelSelector, 1, 4); |
Hal Canary | e03c3e5 | 2017-03-09 11:33:35 -0500 | [diff] [blame] | 760 | SkScalar scale; |
| 761 | bool useCropRect; |
| 762 | fuzz->next(&scale, &useCropRect); |
| 763 | SkImageFilter::CropRect cropRect; |
| 764 | if (useCropRect) { |
Kevin Lubick | dad29a0 | 2017-03-14 17:20:24 -0400 | [diff] [blame] | 765 | fuzz->next(&cropRect); |
Hal Canary | e03c3e5 | 2017-03-09 11:33:35 -0500 | [diff] [blame] | 766 | } |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 767 | sk_sp<SkImageFilter> displacement = make_fuzz_imageFilter(fuzz, depth - 1); |
| 768 | sk_sp<SkImageFilter> color = make_fuzz_imageFilter(fuzz, depth - 1); |
Hal Canary | e03c3e5 | 2017-03-09 11:33:35 -0500 | [diff] [blame] | 769 | return SkDisplacementMapEffect::Make(xChannelSelector, yChannelSelector, scale, |
| 770 | std::move(displacement), std::move(color), |
| 771 | useCropRect ? &cropRect : nullptr); |
| 772 | } |
| 773 | case 8: { |
| 774 | SkScalar dx, dy, sigmaX, sigmaY; |
| 775 | SkColor color; |
| 776 | SkDropShadowImageFilter::ShadowMode shadowMode; |
Hal Canary | f700520 | 2017-03-10 08:48:28 -0500 | [diff] [blame] | 777 | fuzz_enum_range(fuzz, &shadowMode, 0, 1); |
Hal Canary | e03c3e5 | 2017-03-09 11:33:35 -0500 | [diff] [blame] | 778 | bool useCropRect; |
| 779 | fuzz->next(&dx, &dy, &sigmaX, &sigmaY, &color, &useCropRect); |
| 780 | SkImageFilter::CropRect cropRect; |
| 781 | if (useCropRect) { |
Kevin Lubick | dad29a0 | 2017-03-14 17:20:24 -0400 | [diff] [blame] | 782 | fuzz->next(&cropRect); |
Hal Canary | e03c3e5 | 2017-03-09 11:33:35 -0500 | [diff] [blame] | 783 | } |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 784 | sk_sp<SkImageFilter> input = make_fuzz_imageFilter(fuzz, depth - 1); |
Hal Canary | e03c3e5 | 2017-03-09 11:33:35 -0500 | [diff] [blame] | 785 | return SkDropShadowImageFilter::Make(dx, dy, sigmaX, sigmaY, color, shadowMode, |
| 786 | std::move(input), |
| 787 | useCropRect ? &cropRect : nullptr); |
| 788 | } |
| 789 | case 9: |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 790 | return SkImageSource::Make(make_fuzz_image(fuzz)); |
Hal Canary | e03c3e5 | 2017-03-09 11:33:35 -0500 | [diff] [blame] | 791 | case 10: { |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 792 | sk_sp<SkImage> image = make_fuzz_image(fuzz); |
Hal Canary | e03c3e5 | 2017-03-09 11:33:35 -0500 | [diff] [blame] | 793 | SkRect srcRect, dstRect; |
| 794 | SkFilterQuality filterQuality; |
| 795 | fuzz->next(&srcRect, &dstRect, &filterQuality); |
| 796 | return SkImageSource::Make(std::move(image), srcRect, dstRect, filterQuality); |
| 797 | } |
| 798 | case 11: |
| 799 | return make_fuzz_lighting_imagefilter(fuzz, depth - 1); |
| 800 | case 12: { |
| 801 | SkRect srcRect; |
| 802 | SkScalar inset; |
| 803 | bool useCropRect; |
| 804 | SkImageFilter::CropRect cropRect; |
| 805 | fuzz->next(&srcRect, &inset, &useCropRect); |
| 806 | if (useCropRect) { |
Kevin Lubick | dad29a0 | 2017-03-14 17:20:24 -0400 | [diff] [blame] | 807 | fuzz->next(&cropRect); |
Hal Canary | e03c3e5 | 2017-03-09 11:33:35 -0500 | [diff] [blame] | 808 | } |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 809 | sk_sp<SkImageFilter> input = make_fuzz_imageFilter(fuzz, depth - 1); |
Hal Canary | e03c3e5 | 2017-03-09 11:33:35 -0500 | [diff] [blame] | 810 | return SkMagnifierImageFilter::Make(srcRect, inset, std::move(input), |
| 811 | useCropRect ? &cropRect : nullptr); |
| 812 | } |
| 813 | case 13: { |
| 814 | constexpr int kMaxKernelSize = 5; |
| 815 | int32_t n, m; |
| 816 | fuzz->nextRange(&n, 1, kMaxKernelSize); |
| 817 | fuzz->nextRange(&m, 1, kMaxKernelSize); |
| 818 | SkScalar kernel[kMaxKernelSize * kMaxKernelSize]; |
| 819 | fuzz->nextN(kernel, n * m); |
| 820 | int32_t offsetX, offsetY; |
| 821 | fuzz->nextRange(&offsetX, 0, n - 1); |
| 822 | fuzz->nextRange(&offsetY, 0, m - 1); |
| 823 | SkScalar gain, bias; |
| 824 | bool convolveAlpha, useCropRect; |
| 825 | fuzz->next(&gain, &bias, &convolveAlpha, &useCropRect); |
| 826 | SkMatrixConvolutionImageFilter::TileMode tileMode; |
Hal Canary | f700520 | 2017-03-10 08:48:28 -0500 | [diff] [blame] | 827 | fuzz_enum_range(fuzz, &tileMode, 0, 2); |
Hal Canary | e03c3e5 | 2017-03-09 11:33:35 -0500 | [diff] [blame] | 828 | SkImageFilter::CropRect cropRect; |
| 829 | if (useCropRect) { |
Kevin Lubick | dad29a0 | 2017-03-14 17:20:24 -0400 | [diff] [blame] | 830 | fuzz->next(&cropRect); |
Hal Canary | e03c3e5 | 2017-03-09 11:33:35 -0500 | [diff] [blame] | 831 | } |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 832 | sk_sp<SkImageFilter> input = make_fuzz_imageFilter(fuzz, depth - 1); |
Hal Canary | e03c3e5 | 2017-03-09 11:33:35 -0500 | [diff] [blame] | 833 | return SkMatrixConvolutionImageFilter::Make( |
| 834 | SkISize{n, m}, kernel, gain, bias, SkIPoint{offsetX, offsetY}, tileMode, |
| 835 | convolveAlpha, std::move(input), useCropRect ? &cropRect : nullptr); |
| 836 | } |
| 837 | case 14: { |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 838 | sk_sp<SkImageFilter> first = make_fuzz_imageFilter(fuzz, depth - 1); |
| 839 | sk_sp<SkImageFilter> second = make_fuzz_imageFilter(fuzz, depth - 1); |
Hal Canary | e03c3e5 | 2017-03-09 11:33:35 -0500 | [diff] [blame] | 840 | SkBlendMode blendMode; |
| 841 | bool useCropRect; |
| 842 | fuzz->next(&useCropRect, &blendMode); |
| 843 | SkImageFilter::CropRect cropRect; |
| 844 | if (useCropRect) { |
Kevin Lubick | dad29a0 | 2017-03-14 17:20:24 -0400 | [diff] [blame] | 845 | fuzz->next(&cropRect); |
Hal Canary | e03c3e5 | 2017-03-09 11:33:35 -0500 | [diff] [blame] | 846 | } |
| 847 | return SkMergeImageFilter::Make(std::move(first), std::move(second), blendMode, |
| 848 | useCropRect ? &cropRect : nullptr); |
| 849 | } |
| 850 | case 15: { |
| 851 | constexpr int kMaxCount = 4; |
| 852 | sk_sp<SkImageFilter> ifs[kMaxCount]; |
| 853 | SkBlendMode blendModes[kMaxCount]; |
| 854 | int count; |
| 855 | fuzz->nextRange(&count, 1, kMaxCount); |
| 856 | for (int i = 0; i < count; ++i) { |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 857 | ifs[i] = make_fuzz_imageFilter(fuzz, depth - 1); |
Hal Canary | e03c3e5 | 2017-03-09 11:33:35 -0500 | [diff] [blame] | 858 | } |
| 859 | fuzz->nextN(blendModes, count); |
| 860 | bool useCropRect; |
| 861 | fuzz->next(&useCropRect); |
| 862 | SkImageFilter::CropRect cropRect; |
| 863 | if (useCropRect) { |
Kevin Lubick | dad29a0 | 2017-03-14 17:20:24 -0400 | [diff] [blame] | 864 | fuzz->next(&cropRect); |
Hal Canary | e03c3e5 | 2017-03-09 11:33:35 -0500 | [diff] [blame] | 865 | } |
| 866 | return SkMergeImageFilter::MakeN(ifs, count, blendModes, |
| 867 | useCropRect ? &cropRect : nullptr); |
| 868 | } |
| 869 | case 16: { |
| 870 | int rx, ry; |
| 871 | fuzz->next(&rx, &ry); |
| 872 | bool useCropRect; |
| 873 | fuzz->next(&useCropRect); |
| 874 | SkImageFilter::CropRect cropRect; |
| 875 | if (useCropRect) { |
Kevin Lubick | dad29a0 | 2017-03-14 17:20:24 -0400 | [diff] [blame] | 876 | fuzz->next(&cropRect); |
Hal Canary | e03c3e5 | 2017-03-09 11:33:35 -0500 | [diff] [blame] | 877 | } |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 878 | sk_sp<SkImageFilter> input = make_fuzz_imageFilter(fuzz, depth - 1); |
Hal Canary | e03c3e5 | 2017-03-09 11:33:35 -0500 | [diff] [blame] | 879 | return SkDilateImageFilter::Make(rx, ry, std::move(input), |
| 880 | useCropRect ? &cropRect : nullptr); |
| 881 | } |
| 882 | case 17: { |
| 883 | int rx, ry; |
| 884 | fuzz->next(&rx, &ry); |
| 885 | bool useCropRect; |
| 886 | fuzz->next(&useCropRect); |
| 887 | SkImageFilter::CropRect cropRect; |
| 888 | if (useCropRect) { |
Kevin Lubick | dad29a0 | 2017-03-14 17:20:24 -0400 | [diff] [blame] | 889 | fuzz->next(&cropRect); |
Hal Canary | e03c3e5 | 2017-03-09 11:33:35 -0500 | [diff] [blame] | 890 | } |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 891 | sk_sp<SkImageFilter> input = make_fuzz_imageFilter(fuzz, depth - 1); |
Hal Canary | e03c3e5 | 2017-03-09 11:33:35 -0500 | [diff] [blame] | 892 | return SkErodeImageFilter::Make(rx, ry, std::move(input), |
| 893 | useCropRect ? &cropRect : nullptr); |
| 894 | } |
| 895 | case 18: { |
| 896 | SkScalar dx, dy; |
| 897 | fuzz->next(&dx, &dy); |
| 898 | bool useCropRect; |
| 899 | fuzz->next(&useCropRect); |
| 900 | SkImageFilter::CropRect cropRect; |
| 901 | if (useCropRect) { |
Kevin Lubick | dad29a0 | 2017-03-14 17:20:24 -0400 | [diff] [blame] | 902 | fuzz->next(&cropRect); |
Hal Canary | e03c3e5 | 2017-03-09 11:33:35 -0500 | [diff] [blame] | 903 | } |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 904 | sk_sp<SkImageFilter> input = make_fuzz_imageFilter(fuzz, depth - 1); |
Hal Canary | e03c3e5 | 2017-03-09 11:33:35 -0500 | [diff] [blame] | 905 | return SkOffsetImageFilter::Make(dx, dy, std::move(input), |
| 906 | useCropRect ? &cropRect : nullptr); |
| 907 | } |
| 908 | case 19: { |
| 909 | SkPaint paint; |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 910 | fuzz_paint(fuzz, &paint, depth - 1); |
Hal Canary | e03c3e5 | 2017-03-09 11:33:35 -0500 | [diff] [blame] | 911 | bool useCropRect; |
| 912 | fuzz->next(&useCropRect); |
| 913 | SkImageFilter::CropRect cropRect; |
| 914 | if (useCropRect) { |
Kevin Lubick | dad29a0 | 2017-03-14 17:20:24 -0400 | [diff] [blame] | 915 | fuzz->next(&cropRect); |
Hal Canary | e03c3e5 | 2017-03-09 11:33:35 -0500 | [diff] [blame] | 916 | } |
| 917 | return SkPaintImageFilter::Make(paint, useCropRect ? &cropRect : nullptr); |
| 918 | } |
| 919 | case 20: { |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 920 | sk_sp<SkPicture> picture = make_fuzz_picture(fuzz, depth - 1); |
Hal Canary | e03c3e5 | 2017-03-09 11:33:35 -0500 | [diff] [blame] | 921 | return SkPictureImageFilter::Make(std::move(picture)); |
| 922 | } |
| 923 | case 21: { |
| 924 | SkRect cropRect; |
| 925 | fuzz->next(&cropRect); |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 926 | sk_sp<SkPicture> picture = make_fuzz_picture(fuzz, depth - 1); |
Hal Canary | e03c3e5 | 2017-03-09 11:33:35 -0500 | [diff] [blame] | 927 | return SkPictureImageFilter::Make(std::move(picture), cropRect); |
| 928 | } |
| 929 | case 22: { |
| 930 | SkRect cropRect; |
| 931 | SkFilterQuality filterQuality; |
| 932 | fuzz->next(&cropRect, &filterQuality); |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 933 | sk_sp<SkPicture> picture = make_fuzz_picture(fuzz, depth - 1); |
Hal Canary | e03c3e5 | 2017-03-09 11:33:35 -0500 | [diff] [blame] | 934 | return SkPictureImageFilter::MakeForLocalSpace(std::move(picture), cropRect, |
| 935 | filterQuality); |
| 936 | } |
| 937 | case 23: { |
| 938 | SkRect src, dst; |
| 939 | fuzz->next(&src, &dst); |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 940 | sk_sp<SkImageFilter> input = make_fuzz_imageFilter(fuzz, depth - 1); |
Hal Canary | e03c3e5 | 2017-03-09 11:33:35 -0500 | [diff] [blame] | 941 | return SkTileImageFilter::Make(src, dst, std::move(input)); |
| 942 | } |
| 943 | case 24: { |
| 944 | SkBlendMode blendMode; |
| 945 | bool useCropRect; |
| 946 | fuzz->next(&useCropRect, &blendMode); |
| 947 | SkImageFilter::CropRect cropRect; |
| 948 | if (useCropRect) { |
Kevin Lubick | dad29a0 | 2017-03-14 17:20:24 -0400 | [diff] [blame] | 949 | fuzz->next(&cropRect); |
Hal Canary | e03c3e5 | 2017-03-09 11:33:35 -0500 | [diff] [blame] | 950 | } |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 951 | sk_sp<SkImageFilter> bg = make_fuzz_imageFilter(fuzz, depth - 1); |
| 952 | sk_sp<SkImageFilter> fg = make_fuzz_imageFilter(fuzz, depth - 1); |
Hal Canary | e03c3e5 | 2017-03-09 11:33:35 -0500 | [diff] [blame] | 953 | return SkXfermodeImageFilter::Make(blendMode, std::move(bg), std::move(fg), |
| 954 | useCropRect ? &cropRect : nullptr); |
| 955 | } |
| 956 | default: |
| 957 | SkASSERT(false); |
| 958 | return nullptr; |
| 959 | } |
| 960 | } |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 961 | |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 962 | static sk_sp<SkImage> make_fuzz_image(Fuzz* fuzz) { |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 963 | int w, h; |
| 964 | fuzz->nextRange(&w, 1, 1024); |
| 965 | fuzz->nextRange(&h, 1, 1024); |
| 966 | SkAutoTMalloc<SkPMColor> data(w * h); |
| 967 | SkPixmap pixmap(SkImageInfo::MakeN32Premul(w, h), data.get(), w * sizeof(SkPMColor)); |
| 968 | int n = w * h; |
| 969 | for (int i = 0; i < n; ++i) { |
| 970 | SkColor c; |
| 971 | fuzz->next(&c); |
| 972 | data[i] = SkPreMultiplyColor(c); |
| 973 | } |
| 974 | (void)data.release(); |
Hal Canary | b69c4b8 | 2017-03-08 11:02:40 -0500 | [diff] [blame] | 975 | return SkImage::MakeFromRaster(pixmap, [](const void* p, void*) { sk_free((void*)p); }, |
| 976 | nullptr); |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 977 | } |
| 978 | |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 979 | static SkBitmap make_fuzz_bitmap(Fuzz* fuzz) { |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 980 | SkBitmap bitmap; |
| 981 | int w, h; |
| 982 | fuzz->nextRange(&w, 1, 1024); |
| 983 | fuzz->nextRange(&h, 1, 1024); |
| 984 | bitmap.allocN32Pixels(w, h); |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 985 | for (int y = 0; y < h; ++y) { |
| 986 | for (int x = 0; x < w; ++x) { |
| 987 | SkColor c; |
| 988 | fuzz->next(&c); |
| 989 | *bitmap.getAddr32(x, y) = SkPreMultiplyColor(c); |
| 990 | } |
| 991 | } |
| 992 | return bitmap; |
| 993 | } |
| 994 | |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 995 | template <typename T, typename Min, typename Max> |
| 996 | inline T make_fuzz_t_range(Fuzz* fuzz, Min minv, Max maxv) { |
| 997 | T value; |
| 998 | fuzz_enum_range(fuzz, &value, minv, maxv); |
| 999 | return value; |
| 1000 | } |
| 1001 | |
| 1002 | static void fuzz_paint(Fuzz* fuzz, SkPaint* paint, int depth) { |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 1003 | if (!fuzz || !paint || depth <= 0) { |
| 1004 | return; |
| 1005 | } |
| 1006 | |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 1007 | paint->setAntiAlias( make_fuzz_t<bool>(fuzz)); |
| 1008 | paint->setDither( make_fuzz_t<bool>(fuzz)); |
| 1009 | paint->setColor( make_fuzz_t<SkColor>(fuzz)); |
| 1010 | paint->setBlendMode( make_fuzz_t_range<SkBlendMode>(fuzz, 0, SkBlendMode::kLastMode)); |
| 1011 | paint->setFilterQuality(make_fuzz_t_range<SkFilterQuality>(fuzz, 0, kLast_SkFilterQuality)); |
| 1012 | paint->setStyle( make_fuzz_t_range<SkPaint::Style>(fuzz, 0, 2)); |
| 1013 | paint->setShader( make_fuzz_shader(fuzz, depth - 1)); |
| 1014 | paint->setPathEffect( make_fuzz_patheffect(fuzz, depth - 1)); |
| 1015 | paint->setMaskFilter( make_fuzz_maskfilter(fuzz)); |
| 1016 | paint->setImageFilter( make_fuzz_imageFilter(fuzz, depth - 1)); |
| 1017 | paint->setColorFilter( make_fuzz_colorfilter(fuzz, depth - 1)); |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 1018 | |
| 1019 | if (paint->getStyle() != SkPaint::kFill_Style) { |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 1020 | paint->setStrokeWidth(make_fuzz_t<SkScalar>(fuzz)); |
| 1021 | paint->setStrokeMiter(make_fuzz_t<SkScalar>(fuzz)); |
| 1022 | paint->setStrokeCap( make_fuzz_t_range<SkPaint::Cap>(fuzz, 0, SkPaint::kLast_Cap)); |
| 1023 | paint->setStrokeJoin( make_fuzz_t_range<SkPaint::Join>(fuzz, 0, SkPaint::kLast_Join)); |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 1024 | } |
| 1025 | } |
| 1026 | |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 1027 | static void fuzz_paint_text(Fuzz* fuzz, SkPaint* paint) { |
| 1028 | paint->setTypeface( make_fuzz_typeface(fuzz)); |
| 1029 | paint->setTextSize( make_fuzz_t<SkScalar>(fuzz)); |
| 1030 | paint->setTextScaleX( make_fuzz_t<SkScalar>(fuzz)); |
| 1031 | paint->setTextSkewX( make_fuzz_t<SkScalar>(fuzz)); |
| 1032 | paint->setLinearText( make_fuzz_t<bool>(fuzz)); |
| 1033 | paint->setSubpixelText( make_fuzz_t<bool>(fuzz)); |
| 1034 | paint->setLCDRenderText( make_fuzz_t<bool>(fuzz)); |
| 1035 | paint->setEmbeddedBitmapText(make_fuzz_t<bool>(fuzz)); |
| 1036 | paint->setAutohinted( make_fuzz_t<bool>(fuzz)); |
| 1037 | paint->setVerticalText( make_fuzz_t<bool>(fuzz)); |
| 1038 | paint->setFakeBoldText( make_fuzz_t<bool>(fuzz)); |
| 1039 | paint->setDevKernText( make_fuzz_t<bool>(fuzz)); |
| 1040 | paint->setHinting( make_fuzz_t_range<SkPaint::Hinting>(fuzz, 0, |
| 1041 | SkPaint::kFull_Hinting)); |
| 1042 | paint->setTextAlign( make_fuzz_t_range<SkPaint::Align>(fuzz, 0, 2)); |
Hal Canary | 5395c59 | 2017-03-08 16:52:18 -0500 | [diff] [blame] | 1043 | } |
| 1044 | |
| 1045 | static void fuzz_paint_text_encoding(Fuzz* fuzz, SkPaint* paint) { |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 1046 | paint->setTextEncoding(make_fuzz_t_range<SkPaint::TextEncoding>(fuzz, 0, 3)); |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 1047 | } |
| 1048 | |
Hal Canary | 5395c59 | 2017-03-08 16:52:18 -0500 | [diff] [blame] | 1049 | constexpr int kMaxGlyphCount = 30; |
| 1050 | |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 1051 | static SkTDArray<uint8_t> make_fuzz_text(Fuzz* fuzz, const SkPaint& paint) { |
Hal Canary | 671e442 | 2017-02-27 13:36:38 -0500 | [diff] [blame] | 1052 | SkTDArray<uint8_t> array; |
| 1053 | if (SkPaint::kGlyphID_TextEncoding == paint.getTextEncoding()) { |
Hal Canary | b69c4b8 | 2017-03-08 11:02:40 -0500 | [diff] [blame] | 1054 | int glyphRange = paint.getTypeface() ? paint.getTypeface()->countGlyphs() |
| 1055 | : SkTypeface::MakeDefault()->countGlyphs(); |
Hal Canary | 671e442 | 2017-02-27 13:36:38 -0500 | [diff] [blame] | 1056 | int glyphCount; |
Hal Canary | 5395c59 | 2017-03-08 16:52:18 -0500 | [diff] [blame] | 1057 | fuzz->nextRange(&glyphCount, 1, kMaxGlyphCount); |
Hal Canary | 671e442 | 2017-02-27 13:36:38 -0500 | [diff] [blame] | 1058 | SkGlyphID* glyphs = (SkGlyphID*)array.append(glyphCount * sizeof(SkGlyphID)); |
| 1059 | for (int i = 0; i < glyphCount; ++i) { |
| 1060 | fuzz->nextRange(&glyphs[i], 0, glyphRange - 1); |
| 1061 | } |
| 1062 | return array; |
| 1063 | } |
| 1064 | static const SkUnichar ranges[][2] = { |
| 1065 | {0x0020, 0x007F}, |
| 1066 | {0x00A1, 0x0250}, |
| 1067 | {0x0400, 0x0500}, |
| 1068 | }; |
| 1069 | int32_t count = 0; |
Hal Canary | b69c4b8 | 2017-03-08 11:02:40 -0500 | [diff] [blame] | 1070 | for (size_t i = 0; i < SK_ARRAY_COUNT(ranges); ++i) { |
Hal Canary | 671e442 | 2017-02-27 13:36:38 -0500 | [diff] [blame] | 1071 | count += (ranges[i][1] - ranges[i][0]); |
| 1072 | } |
Hal Canary | 5395c59 | 2017-03-08 16:52:18 -0500 | [diff] [blame] | 1073 | constexpr int kMaxLength = kMaxGlyphCount; |
Hal Canary | 671e442 | 2017-02-27 13:36:38 -0500 | [diff] [blame] | 1074 | SkUnichar buffer[kMaxLength]; |
| 1075 | int length; |
| 1076 | fuzz->nextRange(&length, 1, kMaxLength); |
| 1077 | for (int j = 0; j < length; ++j) { |
| 1078 | int32_t value; |
| 1079 | fuzz->nextRange(&value, 0, count - 1); |
Hal Canary | b69c4b8 | 2017-03-08 11:02:40 -0500 | [diff] [blame] | 1080 | for (size_t i = 0; i < SK_ARRAY_COUNT(ranges); ++i) { |
Hal Canary | 671e442 | 2017-02-27 13:36:38 -0500 | [diff] [blame] | 1081 | if (value + ranges[i][0] < ranges[i][1]) { |
| 1082 | buffer[j] = value + ranges[i][0]; |
| 1083 | break; |
| 1084 | } else { |
| 1085 | value -= (ranges[i][1] - ranges[i][0]); |
| 1086 | } |
| 1087 | } |
| 1088 | } |
| 1089 | switch (paint.getTextEncoding()) { |
Hal Canary | b69c4b8 | 2017-03-08 11:02:40 -0500 | [diff] [blame] | 1090 | case SkPaint::kUTF8_TextEncoding: { |
| 1091 | size_t utf8len = 0; |
| 1092 | for (int j = 0; j < length; ++j) { |
| 1093 | utf8len += SkUTF8_FromUnichar(buffer[j], nullptr); |
Hal Canary | 671e442 | 2017-02-27 13:36:38 -0500 | [diff] [blame] | 1094 | } |
Hal Canary | b69c4b8 | 2017-03-08 11:02:40 -0500 | [diff] [blame] | 1095 | char* ptr = (char*)array.append(utf8len); |
| 1096 | for (int j = 0; j < length; ++j) { |
| 1097 | ptr += SkUTF8_FromUnichar(buffer[j], ptr); |
Hal Canary | 671e442 | 2017-02-27 13:36:38 -0500 | [diff] [blame] | 1098 | } |
Hal Canary | b69c4b8 | 2017-03-08 11:02:40 -0500 | [diff] [blame] | 1099 | } break; |
| 1100 | case SkPaint::kUTF16_TextEncoding: { |
| 1101 | size_t utf16len = 0; |
| 1102 | for (int j = 0; j < length; ++j) { |
| 1103 | utf16len += SkUTF16_FromUnichar(buffer[j]); |
| 1104 | } |
| 1105 | uint16_t* ptr = (uint16_t*)array.append(utf16len * sizeof(uint16_t)); |
| 1106 | for (int j = 0; j < length; ++j) { |
| 1107 | ptr += SkUTF16_FromUnichar(buffer[j], ptr); |
| 1108 | } |
| 1109 | } break; |
Hal Canary | 671e442 | 2017-02-27 13:36:38 -0500 | [diff] [blame] | 1110 | case SkPaint::kUTF32_TextEncoding: |
| 1111 | memcpy(array.append(length * sizeof(SkUnichar)), buffer, length * sizeof(SkUnichar)); |
Hal Canary | c1a70e2 | 2017-03-01 15:40:46 -0500 | [diff] [blame] | 1112 | break; |
Hal Canary | 671e442 | 2017-02-27 13:36:38 -0500 | [diff] [blame] | 1113 | default: |
Hal Canary | b69c4b8 | 2017-03-08 11:02:40 -0500 | [diff] [blame] | 1114 | SkASSERT(false); |
Hal Canary | 671e442 | 2017-02-27 13:36:38 -0500 | [diff] [blame] | 1115 | } |
| 1116 | return array; |
| 1117 | } |
| 1118 | |
Hal Canary | 5395c59 | 2017-03-08 16:52:18 -0500 | [diff] [blame] | 1119 | static sk_sp<SkTextBlob> make_fuzz_textblob(Fuzz* fuzz) { |
| 1120 | SkTextBlobBuilder textBlobBuilder; |
| 1121 | int8_t runCount; |
| 1122 | fuzz->nextRange(&runCount, (int8_t)1, (int8_t)8); |
| 1123 | while (runCount-- > 0) { |
| 1124 | SkPaint paint; |
| 1125 | fuzz_paint_text_encoding(fuzz, &paint); |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 1126 | paint.setAntiAlias(make_fuzz_t<bool>(fuzz)); |
Hal Canary | 5395c59 | 2017-03-08 16:52:18 -0500 | [diff] [blame] | 1127 | paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding); |
| 1128 | SkTDArray<uint8_t> text = make_fuzz_text(fuzz, paint); |
| 1129 | int glyphCount = paint.countText(text.begin(), SkToSizeT(text.count())); |
| 1130 | SkASSERT(glyphCount <= kMaxGlyphCount); |
| 1131 | SkScalar x, y; |
| 1132 | const SkTextBlobBuilder::RunBuffer* buffer; |
| 1133 | uint8_t runType; |
| 1134 | fuzz->nextRange(&runType, (uint8_t)0, (uint8_t)2); |
| 1135 | switch (runType) { |
| 1136 | case 0: |
| 1137 | fuzz->next(&x, &y); |
| 1138 | // TODO: Test other variations of this. |
| 1139 | buffer = &textBlobBuilder.allocRun(paint, glyphCount, x, y); |
| 1140 | memcpy(buffer->glyphs, text.begin(), SkToSizeT(text.count())); |
| 1141 | break; |
| 1142 | case 1: |
| 1143 | fuzz->next(&y); |
| 1144 | // TODO: Test other variations of this. |
| 1145 | buffer = &textBlobBuilder.allocRunPosH(paint, glyphCount, y); |
| 1146 | memcpy(buffer->glyphs, text.begin(), SkToSizeT(text.count())); |
| 1147 | fuzz->nextN(buffer->pos, glyphCount); |
| 1148 | break; |
| 1149 | case 2: |
| 1150 | // TODO: Test other variations of this. |
| 1151 | buffer = &textBlobBuilder.allocRunPos(paint, glyphCount); |
| 1152 | memcpy(buffer->glyphs, text.begin(), SkToSizeT(text.count())); |
| 1153 | fuzz->nextN(buffer->pos, glyphCount * 2); |
| 1154 | break; |
| 1155 | default: |
| 1156 | SkASSERT(false); |
| 1157 | } |
| 1158 | } |
| 1159 | return textBlobBuilder.make(); |
| 1160 | } |
| 1161 | |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 1162 | static void fuzz_canvas(Fuzz* fuzz, SkCanvas* canvas, int depth = 9) { |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 1163 | if (!fuzz || !canvas || depth <= 0) { |
| 1164 | return; |
| 1165 | } |
| 1166 | SkAutoCanvasRestore autoCanvasRestore(canvas, false); |
| 1167 | unsigned N; |
| 1168 | fuzz->nextRange(&N, 0, 2000); |
| 1169 | for (unsigned i = 0; i < N; ++i) { |
| 1170 | if (fuzz->exhausted()) { |
| 1171 | return; |
| 1172 | } |
| 1173 | SkPaint paint; |
| 1174 | SkMatrix matrix; |
| 1175 | unsigned drawCommand; |
Hal Canary | 5af600e | 2017-03-09 14:10:36 -0500 | [diff] [blame] | 1176 | fuzz->nextRange(&drawCommand, 0, 53); |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 1177 | switch (drawCommand) { |
| 1178 | case 0: |
| 1179 | canvas->flush(); |
| 1180 | break; |
| 1181 | case 1: |
| 1182 | canvas->save(); |
| 1183 | break; |
| 1184 | case 2: { |
| 1185 | SkRect bounds; |
| 1186 | fuzz->next(&bounds); |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 1187 | fuzz_paint(fuzz, &paint, depth - 1); |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 1188 | canvas->saveLayer(&bounds, &paint); |
| 1189 | break; |
| 1190 | } |
| 1191 | case 3: { |
| 1192 | SkRect bounds; |
| 1193 | fuzz->next(&bounds); |
| 1194 | canvas->saveLayer(&bounds, nullptr); |
| 1195 | break; |
| 1196 | } |
| 1197 | case 4: |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 1198 | fuzz_paint(fuzz, &paint, depth - 1); |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 1199 | canvas->saveLayer(nullptr, &paint); |
| 1200 | break; |
| 1201 | case 5: |
| 1202 | canvas->saveLayer(nullptr, nullptr); |
| 1203 | break; |
| 1204 | case 6: { |
| 1205 | uint8_t alpha; |
| 1206 | fuzz->next(&alpha); |
| 1207 | canvas->saveLayerAlpha(nullptr, (U8CPU)alpha); |
| 1208 | break; |
| 1209 | } |
| 1210 | case 7: { |
| 1211 | SkRect bounds; |
| 1212 | uint8_t alpha; |
| 1213 | fuzz->next(&bounds, &alpha); |
| 1214 | canvas->saveLayerAlpha(&bounds, (U8CPU)alpha); |
| 1215 | break; |
| 1216 | } |
| 1217 | case 8: { |
| 1218 | SkCanvas::SaveLayerRec saveLayerRec; |
| 1219 | SkRect bounds; |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 1220 | if (make_fuzz_t<bool>(fuzz)) { |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 1221 | fuzz->next(&bounds); |
| 1222 | saveLayerRec.fBounds = &bounds; |
| 1223 | } |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 1224 | if (make_fuzz_t<bool>(fuzz)) { |
| 1225 | fuzz_paint(fuzz, &paint, depth - 1); |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 1226 | saveLayerRec.fPaint = &paint; |
| 1227 | } |
| 1228 | sk_sp<SkImageFilter> imageFilter; |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 1229 | if (make_fuzz_t<bool>(fuzz)) { |
| 1230 | imageFilter = make_fuzz_imageFilter(fuzz, depth - 1); |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 1231 | saveLayerRec.fBackdrop = imageFilter.get(); |
| 1232 | } |
Hal Canary | 5395c59 | 2017-03-08 16:52:18 -0500 | [diff] [blame] | 1233 | // _DumpCanvas can't handle this. |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 1234 | // if (make_fuzz_t<bool>(fuzz)) { |
Hal Canary | 5395c59 | 2017-03-08 16:52:18 -0500 | [diff] [blame] | 1235 | // saveLayerRec.fSaveLayerFlags |= SkCanvas::kIsOpaque_SaveLayerFlag; |
| 1236 | // } |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 1237 | // if (make_fuzz_t<bool>(fuzz)) { |
Hal Canary | 5395c59 | 2017-03-08 16:52:18 -0500 | [diff] [blame] | 1238 | // saveLayerRec.fSaveLayerFlags |= SkCanvas::kPreserveLCDText_SaveLayerFlag; |
| 1239 | // } |
| 1240 | |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 1241 | canvas->saveLayer(saveLayerRec); |
| 1242 | break; |
| 1243 | } |
| 1244 | case 9: |
| 1245 | canvas->restore(); |
| 1246 | break; |
| 1247 | case 10: { |
| 1248 | int saveCount; |
| 1249 | fuzz->next(&saveCount); |
| 1250 | canvas->restoreToCount(saveCount); |
| 1251 | break; |
| 1252 | } |
| 1253 | case 11: { |
| 1254 | SkScalar x, y; |
| 1255 | fuzz->next(&x, &y); |
| 1256 | canvas->translate(x, y); |
| 1257 | break; |
| 1258 | } |
| 1259 | case 12: { |
| 1260 | SkScalar x, y; |
| 1261 | fuzz->next(&x, &y); |
| 1262 | canvas->scale(x, y); |
| 1263 | break; |
| 1264 | } |
| 1265 | case 13: { |
| 1266 | SkScalar v; |
| 1267 | fuzz->next(&v); |
| 1268 | canvas->rotate(v); |
| 1269 | break; |
| 1270 | } |
| 1271 | case 14: { |
| 1272 | SkScalar x, y, v; |
| 1273 | fuzz->next(&x, &y, &v); |
| 1274 | canvas->rotate(v, x, y); |
| 1275 | break; |
| 1276 | } |
| 1277 | case 15: { |
| 1278 | SkScalar x, y; |
| 1279 | fuzz->next(&x, &y); |
| 1280 | canvas->skew(x, y); |
| 1281 | break; |
| 1282 | } |
| 1283 | case 16: { |
| 1284 | SkMatrix mat; |
| 1285 | fuzz->next(&mat); |
| 1286 | canvas->concat(mat); |
| 1287 | break; |
| 1288 | } |
| 1289 | case 17: { |
| 1290 | SkMatrix mat; |
| 1291 | fuzz->next(&mat); |
| 1292 | canvas->setMatrix(mat); |
| 1293 | break; |
| 1294 | } |
| 1295 | case 18: |
| 1296 | canvas->resetMatrix(); |
| 1297 | break; |
| 1298 | case 19: { |
| 1299 | SkRect r; |
| 1300 | int op; |
| 1301 | bool doAntiAlias; |
| 1302 | fuzz->next(&r, &doAntiAlias); |
| 1303 | fuzz->nextRange(&op, 0, 1); |
| 1304 | r.sort(); |
| 1305 | canvas->clipRect(r, (SkClipOp)op, doAntiAlias); |
| 1306 | break; |
| 1307 | } |
| 1308 | case 20: { |
| 1309 | SkRRect rr; |
| 1310 | int op; |
| 1311 | bool doAntiAlias; |
| 1312 | fuzz->next(&rr); |
| 1313 | fuzz->next(&doAntiAlias); |
| 1314 | fuzz->nextRange(&op, 0, 1); |
| 1315 | canvas->clipRRect(rr, (SkClipOp)op, doAntiAlias); |
| 1316 | break; |
| 1317 | } |
| 1318 | case 21: { |
| 1319 | SkPath path; |
Hal Canary | ce540ea | 2017-03-06 08:30:44 -0500 | [diff] [blame] | 1320 | fuzz_path(fuzz, &path, 30); |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 1321 | int op; |
| 1322 | bool doAntiAlias; |
| 1323 | fuzz->next(&doAntiAlias); |
| 1324 | fuzz->nextRange(&op, 0, 1); |
| 1325 | canvas->clipPath(path, (SkClipOp)op, doAntiAlias); |
| 1326 | break; |
| 1327 | } |
| 1328 | case 22: { |
| 1329 | SkRegion region; |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 1330 | int op; |
Hal Canary | e03c3e5 | 2017-03-09 11:33:35 -0500 | [diff] [blame] | 1331 | fuzz->next(®ion); |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 1332 | fuzz->nextRange(&op, 0, 1); |
| 1333 | canvas->clipRegion(region, (SkClipOp)op); |
| 1334 | break; |
| 1335 | } |
| 1336 | case 23: |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 1337 | fuzz_paint(fuzz, &paint, depth - 1); |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 1338 | canvas->drawPaint(paint); |
| 1339 | break; |
| 1340 | case 24: { |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 1341 | fuzz_paint(fuzz, &paint, depth - 1); |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 1342 | uint8_t pointMode; |
| 1343 | fuzz->nextRange(&pointMode, 0, 3); |
| 1344 | size_t count; |
| 1345 | constexpr int kMaxCount = 30; |
| 1346 | fuzz->nextRange(&count, 0, kMaxCount); |
| 1347 | SkPoint pts[kMaxCount]; |
| 1348 | fuzz->nextN(pts, count); |
| 1349 | canvas->drawPoints((SkCanvas::PointMode)pointMode, count, pts, paint); |
| 1350 | break; |
| 1351 | } |
| 1352 | case 25: { |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 1353 | fuzz_paint(fuzz, &paint, depth - 1); |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 1354 | SkRect r; |
| 1355 | fuzz->next(&r); |
| 1356 | canvas->drawRect(r, paint); |
| 1357 | break; |
| 1358 | } |
| 1359 | case 26: { |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 1360 | fuzz_paint(fuzz, &paint, depth - 1); |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 1361 | SkRegion region; |
Hal Canary | e03c3e5 | 2017-03-09 11:33:35 -0500 | [diff] [blame] | 1362 | fuzz->next(®ion); |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 1363 | canvas->drawRegion(region, paint); |
| 1364 | break; |
| 1365 | } |
| 1366 | case 27: { |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 1367 | fuzz_paint(fuzz, &paint, depth - 1); |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 1368 | SkRect r; |
| 1369 | fuzz->next(&r); |
| 1370 | canvas->drawOval(r, paint); |
| 1371 | break; |
| 1372 | } |
| 1373 | case 29: { |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 1374 | fuzz_paint(fuzz, &paint, depth - 1); |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 1375 | SkRRect rr; |
| 1376 | fuzz->next(&rr); |
| 1377 | canvas->drawRRect(rr, paint); |
| 1378 | break; |
| 1379 | } |
| 1380 | case 30: { |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 1381 | fuzz_paint(fuzz, &paint, depth - 1); |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 1382 | SkRRect orr, irr; |
| 1383 | fuzz->next(&orr); |
| 1384 | fuzz->next(&irr); |
Hal Canary | 27bece8 | 2017-03-07 16:23:20 -0500 | [diff] [blame] | 1385 | if (orr.getBounds().contains(irr.getBounds())) { |
| 1386 | canvas->drawDRRect(orr, irr, paint); |
| 1387 | } |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 1388 | break; |
| 1389 | } |
| 1390 | case 31: { |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 1391 | fuzz_paint(fuzz, &paint, depth - 1); |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 1392 | SkRect r; |
| 1393 | SkScalar start, sweep; |
| 1394 | bool useCenter; |
| 1395 | fuzz->next(&r, &start, &sweep, &useCenter); |
| 1396 | canvas->drawArc(r, start, sweep, useCenter, paint); |
| 1397 | break; |
| 1398 | } |
| 1399 | case 32: { |
| 1400 | SkPath path; |
Hal Canary | ce540ea | 2017-03-06 08:30:44 -0500 | [diff] [blame] | 1401 | fuzz_path(fuzz, &path, 60); |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 1402 | canvas->drawPath(path, paint); |
| 1403 | break; |
| 1404 | } |
| 1405 | case 33: { |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 1406 | sk_sp<SkImage> img = make_fuzz_image(fuzz); |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 1407 | SkScalar left, top; |
| 1408 | bool usePaint; |
| 1409 | fuzz->next(&left, &top, &usePaint); |
| 1410 | if (usePaint) { |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 1411 | fuzz_paint(fuzz, &paint, depth - 1); |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 1412 | } |
| 1413 | canvas->drawImage(img.get(), left, top, usePaint ? &paint : nullptr); |
| 1414 | break; |
| 1415 | } |
| 1416 | case 34: { |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 1417 | auto img = make_fuzz_image(fuzz); |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 1418 | SkRect src, dst; |
| 1419 | bool usePaint; |
| 1420 | fuzz->next(&src, &dst, &usePaint); |
| 1421 | if (usePaint) { |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 1422 | fuzz_paint(fuzz, &paint, depth - 1); |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 1423 | } |
Hal Canary | b69c4b8 | 2017-03-08 11:02:40 -0500 | [diff] [blame] | 1424 | SkCanvas::SrcRectConstraint constraint = |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 1425 | make_fuzz_t<bool>(fuzz) ? SkCanvas::kStrict_SrcRectConstraint |
| 1426 | : SkCanvas::kFast_SrcRectConstraint; |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 1427 | canvas->drawImageRect(img, src, dst, usePaint ? &paint : nullptr, constraint); |
| 1428 | break; |
| 1429 | } |
| 1430 | case 35: { |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 1431 | auto img = make_fuzz_image(fuzz); |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 1432 | SkIRect src; |
| 1433 | SkRect dst; |
| 1434 | bool usePaint; |
| 1435 | fuzz->next(&src, &dst, &usePaint); |
| 1436 | if (usePaint) { |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 1437 | fuzz_paint(fuzz, &paint, depth - 1); |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 1438 | } |
Hal Canary | b69c4b8 | 2017-03-08 11:02:40 -0500 | [diff] [blame] | 1439 | SkCanvas::SrcRectConstraint constraint = |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 1440 | make_fuzz_t<bool>(fuzz) ? SkCanvas::kStrict_SrcRectConstraint |
| 1441 | : SkCanvas::kFast_SrcRectConstraint; |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 1442 | canvas->drawImageRect(img, src, dst, usePaint ? &paint : nullptr, constraint); |
| 1443 | break; |
| 1444 | } |
| 1445 | case 36: { |
| 1446 | bool usePaint; |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 1447 | auto img = make_fuzz_image(fuzz); |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 1448 | SkRect dst; |
| 1449 | fuzz->next(&dst, &usePaint); |
| 1450 | if (usePaint) { |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 1451 | fuzz_paint(fuzz, &paint, depth - 1); |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 1452 | } |
Hal Canary | b69c4b8 | 2017-03-08 11:02:40 -0500 | [diff] [blame] | 1453 | SkCanvas::SrcRectConstraint constraint = |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 1454 | make_fuzz_t<bool>(fuzz) ? SkCanvas::kStrict_SrcRectConstraint |
| 1455 | : SkCanvas::kFast_SrcRectConstraint; |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 1456 | canvas->drawImageRect(img, dst, usePaint ? &paint : nullptr, constraint); |
| 1457 | break; |
| 1458 | } |
| 1459 | case 37: { |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 1460 | auto img = make_fuzz_image(fuzz); |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 1461 | SkIRect center; |
| 1462 | SkRect dst; |
| 1463 | bool usePaint; |
Hal Canary | 0361d49 | 2017-03-15 12:58:15 -0400 | [diff] [blame] | 1464 | fuzz->next(&usePaint); |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 1465 | if (usePaint) { |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 1466 | fuzz_paint(fuzz, &paint, depth - 1); |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 1467 | } |
Hal Canary | 0361d49 | 2017-03-15 12:58:15 -0400 | [diff] [blame] | 1468 | if (make_fuzz_t<bool>(fuzz)) { |
| 1469 | fuzz->next(¢er); |
| 1470 | } else { // Make valid center, see SkLatticeIter::Valid(). |
| 1471 | fuzz->nextRange(¢er.fLeft, 0, img->width() - 1); |
| 1472 | fuzz->nextRange(¢er.fTop, 0, img->height() - 1); |
| 1473 | fuzz->nextRange(¢er.fRight, center.fLeft + 1, img->width()); |
| 1474 | fuzz->nextRange(¢er.fBottom, center.fTop + 1, img->height()); |
| 1475 | } |
| 1476 | fuzz->next(&dst); |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 1477 | canvas->drawImageNine(img, center, dst, usePaint ? &paint : nullptr); |
| 1478 | break; |
| 1479 | } |
| 1480 | case 38: { |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 1481 | SkBitmap bitmap = make_fuzz_bitmap(fuzz); |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 1482 | SkScalar left, top; |
| 1483 | bool usePaint; |
| 1484 | fuzz->next(&left, &top, &usePaint); |
| 1485 | if (usePaint) { |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 1486 | fuzz_paint(fuzz, &paint, depth - 1); |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 1487 | } |
| 1488 | canvas->drawBitmap(bitmap, left, top, usePaint ? &paint : nullptr); |
| 1489 | break; |
| 1490 | } |
| 1491 | case 39: { |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 1492 | SkBitmap bitmap = make_fuzz_bitmap(fuzz); |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 1493 | SkRect src, dst; |
| 1494 | bool usePaint; |
| 1495 | fuzz->next(&src, &dst, &usePaint); |
| 1496 | if (usePaint) { |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 1497 | fuzz_paint(fuzz, &paint, depth - 1); |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 1498 | } |
Hal Canary | b69c4b8 | 2017-03-08 11:02:40 -0500 | [diff] [blame] | 1499 | SkCanvas::SrcRectConstraint constraint = |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 1500 | make_fuzz_t<bool>(fuzz) ? SkCanvas::kStrict_SrcRectConstraint |
| 1501 | : SkCanvas::kFast_SrcRectConstraint; |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 1502 | canvas->drawBitmapRect(bitmap, src, dst, usePaint ? &paint : nullptr, constraint); |
| 1503 | break; |
| 1504 | } |
| 1505 | case 40: { |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 1506 | SkBitmap img = make_fuzz_bitmap(fuzz); |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 1507 | SkIRect src; |
| 1508 | SkRect dst; |
| 1509 | bool usePaint; |
| 1510 | fuzz->next(&src, &dst, &usePaint); |
| 1511 | if (usePaint) { |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 1512 | fuzz_paint(fuzz, &paint, depth - 1); |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 1513 | } |
Hal Canary | b69c4b8 | 2017-03-08 11:02:40 -0500 | [diff] [blame] | 1514 | SkCanvas::SrcRectConstraint constraint = |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 1515 | make_fuzz_t<bool>(fuzz) ? SkCanvas::kStrict_SrcRectConstraint |
| 1516 | : SkCanvas::kFast_SrcRectConstraint; |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 1517 | canvas->drawBitmapRect(img, src, dst, usePaint ? &paint : nullptr, constraint); |
| 1518 | break; |
| 1519 | } |
| 1520 | case 41: { |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 1521 | SkBitmap img = make_fuzz_bitmap(fuzz); |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 1522 | SkRect dst; |
| 1523 | bool usePaint; |
| 1524 | fuzz->next(&dst, &usePaint); |
| 1525 | if (usePaint) { |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 1526 | fuzz_paint(fuzz, &paint, depth - 1); |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 1527 | } |
Hal Canary | b69c4b8 | 2017-03-08 11:02:40 -0500 | [diff] [blame] | 1528 | SkCanvas::SrcRectConstraint constraint = |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 1529 | make_fuzz_t<bool>(fuzz) ? SkCanvas::kStrict_SrcRectConstraint |
| 1530 | : SkCanvas::kFast_SrcRectConstraint; |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 1531 | canvas->drawBitmapRect(img, dst, usePaint ? &paint : nullptr, constraint); |
| 1532 | break; |
| 1533 | } |
| 1534 | case 42: { |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 1535 | SkBitmap img = make_fuzz_bitmap(fuzz); |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 1536 | SkIRect center; |
| 1537 | SkRect dst; |
| 1538 | bool usePaint; |
Hal Canary | 0361d49 | 2017-03-15 12:58:15 -0400 | [diff] [blame] | 1539 | fuzz->next(&usePaint); |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 1540 | if (usePaint) { |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 1541 | fuzz_paint(fuzz, &paint, depth - 1); |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 1542 | } |
Hal Canary | 0361d49 | 2017-03-15 12:58:15 -0400 | [diff] [blame] | 1543 | if (make_fuzz_t<bool>(fuzz)) { |
| 1544 | fuzz->next(¢er); |
| 1545 | } else { // Make valid center, see SkLatticeIter::Valid(). |
| 1546 | fuzz->nextRange(¢er.fLeft, 0, img.width() - 1); |
| 1547 | fuzz->nextRange(¢er.fTop, 0, img.height() - 1); |
| 1548 | fuzz->nextRange(¢er.fRight, center.fLeft + 1, img.width()); |
| 1549 | fuzz->nextRange(¢er.fBottom, center.fTop + 1, img.height()); |
| 1550 | } |
| 1551 | fuzz->next(&dst); |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 1552 | canvas->drawBitmapNine(img, center, dst, usePaint ? &paint : nullptr); |
| 1553 | break; |
| 1554 | } |
| 1555 | case 43: { |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 1556 | SkBitmap img = make_fuzz_bitmap(fuzz); |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 1557 | bool usePaint; |
| 1558 | SkRect dst; |
| 1559 | fuzz->next(&usePaint, &dst); |
| 1560 | if (usePaint) { |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 1561 | fuzz_paint(fuzz, &paint, depth - 1); |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 1562 | } |
| 1563 | constexpr int kMax = 6; |
| 1564 | int xDivs[kMax], yDivs[kMax]; |
| 1565 | SkCanvas::Lattice lattice{xDivs, yDivs, nullptr, 0, 0, nullptr}; |
| 1566 | fuzz->nextRange(&lattice.fXCount, 2, kMax); |
| 1567 | fuzz->nextRange(&lattice.fYCount, 2, kMax); |
| 1568 | fuzz->nextN(xDivs, lattice.fXCount); |
| 1569 | fuzz->nextN(yDivs, lattice.fYCount); |
| 1570 | canvas->drawBitmapLattice(img, lattice, dst, usePaint ? &paint : nullptr); |
| 1571 | break; |
| 1572 | } |
| 1573 | case 44: { |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 1574 | auto img = make_fuzz_image(fuzz); |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 1575 | bool usePaint; |
| 1576 | SkRect dst; |
| 1577 | fuzz->next(&usePaint, &dst); |
| 1578 | if (usePaint) { |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 1579 | fuzz_paint(fuzz, &paint, depth - 1); |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 1580 | } |
| 1581 | constexpr int kMax = 6; |
| 1582 | int xDivs[kMax], yDivs[kMax]; |
| 1583 | SkCanvas::Lattice lattice{xDivs, yDivs, nullptr, 0, 0, nullptr}; |
| 1584 | fuzz->nextRange(&lattice.fXCount, 2, kMax); |
| 1585 | fuzz->nextRange(&lattice.fYCount, 2, kMax); |
| 1586 | fuzz->nextN(xDivs, lattice.fXCount); |
| 1587 | fuzz->nextN(yDivs, lattice.fYCount); |
| 1588 | canvas->drawImageLattice(img.get(), lattice, dst, usePaint ? &paint : nullptr); |
| 1589 | break; |
| 1590 | } |
| 1591 | case 45: { |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 1592 | fuzz_paint(fuzz, &paint, depth - 1); |
| 1593 | fuzz_paint_text(fuzz, &paint); |
Hal Canary | 5395c59 | 2017-03-08 16:52:18 -0500 | [diff] [blame] | 1594 | fuzz_paint_text_encoding(fuzz, &paint); |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 1595 | SkScalar x, y; |
| 1596 | fuzz->next(&x, &y); |
Hal Canary | 5395c59 | 2017-03-08 16:52:18 -0500 | [diff] [blame] | 1597 | SkTDArray<uint8_t> text = make_fuzz_text(fuzz, paint); |
Hal Canary | 671e442 | 2017-02-27 13:36:38 -0500 | [diff] [blame] | 1598 | canvas->drawText(text.begin(), SkToSizeT(text.count()), x, y, paint); |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 1599 | break; |
| 1600 | } |
| 1601 | case 46: { |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 1602 | fuzz_paint(fuzz, &paint, depth - 1); |
| 1603 | fuzz_paint_text(fuzz, &paint); |
Hal Canary | 5395c59 | 2017-03-08 16:52:18 -0500 | [diff] [blame] | 1604 | fuzz_paint_text_encoding(fuzz, &paint); |
| 1605 | SkTDArray<uint8_t> text = make_fuzz_text(fuzz, paint); |
Hal Canary | 671e442 | 2017-02-27 13:36:38 -0500 | [diff] [blame] | 1606 | int glyphCount = paint.countText(text.begin(), SkToSizeT(text.count())); |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 1607 | if (glyphCount < 1) { |
| 1608 | break; |
| 1609 | } |
| 1610 | SkAutoTMalloc<SkPoint> pos(glyphCount); |
| 1611 | SkAutoTMalloc<SkScalar> widths(glyphCount); |
Hal Canary | 671e442 | 2017-02-27 13:36:38 -0500 | [diff] [blame] | 1612 | paint.getTextWidths(text.begin(), SkToSizeT(text.count()), widths.get()); |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 1613 | pos[0] = {0, 0}; |
| 1614 | for (int i = 1; i < glyphCount; ++i) { |
| 1615 | float y; |
Hal Canary | b69c4b8 | 2017-03-08 11:02:40 -0500 | [diff] [blame] | 1616 | fuzz->nextRange(&y, -0.5f * paint.getTextSize(), 0.5f * paint.getTextSize()); |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 1617 | pos[i] = {pos[i - 1].x() + widths[i - 1], y}; |
| 1618 | } |
Hal Canary | 671e442 | 2017-02-27 13:36:38 -0500 | [diff] [blame] | 1619 | canvas->drawPosText(text.begin(), SkToSizeT(text.count()), pos.get(), paint); |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 1620 | break; |
| 1621 | } |
| 1622 | case 47: { |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 1623 | fuzz_paint(fuzz, &paint, depth - 1); |
| 1624 | fuzz_paint_text(fuzz, &paint); |
Hal Canary | 5395c59 | 2017-03-08 16:52:18 -0500 | [diff] [blame] | 1625 | fuzz_paint_text_encoding(fuzz, &paint); |
| 1626 | SkTDArray<uint8_t> text = make_fuzz_text(fuzz, paint); |
Hal Canary | 671e442 | 2017-02-27 13:36:38 -0500 | [diff] [blame] | 1627 | int glyphCount = paint.countText(text.begin(), SkToSizeT(text.count())); |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 1628 | SkAutoTMalloc<SkScalar> widths(glyphCount); |
| 1629 | if (glyphCount < 1) { |
| 1630 | break; |
| 1631 | } |
Hal Canary | 671e442 | 2017-02-27 13:36:38 -0500 | [diff] [blame] | 1632 | paint.getTextWidths(text.begin(), SkToSizeT(text.count()), widths.get()); |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 1633 | SkScalar x = widths[0]; |
| 1634 | for (int i = 0; i < glyphCount; ++i) { |
| 1635 | SkTSwap(x, widths[i]); |
| 1636 | x += widths[i]; |
| 1637 | SkScalar offset; |
| 1638 | fuzz->nextRange(&offset, -0.125f * paint.getTextSize(), |
Hal Canary | b69c4b8 | 2017-03-08 11:02:40 -0500 | [diff] [blame] | 1639 | 0.125f * paint.getTextSize()); |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 1640 | widths[i] += offset; |
| 1641 | } |
| 1642 | SkScalar y; |
| 1643 | fuzz->next(&y); |
Hal Canary | b69c4b8 | 2017-03-08 11:02:40 -0500 | [diff] [blame] | 1644 | canvas->drawPosTextH(text.begin(), SkToSizeT(text.count()), widths.get(), y, paint); |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 1645 | break; |
| 1646 | } |
| 1647 | case 48: { |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 1648 | fuzz_paint(fuzz, &paint, depth - 1); |
| 1649 | fuzz_paint_text(fuzz, &paint); |
Hal Canary | 5395c59 | 2017-03-08 16:52:18 -0500 | [diff] [blame] | 1650 | fuzz_paint_text_encoding(fuzz, &paint); |
| 1651 | SkTDArray<uint8_t> text = make_fuzz_text(fuzz, paint); |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 1652 | SkPath path; |
Hal Canary | ce540ea | 2017-03-06 08:30:44 -0500 | [diff] [blame] | 1653 | fuzz_path(fuzz, &path, 20); |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 1654 | SkScalar hOffset, vOffset; |
| 1655 | fuzz->next(&hOffset, &vOffset); |
Hal Canary | b69c4b8 | 2017-03-08 11:02:40 -0500 | [diff] [blame] | 1656 | canvas->drawTextOnPathHV(text.begin(), SkToSizeT(text.count()), path, hOffset, |
| 1657 | vOffset, paint); |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 1658 | break; |
| 1659 | } |
| 1660 | case 49: { |
| 1661 | SkMatrix matrix; |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 1662 | bool useMatrix = make_fuzz_t<bool>(fuzz); |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 1663 | if (useMatrix) { |
| 1664 | fuzz->next(&matrix); |
| 1665 | } |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 1666 | fuzz_paint(fuzz, &paint, depth - 1); |
| 1667 | fuzz_paint_text(fuzz, &paint); |
Hal Canary | 5395c59 | 2017-03-08 16:52:18 -0500 | [diff] [blame] | 1668 | fuzz_paint_text_encoding(fuzz, &paint); |
| 1669 | SkTDArray<uint8_t> text = make_fuzz_text(fuzz, paint); |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 1670 | SkPath path; |
Hal Canary | ce540ea | 2017-03-06 08:30:44 -0500 | [diff] [blame] | 1671 | fuzz_path(fuzz, &path, 20); |
Hal Canary | 671e442 | 2017-02-27 13:36:38 -0500 | [diff] [blame] | 1672 | canvas->drawTextOnPath(text.begin(), SkToSizeT(text.count()), path, |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 1673 | useMatrix ? &matrix : nullptr, paint); |
| 1674 | break; |
| 1675 | } |
| 1676 | case 50: { |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 1677 | fuzz_paint(fuzz, &paint, depth - 1); |
| 1678 | fuzz_paint_text(fuzz, &paint); |
Hal Canary | 5395c59 | 2017-03-08 16:52:18 -0500 | [diff] [blame] | 1679 | fuzz_paint_text_encoding(fuzz, &paint); |
| 1680 | SkTDArray<uint8_t> text = make_fuzz_text(fuzz, paint); |
| 1681 | SkRSXform rSXform[kMaxGlyphCount]; |
| 1682 | int glyphCount = paint.countText(text.begin(), SkToSizeT(text.count())); |
| 1683 | SkASSERT(glyphCount <= kMaxGlyphCount); |
| 1684 | fuzz->nextN(rSXform, glyphCount); |
| 1685 | SkRect cullRect; |
| 1686 | bool useCullRect; |
| 1687 | fuzz->next(&useCullRect); |
| 1688 | if (useCullRect) { |
| 1689 | fuzz->next(&cullRect); |
| 1690 | } |
| 1691 | canvas->drawTextRSXform(text.begin(), SkToSizeT(text.count()), rSXform, |
| 1692 | useCullRect ? &cullRect : nullptr, paint); |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 1693 | break; |
| 1694 | } |
| 1695 | case 51: { |
Hal Canary | 5395c59 | 2017-03-08 16:52:18 -0500 | [diff] [blame] | 1696 | sk_sp<SkTextBlob> blob = make_fuzz_textblob(fuzz); |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 1697 | fuzz_paint(fuzz, &paint, depth - 1); |
Hal Canary | 5395c59 | 2017-03-08 16:52:18 -0500 | [diff] [blame] | 1698 | SkScalar x, y; |
| 1699 | fuzz->next(&x, &y); |
| 1700 | canvas->drawTextBlob(blob, x, y, paint); |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 1701 | break; |
| 1702 | } |
| 1703 | case 52: { |
| 1704 | bool usePaint, useMatrix; |
| 1705 | fuzz->next(&usePaint, &useMatrix); |
| 1706 | if (usePaint) { |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 1707 | fuzz_paint(fuzz, &paint, depth - 1); |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 1708 | } |
| 1709 | if (useMatrix) { |
| 1710 | fuzz->next(&matrix); |
| 1711 | } |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 1712 | auto pic = make_fuzz_picture(fuzz, depth - 1); |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 1713 | canvas->drawPicture(pic, useMatrix ? &matrix : nullptr, |
| 1714 | usePaint ? &paint : nullptr); |
| 1715 | break; |
| 1716 | } |
| 1717 | case 53: { |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 1718 | fuzz_paint(fuzz, &paint, depth - 1); |
Mike Reed | 887cdf1 | 2017-04-03 11:11:09 -0400 | [diff] [blame] | 1719 | SkVertices::VertexMode vertexMode; |
Hal Canary | 5af600e | 2017-03-09 14:10:36 -0500 | [diff] [blame] | 1720 | SkBlendMode blendMode; |
Mike Reed | 887cdf1 | 2017-04-03 11:11:09 -0400 | [diff] [blame] | 1721 | fuzz_enum_range(fuzz, &vertexMode, 0, SkVertices::kTriangleFan_VertexMode); |
Hal Canary | 5af600e | 2017-03-09 14:10:36 -0500 | [diff] [blame] | 1722 | fuzz->next(&blendMode); |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 1723 | constexpr int kMaxCount = 100; |
| 1724 | int vertexCount; |
| 1725 | SkPoint vertices[kMaxCount]; |
| 1726 | SkPoint texs[kMaxCount]; |
| 1727 | SkColor colors[kMaxCount]; |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 1728 | fuzz->nextRange(&vertexCount, 3, kMaxCount); |
| 1729 | fuzz->nextN(vertices, vertexCount); |
| 1730 | bool useTexs, useColors; |
| 1731 | fuzz->next(&useTexs, &useColors); |
| 1732 | if (useTexs) { |
| 1733 | fuzz->nextN(texs, vertexCount); |
| 1734 | } |
| 1735 | if (useColors) { |
| 1736 | fuzz->nextN(colors, vertexCount); |
| 1737 | } |
| 1738 | int indexCount = 0; |
Hal Canary | 68b9b57 | 2017-03-02 15:27:23 -0500 | [diff] [blame] | 1739 | uint16_t indices[kMaxCount * 2]; |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 1740 | if (make_fuzz_t<bool>(fuzz)) { |
Hal Canary | 68b9b57 | 2017-03-02 15:27:23 -0500 | [diff] [blame] | 1741 | fuzz->nextRange(&indexCount, vertexCount, vertexCount + kMaxCount); |
| 1742 | for (int i = 0; i < indexCount; ++i) { |
| 1743 | fuzz->nextRange(&indices[i], 0, vertexCount - 1); |
| 1744 | } |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 1745 | } |
Mike Reed | 887cdf1 | 2017-04-03 11:11:09 -0400 | [diff] [blame] | 1746 | canvas->drawVertices(SkVertices::MakeCopy(vertexMode, vertexCount, vertices, |
| 1747 | useTexs ? texs : nullptr, |
| 1748 | useColors ? colors : nullptr, |
| 1749 | indexCount, indices), |
| 1750 | blendMode, paint); |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 1751 | break; |
| 1752 | } |
| 1753 | default: |
| 1754 | break; |
| 1755 | } |
| 1756 | } |
| 1757 | } |
| 1758 | |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 1759 | static sk_sp<SkPicture> make_fuzz_picture(Fuzz* fuzz, int depth) { |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 1760 | SkScalar w, h; |
| 1761 | fuzz->next(&w, &h); |
| 1762 | SkPictureRecorder pictureRecorder; |
| 1763 | fuzz_canvas(fuzz, pictureRecorder.beginRecording(w, h), depth - 1); |
| 1764 | return pictureRecorder.finishRecordingAsPicture(); |
| 1765 | } |
| 1766 | |
Kevin Lubick | 1ac8fd2 | 2017-03-01 10:42:45 -0500 | [diff] [blame] | 1767 | DEF_FUZZ(NullCanvas, fuzz) { |
| 1768 | fuzz_canvas(fuzz, SkMakeNullCanvas().get()); |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 1769 | } |
| 1770 | |
Hal Canary | 44801ca | 2017-03-15 11:39:06 -0400 | [diff] [blame] | 1771 | // 8.5x11 letter paper at 72ppi. |
| 1772 | constexpr SkISize kCanvasSize = {612, 792}; |
| 1773 | |
Kevin Lubick | 1ac8fd2 | 2017-03-01 10:42:45 -0500 | [diff] [blame] | 1774 | DEF_FUZZ(RasterN32Canvas, fuzz) { |
Hal Canary | 44801ca | 2017-03-15 11:39:06 -0400 | [diff] [blame] | 1775 | auto surface = SkSurface::MakeRasterN32Premul(kCanvasSize.width(), kCanvasSize.height()); |
Kevin Lubick | 1ac8fd2 | 2017-03-01 10:42:45 -0500 | [diff] [blame] | 1776 | SkASSERT(surface && surface->getCanvas()); |
| 1777 | fuzz_canvas(fuzz, surface->getCanvas()); |
| 1778 | } |
| 1779 | |
Hal Canary | 44801ca | 2017-03-15 11:39:06 -0400 | [diff] [blame] | 1780 | #if SK_SUPPORT_GPU |
Hal Canary | 5aa9158 | 2017-03-21 11:11:44 -0700 | [diff] [blame] | 1781 | static void fuzz_ganesh(Fuzz* fuzz, GrContext* context) { |
| 1782 | SkASSERT(context); |
| 1783 | auto surface = SkSurface::MakeRenderTarget( |
| 1784 | context, |
| 1785 | SkBudgeted::kNo, |
| 1786 | SkImageInfo::Make(kCanvasSize.width(), kCanvasSize.height(), kRGBA_8888_SkColorType, kPremul_SkAlphaType)); |
| 1787 | SkASSERT(surface && surface->getCanvas()); |
| 1788 | fuzz_canvas(fuzz, surface->getCanvas()); |
| 1789 | } |
| 1790 | |
Hal Canary | 44801ca | 2017-03-15 11:39:06 -0400 | [diff] [blame] | 1791 | DEF_FUZZ(NativeGLCanvas, fuzz) { |
Brian Salomon | 6405e71 | 2017-03-20 08:54:16 -0400 | [diff] [blame] | 1792 | GrContext* context = sk_gpu_test::GrContextFactory().get( |
| 1793 | sk_gpu_test::GrContextFactory::kGL_ContextType); |
| 1794 | if (!context) { |
| 1795 | context = sk_gpu_test::GrContextFactory().get( |
| 1796 | sk_gpu_test::GrContextFactory::kGLES_ContextType); |
| 1797 | } |
Hal Canary | 5aa9158 | 2017-03-21 11:11:44 -0700 | [diff] [blame] | 1798 | fuzz_ganesh(fuzz, context); |
| 1799 | } |
| 1800 | |
| 1801 | DEF_FUZZ(NullGLCanvas, fuzz) { |
| 1802 | fuzz_ganesh(fuzz, sk_gpu_test::GrContextFactory().get( |
| 1803 | sk_gpu_test::GrContextFactory::kNullGL_ContextType)); |
| 1804 | } |
| 1805 | |
| 1806 | DEF_FUZZ(DebugGLCanvas, fuzz) { |
| 1807 | fuzz_ganesh(fuzz, sk_gpu_test::GrContextFactory().get( |
| 1808 | sk_gpu_test::GrContextFactory::kDebugGL_ContextType)); |
Hal Canary | 44801ca | 2017-03-15 11:39:06 -0400 | [diff] [blame] | 1809 | } |
| 1810 | #endif |
| 1811 | |
Kevin Lubick | 1ac8fd2 | 2017-03-01 10:42:45 -0500 | [diff] [blame] | 1812 | DEF_FUZZ(PDFCanvas, fuzz) { |
| 1813 | struct final : public SkWStream { |
| 1814 | bool write(const void*, size_t n) override { fN += n; return true; } |
| 1815 | size_t bytesWritten() const override { return fN; } |
| 1816 | size_t fN = 0; |
| 1817 | } stream; |
| 1818 | auto doc = SkDocument::MakePDF(&stream); |
Hal Canary | 44801ca | 2017-03-15 11:39:06 -0400 | [diff] [blame] | 1819 | fuzz_canvas(fuzz, doc->beginPage(SkIntToScalar(kCanvasSize.width()), |
| 1820 | SkIntToScalar(kCanvasSize.height()))); |
Kevin Lubick | 1ac8fd2 | 2017-03-01 10:42:45 -0500 | [diff] [blame] | 1821 | } |
| 1822 | |
| 1823 | // not a "real" thing to fuzz, used to debug errors found while fuzzing. |
| 1824 | DEF_FUZZ(_DumpCanvas, fuzz) { |
Hal Canary | 44801ca | 2017-03-15 11:39:06 -0400 | [diff] [blame] | 1825 | SkDebugCanvas debugCanvas(kCanvasSize.width(), kCanvasSize.height()); |
Kevin Lubick | 1ac8fd2 | 2017-03-01 10:42:45 -0500 | [diff] [blame] | 1826 | fuzz_canvas(fuzz, &debugCanvas); |
| 1827 | std::unique_ptr<SkCanvas> nullCanvas = SkMakeNullCanvas(); |
| 1828 | UrlDataManager dataManager(SkString("data")); |
| 1829 | Json::Value json = debugCanvas.toJSON(dataManager, debugCanvas.getSize(), nullCanvas.get()); |
| 1830 | Json::StyledStreamWriter(" ").write(std::cout, json); |
| 1831 | } |