Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Functions
ClipCubicTest.cpp File Reference
#include "include/core/SkBitmap.h"
#include "include/core/SkCanvas.h"
#include "include/core/SkColor.h"
#include "include/core/SkImageInfo.h"
#include "include/core/SkPaint.h"
#include "include/core/SkPath.h"
#include "include/core/SkPoint.h"
#include "include/core/SkRect.h"
#include "include/core/SkRefCnt.h"
#include "include/core/SkScalar.h"
#include "include/core/SkSurface.h"
#include "include/core/SkTypes.h"
#include "include/private/base/SkDebug.h"
#include "src/base/SkFloatBits.h"
#include "src/core/SkCubicClipper.h"
#include "tests/Test.h"

Go to the source code of this file.

Functions

static void test_giantClip ()
 
static void PrintCurve (const char *name, const SkPoint crv[4])
 
static bool CurvesAreEqual (const SkPoint c0[4], const SkPoint c1[4], float tol)
 
static SkPointSetCurve (float x0, float y0, float x1, float y1, float x2, float y2, float x3, float y3, SkPoint crv[4])
 
 DEF_TEST (ClipCubic, reporter)
 
 DEF_TEST (test_fuzz_crbug_698714, reporter)
 
 DEF_TEST (cubic_scan_error_crbug_844457_and_845489, reporter)
 

Function Documentation

◆ CurvesAreEqual()

static bool CurvesAreEqual ( const SkPoint  c0[4],
const SkPoint  c1[4],
float  tol 
)
static

Definition at line 50 of file ClipCubicTest.cpp.

52 {
53 for (int i = 0; i < 4; i++) {
54 if (SkScalarAbs(c0[i].fX - c1[i].fX) > tol ||
55 SkScalarAbs(c0[i].fY - c1[i].fY) > tol
56 ) {
57 PrintCurve("c0", c0);
58 PrintCurve("c1", c1);
59 return false;
60 }
61 }
62 return true;
63}
static void PrintCurve(const char *name, const SkPoint crv[4])
#define SkScalarAbs(x)
Definition SkScalar.h:39

◆ DEF_TEST() [1/3]

DEF_TEST ( ClipCubic  ,
reporter   
)

Definition at line 79 of file ClipCubicTest.cpp.

79 {
80 static SkPoint crv[4] = {
83 { SkIntToScalar(1), SkIntToScalar(10) },
85 };
86
87 SkCubicClipper clipper;
88 SkPoint clipped[4], shouldbe[4];
90 bool success;
91 const float tol = 1e-4f;
92
93 // Test no clip, with plenty of room.
94 clipRect.setLTRB(-2, -2, 6, 14);
95 clipper.setClip(clipRect);
96 success = clipper.clipCubic(crv, clipped);
97 REPORTER_ASSERT(reporter, success == true);
99 0, 0, 2, 3, 1, 10, 4, 12, shouldbe), tol));
100
101 // Test no clip, touching first point.
102 clipRect.setLTRB(-2, 0, 6, 14);
103 clipper.setClip(clipRect);
104 success = clipper.clipCubic(crv, clipped);
105 REPORTER_ASSERT(reporter, success == true);
107 0, 0, 2, 3, 1, 10, 4, 12, shouldbe), tol));
108
109 // Test no clip, touching last point.
110 clipRect.setLTRB(-2, -2, 6, 12);
111 clipper.setClip(clipRect);
112 success = clipper.clipCubic(crv, clipped);
113 REPORTER_ASSERT(reporter, success == true);
115 0, 0, 2, 3, 1, 10, 4, 12, shouldbe), tol));
116
117 // Test all clip.
118 clipRect.setLTRB(-2, 14, 6, 20);
119 clipper.setClip(clipRect);
120 success = clipper.clipCubic(crv, clipped);
121 REPORTER_ASSERT(reporter, success == false);
122
123 // Test clip at 1.
124 clipRect.setLTRB(-2, 1, 6, 14);
125 clipper.setClip(clipRect);
126 success = clipper.clipCubic(crv, clipped);
127 REPORTER_ASSERT(reporter, success == true);
129 0.5126125216f, 1,
130 1.841195941f, 4.337081432f,
131 1.297019958f, 10.19801331f,
132 4, 12,
133 shouldbe), tol));
134
135 // Test clip at 2.
136 clipRect.setLTRB(-2, 2, 6, 14);
137 clipper.setClip(clipRect);
138 success = clipper.clipCubic(crv, clipped);
139 REPORTER_ASSERT(reporter, success == true);
141 00.8412352204f, 2,
142 1.767683744f, 5.400758266f,
143 1.55052948f, 10.36701965f,
144 4, 12,
145 shouldbe), tol));
146
147 // Test clip at 11.
148 clipRect.setLTRB(-2, -2, 6, 11);
149 clipper.setClip(clipRect);
150 success = clipper.clipCubic(crv, clipped);
151 REPORTER_ASSERT(reporter, success == true);
153 0, 0,
154 1.742904663f, 2.614356995f,
155 1.207521796f, 8.266430855f,
156 3.026495695f, 11,
157 shouldbe), tol));
158
159 // Test clip at 10.
160 clipRect.setLTRB(-2, -2, 6, 10);
161 clipper.setClip(clipRect);
162 success = clipper.clipCubic(crv, clipped);
163 REPORTER_ASSERT(reporter, success == true);
165 0, 0,
166 1.551193237f, 2.326789856f,
167 1.297736168f, 7.059780121f,
168 2.505550385f, 10,
169 shouldbe), tol));
170
172}
static bool CurvesAreEqual(const SkPoint c0[4], const SkPoint c1[4], float tol)
static SkPoint * SetCurve(float x0, float y0, float x1, float y1, float x2, float y2, float x3, float y3, SkPoint crv[4])
static void test_giantClip()
reporter
#define SkIntToScalar(x)
Definition SkScalar.h:57
#define REPORTER_ASSERT(r, cond,...)
Definition Test.h:286
bool clipCubic(const SkPoint src[4], SkPoint dst[4])
void setClip(const SkIRect &clip)
clipRect(r.rect, r.opAA.op(), r.opAA.aa())) template<> void Draw

