xref: /aosp_15_r20/external/skia/tests/PreChopPathCurvesTest.cpp (revision c8dee2aa9b3f27cf6c858bd81872bdeb2c07ed17)
1 /*
2  * Copyright 2021 Google Inc.
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 "include/core/SkMatrix.h"
9 #include "include/core/SkPath.h"
10 #include "src/gpu/tessellate/Tessellation.h"
11 #include "tests/Test.h"
12 
13 namespace skgpu::tess {
14 
DEF_TEST(PreChopPathCurves,reporter)15 DEF_TEST(PreChopPathCurves, reporter) {
16     // These particular test cases can get stuck in infinite recursion due to limited fp32
17     // precision. (Although they will not with the provided tessellationPrecision values; we had to
18     // lower precision in order to avoid the "viewport size" assert in PreChopPathCurves.) Bump the
19     // tessellationPreciion up to 4 and run these tests in order to verify our bail condition for
20     // infinite recursion caused by bad fp32 precision. If the test completes, it passed.
21     SkPath p = SkPath().moveTo(11.171727877046647f, -11.78621173228717f)
22                        .quadTo(11.171727877046647f, -11.78621173228717f,
23                                8.33583747124031f, 77.27177002747368f)
24                        .cubicTo(8.33583747124031f, 77.27177002747368f,
25                                 8.33583747124031f, 77.27177002747368f,
26                                 11.171727877046647f, -11.78621173228717f)
27                        .conicTo(11.171727877046647f, -11.78621173228717f,
28                                 8.33583747124031f, 77.27177002747368f,
29                                 1e-6f)
30                        .conicTo(8.33583747124031f, 77.27177002747368f,
31                                 11.171727877046647f, -11.78621173228717f,
32                                 1e6f);
33 
34     SkMatrix m = SkMatrix::Scale(138.68622826903837f, 74192976757580.44189f);
35     PreChopPathCurves(1/16.f, p, m, {1000, -74088852800000.f, 3000, -74088852700000.f});
36 
37     m = SkMatrix::Scale(138.68622826903837f, 74192976757580.44189f*.3f);
38     PreChopPathCurves(.25f, p, m, {1000, -22226658140000.f, 3000, -22226658130000.f});
39 
40     m = SkMatrix::Scale(138.68622826903837f, 74192976757580.44189f/4);
41     PreChopPathCurves(.25f, p, m, {1000, -18522213200000.f, 3000, -18522213100000.f});
42 }
43 
44 }  // namespace skgpu::tess
45