1cb93a386Sopenharmony_ci/* 2cb93a386Sopenharmony_ci * Copyright 2012 Google Inc. 3cb93a386Sopenharmony_ci * 4cb93a386Sopenharmony_ci * Use of this source code is governed by a BSD-style license that can be 5cb93a386Sopenharmony_ci * found in the LICENSE file. 6cb93a386Sopenharmony_ci */ 7cb93a386Sopenharmony_ci#include "include/core/SkString.h" 8cb93a386Sopenharmony_ci#include "tests/PathOpsDebug.h" 9cb93a386Sopenharmony_ci#include "tests/PathOpsExtendedTest.h" 10cb93a386Sopenharmony_ci#include "tests/PathOpsThreadedCommon.h" 11cb93a386Sopenharmony_ci#include <atomic> 12cb93a386Sopenharmony_ci 13cb93a386Sopenharmony_ci// four rects, of four sizes 14cb93a386Sopenharmony_ci// for 3 smaller sizes, tall, wide 15cb93a386Sopenharmony_ci // top upper mid lower bottom aligned (3 bits, 5 values) 16cb93a386Sopenharmony_ci // same with x (3 bits, 5 values) 17cb93a386Sopenharmony_ci// not included, square, tall, wide (2 bits) 18cb93a386Sopenharmony_ci// cw or ccw (1 bit) 19cb93a386Sopenharmony_ci 20cb93a386Sopenharmony_cistatic int loopNo = 6; 21cb93a386Sopenharmony_cistatic std::atomic<int> gRectsTestNo{0}; 22cb93a386Sopenharmony_ci 23cb93a386Sopenharmony_cistatic void testPathOpsRectsMain(PathOpsThreadState* data) 24cb93a386Sopenharmony_ci{ 25cb93a386Sopenharmony_ci SkASSERT(data); 26cb93a386Sopenharmony_ci const SkPathFillType fts[] = { SkPathFillType::kWinding, SkPathFillType::kEvenOdd }; 27cb93a386Sopenharmony_ci PathOpsThreadState& state = *data; 28cb93a386Sopenharmony_ci SkString pathStr; 29cb93a386Sopenharmony_ci for (int a = 0 ; a < 6; ++a) { 30cb93a386Sopenharmony_ci for (int b = a + 1 ; b < 7; ++b) { 31cb93a386Sopenharmony_ci for (int c = 0 ; c < 6; ++c) { 32cb93a386Sopenharmony_ci for (int d = c + 1 ; d < 7; ++d) { 33cb93a386Sopenharmony_ci for (auto e : fts) { 34cb93a386Sopenharmony_ci for (auto f : fts) { 35cb93a386Sopenharmony_ci SkPath pathA, pathB; 36cb93a386Sopenharmony_ci pathA.setFillType((SkPathFillType) e); 37cb93a386Sopenharmony_ci pathA.addRect(SkIntToScalar(state.fA), SkIntToScalar(state.fA), SkIntToScalar(state.fB), 38cb93a386Sopenharmony_ci SkIntToScalar(state.fB), SkPathDirection::kCW); 39cb93a386Sopenharmony_ci pathA.addRect(SkIntToScalar(state.fC), SkIntToScalar(state.fC), SkIntToScalar(state.fD), 40cb93a386Sopenharmony_ci SkIntToScalar(state.fD), SkPathDirection::kCW); 41cb93a386Sopenharmony_ci pathA.close(); 42cb93a386Sopenharmony_ci pathB.setFillType((SkPathFillType) f); 43cb93a386Sopenharmony_ci pathB.addRect(SkIntToScalar(a), SkIntToScalar(a), SkIntToScalar(b), 44cb93a386Sopenharmony_ci SkIntToScalar(b), SkPathDirection::kCW); 45cb93a386Sopenharmony_ci pathB.addRect(SkIntToScalar(c), SkIntToScalar(c), SkIntToScalar(d), 46cb93a386Sopenharmony_ci SkIntToScalar(d), SkPathDirection::kCW); 47cb93a386Sopenharmony_ci pathB.close(); 48cb93a386Sopenharmony_ci for (int op = 0 ; op <= kXOR_SkPathOp; ++op) { 49cb93a386Sopenharmony_ci if (state.fReporter->verbose()) { 50cb93a386Sopenharmony_ci pathStr.printf( 51cb93a386Sopenharmony_ci "static void rects%d(skiatest::Reporter* reporter," 52cb93a386Sopenharmony_ci "const char* filename) {\n", loopNo); 53cb93a386Sopenharmony_ci pathStr.appendf(" SkPath path, pathB;"); 54cb93a386Sopenharmony_ci pathStr.appendf(" path.setFillType(SkPathFillType::k%s);\n", 55cb93a386Sopenharmony_ci e == SkPathFillType::kWinding ? "Winding" : e == SkPathFillType::kEvenOdd 56cb93a386Sopenharmony_ci ? "EvenOdd" : "?UNDEFINED"); 57cb93a386Sopenharmony_ci pathStr.appendf(" path.addRect(%d, %d, %d, %d," 58cb93a386Sopenharmony_ci " SkPathDirection::kCW);\n", state.fA, state.fA, state.fB, state.fB); 59cb93a386Sopenharmony_ci pathStr.appendf(" path.addRect(%d, %d, %d, %d," 60cb93a386Sopenharmony_ci " SkPathDirection::kCW);\n", state.fC, state.fC, state.fD, state.fD); 61cb93a386Sopenharmony_ci pathStr.appendf(" pathB.setFillType(SkPathFillType::k%s);\n", 62cb93a386Sopenharmony_ci f == SkPathFillType::kWinding ? "Winding" : f == SkPathFillType::kEvenOdd 63cb93a386Sopenharmony_ci ? "EvenOdd" : "?UNDEFINED"); 64cb93a386Sopenharmony_ci pathStr.appendf(" pathB.addRect(%d, %d, %d, %d," 65cb93a386Sopenharmony_ci " SkPathDirection::kCW);\n", a, a, b, b); 66cb93a386Sopenharmony_ci pathStr.appendf(" pathB.addRect(%d, %d, %d, %d," 67cb93a386Sopenharmony_ci " SkPathDirection::kCW);\n", c, c, d, d); 68cb93a386Sopenharmony_ci pathStr.appendf(" testPathOp(reporter, path, pathB, %s, filename);\n", 69cb93a386Sopenharmony_ci SkPathOpsDebug::OpStr((SkPathOp) op)); 70cb93a386Sopenharmony_ci pathStr.appendf("}\n\n"); 71cb93a386Sopenharmony_ci state.outputProgress(pathStr.c_str(), (SkPathOp) op); 72cb93a386Sopenharmony_ci } 73cb93a386Sopenharmony_ci SkString testName; 74cb93a386Sopenharmony_ci testName.printf("thread_rects%d", ++gRectsTestNo); 75cb93a386Sopenharmony_ci if (!testPathOp(state.fReporter, pathA, pathB, (SkPathOp) op, testName.c_str())) { 76cb93a386Sopenharmony_ci if (state.fReporter->verbose()) { 77cb93a386Sopenharmony_ci ++loopNo; 78cb93a386Sopenharmony_ci goto skipToNext; 79cb93a386Sopenharmony_ci } 80cb93a386Sopenharmony_ci } 81cb93a386Sopenharmony_ci if (PathOpsDebug::gCheckForDuplicateNames) return; 82cb93a386Sopenharmony_ci } 83cb93a386Sopenharmony_ci } 84cb93a386Sopenharmony_ci } 85cb93a386Sopenharmony_ciskipToNext: ; 86cb93a386Sopenharmony_ci } 87cb93a386Sopenharmony_ci } 88cb93a386Sopenharmony_ci } 89cb93a386Sopenharmony_ci } 90cb93a386Sopenharmony_ci} 91cb93a386Sopenharmony_ci 92cb93a386Sopenharmony_ciDEF_TEST(PathOpsRectsThreaded, reporter) { 93cb93a386Sopenharmony_ci initializeTests(reporter, "testOp"); 94cb93a386Sopenharmony_ci PathOpsThreadedTestRunner testRunner(reporter); 95cb93a386Sopenharmony_ci for (int a = 0; a < 6; ++a) { // outermost 96cb93a386Sopenharmony_ci for (int b = a + 1; b < 7; ++b) { 97cb93a386Sopenharmony_ci for (int c = 0 ; c < 6; ++c) { 98cb93a386Sopenharmony_ci for (int d = c + 1; d < 7; ++d) { 99cb93a386Sopenharmony_ci *testRunner.fRunnables.append() = new PathOpsThreadedRunnable( 100cb93a386Sopenharmony_ci &testPathOpsRectsMain, a, b, c, d, &testRunner); 101cb93a386Sopenharmony_ci } 102cb93a386Sopenharmony_ci } 103cb93a386Sopenharmony_ci if (!reporter->allowExtendedTest()) goto finish; 104cb93a386Sopenharmony_ci } 105cb93a386Sopenharmony_ci } 106cb93a386Sopenharmony_cifinish: 107cb93a386Sopenharmony_ci testRunner.render(); 108cb93a386Sopenharmony_ci} 109cb93a386Sopenharmony_ci 110cb93a386Sopenharmony_cistatic std::atomic<int> gFastTestNo{0}; 111cb93a386Sopenharmony_ci 112cb93a386Sopenharmony_cistatic void testPathOpsFastMain(PathOpsThreadState* data) 113cb93a386Sopenharmony_ci{ 114cb93a386Sopenharmony_ci SkASSERT(data); 115cb93a386Sopenharmony_ci const SkPathFillType fts[] = { 116cb93a386Sopenharmony_ci SkPathFillType::kWinding, SkPathFillType::kEvenOdd, 117cb93a386Sopenharmony_ci SkPathFillType::kInverseWinding, SkPathFillType::kInverseEvenOdd 118cb93a386Sopenharmony_ci }; 119cb93a386Sopenharmony_ci PathOpsThreadState& state = *data; 120cb93a386Sopenharmony_ci SkString pathStr; 121cb93a386Sopenharmony_ci int step = data->fReporter->allowExtendedTest() ? 2 : 5; 122cb93a386Sopenharmony_ci for (bool a : { false, true } ) { 123cb93a386Sopenharmony_ci for (bool b : { false, true } ) { 124cb93a386Sopenharmony_ci for (int c = 0; c < 6; c += step) { 125cb93a386Sopenharmony_ci for (int d = 0; d < 6; d += step) { 126cb93a386Sopenharmony_ci for (auto e : fts) { 127cb93a386Sopenharmony_ci for (auto f : fts) { 128cb93a386Sopenharmony_ci SkPath pathA, pathB; 129cb93a386Sopenharmony_ci pathA.setFillType(e); 130cb93a386Sopenharmony_ci if (a) { 131cb93a386Sopenharmony_ci pathA.addRect(SkIntToScalar(state.fA), SkIntToScalar(state.fA), SkIntToScalar(state.fB) + c, 132cb93a386Sopenharmony_ci SkIntToScalar(state.fB), SkPathDirection::kCW); 133cb93a386Sopenharmony_ci } 134cb93a386Sopenharmony_ci pathA.close(); 135cb93a386Sopenharmony_ci pathB.setFillType(f); 136cb93a386Sopenharmony_ci if (b) { 137cb93a386Sopenharmony_ci pathB.addRect(SkIntToScalar(state.fC), SkIntToScalar(state.fC), SkIntToScalar(state.fD) + d, 138cb93a386Sopenharmony_ci SkIntToScalar(state.fD), SkPathDirection::kCW); 139cb93a386Sopenharmony_ci } 140cb93a386Sopenharmony_ci pathB.close(); 141cb93a386Sopenharmony_ci const char* fillTypeStr[] = { "Winding", "EvenOdd", "InverseWinding", "InverseEvenOdd" }; 142cb93a386Sopenharmony_ci for (int op = 0; op <= kXOR_SkPathOp; ++op) { 143cb93a386Sopenharmony_ci if (state.fReporter->verbose()) { 144cb93a386Sopenharmony_ci pathStr.printf( 145cb93a386Sopenharmony_ci "static void fast%d(skiatest::Reporter* reporter," 146cb93a386Sopenharmony_ci "const char* filename) {\n", loopNo); 147cb93a386Sopenharmony_ci pathStr.appendf(" SkPath path, pathB;"); 148cb93a386Sopenharmony_ci pathStr.appendf(" path.setFillType(SkPathFillType::k%s);\n", fillTypeStr[(int)e]); 149cb93a386Sopenharmony_ci if (a) { 150cb93a386Sopenharmony_ci pathStr.appendf(" path.addRect(%d, %d, %d, %d," 151cb93a386Sopenharmony_ci " SkPathDirection::kCW);\n", state.fA, state.fA, state.fB + c, state.fB); 152cb93a386Sopenharmony_ci } 153cb93a386Sopenharmony_ci pathStr.appendf(" path.setFillType(SkPathFillType::k%s);\n", fillTypeStr[(int)f]); 154cb93a386Sopenharmony_ci if (b) { 155cb93a386Sopenharmony_ci pathStr.appendf(" path.addRect(%d, %d, %d, %d," 156cb93a386Sopenharmony_ci " SkPathDirection::kCW);\n", state.fC, state.fC, state.fD + d, state.fD); 157cb93a386Sopenharmony_ci } 158cb93a386Sopenharmony_ci pathStr.appendf(" testPathOp(reporter, path, pathB, %s, filename);\n", 159cb93a386Sopenharmony_ci SkPathOpsDebug::OpStr((SkPathOp) op)); 160cb93a386Sopenharmony_ci pathStr.appendf("}\n\n"); 161cb93a386Sopenharmony_ci state.outputProgress(pathStr.c_str(), (SkPathOp) op); 162cb93a386Sopenharmony_ci } 163cb93a386Sopenharmony_ci SkString testName; 164cb93a386Sopenharmony_ci testName.printf("fast%d", ++gFastTestNo); 165cb93a386Sopenharmony_ci if (!testPathOp(state.fReporter, pathA, pathB, (SkPathOp) op, testName.c_str())) { 166cb93a386Sopenharmony_ci if (state.fReporter->verbose()) { 167cb93a386Sopenharmony_ci ++loopNo; 168cb93a386Sopenharmony_ci goto skipToNext; 169cb93a386Sopenharmony_ci } 170cb93a386Sopenharmony_ci } 171cb93a386Sopenharmony_ci if (PathOpsDebug::gCheckForDuplicateNames) return; 172cb93a386Sopenharmony_ci } 173cb93a386Sopenharmony_ci } 174cb93a386Sopenharmony_ci } 175cb93a386Sopenharmony_ciskipToNext: ; 176cb93a386Sopenharmony_ci } 177cb93a386Sopenharmony_ci } 178cb93a386Sopenharmony_ci } 179cb93a386Sopenharmony_ci } 180cb93a386Sopenharmony_ci} 181cb93a386Sopenharmony_ci 182cb93a386Sopenharmony_ciDEF_TEST(PathOpsFastThreaded, reporter) { 183cb93a386Sopenharmony_ci initializeTests(reporter, "testOp"); 184cb93a386Sopenharmony_ci PathOpsThreadedTestRunner testRunner(reporter); 185cb93a386Sopenharmony_ci int step = reporter->allowExtendedTest() ? 2 : 5; 186cb93a386Sopenharmony_ci for (int a = 0; a < 6; a += step) { // outermost 187cb93a386Sopenharmony_ci for (int b = a + 1; b < 7; b += step) { 188cb93a386Sopenharmony_ci for (int c = 0 ; c < 6; c += step) { 189cb93a386Sopenharmony_ci for (int d = c + 1; d < 7; d += step) { 190cb93a386Sopenharmony_ci *testRunner.fRunnables.append() = new PathOpsThreadedRunnable( 191cb93a386Sopenharmony_ci &testPathOpsFastMain, a, b, c, d, &testRunner); 192cb93a386Sopenharmony_ci } 193cb93a386Sopenharmony_ci } 194cb93a386Sopenharmony_ci } 195cb93a386Sopenharmony_ci } 196cb93a386Sopenharmony_ci testRunner.render(); 197cb93a386Sopenharmony_ci} 198