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