diff options
-rw-r--r-- | src/pathops/SkPathOpsOp.cpp | 53 | ||||
-rw-r--r-- | tests/PathOpsOpRectThreadedTest.cpp | 81 | ||||
-rw-r--r-- | tests/PathOpsOpTest.cpp | 23 |
3 files changed, 149 insertions, 8 deletions
diff --git a/src/pathops/SkPathOpsOp.cpp b/src/pathops/SkPathOpsOp.cpp index ee2b200f62..4dd687922f 100644 --- a/src/pathops/SkPathOpsOp.cpp +++ b/src/pathops/SkPathOpsOp.cpp @@ -217,12 +217,6 @@ extern void (*gVerboseFinalize)(); bool OpDebug(const SkPath& one, const SkPath& two, SkPathOp op, SkPath* result SkDEBUGPARAMS(bool skipAssert) SkDEBUGPARAMS(const char* testName)) { - SkSTArenaAlloc<4096> allocator; // FIXME: add a constant expression here, tune - SkOpContour contour; - SkOpContourHead* contourList = static_cast<SkOpContourHead*>(&contour); - SkOpGlobalState globalState(contourList, &allocator - SkDEBUGPARAMS(skipAssert) SkDEBUGPARAMS(testName)); - SkOpCoincidence coincidence(&globalState); #if DEBUG_DUMP_VERIFY #ifndef SK_DEBUG const char* testName = "release"; @@ -232,8 +226,51 @@ bool OpDebug(const SkPath& one, const SkPath& two, SkPathOp op, SkPath* result } #endif op = gOpInverse[op][one.isInverseFillType()][two.isInverseFillType()]; - SkPath::FillType fillType = gOutInverse[op][one.isInverseFillType()][two.isInverseFillType()] - ? SkPath::kInverseEvenOdd_FillType : SkPath::kEvenOdd_FillType; + bool inverseFill = gOutInverse[op][one.isInverseFillType()][two.isInverseFillType()]; + SkPath::FillType fillType = inverseFill ? SkPath::kInverseEvenOdd_FillType : + SkPath::kEvenOdd_FillType; + SkRect rect1, rect2; + if (kIntersect_SkPathOp == op && one.isRect(&rect1) && two.isRect(&rect2)) { + result->reset(); + result->setFillType(fillType); + if (rect1.intersect(rect2)) { + result->addRect(rect1); + } + return true; + } + if (one.isEmpty() || two.isEmpty()) { + SkPath work; + switch (op) { + case kIntersect_SkPathOp: + break; + case kUnion_SkPathOp: + case kXOR_SkPathOp: + work = one.isEmpty() ? two : one; + break; + case kDifference_SkPathOp: + if (!one.isEmpty()) { + work = one; + } + break; + case kReverseDifference_SkPathOp: + if (!two.isEmpty()) { + work = two; + } + break; + default: + SkASSERT(0); // unhandled case + } + if (inverseFill != work.isInverseFillType()) { + work.toggleInverseFillType(); + } + return Simplify(work, result); + } + SkSTArenaAlloc<4096> allocator; // FIXME: add a constant expression here, tune + SkOpContour contour; + SkOpContourHead* contourList = static_cast<SkOpContourHead*>(&contour); + SkOpGlobalState globalState(contourList, &allocator + SkDEBUGPARAMS(skipAssert) SkDEBUGPARAMS(testName)); + SkOpCoincidence coincidence(&globalState); SkScalar scaleFactor = SkTMax(ScaleFactor(one), ScaleFactor(two)); SkPath scaledOne, scaledTwo; const SkPath* minuend, * subtrahend; diff --git a/tests/PathOpsOpRectThreadedTest.cpp b/tests/PathOpsOpRectThreadedTest.cpp index e904a8d23e..9adcd732a9 100644 --- a/tests/PathOpsOpRectThreadedTest.cpp +++ b/tests/PathOpsOpRectThreadedTest.cpp @@ -99,3 +99,84 @@ DEF_TEST(PathOpsRectsThreaded, reporter) { finish: testRunner.render(); } + +static void testPathOpsFastMain(PathOpsThreadState* data) +{ + SkASSERT(data); + PathOpsThreadState& state = *data; + SkString pathStr; + int step = data->fReporter->allowExtendedTest() ? 2 : 5; + + for (bool a : { false, true } ) { + for (bool b : { false, true } ) { + for (int c = 0; c < 6; c += step) { + for (int d = 0; d < 6; d += step) { + for (int e = SkPath::kWinding_FillType; e <= SkPath::kInverseEvenOdd_FillType; ++e) { + for (int f = SkPath::kWinding_FillType; f <= SkPath::kInverseEvenOdd_FillType; ++f) { + SkPath pathA, pathB; + pathA.setFillType((SkPath::FillType) e); + if (a) { + pathA.addRect(SkIntToScalar(state.fA), SkIntToScalar(state.fA), SkIntToScalar(state.fB) + c, + SkIntToScalar(state.fB), SkPath::kCW_Direction); + } + pathA.close(); + pathB.setFillType((SkPath::FillType) f); + if (b) { + pathB.addRect(SkIntToScalar(state.fC), SkIntToScalar(state.fC), SkIntToScalar(state.fD) + d, + SkIntToScalar(state.fD), SkPath::kCW_Direction); + } + pathB.close(); + const char* fillTypeStr[] = { "Winding", "EvenOdd", "InverseWinding", "InverseEvenOdd" }; + for (int op = 0; op <= kXOR_SkPathOp; ++op) { + if (state.fReporter->verbose()) { + pathStr.printf( + "static void fast%d(skiatest::Reporter* reporter," + "const char* filename) {\n", loopNo); + pathStr.appendf(" SkPath path, pathB;"); + pathStr.appendf(" path.setFillType(SkPath::k%s_FillType);\n", fillTypeStr[e]); + if (a) { + pathStr.appendf(" path.addRect(%d, %d, %d, %d," + " SkPath::kCW_Direction);\n", state.fA, state.fA, state.fB + c, state.fB); + } + pathStr.appendf(" path.setFillType(SkPath::k%s_FillType);\n", fillTypeStr[f]); + if (b) { + pathStr.appendf(" path.addRect(%d, %d, %d, %d," + " SkPath::kCW_Direction);\n", state.fC, state.fC, state.fD + d, state.fD); + } + pathStr.appendf(" testPathOp(reporter, path, pathB, %s, filename);\n", + SkPathOpsDebug::OpStr((SkPathOp) op)); + pathStr.appendf("}\n\n"); + state.outputProgress(pathStr.c_str(), (SkPathOp) op); + } + if (!testPathOp(state.fReporter, pathA, pathB, (SkPathOp) op, "fast")) { + if (state.fReporter->verbose()) { + ++loopNo; + goto skipToNext; + } + } + } + } + } +skipToNext: ; + } + } + } + } +} + +DEF_TEST(PathOpsFastThreaded, reporter) { + initializeTests(reporter, "testOp"); + PathOpsThreadedTestRunner testRunner(reporter); + int step = reporter->allowExtendedTest() ? 2 : 5; + for (int a = 0; a < 6; a += step) { // outermost + for (int b = a + 1; b < 7; b += step) { + for (int c = 0 ; c < 6; c += step) { + for (int d = c + 1; d < 7; d += step) { + *testRunner.fRunnables.append() = new PathOpsThreadedRunnable( + &testPathOpsFastMain, a, b, c, d, &testRunner); + } + } + } + } + testRunner.render(); +} diff --git a/tests/PathOpsOpTest.cpp b/tests/PathOpsOpTest.cpp index cfa9a450a0..52cd8b2a04 100644 --- a/tests/PathOpsOpTest.cpp +++ b/tests/PathOpsOpTest.cpp @@ -5729,6 +5729,28 @@ static void halbug(skiatest::Reporter* reporter, const char* filename) { testPathOp(reporter, path, path2, kIntersect_SkPathOp, filename); } +static void testRect1_u(skiatest::Reporter* reporter, const char* filename) { + SkPath path, pathB; + path.setFillType(SkPath::kWinding_FillType); + path.moveTo(0, 0); + path.lineTo(0, 60); + path.lineTo(60, 60); + path.lineTo(60, 0); + path.close(); + path.moveTo(30, 20); + path.lineTo(30, 50); + path.lineTo(50, 50); + path.lineTo(50, 20); + path.close(); + path.moveTo(24, 20); + path.lineTo(24, 30); + path.lineTo(36, 30); + path.lineTo(36, 20); + path.close(); + pathB.setFillType(SkPath::kWinding_FillType); + testPathOp(reporter, path, pathB, kUnion_SkPathOp, filename); +} + static void (*skipTest)(skiatest::Reporter* , const char* filename) = 0; static void (*firstTest)(skiatest::Reporter* , const char* filename) = 0; static void (*stopTest)(skiatest::Reporter* , const char* filename) = 0; @@ -5736,6 +5758,7 @@ static void (*stopTest)(skiatest::Reporter* , const char* filename) = 0; #define TEST(name) { name, #name } static struct TestDesc tests[] = { + TEST(testRect1_u), TEST(halbug), TEST(seanbug), TEST(android1), |