Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Functions | Variables
FuzzDrawFunctions.cpp File Reference
#include "fuzz/Fuzz.h"
#include "include/core/SkBitmap.h"
#include "include/core/SkCanvas.h"
#include "include/core/SkFont.h"
#include "include/core/SkImage.h"
#include "include/core/SkPath.h"
#include "include/core/SkSurface.h"
#include "include/core/SkTextBlob.h"
#include "include/core/SkTypeface.h"
#include "src/core/SkPaintPriv.h"
#include "tools/fonts/FontToolUtils.h"

Go to the source code of this file.

Functions

static void init_string (Fuzz *fuzz, char *str, size_t bufSize)
 
static void init_paint (Fuzz *fuzz, SkPaint *p)
 
static void init_bitmap (Fuzz *fuzz, SkBitmap *bmp)
 
static void init_surface (Fuzz *fuzz, sk_sp< SkSurface > *s)
 
static void fuzz_drawText (Fuzz *fuzz, sk_sp< SkTypeface > typeface)
 
static void fuzz_drawCircle (Fuzz *fuzz)
 
static void fuzz_drawLine (Fuzz *fuzz)
 
static void fuzz_drawRect (Fuzz *fuzz)
 
static void fuzz_drawPath (Fuzz *fuzz)
 
static void fuzz_drawImage (Fuzz *fuzz)
 
static void fuzz_drawPaint (Fuzz *fuzz)
 
 DEF_FUZZ (DrawFunctions, fuzz)
 

Variables

static const int kBmpSize = 24
 
static const int kMaxX = 250
 
static const int kMaxY = 250
 
static const int kPtsLen = 10
 
static const int kTxtLen = 5
 

Function Documentation

◆ DEF_FUZZ()

DEF_FUZZ ( DrawFunctions  ,
fuzz   
)

Definition at line 287 of file FuzzDrawFunctions.cpp.

