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