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