◆ DEF_TEST() [2/3]

DEF_TEST ( cubic_scan_error_crbug_844457_and_845489  ,
reporter   
)

Definition at line 212 of file ClipCubicTest.cpp.

212 {
214 SkCanvas* canvas = surface->getCanvas();
215 SkPaint p;
216
217 SkPath path;
218 path.moveTo(-30/64.0, -31/64.0);
219 path.cubicTo(-31/64.0, -31/64,-31/64.0, -31/64,-31/64.0, 100);
220 path.lineTo(100, 100);
221 canvas->drawPath(path, p);
222
223 // May need to define SK_RASTERIZE_EVEN_ROUNDING to trigger the need for this test
224 path.reset();
225 path.moveTo(-30/64.0f, -31/64.0f + 1/256.0f);
226 path.cubicTo(-31/64.0f + 1/256.0f, -31/64.0f + 1/256.0f,
227 -31/64.0f + 1/256.0f, -31/64.0f + 1/256.0f,
228 -31/64.0f + 1/256.0f, 100);
229 path.lineTo(100, 100);
230 canvas->drawPath(path, p);
231}
void drawPath(const SkPath &path, const SkPaint &paint)
VkSurfaceKHR surface
Definition main.cc:49
SK_API sk_sp< SkSurface > Raster(const SkImageInfo &imageInfo, size_t rowBytes, const SkSurfaceProps *surfaceProps)
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
static SkImageInfo MakeN32Premul(int width, int height)

◆ DEF_TEST() [3/3]

DEF_TEST ( test_fuzz_crbug_698714  ,
reporter   
)

Definition at line 174 of file ClipCubicTest.cpp.

