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