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