Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Functions | Variables
FuzzGradients.cpp File Reference
#include "fuzz/Fuzz.h"
#include "include/core/SkCanvas.h"
#include "include/core/SkSurface.h"
#include "include/effects/SkGradientShader.h"
#include "src/base/SkTLazy.h"
#include "src/core/SkDebugUtils.h"
#include "tools/flags/CommandLineFlags.h"
#include <algorithm>
#include <vector>

Go to the source code of this file.

Functions

static DEFINE_bool2 (verbose, v, false, "log verbose linear gradient description")
 
void makeMatrix (Fuzz *fuzz, SkMatrix *m)
 
void initGradientParams (Fuzz *fuzz, std::vector< SkColor > *colors, std::vector< SkScalar > *pos, SkTileMode *mode)
 
static void logOptionalMatrix (const char *label, const SkMatrix *m)
 
static void logLinearGradient (const SkPoint pts[2], const std::vector< SkColor > &colors, const std::vector< SkScalar > &pos, SkTileMode mode, uint32_t flags, const SkMatrix *localMatrix, const SkMatrix *globalMatrix)
 
void fuzzLinearGradient (Fuzz *fuzz)
 
void fuzzRadialGradient (Fuzz *fuzz)
 
void fuzzTwoPointConicalGradient (Fuzz *fuzz)
 
void fuzzSweepGradient (Fuzz *fuzz)
 
 DEF_FUZZ (Gradients, fuzz)
 

Variables

const int MAX_COUNT = 400
 

Function Documentation

◆ DEF_FUZZ()

DEF_FUZZ ( Gradients  ,
fuzz   
)

Definition at line 251 of file FuzzGradients.cpp.

251 {
252 uint8_t i;
253 fuzz->next(&i);
254
255 switch(i) {
256 case 0:
257 SkDEBUGF("LinearGradient\n");
258 fuzzLinearGradient(fuzz);
259 return;
260 case 1:
261 SkDEBUGF("RadialGradient\n");
262 fuzzRadialGradient(fuzz);
263 return;
264 case 2:
265 SkDEBUGF("TwoPointConicalGradient\n");
267 return;
268 }
269 SkDEBUGF("SweepGradient\n");
270 fuzzSweepGradient(fuzz);
271 return;
272}
void fuzzLinearGradient(Fuzz *fuzz)
void fuzzTwoPointConicalGradient(Fuzz *fuzz)
void fuzzRadialGradient(Fuzz *fuzz)
void fuzzSweepGradient(Fuzz *fuzz)
#define SkDEBUGF(...)
Definition SkDebug.h:24

◆ DEFINE_bool2()

static DEFINE_bool2 ( verbose  ,
,
false  ,
"log verbose linear gradient description"   
)
static

◆ fuzzLinearGradient()

void fuzzLinearGradient ( Fuzz fuzz)

Definition at line 105 of file FuzzGradients.cpp.

105 {
106 SkPoint pts[2];
107 fuzz->next(&pts[0].fX, &pts[0].fY, &pts[1].fX, &pts[1].fY);
108 bool useLocalMatrix, useGlobalMatrix;
109 fuzz->next(&useLocalMatrix, &useGlobalMatrix);
110
111 std::vector<SkColor> colors;
112 std::vector<SkScalar> pos;
114 initGradientParams(fuzz, &colors, &pos, &mode);
115
116 SkPaint p;
117 uint32_t flags;
118 fuzz->next(&flags);
119
120 SkTLazy<SkMatrix> localMatrix;
121 if (useLocalMatrix) {
122 makeMatrix(fuzz, localMatrix.init());
123 }
124 p.setShader(SkGradientShader::MakeLinear(pts, colors.data(), pos.data(),
125 colors.size(), mode, flags, localMatrix.getMaybeNull()));
126
128 if (useGlobalMatrix) {
129 SkMatrix gm;
130 makeMatrix(fuzz, &gm);
131 logLinearGradient(pts, colors, pos, mode, flags, localMatrix.getMaybeNull(), &gm);
132 SkCanvas* c = surface->getCanvas();
133 c->setMatrix(gm);
134 c->drawPaint(p);
135 } else {
136 logLinearGradient(pts, colors, pos, mode, flags, localMatrix.getMaybeNull(), nullptr);
137 surface->getCanvas()->drawPaint(p);
138 }
139}
static void logLinearGradient(const SkPoint pts[2], const std::vector< SkColor > &colors, const std::vector< SkScalar > &pos, SkTileMode mode, uint32_t flags, const SkMatrix *localMatrix, const SkMatrix *globalMatrix)
void initGradientParams(Fuzz *fuzz, std::vector< SkColor > *colors, std::vector< SkScalar > *pos, SkTileMode *mode)
void makeMatrix(Fuzz *fuzz, SkMatrix *m)
SkPoint pos
SkTileMode
Definition SkTileMode.h:13
void next(T *t)
Definition Fuzz.h:64
void drawPaint(const SkPaint &paint)
void setMatrix(const SkM44 &matrix)
static sk_sp< SkShader > MakeLinear(const SkPoint pts[2], const SkColor colors[], const SkScalar pos[], int count, SkTileMode mode, uint32_t flags=0, const SkMatrix *localMatrix=nullptr)
T * init(Args &&... args)
Definition SkTLazy.h:45
const T * getMaybeNull() const
Definition SkTLazy.h:108
VkSurfaceKHR surface
Definition main.cc:49
FlutterSemanticsFlag flags
PODArray< SkColor > colors
Definition SkRecords.h:276
SK_API sk_sp< SkSurface > Raster(const SkImageInfo &imageInfo, size_t rowBytes, const SkSurfaceProps *surfaceProps)
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive mode
Definition switches.h:228
static SkImageInfo MakeN32Premul(int width, int height)

