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