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