287 {
288 uint8_t i;
289 fuzz->next(&i);
290
291 switch(i) {
292 case 0: {
294 if (f == nullptr) {
295 SkDebugf("Could not initialize font.\n");
296 fuzz->signalBug();
297 }
298 SkDEBUGF("Fuzz DrawText\n");
299 fuzz_drawText(fuzz, f);
300 return;
301 }
302 case 1:
303 SkDEBUGF("Fuzz DrawRect\n");
304 fuzz_drawRect(fuzz);
305 return;
306 case 2:
307 SkDEBUGF("Fuzz DrawCircle\n");
308 fuzz_drawCircle(fuzz);
309 return;
310 case 3:
311 SkDEBUGF("Fuzz DrawLine\n");
312 fuzz_drawLine(fuzz);
313 return;
314 case 4:
315 SkDEBUGF("Fuzz DrawPath\n");
316 fuzz_drawPath(fuzz);
317 return;
318 case 5:
319 SkDEBUGF("Fuzz DrawImage/DrawImageRect\n");
320 fuzz_drawImage(fuzz);
321 return;
322 case 6:
323 SkDEBUGF("Fuzz DrawPaint\n");
324 fuzz_drawPaint(fuzz);
325 return;
326 }
327}
static void fuzz_drawPaint(Fuzz *fuzz)
static void fuzz_drawRect(Fuzz *fuzz)
static void fuzz_drawImage(Fuzz *fuzz)
static void fuzz_drawCircle(Fuzz *fuzz)
static void fuzz_drawText(Fuzz *fuzz, sk_sp< SkTypeface > typeface)
static void fuzz_drawPath(Fuzz *fuzz)
static void fuzz_drawLine(Fuzz *fuzz)
void SK_SPI SkDebugf(const char format[],...) SK_PRINTF_LIKE(1
#define SkDEBUGF(...)
Definition SkDebug.h:24
sk_sp< SkTypeface > DefaultPortableTypeface()

◆ fuzz_drawCircle()

static void fuzz_drawCircle ( Fuzz fuzz)
static

Definition at line 156 of file FuzzDrawFunctions.cpp.

156 {
157 SkPaint p;
158 init_paint(fuzz, &p);
160 init_surface(fuzz, &surface);
161
162 SkScalar a, b, c;
163 fuzz->next(&a, &b, &c);
164 surface->getCanvas()->drawCircle(a, b, c, p);
165}
static void init_surface(Fuzz *fuzz, sk_sp< SkSurface > *s)
static void init_paint(Fuzz *fuzz, SkPaint *p)
void next(T *t)
Definition Fuzz.h:64
VkSurfaceKHR surface
Definition main.cc:49
float SkScalar
Definition extension.cpp:12
static bool b
struct MyStruct a[10]

◆ fuzz_drawImage()

static void fuzz_drawImage ( Fuzz fuzz)
static

Definition at line 250 of file FuzzDrawFunctions.cpp.

250 {
251 SkPaint p;
252 init_paint(fuzz, &p);
254 init_surface(fuzz, &surface);
255 SkBitmap bmp;
256 init_bitmap(fuzz, &bmp);
257
259
260 bool bl;
261 fuzz->next(&bl);
262 SkScalar a, b;
263 fuzz->next(&a, &b);
264 if (bl) {
265 surface->getCanvas()->drawImage(image, a, b, SkSamplingOptions(), &p);
266 }
267 else {
269 fuzz->next(&a, &b);
271 uint8_t x;
272 fuzz->nextRange(&x, 0, 1);
274 surface->getCanvas()->drawImageRect(image.get(), src, dst, SkSamplingOptions(), &p, cst);
275 }
276}
static void init_bitmap(Fuzz *fuzz, SkBitmap *bmp)
void nextRange(T *, Min, Max)
Definition Fuzz.h:119
sk_sp< SkImage > asImage() const
Definition SkBitmap.cpp:645
SrcRectConstraint
Definition SkCanvas.h:1541
T * get() const
Definition SkRefCnt.h:303
sk_sp< SkImage > image
Definition examples.cpp:29
double x
dst
Definition cp.py:12
static constexpr SkRect MakeWH(float w, float h)
Definition SkRect.h:609

◆ fuzz_drawLine()

static void fuzz_drawLine ( Fuzz fuzz)
static

Definition at line 167 of file FuzzDrawFunctions.cpp.

167 {
168 SkPaint p;
169 init_paint(fuzz, &p);
171 init_surface(fuzz, &surface);
172
173 SkScalar a, b, c, d;
174 fuzz->next(&a, &b, &c, &d);
175 surface->getCanvas()->drawLine(a, b, c, d, p);
176}
VULKAN_HPP_DEFAULT_DISPATCH_LOADER_DYNAMIC_STORAGE auto & d
Definition main.cc:19

◆ fuzz_drawPaint()

static void fuzz_drawPaint ( Fuzz fuzz)
static

Definition at line 278 of file FuzzDrawFunctions.cpp.

278 {
279 SkPaint l, p;
280 init_paint(fuzz, &p);
282 init_surface(fuzz, &surface);
283
284 surface->getCanvas()->drawPaint(p);
285}

◆ fuzz_drawPath()

static void fuzz_drawPath ( Fuzz fuzz)
static

Definition at line 199 of file FuzzDrawFunctions.cpp.

199 {
200 SkPaint p;
201 init_paint(fuzz, &p);
203 init_surface(fuzz, &surface);
204
205 // TODO(kjlubick): put the ability to fuzz a path in shared file, with
206 // other common things (e.g. rects, lines)
207 uint8_t i, j;
208 fuzz->nextRange(&i, 0, 10); // set i to number of operations to perform
209 SkPath path;
210 SkScalar a, b, c, d, e, f;
211 for (int k = 0; k < i; ++k) {
212 fuzz->nextRange(&j, 0, 5); // set j to choose operation to perform
213 switch (j) {
214 case 0:
215 fuzz->next(&a, &b);
216 path.moveTo(a, b);
217 break;
218 case 1:
219 fuzz->next(&a, &b);
220 path.lineTo(a, b);
221 break;
222 case 2:
223 fuzz->next(&a, &b, &c, &d);
224 path.quadTo(a, b, c, d);
225 break;
226 case 3:
227 fuzz->next(&a, &b, &c, &d, &e);
228 path.conicTo(a, b, c, d, e);
229 break;
230 case 4:
231 fuzz->next(&a, &b, &c, &d, &e, &f);
232 path.cubicTo(a, b, c, d, e, f);
233 break;
234 case 5:
235 fuzz->next(&a, &b, &c, &d, &e);
236 path.arcTo(a, b, c, d, e);
237 break;
238 }
239 }
240 path.close();
241
242 SkCanvas* cnv = surface->getCanvas();
243 cnv->drawPath(path, p);
244
245 bool bl;
246 fuzz->next(&bl);
247 cnv->clipPath(path, SkClipOp::kIntersect, bl);
248}
void clipPath(const SkPath &path, SkClipOp op, bool doAntiAlias)
void drawPath(const SkPath &path, const SkPaint &paint)
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir path
Definition switches.h:57

◆ fuzz_drawRect()

static void fuzz_drawRect ( Fuzz fuzz)
static

Definition at line 178 of file FuzzDrawFunctions.cpp.

178 {
179 SkPaint p;
180 init_paint(fuzz, &p);
182 init_surface(fuzz, &surface);
183
184 SkScalar a, b, c, d;
185 fuzz->next(&a, &b, &c, &d);
186 SkRect r;
187 r = SkRect::MakeXYWH(a, b, c, d);
188
189 SkCanvas* cnv = surface->getCanvas();
190 cnv->drawRect(r, p);
191
192 bool bl;
193 fuzz->next(&bl);
194 fuzz->next(&a, &b, &c, &d);
195 r = SkRect::MakeXYWH(a, b, c, d);
196 cnv->clipRect(r, SkClipOp::kIntersect, bl);
197}
void drawRect(const SkRect &rect, const SkPaint &paint)
void clipRect(const SkRect &rect, SkClipOp op, bool doAntiAlias)
static constexpr SkRect MakeXYWH(float x, float y, float w, float h)
Definition SkRect.h:659

◆ fuzz_drawText()

static void fuzz_drawText ( Fuzz fuzz,
sk_sp< SkTypeface typeface 
)
static

Definition at line 111 of file FuzzDrawFunctions.cpp.

111 {
112 SkFont font(std::move(typeface));
113 SkPaint p;
114 init_paint(fuzz, &p);
116 init_surface(fuzz, &surface);
117
118 char text[kTxtLen];
119 init_string(fuzz, text, kTxtLen);
120
121 SkScalar x, y;
122 fuzz->next(&x, &y);
123 // populate pts array
124 SkPoint pts[kPtsLen];
125 for (uint8_t i = 0; i < kPtsLen; ++i) {
126 pts[i].set(x, y);
127 x += font.getSize();
128 }
129
130 bool b;
131 fuzz->next(&b);
132 font.setForceAutoHinting(b);
133 fuzz->next(&b);
134 font.setEmbeddedBitmaps(b);
135 fuzz->next(&b);
136 font.setEmbolden(b);
137 fuzz->next(&b);
138 font.setEdging(b ? SkFont::Edging::kAntiAlias : SkFont::Edging::kSubpixelAntiAlias);
139 fuzz->next(&b);
140 font.setLinearMetrics(b);
141 fuzz->next(&b);
142 font.setSubpixel(b);
143 fuzz->next(&x);
144 font.setScaleX(x);
145 fuzz->next(&x);
146 font.setSkewX(x);
147 fuzz->next(&x);
148 font.setSize(x);
149
150 SkCanvas* cnv = surface->getCanvas();
151 fuzz->next(&x);
152 fuzz->next(&y);
153 cnv->drawTextBlob(SkTextBlob::MakeFromPosText(text, kTxtLen-1, pts, font), x, y, p);
154}
static const int kTxtLen
static void init_string(Fuzz *fuzz, char *str, size_t bufSize)
static const int kPtsLen
void drawTextBlob(const SkTextBlob *blob, SkScalar x, SkScalar y, const SkPaint &paint)
@ kAntiAlias
may have transparent pixels on glyph edges
static sk_sp< SkTextBlob > MakeFromPosText(const void *text, size_t byteLength, const SkPoint pos[], const SkFont &font, SkTextEncoding encoding=SkTextEncoding::kUTF8)
std::u16string text
double y
font
Font Metadata and Metrics.
void set(float x, float y)

◆ init_bitmap()

static void init_bitmap ( Fuzz fuzz,
SkBitmap bmp 
)
static

Definition at line 67 of file FuzzDrawFunctions.cpp.

67 {
68 uint8_t colorType;
70 // ColorType needs to match what the system configuration is.
72 colorType = kN32_SkColorType;
73 }
74 bool b;
75 fuzz->next(&b);
80 if (!bmp->tryAllocPixels(info)) {
81 SkDEBUGF("Bitmap not allocated\n");
82 }
83 SkColor c;
84 fuzz->next(&c);
85 bmp->eraseColor(c);
86
87 fuzz->next(&b);
88 SkPaint p;
89 if (b) {
90 init_paint(fuzz, &p);
91 }
92 else {
93 fuzz->next(&c);
94 p.setColor(c);
95 }
96}
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition DM.cpp:213
static const int kBmpSize
@ kOpaque_SkAlphaType
pixel is opaque
Definition SkAlphaType.h:28
@ kPremul_SkAlphaType
pixel components are premultiplied by alpha
Definition SkAlphaType.h:29
SkColorType
Definition SkColorType.h:19
@ kBGRA_8888_SkColorType
pixel with 8 bits for blue, green, red, alpha; in 32-bit word
Definition SkColorType.h:26
@ kLastEnum_SkColorType
last valid value
Definition SkColorType.h:56
@ kRGBA_8888_SkColorType
pixel with 8 bits for red, green, blue, alpha; in 32-bit word
Definition SkColorType.h:24
uint32_t SkColor
Definition SkColor.h:37
static SkColorType colorType(AImageDecoder *decoder, const AImageDecoderHeaderInfo *headerInfo)
bool tryAllocPixels(const SkImageInfo &info, size_t rowBytes)
Definition SkBitmap.cpp:271
void eraseColor(SkColor4f) const
Definition SkBitmap.cpp:442
static SkImageInfo Make(int width, int height, SkColorType ct, SkAlphaType at)

