18cb1daaa1e4343eb60a7c4f21c12e33de30dad64commit-bot@chromium.org/* 28cb1daaa1e4343eb60a7c4f21c12e33de30dad64commit-bot@chromium.org * Copyright 2014 Google Inc. 38cb1daaa1e4343eb60a7c4f21c12e33de30dad64commit-bot@chromium.org * 48cb1daaa1e4343eb60a7c4f21c12e33de30dad64commit-bot@chromium.org * Use of this source code is governed by a BSD-style license that can be 58cb1daaa1e4343eb60a7c4f21c12e33de30dad64commit-bot@chromium.org * found in the LICENSE file. 68cb1daaa1e4343eb60a7c4f21c12e33de30dad64commit-bot@chromium.org */ 78cb1daaa1e4343eb60a7c4f21c12e33de30dad64commit-bot@chromium.org#include "PathOpsExtendedTest.h" 88cb1daaa1e4343eb60a7c4f21c12e33de30dad64commit-bot@chromium.org#include "PathOpsThreadedCommon.h" 98cb1daaa1e4343eb60a7c4f21c12e33de30dad64commit-bot@chromium.org 108cb1daaa1e4343eb60a7c4f21c12e33de30dad64commit-bot@chromium.orgstatic void testOpLoopsMain(PathOpsThreadState* data) { 118cb1daaa1e4343eb60a7c4f21c12e33de30dad64commit-bot@chromium.org#if DEBUG_SHOW_TEST_NAME 128cb1daaa1e4343eb60a7c4f21c12e33de30dad64commit-bot@chromium.org strncpy(DEBUG_FILENAME_STRING, "", DEBUG_FILENAME_STRING_LENGTH); 138cb1daaa1e4343eb60a7c4f21c12e33de30dad64commit-bot@chromium.org#endif 148cb1daaa1e4343eb60a7c4f21c12e33de30dad64commit-bot@chromium.org SkASSERT(data); 158cb1daaa1e4343eb60a7c4f21c12e33de30dad64commit-bot@chromium.org PathOpsThreadState& state = *data; 168cb1daaa1e4343eb60a7c4f21c12e33de30dad64commit-bot@chromium.org char pathStr[1024]; // gdb: set print elements 400 178cb1daaa1e4343eb60a7c4f21c12e33de30dad64commit-bot@chromium.org bool progress = state.fReporter->verbose(); // FIXME: break out into its own parameter? 188cb1daaa1e4343eb60a7c4f21c12e33de30dad64commit-bot@chromium.org if (progress) { 198cb1daaa1e4343eb60a7c4f21c12e33de30dad64commit-bot@chromium.org sk_bzero(pathStr, sizeof(pathStr)); 208cb1daaa1e4343eb60a7c4f21c12e33de30dad64commit-bot@chromium.org } 218cb1daaa1e4343eb60a7c4f21c12e33de30dad64commit-bot@chromium.org for (int a = 0 ; a < 6; ++a) { 228cb1daaa1e4343eb60a7c4f21c12e33de30dad64commit-bot@chromium.org for (int b = a + 1 ; b < 7; ++b) { 238cb1daaa1e4343eb60a7c4f21c12e33de30dad64commit-bot@chromium.org for (int c = 0 ; c < 6; ++c) { 248cb1daaa1e4343eb60a7c4f21c12e33de30dad64commit-bot@chromium.org for (int d = c + 1 ; d < 7; ++d) { 258cb1daaa1e4343eb60a7c4f21c12e33de30dad64commit-bot@chromium.org // define 4 points that form two lines that often cross; one line is (a, b) (c, d) 268cb1daaa1e4343eb60a7c4f21c12e33de30dad64commit-bot@chromium.org SkVector v = {SkIntToScalar(a - c), SkIntToScalar(b - d)}; 278cb1daaa1e4343eb60a7c4f21c12e33de30dad64commit-bot@chromium.org SkPoint midA = { SkIntToScalar(a * state.fA + c * (6 - state.fA)) / 6, 288cb1daaa1e4343eb60a7c4f21c12e33de30dad64commit-bot@chromium.org SkIntToScalar(b * state.fA + d * (6 - state.fA)) / 6 }; 298cb1daaa1e4343eb60a7c4f21c12e33de30dad64commit-bot@chromium.org SkPoint midB = { SkIntToScalar(a * state.fB + c * (6 - state.fB)) / 6, 308cb1daaa1e4343eb60a7c4f21c12e33de30dad64commit-bot@chromium.org SkIntToScalar(b * state.fB + d * (6 - state.fB)) / 6 }; 318cb1daaa1e4343eb60a7c4f21c12e33de30dad64commit-bot@chromium.org SkPoint endC = { midA.fX + v.fY * state.fC / 3, 328cb1daaa1e4343eb60a7c4f21c12e33de30dad64commit-bot@chromium.org midA.fY + v.fX * state.fC / 3 }; 338cb1daaa1e4343eb60a7c4f21c12e33de30dad64commit-bot@chromium.org SkPoint endD = { midB.fX - v.fY * state.fD / 3, 348cb1daaa1e4343eb60a7c4f21c12e33de30dad64commit-bot@chromium.org midB.fY + v.fX * state.fD / 3 }; 358cb1daaa1e4343eb60a7c4f21c12e33de30dad64commit-bot@chromium.org SkPath pathA, pathB; 368cb1daaa1e4343eb60a7c4f21c12e33de30dad64commit-bot@chromium.org if (progress) { 378cb1daaa1e4343eb60a7c4f21c12e33de30dad64commit-bot@chromium.org char* str = pathStr; 388cb1daaa1e4343eb60a7c4f21c12e33de30dad64commit-bot@chromium.org str += sprintf(str, " path.moveTo(%d,%d);\n", a, b); 398cb1daaa1e4343eb60a7c4f21c12e33de30dad64commit-bot@chromium.org str += sprintf(str, " path.cubicTo(%d,%d, %1.9gf,%1.9gf, %1.9gf,%1.9gf);\n", 408cb1daaa1e4343eb60a7c4f21c12e33de30dad64commit-bot@chromium.org c, d, endC.fX, endC.fY, endD.fX, endD.fY); 418cb1daaa1e4343eb60a7c4f21c12e33de30dad64commit-bot@chromium.org str += sprintf(str, " path.close();\n"); 428cb1daaa1e4343eb60a7c4f21c12e33de30dad64commit-bot@chromium.org str += sprintf(str, " pathB.moveTo(%d,%d);\n", c, d); 438cb1daaa1e4343eb60a7c4f21c12e33de30dad64commit-bot@chromium.org str += sprintf(str, " pathB.cubicTo(%1.9gf,%1.9gf, %1.9gf,%1.9gf, %d,%d);\n", 448cb1daaa1e4343eb60a7c4f21c12e33de30dad64commit-bot@chromium.org endC.fX, endC.fY, endD.fX, endD.fY, a, b); 458cb1daaa1e4343eb60a7c4f21c12e33de30dad64commit-bot@chromium.org str += sprintf(str, " pathB.close();\n"); 468cb1daaa1e4343eb60a7c4f21c12e33de30dad64commit-bot@chromium.org } 478cb1daaa1e4343eb60a7c4f21c12e33de30dad64commit-bot@chromium.org pathA.moveTo(SkIntToScalar(a), SkIntToScalar(b)); 488cb1daaa1e4343eb60a7c4f21c12e33de30dad64commit-bot@chromium.org pathA.cubicTo(SkIntToScalar(c), SkIntToScalar(d), endC.fX, endC.fY, endD.fX, endD.fY); 498cb1daaa1e4343eb60a7c4f21c12e33de30dad64commit-bot@chromium.org pathA.close(); 508cb1daaa1e4343eb60a7c4f21c12e33de30dad64commit-bot@chromium.org pathB.moveTo(SkIntToScalar(c), SkIntToScalar(d)); 518cb1daaa1e4343eb60a7c4f21c12e33de30dad64commit-bot@chromium.org pathB.cubicTo(endC.fX, endC.fY, endD.fX, endD.fY, SkIntToScalar(a), SkIntToScalar(b)); 528cb1daaa1e4343eb60a7c4f21c12e33de30dad64commit-bot@chromium.org pathB.close(); 538cb1daaa1e4343eb60a7c4f21c12e33de30dad64commit-bot@chromium.org// SkDebugf("%s\n", pathStr); 548cb1daaa1e4343eb60a7c4f21c12e33de30dad64commit-bot@chromium.org if (progress) { 558cb1daaa1e4343eb60a7c4f21c12e33de30dad64commit-bot@chromium.org outputProgress(state.fPathStr, pathStr, kIntersect_PathOp); 568cb1daaa1e4343eb60a7c4f21c12e33de30dad64commit-bot@chromium.org } 578cb1daaa1e4343eb60a7c4f21c12e33de30dad64commit-bot@chromium.org testThreadedPathOp(state.fReporter, pathA, pathB, kIntersect_PathOp, "loops"); 588cb1daaa1e4343eb60a7c4f21c12e33de30dad64commit-bot@chromium.org } 598cb1daaa1e4343eb60a7c4f21c12e33de30dad64commit-bot@chromium.org } 608cb1daaa1e4343eb60a7c4f21c12e33de30dad64commit-bot@chromium.org } 618cb1daaa1e4343eb60a7c4f21c12e33de30dad64commit-bot@chromium.org } 628cb1daaa1e4343eb60a7c4f21c12e33de30dad64commit-bot@chromium.org} 638cb1daaa1e4343eb60a7c4f21c12e33de30dad64commit-bot@chromium.org 648cb1daaa1e4343eb60a7c4f21c12e33de30dad64commit-bot@chromium.orgDEF_TEST(PathOpsOpLoopsThreaded, reporter) { 6565b427cff9cd34a06ff060d65d00cc3615d8fd94caryclark if (!FLAGS_runFail) { 6665b427cff9cd34a06ff060d65d00cc3615d8fd94caryclark return; 6765b427cff9cd34a06ff060d65d00cc3615d8fd94caryclark } 68406654be7a930b484159f5bca107d3b11d8a9edemtklein initializeTests(reporter, "cubicOp"); 69406654be7a930b484159f5bca107d3b11d8a9edemtklein PathOpsThreadedTestRunner testRunner(reporter); 708cb1daaa1e4343eb60a7c4f21c12e33de30dad64commit-bot@chromium.org for (int a = 0; a < 6; ++a) { // outermost 718cb1daaa1e4343eb60a7c4f21c12e33de30dad64commit-bot@chromium.org for (int b = a + 1; b < 7; ++b) { 728cb1daaa1e4343eb60a7c4f21c12e33de30dad64commit-bot@chromium.org for (int c = 0 ; c < 6; ++c) { 738cb1daaa1e4343eb60a7c4f21c12e33de30dad64commit-bot@chromium.org for (int d = c + 1; d < 7; ++d) { 748cb1daaa1e4343eb60a7c4f21c12e33de30dad64commit-bot@chromium.org *testRunner.fRunnables.append() = SkNEW_ARGS(PathOpsThreadedRunnable, 758cb1daaa1e4343eb60a7c4f21c12e33de30dad64commit-bot@chromium.org (&testOpLoopsMain, a, b, c, d, &testRunner)); 768cb1daaa1e4343eb60a7c4f21c12e33de30dad64commit-bot@chromium.org } 778cb1daaa1e4343eb60a7c4f21c12e33de30dad64commit-bot@chromium.org } 788cb1daaa1e4343eb60a7c4f21c12e33de30dad64commit-bot@chromium.org if (!reporter->allowExtendedTest()) goto finish; 798cb1daaa1e4343eb60a7c4f21c12e33de30dad64commit-bot@chromium.org } 808cb1daaa1e4343eb60a7c4f21c12e33de30dad64commit-bot@chromium.org } 818cb1daaa1e4343eb60a7c4f21c12e33de30dad64commit-bot@chromium.orgfinish: 828cb1daaa1e4343eb60a7c4f21c12e33de30dad64commit-bot@chromium.org testRunner.render(); 838cb1daaa1e4343eb60a7c4f21c12e33de30dad64commit-bot@chromium.org ShowTestArray(); 848cb1daaa1e4343eb60a7c4f21c12e33de30dad64commit-bot@chromium.org} 858cb1daaa1e4343eb60a7c4f21c12e33de30dad64commit-bot@chromium.org 868cb1daaa1e4343eb60a7c4f21c12e33de30dad64commit-bot@chromium.orgDEF_TEST(PathOpsOpLoops, reporter) { 8765b427cff9cd34a06ff060d65d00cc3615d8fd94caryclark if (!FLAGS_runFail) { 8865b427cff9cd34a06ff060d65d00cc3615d8fd94caryclark return; 8965b427cff9cd34a06ff060d65d00cc3615d8fd94caryclark } 90406654be7a930b484159f5bca107d3b11d8a9edemtklein initializeTests(reporter, "cubicOp"); 918cb1daaa1e4343eb60a7c4f21c12e33de30dad64commit-bot@chromium.org PathOpsThreadState state; 928cb1daaa1e4343eb60a7c4f21c12e33de30dad64commit-bot@chromium.org state.fReporter = reporter; 938cb1daaa1e4343eb60a7c4f21c12e33de30dad64commit-bot@chromium.org SkBitmap bitmap; 948cb1daaa1e4343eb60a7c4f21c12e33de30dad64commit-bot@chromium.org state.fBitmap = &bitmap; 958cb1daaa1e4343eb60a7c4f21c12e33de30dad64commit-bot@chromium.org char pathStr[PATH_STR_SIZE]; 968cb1daaa1e4343eb60a7c4f21c12e33de30dad64commit-bot@chromium.org state.fPathStr = pathStr; 978cb1daaa1e4343eb60a7c4f21c12e33de30dad64commit-bot@chromium.org for (state.fA = 0; state.fA < 6; ++state.fA) { // outermost 988cb1daaa1e4343eb60a7c4f21c12e33de30dad64commit-bot@chromium.org for (state.fB = state.fA + 1; state.fB < 7; ++state.fB) { 998cb1daaa1e4343eb60a7c4f21c12e33de30dad64commit-bot@chromium.org for (state.fC = 0 ; state.fC < 6; ++state.fC) { 1008cb1daaa1e4343eb60a7c4f21c12e33de30dad64commit-bot@chromium.org for (state.fD = state.fC + 1; state.fD < 7; ++state.fD) { 1018cb1daaa1e4343eb60a7c4f21c12e33de30dad64commit-bot@chromium.org testOpLoopsMain(&state); 1028cb1daaa1e4343eb60a7c4f21c12e33de30dad64commit-bot@chromium.org } 1038cb1daaa1e4343eb60a7c4f21c12e33de30dad64commit-bot@chromium.org } 1048cb1daaa1e4343eb60a7c4f21c12e33de30dad64commit-bot@chromium.org if (!reporter->allowExtendedTest()) goto finish; 1058cb1daaa1e4343eb60a7c4f21c12e33de30dad64commit-bot@chromium.org } 1068cb1daaa1e4343eb60a7c4f21c12e33de30dad64commit-bot@chromium.org } 1078cb1daaa1e4343eb60a7c4f21c12e33de30dad64commit-bot@chromium.orgfinish: 1088cb1daaa1e4343eb60a7c4f21c12e33de30dad64commit-bot@chromium.org ShowTestArray(); 1098cb1daaa1e4343eb60a7c4f21c12e33de30dad64commit-bot@chromium.org} 110