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