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