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