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