◆ init_paint()

static void init_paint ( Fuzz fuzz,
SkPaint p 
)
static

Definition at line 34 of file FuzzDrawFunctions.cpp.

34 {
35 bool b;
36 fuzz->next(&b);
37 p->setAntiAlias(b);
38
39 uint8_t tmp_u8;
40 fuzz->nextRange(&tmp_u8, 0, (int)SkBlendMode::kLastMode);
41 p->setBlendMode(static_cast<SkBlendMode>(tmp_u8));
42
43 SkColor co;
44 fuzz->next(&co);
45 p->setColor(co);
46
47 fuzz->next(&b);
48 p->setDither(b);
49
50 fuzz->nextRange(&tmp_u8, 0, (int)SkPaint::kLast_Cap);
51 p->setStrokeCap(static_cast<SkPaint::Cap>(tmp_u8));
52
53 fuzz->nextRange(&tmp_u8, 0, (int)SkPaint::kLast_Join);
54 p->setStrokeJoin(static_cast<SkPaint::Join>(tmp_u8));
55
56 SkScalar sc;
57 fuzz->next(&sc);
58 p->setStrokeMiter(sc);
59
60 fuzz->next(&sc);
61 p->setStrokeWidth(sc);
62
63 fuzz->nextRange(&tmp_u8, 0, (int)SkPaint::kStrokeAndFill_Style);
64 p->setStyle(static_cast<SkPaint::Style>(tmp_u8));
65}
SkBlendMode
Definition SkBlendMode.h:38
@ kLastMode
last valid value
@ kLast_Cap
largest Cap value
Definition SkPaint.h:337
@ kStrokeAndFill_Style
sets to stroke and fill geometry
Definition SkPaint.h:195
@ kLast_Join
equivalent to the largest value for Join
Definition SkPaint.h:362

