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