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