Debian Codegraph @

fuzz/FuzzGrStyledShape.cpp

raw
1 /*
2 * Copyright 2025 Google LLC
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/Fuzz.h"
9 #include "fuzz/FuzzCanvasHelpers.h"
10 #include "fuzz/FuzzCommon.h"
11 #include "include/core/SkPaint.h"
12 #include "include/core/SkPath.h"
13 #include "include/core/SkRRect.h"
14 #include "include/core/SkRect.h"
15 #include "src/gpu/ganesh/geometry/GrStyledShape.h"
16
17 DEF_FUZZ(GrStyledShape, fuzz) {
18 SkPathBuilder pb;
19 FuzzNicePath(fuzz, &pb, 10);
20
21 SkRect rect;
22 fuzz->next(&rect);
23 if (!rect.isFinite()) {
24 return;
25 }
26
27 SkRRect rrect;
28 fuzz->next(&rrect);
29 if (!rrect.isValid()) {
30 return;
31 }
32
33 SkPaint paint;
34 FuzzPaint(fuzz, &paint, 3);
35
36 GrStyledShape shape1(pb.detach(), paint);
37 GrStyledShape shape2(rect, paint);
38 GrStyledShape shape3(rrect, paint);
39
40 SkPathBuilder pb2;
41 FuzzNicePath(fuzz, &pb2, 10);
42 SkPath path = pb.detach();
43 GrStyledShape shape4(path);
44 GrStyledShape shape5(rect);
45 GrStyledShape shape6(rrect);
46
47 GrStyledShape shape7(SkPath::Rect(rect));
48 GrStyledShape shape8(SkPath::RRect(rrect));
49 GrStyledShape shape9(SkPath::Oval(rect));
50 GrStyledShape shape10 = GrStyledShape::MakeFilled(shape4);
51
52 auto exercise_shape = [&](const GrStyledShape& shape) {
53 shape.style();
54 shape.simplified();
55 GrStyle::Apply apply;
56 fuzz->nextEnum(&apply, GrStyle::Apply::kPathEffectAndStrokeRec);
57 SkScalar scale;
58 fuzz->nextRange(&scale, 0.001f, 20.0f);
59 shape.applyStyle(apply, scale);
60 shape.isRect();
61 SkRRect r;
62 bool inverted;
63 shape.asRRect(&r, &inverted);
64 SkPoint pts[2];
65 shape.asLine(pts, &inverted);
66 SkRect rects[2];
67 shape.asNestedRects(rects);
68 SkPath p = shape.asPath();
69 SkASSERT_RELEASE(p.isValid());
70 shape.isEmpty();
71 shape.bounds();
72 shape.styledBounds();
73 shape.knownToBeConvex();
74 shape.knownDirection();
75 shape.inverseFilled();
76 shape.mayBeInverseFilledAfterStyling();
77 shape.knownToBeClosed();
78 shape.segmentMask();
79
80 };
81
82 exercise_shape(shape1);
83 exercise_shape(shape2);
84 exercise_shape(shape3);
85 exercise_shape(shape4);
86 exercise_shape(shape5);
87 exercise_shape(shape6);
88 exercise_shape(shape7);
89 exercise_shape(shape8);
90 exercise_shape(shape9);
91 exercise_shape(shape10);
92 }