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