EdgeWalkerQuadratic4x4_Test.cpp revision d6176b0dcacb124539e0cfd051e6d93a9782f020
1#include "EdgeWalker_Test.h"
2#include "Intersection_Tests.h"
3#include "SkBitmap.h"
4#include "SkCanvas.h"
5#include <assert.h>
6
7
8static void* testSimplify4x4QuadraticsMain(void* data)
9{
10    SkASSERT(data);
11    State4& state = *(State4*) data;
12    char pathStr[1024];
13    bzero(pathStr, sizeof(pathStr));
14    do {
15        int ax = state.a & 0x03;
16        int ay = state.a >> 2;
17        int bx = state.b & 0x03;
18        int by = state.b >> 2;
19        int cx = state.c & 0x03;
20        int cy = state.c >> 2;
21        int dx = state.d & 0x03;
22        int dy = state.d >> 2;
23        for (int e = 0 ; e < 16; ++e) {
24            int ex = e & 0x03;
25            int ey = e >> 2;
26            for (int f = e ; f < 16; ++f) {
27                int fx = f & 0x03;
28                int fy = f >> 2;
29                for (int g = f ; g < 16; ++g) {
30                    int gx = g & 0x03;
31                    int gy = g >> 2;
32                    for (int h = g ; h < 16; ++h) {
33                        int hx = h & 0x03;
34                        int hy = h >> 2;
35                        SkPath path, out;
36                        path.setFillType(SkPath::kWinding_FillType);
37                        path.moveTo(ax, ay);
38                        path.quadTo(bx, by, cx, cy);
39                        path.lineTo(dx, dy);
40                        path.close();
41                        path.moveTo(ex, ey);
42                        path.lineTo(fx, fy);
43                        path.quadTo(gx, gy, hx, hy);
44                        path.close();
45                        if (1) {  // gdb: set print elements 400
46                            char* str = pathStr;
47                            str += sprintf(str, "    path.moveTo(%d, %d);\n", ax, ay);
48                            str += sprintf(str, "    path.quadTo(%d, %d, %d, %d);\n", bx, by, cx, cy);
49                            str += sprintf(str, "    path.lineTo(%d, %d);\n", dx, dy);
50                            str += sprintf(str, "    path.close();\n");
51                            str += sprintf(str, "    path.moveTo(%d, %d);\n", ex, ey);
52                            str += sprintf(str, "    path.lineTo(%d, %d);\n", fx, fy);
53                            str += sprintf(str, "    path.quadTo(%d, %d, %d, %d);\n", gx, gy, hx, hy);
54                            str += sprintf(str, "    path.close();\n");
55                        }
56                        outputProgress(state, pathStr, SkPath::kWinding_FillType);
57                        testSimplifyx(path, false, out, state, pathStr);
58                        state.testsRun++;
59                        path.setFillType(SkPath::kEvenOdd_FillType);
60                        outputProgress(state, pathStr, SkPath::kEvenOdd_FillType);
61                        testSimplifyx(path, true, out, state, pathStr);
62                        state.testsRun++;
63                    }
64                }
65            }
66        }
67    } while (runNextTestSet(state));
68    return NULL;
69}
70
71void Simplify4x4QuadraticsThreaded_Test(int& testsRun)
72{
73    SkDebugf("%s\n", __FUNCTION__);
74#ifdef SK_DEBUG
75    gDebugMaxWindSum = 4; // FIXME: 3?
76    gDebugMaxWindValue = 4;
77#endif
78    const char testStr[] = "testQuadratic";
79    initializeTests(testStr, sizeof(testStr));
80    int testsStart = testsRun;
81    for (int a = 0; a < 16; ++a) {
82        for (int b = a ; b < 16; ++b) {
83            for (int c = b ; c < 16; ++c) {
84                for (int d = c; d < 16; ++d) {
85                    testsRun += dispatchTest4(testSimplify4x4QuadraticsMain,
86                            a, b, c, d);
87                }
88                if (!gRunTestsInOneThread) SkDebugf(".");
89            }
90            if (!gRunTestsInOneThread) SkDebugf("%d", b);
91        }
92        if (!gRunTestsInOneThread) SkDebugf("\n%d", a);
93    }
94    testsRun += waitForCompletion();
95    SkDebugf("%s tests=%d total=%d\n", __FUNCTION__, testsRun - testsStart, testsRun);
96}
97