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 | ea60b95 | 2018-08-21 11:45:46 -0400 | [diff] [blame] | 67 | #include "SkUTF.h" |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 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); |
Kevin Lubick | 1b1a557 | 2018-06-04 17:02:46 -0400 | [diff] [blame] | 510 | bool respectCTM; |
| 511 | fuzz->next(&respectCTM); |
Kevin Lubick | 1b1a557 | 2018-06-04 17:02:46 -0400 | [diff] [blame] | 512 | return SkMaskFilter::MakeBlur(blurStyle, sigma, respectCTM); |
Hal Canary | 5395c59 | 2017-03-08 16:52:18 -0500 | [diff] [blame] | 513 | } |
Hal Canary | 5395c59 | 2017-03-08 16:52:18 -0500 | [diff] [blame] | 514 | default: |
| 515 | SkASSERT(false); |
| 516 | return nullptr; |
| 517 | } |
| 518 | } |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 519 | |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 520 | static sk_sp<SkTypeface> make_fuzz_typeface(Fuzz* fuzz) { |
| 521 | if (make_fuzz_t<bool>(fuzz)) { |
Hal Canary | 671e442 | 2017-02-27 13:36:38 -0500 | [diff] [blame] | 522 | return nullptr; |
| 523 | } |
| 524 | auto fontMugger = SkFontMgr::RefDefault(); |
| 525 | SkASSERT(fontMugger); |
| 526 | int familyCount = fontMugger->countFamilies(); |
| 527 | int i, j; |
| 528 | fuzz->nextRange(&i, 0, familyCount - 1); |
| 529 | sk_sp<SkFontStyleSet> family(fontMugger->createStyleSet(i)); |
| 530 | int styleCount = family->count(); |
| 531 | fuzz->nextRange(&j, 0, styleCount - 1); |
| 532 | return sk_sp<SkTypeface>(family->createTypeface(j)); |
| 533 | } |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 534 | |
Hal Canary | e03c3e5 | 2017-03-09 11:33:35 -0500 | [diff] [blame] | 535 | template <> |
| 536 | inline void Fuzz::next(SkImageFilter::CropRect* cropRect) { |
| 537 | SkRect rect; |
| 538 | uint8_t flags; |
| 539 | this->next(&rect); |
| 540 | this->nextRange(&flags, 0, 0xF); |
| 541 | *cropRect = SkImageFilter::CropRect(rect, flags); |
| 542 | } |
| 543 | |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 544 | static sk_sp<SkImageFilter> make_fuzz_imageFilter(Fuzz* fuzz, int depth); |
Hal Canary | e03c3e5 | 2017-03-09 11:33:35 -0500 | [diff] [blame] | 545 | |
| 546 | static sk_sp<SkImageFilter> make_fuzz_lighting_imagefilter(Fuzz* fuzz, int depth) { |
| 547 | if (depth <= 0) { |
| 548 | return nullptr; |
| 549 | } |
| 550 | uint8_t imageFilterType; |
| 551 | fuzz->nextRange(&imageFilterType, 1, 6); |
| 552 | SkPoint3 p, q; |
| 553 | SkColor lightColor; |
| 554 | SkScalar surfaceScale, k, specularExponent, cutoffAngle, shininess; |
| 555 | sk_sp<SkImageFilter> input; |
| 556 | SkImageFilter::CropRect cropRect; |
| 557 | bool useCropRect; |
| 558 | fuzz->next(&useCropRect); |
| 559 | if (useCropRect) { |
| 560 | fuzz->next(&cropRect); |
| 561 | } |
| 562 | switch (imageFilterType) { |
| 563 | case 1: |
| 564 | fuzz->next(&p, &lightColor, &surfaceScale, &k); |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 565 | input = make_fuzz_imageFilter(fuzz, depth - 1); |
Hal Canary | e03c3e5 | 2017-03-09 11:33:35 -0500 | [diff] [blame] | 566 | return SkLightingImageFilter::MakeDistantLitDiffuse(p, lightColor, surfaceScale, k, |
| 567 | std::move(input), |
| 568 | useCropRect ? &cropRect : nullptr); |
| 569 | case 2: |
| 570 | fuzz->next(&p, &lightColor, &surfaceScale, &k); |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 571 | input = make_fuzz_imageFilter(fuzz, depth - 1); |
Hal Canary | e03c3e5 | 2017-03-09 11:33:35 -0500 | [diff] [blame] | 572 | return SkLightingImageFilter::MakePointLitDiffuse(p, lightColor, surfaceScale, k, |
| 573 | std::move(input), |
| 574 | useCropRect ? &cropRect : nullptr); |
| 575 | case 3: |
| 576 | fuzz->next(&p, &q, &specularExponent, &cutoffAngle, &lightColor, &surfaceScale, &k); |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 577 | input = make_fuzz_imageFilter(fuzz, depth - 1); |
Hal Canary | e03c3e5 | 2017-03-09 11:33:35 -0500 | [diff] [blame] | 578 | return SkLightingImageFilter::MakeSpotLitDiffuse( |
| 579 | p, q, specularExponent, cutoffAngle, lightColor, surfaceScale, k, |
| 580 | std::move(input), useCropRect ? &cropRect : nullptr); |
| 581 | case 4: |
| 582 | fuzz->next(&p, &lightColor, &surfaceScale, &k, &shininess); |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 583 | input = make_fuzz_imageFilter(fuzz, depth - 1); |
Hal Canary | e03c3e5 | 2017-03-09 11:33:35 -0500 | [diff] [blame] | 584 | return SkLightingImageFilter::MakeDistantLitSpecular(p, lightColor, surfaceScale, k, |
| 585 | shininess, std::move(input), |
| 586 | useCropRect ? &cropRect : nullptr); |
| 587 | case 5: |
| 588 | fuzz->next(&p, &lightColor, &surfaceScale, &k, &shininess); |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 589 | input = make_fuzz_imageFilter(fuzz, depth - 1); |
Hal Canary | e03c3e5 | 2017-03-09 11:33:35 -0500 | [diff] [blame] | 590 | return SkLightingImageFilter::MakePointLitSpecular(p, lightColor, surfaceScale, k, |
| 591 | shininess, std::move(input), |
| 592 | useCropRect ? &cropRect : nullptr); |
| 593 | case 6: |
| 594 | fuzz->next(&p, &q, &specularExponent, &cutoffAngle, &lightColor, &surfaceScale, &k, |
| 595 | &shininess); |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 596 | input = make_fuzz_imageFilter(fuzz, depth - 1); |
Hal Canary | e03c3e5 | 2017-03-09 11:33:35 -0500 | [diff] [blame] | 597 | return SkLightingImageFilter::MakeSpotLitSpecular( |
| 598 | p, q, specularExponent, cutoffAngle, lightColor, surfaceScale, k, shininess, |
| 599 | std::move(input), useCropRect ? &cropRect : nullptr); |
| 600 | default: |
| 601 | SkASSERT(false); |
| 602 | return nullptr; |
| 603 | } |
| 604 | } |
| 605 | |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 606 | static void fuzz_paint(Fuzz* fuzz, SkPaint* paint, int depth); |
Hal Canary | e03c3e5 | 2017-03-09 11:33:35 -0500 | [diff] [blame] | 607 | |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 608 | static sk_sp<SkImageFilter> make_fuzz_imageFilter(Fuzz* fuzz, int depth) { |
Hal Canary | e03c3e5 | 2017-03-09 11:33:35 -0500 | [diff] [blame] | 609 | if (depth <= 0) { |
| 610 | return nullptr; |
| 611 | } |
| 612 | uint8_t imageFilterType; |
Kevin Lubick | 54f20e0 | 2018-01-11 14:50:21 -0500 | [diff] [blame] | 613 | fuzz->nextRange(&imageFilterType, 0, 23); |
Hal Canary | e03c3e5 | 2017-03-09 11:33:35 -0500 | [diff] [blame] | 614 | switch (imageFilterType) { |
| 615 | case 0: |
| 616 | return nullptr; |
| 617 | case 1: { |
| 618 | SkScalar sigmaX, sigmaY; |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 619 | sk_sp<SkImageFilter> input = make_fuzz_imageFilter(fuzz, depth - 1); |
Hal Canary | e03c3e5 | 2017-03-09 11:33:35 -0500 | [diff] [blame] | 620 | bool useCropRect; |
| 621 | fuzz->next(&sigmaX, &sigmaY, &useCropRect); |
Kevin Lubick | dad29a0 | 2017-03-14 17:20:24 -0400 | [diff] [blame] | 622 | SkImageFilter::CropRect cropRect; |
Hal Canary | e03c3e5 | 2017-03-09 11:33:35 -0500 | [diff] [blame] | 623 | if (useCropRect) { |
Kevin Lubick | dad29a0 | 2017-03-14 17:20:24 -0400 | [diff] [blame] | 624 | fuzz->next(&cropRect); |
Hal Canary | e03c3e5 | 2017-03-09 11:33:35 -0500 | [diff] [blame] | 625 | } |
Robert Phillips | 70e3e9a | 2017-06-26 14:22:01 -0400 | [diff] [blame] | 626 | return SkBlurImageFilter::Make(sigmaX, sigmaY, std::move(input), |
Hal Canary | e03c3e5 | 2017-03-09 11:33:35 -0500 | [diff] [blame] | 627 | useCropRect ? &cropRect : nullptr); |
| 628 | } |
| 629 | case 2: { |
| 630 | SkMatrix matrix; |
| 631 | SkFilterQuality quality; |
| 632 | fuzz->next(&matrix, &quality); |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 633 | sk_sp<SkImageFilter> input = make_fuzz_imageFilter(fuzz, depth - 1); |
Hal Canary | e03c3e5 | 2017-03-09 11:33:35 -0500 | [diff] [blame] | 634 | return SkImageFilter::MakeMatrixFilter(matrix, quality, std::move(input)); |
| 635 | } |
| 636 | case 3: { |
| 637 | SkRegion region; |
| 638 | SkScalar innerMin, outerMax; |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 639 | sk_sp<SkImageFilter> input = make_fuzz_imageFilter(fuzz, depth - 1); |
Hal Canary | e03c3e5 | 2017-03-09 11:33:35 -0500 | [diff] [blame] | 640 | bool useCropRect; |
| 641 | fuzz->next(®ion, &innerMin, &outerMax, &useCropRect); |
Kevin Lubick | dad29a0 | 2017-03-14 17:20:24 -0400 | [diff] [blame] | 642 | SkImageFilter::CropRect cropRect; |
Hal Canary | e03c3e5 | 2017-03-09 11:33:35 -0500 | [diff] [blame] | 643 | if (useCropRect) { |
Kevin Lubick | dad29a0 | 2017-03-14 17:20:24 -0400 | [diff] [blame] | 644 | fuzz->next(&cropRect); |
Hal Canary | e03c3e5 | 2017-03-09 11:33:35 -0500 | [diff] [blame] | 645 | } |
| 646 | return SkAlphaThresholdFilter::Make(region, innerMin, outerMax, std::move(input), |
| 647 | useCropRect ? &cropRect : nullptr); |
| 648 | } |
| 649 | case 4: { |
| 650 | float k1, k2, k3, k4; |
| 651 | bool enforcePMColor; |
| 652 | bool useCropRect; |
| 653 | fuzz->next(&k1, &k2, &k3, &k4, &enforcePMColor, &useCropRect); |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 654 | sk_sp<SkImageFilter> background = make_fuzz_imageFilter(fuzz, depth - 1); |
| 655 | sk_sp<SkImageFilter> foreground = make_fuzz_imageFilter(fuzz, depth - 1); |
Hal Canary | e03c3e5 | 2017-03-09 11:33:35 -0500 | [diff] [blame] | 656 | SkImageFilter::CropRect cropRect; |
| 657 | if (useCropRect) { |
Kevin Lubick | dad29a0 | 2017-03-14 17:20:24 -0400 | [diff] [blame] | 658 | fuzz->next(&cropRect); |
Hal Canary | e03c3e5 | 2017-03-09 11:33:35 -0500 | [diff] [blame] | 659 | } |
| 660 | return SkArithmeticImageFilter::Make(k1, k2, k3, k4, enforcePMColor, |
| 661 | std::move(background), std::move(foreground), |
| 662 | useCropRect ? &cropRect : nullptr); |
| 663 | } |
| 664 | case 5: { |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 665 | sk_sp<SkColorFilter> cf = make_fuzz_colorfilter(fuzz, depth - 1); |
| 666 | sk_sp<SkImageFilter> input = make_fuzz_imageFilter(fuzz, depth - 1); |
Hal Canary | e03c3e5 | 2017-03-09 11:33:35 -0500 | [diff] [blame] | 667 | bool useCropRect; |
| 668 | SkImageFilter::CropRect cropRect; |
| 669 | fuzz->next(&useCropRect); |
| 670 | if (useCropRect) { |
Kevin Lubick | dad29a0 | 2017-03-14 17:20:24 -0400 | [diff] [blame] | 671 | fuzz->next(&cropRect); |
Hal Canary | e03c3e5 | 2017-03-09 11:33:35 -0500 | [diff] [blame] | 672 | } |
| 673 | return SkColorFilterImageFilter::Make(std::move(cf), std::move(input), |
| 674 | useCropRect ? &cropRect : nullptr); |
| 675 | } |
| 676 | case 6: { |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 677 | sk_sp<SkImageFilter> ifo = make_fuzz_imageFilter(fuzz, depth - 1); |
| 678 | sk_sp<SkImageFilter> ifi = make_fuzz_imageFilter(fuzz, depth - 1); |
Hal Canary | e03c3e5 | 2017-03-09 11:33:35 -0500 | [diff] [blame] | 679 | return SkComposeImageFilter::Make(std::move(ifo), std::move(ifi)); |
| 680 | } |
| 681 | case 7: { |
| 682 | SkDisplacementMapEffect::ChannelSelectorType xChannelSelector, yChannelSelector; |
Hal Canary | f49b1e0 | 2017-03-15 16:58:33 -0400 | [diff] [blame] | 683 | fuzz_enum_range(fuzz, &xChannelSelector, 1, 4); |
| 684 | fuzz_enum_range(fuzz, &yChannelSelector, 1, 4); |
Hal Canary | e03c3e5 | 2017-03-09 11:33:35 -0500 | [diff] [blame] | 685 | SkScalar scale; |
| 686 | bool useCropRect; |
| 687 | fuzz->next(&scale, &useCropRect); |
| 688 | SkImageFilter::CropRect cropRect; |
| 689 | if (useCropRect) { |
Kevin Lubick | dad29a0 | 2017-03-14 17:20:24 -0400 | [diff] [blame] | 690 | fuzz->next(&cropRect); |
Hal Canary | e03c3e5 | 2017-03-09 11:33:35 -0500 | [diff] [blame] | 691 | } |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 692 | sk_sp<SkImageFilter> displacement = make_fuzz_imageFilter(fuzz, depth - 1); |
| 693 | sk_sp<SkImageFilter> color = make_fuzz_imageFilter(fuzz, depth - 1); |
Hal Canary | e03c3e5 | 2017-03-09 11:33:35 -0500 | [diff] [blame] | 694 | return SkDisplacementMapEffect::Make(xChannelSelector, yChannelSelector, scale, |
| 695 | std::move(displacement), std::move(color), |
| 696 | useCropRect ? &cropRect : nullptr); |
| 697 | } |
| 698 | case 8: { |
| 699 | SkScalar dx, dy, sigmaX, sigmaY; |
| 700 | SkColor color; |
| 701 | SkDropShadowImageFilter::ShadowMode shadowMode; |
Hal Canary | f700520 | 2017-03-10 08:48:28 -0500 | [diff] [blame] | 702 | fuzz_enum_range(fuzz, &shadowMode, 0, 1); |
Hal Canary | e03c3e5 | 2017-03-09 11:33:35 -0500 | [diff] [blame] | 703 | bool useCropRect; |
| 704 | fuzz->next(&dx, &dy, &sigmaX, &sigmaY, &color, &useCropRect); |
| 705 | SkImageFilter::CropRect cropRect; |
| 706 | if (useCropRect) { |
Kevin Lubick | dad29a0 | 2017-03-14 17:20:24 -0400 | [diff] [blame] | 707 | fuzz->next(&cropRect); |
Hal Canary | e03c3e5 | 2017-03-09 11:33:35 -0500 | [diff] [blame] | 708 | } |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 709 | sk_sp<SkImageFilter> input = make_fuzz_imageFilter(fuzz, depth - 1); |
Hal Canary | e03c3e5 | 2017-03-09 11:33:35 -0500 | [diff] [blame] | 710 | return SkDropShadowImageFilter::Make(dx, dy, sigmaX, sigmaY, color, shadowMode, |
| 711 | std::move(input), |
| 712 | useCropRect ? &cropRect : nullptr); |
| 713 | } |
| 714 | case 9: |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 715 | return SkImageSource::Make(make_fuzz_image(fuzz)); |
Hal Canary | e03c3e5 | 2017-03-09 11:33:35 -0500 | [diff] [blame] | 716 | case 10: { |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 717 | sk_sp<SkImage> image = make_fuzz_image(fuzz); |
Hal Canary | e03c3e5 | 2017-03-09 11:33:35 -0500 | [diff] [blame] | 718 | SkRect srcRect, dstRect; |
| 719 | SkFilterQuality filterQuality; |
| 720 | fuzz->next(&srcRect, &dstRect, &filterQuality); |
| 721 | return SkImageSource::Make(std::move(image), srcRect, dstRect, filterQuality); |
| 722 | } |
| 723 | case 11: |
| 724 | return make_fuzz_lighting_imagefilter(fuzz, depth - 1); |
| 725 | case 12: { |
| 726 | SkRect srcRect; |
| 727 | SkScalar inset; |
| 728 | bool useCropRect; |
| 729 | SkImageFilter::CropRect cropRect; |
| 730 | fuzz->next(&srcRect, &inset, &useCropRect); |
| 731 | if (useCropRect) { |
Kevin Lubick | dad29a0 | 2017-03-14 17:20:24 -0400 | [diff] [blame] | 732 | fuzz->next(&cropRect); |
Hal Canary | e03c3e5 | 2017-03-09 11:33:35 -0500 | [diff] [blame] | 733 | } |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 734 | sk_sp<SkImageFilter> input = make_fuzz_imageFilter(fuzz, depth - 1); |
Hal Canary | e03c3e5 | 2017-03-09 11:33:35 -0500 | [diff] [blame] | 735 | return SkMagnifierImageFilter::Make(srcRect, inset, std::move(input), |
| 736 | useCropRect ? &cropRect : nullptr); |
| 737 | } |
| 738 | case 13: { |
| 739 | constexpr int kMaxKernelSize = 5; |
| 740 | int32_t n, m; |
| 741 | fuzz->nextRange(&n, 1, kMaxKernelSize); |
| 742 | fuzz->nextRange(&m, 1, kMaxKernelSize); |
| 743 | SkScalar kernel[kMaxKernelSize * kMaxKernelSize]; |
| 744 | fuzz->nextN(kernel, n * m); |
| 745 | int32_t offsetX, offsetY; |
| 746 | fuzz->nextRange(&offsetX, 0, n - 1); |
| 747 | fuzz->nextRange(&offsetY, 0, m - 1); |
| 748 | SkScalar gain, bias; |
| 749 | bool convolveAlpha, useCropRect; |
| 750 | fuzz->next(&gain, &bias, &convolveAlpha, &useCropRect); |
| 751 | SkMatrixConvolutionImageFilter::TileMode tileMode; |
Hal Canary | f700520 | 2017-03-10 08:48:28 -0500 | [diff] [blame] | 752 | fuzz_enum_range(fuzz, &tileMode, 0, 2); |
Hal Canary | e03c3e5 | 2017-03-09 11:33:35 -0500 | [diff] [blame] | 753 | SkImageFilter::CropRect cropRect; |
| 754 | if (useCropRect) { |
Kevin Lubick | dad29a0 | 2017-03-14 17:20:24 -0400 | [diff] [blame] | 755 | fuzz->next(&cropRect); |
Hal Canary | e03c3e5 | 2017-03-09 11:33:35 -0500 | [diff] [blame] | 756 | } |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 757 | sk_sp<SkImageFilter> input = make_fuzz_imageFilter(fuzz, depth - 1); |
Hal Canary | e03c3e5 | 2017-03-09 11:33:35 -0500 | [diff] [blame] | 758 | return SkMatrixConvolutionImageFilter::Make( |
| 759 | SkISize{n, m}, kernel, gain, bias, SkIPoint{offsetX, offsetY}, tileMode, |
| 760 | convolveAlpha, std::move(input), useCropRect ? &cropRect : nullptr); |
| 761 | } |
| 762 | case 14: { |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 763 | sk_sp<SkImageFilter> first = make_fuzz_imageFilter(fuzz, depth - 1); |
| 764 | sk_sp<SkImageFilter> second = make_fuzz_imageFilter(fuzz, depth - 1); |
Hal Canary | e03c3e5 | 2017-03-09 11:33:35 -0500 | [diff] [blame] | 765 | bool useCropRect; |
| 766 | fuzz->next(&useCropRect); |
| 767 | SkImageFilter::CropRect cropRect; |
| 768 | if (useCropRect) { |
Kevin Lubick | dad29a0 | 2017-03-14 17:20:24 -0400 | [diff] [blame] | 769 | fuzz->next(&cropRect); |
Hal Canary | e03c3e5 | 2017-03-09 11:33:35 -0500 | [diff] [blame] | 770 | } |
Mike Reed | 0bdaf05 | 2017-06-18 23:35:57 -0400 | [diff] [blame] | 771 | return SkMergeImageFilter::Make(std::move(first), std::move(second), |
| 772 | useCropRect ? &cropRect : nullptr); |
| 773 | } |
| 774 | case 15: { |
| 775 | constexpr int kMaxCount = 4; |
| 776 | sk_sp<SkImageFilter> ifs[kMaxCount]; |
| 777 | int count; |
| 778 | fuzz->nextRange(&count, 1, kMaxCount); |
| 779 | for (int i = 0; i < count; ++i) { |
| 780 | ifs[i] = make_fuzz_imageFilter(fuzz, depth - 1); |
| 781 | } |
| 782 | bool useCropRect; |
| 783 | fuzz->next(&useCropRect); |
| 784 | SkImageFilter::CropRect cropRect; |
| 785 | if (useCropRect) { |
| 786 | fuzz->next(&cropRect); |
| 787 | } |
| 788 | return SkMergeImageFilter::Make(ifs, count, useCropRect ? &cropRect : nullptr); |
Hal Canary | e03c3e5 | 2017-03-09 11:33:35 -0500 | [diff] [blame] | 789 | } |
| 790 | case 16: { |
| 791 | int rx, ry; |
| 792 | fuzz->next(&rx, &ry); |
| 793 | bool useCropRect; |
| 794 | fuzz->next(&useCropRect); |
| 795 | SkImageFilter::CropRect cropRect; |
| 796 | if (useCropRect) { |
Kevin Lubick | dad29a0 | 2017-03-14 17:20:24 -0400 | [diff] [blame] | 797 | fuzz->next(&cropRect); |
Hal Canary | e03c3e5 | 2017-03-09 11:33:35 -0500 | [diff] [blame] | 798 | } |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 799 | sk_sp<SkImageFilter> input = make_fuzz_imageFilter(fuzz, depth - 1); |
Hal Canary | e03c3e5 | 2017-03-09 11:33:35 -0500 | [diff] [blame] | 800 | return SkDilateImageFilter::Make(rx, ry, std::move(input), |
| 801 | useCropRect ? &cropRect : nullptr); |
| 802 | } |
| 803 | case 17: { |
| 804 | int rx, ry; |
| 805 | fuzz->next(&rx, &ry); |
| 806 | bool useCropRect; |
| 807 | fuzz->next(&useCropRect); |
| 808 | SkImageFilter::CropRect cropRect; |
| 809 | if (useCropRect) { |
Kevin Lubick | dad29a0 | 2017-03-14 17:20:24 -0400 | [diff] [blame] | 810 | fuzz->next(&cropRect); |
Hal Canary | e03c3e5 | 2017-03-09 11:33:35 -0500 | [diff] [blame] | 811 | } |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 812 | sk_sp<SkImageFilter> input = make_fuzz_imageFilter(fuzz, depth - 1); |
Hal Canary | e03c3e5 | 2017-03-09 11:33:35 -0500 | [diff] [blame] | 813 | return SkErodeImageFilter::Make(rx, ry, std::move(input), |
| 814 | useCropRect ? &cropRect : nullptr); |
| 815 | } |
| 816 | case 18: { |
| 817 | SkScalar dx, dy; |
| 818 | fuzz->next(&dx, &dy); |
| 819 | bool useCropRect; |
| 820 | fuzz->next(&useCropRect); |
| 821 | SkImageFilter::CropRect cropRect; |
| 822 | if (useCropRect) { |
Kevin Lubick | dad29a0 | 2017-03-14 17:20:24 -0400 | [diff] [blame] | 823 | fuzz->next(&cropRect); |
Hal Canary | e03c3e5 | 2017-03-09 11:33:35 -0500 | [diff] [blame] | 824 | } |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 825 | sk_sp<SkImageFilter> input = make_fuzz_imageFilter(fuzz, depth - 1); |
Hal Canary | e03c3e5 | 2017-03-09 11:33:35 -0500 | [diff] [blame] | 826 | return SkOffsetImageFilter::Make(dx, dy, std::move(input), |
| 827 | useCropRect ? &cropRect : nullptr); |
| 828 | } |
| 829 | case 19: { |
| 830 | SkPaint paint; |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 831 | fuzz_paint(fuzz, &paint, depth - 1); |
Hal Canary | e03c3e5 | 2017-03-09 11:33:35 -0500 | [diff] [blame] | 832 | bool useCropRect; |
| 833 | fuzz->next(&useCropRect); |
| 834 | SkImageFilter::CropRect cropRect; |
| 835 | if (useCropRect) { |
Kevin Lubick | dad29a0 | 2017-03-14 17:20:24 -0400 | [diff] [blame] | 836 | fuzz->next(&cropRect); |
Hal Canary | e03c3e5 | 2017-03-09 11:33:35 -0500 | [diff] [blame] | 837 | } |
| 838 | return SkPaintImageFilter::Make(paint, useCropRect ? &cropRect : nullptr); |
| 839 | } |
| 840 | case 20: { |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 841 | sk_sp<SkPicture> picture = make_fuzz_picture(fuzz, depth - 1); |
Hal Canary | e03c3e5 | 2017-03-09 11:33:35 -0500 | [diff] [blame] | 842 | return SkPictureImageFilter::Make(std::move(picture)); |
| 843 | } |
| 844 | case 21: { |
| 845 | SkRect cropRect; |
| 846 | fuzz->next(&cropRect); |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 847 | sk_sp<SkPicture> picture = make_fuzz_picture(fuzz, depth - 1); |
Hal Canary | e03c3e5 | 2017-03-09 11:33:35 -0500 | [diff] [blame] | 848 | return SkPictureImageFilter::Make(std::move(picture), cropRect); |
| 849 | } |
| 850 | case 22: { |
Hal Canary | e03c3e5 | 2017-03-09 11:33:35 -0500 | [diff] [blame] | 851 | SkRect src, dst; |
| 852 | fuzz->next(&src, &dst); |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 853 | sk_sp<SkImageFilter> input = make_fuzz_imageFilter(fuzz, depth - 1); |
Hal Canary | e03c3e5 | 2017-03-09 11:33:35 -0500 | [diff] [blame] | 854 | return SkTileImageFilter::Make(src, dst, std::move(input)); |
| 855 | } |
Mike Reed | 77e487d | 2017-11-09 21:50:20 +0000 | [diff] [blame] | 856 | case 23: { |
Hal Canary | e03c3e5 | 2017-03-09 11:33:35 -0500 | [diff] [blame] | 857 | SkBlendMode blendMode; |
| 858 | bool useCropRect; |
| 859 | fuzz->next(&useCropRect, &blendMode); |
| 860 | SkImageFilter::CropRect cropRect; |
| 861 | if (useCropRect) { |
Kevin Lubick | dad29a0 | 2017-03-14 17:20:24 -0400 | [diff] [blame] | 862 | fuzz->next(&cropRect); |
Hal Canary | e03c3e5 | 2017-03-09 11:33:35 -0500 | [diff] [blame] | 863 | } |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 864 | sk_sp<SkImageFilter> bg = make_fuzz_imageFilter(fuzz, depth - 1); |
| 865 | sk_sp<SkImageFilter> fg = make_fuzz_imageFilter(fuzz, depth - 1); |
Hal Canary | e03c3e5 | 2017-03-09 11:33:35 -0500 | [diff] [blame] | 866 | return SkXfermodeImageFilter::Make(blendMode, std::move(bg), std::move(fg), |
| 867 | useCropRect ? &cropRect : nullptr); |
| 868 | } |
| 869 | default: |
| 870 | SkASSERT(false); |
| 871 | return nullptr; |
| 872 | } |
| 873 | } |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 874 | |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 875 | static sk_sp<SkImage> make_fuzz_image(Fuzz* fuzz) { |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 876 | int w, h; |
| 877 | fuzz->nextRange(&w, 1, 1024); |
| 878 | fuzz->nextRange(&h, 1, 1024); |
| 879 | SkAutoTMalloc<SkPMColor> data(w * h); |
| 880 | SkPixmap pixmap(SkImageInfo::MakeN32Premul(w, h), data.get(), w * sizeof(SkPMColor)); |
| 881 | int n = w * h; |
| 882 | for (int i = 0; i < n; ++i) { |
| 883 | SkColor c; |
| 884 | fuzz->next(&c); |
| 885 | data[i] = SkPreMultiplyColor(c); |
| 886 | } |
| 887 | (void)data.release(); |
Hal Canary | b69c4b8 | 2017-03-08 11:02:40 -0500 | [diff] [blame] | 888 | return SkImage::MakeFromRaster(pixmap, [](const void* p, void*) { sk_free((void*)p); }, |
| 889 | nullptr); |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 890 | } |
| 891 | |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 892 | static SkBitmap make_fuzz_bitmap(Fuzz* fuzz) { |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 893 | SkBitmap bitmap; |
| 894 | int w, h; |
| 895 | fuzz->nextRange(&w, 1, 1024); |
| 896 | fuzz->nextRange(&h, 1, 1024); |
Kevin Lubick | 1991f55 | 2018-02-27 10:59:10 -0500 | [diff] [blame] | 897 | if (!bitmap.tryAllocN32Pixels(w, h)) { |
Hal Canary | 2b0e6cd | 2018-07-09 12:43:39 -0400 | [diff] [blame] | 898 | SkDEBUGF("Could not allocate pixels %d x %d", w, h); |
Kevin Lubick | 1991f55 | 2018-02-27 10:59:10 -0500 | [diff] [blame] | 899 | return bitmap; |
| 900 | } |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 901 | for (int y = 0; y < h; ++y) { |
| 902 | for (int x = 0; x < w; ++x) { |
| 903 | SkColor c; |
| 904 | fuzz->next(&c); |
| 905 | *bitmap.getAddr32(x, y) = SkPreMultiplyColor(c); |
| 906 | } |
| 907 | } |
| 908 | return bitmap; |
| 909 | } |
| 910 | |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 911 | template <typename T, typename Min, typename Max> |
| 912 | inline T make_fuzz_t_range(Fuzz* fuzz, Min minv, Max maxv) { |
| 913 | T value; |
| 914 | fuzz_enum_range(fuzz, &value, minv, maxv); |
| 915 | return value; |
| 916 | } |
| 917 | |
| 918 | static void fuzz_paint(Fuzz* fuzz, SkPaint* paint, int depth) { |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 919 | if (!fuzz || !paint || depth <= 0) { |
| 920 | return; |
| 921 | } |
| 922 | |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 923 | paint->setAntiAlias( make_fuzz_t<bool>(fuzz)); |
| 924 | paint->setDither( make_fuzz_t<bool>(fuzz)); |
| 925 | paint->setColor( make_fuzz_t<SkColor>(fuzz)); |
| 926 | paint->setBlendMode( make_fuzz_t_range<SkBlendMode>(fuzz, 0, SkBlendMode::kLastMode)); |
| 927 | paint->setFilterQuality(make_fuzz_t_range<SkFilterQuality>(fuzz, 0, kLast_SkFilterQuality)); |
| 928 | paint->setStyle( make_fuzz_t_range<SkPaint::Style>(fuzz, 0, 2)); |
| 929 | paint->setShader( make_fuzz_shader(fuzz, depth - 1)); |
| 930 | paint->setPathEffect( make_fuzz_patheffect(fuzz, depth - 1)); |
| 931 | paint->setMaskFilter( make_fuzz_maskfilter(fuzz)); |
| 932 | paint->setImageFilter( make_fuzz_imageFilter(fuzz, depth - 1)); |
| 933 | paint->setColorFilter( make_fuzz_colorfilter(fuzz, depth - 1)); |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 934 | |
| 935 | if (paint->getStyle() != SkPaint::kFill_Style) { |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 936 | paint->setStrokeWidth(make_fuzz_t<SkScalar>(fuzz)); |
| 937 | paint->setStrokeMiter(make_fuzz_t<SkScalar>(fuzz)); |
| 938 | paint->setStrokeCap( make_fuzz_t_range<SkPaint::Cap>(fuzz, 0, SkPaint::kLast_Cap)); |
| 939 | 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] | 940 | } |
| 941 | } |
| 942 | |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 943 | static void fuzz_paint_text(Fuzz* fuzz, SkPaint* paint) { |
| 944 | paint->setTypeface( make_fuzz_typeface(fuzz)); |
| 945 | paint->setTextSize( make_fuzz_t<SkScalar>(fuzz)); |
| 946 | paint->setTextScaleX( make_fuzz_t<SkScalar>(fuzz)); |
| 947 | paint->setTextSkewX( make_fuzz_t<SkScalar>(fuzz)); |
| 948 | paint->setLinearText( make_fuzz_t<bool>(fuzz)); |
| 949 | paint->setSubpixelText( make_fuzz_t<bool>(fuzz)); |
| 950 | paint->setLCDRenderText( make_fuzz_t<bool>(fuzz)); |
| 951 | paint->setEmbeddedBitmapText(make_fuzz_t<bool>(fuzz)); |
| 952 | paint->setAutohinted( make_fuzz_t<bool>(fuzz)); |
| 953 | paint->setVerticalText( make_fuzz_t<bool>(fuzz)); |
| 954 | paint->setFakeBoldText( make_fuzz_t<bool>(fuzz)); |
| 955 | paint->setDevKernText( make_fuzz_t<bool>(fuzz)); |
| 956 | paint->setHinting( make_fuzz_t_range<SkPaint::Hinting>(fuzz, 0, |
| 957 | SkPaint::kFull_Hinting)); |
| 958 | paint->setTextAlign( make_fuzz_t_range<SkPaint::Align>(fuzz, 0, 2)); |
Hal Canary | 5395c59 | 2017-03-08 16:52:18 -0500 | [diff] [blame] | 959 | } |
| 960 | |
| 961 | static void fuzz_paint_text_encoding(Fuzz* fuzz, SkPaint* paint) { |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 962 | paint->setTextEncoding(make_fuzz_t_range<SkPaint::TextEncoding>(fuzz, 0, 3)); |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 963 | } |
| 964 | |
Hal Canary | 5395c59 | 2017-03-08 16:52:18 -0500 | [diff] [blame] | 965 | constexpr int kMaxGlyphCount = 30; |
| 966 | |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 967 | static SkTDArray<uint8_t> make_fuzz_text(Fuzz* fuzz, const SkPaint& paint) { |
Hal Canary | 671e442 | 2017-02-27 13:36:38 -0500 | [diff] [blame] | 968 | SkTDArray<uint8_t> array; |
| 969 | if (SkPaint::kGlyphID_TextEncoding == paint.getTextEncoding()) { |
Hal Canary | b69c4b8 | 2017-03-08 11:02:40 -0500 | [diff] [blame] | 970 | int glyphRange = paint.getTypeface() ? paint.getTypeface()->countGlyphs() |
| 971 | : SkTypeface::MakeDefault()->countGlyphs(); |
Kevin Lubick | 1991f55 | 2018-02-27 10:59:10 -0500 | [diff] [blame] | 972 | if (glyphRange == 0) { |
| 973 | // Some fuzzing environments have no fonts, so empty array is the best |
| 974 | // we can do. |
| 975 | return array; |
| 976 | } |
Hal Canary | 671e442 | 2017-02-27 13:36:38 -0500 | [diff] [blame] | 977 | int glyphCount; |
Hal Canary | 5395c59 | 2017-03-08 16:52:18 -0500 | [diff] [blame] | 978 | fuzz->nextRange(&glyphCount, 1, kMaxGlyphCount); |
Hal Canary | 671e442 | 2017-02-27 13:36:38 -0500 | [diff] [blame] | 979 | SkGlyphID* glyphs = (SkGlyphID*)array.append(glyphCount * sizeof(SkGlyphID)); |
| 980 | for (int i = 0; i < glyphCount; ++i) { |
| 981 | fuzz->nextRange(&glyphs[i], 0, glyphRange - 1); |
| 982 | } |
| 983 | return array; |
| 984 | } |
| 985 | static const SkUnichar ranges[][2] = { |
| 986 | {0x0020, 0x007F}, |
| 987 | {0x00A1, 0x0250}, |
| 988 | {0x0400, 0x0500}, |
| 989 | }; |
| 990 | int32_t count = 0; |
Hal Canary | b69c4b8 | 2017-03-08 11:02:40 -0500 | [diff] [blame] | 991 | for (size_t i = 0; i < SK_ARRAY_COUNT(ranges); ++i) { |
Hal Canary | 671e442 | 2017-02-27 13:36:38 -0500 | [diff] [blame] | 992 | count += (ranges[i][1] - ranges[i][0]); |
| 993 | } |
Hal Canary | 5395c59 | 2017-03-08 16:52:18 -0500 | [diff] [blame] | 994 | constexpr int kMaxLength = kMaxGlyphCount; |
Hal Canary | 671e442 | 2017-02-27 13:36:38 -0500 | [diff] [blame] | 995 | SkUnichar buffer[kMaxLength]; |
| 996 | int length; |
| 997 | fuzz->nextRange(&length, 1, kMaxLength); |
| 998 | for (int j = 0; j < length; ++j) { |
| 999 | int32_t value; |
| 1000 | fuzz->nextRange(&value, 0, count - 1); |
Hal Canary | b69c4b8 | 2017-03-08 11:02:40 -0500 | [diff] [blame] | 1001 | for (size_t i = 0; i < SK_ARRAY_COUNT(ranges); ++i) { |
Hal Canary | 671e442 | 2017-02-27 13:36:38 -0500 | [diff] [blame] | 1002 | if (value + ranges[i][0] < ranges[i][1]) { |
| 1003 | buffer[j] = value + ranges[i][0]; |
| 1004 | break; |
| 1005 | } else { |
| 1006 | value -= (ranges[i][1] - ranges[i][0]); |
| 1007 | } |
| 1008 | } |
| 1009 | } |
| 1010 | switch (paint.getTextEncoding()) { |
Hal Canary | b69c4b8 | 2017-03-08 11:02:40 -0500 | [diff] [blame] | 1011 | case SkPaint::kUTF8_TextEncoding: { |
| 1012 | size_t utf8len = 0; |
| 1013 | for (int j = 0; j < length; ++j) { |
Hal Canary | f107a2f | 2018-07-25 16:52:48 -0400 | [diff] [blame] | 1014 | utf8len += SkUTF::ToUTF8(buffer[j], nullptr); |
Hal Canary | 671e442 | 2017-02-27 13:36:38 -0500 | [diff] [blame] | 1015 | } |
Hal Canary | b69c4b8 | 2017-03-08 11:02:40 -0500 | [diff] [blame] | 1016 | char* ptr = (char*)array.append(utf8len); |
| 1017 | for (int j = 0; j < length; ++j) { |
Hal Canary | f107a2f | 2018-07-25 16:52:48 -0400 | [diff] [blame] | 1018 | ptr += SkUTF::ToUTF8(buffer[j], ptr); |
Hal Canary | 671e442 | 2017-02-27 13:36:38 -0500 | [diff] [blame] | 1019 | } |
Hal Canary | b69c4b8 | 2017-03-08 11:02:40 -0500 | [diff] [blame] | 1020 | } break; |
| 1021 | case SkPaint::kUTF16_TextEncoding: { |
| 1022 | size_t utf16len = 0; |
| 1023 | for (int j = 0; j < length; ++j) { |
Hal Canary | f107a2f | 2018-07-25 16:52:48 -0400 | [diff] [blame] | 1024 | utf16len += SkUTF::ToUTF16(buffer[j]); |
Hal Canary | b69c4b8 | 2017-03-08 11:02:40 -0500 | [diff] [blame] | 1025 | } |
| 1026 | uint16_t* ptr = (uint16_t*)array.append(utf16len * sizeof(uint16_t)); |
| 1027 | for (int j = 0; j < length; ++j) { |
Hal Canary | f107a2f | 2018-07-25 16:52:48 -0400 | [diff] [blame] | 1028 | ptr += SkUTF::ToUTF16(buffer[j], ptr); |
Hal Canary | b69c4b8 | 2017-03-08 11:02:40 -0500 | [diff] [blame] | 1029 | } |
| 1030 | } break; |
Hal Canary | 671e442 | 2017-02-27 13:36:38 -0500 | [diff] [blame] | 1031 | case SkPaint::kUTF32_TextEncoding: |
| 1032 | memcpy(array.append(length * sizeof(SkUnichar)), buffer, length * sizeof(SkUnichar)); |
Hal Canary | c1a70e2 | 2017-03-01 15:40:46 -0500 | [diff] [blame] | 1033 | break; |
Hal Canary | 671e442 | 2017-02-27 13:36:38 -0500 | [diff] [blame] | 1034 | default: |
Hal Canary | b69c4b8 | 2017-03-08 11:02:40 -0500 | [diff] [blame] | 1035 | SkASSERT(false); |
Kevin Lubick | 54f20e0 | 2018-01-11 14:50:21 -0500 | [diff] [blame] | 1036 | break; |
Hal Canary | 671e442 | 2017-02-27 13:36:38 -0500 | [diff] [blame] | 1037 | } |
| 1038 | return array; |
| 1039 | } |
| 1040 | |
Hal Canary | 5395c59 | 2017-03-08 16:52:18 -0500 | [diff] [blame] | 1041 | static sk_sp<SkTextBlob> make_fuzz_textblob(Fuzz* fuzz) { |
| 1042 | SkTextBlobBuilder textBlobBuilder; |
| 1043 | int8_t runCount; |
| 1044 | fuzz->nextRange(&runCount, (int8_t)1, (int8_t)8); |
| 1045 | while (runCount-- > 0) { |
| 1046 | SkPaint paint; |
| 1047 | fuzz_paint_text_encoding(fuzz, &paint); |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 1048 | paint.setAntiAlias(make_fuzz_t<bool>(fuzz)); |
Hal Canary | 5395c59 | 2017-03-08 16:52:18 -0500 | [diff] [blame] | 1049 | paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding); |
| 1050 | SkTDArray<uint8_t> text = make_fuzz_text(fuzz, paint); |
| 1051 | int glyphCount = paint.countText(text.begin(), SkToSizeT(text.count())); |
| 1052 | SkASSERT(glyphCount <= kMaxGlyphCount); |
| 1053 | SkScalar x, y; |
| 1054 | const SkTextBlobBuilder::RunBuffer* buffer; |
| 1055 | uint8_t runType; |
| 1056 | fuzz->nextRange(&runType, (uint8_t)0, (uint8_t)2); |
| 1057 | switch (runType) { |
| 1058 | case 0: |
| 1059 | fuzz->next(&x, &y); |
| 1060 | // TODO: Test other variations of this. |
| 1061 | buffer = &textBlobBuilder.allocRun(paint, glyphCount, x, y); |
| 1062 | memcpy(buffer->glyphs, text.begin(), SkToSizeT(text.count())); |
| 1063 | break; |
| 1064 | case 1: |
| 1065 | fuzz->next(&y); |
| 1066 | // TODO: Test other variations of this. |
| 1067 | buffer = &textBlobBuilder.allocRunPosH(paint, glyphCount, y); |
| 1068 | memcpy(buffer->glyphs, text.begin(), SkToSizeT(text.count())); |
| 1069 | fuzz->nextN(buffer->pos, glyphCount); |
| 1070 | break; |
| 1071 | case 2: |
| 1072 | // TODO: Test other variations of this. |
| 1073 | buffer = &textBlobBuilder.allocRunPos(paint, glyphCount); |
| 1074 | memcpy(buffer->glyphs, text.begin(), SkToSizeT(text.count())); |
| 1075 | fuzz->nextN(buffer->pos, glyphCount * 2); |
| 1076 | break; |
| 1077 | default: |
| 1078 | SkASSERT(false); |
Kevin Lubick | 54f20e0 | 2018-01-11 14:50:21 -0500 | [diff] [blame] | 1079 | break; |
Hal Canary | 5395c59 | 2017-03-08 16:52:18 -0500 | [diff] [blame] | 1080 | } |
| 1081 | } |
| 1082 | return textBlobBuilder.make(); |
| 1083 | } |
| 1084 | |
Kevin Lubick | d2ae8dc | 2018-06-01 13:16:20 -0400 | [diff] [blame] | 1085 | extern std::atomic<bool> gSkUseDeltaAA; |
| 1086 | extern std::atomic<bool> gSkForceDeltaAA; |
| 1087 | |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 1088 | static void fuzz_canvas(Fuzz* fuzz, SkCanvas* canvas, int depth = 9) { |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 1089 | if (!fuzz || !canvas || depth <= 0) { |
| 1090 | return; |
| 1091 | } |
| 1092 | SkAutoCanvasRestore autoCanvasRestore(canvas, false); |
Kevin Lubick | d2ae8dc | 2018-06-01 13:16:20 -0400 | [diff] [blame] | 1093 | bool useDAA; |
| 1094 | fuzz->next(&useDAA); |
| 1095 | if (useDAA) { |
| 1096 | gSkForceDeltaAA = true; |
| 1097 | gSkUseDeltaAA = true; |
| 1098 | } |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 1099 | unsigned N; |
| 1100 | fuzz->nextRange(&N, 0, 2000); |
| 1101 | for (unsigned i = 0; i < N; ++i) { |
| 1102 | if (fuzz->exhausted()) { |
| 1103 | return; |
| 1104 | } |
| 1105 | SkPaint paint; |
| 1106 | SkMatrix matrix; |
| 1107 | unsigned drawCommand; |
Hal Canary | 5af600e | 2017-03-09 14:10:36 -0500 | [diff] [blame] | 1108 | fuzz->nextRange(&drawCommand, 0, 53); |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 1109 | switch (drawCommand) { |
| 1110 | case 0: |
| 1111 | canvas->flush(); |
| 1112 | break; |
| 1113 | case 1: |
| 1114 | canvas->save(); |
| 1115 | break; |
| 1116 | case 2: { |
| 1117 | SkRect bounds; |
| 1118 | fuzz->next(&bounds); |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 1119 | fuzz_paint(fuzz, &paint, depth - 1); |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 1120 | canvas->saveLayer(&bounds, &paint); |
| 1121 | break; |
| 1122 | } |
| 1123 | case 3: { |
| 1124 | SkRect bounds; |
| 1125 | fuzz->next(&bounds); |
| 1126 | canvas->saveLayer(&bounds, nullptr); |
| 1127 | break; |
| 1128 | } |
| 1129 | case 4: |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 1130 | fuzz_paint(fuzz, &paint, depth - 1); |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 1131 | canvas->saveLayer(nullptr, &paint); |
| 1132 | break; |
| 1133 | case 5: |
| 1134 | canvas->saveLayer(nullptr, nullptr); |
| 1135 | break; |
| 1136 | case 6: { |
| 1137 | uint8_t alpha; |
| 1138 | fuzz->next(&alpha); |
| 1139 | canvas->saveLayerAlpha(nullptr, (U8CPU)alpha); |
| 1140 | break; |
| 1141 | } |
| 1142 | case 7: { |
| 1143 | SkRect bounds; |
| 1144 | uint8_t alpha; |
| 1145 | fuzz->next(&bounds, &alpha); |
| 1146 | canvas->saveLayerAlpha(&bounds, (U8CPU)alpha); |
| 1147 | break; |
| 1148 | } |
| 1149 | case 8: { |
| 1150 | SkCanvas::SaveLayerRec saveLayerRec; |
| 1151 | SkRect bounds; |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 1152 | if (make_fuzz_t<bool>(fuzz)) { |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 1153 | fuzz->next(&bounds); |
| 1154 | saveLayerRec.fBounds = &bounds; |
| 1155 | } |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 1156 | if (make_fuzz_t<bool>(fuzz)) { |
| 1157 | fuzz_paint(fuzz, &paint, depth - 1); |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 1158 | saveLayerRec.fPaint = &paint; |
| 1159 | } |
| 1160 | sk_sp<SkImageFilter> imageFilter; |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 1161 | if (make_fuzz_t<bool>(fuzz)) { |
| 1162 | imageFilter = make_fuzz_imageFilter(fuzz, depth - 1); |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 1163 | saveLayerRec.fBackdrop = imageFilter.get(); |
| 1164 | } |
Hal Canary | 5395c59 | 2017-03-08 16:52:18 -0500 | [diff] [blame] | 1165 | // _DumpCanvas can't handle this. |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 1166 | // if (make_fuzz_t<bool>(fuzz)) { |
Hal Canary | 5395c59 | 2017-03-08 16:52:18 -0500 | [diff] [blame] | 1167 | // saveLayerRec.fSaveLayerFlags |= SkCanvas::kPreserveLCDText_SaveLayerFlag; |
| 1168 | // } |
| 1169 | |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 1170 | canvas->saveLayer(saveLayerRec); |
| 1171 | break; |
| 1172 | } |
| 1173 | case 9: |
| 1174 | canvas->restore(); |
| 1175 | break; |
| 1176 | case 10: { |
| 1177 | int saveCount; |
| 1178 | fuzz->next(&saveCount); |
| 1179 | canvas->restoreToCount(saveCount); |
| 1180 | break; |
| 1181 | } |
| 1182 | case 11: { |
| 1183 | SkScalar x, y; |
| 1184 | fuzz->next(&x, &y); |
| 1185 | canvas->translate(x, y); |
| 1186 | break; |
| 1187 | } |
| 1188 | case 12: { |
| 1189 | SkScalar x, y; |
| 1190 | fuzz->next(&x, &y); |
| 1191 | canvas->scale(x, y); |
| 1192 | break; |
| 1193 | } |
| 1194 | case 13: { |
| 1195 | SkScalar v; |
| 1196 | fuzz->next(&v); |
| 1197 | canvas->rotate(v); |
| 1198 | break; |
| 1199 | } |
| 1200 | case 14: { |
| 1201 | SkScalar x, y, v; |
| 1202 | fuzz->next(&x, &y, &v); |
| 1203 | canvas->rotate(v, x, y); |
| 1204 | break; |
| 1205 | } |
| 1206 | case 15: { |
| 1207 | SkScalar x, y; |
| 1208 | fuzz->next(&x, &y); |
| 1209 | canvas->skew(x, y); |
| 1210 | break; |
| 1211 | } |
| 1212 | case 16: { |
| 1213 | SkMatrix mat; |
| 1214 | fuzz->next(&mat); |
| 1215 | canvas->concat(mat); |
| 1216 | break; |
| 1217 | } |
| 1218 | case 17: { |
| 1219 | SkMatrix mat; |
| 1220 | fuzz->next(&mat); |
| 1221 | canvas->setMatrix(mat); |
| 1222 | break; |
| 1223 | } |
| 1224 | case 18: |
| 1225 | canvas->resetMatrix(); |
| 1226 | break; |
| 1227 | case 19: { |
| 1228 | SkRect r; |
| 1229 | int op; |
| 1230 | bool doAntiAlias; |
| 1231 | fuzz->next(&r, &doAntiAlias); |
| 1232 | fuzz->nextRange(&op, 0, 1); |
| 1233 | r.sort(); |
| 1234 | canvas->clipRect(r, (SkClipOp)op, doAntiAlias); |
| 1235 | break; |
| 1236 | } |
| 1237 | case 20: { |
| 1238 | SkRRect rr; |
| 1239 | int op; |
| 1240 | bool doAntiAlias; |
| 1241 | fuzz->next(&rr); |
| 1242 | fuzz->next(&doAntiAlias); |
| 1243 | fuzz->nextRange(&op, 0, 1); |
| 1244 | canvas->clipRRect(rr, (SkClipOp)op, doAntiAlias); |
| 1245 | break; |
| 1246 | } |
| 1247 | case 21: { |
| 1248 | SkPath path; |
Cary Clark | 91390c8 | 2018-03-09 14:02:46 -0500 | [diff] [blame] | 1249 | FuzzPath(fuzz, &path, 30); |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 1250 | int op; |
| 1251 | bool doAntiAlias; |
| 1252 | fuzz->next(&doAntiAlias); |
| 1253 | fuzz->nextRange(&op, 0, 1); |
| 1254 | canvas->clipPath(path, (SkClipOp)op, doAntiAlias); |
| 1255 | break; |
| 1256 | } |
| 1257 | case 22: { |
| 1258 | SkRegion region; |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 1259 | int op; |
Hal Canary | e03c3e5 | 2017-03-09 11:33:35 -0500 | [diff] [blame] | 1260 | fuzz->next(®ion); |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 1261 | fuzz->nextRange(&op, 0, 1); |
| 1262 | canvas->clipRegion(region, (SkClipOp)op); |
| 1263 | break; |
| 1264 | } |
| 1265 | case 23: |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 1266 | fuzz_paint(fuzz, &paint, depth - 1); |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 1267 | canvas->drawPaint(paint); |
| 1268 | break; |
| 1269 | case 24: { |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 1270 | fuzz_paint(fuzz, &paint, depth - 1); |
Hal Canary | c8bebd4 | 2017-12-20 11:21:05 -0500 | [diff] [blame] | 1271 | SkCanvas::PointMode pointMode; |
| 1272 | fuzz_enum_range(fuzz, &pointMode, |
| 1273 | SkCanvas::kPoints_PointMode, SkCanvas::kPolygon_PointMode); |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 1274 | size_t count; |
| 1275 | constexpr int kMaxCount = 30; |
| 1276 | fuzz->nextRange(&count, 0, kMaxCount); |
| 1277 | SkPoint pts[kMaxCount]; |
| 1278 | fuzz->nextN(pts, count); |
Hal Canary | c8bebd4 | 2017-12-20 11:21:05 -0500 | [diff] [blame] | 1279 | canvas->drawPoints(pointMode, count, pts, paint); |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 1280 | break; |
| 1281 | } |
| 1282 | case 25: { |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 1283 | fuzz_paint(fuzz, &paint, depth - 1); |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 1284 | SkRect r; |
| 1285 | fuzz->next(&r); |
Kevin Lubick | c5f0427 | 2018-04-05 12:54:00 -0400 | [diff] [blame] | 1286 | if (!r.isFinite()) { |
| 1287 | break; |
| 1288 | } |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 1289 | canvas->drawRect(r, paint); |
| 1290 | break; |
| 1291 | } |
| 1292 | case 26: { |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 1293 | fuzz_paint(fuzz, &paint, depth - 1); |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 1294 | SkRegion region; |
Hal Canary | e03c3e5 | 2017-03-09 11:33:35 -0500 | [diff] [blame] | 1295 | fuzz->next(®ion); |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 1296 | canvas->drawRegion(region, paint); |
| 1297 | break; |
| 1298 | } |
| 1299 | case 27: { |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 1300 | fuzz_paint(fuzz, &paint, depth - 1); |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 1301 | SkRect r; |
| 1302 | fuzz->next(&r); |
Kevin Lubick | c5f0427 | 2018-04-05 12:54:00 -0400 | [diff] [blame] | 1303 | if (!r.isFinite()) { |
| 1304 | break; |
| 1305 | } |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 1306 | canvas->drawOval(r, paint); |
| 1307 | break; |
| 1308 | } |
Mike Reed | 9cec1bc | 2018-01-19 12:57:01 -0500 | [diff] [blame] | 1309 | case 28: break; // must have deleted this some time earlier |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 1310 | case 29: { |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 1311 | fuzz_paint(fuzz, &paint, depth - 1); |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 1312 | SkRRect rr; |
| 1313 | fuzz->next(&rr); |
| 1314 | canvas->drawRRect(rr, paint); |
| 1315 | break; |
| 1316 | } |
| 1317 | case 30: { |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 1318 | fuzz_paint(fuzz, &paint, depth - 1); |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 1319 | SkRRect orr, irr; |
| 1320 | fuzz->next(&orr); |
| 1321 | fuzz->next(&irr); |
Hal Canary | 27bece8 | 2017-03-07 16:23:20 -0500 | [diff] [blame] | 1322 | if (orr.getBounds().contains(irr.getBounds())) { |
| 1323 | canvas->drawDRRect(orr, irr, paint); |
| 1324 | } |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 1325 | break; |
| 1326 | } |
| 1327 | case 31: { |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 1328 | fuzz_paint(fuzz, &paint, depth - 1); |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 1329 | SkRect r; |
| 1330 | SkScalar start, sweep; |
| 1331 | bool useCenter; |
| 1332 | fuzz->next(&r, &start, &sweep, &useCenter); |
| 1333 | canvas->drawArc(r, start, sweep, useCenter, paint); |
| 1334 | break; |
| 1335 | } |
| 1336 | case 32: { |
Kevin Lubick | 0938ce7 | 2018-05-21 21:17:15 -0400 | [diff] [blame] | 1337 | fuzz_paint(fuzz, &paint, depth - 1); |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 1338 | SkPath path; |
Cary Clark | 91390c8 | 2018-03-09 14:02:46 -0500 | [diff] [blame] | 1339 | FuzzPath(fuzz, &path, 60); |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 1340 | canvas->drawPath(path, paint); |
| 1341 | break; |
| 1342 | } |
| 1343 | case 33: { |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 1344 | sk_sp<SkImage> img = make_fuzz_image(fuzz); |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 1345 | SkScalar left, top; |
| 1346 | bool usePaint; |
| 1347 | fuzz->next(&left, &top, &usePaint); |
| 1348 | if (usePaint) { |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 1349 | fuzz_paint(fuzz, &paint, depth - 1); |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 1350 | } |
| 1351 | canvas->drawImage(img.get(), left, top, usePaint ? &paint : nullptr); |
| 1352 | break; |
| 1353 | } |
| 1354 | case 34: { |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 1355 | auto img = make_fuzz_image(fuzz); |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 1356 | SkRect src, dst; |
| 1357 | bool usePaint; |
| 1358 | fuzz->next(&src, &dst, &usePaint); |
| 1359 | if (usePaint) { |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 1360 | fuzz_paint(fuzz, &paint, depth - 1); |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 1361 | } |
Hal Canary | b69c4b8 | 2017-03-08 11:02:40 -0500 | [diff] [blame] | 1362 | SkCanvas::SrcRectConstraint constraint = |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 1363 | make_fuzz_t<bool>(fuzz) ? SkCanvas::kStrict_SrcRectConstraint |
| 1364 | : SkCanvas::kFast_SrcRectConstraint; |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 1365 | canvas->drawImageRect(img, src, dst, usePaint ? &paint : nullptr, constraint); |
| 1366 | break; |
| 1367 | } |
| 1368 | case 35: { |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 1369 | auto img = make_fuzz_image(fuzz); |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 1370 | SkIRect src; |
| 1371 | SkRect dst; |
| 1372 | bool usePaint; |
| 1373 | fuzz->next(&src, &dst, &usePaint); |
| 1374 | if (usePaint) { |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 1375 | fuzz_paint(fuzz, &paint, depth - 1); |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 1376 | } |
Hal Canary | b69c4b8 | 2017-03-08 11:02:40 -0500 | [diff] [blame] | 1377 | SkCanvas::SrcRectConstraint constraint = |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 1378 | make_fuzz_t<bool>(fuzz) ? SkCanvas::kStrict_SrcRectConstraint |
| 1379 | : SkCanvas::kFast_SrcRectConstraint; |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 1380 | canvas->drawImageRect(img, src, dst, usePaint ? &paint : nullptr, constraint); |
| 1381 | break; |
| 1382 | } |
| 1383 | case 36: { |
| 1384 | bool usePaint; |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 1385 | auto img = make_fuzz_image(fuzz); |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 1386 | SkRect dst; |
| 1387 | fuzz->next(&dst, &usePaint); |
| 1388 | if (usePaint) { |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 1389 | fuzz_paint(fuzz, &paint, depth - 1); |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 1390 | } |
Hal Canary | b69c4b8 | 2017-03-08 11:02:40 -0500 | [diff] [blame] | 1391 | SkCanvas::SrcRectConstraint constraint = |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 1392 | make_fuzz_t<bool>(fuzz) ? SkCanvas::kStrict_SrcRectConstraint |
| 1393 | : SkCanvas::kFast_SrcRectConstraint; |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 1394 | canvas->drawImageRect(img, dst, usePaint ? &paint : nullptr, constraint); |
| 1395 | break; |
| 1396 | } |
| 1397 | case 37: { |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 1398 | auto img = make_fuzz_image(fuzz); |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 1399 | SkIRect center; |
| 1400 | SkRect dst; |
| 1401 | bool usePaint; |
Hal Canary | 0361d49 | 2017-03-15 12:58:15 -0400 | [diff] [blame] | 1402 | fuzz->next(&usePaint); |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 1403 | if (usePaint) { |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 1404 | fuzz_paint(fuzz, &paint, depth - 1); |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 1405 | } |
Hal Canary | 0361d49 | 2017-03-15 12:58:15 -0400 | [diff] [blame] | 1406 | if (make_fuzz_t<bool>(fuzz)) { |
| 1407 | fuzz->next(¢er); |
| 1408 | } else { // Make valid center, see SkLatticeIter::Valid(). |
| 1409 | fuzz->nextRange(¢er.fLeft, 0, img->width() - 1); |
| 1410 | fuzz->nextRange(¢er.fTop, 0, img->height() - 1); |
| 1411 | fuzz->nextRange(¢er.fRight, center.fLeft + 1, img->width()); |
| 1412 | fuzz->nextRange(¢er.fBottom, center.fTop + 1, img->height()); |
| 1413 | } |
| 1414 | fuzz->next(&dst); |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 1415 | canvas->drawImageNine(img, center, dst, usePaint ? &paint : nullptr); |
| 1416 | break; |
| 1417 | } |
| 1418 | case 38: { |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 1419 | SkBitmap bitmap = make_fuzz_bitmap(fuzz); |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 1420 | SkScalar left, top; |
| 1421 | bool usePaint; |
| 1422 | fuzz->next(&left, &top, &usePaint); |
| 1423 | if (usePaint) { |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 1424 | fuzz_paint(fuzz, &paint, depth - 1); |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 1425 | } |
| 1426 | canvas->drawBitmap(bitmap, left, top, usePaint ? &paint : nullptr); |
| 1427 | break; |
| 1428 | } |
| 1429 | case 39: { |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 1430 | SkBitmap bitmap = make_fuzz_bitmap(fuzz); |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 1431 | SkRect src, dst; |
| 1432 | bool usePaint; |
| 1433 | fuzz->next(&src, &dst, &usePaint); |
| 1434 | if (usePaint) { |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 1435 | fuzz_paint(fuzz, &paint, depth - 1); |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 1436 | } |
Hal Canary | b69c4b8 | 2017-03-08 11:02:40 -0500 | [diff] [blame] | 1437 | SkCanvas::SrcRectConstraint constraint = |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 1438 | make_fuzz_t<bool>(fuzz) ? SkCanvas::kStrict_SrcRectConstraint |
| 1439 | : SkCanvas::kFast_SrcRectConstraint; |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 1440 | canvas->drawBitmapRect(bitmap, src, dst, usePaint ? &paint : nullptr, constraint); |
| 1441 | break; |
| 1442 | } |
| 1443 | case 40: { |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 1444 | SkBitmap img = make_fuzz_bitmap(fuzz); |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 1445 | SkIRect src; |
| 1446 | SkRect dst; |
| 1447 | bool usePaint; |
| 1448 | fuzz->next(&src, &dst, &usePaint); |
| 1449 | if (usePaint) { |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 1450 | fuzz_paint(fuzz, &paint, depth - 1); |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 1451 | } |
Hal Canary | b69c4b8 | 2017-03-08 11:02:40 -0500 | [diff] [blame] | 1452 | SkCanvas::SrcRectConstraint constraint = |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 1453 | make_fuzz_t<bool>(fuzz) ? SkCanvas::kStrict_SrcRectConstraint |
| 1454 | : SkCanvas::kFast_SrcRectConstraint; |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 1455 | canvas->drawBitmapRect(img, src, dst, usePaint ? &paint : nullptr, constraint); |
| 1456 | break; |
| 1457 | } |
| 1458 | case 41: { |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 1459 | SkBitmap img = make_fuzz_bitmap(fuzz); |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 1460 | SkRect dst; |
| 1461 | bool usePaint; |
| 1462 | fuzz->next(&dst, &usePaint); |
| 1463 | if (usePaint) { |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 1464 | fuzz_paint(fuzz, &paint, depth - 1); |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 1465 | } |
Hal Canary | b69c4b8 | 2017-03-08 11:02:40 -0500 | [diff] [blame] | 1466 | SkCanvas::SrcRectConstraint constraint = |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 1467 | make_fuzz_t<bool>(fuzz) ? SkCanvas::kStrict_SrcRectConstraint |
| 1468 | : SkCanvas::kFast_SrcRectConstraint; |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 1469 | canvas->drawBitmapRect(img, dst, usePaint ? &paint : nullptr, constraint); |
| 1470 | break; |
| 1471 | } |
| 1472 | case 42: { |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 1473 | SkBitmap img = make_fuzz_bitmap(fuzz); |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 1474 | SkIRect center; |
| 1475 | SkRect dst; |
| 1476 | bool usePaint; |
Hal Canary | 0361d49 | 2017-03-15 12:58:15 -0400 | [diff] [blame] | 1477 | fuzz->next(&usePaint); |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 1478 | if (usePaint) { |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 1479 | fuzz_paint(fuzz, &paint, depth - 1); |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 1480 | } |
Hal Canary | 0361d49 | 2017-03-15 12:58:15 -0400 | [diff] [blame] | 1481 | if (make_fuzz_t<bool>(fuzz)) { |
| 1482 | fuzz->next(¢er); |
| 1483 | } else { // Make valid center, see SkLatticeIter::Valid(). |
Kevin Lubick | 1991f55 | 2018-02-27 10:59:10 -0500 | [diff] [blame] | 1484 | if (img.width() == 0 || img.height() == 0) { |
| 1485 | // bitmap may not have had its pixels initialized. |
| 1486 | break; |
| 1487 | } |
Hal Canary | 0361d49 | 2017-03-15 12:58:15 -0400 | [diff] [blame] | 1488 | fuzz->nextRange(¢er.fLeft, 0, img.width() - 1); |
| 1489 | fuzz->nextRange(¢er.fTop, 0, img.height() - 1); |
| 1490 | fuzz->nextRange(¢er.fRight, center.fLeft + 1, img.width()); |
| 1491 | fuzz->nextRange(¢er.fBottom, center.fTop + 1, img.height()); |
| 1492 | } |
| 1493 | fuzz->next(&dst); |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 1494 | canvas->drawBitmapNine(img, center, dst, usePaint ? &paint : nullptr); |
| 1495 | break; |
| 1496 | } |
| 1497 | case 43: { |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 1498 | SkBitmap img = make_fuzz_bitmap(fuzz); |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 1499 | bool usePaint; |
| 1500 | SkRect dst; |
| 1501 | fuzz->next(&usePaint, &dst); |
| 1502 | if (usePaint) { |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 1503 | fuzz_paint(fuzz, &paint, depth - 1); |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 1504 | } |
| 1505 | constexpr int kMax = 6; |
| 1506 | int xDivs[kMax], yDivs[kMax]; |
Stan Iliev | ca8c095 | 2017-12-11 13:01:58 -0500 | [diff] [blame] | 1507 | SkCanvas::Lattice lattice{xDivs, yDivs, nullptr, 0, 0, nullptr, nullptr}; |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 1508 | fuzz->nextRange(&lattice.fXCount, 2, kMax); |
| 1509 | fuzz->nextRange(&lattice.fYCount, 2, kMax); |
| 1510 | fuzz->nextN(xDivs, lattice.fXCount); |
| 1511 | fuzz->nextN(yDivs, lattice.fYCount); |
| 1512 | canvas->drawBitmapLattice(img, lattice, dst, usePaint ? &paint : nullptr); |
| 1513 | break; |
| 1514 | } |
| 1515 | case 44: { |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 1516 | auto img = make_fuzz_image(fuzz); |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 1517 | bool usePaint; |
| 1518 | SkRect dst; |
| 1519 | fuzz->next(&usePaint, &dst); |
| 1520 | if (usePaint) { |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 1521 | fuzz_paint(fuzz, &paint, depth - 1); |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 1522 | } |
| 1523 | constexpr int kMax = 6; |
| 1524 | int xDivs[kMax], yDivs[kMax]; |
Stan Iliev | ca8c095 | 2017-12-11 13:01:58 -0500 | [diff] [blame] | 1525 | SkCanvas::Lattice lattice{xDivs, yDivs, nullptr, 0, 0, nullptr, nullptr}; |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 1526 | fuzz->nextRange(&lattice.fXCount, 2, kMax); |
| 1527 | fuzz->nextRange(&lattice.fYCount, 2, kMax); |
| 1528 | fuzz->nextN(xDivs, lattice.fXCount); |
| 1529 | fuzz->nextN(yDivs, lattice.fYCount); |
| 1530 | canvas->drawImageLattice(img.get(), lattice, dst, usePaint ? &paint : nullptr); |
| 1531 | break; |
| 1532 | } |
| 1533 | case 45: { |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 1534 | fuzz_paint(fuzz, &paint, depth - 1); |
| 1535 | fuzz_paint_text(fuzz, &paint); |
Hal Canary | 5395c59 | 2017-03-08 16:52:18 -0500 | [diff] [blame] | 1536 | fuzz_paint_text_encoding(fuzz, &paint); |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 1537 | SkScalar x, y; |
| 1538 | fuzz->next(&x, &y); |
Hal Canary | 5395c59 | 2017-03-08 16:52:18 -0500 | [diff] [blame] | 1539 | SkTDArray<uint8_t> text = make_fuzz_text(fuzz, paint); |
Hal Canary | 671e442 | 2017-02-27 13:36:38 -0500 | [diff] [blame] | 1540 | canvas->drawText(text.begin(), SkToSizeT(text.count()), x, y, paint); |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 1541 | break; |
| 1542 | } |
| 1543 | case 46: { |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 1544 | fuzz_paint(fuzz, &paint, depth - 1); |
| 1545 | fuzz_paint_text(fuzz, &paint); |
Hal Canary | 5395c59 | 2017-03-08 16:52:18 -0500 | [diff] [blame] | 1546 | fuzz_paint_text_encoding(fuzz, &paint); |
| 1547 | SkTDArray<uint8_t> text = make_fuzz_text(fuzz, paint); |
Hal Canary | 671e442 | 2017-02-27 13:36:38 -0500 | [diff] [blame] | 1548 | int glyphCount = paint.countText(text.begin(), SkToSizeT(text.count())); |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 1549 | if (glyphCount < 1) { |
| 1550 | break; |
| 1551 | } |
| 1552 | SkAutoTMalloc<SkPoint> pos(glyphCount); |
| 1553 | SkAutoTMalloc<SkScalar> widths(glyphCount); |
Hal Canary | 671e442 | 2017-02-27 13:36:38 -0500 | [diff] [blame] | 1554 | paint.getTextWidths(text.begin(), SkToSizeT(text.count()), widths.get()); |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 1555 | pos[0] = {0, 0}; |
| 1556 | for (int i = 1; i < glyphCount; ++i) { |
| 1557 | float y; |
Hal Canary | b69c4b8 | 2017-03-08 11:02:40 -0500 | [diff] [blame] | 1558 | fuzz->nextRange(&y, -0.5f * paint.getTextSize(), 0.5f * paint.getTextSize()); |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 1559 | pos[i] = {pos[i - 1].x() + widths[i - 1], y}; |
| 1560 | } |
Hal Canary | 671e442 | 2017-02-27 13:36:38 -0500 | [diff] [blame] | 1561 | canvas->drawPosText(text.begin(), SkToSizeT(text.count()), pos.get(), paint); |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 1562 | break; |
| 1563 | } |
| 1564 | case 47: { |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 1565 | fuzz_paint(fuzz, &paint, depth - 1); |
| 1566 | fuzz_paint_text(fuzz, &paint); |
Hal Canary | 5395c59 | 2017-03-08 16:52:18 -0500 | [diff] [blame] | 1567 | fuzz_paint_text_encoding(fuzz, &paint); |
| 1568 | SkTDArray<uint8_t> text = make_fuzz_text(fuzz, paint); |
Hal Canary | 671e442 | 2017-02-27 13:36:38 -0500 | [diff] [blame] | 1569 | int glyphCount = paint.countText(text.begin(), SkToSizeT(text.count())); |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 1570 | SkAutoTMalloc<SkScalar> widths(glyphCount); |
| 1571 | if (glyphCount < 1) { |
| 1572 | break; |
| 1573 | } |
Hal Canary | 671e442 | 2017-02-27 13:36:38 -0500 | [diff] [blame] | 1574 | paint.getTextWidths(text.begin(), SkToSizeT(text.count()), widths.get()); |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 1575 | SkScalar x = widths[0]; |
| 1576 | for (int i = 0; i < glyphCount; ++i) { |
Ben Wagner | f08d1d0 | 2018-06-18 15:11:00 -0400 | [diff] [blame] | 1577 | using std::swap; |
| 1578 | swap(x, widths[i]); |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 1579 | x += widths[i]; |
| 1580 | SkScalar offset; |
| 1581 | fuzz->nextRange(&offset, -0.125f * paint.getTextSize(), |
Hal Canary | b69c4b8 | 2017-03-08 11:02:40 -0500 | [diff] [blame] | 1582 | 0.125f * paint.getTextSize()); |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 1583 | widths[i] += offset; |
| 1584 | } |
| 1585 | SkScalar y; |
| 1586 | fuzz->next(&y); |
Hal Canary | b69c4b8 | 2017-03-08 11:02:40 -0500 | [diff] [blame] | 1587 | canvas->drawPosTextH(text.begin(), SkToSizeT(text.count()), widths.get(), y, paint); |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 1588 | break; |
| 1589 | } |
| 1590 | case 48: { |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 1591 | fuzz_paint(fuzz, &paint, depth - 1); |
| 1592 | fuzz_paint_text(fuzz, &paint); |
Hal Canary | 5395c59 | 2017-03-08 16:52:18 -0500 | [diff] [blame] | 1593 | fuzz_paint_text_encoding(fuzz, &paint); |
| 1594 | SkTDArray<uint8_t> text = make_fuzz_text(fuzz, paint); |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 1595 | SkPath path; |
Cary Clark | 91390c8 | 2018-03-09 14:02:46 -0500 | [diff] [blame] | 1596 | FuzzPath(fuzz, &path, 20); |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 1597 | SkScalar hOffset, vOffset; |
| 1598 | fuzz->next(&hOffset, &vOffset); |
Hal Canary | b69c4b8 | 2017-03-08 11:02:40 -0500 | [diff] [blame] | 1599 | canvas->drawTextOnPathHV(text.begin(), SkToSizeT(text.count()), path, hOffset, |
| 1600 | vOffset, paint); |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 1601 | break; |
| 1602 | } |
| 1603 | case 49: { |
| 1604 | SkMatrix matrix; |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 1605 | bool useMatrix = make_fuzz_t<bool>(fuzz); |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 1606 | if (useMatrix) { |
| 1607 | fuzz->next(&matrix); |
| 1608 | } |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 1609 | fuzz_paint(fuzz, &paint, depth - 1); |
| 1610 | fuzz_paint_text(fuzz, &paint); |
Hal Canary | 5395c59 | 2017-03-08 16:52:18 -0500 | [diff] [blame] | 1611 | fuzz_paint_text_encoding(fuzz, &paint); |
| 1612 | SkTDArray<uint8_t> text = make_fuzz_text(fuzz, paint); |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 1613 | SkPath path; |
Cary Clark | 91390c8 | 2018-03-09 14:02:46 -0500 | [diff] [blame] | 1614 | FuzzPath(fuzz, &path, 20); |
Hal Canary | 671e442 | 2017-02-27 13:36:38 -0500 | [diff] [blame] | 1615 | canvas->drawTextOnPath(text.begin(), SkToSizeT(text.count()), path, |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 1616 | useMatrix ? &matrix : nullptr, paint); |
| 1617 | break; |
| 1618 | } |
| 1619 | case 50: { |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 1620 | fuzz_paint(fuzz, &paint, depth - 1); |
| 1621 | fuzz_paint_text(fuzz, &paint); |
Hal Canary | 5395c59 | 2017-03-08 16:52:18 -0500 | [diff] [blame] | 1622 | fuzz_paint_text_encoding(fuzz, &paint); |
| 1623 | SkTDArray<uint8_t> text = make_fuzz_text(fuzz, paint); |
| 1624 | SkRSXform rSXform[kMaxGlyphCount]; |
| 1625 | int glyphCount = paint.countText(text.begin(), SkToSizeT(text.count())); |
| 1626 | SkASSERT(glyphCount <= kMaxGlyphCount); |
| 1627 | fuzz->nextN(rSXform, glyphCount); |
| 1628 | SkRect cullRect; |
| 1629 | bool useCullRect; |
| 1630 | fuzz->next(&useCullRect); |
| 1631 | if (useCullRect) { |
| 1632 | fuzz->next(&cullRect); |
| 1633 | } |
| 1634 | canvas->drawTextRSXform(text.begin(), SkToSizeT(text.count()), rSXform, |
| 1635 | useCullRect ? &cullRect : nullptr, paint); |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 1636 | break; |
| 1637 | } |
| 1638 | case 51: { |
Hal Canary | 5395c59 | 2017-03-08 16:52:18 -0500 | [diff] [blame] | 1639 | sk_sp<SkTextBlob> blob = make_fuzz_textblob(fuzz); |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 1640 | fuzz_paint(fuzz, &paint, depth - 1); |
Hal Canary | 5395c59 | 2017-03-08 16:52:18 -0500 | [diff] [blame] | 1641 | SkScalar x, y; |
| 1642 | fuzz->next(&x, &y); |
| 1643 | canvas->drawTextBlob(blob, x, y, paint); |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 1644 | break; |
| 1645 | } |
| 1646 | case 52: { |
| 1647 | bool usePaint, useMatrix; |
| 1648 | fuzz->next(&usePaint, &useMatrix); |
| 1649 | if (usePaint) { |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 1650 | fuzz_paint(fuzz, &paint, depth - 1); |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 1651 | } |
| 1652 | if (useMatrix) { |
| 1653 | fuzz->next(&matrix); |
| 1654 | } |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 1655 | auto pic = make_fuzz_picture(fuzz, depth - 1); |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 1656 | canvas->drawPicture(pic, useMatrix ? &matrix : nullptr, |
| 1657 | usePaint ? &paint : nullptr); |
| 1658 | break; |
| 1659 | } |
| 1660 | case 53: { |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 1661 | fuzz_paint(fuzz, &paint, depth - 1); |
Mike Reed | 887cdf1 | 2017-04-03 11:11:09 -0400 | [diff] [blame] | 1662 | SkVertices::VertexMode vertexMode; |
Hal Canary | 5af600e | 2017-03-09 14:10:36 -0500 | [diff] [blame] | 1663 | SkBlendMode blendMode; |
Mike Reed | 887cdf1 | 2017-04-03 11:11:09 -0400 | [diff] [blame] | 1664 | fuzz_enum_range(fuzz, &vertexMode, 0, SkVertices::kTriangleFan_VertexMode); |
Hal Canary | 5af600e | 2017-03-09 14:10:36 -0500 | [diff] [blame] | 1665 | fuzz->next(&blendMode); |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 1666 | constexpr int kMaxCount = 100; |
| 1667 | int vertexCount; |
| 1668 | SkPoint vertices[kMaxCount]; |
| 1669 | SkPoint texs[kMaxCount]; |
| 1670 | SkColor colors[kMaxCount]; |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 1671 | fuzz->nextRange(&vertexCount, 3, kMaxCount); |
| 1672 | fuzz->nextN(vertices, vertexCount); |
| 1673 | bool useTexs, useColors; |
| 1674 | fuzz->next(&useTexs, &useColors); |
| 1675 | if (useTexs) { |
| 1676 | fuzz->nextN(texs, vertexCount); |
| 1677 | } |
| 1678 | if (useColors) { |
| 1679 | fuzz->nextN(colors, vertexCount); |
| 1680 | } |
| 1681 | int indexCount = 0; |
Hal Canary | 68b9b57 | 2017-03-02 15:27:23 -0500 | [diff] [blame] | 1682 | uint16_t indices[kMaxCount * 2]; |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 1683 | if (make_fuzz_t<bool>(fuzz)) { |
Hal Canary | 68b9b57 | 2017-03-02 15:27:23 -0500 | [diff] [blame] | 1684 | fuzz->nextRange(&indexCount, vertexCount, vertexCount + kMaxCount); |
| 1685 | for (int i = 0; i < indexCount; ++i) { |
| 1686 | fuzz->nextRange(&indices[i], 0, vertexCount - 1); |
| 1687 | } |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 1688 | } |
Mike Reed | 887cdf1 | 2017-04-03 11:11:09 -0400 | [diff] [blame] | 1689 | canvas->drawVertices(SkVertices::MakeCopy(vertexMode, vertexCount, vertices, |
| 1690 | useTexs ? texs : nullptr, |
| 1691 | useColors ? colors : nullptr, |
| 1692 | indexCount, indices), |
| 1693 | blendMode, paint); |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 1694 | break; |
| 1695 | } |
| 1696 | default: |
Kevin Lubick | 54f20e0 | 2018-01-11 14:50:21 -0500 | [diff] [blame] | 1697 | SkASSERT(false); |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 1698 | break; |
| 1699 | } |
| 1700 | } |
| 1701 | } |
| 1702 | |
Hal Canary | 1e0138b | 2017-03-10 13:56:08 -0500 | [diff] [blame] | 1703 | static sk_sp<SkPicture> make_fuzz_picture(Fuzz* fuzz, int depth) { |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 1704 | SkScalar w, h; |
| 1705 | fuzz->next(&w, &h); |
| 1706 | SkPictureRecorder pictureRecorder; |
| 1707 | fuzz_canvas(fuzz, pictureRecorder.beginRecording(w, h), depth - 1); |
| 1708 | return pictureRecorder.finishRecordingAsPicture(); |
| 1709 | } |
| 1710 | |
Kevin Lubick | 1ac8fd2 | 2017-03-01 10:42:45 -0500 | [diff] [blame] | 1711 | DEF_FUZZ(NullCanvas, fuzz) { |
| 1712 | fuzz_canvas(fuzz, SkMakeNullCanvas().get()); |
Hal Canary | 24ac42b | 2017-02-14 13:35:14 -0500 | [diff] [blame] | 1713 | } |
| 1714 | |
Kevin Lubick | 486ee3d | 2018-03-21 10:17:25 -0400 | [diff] [blame] | 1715 | constexpr SkISize kCanvasSize = {128, 160}; |
Hal Canary | 44801ca | 2017-03-15 11:39:06 -0400 | [diff] [blame] | 1716 | |
Kevin Lubick | 1ac8fd2 | 2017-03-01 10:42:45 -0500 | [diff] [blame] | 1717 | DEF_FUZZ(RasterN32Canvas, fuzz) { |
Hal Canary | 44801ca | 2017-03-15 11:39:06 -0400 | [diff] [blame] | 1718 | auto surface = SkSurface::MakeRasterN32Premul(kCanvasSize.width(), kCanvasSize.height()); |
Kevin Lubick | 486ee3d | 2018-03-21 10:17:25 -0400 | [diff] [blame] | 1719 | if (!surface || !surface->getCanvas()) { fuzz->signalBug(); } |
Kevin Lubick | 1ac8fd2 | 2017-03-01 10:42:45 -0500 | [diff] [blame] | 1720 | fuzz_canvas(fuzz, surface->getCanvas()); |
| 1721 | } |
| 1722 | |
Hal Canary | e292443 | 2017-12-01 11:46:26 -0500 | [diff] [blame] | 1723 | DEF_FUZZ(RasterN32CanvasViaSerialization, fuzz) { |
| 1724 | SkPictureRecorder recorder; |
| 1725 | fuzz_canvas(fuzz, recorder.beginRecording(SkIntToScalar(kCanvasSize.width()), |
| 1726 | SkIntToScalar(kCanvasSize.height()))); |
| 1727 | sk_sp<SkPicture> pic(recorder.finishRecordingAsPicture()); |
| 1728 | if (!pic) { fuzz->signalBug(); } |
| 1729 | sk_sp<SkData> data = pic->serialize(); |
| 1730 | if (!data) { fuzz->signalBug(); } |
Mike Reed | fadbfcd | 2017-12-06 16:09:20 -0500 | [diff] [blame] | 1731 | SkReadBuffer rb(data->data(), data->size()); |
Cary Clark | efd99cc | 2018-06-11 16:25:43 -0400 | [diff] [blame] | 1732 | auto deserialized = SkPicturePriv::MakeFromBuffer(rb); |
Hal Canary | e292443 | 2017-12-01 11:46:26 -0500 | [diff] [blame] | 1733 | if (!deserialized) { fuzz->signalBug(); } |
| 1734 | auto surface = SkSurface::MakeRasterN32Premul(kCanvasSize.width(), kCanvasSize.height()); |
| 1735 | SkASSERT(surface && surface->getCanvas()); |
| 1736 | surface->getCanvas()->drawPicture(deserialized); |
| 1737 | } |
| 1738 | |
Kevin Lubick | edef8ec | 2018-01-09 15:32:58 -0500 | [diff] [blame] | 1739 | DEF_FUZZ(ImageFilter, fuzz) { |
| 1740 | auto fil = make_fuzz_imageFilter(fuzz, 20); |
| 1741 | |
| 1742 | SkPaint paint; |
| 1743 | paint.setImageFilter(fil); |
| 1744 | SkBitmap bitmap; |
| 1745 | SkCanvas canvas(bitmap); |
| 1746 | canvas.saveLayer(SkRect::MakeWH(500, 500), &paint); |
| 1747 | } |
| 1748 | |
| 1749 | |
| 1750 | //SkRandom _rand; |
| 1751 | #define SK_ADD_RANDOM_BIT_FLIPS |
| 1752 | |
| 1753 | DEF_FUZZ(SerializedImageFilter, fuzz) { |
| 1754 | auto filter = make_fuzz_imageFilter(fuzz, 20); |
| 1755 | auto data = filter->serialize(); |
| 1756 | const unsigned char* ptr = static_cast<const unsigned char*>(data->data()); |
| 1757 | size_t len = data->size(); |
| 1758 | #ifdef SK_ADD_RANDOM_BIT_FLIPS |
| 1759 | unsigned char* p = const_cast<unsigned char*>(ptr); |
| 1760 | for (size_t i = 0; i < len; ++i, ++p) { |
| 1761 | uint8_t j; |
| 1762 | fuzz->nextRange(&j, 1, 250); |
| 1763 | if (j == 1) { // 0.4% of the time, flip a bit or byte |
| 1764 | uint8_t k; |
| 1765 | fuzz->nextRange(&k, 1, 10); |
| 1766 | if (k == 1) { // Then 10% of the time, change a whole byte |
| 1767 | uint8_t s; |
| 1768 | fuzz->nextRange(&s, 0, 2); |
| 1769 | switch(s) { |
| 1770 | case 0: |
| 1771 | *p ^= 0xFF; // Flip entire byte |
| 1772 | break; |
| 1773 | case 1: |
| 1774 | *p = 0xFF; // Set all bits to 1 |
| 1775 | break; |
| 1776 | case 2: |
| 1777 | *p = 0x00; // Set all bits to 0 |
| 1778 | break; |
| 1779 | } |
| 1780 | } else { |
| 1781 | uint8_t s; |
| 1782 | fuzz->nextRange(&s, 0, 7); |
| 1783 | *p ^= (1 << 7); |
| 1784 | } |
| 1785 | } |
| 1786 | } |
| 1787 | #endif // SK_ADD_RANDOM_BIT_FLIPS |
| 1788 | auto deserializedFil = SkImageFilter::Deserialize(ptr, len); |
| 1789 | |
| 1790 | // uncomment below to write out a serialized image filter (to make corpus |
| 1791 | // for -t filter_fuzz) |
| 1792 | // SkString s("./serialized_filters/sf"); |
| 1793 | // s.appendU32(_rand.nextU()); |
| 1794 | // auto file = sk_fopen(s.c_str(), SkFILE_Flags::kWrite_SkFILE_Flag); |
| 1795 | // sk_fwrite(data->bytes(), data->size(), file); |
| 1796 | // sk_fclose(file); |
| 1797 | |
| 1798 | SkPaint paint; |
| 1799 | paint.setImageFilter(deserializedFil); |
| 1800 | SkBitmap bitmap; |
| 1801 | SkCanvas canvas(bitmap); |
| 1802 | canvas.saveLayer(SkRect::MakeWH(500, 500), &paint); |
| 1803 | } |
| 1804 | |
Hal Canary | 44801ca | 2017-03-15 11:39:06 -0400 | [diff] [blame] | 1805 | #if SK_SUPPORT_GPU |
Kevin Lubick | faef514 | 2018-06-07 10:33:11 -0400 | [diff] [blame] | 1806 | |
| 1807 | static void dump_GPU_info(GrContext* context) { |
| 1808 | const GrGLInterface* gl = static_cast<GrGLGpu*>(context->contextPriv().getGpu()) |
| 1809 | ->glInterface(); |
| 1810 | const GrGLubyte* output; |
| 1811 | GR_GL_CALL_RET(gl, output, GetString(GR_GL_RENDERER)); |
| 1812 | SkDebugf("GL_RENDERER %s\n", (const char*) output); |
| 1813 | |
| 1814 | GR_GL_CALL_RET(gl, output, GetString(GR_GL_VENDOR)); |
| 1815 | SkDebugf("GL_VENDOR %s\n", (const char*) output); |
| 1816 | |
| 1817 | GR_GL_CALL_RET(gl, output, GetString(GR_GL_VERSION)); |
| 1818 | SkDebugf("GL_VERSION %s\n", (const char*) output); |
| 1819 | } |
| 1820 | |
Hal Canary | 5aa9158 | 2017-03-21 11:11:44 -0700 | [diff] [blame] | 1821 | static void fuzz_ganesh(Fuzz* fuzz, GrContext* context) { |
| 1822 | SkASSERT(context); |
| 1823 | auto surface = SkSurface::MakeRenderTarget( |
| 1824 | context, |
| 1825 | SkBudgeted::kNo, |
| 1826 | SkImageInfo::Make(kCanvasSize.width(), kCanvasSize.height(), kRGBA_8888_SkColorType, kPremul_SkAlphaType)); |
| 1827 | SkASSERT(surface && surface->getCanvas()); |
| 1828 | fuzz_canvas(fuzz, surface->getCanvas()); |
| 1829 | } |
| 1830 | |
Hal Canary | 44801ca | 2017-03-15 11:39:06 -0400 | [diff] [blame] | 1831 | DEF_FUZZ(NativeGLCanvas, fuzz) { |
Hal Canary | 549be4a | 2018-01-05 16:59:53 -0500 | [diff] [blame] | 1832 | sk_gpu_test::GrContextFactory f; |
| 1833 | GrContext* context = f.get(sk_gpu_test::GrContextFactory::kGL_ContextType); |
Brian Salomon | 6405e71 | 2017-03-20 08:54:16 -0400 | [diff] [blame] | 1834 | if (!context) { |
Hal Canary | 549be4a | 2018-01-05 16:59:53 -0500 | [diff] [blame] | 1835 | context = f.get(sk_gpu_test::GrContextFactory::kGLES_ContextType); |
Brian Salomon | 6405e71 | 2017-03-20 08:54:16 -0400 | [diff] [blame] | 1836 | } |
Kevin Lubick | fe6b489 | 2018-06-05 17:21:30 -0400 | [diff] [blame] | 1837 | if (FLAGS_gpuInfo) { |
Kevin Lubick | faef514 | 2018-06-07 10:33:11 -0400 | [diff] [blame] | 1838 | dump_GPU_info(context); |
Kevin Lubick | fe6b489 | 2018-06-05 17:21:30 -0400 | [diff] [blame] | 1839 | } |
Hal Canary | 5aa9158 | 2017-03-21 11:11:44 -0700 | [diff] [blame] | 1840 | fuzz_ganesh(fuzz, context); |
| 1841 | } |
| 1842 | |
Kevin Lubick | 27d4219 | 2018-04-03 12:30:32 -0400 | [diff] [blame] | 1843 | // This target is deprecated, NullGLContext is not well maintained. |
| 1844 | // Please use MockGPUCanvas instead. |
Hal Canary | 5aa9158 | 2017-03-21 11:11:44 -0700 | [diff] [blame] | 1845 | DEF_FUZZ(NullGLCanvas, fuzz) { |
Hal Canary | 549be4a | 2018-01-05 16:59:53 -0500 | [diff] [blame] | 1846 | sk_gpu_test::GrContextFactory f; |
| 1847 | fuzz_ganesh(fuzz, f.get(sk_gpu_test::GrContextFactory::kNullGL_ContextType)); |
Hal Canary | 5aa9158 | 2017-03-21 11:11:44 -0700 | [diff] [blame] | 1848 | } |
| 1849 | |
Kevin Lubick | 27d4219 | 2018-04-03 12:30:32 -0400 | [diff] [blame] | 1850 | DEF_FUZZ(MockGPUCanvas, fuzz) { |
Kevin Lubick | 3070926 | 2018-04-02 11:06:41 -0400 | [diff] [blame] | 1851 | sk_gpu_test::GrContextFactory f; |
| 1852 | fuzz_ganesh(fuzz, f.get(sk_gpu_test::GrContextFactory::kMock_ContextType)); |
| 1853 | } |
Hal Canary | 44801ca | 2017-03-15 11:39:06 -0400 | [diff] [blame] | 1854 | #endif |
| 1855 | |
Kevin Lubick | 1ac8fd2 | 2017-03-01 10:42:45 -0500 | [diff] [blame] | 1856 | DEF_FUZZ(PDFCanvas, fuzz) { |
Hal Canary | fe75930 | 2017-08-26 17:06:42 -0400 | [diff] [blame] | 1857 | SkNullWStream stream; |
Kevin Lubick | 1ac8fd2 | 2017-03-01 10:42:45 -0500 | [diff] [blame] | 1858 | auto doc = SkDocument::MakePDF(&stream); |
Hal Canary | 44801ca | 2017-03-15 11:39:06 -0400 | [diff] [blame] | 1859 | fuzz_canvas(fuzz, doc->beginPage(SkIntToScalar(kCanvasSize.width()), |
| 1860 | SkIntToScalar(kCanvasSize.height()))); |
Kevin Lubick | 1ac8fd2 | 2017-03-01 10:42:45 -0500 | [diff] [blame] | 1861 | } |
| 1862 | |
| 1863 | // not a "real" thing to fuzz, used to debug errors found while fuzzing. |
| 1864 | DEF_FUZZ(_DumpCanvas, fuzz) { |
Hal Canary | 44801ca | 2017-03-15 11:39:06 -0400 | [diff] [blame] | 1865 | SkDebugCanvas debugCanvas(kCanvasSize.width(), kCanvasSize.height()); |
Kevin Lubick | 1ac8fd2 | 2017-03-01 10:42:45 -0500 | [diff] [blame] | 1866 | fuzz_canvas(fuzz, &debugCanvas); |
| 1867 | std::unique_ptr<SkCanvas> nullCanvas = SkMakeNullCanvas(); |
| 1868 | UrlDataManager dataManager(SkString("data")); |
| 1869 | Json::Value json = debugCanvas.toJSON(dataManager, debugCanvas.getSize(), nullCanvas.get()); |
| 1870 | Json::StyledStreamWriter(" ").write(std::cout, json); |
| 1871 | } |