174 {
176 SkCanvas* canvas = surface->getCanvas();
178 paint.setAntiAlias(true);
179 SkPath path;
180 path.moveTo(SkBits2Float(0x00000000), SkBits2Float(0x00000000)); // 0,0
181 path.lineTo(SkBits2Float(0x43434343), SkBits2Float(0x43430143)); //195.263f, 195.005f
182 path.lineTo(SkBits2Float(0x43434343), SkBits2Float(0x43434343)); //195.263f, 195.263f
183 path.lineTo(SkBits2Float(0xb5434343), SkBits2Float(0x434300be)); //-7.2741e-07f, 195.003f
184 // 195.263f, 195.263f, -1.16387e-05f, 3.58641e-38f, 3.85088e-29f,1.86082e-39f
185 path.cubicTo(SkBits2Float(0x43434343), SkBits2Float(0x43434341),
186 SkBits2Float(0xb74343bd), SkBits2Float(0x01434343),
187 SkBits2Float(0x10434343), SkBits2Float(0x00144332));
188 // 4.11823e-38f, 195.263f, 195.263f, 195.263f, -7.2741e-07f, 195.263f
189 path.cubicTo(SkBits2Float(0x016037c0), SkBits2Float(0x43434343),
190 SkBits2Float(0x43434343), SkBits2Float(0x43434343),
191 SkBits2Float(0xb5434343), SkBits2Float(0x43434343));
192 // 195.263f, 195.263f, -1.16387e-05f, 3.58641e-38f, 195.263f, -2
193 path.cubicTo(SkBits2Float(0x43434344), SkBits2Float(0x43434341),
194 SkBits2Float(0xb74343bd), SkBits2Float(0x01434343),
195 SkBits2Float(0x43434343), SkBits2Float(0xc0000014));
196 // -5.87228e+06f, 3.7773e-07f, 3.60231e-13f, -6.64511e+06f,2.77692e-15f, 2.48803e-15f
197 path.cubicTo(SkBits2Float(0xcab33535), SkBits2Float(0x34cacaca),
198 SkBits2Float(0x2acacaca), SkBits2Float(0xcacacae3),
199 SkBits2Float(0x27481927), SkBits2Float(0x27334805));
200 path.lineTo(SkBits2Float(0xb5434343), SkBits2Float(0x43434343)); //-7.2741e-07f, 195.263f
201 // 195.263f, 195.263f, -1.16387e-05f, 195.212f, 195.263f, -2
202 path.cubicTo(SkBits2Float(0x43434343), SkBits2Float(0x43434341),
203 SkBits2Float(0xb74343b9), SkBits2Float(0x43433643),
204 SkBits2Float(0x43434343), SkBits2Float(0xc0000014));
205 path.lineTo(SkBits2Float(0xc7004343), SkBits2Float(0x27480527)); //-32835.3f, 2.77584e-15f
206 path.lineTo(SkBits2Float(0x00000000), SkBits2Float(0x00000000)); // 0,0
207 path.close();
208 canvas->clipRect({0, 0, 65, 202});
209 canvas->drawPath(path, paint);
210}
static float SkBits2Float(uint32_t bits)
Definition SkFloatBits.h:48
void clipRect(const SkRect &rect, SkClipOp op, bool doAntiAlias)
const Paint & paint

◆ PrintCurve()

static void PrintCurve ( const char *  name,
const SkPoint  crv[4] 
)
static

Definition at line 39 of file ClipCubicTest.cpp.

39 {
40 SkDebugf("%s: %.10g, %.10g, %.10g, %.10g, %.10g, %.10g, %.10g, %.10g\n",
41 name,
42 (float)crv[0].fX, (float)crv[0].fY,
43 (float)crv[1].fX, (float)crv[1].fY,
44 (float)crv[2].fX, (float)crv[2].fY,
45 (float)crv[3].fX, (float)crv[3].fY);
46
47}
void SK_SPI SkDebugf(const char format[],...) SK_PRINTF_LIKE(1
const char * name
Definition fuchsia.cc:50

◆ SetCurve()

static SkPoint * SetCurve ( float  x0,
float  y0,
float  x1,
float  y1,
float  x2,
float  y2,
float  x3,
float  y3,
SkPoint  crv[4] 
)
static

Definition at line 66 of file ClipCubicTest.cpp.

70 {
71 crv[0].fX = x0; crv[0].fY = y0;
72 crv[1].fX = x1; crv[1].fY = y1;
73 crv[2].fX = x2; crv[2].fY = y2;
74 crv[3].fX = x3; crv[3].fY = y3;
75 return crv;
76}
float fX
x-axis value
float fY
y-axis value

◆ test_giantClip()

static void test_giantClip ( )
static

Definition at line 28 of file ClipCubicTest.cpp.

28 {
29 SkBitmap bm;
30 bm.allocN32Pixels(64919, 1);
31 SkCanvas canvas(bm);
32 canvas.clear(SK_ColorTRANSPARENT);
33
35 paint.setAntiAlias(true);
36 canvas.drawPath(SkPath::Polygon({{0,0}, {1,0}, {33,1}}, false), paint);
37}
constexpr SkColor SK_ColorTRANSPARENT
Definition SkColor.h:99
void allocN32Pixels(int width, int height, bool isOpaque=false)
Definition SkBitmap.cpp:232
static SkPath Polygon(const SkPoint pts[], int count, bool isClosed, SkPathFillType=SkPathFillType::kWinding, bool isVolatile=false)
Definition SkPath.cpp:3546