Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
PathOpsOpLoopThreadedTest.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2014 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 */
14#include "tests/PathOpsDebug.h"
17#include "tests/Test.h"
18
19#include <atomic>
20
21static int loopNo = 17;
22
23static void add_point(SkString* str, SkScalar x, SkScalar y) {
24 int asInt = SkScalarRoundToInt(x);
25 if (SkIntToScalar(asInt) == x) {
26 str->appendf("%d", asInt);
27 } else {
28 str->appendf("%1.9gf", x);
29 }
30 str->appendf(",");
31 asInt = SkScalarRoundToInt(y);
32 if (SkIntToScalar(asInt) == y) {
33 str->appendf("%d", asInt);
34 } else {
35 str->appendf("%1.9gf", y);
36 }
37}
38
39static std::atomic<int> gLoopsTestNo{0};
40
42 SkASSERT(data);
44 SkString pathStr;
45 for (int a = 0 ; a < 6; ++a) {
46 for (int b = a + 1 ; b < 7; ++b) {
47 for (int c = 0 ; c < 6; ++c) {
48 for (int d = c + 1 ; d < 7; ++d) {
49 // define 4 points that form two lines that often cross; one line is (a, b) (c, d)
50 SkVector v = {SkIntToScalar(a - c), SkIntToScalar(b - d)};
51 SkPoint midA = { SkIntToScalar(a * state.fA + c * (6 - state.fA)) / 6,
52 SkIntToScalar(b * state.fA + d * (6 - state.fA)) / 6 };
53 SkPoint midB = { SkIntToScalar(a * state.fB + c * (6 - state.fB)) / 6,
54 SkIntToScalar(b * state.fB + d * (6 - state.fB)) / 6 };
55 SkPoint endC = { midA.fX + v.fY * state.fC / 3,
56 midA.fY + v.fX * state.fC / 3 };
57 SkPoint endD = { midB.fX - v.fY * state.fD / 3,
58 midB.fY + v.fX * state.fD / 3 };
59 SkPath pathA, pathB;
61 pathA.cubicTo(SkIntToScalar(c), SkIntToScalar(d), endC.fX, endC.fY, endD.fX, endD.fY);
62 pathA.close();
64 pathB.cubicTo(endC.fX, endC.fY, endD.fX, endD.fY, SkIntToScalar(a), SkIntToScalar(b));
65 pathB.close();
66// SkDebugf("%s\n", pathStr);
67 if (state.fReporter->verbose()) {
68 pathStr.printf("static void loop%d(skiatest::Reporter* reporter,"
69 " const char* filename) {\n", loopNo);
70 pathStr.appendf(" SkPath path, pathB;\n");
71 pathStr.appendf(" path.moveTo(%d,%d);\n", a, b);
72 pathStr.appendf(" path.cubicTo(%d,%d, ", c, d);
73 add_point(&pathStr, endC.fX, endC.fY);
74 pathStr.appendf(", ");
75 add_point(&pathStr, endD.fX, endD.fY);
76 pathStr.appendf(");\n");
77 pathStr.appendf(" path.close();\n");
78 pathStr.appendf(" pathB.moveTo(%d,%d);\n", c, d);
79 pathStr.appendf(" pathB.cubicTo(");
80 add_point(&pathStr, endC.fX, endC.fY);
81 pathStr.appendf(", ");
82 add_point(&pathStr, endD.fX, endD.fY);
83 pathStr.appendf(", %d,%d);\n", a, b);
84 pathStr.appendf(" pathB.close();\n");
85 pathStr.appendf(" testPathOp(reporter, path, pathB, kIntersect_SkPathOp,"
86 " filename);\n");
87 pathStr.appendf("}\n");
88 state.outputProgress(pathStr.c_str(), kIntersect_SkPathOp);
89 }
90 SkString testName;
91 testName.printf("thread_loops%d", ++gLoopsTestNo);
92 testPathOp(state.fReporter, pathA, pathB, kIntersect_SkPathOp, testName.c_str());
94 }
95 }
96 }
97 }
98}
99
100DEF_TEST(PathOpsOpLoopsThreaded, reporter) {
101 initializeTests(reporter, "loopOp");
103 for (int a = 0; a < 6; ++a) { // outermost
104 for (int b = a + 1; b < 7; ++b) {
105 for (int c = 0 ; c < 6; ++c) {
106 for (int d = c + 1; d < 7; ++d) {
107 *testRunner.fRunnables.append() =
108 new PathOpsThreadedRunnable(&testOpLoopsMain, a, b, c, d, &testRunner);
109 }
110 }
111 if (!reporter->allowExtendedTest()) goto finish;
112 }
113 }
114finish:
115 testRunner.render();
116}
reporter
bool testPathOp(skiatest::Reporter *reporter, const SkPath &a, const SkPath &b, const SkPathOp shapeOp, const char *testName)
void initializeTests(skiatest::Reporter *reporter, const char *test)
static void add_point(SkString *str, SkScalar x, SkScalar y)
static int loopNo
static void testOpLoopsMain(PathOpsThreadState *data)
static std::atomic< int > gLoopsTestNo
#define SkASSERT(cond)
Definition SkAssert.h:116
@ kIntersect_SkPathOp
intersect the two paths
Definition SkPathOps.h:24
#define SkScalarRoundToInt(x)
Definition SkScalar.h:37
#define SkIntToScalar(x)
Definition SkScalar.h:57
#define DEF_TEST(name, reporter)
Definition Test.h:312
static bool gCheckForDuplicateNames
SkTDArray< PathOpsThreadedRunnable * > fRunnables
SkPath & moveTo(SkScalar x, SkScalar y)
Definition SkPath.cpp:678
SkPath & cubicTo(SkScalar x1, SkScalar y1, SkScalar x2, SkScalar y2, SkScalar x3, SkScalar y3)
Definition SkPath.cpp:789
SkPath & close()
Definition SkPath.cpp:813
void printf(const char format[],...) SK_PRINTF_LIKE(2
Definition SkString.cpp:534
const char * c_str() const
Definition SkString.h:133
void void void appendf(const char format[],...) SK_PRINTF_LIKE(2
Definition SkString.cpp:550
T * append()
Definition SkTDArray.h:191
VULKAN_HPP_DEFAULT_DISPATCH_LOADER_DYNAMIC_STORAGE auto & d
Definition main.cc:19
float SkScalar
Definition extension.cpp:12
static bool b
struct MyStruct a[10]
AtkStateType state
double y
double x
float fX
x-axis value
float fY
y-axis value