blob: d149377015434f7636ba4f4d21786dbc1d5cff3d [file] [log] [blame]
caryclark@google.comb1c42bb2012-11-16 13:16:41 +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 "EdgeWalker_Test.h"
8#include "Intersection_Tests.h"
9#include "ShapeOps.h"
10
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
18static void* testShapeOps4x4RectsMain(void* data)
19{
20 SkASSERT(data);
21 State4& state = *(State4*) data;
22 char pathStr[1024]; // gdb: set print elements 400
23 bzero(pathStr, sizeof(pathStr));
24 do {
25 for (int a = 0 ; a < 6; ++a) {
caryclark@google.come7bd5f42012-12-13 19:47:53 +000026 for (int b = a + 1 ; b < 7; ++b) {
caryclark@google.comb1c42bb2012-11-16 13:16:41 +000027 for (int c = 0 ; c < 6; ++c) {
28 for (int d = c + 1 ; d < 7; ++d) {
29 for (int op = 0 ; op < kShapeOp_Count; ++op) {
caryclark@google.com4eeda372012-12-06 21:47:48 +000030 for (int e = SkPath::kWinding_FillType ; e <= SkPath::kEvenOdd_FillType; ++e) {
31 for (int f = SkPath::kWinding_FillType ; f <= SkPath::kEvenOdd_FillType; ++f) {
caryclark@google.comb1c42bb2012-11-16 13:16:41 +000032 SkPath pathA, pathB;
33 char* str = pathStr;
34 pathA.setFillType((SkPath::FillType) e);
caryclark@google.com4eeda372012-12-06 21:47:48 +000035 str += sprintf(str, " path.setFillType(SkPath::k%s_FillType);\n",
36 e == SkPath::kWinding_FillType ? "Winding" : e == SkPath::kEvenOdd_FillType
37 ? "EvenOdd" : "?UNDEFINED");
caryclark@google.com7fce0de2012-11-29 14:31:50 +000038 pathA.addRect(state.a, state.a, state.b, state.b, SkPath::kCW_Direction);
caryclark@google.comb1c42bb2012-11-16 13:16:41 +000039 str += sprintf(str, " path.addRect(%d, %d, %d, %d,"
caryclark@google.com7fce0de2012-11-29 14:31:50 +000040 " SkPath::kCW_Direction);\n", state.a, state.a, state.b, state.b);
41 pathA.addRect(state.c, state.c, state.d, state.d, SkPath::kCW_Direction);
caryclark@google.comb1c42bb2012-11-16 13:16:41 +000042 str += sprintf(str, " path.addRect(%d, %d, %d, %d,"
caryclark@google.com7fce0de2012-11-29 14:31:50 +000043 " SkPath::kCW_Direction);\n", state.c, state.c, state.d, state.d);
caryclark@google.comb1c42bb2012-11-16 13:16:41 +000044 pathA.close();
45 pathB.setFillType((SkPath::FillType) f);
caryclark@google.com4eeda372012-12-06 21:47:48 +000046 str += sprintf(str, " pathB.setFillType(SkPath::k%s_FillType);\n",
47 f == SkPath::kWinding_FillType ? "Winding" : f == SkPath::kEvenOdd_FillType
48 ? "EvenOdd" : "?UNDEFINED");
caryclark@google.com7fce0de2012-11-29 14:31:50 +000049 pathB.addRect(a, a, b, b, SkPath::kCW_Direction);
caryclark@google.comb1c42bb2012-11-16 13:16:41 +000050 str += sprintf(str, " pathB.addRect(%d, %d, %d, %d,"
caryclark@google.com7fce0de2012-11-29 14:31:50 +000051 " SkPath::kCW_Direction);\n", a, a, b, b);
52 pathB.addRect(c, c, d, d, SkPath::kCW_Direction);
caryclark@google.comb1c42bb2012-11-16 13:16:41 +000053 str += sprintf(str, " pathB.addRect(%d, %d, %d, %d,"
caryclark@google.com7fce0de2012-11-29 14:31:50 +000054 " SkPath::kCW_Direction);\n", c, c, d, d);
caryclark@google.comb1c42bb2012-11-16 13:16:41 +000055 pathB.close();
56 outputProgress(state, pathStr, kDifference_Op);
57 testShapeOp(pathA, pathB, kDifference_Op);
58 state.testsRun++;
59 outputProgress(state, pathStr, kIntersect_Op);
60 testShapeOp(pathA, pathB, kIntersect_Op);
61 state.testsRun++;
62 outputProgress(state, pathStr, kUnion_Op);
63 testShapeOp(pathA, pathB, kUnion_Op);
64 state.testsRun++;
65 outputProgress(state, pathStr, kXor_Op);
66 testShapeOp(pathA, pathB, kXor_Op);
67 state.testsRun++;
68 }
69 }
70 }
71 }
72 }
73 }
74 }
75 } while (runNextTestSet(state));
76 return NULL;
77}
78
79void ShapeOps4x4RectsThreaded_Test(int& testsRun)
80{
81 SkDebugf("%s\n", __FUNCTION__);
82#ifdef SK_DEBUG
83 gDebugMaxWindSum = 4;
84 gDebugMaxWindValue = 4;
85#endif
86 const char testLineStr[] = "testOp";
87 initializeTests(testLineStr, sizeof(testLineStr));
88 int testsStart = testsRun;
89 for (int a = 0; a < 6; ++a) { // outermost
90 for (int b = a + 1; b < 7; ++b) {
91 for (int c = 0 ; c < 6; ++c) {
92 for (int d = c + 1; d < 7; ++d) {
93 testsRun += dispatchTest4(testShapeOps4x4RectsMain, a, b, c, d);
94 }
95 if (!gRunTestsInOneThread) SkDebugf(".");
96 }
97 if (!gRunTestsInOneThread) SkDebugf("%d", b);
98 }
99 if (!gRunTestsInOneThread) SkDebugf("\n%d", a);
100 }
101 testsRun += waitForCompletion();
102 SkDebugf("%s tests=%d total=%d\n", __FUNCTION__, testsRun - testsStart, testsRun);
103}