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