1818b0cc1b8b0c4acc565e8e2cb8b0b61aa5a300ecaryclark@google.com/*
2818b0cc1b8b0c4acc565e8e2cb8b0b61aa5a300ecaryclark@google.com * Copyright 2012 Google Inc.
3818b0cc1b8b0c4acc565e8e2cb8b0b61aa5a300ecaryclark@google.com *
4818b0cc1b8b0c4acc565e8e2cb8b0b61aa5a300ecaryclark@google.com * Use of this source code is governed by a BSD-style license that can be
5818b0cc1b8b0c4acc565e8e2cb8b0b61aa5a300ecaryclark@google.com * found in the LICENSE file.
6818b0cc1b8b0c4acc565e8e2cb8b0b61aa5a300ecaryclark@google.com */
7818b0cc1b8b0c4acc565e8e2cb8b0b61aa5a300ecaryclark@google.com#include "PathOpsExtendedTest.h"
866089e4ec4f1702caf2154780471417872862148caryclark@google.com#include "PathOpsThreadedCommon.h"
9818b0cc1b8b0c4acc565e8e2cb8b0b61aa5a300ecaryclark@google.com
10818b0cc1b8b0c4acc565e8e2cb8b0b61aa5a300ecaryclark@google.com// four rects, of four sizes
11818b0cc1b8b0c4acc565e8e2cb8b0b61aa5a300ecaryclark@google.com// for 3 smaller sizes, tall, wide
12818b0cc1b8b0c4acc565e8e2cb8b0b61aa5a300ecaryclark@google.com    // top upper mid lower bottom aligned (3 bits, 5 values)
13818b0cc1b8b0c4acc565e8e2cb8b0b61aa5a300ecaryclark@google.com    // same with x (3 bits, 5 values)
14818b0cc1b8b0c4acc565e8e2cb8b0b61aa5a300ecaryclark@google.com// not included, square, tall, wide (2 bits)
15818b0cc1b8b0c4acc565e8e2cb8b0b61aa5a300ecaryclark@google.com// cw or ccw (1 bit)
16818b0cc1b8b0c4acc565e8e2cb8b0b61aa5a300ecaryclark@google.com
1766089e4ec4f1702caf2154780471417872862148caryclark@google.comstatic void testSimplify4x4RectsMain(PathOpsThreadState* data)
18818b0cc1b8b0c4acc565e8e2cb8b0b61aa5a300ecaryclark@google.com{
19818b0cc1b8b0c4acc565e8e2cb8b0b61aa5a300ecaryclark@google.com    SkASSERT(data);
2066089e4ec4f1702caf2154780471417872862148caryclark@google.com    PathOpsThreadState& state = *data;
21818b0cc1b8b0c4acc565e8e2cb8b0b61aa5a300ecaryclark@google.com    char pathStr[1024];  // gdb: set print elements 400
228d0a524a4847bc7e1cc63a93b78922739466c201caryclark@google.com    bool progress = state.fReporter->verbose(); // FIXME: break out into its own parameter?
238d0a524a4847bc7e1cc63a93b78922739466c201caryclark@google.com    if (progress) {
248d0a524a4847bc7e1cc63a93b78922739466c201caryclark@google.com        sk_bzero(pathStr, sizeof(pathStr));
258d0a524a4847bc7e1cc63a93b78922739466c201caryclark@google.com    }
2666089e4ec4f1702caf2154780471417872862148caryclark@google.com    int aShape = state.fA & 0x03;
2766089e4ec4f1702caf2154780471417872862148caryclark@google.com    SkPath::Direction aCW = state.fA >> 2 ? SkPath::kCCW_Direction : SkPath::kCW_Direction;
2866089e4ec4f1702caf2154780471417872862148caryclark@google.com    int bShape = state.fB & 0x03;
2966089e4ec4f1702caf2154780471417872862148caryclark@google.com    SkPath::Direction bCW = state.fB >> 2 ? SkPath::kCCW_Direction : SkPath::kCW_Direction;
3066089e4ec4f1702caf2154780471417872862148caryclark@google.com    int cShape = state.fC & 0x03;
3166089e4ec4f1702caf2154780471417872862148caryclark@google.com    SkPath::Direction cCW = state.fC >> 2 ? SkPath::kCCW_Direction : SkPath::kCW_Direction;
3266089e4ec4f1702caf2154780471417872862148caryclark@google.com    int dShape = state.fD & 0x03;
3366089e4ec4f1702caf2154780471417872862148caryclark@google.com    SkPath::Direction dCW = state.fD >> 2 ? SkPath::kCCW_Direction : SkPath::kCW_Direction;
3466089e4ec4f1702caf2154780471417872862148caryclark@google.com    for (int aXAlign = 0; aXAlign < 5; ++aXAlign) {
3566089e4ec4f1702caf2154780471417872862148caryclark@google.com        for (int aYAlign = 0; aYAlign < 5; ++aYAlign) {
3666089e4ec4f1702caf2154780471417872862148caryclark@google.com            for (int bXAlign = 0; bXAlign < 5; ++bXAlign) {
3766089e4ec4f1702caf2154780471417872862148caryclark@google.com                for (int bYAlign = 0; bYAlign < 5; ++bYAlign) {
3866089e4ec4f1702caf2154780471417872862148caryclark@google.com                    for (int cXAlign = 0; cXAlign < 5; ++cXAlign) {
3966089e4ec4f1702caf2154780471417872862148caryclark@google.com                         for (int cYAlign = 0; cYAlign < 5; ++cYAlign) {
4066089e4ec4f1702caf2154780471417872862148caryclark@google.com                            for (int dXAlign = 0; dXAlign < 5; ++dXAlign) {
4166089e4ec4f1702caf2154780471417872862148caryclark@google.com    for (int dYAlign = 0; dYAlign < 5; ++dYAlign) {
4266089e4ec4f1702caf2154780471417872862148caryclark@google.com        SkPath path, out;
4366089e4ec4f1702caf2154780471417872862148caryclark@google.com        char* str = pathStr;
4466089e4ec4f1702caf2154780471417872862148caryclark@google.com        path.setFillType(SkPath::kWinding_FillType);
4566089e4ec4f1702caf2154780471417872862148caryclark@google.com        int l, t, r, b;
4666089e4ec4f1702caf2154780471417872862148caryclark@google.com        if (aShape) {
4766089e4ec4f1702caf2154780471417872862148caryclark@google.com            switch (aShape) {
4866089e4ec4f1702caf2154780471417872862148caryclark@google.com                case 1:  // square
4966089e4ec4f1702caf2154780471417872862148caryclark@google.com                    l =  0; r = 60;
5066089e4ec4f1702caf2154780471417872862148caryclark@google.com                    t =  0; b = 60;
5166089e4ec4f1702caf2154780471417872862148caryclark@google.com                    aXAlign = 5;
5266089e4ec4f1702caf2154780471417872862148caryclark@google.com                    aYAlign = 5;
5366089e4ec4f1702caf2154780471417872862148caryclark@google.com                    break;
5466089e4ec4f1702caf2154780471417872862148caryclark@google.com                case 2:
5566089e4ec4f1702caf2154780471417872862148caryclark@google.com                    l =  aXAlign * 12;
5666089e4ec4f1702caf2154780471417872862148caryclark@google.com                    r =  l + 30;
5766089e4ec4f1702caf2154780471417872862148caryclark@google.com                    t =  0; b = 60;
5866089e4ec4f1702caf2154780471417872862148caryclark@google.com                    aYAlign = 5;
5966089e4ec4f1702caf2154780471417872862148caryclark@google.com                    break;
6066089e4ec4f1702caf2154780471417872862148caryclark@google.com                case 3:
6166089e4ec4f1702caf2154780471417872862148caryclark@google.com                    l =  0; r = 60;
6266089e4ec4f1702caf2154780471417872862148caryclark@google.com                    t =  aYAlign * 12;
6366089e4ec4f1702caf2154780471417872862148caryclark@google.com                    b =  l + 30;
6466089e4ec4f1702caf2154780471417872862148caryclark@google.com                    aXAlign = 5;
6566089e4ec4f1702caf2154780471417872862148caryclark@google.com                    break;
66818b0cc1b8b0c4acc565e8e2cb8b0b61aa5a300ecaryclark@google.com            }
6766089e4ec4f1702caf2154780471417872862148caryclark@google.com            path.addRect(SkIntToScalar(l), SkIntToScalar(t), SkIntToScalar(r), SkIntToScalar(b),
6866089e4ec4f1702caf2154780471417872862148caryclark@google.com                    aCW);
698d0a524a4847bc7e1cc63a93b78922739466c201caryclark@google.com            if (progress) {
708d0a524a4847bc7e1cc63a93b78922739466c201caryclark@google.com                str += sprintf(str, "    path.addRect(%d, %d, %d, %d,"
718d0a524a4847bc7e1cc63a93b78922739466c201caryclark@google.com                        " SkPath::kC%sW_Direction);\n", l, t, r, b, aCW ? "C" : "");
728d0a524a4847bc7e1cc63a93b78922739466c201caryclark@google.com            }
7366089e4ec4f1702caf2154780471417872862148caryclark@google.com        } else {
7466089e4ec4f1702caf2154780471417872862148caryclark@google.com            aXAlign = 5;
7566089e4ec4f1702caf2154780471417872862148caryclark@google.com            aYAlign = 5;
7666089e4ec4f1702caf2154780471417872862148caryclark@google.com        }
7766089e4ec4f1702caf2154780471417872862148caryclark@google.com        if (bShape) {
7866089e4ec4f1702caf2154780471417872862148caryclark@google.com            switch (bShape) {
7966089e4ec4f1702caf2154780471417872862148caryclark@google.com                case 1:  // square
8066089e4ec4f1702caf2154780471417872862148caryclark@google.com                    l =  bXAlign * 10;
8166089e4ec4f1702caf2154780471417872862148caryclark@google.com                    r =  l + 20;
8266089e4ec4f1702caf2154780471417872862148caryclark@google.com                    t =  bYAlign * 10;
8366089e4ec4f1702caf2154780471417872862148caryclark@google.com                    b =  l + 20;
8466089e4ec4f1702caf2154780471417872862148caryclark@google.com                    break;
8566089e4ec4f1702caf2154780471417872862148caryclark@google.com                case 2:
8666089e4ec4f1702caf2154780471417872862148caryclark@google.com                    l =  bXAlign * 10;
8766089e4ec4f1702caf2154780471417872862148caryclark@google.com                    r =  l + 20;
8866089e4ec4f1702caf2154780471417872862148caryclark@google.com                    t =  10; b = 40;
8966089e4ec4f1702caf2154780471417872862148caryclark@google.com                    bYAlign = 5;
9066089e4ec4f1702caf2154780471417872862148caryclark@google.com                    break;
9166089e4ec4f1702caf2154780471417872862148caryclark@google.com                case 3:
9266089e4ec4f1702caf2154780471417872862148caryclark@google.com                    l =  10; r = 40;
9366089e4ec4f1702caf2154780471417872862148caryclark@google.com                    t =  bYAlign * 10;
9466089e4ec4f1702caf2154780471417872862148caryclark@google.com                    b =  l + 20;
9566089e4ec4f1702caf2154780471417872862148caryclark@google.com                    bXAlign = 5;
9666089e4ec4f1702caf2154780471417872862148caryclark@google.com                    break;
97818b0cc1b8b0c4acc565e8e2cb8b0b61aa5a300ecaryclark@google.com            }
9866089e4ec4f1702caf2154780471417872862148caryclark@google.com            path.addRect(SkIntToScalar(l), SkIntToScalar(t), SkIntToScalar(r), SkIntToScalar(b),
9966089e4ec4f1702caf2154780471417872862148caryclark@google.com                    bCW);
1008d0a524a4847bc7e1cc63a93b78922739466c201caryclark@google.com            if (progress) {
1018d0a524a4847bc7e1cc63a93b78922739466c201caryclark@google.com                str += sprintf(str, "    path.addRect(%d, %d, %d, %d,"
1028d0a524a4847bc7e1cc63a93b78922739466c201caryclark@google.com                        " SkPath::kC%sW_Direction);\n", l, t, r, b, bCW ? "C" : "");
1038d0a524a4847bc7e1cc63a93b78922739466c201caryclark@google.com            }
10466089e4ec4f1702caf2154780471417872862148caryclark@google.com        } else {
10566089e4ec4f1702caf2154780471417872862148caryclark@google.com            bXAlign = 5;
10666089e4ec4f1702caf2154780471417872862148caryclark@google.com            bYAlign = 5;
10766089e4ec4f1702caf2154780471417872862148caryclark@google.com        }
10866089e4ec4f1702caf2154780471417872862148caryclark@google.com        if (cShape) {
10966089e4ec4f1702caf2154780471417872862148caryclark@google.com            switch (cShape) {
11066089e4ec4f1702caf2154780471417872862148caryclark@google.com                case 1:  // square
11166089e4ec4f1702caf2154780471417872862148caryclark@google.com                    l =  cXAlign * 6;
11266089e4ec4f1702caf2154780471417872862148caryclark@google.com                    r =  l + 12;
11366089e4ec4f1702caf2154780471417872862148caryclark@google.com                    t =  cYAlign * 6;
11466089e4ec4f1702caf2154780471417872862148caryclark@google.com                    b =  l + 12;
11566089e4ec4f1702caf2154780471417872862148caryclark@google.com                    break;
11666089e4ec4f1702caf2154780471417872862148caryclark@google.com                case 2:
11766089e4ec4f1702caf2154780471417872862148caryclark@google.com                    l =  cXAlign * 6;
11866089e4ec4f1702caf2154780471417872862148caryclark@google.com                    r =  l + 12;
11966089e4ec4f1702caf2154780471417872862148caryclark@google.com                    t =  20; b = 30;
12066089e4ec4f1702caf2154780471417872862148caryclark@google.com                    cYAlign = 5;
12166089e4ec4f1702caf2154780471417872862148caryclark@google.com                    break;
12266089e4ec4f1702caf2154780471417872862148caryclark@google.com                case 3:
12366089e4ec4f1702caf2154780471417872862148caryclark@google.com                    l =  20; r = 30;
12466089e4ec4f1702caf2154780471417872862148caryclark@google.com                    t =  cYAlign * 6;
12566089e4ec4f1702caf2154780471417872862148caryclark@google.com                    b =  l + 20;
12666089e4ec4f1702caf2154780471417872862148caryclark@google.com                    cXAlign = 5;
12766089e4ec4f1702caf2154780471417872862148caryclark@google.com                    break;
128818b0cc1b8b0c4acc565e8e2cb8b0b61aa5a300ecaryclark@google.com            }
12966089e4ec4f1702caf2154780471417872862148caryclark@google.com            path.addRect(SkIntToScalar(l), SkIntToScalar(t), SkIntToScalar(r), SkIntToScalar(b),
13066089e4ec4f1702caf2154780471417872862148caryclark@google.com                    cCW);
1318d0a524a4847bc7e1cc63a93b78922739466c201caryclark@google.com            if (progress) {
1328d0a524a4847bc7e1cc63a93b78922739466c201caryclark@google.com                str += sprintf(str, "    path.addRect(%d, %d, %d, %d,"
1338d0a524a4847bc7e1cc63a93b78922739466c201caryclark@google.com                        " SkPath::kC%sW_Direction);\n", l, t, r, b, cCW ? "C" : "");
1348d0a524a4847bc7e1cc63a93b78922739466c201caryclark@google.com            }
13566089e4ec4f1702caf2154780471417872862148caryclark@google.com        } else {
13666089e4ec4f1702caf2154780471417872862148caryclark@google.com            cXAlign = 5;
13766089e4ec4f1702caf2154780471417872862148caryclark@google.com            cYAlign = 5;
13866089e4ec4f1702caf2154780471417872862148caryclark@google.com        }
13966089e4ec4f1702caf2154780471417872862148caryclark@google.com        if (dShape) {
14066089e4ec4f1702caf2154780471417872862148caryclark@google.com            switch (dShape) {
14166089e4ec4f1702caf2154780471417872862148caryclark@google.com                case 1:  // square
14266089e4ec4f1702caf2154780471417872862148caryclark@google.com                    l =  dXAlign * 4;
14366089e4ec4f1702caf2154780471417872862148caryclark@google.com                    r =  l + 9;
14466089e4ec4f1702caf2154780471417872862148caryclark@google.com                    t =  dYAlign * 4;
14566089e4ec4f1702caf2154780471417872862148caryclark@google.com                    b =  l + 9;
14666089e4ec4f1702caf2154780471417872862148caryclark@google.com                    break;
14766089e4ec4f1702caf2154780471417872862148caryclark@google.com                case 2:
14866089e4ec4f1702caf2154780471417872862148caryclark@google.com                    l =  dXAlign * 6;
14966089e4ec4f1702caf2154780471417872862148caryclark@google.com                    r =  l + 9;
15066089e4ec4f1702caf2154780471417872862148caryclark@google.com                    t =  32; b = 36;
15166089e4ec4f1702caf2154780471417872862148caryclark@google.com                    dYAlign = 5;
15266089e4ec4f1702caf2154780471417872862148caryclark@google.com                    break;
15366089e4ec4f1702caf2154780471417872862148caryclark@google.com                case 3:
15466089e4ec4f1702caf2154780471417872862148caryclark@google.com                    l =  32; r = 36;
15566089e4ec4f1702caf2154780471417872862148caryclark@google.com                    t =  dYAlign * 6;
15666089e4ec4f1702caf2154780471417872862148caryclark@google.com                    b =  l + 9;
15766089e4ec4f1702caf2154780471417872862148caryclark@google.com                    dXAlign = 5;
15866089e4ec4f1702caf2154780471417872862148caryclark@google.com                    break;
159818b0cc1b8b0c4acc565e8e2cb8b0b61aa5a300ecaryclark@google.com            }
16066089e4ec4f1702caf2154780471417872862148caryclark@google.com            path.addRect(SkIntToScalar(l), SkIntToScalar(t), SkIntToScalar(r), SkIntToScalar(b),
16166089e4ec4f1702caf2154780471417872862148caryclark@google.com                    dCW);
1628d0a524a4847bc7e1cc63a93b78922739466c201caryclark@google.com            if (progress) {
1638d0a524a4847bc7e1cc63a93b78922739466c201caryclark@google.com                str += sprintf(str, "    path.addRect(%d, %d, %d, %d,"
1648d0a524a4847bc7e1cc63a93b78922739466c201caryclark@google.com                        " SkPath::kC%sW_Direction);\n", l, t, r, b, dCW ? "C" : "");
1658d0a524a4847bc7e1cc63a93b78922739466c201caryclark@google.com            }
16666089e4ec4f1702caf2154780471417872862148caryclark@google.com        } else {
16766089e4ec4f1702caf2154780471417872862148caryclark@google.com            dXAlign = 5;
16866089e4ec4f1702caf2154780471417872862148caryclark@google.com            dYAlign = 5;
16966089e4ec4f1702caf2154780471417872862148caryclark@google.com        }
17066089e4ec4f1702caf2154780471417872862148caryclark@google.com        path.close();
1718d0a524a4847bc7e1cc63a93b78922739466c201caryclark@google.com        if (progress) {
1728d0a524a4847bc7e1cc63a93b78922739466c201caryclark@google.com            outputProgress(state.fPathStr, pathStr, SkPath::kWinding_FillType);
1738d0a524a4847bc7e1cc63a93b78922739466c201caryclark@google.com        }
17466089e4ec4f1702caf2154780471417872862148caryclark@google.com        testSimplify(path, false, out, state, pathStr);
1758d0a524a4847bc7e1cc63a93b78922739466c201caryclark@google.com        if (progress) {
1768d0a524a4847bc7e1cc63a93b78922739466c201caryclark@google.com            outputProgress(state.fPathStr, pathStr, SkPath::kEvenOdd_FillType);
1778d0a524a4847bc7e1cc63a93b78922739466c201caryclark@google.com        }
17866089e4ec4f1702caf2154780471417872862148caryclark@google.com        testSimplify(path, true, out, state, pathStr);
17966089e4ec4f1702caf2154780471417872862148caryclark@google.com    }
180818b0cc1b8b0c4acc565e8e2cb8b0b61aa5a300ecaryclark@google.com                            }
181818b0cc1b8b0c4acc565e8e2cb8b0b61aa5a300ecaryclark@google.com                        }
182818b0cc1b8b0c4acc565e8e2cb8b0b61aa5a300ecaryclark@google.com                    }
183818b0cc1b8b0c4acc565e8e2cb8b0b61aa5a300ecaryclark@google.com                }
184818b0cc1b8b0c4acc565e8e2cb8b0b61aa5a300ecaryclark@google.com            }
185818b0cc1b8b0c4acc565e8e2cb8b0b61aa5a300ecaryclark@google.com        }
18666089e4ec4f1702caf2154780471417872862148caryclark@google.com    }
187818b0cc1b8b0c4acc565e8e2cb8b0b61aa5a300ecaryclark@google.com}
188818b0cc1b8b0c4acc565e8e2cb8b0b61aa5a300ecaryclark@google.com
18978e7b4e1b928fa69f672be3c743df6d6c3ecbcedtfarina@chromium.orgDEF_TEST(PathOpsSimplifyRectsThreaded, reporter) {
19016cfe40276bfb0a4d98c9ad995b8e5b134a49b19caryclark@google.com    int threadCount = initializeTests(reporter, "testLine");
19166089e4ec4f1702caf2154780471417872862148caryclark@google.com    PathOpsThreadedTestRunner testRunner(reporter, threadCount);
192818b0cc1b8b0c4acc565e8e2cb8b0b61aa5a300ecaryclark@google.com    for (int a = 0; a < 8; ++a) {  // outermost
193818b0cc1b8b0c4acc565e8e2cb8b0b61aa5a300ecaryclark@google.com        for (int b = a ; b < 8; ++b) {
194818b0cc1b8b0c4acc565e8e2cb8b0b61aa5a300ecaryclark@google.com            for (int c = b ; c < 8; ++c) {
195818b0cc1b8b0c4acc565e8e2cb8b0b61aa5a300ecaryclark@google.com                for (int d = c; d < 8; ++d) {
19666089e4ec4f1702caf2154780471417872862148caryclark@google.com                        *testRunner.fRunnables.append() = SkNEW_ARGS(PathOpsThreadedRunnable,
19766089e4ec4f1702caf2154780471417872862148caryclark@google.com                                (&testSimplify4x4RectsMain, a, b, c, d, &testRunner));
198818b0cc1b8b0c4acc565e8e2cb8b0b61aa5a300ecaryclark@google.com                }
19966089e4ec4f1702caf2154780471417872862148caryclark@google.com                if (!reporter->allowExtendedTest()) goto finish;
200818b0cc1b8b0c4acc565e8e2cb8b0b61aa5a300ecaryclark@google.com            }
201818b0cc1b8b0c4acc565e8e2cb8b0b61aa5a300ecaryclark@google.com        }
202818b0cc1b8b0c4acc565e8e2cb8b0b61aa5a300ecaryclark@google.com    }
203818b0cc1b8b0c4acc565e8e2cb8b0b61aa5a300ecaryclark@google.comfinish:
20466089e4ec4f1702caf2154780471417872862148caryclark@google.com    testRunner.render();
205818b0cc1b8b0c4acc565e8e2cb8b0b61aa5a300ecaryclark@google.com}
206