blob: fee44e51b2dd76b40216dc792c60975fc6c03155 [file] [log] [blame]
caryclark@google.com818b0cc2013-04-08 11:50:46 +00001/*
2 * Copyright 2012 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 "PathOpsExtendedTest.h"
caryclark@google.com66089e42013-04-10 15:55:37 +00008#include "PathOpsThreadedCommon.h"
tfarina@chromium.org78e7b4e2014-01-02 21:45:03 +00009#include "TestClassDef.h"
caryclark@google.com818b0cc2013-04-08 11:50:46 +000010
11// four rects, of four sizes
12// for 3 smaller sizes, tall, wide
13 // top upper mid lower bottom aligned (3 bits, 5 values)
14 // same with x (3 bits, 5 values)
15// not included, square, tall, wide (2 bits)
16// cw or ccw (1 bit)
17
caryclark@google.com66089e42013-04-10 15:55:37 +000018static void testPathOpsRectsMain(PathOpsThreadState* data)
caryclark@google.com818b0cc2013-04-08 11:50:46 +000019{
20 SkASSERT(data);
caryclark@google.com66089e42013-04-10 15:55:37 +000021 PathOpsThreadState& state = *data;
caryclark@google.com818b0cc2013-04-08 11:50:46 +000022 char pathStr[1024]; // gdb: set print elements 400
caryclark@google.com8d0a5242013-07-16 16:11:16 +000023 bool progress = state.fReporter->verbose(); // FIXME: break out into its own parameter?
24 if (progress) {
25 sk_bzero(pathStr, sizeof(pathStr));
26 }
caryclark@google.com66089e42013-04-10 15:55:37 +000027 for (int a = 0 ; a < 6; ++a) {
28 for (int b = a + 1 ; b < 7; ++b) {
29 for (int c = 0 ; c < 6; ++c) {
30 for (int d = c + 1 ; d < 7; ++d) {
31 for (int e = SkPath::kWinding_FillType ; e <= SkPath::kEvenOdd_FillType; ++e) {
32 for (int f = SkPath::kWinding_FillType ; f <= SkPath::kEvenOdd_FillType; ++f) {
caryclark@google.com8d0a5242013-07-16 16:11:16 +000033 if (progress) {
34 char* str = pathStr;
35 str += sprintf(str, " path.setFillType(SkPath::k%s_FillType);\n",
36 e == SkPath::kWinding_FillType ? "Winding" : e == SkPath::kEvenOdd_FillType
37 ? "EvenOdd" : "?UNDEFINED");
38 str += sprintf(str, " path.addRect(%d, %d, %d, %d,"
39 " SkPath::kCW_Direction);\n", state.fA, state.fA, state.fB, state.fB);
40 str += sprintf(str, " path.addRect(%d, %d, %d, %d,"
41 " SkPath::kCW_Direction);\n", state.fC, state.fC, state.fD, state.fD);
42 str += sprintf(str, " pathB.setFillType(SkPath::k%s_FillType);\n",
43 f == SkPath::kWinding_FillType ? "Winding" : f == SkPath::kEvenOdd_FillType
44 ? "EvenOdd" : "?UNDEFINED");
45 str += sprintf(str, " pathB.addRect(%d, %d, %d, %d,"
46 " SkPath::kCW_Direction);\n", a, a, b, b);
47 str += sprintf(str, " pathB.addRect(%d, %d, %d, %d,"
48 " SkPath::kCW_Direction);\n", c, c, d, d);
49 }
caryclark@google.com66089e42013-04-10 15:55:37 +000050 SkPath pathA, pathB;
caryclark@google.com66089e42013-04-10 15:55:37 +000051 pathA.setFillType((SkPath::FillType) e);
caryclark@google.com66089e42013-04-10 15:55:37 +000052 pathA.addRect(SkIntToScalar(state.fA), SkIntToScalar(state.fA), SkIntToScalar(state.fB),
53 SkIntToScalar(state.fB), SkPath::kCW_Direction);
caryclark@google.com66089e42013-04-10 15:55:37 +000054 pathA.addRect(SkIntToScalar(state.fC), SkIntToScalar(state.fC), SkIntToScalar(state.fD),
55 SkIntToScalar(state.fD), SkPath::kCW_Direction);
caryclark@google.com66089e42013-04-10 15:55:37 +000056 pathA.close();
57 pathB.setFillType((SkPath::FillType) f);
caryclark@google.com66089e42013-04-10 15:55:37 +000058 pathB.addRect(SkIntToScalar(a), SkIntToScalar(a), SkIntToScalar(b),
59 SkIntToScalar(b), SkPath::kCW_Direction);
caryclark@google.com66089e42013-04-10 15:55:37 +000060 pathB.addRect(SkIntToScalar(c), SkIntToScalar(c), SkIntToScalar(d),
61 SkIntToScalar(d), SkPath::kCW_Direction);
caryclark@google.com66089e42013-04-10 15:55:37 +000062 pathB.close();
63 for (int op = 0 ; op <= kXOR_PathOp; ++op) {
caryclark@google.com8d0a5242013-07-16 16:11:16 +000064 if (progress) {
65 outputProgress(state.fPathStr, pathStr, (SkPathOp) op);
66 }
67 testThreadedPathOp(state.fReporter, pathA, pathB, (SkPathOp) op);
caryclark@google.com66089e42013-04-10 15:55:37 +000068 }
69 }
caryclark@google.com818b0cc2013-04-08 11:50:46 +000070 }
71 }
72 }
caryclark@google.com66089e42013-04-10 15:55:37 +000073 }
74 }
caryclark@google.com818b0cc2013-04-08 11:50:46 +000075}
76
tfarina@chromium.org78e7b4e2014-01-02 21:45:03 +000077DEF_TEST(PathOpsRectsThreaded, reporter) {
caryclark@google.com16cfe402013-04-18 18:47:37 +000078 int threadCount = initializeTests(reporter, "testOp");
caryclark@google.com66089e42013-04-10 15:55:37 +000079 PathOpsThreadedTestRunner testRunner(reporter, threadCount);
caryclark@google.com818b0cc2013-04-08 11:50:46 +000080 for (int a = 0; a < 6; ++a) { // outermost
81 for (int b = a + 1; b < 7; ++b) {
82 for (int c = 0 ; c < 6; ++c) {
83 for (int d = c + 1; d < 7; ++d) {
caryclark@google.com66089e42013-04-10 15:55:37 +000084 *testRunner.fRunnables.append() = SkNEW_ARGS(PathOpsThreadedRunnable,
85 (&testPathOpsRectsMain, a, b, c, d, &testRunner));
caryclark@google.com818b0cc2013-04-08 11:50:46 +000086 }
caryclark@google.com818b0cc2013-04-08 11:50:46 +000087 }
caryclark@google.com66089e42013-04-10 15:55:37 +000088 if (!reporter->allowExtendedTest()) goto finish;
caryclark@google.com818b0cc2013-04-08 11:50:46 +000089 }
caryclark@google.com818b0cc2013-04-08 11:50:46 +000090 }
91finish:
caryclark@google.com66089e42013-04-10 15:55:37 +000092 testRunner.render();
caryclark@google.com818b0cc2013-04-08 11:50:46 +000093}