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