◆ fuzzRadialGradient()

void fuzzRadialGradient ( Fuzz fuzz)

Definition at line 141 of file FuzzGradients.cpp.

141 {
143 fuzz->next(&center.fX, &center.fY);
144 SkScalar radius;
145 bool useLocalMatrix, useGlobalMatrix;
146 fuzz->next(&radius, &useLocalMatrix, &useGlobalMatrix);
147
148
149 std::vector<SkColor> colors;
150 std::vector<SkScalar> pos;
152 initGradientParams(fuzz, &colors, &pos, &mode);
153
154 SkPaint p;
155 uint32_t flags;
156 fuzz->next(&flags);
157
158 SkTLazy<SkMatrix> localMatrix;
159 if (useLocalMatrix) {
160 makeMatrix(fuzz, localMatrix.init());
161 }
162 p.setShader(SkGradientShader::MakeRadial(center, radius, colors.data(),
163 pos.data(), colors.size(), mode, flags, localMatrix.getMaybeNull()));
164
166 if (useGlobalMatrix) {
167 SkMatrix gm;
168 makeMatrix(fuzz, &gm);
169 SkCanvas* c = surface->getCanvas();
170 c->setMatrix(gm);
171 c->drawPaint(p);
172 } else {
173 surface->getCanvas()->drawPaint(p);
174 }
175}
static SkScalar center(float pos0, float pos1)
static sk_sp< SkShader > MakeRadial(const SkPoint &center, SkScalar radius, const SkColor colors[], const SkScalar pos[], int count, SkTileMode mode, uint32_t flags=0, const SkMatrix *localMatrix=nullptr)
float SkScalar
Definition extension.cpp:12

◆ fuzzSweepGradient()

void fuzzSweepGradient ( Fuzz fuzz)

Definition at line 215 of file FuzzGradients.cpp.

215 {
216 SkScalar cx, cy;
217 bool useLocalMatrix, useGlobalMatrix;
218 fuzz->next(&cx, &cy, &useLocalMatrix, &useGlobalMatrix);
219
220 std::vector<SkColor> colors;
221 std::vector<SkScalar> pos;
223 initGradientParams(fuzz, &colors, &pos, &mode);
224
225 SkPaint p;
226 if (useLocalMatrix) {
227 SkMatrix m;
228 makeMatrix(fuzz, &m);
229 uint32_t flags;
230 fuzz->next(&flags);
231
232 p.setShader(SkGradientShader::MakeSweep(cx, cy, colors.data(),
233 pos.data(), colors.size(), flags, &m));
234 } else {
235 p.setShader(SkGradientShader::MakeSweep(cx, cy, colors.data(),
236 pos.data(), colors.size()));
237 }
238
240 if (useGlobalMatrix) {
241 SkMatrix gm;
242 makeMatrix(fuzz, &gm);
243 SkCanvas* c = surface->getCanvas();
244 c->setMatrix(gm);
245 c->drawPaint(p);
246 } else {
247 surface->getCanvas()->drawPaint(p);
248 }
249}
static sk_sp< SkShader > MakeSweep(SkScalar cx, SkScalar cy, const SkColor colors[], const SkScalar pos[], int count, SkTileMode mode, SkScalar startAngle, SkScalar endAngle, uint32_t flags, const SkMatrix *localMatrix)

◆ fuzzTwoPointConicalGradient()

void fuzzTwoPointConicalGradient ( Fuzz fuzz)

Definition at line 177 of file FuzzGradients.cpp.