◆ init_string()

static void init_string ( Fuzz fuzz,
char *  str,
size_t  bufSize 
)
static

Definition at line 26 of file FuzzDrawFunctions.cpp.

26 {
27 for (size_t i = 0; i < bufSize-1; ++i) {
28 fuzz->nextRange(&str[i], 0x20, 0x7E); // printable ASCII
29 }
30 str[bufSize-1] = '\0';
31}

◆ init_surface()

static void init_surface ( Fuzz fuzz,
sk_sp< SkSurface > *  s 
)
static

Definition at line 98 of file FuzzDrawFunctions.cpp.

98 {
99 uint8_t x, y;
100 fuzz->nextRange(&x, 1, kMaxX);
101 fuzz->nextRange(&y, 1, kMaxY);
103
104 if (!*s) {
105 // Was possibly too big for the memory constrained fuzzing environments
106 *s = SkSurfaces::Null(x, y);
107 }
108}
static const int kMaxY
static const int kMaxX
struct MyStruct s
SK_API sk_sp< SkSurface > Raster(const SkImageInfo &imageInfo, size_t rowBytes, const SkSurfaceProps *surfaceProps)
SK_API sk_sp< SkSurface > Null(int width, int height)
static SkImageInfo MakeN32Premul(int width, int height)

Variable Documentation

◆ kBmpSize

const int kBmpSize = 24
static

Definition at line 20 of file FuzzDrawFunctions.cpp.

◆ kMaxX

const int kMaxX = 250
static

Definition at line 21 of file FuzzDrawFunctions.cpp.

◆ kMaxY

const int kMaxY = 250
static

Definition at line 22 of file FuzzDrawFunctions.cpp.

◆ kPtsLen

const int kPtsLen = 10
static

Definition at line 23 of file FuzzDrawFunctions.cpp.

◆ kTxtLen

const int kTxtLen = 5
static

Definition at line 24 of file FuzzDrawFunctions.cpp.