1/* 2 * Copyright 2015 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#include "include/core/SkString.h" 8#include "tests/PathOpsDebug.h" 9#include "tests/PathOpsExtendedTest.h" 10#include "tests/PathOpsThreadedCommon.h" 11 12#include <atomic> 13 14static int loopNo = 4; 15static std::atomic<int> gCirclesTestNo{0}; 16 17static void testOpCirclesMain(PathOpsThreadState* data) { 18 SkASSERT(data); 19 const SkPathFillType fts[] = { SkPathFillType::kWinding, SkPathFillType::kEvenOdd }; 20 PathOpsThreadState& state = *data; 21 SkString pathStr; 22 for (int a = 0 ; a < 6; ++a) { 23 for (int b = a + 1 ; b < 7; ++b) { 24 for (int c = 0 ; c < 6; ++c) { 25 for (int d = c + 1 ; d < 7; ++d) { 26 for (auto e : fts) { 27 for (auto f : fts) { 28 SkPath pathA, pathB; 29 pathA.setFillType(e); 30 pathA.addCircle(SkIntToScalar(state.fA), SkIntToScalar(state.fB), SkIntToScalar(state.fC), 31 state.fD ? SkPathDirection::kCW : SkPathDirection::kCCW); 32 pathB.setFillType(f); 33 pathB.addCircle(SkIntToScalar(a), SkIntToScalar(b), SkIntToScalar(c), 34 d ? SkPathDirection::kCW : SkPathDirection::kCCW); 35 for (int op = 0 ; op <= kXOR_SkPathOp; ++op) { 36 if (state.fReporter->verbose()) { 37 pathStr.printf("static void circlesOp%d(skiatest::Reporter* reporter," 38 " const char* filename) {\n", loopNo); 39 pathStr.appendf(" SkPath path, pathB;\n"); 40 pathStr.appendf(" path.setFillType(SkPathFillType::k%s);\n", 41 e == SkPathFillType::kWinding ? "Winding" : e == SkPathFillType::kEvenOdd 42 ? "EvenOdd" : "?UNDEFINED"); 43 pathStr.appendf(" path.addCircle(%d, %d, %d, %s);\n", state.fA, state.fB, 44 state.fC, state.fD ? "SkPathDirection::kCW" : "SkPathDirection::kCCW"); 45 pathStr.appendf(" pathB.setFillType(SkPathFillType::k%s);\n", 46 f == SkPathFillType::kWinding ? "Winding" : f == SkPathFillType::kEvenOdd 47 ? "EvenOdd" : "?UNDEFINED"); 48 pathStr.appendf(" pathB.addCircle(%d, %d, %d, %s);\n", a, b, 49 c, d ? "SkPathDirection::kCW" : "SkPathDirection::kCCW"); 50 pathStr.appendf(" testPathOp(reporter, path, pathB, %s, filename);\n", 51 SkPathOpsDebug::OpStr((SkPathOp) op)); 52 pathStr.appendf("}\n"); 53 state.outputProgress(pathStr.c_str(), (SkPathOp) op); 54 } 55 SkString testName; 56 testName.printf("thread_circles%d", ++gCirclesTestNo); 57 if (!testPathOp(state.fReporter, pathA, pathB, (SkPathOp) op, testName.c_str())) { 58 if (state.fReporter->verbose()) { 59 ++loopNo; 60 goto skipToNext; 61 } 62 } 63 if (PathOpsDebug::gCheckForDuplicateNames) return; 64 } 65 } 66 } 67skipToNext: ; 68 } 69 } 70 } 71 } 72} 73 74DEF_TEST(PathOpsOpCircleThreaded, reporter) { 75 initializeTests(reporter, "circleOp"); 76 PathOpsThreadedTestRunner testRunner(reporter); 77 for (int a = 0; a < 6; ++a) { // outermost 78 for (int b = a + 1; b < 7; ++b) { 79 for (int c = 0 ; c < 6; ++c) { 80 for (int d = 0; d < 2; ++d) { 81 *testRunner.fRunnables.append() = new PathOpsThreadedRunnable( 82 &testOpCirclesMain, a, b, c, d, &testRunner); 83 } 84 } 85 if (!reporter->allowExtendedTest()) goto finish; 86 } 87 } 88finish: 89 testRunner.render(); 90} 91