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