forked from flutter/engine
/
PathTest.cpp
5648 lines (5049 loc) · 235 KB
/
PathTest.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright 2011 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "include/core/SkCanvas.h"
#include "include/core/SkFont.h"
#include "include/core/SkPaint.h"
#include "include/core/SkPathEffect.h"
#include "include/core/SkRRect.h"
#include "include/core/SkSize.h"
#include "include/core/SkStream.h"
#include "include/core/SkStrokeRec.h"
#include "include/core/SkSurface.h"
#include "include/private/SkTo.h"
#include "include/utils/SkNullCanvas.h"
#include "include/utils/SkParse.h"
#include "include/utils/SkParsePath.h"
#include "include/utils/SkRandom.h"
#include "src/core/SkAutoMalloc.h"
#include "src/core/SkGeometry.h"
#include "src/core/SkPathPriv.h"
#include "src/core/SkReader32.h"
#include "src/core/SkWriter32.h"
#include "tests/Test.h"
#include <cmath>
#include <utility>
#include <vector>
static void set_radii(SkVector radii[4], int index, float rad) {
sk_bzero(radii, sizeof(SkVector) * 4);
radii[index].set(rad, rad);
}
static void test_add_rrect(skiatest::Reporter* reporter, const SkRect& bounds,
const SkVector radii[4]) {
SkRRect rrect;
rrect.setRectRadii(bounds, radii);
REPORTER_ASSERT(reporter, bounds == rrect.rect());
SkPath path;
// this line should not assert in the debug build (from validate)
path.addRRect(rrect);
REPORTER_ASSERT(reporter, bounds == path.getBounds());
}
static void test_skbug_3469(skiatest::Reporter* reporter) {
SkPath path;
path.moveTo(20, 20);
path.quadTo(20, 50, 80, 50);
path.quadTo(20, 50, 20, 80);
REPORTER_ASSERT(reporter, !path.isConvex());
}
static void test_skbug_3239(skiatest::Reporter* reporter) {
const float min = SkBits2Float(0xcb7f16c8); /* -16717512.000000 */
const float max = SkBits2Float(0x4b7f1c1d); /* 16718877.000000 */
const float big = SkBits2Float(0x4b7f1bd7); /* 16718807.000000 */
const float rad = 33436320;
const SkRect rectx = SkRect::MakeLTRB(min, min, max, big);
const SkRect recty = SkRect::MakeLTRB(min, min, big, max);
SkVector radii[4];
for (int i = 0; i < 4; ++i) {
set_radii(radii, i, rad);
test_add_rrect(reporter, rectx, radii);
test_add_rrect(reporter, recty, radii);
}
}
static void make_path_crbug364224(SkPath* path) {
path->reset();
path->moveTo(3.747501373f, 2.724499941f);
path->lineTo(3.747501373f, 3.75f);
path->cubicTo(3.747501373f, 3.88774991f, 3.635501385f, 4.0f, 3.497501373f, 4.0f);
path->lineTo(0.7475013733f, 4.0f);
path->cubicTo(0.6095013618f, 4.0f, 0.4975013733f, 3.88774991f, 0.4975013733f, 3.75f);
path->lineTo(0.4975013733f, 1.0f);
path->cubicTo(0.4975013733f, 0.8622499704f, 0.6095013618f, 0.75f, 0.7475013733f,0.75f);
path->lineTo(3.497501373f, 0.75f);
path->cubicTo(3.50275135f, 0.75f, 3.5070014f, 0.7527500391f, 3.513001442f, 0.753000021f);
path->lineTo(3.715001345f, 0.5512499809f);
path->cubicTo(3.648251295f, 0.5194999576f, 3.575501442f, 0.4999999702f, 3.497501373f, 0.4999999702f);
path->lineTo(0.7475013733f, 0.4999999702f);
path->cubicTo(0.4715013802f, 0.4999999702f, 0.2475013733f, 0.7239999771f, 0.2475013733f, 1.0f);
path->lineTo(0.2475013733f, 3.75f);
path->cubicTo(0.2475013733f, 4.026000023f, 0.4715013504f, 4.25f, 0.7475013733f, 4.25f);
path->lineTo(3.497501373f, 4.25f);
path->cubicTo(3.773501396f, 4.25f, 3.997501373f, 4.026000023f, 3.997501373f, 3.75f);
path->lineTo(3.997501373f, 2.474750042f);
path->lineTo(3.747501373f, 2.724499941f);
path->close();
}
static void make_path_crbug364224_simplified(SkPath* path) {
path->moveTo(3.747501373f, 2.724499941f);
path->cubicTo(3.648251295f, 0.5194999576f, 3.575501442f, 0.4999999702f, 3.497501373f, 0.4999999702f);
path->close();
}
static void test_sect_with_horizontal_needs_pinning() {
// Test that sect_with_horizontal in SkLineClipper.cpp needs to pin after computing the
// intersection.
SkPath path;
path.reset();
path.moveTo(-540000, -720000);
path.lineTo(-9.10000017e-05f, 9.99999996e-13f);
path.lineTo(1, 1);
// Without the pinning code in sect_with_horizontal(), this would assert in the lineclipper
SkPaint paint;
SkSurface::MakeRasterN32Premul(10, 10)->getCanvas()->drawPath(path, paint);
}
static void test_path_crbug364224() {
SkPath path;
SkPaint paint;
auto surface(SkSurface::MakeRasterN32Premul(84, 88));
SkCanvas* canvas = surface->getCanvas();
make_path_crbug364224_simplified(&path);
canvas->drawPath(path, paint);
make_path_crbug364224(&path);
canvas->drawPath(path, paint);
}
static void test_draw_AA_path(int width, int height, const SkPath& path) {
auto surface(SkSurface::MakeRasterN32Premul(width, height));
SkCanvas* canvas = surface->getCanvas();
SkPaint paint;
paint.setAntiAlias(true);
canvas->drawPath(path, paint);
}
// this is a unit test instead of a GM because it doesn't draw anything
static void test_fuzz_crbug_638223() {
SkPath path;
path.moveTo(SkBits2Float(0x47452a00), SkBits2Float(0x43211d01)); // 50474, 161.113f
path.conicTo(SkBits2Float(0x401c0000), SkBits2Float(0x40680000),
SkBits2Float(0x02c25a81), SkBits2Float(0x981a1fa0),
SkBits2Float(0x6bf9abea)); // 2.4375f, 3.625f, 2.85577e-37f, -1.992e-24f, 6.03669e+26f
test_draw_AA_path(250, 250, path);
}
static void test_fuzz_crbug_643933() {
SkPath path;
path.moveTo(0, 0);
path.conicTo(SkBits2Float(0x002001f2), SkBits2Float(0x4161ffff), // 2.93943e-39f, 14.125f
SkBits2Float(0x49f7224d), SkBits2Float(0x45eec8df), // 2.02452e+06f, 7641.11f
SkBits2Float(0x721aee0c)); // 3.0687e+30f
test_draw_AA_path(250, 250, path);
path.reset();
path.moveTo(0, 0);
path.conicTo(SkBits2Float(0x00007ff2), SkBits2Float(0x4169ffff), // 4.58981e-41f, 14.625f
SkBits2Float(0x43ff2261), SkBits2Float(0x41eeea04), // 510.269f, 29.8643f
SkBits2Float(0x5d06eff8)); // 6.07704e+17f
test_draw_AA_path(250, 250, path);
}
static void test_fuzz_crbug_647922() {
SkPath path;
path.moveTo(0, 0);
path.conicTo(SkBits2Float(0x00003939), SkBits2Float(0x42487fff), // 2.05276e-41f, 50.125f
SkBits2Float(0x48082361), SkBits2Float(0x4408e8e9), // 139406, 547.639f
SkBits2Float(0x4d1ade0f)); // 1.6239e+08f
test_draw_AA_path(250, 250, path);
}
static void test_fuzz_crbug_662780() {
auto surface(SkSurface::MakeRasterN32Premul(250, 250));
SkCanvas* canvas = surface->getCanvas();
SkPaint paint;
paint.setAntiAlias(true);
SkPath path;
path.moveTo(SkBits2Float(0x41000000), SkBits2Float(0x431e0000)); // 8, 158
path.lineTo(SkBits2Float(0x41000000), SkBits2Float(0x42f00000)); // 8, 120
// 8, 8, 8.00002f, 8, 0.707107f
path.conicTo(SkBits2Float(0x41000000), SkBits2Float(0x41000000),
SkBits2Float(0x41000010), SkBits2Float(0x41000000), SkBits2Float(0x3f3504f3));
path.lineTo(SkBits2Float(0x439a0000), SkBits2Float(0x41000000)); // 308, 8
// 308, 8, 308, 8, 0.707107f
path.conicTo(SkBits2Float(0x439a0000), SkBits2Float(0x41000000),
SkBits2Float(0x439a0000), SkBits2Float(0x41000000), SkBits2Float(0x3f3504f3));
path.lineTo(SkBits2Float(0x439a0000), SkBits2Float(0x431e0000)); // 308, 158
// 308, 158, 308, 158, 0.707107f
path.conicTo(SkBits2Float(0x439a0000), SkBits2Float(0x431e0000),
SkBits2Float(0x439a0000), SkBits2Float(0x431e0000), SkBits2Float(0x3f3504f3));
path.lineTo(SkBits2Float(0x41000000), SkBits2Float(0x431e0000)); // 8, 158
// 8, 158, 8, 158, 0.707107f
path.conicTo(SkBits2Float(0x41000000), SkBits2Float(0x431e0000),
SkBits2Float(0x41000000), SkBits2Float(0x431e0000), SkBits2Float(0x3f3504f3));
path.close();
canvas->clipPath(path, true);
canvas->drawRect(SkRect::MakeWH(250, 250), paint);
}
static void test_mask_overflow() {
SkPath path;
path.moveTo(SkBits2Float(0x43e28000), SkBits2Float(0x43aa8000)); // 453, 341
path.lineTo(SkBits2Float(0x43de6000), SkBits2Float(0x43aa8000)); // 444.75f, 341
// 440.47f, 341, 437, 344.47f, 437, 348.75f
path.cubicTo(SkBits2Float(0x43dc3c29), SkBits2Float(0x43aa8000),
SkBits2Float(0x43da8000), SkBits2Float(0x43ac3c29),
SkBits2Float(0x43da8000), SkBits2Float(0x43ae6000));
path.lineTo(SkBits2Float(0x43da8000), SkBits2Float(0x43b18000)); // 437, 355
path.lineTo(SkBits2Float(0x43e28000), SkBits2Float(0x43b18000)); // 453, 355
path.lineTo(SkBits2Float(0x43e28000), SkBits2Float(0x43aa8000)); // 453, 341
test_draw_AA_path(500, 500, path);
}
static void test_fuzz_crbug_668907() {
SkPath path;
path.moveTo(SkBits2Float(0x46313741), SkBits2Float(0x3b00e540)); // 11341.8f, 0.00196679f
path.quadTo(SkBits2Float(0x41410041), SkBits2Float(0xc1414141), SkBits2Float(0x41414141),
SkBits2Float(0x414100ff)); // 12.0626f, -12.0784f, 12.0784f, 12.0627f
path.lineTo(SkBits2Float(0x46313741), SkBits2Float(0x3b00e540)); // 11341.8f, 0.00196679f
path.close();
test_draw_AA_path(400, 500, path);
}
/**
* In debug mode, this path was causing an assertion to fail in
* SkPathStroker::preJoinTo() and, in Release, the use of an unitialized value.
*/
static void make_path_crbugskia2820(SkPath* path, skiatest::Reporter* reporter) {
SkPoint orig, p1, p2, p3;
orig = SkPoint::Make(1.f, 1.f);
p1 = SkPoint::Make(1.f - SK_ScalarNearlyZero, 1.f);
p2 = SkPoint::Make(1.f, 1.f + SK_ScalarNearlyZero);
p3 = SkPoint::Make(2.f, 2.f);
path->reset();
path->moveTo(orig);
path->cubicTo(p1, p2, p3);
path->close();
}
static void test_path_crbugskia2820(skiatest::Reporter* reporter) {//GrContext* context) {
SkPath path;
make_path_crbugskia2820(&path, reporter);
SkStrokeRec stroke(SkStrokeRec::kFill_InitStyle);
stroke.setStrokeStyle(2 * SK_Scalar1);
stroke.applyToPath(&path, path);
}
static void test_path_crbugskia5995() {
SkPath path;
path.moveTo(SkBits2Float(0x40303030), SkBits2Float(0x3e303030)); // 2.75294f, 0.172059f
path.quadTo(SkBits2Float(0x41d63030), SkBits2Float(0x30303030), SkBits2Float(0x41013030),
SkBits2Float(0x00000000)); // 26.7735f, 6.40969e-10f, 8.07426f, 0
path.moveTo(SkBits2Float(0x00000000), SkBits2Float(0x00000000)); // 0, 0
test_draw_AA_path(500, 500, path);
}
static void make_path0(SkPath* path) {
// from * https://code.google.com/p/skia/issues/detail?id=1706
path->moveTo(146.939f, 1012.84f);
path->lineTo(181.747f, 1009.18f);
path->lineTo(182.165f, 1013.16f);
path->lineTo(147.357f, 1016.82f);
path->lineTo(146.939f, 1012.84f);
path->close();
}
static void make_path1(SkPath* path) {
path->addRect(SkRect::MakeXYWH(10, 10, 10, 1));
}
typedef void (*PathProc)(SkPath*);
/*
* Regression test: we used to crash (overwrite internal storage) during
* construction of the region when the path was INVERSE. That is now fixed,
* so test these regions (which used to assert/crash).
*
* https://code.google.com/p/skia/issues/detail?id=1706
*/
static void test_path_to_region(skiatest::Reporter* reporter) {
PathProc procs[] = {
make_path0,
make_path1,
};
SkRegion clip;
clip.setRect({0, 0, 1255, 1925});
for (size_t i = 0; i < SK_ARRAY_COUNT(procs); ++i) {
SkPath path;
procs[i](&path);
SkRegion rgn;
rgn.setPath(path, clip);
path.toggleInverseFillType();
rgn.setPath(path, clip);
}
}
#ifdef SK_BUILD_FOR_WIN
#define SUPPRESS_VISIBILITY_WARNING
#else
#define SUPPRESS_VISIBILITY_WARNING __attribute__((visibility("hidden")))
#endif
static void test_path_close_issue1474(skiatest::Reporter* reporter) {
// This test checks that r{Line,Quad,Conic,Cubic}To following a close()
// are relative to the point we close to, not relative to the point we close from.
SkPath path;
SkPoint last;
// Test rLineTo().
path.rLineTo(0, 100);
path.rLineTo(100, 0);
path.close(); // Returns us back to 0,0.
path.rLineTo(50, 50); // This should go to 50,50.
path.getLastPt(&last);
REPORTER_ASSERT(reporter, 50 == last.fX);
REPORTER_ASSERT(reporter, 50 == last.fY);
// Test rQuadTo().
path.rewind();
path.rLineTo(0, 100);
path.rLineTo(100, 0);
path.close();
path.rQuadTo(50, 50, 75, 75);
path.getLastPt(&last);
REPORTER_ASSERT(reporter, 75 == last.fX);
REPORTER_ASSERT(reporter, 75 == last.fY);
// Test rConicTo().
path.rewind();
path.rLineTo(0, 100);
path.rLineTo(100, 0);
path.close();
path.rConicTo(50, 50, 85, 85, 2);
path.getLastPt(&last);
REPORTER_ASSERT(reporter, 85 == last.fX);
REPORTER_ASSERT(reporter, 85 == last.fY);
// Test rCubicTo().
path.rewind();
path.rLineTo(0, 100);
path.rLineTo(100, 0);
path.close();
path.rCubicTo(50, 50, 85, 85, 95, 95);
path.getLastPt(&last);
REPORTER_ASSERT(reporter, 95 == last.fX);
REPORTER_ASSERT(reporter, 95 == last.fY);
}
static void test_gen_id(skiatest::Reporter* reporter) {
SkPath a, b;
REPORTER_ASSERT(reporter, a.getGenerationID() == b.getGenerationID());
a.moveTo(0, 0);
const uint32_t z = a.getGenerationID();
REPORTER_ASSERT(reporter, z != b.getGenerationID());
a.reset();
REPORTER_ASSERT(reporter, a.getGenerationID() == b.getGenerationID());
a.moveTo(1, 1);
const uint32_t y = a.getGenerationID();
REPORTER_ASSERT(reporter, z != y);
b.moveTo(2, 2);
const uint32_t x = b.getGenerationID();
REPORTER_ASSERT(reporter, x != y && x != z);
a.swap(b);
REPORTER_ASSERT(reporter, b.getGenerationID() == y && a.getGenerationID() == x);
b = a;
REPORTER_ASSERT(reporter, b.getGenerationID() == x);
SkPath c(a);
REPORTER_ASSERT(reporter, c.getGenerationID() == x);
c.lineTo(3, 3);
const uint32_t w = c.getGenerationID();
REPORTER_ASSERT(reporter, b.getGenerationID() == x);
REPORTER_ASSERT(reporter, a.getGenerationID() == x);
REPORTER_ASSERT(reporter, w != x);
#ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK
static bool kExpectGenIDToIgnoreFill = false;
#else
static bool kExpectGenIDToIgnoreFill = true;
#endif
c.toggleInverseFillType();
const uint32_t v = c.getGenerationID();
REPORTER_ASSERT(reporter, (v == w) == kExpectGenIDToIgnoreFill);
c.rewind();
REPORTER_ASSERT(reporter, v != c.getGenerationID());
}
// This used to assert in the debug build, as the edges did not all line-up.
static void test_bad_cubic_crbug234190() {
SkPath path;
path.moveTo(13.8509f, 3.16858f);
path.cubicTo(-2.35893e+08f, -4.21044e+08f,
-2.38991e+08f, -4.26573e+08f,
-2.41016e+08f, -4.30188e+08f);
test_draw_AA_path(84, 88, path);
}
static void test_bad_cubic_crbug229478() {
const SkPoint pts[] = {
{ 4595.91064f, -11596.9873f },
{ 4597.2168f, -11595.9414f },
{ 4598.52344f, -11594.8955f },
{ 4599.83008f, -11593.8496f },
};
SkPath path;
path.moveTo(pts[0]);
path.cubicTo(pts[1], pts[2], pts[3]);
SkPaint paint;
paint.setStyle(SkPaint::kStroke_Style);
paint.setStrokeWidth(20);
SkPath dst;
// Before the fix, this would infinite-recurse, and run out of stack
// because we would keep trying to subdivide a degenerate cubic segment.
paint.getFillPath(path, &dst, nullptr);
}
static void build_path_170666(SkPath& path) {
path.moveTo(17.9459f, 21.6344f);
path.lineTo(139.545f, -47.8105f);
path.lineTo(139.545f, -47.8105f);
path.lineTo(131.07f, -47.3888f);
path.lineTo(131.07f, -47.3888f);
path.lineTo(122.586f, -46.9532f);
path.lineTo(122.586f, -46.9532f);
path.lineTo(18076.6f, 31390.9f);
path.lineTo(18076.6f, 31390.9f);
path.lineTo(18085.1f, 31390.5f);
path.lineTo(18085.1f, 31390.5f);
path.lineTo(18076.6f, 31390.9f);
path.lineTo(18076.6f, 31390.9f);
path.lineTo(17955, 31460.3f);
path.lineTo(17955, 31460.3f);
path.lineTo(17963.5f, 31459.9f);
path.lineTo(17963.5f, 31459.9f);
path.lineTo(17971.9f, 31459.5f);
path.lineTo(17971.9f, 31459.5f);
path.lineTo(17.9551f, 21.6205f);
path.lineTo(17.9551f, 21.6205f);
path.lineTo(9.47091f, 22.0561f);
path.lineTo(9.47091f, 22.0561f);
path.lineTo(17.9459f, 21.6344f);
path.lineTo(17.9459f, 21.6344f);
path.close();path.moveTo(0.995934f, 22.4779f);
path.lineTo(0.986725f, 22.4918f);
path.lineTo(0.986725f, 22.4918f);
path.lineTo(17955, 31460.4f);
path.lineTo(17955, 31460.4f);
path.lineTo(17971.9f, 31459.5f);
path.lineTo(17971.9f, 31459.5f);
path.lineTo(18093.6f, 31390.1f);
path.lineTo(18093.6f, 31390.1f);
path.lineTo(18093.6f, 31390);
path.lineTo(18093.6f, 31390);
path.lineTo(139.555f, -47.8244f);
path.lineTo(139.555f, -47.8244f);
path.lineTo(122.595f, -46.9671f);
path.lineTo(122.595f, -46.9671f);
path.lineTo(0.995934f, 22.4779f);
path.lineTo(0.995934f, 22.4779f);
path.close();
path.moveTo(5.43941f, 25.5223f);
path.lineTo(798267, -28871.1f);
path.lineTo(798267, -28871.1f);
path.lineTo(3.12512e+06f, -113102);
path.lineTo(3.12512e+06f, -113102);
path.cubicTo(5.16324e+06f, -186882, 8.15247e+06f, -295092, 1.1957e+07f, -432813);
path.cubicTo(1.95659e+07f, -708257, 3.04359e+07f, -1.10175e+06f, 4.34798e+07f, -1.57394e+06f);
path.cubicTo(6.95677e+07f, -2.51831e+06f, 1.04352e+08f, -3.77748e+06f, 1.39135e+08f, -5.03666e+06f);
path.cubicTo(1.73919e+08f, -6.29583e+06f, 2.08703e+08f, -7.555e+06f, 2.34791e+08f, -8.49938e+06f);
path.cubicTo(2.47835e+08f, -8.97157e+06f, 2.58705e+08f, -9.36506e+06f, 2.66314e+08f, -9.6405e+06f);
path.cubicTo(2.70118e+08f, -9.77823e+06f, 2.73108e+08f, -9.88644e+06f, 2.75146e+08f, -9.96022e+06f);
path.cubicTo(2.76165e+08f, -9.99711e+06f, 2.76946e+08f, -1.00254e+07f, 2.77473e+08f, -1.00444e+07f);
path.lineTo(2.78271e+08f, -1.00733e+07f);
path.lineTo(2.78271e+08f, -1.00733e+07f);
path.cubicTo(2.78271e+08f, -1.00733e+07f, 2.08703e+08f, -7.555e+06f, 135.238f, 23.3517f);
path.cubicTo(131.191f, 23.4981f, 125.995f, 23.7976f, 123.631f, 24.0206f);
path.cubicTo(121.267f, 24.2436f, 122.631f, 24.3056f, 126.677f, 24.1591f);
path.cubicTo(2.08703e+08f, -7.555e+06f, 2.78271e+08f, -1.00733e+07f, 2.78271e+08f, -1.00733e+07f);
path.lineTo(2.77473e+08f, -1.00444e+07f);
path.lineTo(2.77473e+08f, -1.00444e+07f);
path.cubicTo(2.76946e+08f, -1.00254e+07f, 2.76165e+08f, -9.99711e+06f, 2.75146e+08f, -9.96022e+06f);
path.cubicTo(2.73108e+08f, -9.88644e+06f, 2.70118e+08f, -9.77823e+06f, 2.66314e+08f, -9.6405e+06f);
path.cubicTo(2.58705e+08f, -9.36506e+06f, 2.47835e+08f, -8.97157e+06f, 2.34791e+08f, -8.49938e+06f);
path.cubicTo(2.08703e+08f, -7.555e+06f, 1.73919e+08f, -6.29583e+06f, 1.39135e+08f, -5.03666e+06f);
path.cubicTo(1.04352e+08f, -3.77749e+06f, 6.95677e+07f, -2.51831e+06f, 4.34798e+07f, -1.57394e+06f);
path.cubicTo(3.04359e+07f, -1.10175e+06f, 1.95659e+07f, -708258, 1.1957e+07f, -432814);
path.cubicTo(8.15248e+06f, -295092, 5.16324e+06f, -186883, 3.12513e+06f, -113103);
path.lineTo(798284, -28872);
path.lineTo(798284, -28872);
path.lineTo(22.4044f, 24.6677f);
path.lineTo(22.4044f, 24.6677f);
path.cubicTo(22.5186f, 24.5432f, 18.8134f, 24.6337f, 14.1287f, 24.8697f);
path.cubicTo(9.4439f, 25.1057f, 5.55359f, 25.3978f, 5.43941f, 25.5223f);
path.close();
}
static void build_path_simple_170666(SkPath& path) {
path.moveTo(126.677f, 24.1591f);
path.cubicTo(2.08703e+08f, -7.555e+06f, 2.78271e+08f, -1.00733e+07f, 2.78271e+08f, -1.00733e+07f);
}
// This used to assert in the SK_DEBUG build, as the clip step would fail with
// too-few interations in our cubic-line intersection code. That code now runs
// 24 interations (instead of 16).
static void test_crbug_170666() {
SkPath path;
build_path_simple_170666(path);
test_draw_AA_path(1000, 1000, path);
build_path_170666(path);
test_draw_AA_path(1000, 1000, path);
}
static void test_tiny_path_convexity(skiatest::Reporter* reporter, const char* pathBug,
SkScalar tx, SkScalar ty, SkScalar scale) {
SkPath smallPath;
SkAssertResult(SkParsePath::FromSVGString(pathBug, &smallPath));
bool smallConvex = smallPath.isConvex();
SkPath largePath;
SkAssertResult(SkParsePath::FromSVGString(pathBug, &largePath));
SkMatrix matrix;
matrix.reset();
matrix.preTranslate(100, 100);
matrix.preScale(scale, scale);
largePath.transform(matrix);
bool largeConvex = largePath.isConvex();
REPORTER_ASSERT(reporter, smallConvex == largeConvex);
}
static void test_crbug_493450(skiatest::Reporter* reporter) {
const char reducedCase[] =
"M0,0"
"L0.0002, 0"
"L0.0002, 0.0002"
"L0.0001, 0.0001"
"L0,0.0002"
"Z";
test_tiny_path_convexity(reporter, reducedCase, 100, 100, 100000);
const char originalFiddleData[] =
"M-0.3383152268862998,-0.11217565719203619L-0.33846085183212765,-0.11212264406895281"
"L-0.338509393480737,-0.11210607966681395L-0.33857792286700894,-0.1121889121487573"
"L-0.3383866116636664,-0.11228834570924921L-0.33842087635680235,-0.11246078673250548"
"L-0.33809536177201055,-0.11245415228342878L-0.33797257995493996,-0.11216571641452182"
"L-0.33802112160354925,-0.11201996164188659L-0.33819815585141844,-0.11218559834671019Z";
test_tiny_path_convexity(reporter, originalFiddleData, 280081.4116670522f, 93268.04618493588f,
826357.3384828606f);
}
static void test_crbug_495894(skiatest::Reporter* reporter) {
const char originalFiddleData[] =
"M-0.34004273849857214,-0.11332803232216355L-0.34008271397389744,-0.11324483772714951"
"L-0.3401940742265893,-0.11324483772714951L-0.34017694188002134,-0.11329807920275889"
"L-0.3402026403998733,-0.11333468903941245L-0.34029972369709194,-0.11334134592705701"
"L-0.3403054344792813,-0.11344121970007795L-0.3403140006525653,-0.11351115418399343"
"L-0.34024261587519866,-0.11353446986281181L-0.3402197727464413,-0.11360442946144192"
"L-0.34013696640469604,-0.11359110237029302L-0.34009128014718143,-0.1135877707043939"
"L-0.3400598708451401,-0.11360776134112742L-0.34004273849857214,-0.11355112520064405"
"L-0.3400113291965308,-0.11355112520064405L-0.3399970522410575,-0.11359110237029302"
"L-0.33997135372120546,-0.11355112520064405L-0.3399627875479215,-0.11353780084493197"
"L-0.3399485105924481,-0.11350782354357004L-0.3400027630232468,-0.11346452910331437"
"L-0.3399485105924481,-0.11340126558629839L-0.33993994441916414,-0.11340126558629839"
"L-0.33988283659727087,-0.11331804756574679L-0.33989140277055485,-0.11324483772714951"
"L-0.33997991989448945,-0.11324483772714951L-0.3399856306766788,-0.11324483772714951"
"L-0.34002560615200417,-0.11334467443478255ZM-0.3400684370184241,-0.11338461985124307"
"L-0.340154098751264,-0.11341791238732665L-0.340162664924548,-0.1134378899559977"
"L-0.34017979727111597,-0.11340126558629839L-0.3401655203156427,-0.11338129083212668"
"L-0.34012268944922275,-0.11332137577529414L-0.34007414780061346,-0.11334467443478255Z"
"M-0.3400027630232468,-0.11290567901106024L-0.3400113291965308,-0.11298876531245433"
"L-0.33997991989448945,-0.11301535852306784L-0.33990282433493346,-0.11296217481488612"
"L-0.33993994441916414,-0.11288906492739594Z";
test_tiny_path_convexity(reporter, originalFiddleData, 22682.240000000005f,7819.72220766405f,
65536);
}
static void test_crbug_613918() {
SkPath path;
path.conicTo(-6.62478e-08f, 4.13885e-08f, -6.36935e-08f, 3.97927e-08f, 0.729058f);
path.quadTo(2.28206e-09f, -1.42572e-09f, 3.91919e-09f, -2.44852e-09f);
path.cubicTo(-16752.2f, -26792.9f, -21.4673f, 10.9347f, -8.57322f, -7.22739f);
// This call could lead to an assert or uninitialized read due to a failure
// to check the return value from SkCubicClipper::ChopMonoAtY.
path.contains(-1.84817e-08f, 1.15465e-08f);
}
static void test_addrect(skiatest::Reporter* reporter) {
SkPath path;
path.lineTo(0, 0);
path.addRect(SkRect::MakeWH(50, 100));
REPORTER_ASSERT(reporter, path.isRect(nullptr));
path.reset();
path.lineTo(FLT_EPSILON, FLT_EPSILON);
path.addRect(SkRect::MakeWH(50, 100));
REPORTER_ASSERT(reporter, !path.isRect(nullptr));
path.reset();
path.quadTo(0, 0, 0, 0);
path.addRect(SkRect::MakeWH(50, 100));
REPORTER_ASSERT(reporter, !path.isRect(nullptr));
path.reset();
path.conicTo(0, 0, 0, 0, 0.5f);
path.addRect(SkRect::MakeWH(50, 100));
REPORTER_ASSERT(reporter, !path.isRect(nullptr));
path.reset();
path.cubicTo(0, 0, 0, 0, 0, 0);
path.addRect(SkRect::MakeWH(50, 100));
REPORTER_ASSERT(reporter, !path.isRect(nullptr));
}
// Make sure we stay non-finite once we get there (unless we reset or rewind).
static void test_addrect_isfinite(skiatest::Reporter* reporter) {
SkPath path;
path.addRect(SkRect::MakeWH(50, 100));
REPORTER_ASSERT(reporter, path.isFinite());
path.moveTo(0, 0);
path.lineTo(SK_ScalarInfinity, 42);
REPORTER_ASSERT(reporter, !path.isFinite());
path.addRect(SkRect::MakeWH(50, 100));
REPORTER_ASSERT(reporter, !path.isFinite());
path.reset();
REPORTER_ASSERT(reporter, path.isFinite());
path.addRect(SkRect::MakeWH(50, 100));
REPORTER_ASSERT(reporter, path.isFinite());
}
static void build_big_path(SkPath* path, bool reducedCase) {
if (reducedCase) {
path->moveTo(577330, 1971.72f);
path->cubicTo(10.7082f, -116.596f, 262.057f, 45.6468f, 294.694f, 1.96237f);
} else {
path->moveTo(60.1631f, 7.70567f);
path->quadTo(60.1631f, 7.70567f, 0.99474f, 0.901199f);
path->lineTo(577379, 1977.77f);
path->quadTo(577364, 1979.57f, 577325, 1980.26f);
path->quadTo(577286, 1980.95f, 577245, 1980.13f);
path->quadTo(577205, 1979.3f, 577187, 1977.45f);
path->quadTo(577168, 1975.6f, 577183, 1973.8f);
path->quadTo(577198, 1972, 577238, 1971.31f);
path->quadTo(577277, 1970.62f, 577317, 1971.45f);
path->quadTo(577330, 1971.72f, 577341, 1972.11f);
path->cubicTo(10.7082f, -116.596f, 262.057f, 45.6468f, 294.694f, 1.96237f);
path->moveTo(306.718f, -32.912f);
path->cubicTo(30.531f, 10.0005f, 1502.47f, 13.2804f, 84.3088f, 9.99601f);
}
}
static void test_clipped_cubic() {
auto surface(SkSurface::MakeRasterN32Premul(640, 480));
// This path used to assert, because our cubic-chopping code incorrectly
// moved control points after the chop. This test should be run in SK_DEBUG
// mode to ensure that we no long assert.
SkPath path;
for (int doReducedCase = 0; doReducedCase <= 1; ++doReducedCase) {
build_big_path(&path, SkToBool(doReducedCase));
SkPaint paint;
for (int doAA = 0; doAA <= 1; ++doAA) {
paint.setAntiAlias(SkToBool(doAA));
surface->getCanvas()->drawPath(path, paint);
}
}
}
static void dump_if_ne(skiatest::Reporter* reporter, const SkRect& expected, const SkRect& bounds) {
if (expected != bounds) {
ERRORF(reporter, "path.getBounds() returned [%g %g %g %g], but expected [%g %g %g %g]",
bounds.left(), bounds.top(), bounds.right(), bounds.bottom(),
expected.left(), expected.top(), expected.right(), expected.bottom());
}
}
static void test_bounds_crbug_513799(skiatest::Reporter* reporter) {
SkPath path;
#if 0
// As written these tests were failing on LLVM 4.2 MacMini Release mysteriously, so we've
// rewritten them to avoid this (compiler-bug?).
REPORTER_ASSERT(reporter, SkRect::MakeLTRB(0, 0, 0, 0) == path.getBounds());
path.moveTo(-5, -8);
REPORTER_ASSERT(reporter, SkRect::MakeLTRB(-5, -8, -5, -8) == path.getBounds());
path.addRect(SkRect::MakeLTRB(1, 2, 3, 4));
REPORTER_ASSERT(reporter, SkRect::MakeLTRB(-5, -8, 3, 4) == path.getBounds());
path.moveTo(1, 2);
REPORTER_ASSERT(reporter, SkRect::MakeLTRB(-5, -8, 3, 4) == path.getBounds());
#else
dump_if_ne(reporter, SkRect::MakeLTRB(0, 0, 0, 0), path.getBounds());
path.moveTo(-5, -8); // should set the bounds
dump_if_ne(reporter, SkRect::MakeLTRB(-5, -8, -5, -8), path.getBounds());
path.addRect(SkRect::MakeLTRB(1, 2, 3, 4)); // should extend the bounds
dump_if_ne(reporter, SkRect::MakeLTRB(-5, -8, 3, 4), path.getBounds());
path.moveTo(1, 2); // don't expect this to have changed the bounds
dump_if_ne(reporter, SkRect::MakeLTRB(-5, -8, 3, 4), path.getBounds());
#endif
}
#include "include/core/SkSurface.h"
static void test_fuzz_crbug_627414(skiatest::Reporter* reporter) {
SkPath path;
path.moveTo(0, 0);
path.conicTo(3.58732e-43f, 2.72084f, 3.00392f, 3.00392f, 8.46e+37f);
test_draw_AA_path(100, 100, path);
}
// Inspired by http://ie.microsoft.com/testdrive/Performance/Chalkboard/
// which triggered an assert, from a tricky cubic. This test replicates that
// example, so we can ensure that we handle it (in SkEdge.cpp), and don't
// assert in the SK_DEBUG build.
static void test_tricky_cubic() {
const SkPoint pts[] = {
{ SkDoubleToScalar(18.8943768), SkDoubleToScalar(129.121277) },
{ SkDoubleToScalar(18.8937435), SkDoubleToScalar(129.121689) },
{ SkDoubleToScalar(18.8950119), SkDoubleToScalar(129.120422) },
{ SkDoubleToScalar(18.5030727), SkDoubleToScalar(129.13121) },
};
SkPath path;
path.moveTo(pts[0]);
path.cubicTo(pts[1], pts[2], pts[3]);
test_draw_AA_path(19, 130, path);
}
// Inspired by http://code.google.com/p/chromium/issues/detail?id=141651
//
static void test_isfinite_after_transform(skiatest::Reporter* reporter) {
SkPath path;
path.quadTo(157, 366, 286, 208);
path.arcTo(37, 442, 315, 163, 957494590897113.0f);
SkMatrix matrix;
matrix.setScale(1000*1000, 1000*1000);
// Be sure that path::transform correctly updates isFinite and the bounds
// if the transformation overflows. The previous bug was that isFinite was
// set to true in this case, but the bounds were not set to empty (which
// they should be).
while (path.isFinite()) {
REPORTER_ASSERT(reporter, path.getBounds().isFinite());
REPORTER_ASSERT(reporter, !path.getBounds().isEmpty());
path.transform(matrix);
}
REPORTER_ASSERT(reporter, path.getBounds().isEmpty());
matrix.setTranslate(SK_Scalar1, SK_Scalar1);
path.transform(matrix);
// we need to still be non-finite
REPORTER_ASSERT(reporter, !path.isFinite());
REPORTER_ASSERT(reporter, path.getBounds().isEmpty());
}
static void add_corner_arc(SkPath* path, const SkRect& rect,
SkScalar xIn, SkScalar yIn,
int startAngle)
{
SkScalar rx = std::min(rect.width(), xIn);
SkScalar ry = std::min(rect.height(), yIn);
SkRect arcRect;
arcRect.setLTRB(-rx, -ry, rx, ry);
switch (startAngle) {
case 0:
arcRect.offset(rect.fRight - arcRect.fRight, rect.fBottom - arcRect.fBottom);
break;
case 90:
arcRect.offset(rect.fLeft - arcRect.fLeft, rect.fBottom - arcRect.fBottom);
break;
case 180:
arcRect.offset(rect.fLeft - arcRect.fLeft, rect.fTop - arcRect.fTop);
break;
case 270:
arcRect.offset(rect.fRight - arcRect.fRight, rect.fTop - arcRect.fTop);
break;
default:
break;
}
path->arcTo(arcRect, SkIntToScalar(startAngle), SkIntToScalar(90), false);
}
static void make_arb_round_rect(SkPath* path, const SkRect& r,
SkScalar xCorner, SkScalar yCorner) {
// we are lazy here and use the same x & y for each corner
add_corner_arc(path, r, xCorner, yCorner, 270);
add_corner_arc(path, r, xCorner, yCorner, 0);
add_corner_arc(path, r, xCorner, yCorner, 90);
add_corner_arc(path, r, xCorner, yCorner, 180);
path->close();
}
// Chrome creates its own round rects with each corner possibly being different.
// Performance will suffer if they are not convex.
// Note: PathBench::ArbRoundRectBench performs almost exactly
// the same test (but with drawing)
static void test_arb_round_rect_is_convex(skiatest::Reporter* reporter) {
SkRandom rand;
SkRect r;
for (int i = 0; i < 5000; ++i) {
SkScalar size = rand.nextUScalar1() * 30;
if (size < SK_Scalar1) {
continue;
}
r.fLeft = rand.nextUScalar1() * 300;
r.fTop = rand.nextUScalar1() * 300;
r.fRight = r.fLeft + 2 * size;
r.fBottom = r.fTop + 2 * size;
SkPath temp;
make_arb_round_rect(&temp, r, r.width() / 10, r.height() / 15);
REPORTER_ASSERT(reporter, temp.isConvex());
}
}
// Chrome will sometimes create a 0 radius round rect. The degenerate
// quads prevent the path from being converted to a rect
// Note: PathBench::ArbRoundRectBench performs almost exactly
// the same test (but with drawing)
static void test_arb_zero_rad_round_rect_is_rect(skiatest::Reporter* reporter) {
SkRandom rand;
SkRect r;
for (int i = 0; i < 5000; ++i) {
SkScalar size = rand.nextUScalar1() * 30;
if (size < SK_Scalar1) {
continue;
}
r.fLeft = rand.nextUScalar1() * 300;
r.fTop = rand.nextUScalar1() * 300;
r.fRight = r.fLeft + 2 * size;
r.fBottom = r.fTop + 2 * size;
SkPath temp;
make_arb_round_rect(&temp, r, 0, 0);
SkRect result;
REPORTER_ASSERT(reporter, temp.isRect(&result));
REPORTER_ASSERT(reporter, r == result);
}
}
static void test_rect_isfinite(skiatest::Reporter* reporter) {
const SkScalar inf = SK_ScalarInfinity;
const SkScalar negInf = SK_ScalarNegativeInfinity;
const SkScalar nan = SK_ScalarNaN;
SkRect r;
r.setEmpty();
REPORTER_ASSERT(reporter, r.isFinite());
r.setLTRB(0, 0, inf, negInf);
REPORTER_ASSERT(reporter, !r.isFinite());
r.setLTRB(0, 0, nan, 0);
REPORTER_ASSERT(reporter, !r.isFinite());
SkPoint pts[] = {
{ 0, 0 },
{ SK_Scalar1, 0 },
{ 0, SK_Scalar1 },
};
bool isFine = r.setBoundsCheck(pts, 3);
REPORTER_ASSERT(reporter, isFine);
REPORTER_ASSERT(reporter, !r.isEmpty());
pts[1].set(inf, 0);
isFine = r.setBoundsCheck(pts, 3);
REPORTER_ASSERT(reporter, !isFine);
REPORTER_ASSERT(reporter, r.isEmpty());
pts[1].set(nan, 0);
isFine = r.setBoundsCheck(pts, 3);
REPORTER_ASSERT(reporter, !isFine);
REPORTER_ASSERT(reporter, r.isEmpty());
}
static void test_path_isfinite(skiatest::Reporter* reporter) {
const SkScalar inf = SK_ScalarInfinity;
const SkScalar negInf = SK_ScalarNegativeInfinity;
const SkScalar nan = SK_ScalarNaN;
SkPath path;
REPORTER_ASSERT(reporter, path.isFinite());
path.reset();
REPORTER_ASSERT(reporter, path.isFinite());
path.reset();
path.moveTo(SK_Scalar1, 0);
REPORTER_ASSERT(reporter, path.isFinite());
path.reset();
path.moveTo(inf, negInf);
REPORTER_ASSERT(reporter, !path.isFinite());
path.reset();
path.moveTo(nan, 0);
REPORTER_ASSERT(reporter, !path.isFinite());
}
static void test_isfinite(skiatest::Reporter* reporter) {
test_rect_isfinite(reporter);
test_path_isfinite(reporter);
}
static void test_islastcontourclosed(skiatest::Reporter* reporter) {
SkPath path;
REPORTER_ASSERT(reporter, !path.isLastContourClosed());
path.moveTo(0, 0);
REPORTER_ASSERT(reporter, !path.isLastContourClosed());
path.close();
REPORTER_ASSERT(reporter, path.isLastContourClosed());
path.lineTo(100, 100);
REPORTER_ASSERT(reporter, !path.isLastContourClosed());
path.moveTo(200, 200);
REPORTER_ASSERT(reporter, !path.isLastContourClosed());
path.close();
REPORTER_ASSERT(reporter, path.isLastContourClosed());
path.moveTo(0, 0);
REPORTER_ASSERT(reporter, !path.isLastContourClosed());
}
// assert that we always
// start with a moveTo
// only have 1 moveTo
// only have Lines after that
// end with a single close
// only have (at most) 1 close
//
static void test_poly(skiatest::Reporter* reporter, const SkPath& path,
const SkPoint srcPts[], bool expectClose) {
SkPath::RawIter iter(path);
SkPoint pts[4];
bool firstTime = true;
bool foundClose = false;
for (;;) {
switch (iter.next(pts)) {
case SkPath::kMove_Verb:
REPORTER_ASSERT(reporter, firstTime);
REPORTER_ASSERT(reporter, pts[0] == srcPts[0]);
srcPts++;
firstTime = false;
break;
case SkPath::kLine_Verb:
REPORTER_ASSERT(reporter, !firstTime);
REPORTER_ASSERT(reporter, pts[1] == srcPts[0]);
srcPts++;
break;
case SkPath::kQuad_Verb:
REPORTER_ASSERT(reporter, false, "unexpected quad verb");
break;
case SkPath::kConic_Verb:
REPORTER_ASSERT(reporter, false, "unexpected conic verb");
break;
case SkPath::kCubic_Verb:
REPORTER_ASSERT(reporter, false, "unexpected cubic verb");