5 #include "flutter/testing/testing.h"
6 #include "gmock/gmock.h"
7 #include "gtest/gtest.h"
11 #include "flutter/display_list/geometry/dl_path.h"
12 #include "flutter/display_list/geometry/dl_path_builder.h"
27 (
Point origin,
bool will_be_closed),
42 TEST(PathTessellatorTest, EmptyPath) {
43 flutter::DlPathBuilder builder;
44 builder.MoveTo({0, 0});
47 ::testing::StrictMock<MockSegmentReceiver> mock_receiver;
54 ::testing::StrictMock<MockPathVertexWriter> mock_writer;
58 TEST(PathTessellatorTest, EmptyPathMultipleMoveTo) {
59 flutter::DlPathBuilder builder;
60 builder.MoveTo({0, 0});
61 builder.MoveTo({10, 10});
62 builder.MoveTo({20, 20});
65 ::testing::StrictMock<MockSegmentReceiver> mock_receiver;
72 ::testing::StrictMock<MockPathVertexWriter> mock_writer;
76 TEST(PathTessellatorTest, SimpleClosedPath) {
77 flutter::DlPathBuilder builder;
78 builder.MoveTo({0, 0});
79 builder.LineTo({10, 10});
80 builder.LineTo({0, 20});
84 ::testing::StrictMock<MockSegmentReceiver> mock_receiver;
86 ::testing::InSequence sequence;
88 EXPECT_CALL(mock_receiver,
89 BeginContour(
Point(0, 0),
true));
90 EXPECT_CALL(mock_receiver, RecordLine(
Point(0, 0),
Point(10, 10)));
91 EXPECT_CALL(mock_receiver, RecordLine(
Point(10, 10),
Point(0, 20)));
92 EXPECT_CALL(mock_receiver, RecordLine(
Point(0, 20),
Point(0, 0)));
93 EXPECT_CALL(mock_receiver, EndContour(
Point(0, 0),
true));
101 ::testing::StrictMock<MockPathVertexWriter> mock_writer;
103 ::testing::InSequence sequence;
105 EXPECT_CALL(mock_writer, Write(
Point(0, 0)));
106 EXPECT_CALL(mock_writer, Write(
Point(10, 10)));
107 EXPECT_CALL(mock_writer, Write(
Point(0, 20)));
108 EXPECT_CALL(mock_writer, Write(
Point(0, 0)));
109 EXPECT_CALL(mock_writer, EndContour());
114 TEST(PathTessellatorTest, SimpleUnclosedPath) {
115 flutter::DlPathBuilder builder;
116 builder.MoveTo({0, 0});
117 builder.LineTo({10, 10});
118 builder.LineTo({0, 20});
122 ::testing::StrictMock<MockSegmentReceiver> mock_receiver;
124 ::testing::InSequence sequence;
126 EXPECT_CALL(mock_receiver,
127 BeginContour(
Point(0, 0),
false));
128 EXPECT_CALL(mock_receiver, RecordLine(
Point(0, 0),
Point(10, 10)));
129 EXPECT_CALL(mock_receiver, RecordLine(
Point(10, 10),
Point(0, 20)));
130 EXPECT_CALL(mock_receiver, RecordLine(
Point(0, 20),
Point(0, 0)));
131 EXPECT_CALL(mock_receiver, EndContour(
Point(0, 0),
false));
139 ::testing::StrictMock<MockPathVertexWriter> mock_writer;
141 ::testing::InSequence sequence;
143 EXPECT_CALL(mock_writer, Write(
Point(0, 0)));
144 EXPECT_CALL(mock_writer, Write(
Point(10, 10)));
145 EXPECT_CALL(mock_writer, Write(
Point(0, 20)));
146 EXPECT_CALL(mock_writer, Write(
Point(0, 0)));
147 EXPECT_CALL(mock_writer, EndContour());
152 TEST(PathTessellatorTest, SimplePathTrailingMoveTo) {
153 flutter::DlPathBuilder builder;
154 builder.MoveTo({0, 0});
155 builder.LineTo({10, 10});
156 builder.LineTo({0, 20});
158 builder.MoveTo({500, 100});
161 ::testing::StrictMock<MockSegmentReceiver> mock_receiver;
163 ::testing::InSequence sequence;
165 EXPECT_CALL(mock_receiver,
166 BeginContour(
Point(0, 0),
true));
167 EXPECT_CALL(mock_receiver, RecordLine(
Point(0, 0),
Point(10, 10)));
168 EXPECT_CALL(mock_receiver, RecordLine(
Point(10, 10),
Point(0, 20)));
169 EXPECT_CALL(mock_receiver, RecordLine(
Point(0, 20),
Point(0, 0)));
170 EXPECT_CALL(mock_receiver, EndContour(
Point(0, 0),
true));
178 ::testing::StrictMock<MockPathVertexWriter> mock_writer;
180 ::testing::InSequence sequence;
182 EXPECT_CALL(mock_writer, Write(
Point(0, 0)));
183 EXPECT_CALL(mock_writer, Write(
Point(10, 10)));
184 EXPECT_CALL(mock_writer, Write(
Point(0, 20)));
185 EXPECT_CALL(mock_writer, Write(
Point(0, 0)));
186 EXPECT_CALL(mock_writer, EndContour());
191 TEST(PathTessellatorTest, DegenerateSegmentsPath) {
192 flutter::DlPathBuilder builder;
193 builder.MoveTo({0, 0});
194 builder.LineTo({0, 0});
195 builder.LineTo({0, 0});
196 builder.QuadraticCurveTo({0, 0}, {0, 0});
197 builder.QuadraticCurveTo({0, 0}, {0, 0});
198 builder.ConicCurveTo({0, 0}, {0, 0}, 12.0f);
199 builder.ConicCurveTo({0, 0}, {0, 0}, 12.0f);
200 builder.CubicCurveTo({0, 0}, {0, 0}, {0, 0});
201 builder.CubicCurveTo({0, 0}, {0, 0}, {0, 0});
205 ::testing::StrictMock<MockSegmentReceiver> mock_receiver;
207 ::testing::InSequence sequence;
209 EXPECT_CALL(mock_receiver,
210 BeginContour(
Point(0, 0),
true));
211 EXPECT_CALL(mock_receiver, EndContour(
Point(0, 0),
true));
219 ::testing::StrictMock<MockPathVertexWriter> mock_writer;
221 ::testing::InSequence sequence;
223 EXPECT_CALL(mock_writer, Write(
Point(0, 0)));
224 EXPECT_CALL(mock_writer, EndContour());
229 TEST(PathTessellatorTest, QuadToLineToOptimization) {
230 flutter::DlPathBuilder builder;
231 builder.MoveTo({0, 0});
233 builder.QuadraticCurveTo({0, 0}, {10, 10});
235 builder.QuadraticCurveTo({20, 10}, {20, 10});
239 ::testing::StrictMock<MockSegmentReceiver> mock_receiver;
241 ::testing::InSequence sequence;
243 EXPECT_CALL(mock_receiver,
244 BeginContour(
Point(0, 0),
true));
245 EXPECT_CALL(mock_receiver, RecordLine(
Point(0, 0),
Point(10, 10)));
246 EXPECT_CALL(mock_receiver, RecordLine(
Point(10, 10),
Point(20, 10)));
247 EXPECT_CALL(mock_receiver, RecordLine(
Point(20, 10),
Point(0, 0)));
248 EXPECT_CALL(mock_receiver, EndContour(
Point(0, 0),
true));
256 ::testing::StrictMock<MockPathVertexWriter> mock_writer;
258 ::testing::InSequence sequence;
260 EXPECT_CALL(mock_writer, Write(
Point(0, 0)));
261 EXPECT_CALL(mock_writer, Write(
Point(10, 10)));
262 EXPECT_CALL(mock_writer, Write(
Point(20, 10)));
263 EXPECT_CALL(mock_writer, Write(
Point(0, 0)));
264 EXPECT_CALL(mock_writer, EndContour());
269 TEST(PathTessellatorTest, ConicToLineToOptimization) {
270 flutter::DlPathBuilder builder;
271 builder.MoveTo({0, 0});
273 builder.ConicCurveTo({0, 0}, {10, 10}, 2.0f);
275 builder.ConicCurveTo({20, 10}, {20, 10}, 2.0f);
277 builder.ConicCurveTo({20, 0}, {10, 0}, 0.0f);
281 ::testing::StrictMock<MockSegmentReceiver> mock_receiver;
283 ::testing::InSequence sequence;
285 EXPECT_CALL(mock_receiver,
286 BeginContour(
Point(0, 0),
true));
287 EXPECT_CALL(mock_receiver, RecordLine(
Point(0, 0),
Point(10, 10)));
288 EXPECT_CALL(mock_receiver, RecordLine(
Point(10, 10),
Point(20, 10)));
289 EXPECT_CALL(mock_receiver, RecordLine(
Point(20, 10),
Point(10, 0)));
290 EXPECT_CALL(mock_receiver, RecordLine(
Point(10, 0),
Point(0, 0)));
291 EXPECT_CALL(mock_receiver, EndContour(
Point(0, 0),
true));
299 ::testing::StrictMock<MockPathVertexWriter> mock_writer;
301 ::testing::InSequence sequence;
303 EXPECT_CALL(mock_writer, Write(
Point(0, 0)));
304 EXPECT_CALL(mock_writer, Write(
Point(10, 10)));
305 EXPECT_CALL(mock_writer, Write(
Point(20, 10)));
306 EXPECT_CALL(mock_writer, Write(
Point(10, 0)));
307 EXPECT_CALL(mock_writer, Write(
Point(0, 0)));
308 EXPECT_CALL(mock_writer, EndContour());
313 TEST(PathTessellatorTest, ConicToQuadToOptimization) {
317 flutter::DlPathBuilder builder;
318 builder.MoveTo(quad.p1);
320 builder.ConicCurveTo(quad.cp, quad.p2, 1.0f);
324 ::testing::StrictMock<MockSegmentReceiver> mock_receiver;
326 ::testing::InSequence sequence;
328 EXPECT_CALL(mock_receiver, BeginContour(quad.p1,
true));
329 EXPECT_CALL(mock_receiver, RecordQuad(quad.p1, quad.cp, quad.p2));
330 EXPECT_CALL(mock_receiver, RecordLine(quad.p2, quad.p1));
331 EXPECT_CALL(mock_receiver, EndContour(quad.p1,
true));
339 ::testing::StrictMock<MockPathVertexWriter> mock_writer;
341 ::testing::InSequence sequence;
343 EXPECT_CALL(mock_writer, Write(quad.p1));
345 EXPECT_CALL(mock_writer, Write(quad.Solve(1 / 5.0f)));
346 EXPECT_CALL(mock_writer, Write(quad.Solve(2 / 5.0f)));
347 EXPECT_CALL(mock_writer, Write(quad.Solve(3 / 5.0f)));
348 EXPECT_CALL(mock_writer, Write(quad.Solve(4 / 5.0f)));
349 EXPECT_CALL(mock_writer, Write(quad.p2));
351 EXPECT_CALL(mock_writer, Write(quad.p1));
352 EXPECT_CALL(mock_writer, EndContour());
357 TEST(PathTessellatorTest, SimplePathMultipleMoveTo) {
358 flutter::DlPathBuilder builder;
359 builder.MoveTo({500, 100});
360 builder.MoveTo({0, 0});
361 builder.LineTo({10, 10});
362 builder.LineTo({0, 20});
366 ::testing::StrictMock<MockSegmentReceiver> mock_receiver;
368 ::testing::InSequence sequence;
370 EXPECT_CALL(mock_receiver,
371 BeginContour(
Point(0, 0),
true));
372 EXPECT_CALL(mock_receiver, RecordLine(
Point(0, 0),
Point(10, 10)));
373 EXPECT_CALL(mock_receiver, RecordLine(
Point(10, 10),
Point(0, 20)));
374 EXPECT_CALL(mock_receiver, RecordLine(
Point(0, 20),
Point(0, 0)));
375 EXPECT_CALL(mock_receiver, EndContour(
Point(0, 0),
true));
383 ::testing::StrictMock<MockPathVertexWriter> mock_writer;
385 ::testing::InSequence sequence;
387 EXPECT_CALL(mock_writer, Write(
Point(0, 0)));
388 EXPECT_CALL(mock_writer, Write(
Point(10, 10)));
389 EXPECT_CALL(mock_writer, Write(
Point(0, 20)));
390 EXPECT_CALL(mock_writer, Write(
Point(0, 0)));
391 EXPECT_CALL(mock_writer, EndContour());
396 TEST(PathTessellatorTest, ComplexPath) {
401 flutter::DlPathBuilder builder;
402 builder.MoveTo({0, 0});
403 builder.LineTo({10, 10});
404 builder.QuadraticCurveTo(quad.cp, quad.p2);
405 builder.ConicCurveTo(conic.cp, conic.p2, conic.weight);
406 builder.CubicCurveTo(cubic.cp1, cubic.cp2, cubic.p2);
410 ::testing::StrictMock<MockSegmentReceiver> mock_receiver;
412 ::testing::InSequence sequence;
414 EXPECT_CALL(mock_receiver,
415 BeginContour(
Point(0, 0),
true));
416 EXPECT_CALL(mock_receiver, RecordLine(
Point(0, 0),
Point(10, 10)));
417 EXPECT_CALL(mock_receiver, RecordQuad(quad.p1, quad.cp, quad.p2));
418 EXPECT_CALL(mock_receiver,
419 RecordConic(conic.p1, conic.cp, conic.p2, conic.weight));
420 EXPECT_CALL(mock_receiver,
421 RecordCubic(cubic.p1, cubic.cp1, cubic.cp2, cubic.p2));
422 EXPECT_CALL(mock_receiver, RecordLine(cubic.p2,
Point(0, 0)));
423 EXPECT_CALL(mock_receiver, EndContour(
Point(0, 0),
true));
431 ::testing::StrictMock<MockPathVertexWriter> mock_writer;
433 ::testing::InSequence sequence;
435 EXPECT_CALL(mock_writer, Write(
Point(0, 0)));
436 EXPECT_CALL(mock_writer, Write(
Point(10, 10)));
438 EXPECT_CALL(mock_writer, Write(quad.Solve(1 / 5.0f)));
439 EXPECT_CALL(mock_writer, Write(quad.Solve(2 / 5.0f)));
440 EXPECT_CALL(mock_writer, Write(quad.Solve(3 / 5.0f)));
441 EXPECT_CALL(mock_writer, Write(quad.Solve(4 / 5.0f)));
442 EXPECT_CALL(mock_writer, Write(quad.p2));
445 EXPECT_CALL(mock_writer, Write(conic.Solve(1 / 8.0f)));
446 EXPECT_CALL(mock_writer, Write(conic.Solve(2 / 8.0f)));
447 EXPECT_CALL(mock_writer, Write(conic.Solve(3 / 8.0f)));
448 EXPECT_CALL(mock_writer, Write(conic.Solve(4 / 8.0f)));
449 EXPECT_CALL(mock_writer, Write(conic.Solve(5 / 8.0f)));
450 EXPECT_CALL(mock_writer, Write(conic.Solve(6 / 8.0f)));
451 EXPECT_CALL(mock_writer, Write(conic.Solve(7 / 8.0f)));
452 EXPECT_CALL(mock_writer, Write(conic.p2));
455 EXPECT_CALL(mock_writer, Write(cubic.Solve(1 / 9.0f)));
456 EXPECT_CALL(mock_writer, Write(cubic.Solve(2 / 9.0f)));
457 EXPECT_CALL(mock_writer, Write(cubic.Solve(3 / 9.0f)));
458 EXPECT_CALL(mock_writer, Write(cubic.Solve(4 / 9.0f)));
459 EXPECT_CALL(mock_writer, Write(cubic.Solve(5 / 9.0f)));
460 EXPECT_CALL(mock_writer, Write(cubic.Solve(6 / 9.0f)));
461 EXPECT_CALL(mock_writer, Write(cubic.Solve(7 / 9.0f)));
462 EXPECT_CALL(mock_writer, Write(cubic.Solve(8 / 9.0f)));
463 EXPECT_CALL(mock_writer, Write(cubic.p2));
465 EXPECT_CALL(mock_writer, Write(
Point(0, 0)));
466 EXPECT_CALL(mock_writer, EndContour());
471 TEST(PathTessellatorTest, ComplexPathTrailingMoveTo) {
476 flutter::DlPathBuilder builder;
477 builder.MoveTo({0, 0});
478 builder.LineTo({10, 10});
479 builder.QuadraticCurveTo(quad.cp, quad.p2);
480 builder.ConicCurveTo(conic.cp, conic.p2, conic.weight);
481 builder.CubicCurveTo(cubic.cp1, cubic.cp2, cubic.p2);
483 builder.MoveTo({500, 100});
486 ::testing::StrictMock<MockSegmentReceiver> mock_receiver;
488 ::testing::InSequence sequence;
490 EXPECT_CALL(mock_receiver,
491 BeginContour(
Point(0, 0),
true));
492 EXPECT_CALL(mock_receiver, RecordLine(
Point(0, 0),
Point(10, 10)));
493 EXPECT_CALL(mock_receiver, RecordQuad(quad.p1, quad.cp, quad.p2));
494 EXPECT_CALL(mock_receiver,
495 RecordConic(conic.p1, conic.cp, conic.p2, conic.weight));
496 EXPECT_CALL(mock_receiver,
497 RecordCubic(cubic.p1, cubic.cp1, cubic.cp2, cubic.p2));
498 EXPECT_CALL(mock_receiver, RecordLine(cubic.p2,
Point(0, 0)));
499 EXPECT_CALL(mock_receiver, EndContour(
Point(0, 0),
true));
507 ::testing::StrictMock<MockPathVertexWriter> mock_writer;
509 ::testing::InSequence sequence;
511 EXPECT_CALL(mock_writer, Write(
Point(0, 0)));
512 EXPECT_CALL(mock_writer, Write(
Point(10, 10)));
514 EXPECT_CALL(mock_writer, Write(quad.Solve(1 / 5.0f)));
515 EXPECT_CALL(mock_writer, Write(quad.Solve(2 / 5.0f)));
516 EXPECT_CALL(mock_writer, Write(quad.Solve(3 / 5.0f)));
517 EXPECT_CALL(mock_writer, Write(quad.Solve(4 / 5.0f)));
518 EXPECT_CALL(mock_writer, Write(quad.p2));
521 EXPECT_CALL(mock_writer, Write(conic.Solve(1 / 8.0f)));
522 EXPECT_CALL(mock_writer, Write(conic.Solve(2 / 8.0f)));
523 EXPECT_CALL(mock_writer, Write(conic.Solve(3 / 8.0f)));
524 EXPECT_CALL(mock_writer, Write(conic.Solve(4 / 8.0f)));
525 EXPECT_CALL(mock_writer, Write(conic.Solve(5 / 8.0f)));
526 EXPECT_CALL(mock_writer, Write(conic.Solve(6 / 8.0f)));
527 EXPECT_CALL(mock_writer, Write(conic.Solve(7 / 8.0f)));
528 EXPECT_CALL(mock_writer, Write(conic.p2));
531 EXPECT_CALL(mock_writer, Write(cubic.Solve(1 / 9.0f)));
532 EXPECT_CALL(mock_writer, Write(cubic.Solve(2 / 9.0f)));
533 EXPECT_CALL(mock_writer, Write(cubic.Solve(3 / 9.0f)));
534 EXPECT_CALL(mock_writer, Write(cubic.Solve(4 / 9.0f)));
535 EXPECT_CALL(mock_writer, Write(cubic.Solve(5 / 9.0f)));
536 EXPECT_CALL(mock_writer, Write(cubic.Solve(6 / 9.0f)));
537 EXPECT_CALL(mock_writer, Write(cubic.Solve(7 / 9.0f)));
538 EXPECT_CALL(mock_writer, Write(cubic.Solve(8 / 9.0f)));
539 EXPECT_CALL(mock_writer, Write(cubic.p2));
541 EXPECT_CALL(mock_writer, Write(
Point(0, 0)));
542 EXPECT_CALL(mock_writer, EndContour());
547 TEST(PathTessellatorTest, LinearQuadToPointCount) {
548 flutter::DlPathBuilder builder;
549 builder.MoveTo({316.3, 121.5});
550 builder.QuadraticCurveTo({316.4, 121.5}, {316.5, 121.5});
552 auto path = builder.TakePath();
559 TEST(PathTessellatorTest, LinearConicToPointCount) {
560 flutter::DlPathBuilder builder;
561 builder.MoveTo({316.3, 121.5});
562 builder.ConicCurveTo({316.4, 121.5}, {316.5, 121.5}, 2.0f);
564 auto path = builder.TakePath();
571 TEST(PathTessellatorTest, LinearCubicToPointCount) {
572 flutter::DlPathBuilder builder;
573 builder.MoveTo({316.3, 121.5});
574 builder.CubicCurveTo({316.4, 121.5}, {316.5, 121.5}, {316.6, 121.5});
576 auto path = builder.TakePath();
An interface for receiving pruned path segments.
virtual void RecordLine(Point p1, Point p2)=0
virtual void RecordCubic(Point p1, Point cp1, Point cp2, Point p2)=0
virtual void RecordConic(Point p1, Point cp, Point p2, Scalar weight)=0
virtual void RecordQuad(Point p1, Point cp, Point p2)=0
virtual void EndContour(Point origin, bool with_close)=0
virtual void BeginContour(Point origin, bool will_be_closed)=0
An interface for generating a multi contour polyline as a triangle strip.
virtual void EndContour()=0
virtual void Write(Point point)=0
static void PathToFilledSegments(const PathSource &source, SegmentReceiver &receiver)
static void PathToFilledVertices(const PathSource &source, VertexWriter &writer, Scalar scale)
static std::pair< size_t, size_t > CountFillStorage(const PathSource &source, Scalar scale)
MOCK_METHOD(void, Write,(Point point),(override))
MOCK_METHOD(void, EndContour,(),(override))
MOCK_METHOD(void, RecordLine,(Point p1, Point p2),(override))
MOCK_METHOD(void, RecordCubic,(Point p1, Point cp1, Point cp2, Point p2),(override))
MOCK_METHOD(void, RecordQuad,(Point p1, Point cp, Point p2),(override))
MOCK_METHOD(void, EndContour,(Point origin, bool with_close),(override))
MOCK_METHOD(void, RecordConic,(Point p1, Point cp, Point p2, Scalar weight),(override))
MOCK_METHOD(void, BeginContour,(Point origin, bool will_be_closed),(override))
TEST(AllocationSizeTest, CanCreateTypedAllocations)
std::vector< Point > points
std::vector< Contour > contours