177 {
179 fuzz->next(&start.fX, &start.fY);
180 SkPoint end;
181 fuzz->next(&end.fX, &end.fY);
182 SkScalar startRadius, endRadius;
183 bool useLocalMatrix, useGlobalMatrix;
184 fuzz->next(&startRadius, &endRadius, &useLocalMatrix, &useGlobalMatrix);
185
186 std::vector<SkColor> colors;
187 std::vector<SkScalar> pos;
189 initGradientParams(fuzz, &colors, &pos, &mode);
190
191 SkPaint p;
192 uint32_t flags;
193 fuzz->next(&flags);
194
195 SkTLazy<SkMatrix> localMatrix;
196 if (useLocalMatrix) {
197 makeMatrix(fuzz, localMatrix.init());
198 }
199 p.setShader(SkGradientShader::MakeTwoPointConical(start, startRadius,
200 end, endRadius, colors.data(), pos.data(), colors.size(), mode,
201 flags, localMatrix.getMaybeNull()));
202
204 if (useGlobalMatrix) {
205 SkMatrix gm;
206 makeMatrix(fuzz, &gm);
207 SkCanvas* c = surface->getCanvas();
208 c->setMatrix(gm);
209 c->drawPaint(p);
210 } else {
211 surface->getCanvas()->drawPaint(p);
212 }
213}
static sk_sp< SkShader > MakeTwoPointConical(const SkPoint &start, SkScalar startRadius, const SkPoint &end, SkScalar endRadius, const SkColor colors[], const SkScalar pos[], int count, SkTileMode mode, uint32_t flags=0, const SkMatrix *localMatrix=nullptr)
glong glong end

◆ initGradientParams()

void initGradientParams ( Fuzz fuzz,
std::vector< SkColor > *  colors,
std::vector< SkScalar > *  pos,
SkTileMode mode 
)

Definition at line 29 of file FuzzGradients.cpp.

30 {
31 int count;
32 fuzz->nextRange(&count, 0, MAX_COUNT);
33
34 // Use a uint8_t to conserve bytes. This makes our "fuzzed bytes footprint"
35 // smaller, which leads to more efficient fuzzing.
36 uint8_t m;
37 fuzz->nextRange(&m, 0, 2);
38 *mode = static_cast<SkTileMode>(m);
39
40 colors->clear();
41 pos ->clear();
42 for (int i = 0; i < count; i++) {
43 SkColor c;
44 SkScalar s;
45 fuzz->next(&c, &s);
46 colors->push_back(c);
47 pos ->push_back(s);
48 }
49 if (count) {
50 std::sort(pos->begin(), pos->end());
51 // The order matters. If count == 1, we want pos == 0.
52 (*pos)[count - 1] = 1;
53 (*pos)[0] = 0;
54 }
55}
int count
const int MAX_COUNT
uint32_t SkColor
Definition SkColor.h:37
void nextRange(T *, Min, Max)
Definition Fuzz.h:119
struct MyStruct s

◆ logLinearGradient()

static void logLinearGradient ( const SkPoint  pts[2],
const std::vector< SkColor > &  colors,
const std::vector< SkScalar > &  pos,
SkTileMode  mode,
uint32_t  flags,
const SkMatrix localMatrix,
const SkMatrix globalMatrix 
)
static

Definition at line 69 of file FuzzGradients.cpp.

75 {
76 if (!FLAGS_verbose) {
77 return;
78 }
79
80 SkDebugf("--- fuzzLinearGradient ---\n");
81 SkDebugf(" pts:\t\t[ (%.9g %.9g) (%.9g %.9g) ]\n",
82 pts[0].x(), pts[0].y(), pts[1].x(), pts[1].y());
83 SkDebugf(" colors:\t[ ");
84 for (auto color : colors) {
85 SkDebugf("0x%x ", color);
86 }
87
88 SkDebugf("]\n pos:\t\t");
89 if (pos.empty()) {
90 SkDebugf("nullptr");
91 } else {
92 SkDebugf("[ ");
93 for (auto p : pos) {
94 SkDebugf("%f ", p);
95 }
96 }
97 SkDebugf("]\n");
98
99 SkDebugf(" mode:\t\t%s\n", SkTileModeToStr(mode));
100 SkDebugf(" flags:\t0x%x\n", flags);
101 logOptionalMatrix("local matrix", localMatrix);
102 logOptionalMatrix("global matrix", globalMatrix);
103}
static void logOptionalMatrix(const char *label, const SkMatrix *m)
SkColor4f color
static constexpr const char * SkTileModeToStr(SkTileMode tm)
void SK_SPI SkDebugf(const char format[],...) SK_PRINTF_LIKE(1
double y
double x

◆ logOptionalMatrix()

static void logOptionalMatrix ( const char *  label,
const SkMatrix m 
)
static

Definition at line 57 of file FuzzGradients.cpp.

57 {
58 if (!m) {
59 return;
60 }
61
62 SkDEBUGF(" %s: [ ", label);
63 for (int i = 0; i < 9; ++i) {
64 SkDEBUGF("%.9g ", m->get(i));
65 }
66 SkDEBUGF("]\n");
67}

◆ makeMatrix()

void makeMatrix ( Fuzz fuzz,
SkMatrix m 
)

Definition at line 23 of file FuzzGradients.cpp.

23 {
24 SkScalar mat[9];
25 fuzz->nextN(mat, 9);
26 m->set9(mat);
27}
void nextN(T *ptr, int n)
Definition Fuzz.h:144

Variable Documentation

◆ MAX_COUNT

const int MAX_COUNT = 400

Definition at line 21 of file FuzzGradients.cpp.