19e49fb63d355446b91d20ff78ad78b297e89a50dcaryclark@google.com/*
29e49fb63d355446b91d20ff78ad78b297e89a50dcaryclark@google.com * Copyright 2012 Google Inc.
39e49fb63d355446b91d20ff78ad78b297e89a50dcaryclark@google.com *
49e49fb63d355446b91d20ff78ad78b297e89a50dcaryclark@google.com * Use of this source code is governed by a BSD-style license that can be
59e49fb63d355446b91d20ff78ad78b297e89a50dcaryclark@google.com * found in the LICENSE file.
69e49fb63d355446b91d20ff78ad78b297e89a50dcaryclark@google.com */
7fa0588ff672564af1c235a63589573829035a60bcaryclark@google.com#include "EdgeWalker_Test.h"
8fa0588ff672564af1c235a63589573829035a60bcaryclark@google.com#include "Intersection_Tests.h"
9fa0588ff672564af1c235a63589573829035a60bcaryclark@google.com#include "SkBitmap.h"
10fa0588ff672564af1c235a63589573829035a60bcaryclark@google.com#include "SkCanvas.h"
11fa0588ff672564af1c235a63589573829035a60bcaryclark@google.com
12fa0588ff672564af1c235a63589573829035a60bcaryclark@google.com
13fa0588ff672564af1c235a63589573829035a60bcaryclark@google.comstatic void* testSimplify4x4QuadraticsMain(void* data)
14fa0588ff672564af1c235a63589573829035a60bcaryclark@google.com{
15fa0588ff672564af1c235a63589573829035a60bcaryclark@google.com    SkASSERT(data);
16fa0588ff672564af1c235a63589573829035a60bcaryclark@google.com    State4& state = *(State4*) data;
1759823f7f3ba43c7c6bc1fa8c600b093ecb4236aacaryclark@google.com    char pathStr[1024];
1859823f7f3ba43c7c6bc1fa8c600b093ecb4236aacaryclark@google.com    bzero(pathStr, sizeof(pathStr));
1959823f7f3ba43c7c6bc1fa8c600b093ecb4236aacaryclark@google.com    do {
2059823f7f3ba43c7c6bc1fa8c600b093ecb4236aacaryclark@google.com        int ax = state.a & 0x03;
2159823f7f3ba43c7c6bc1fa8c600b093ecb4236aacaryclark@google.com        int ay = state.a >> 2;
2259823f7f3ba43c7c6bc1fa8c600b093ecb4236aacaryclark@google.com        int bx = state.b & 0x03;
2359823f7f3ba43c7c6bc1fa8c600b093ecb4236aacaryclark@google.com        int by = state.b >> 2;
2459823f7f3ba43c7c6bc1fa8c600b093ecb4236aacaryclark@google.com        int cx = state.c & 0x03;
2559823f7f3ba43c7c6bc1fa8c600b093ecb4236aacaryclark@google.com        int cy = state.c >> 2;
2659823f7f3ba43c7c6bc1fa8c600b093ecb4236aacaryclark@google.com        int dx = state.d & 0x03;
2759823f7f3ba43c7c6bc1fa8c600b093ecb4236aacaryclark@google.com        int dy = state.d >> 2;
2859823f7f3ba43c7c6bc1fa8c600b093ecb4236aacaryclark@google.com        for (int e = 0 ; e < 16; ++e) {
2959823f7f3ba43c7c6bc1fa8c600b093ecb4236aacaryclark@google.com            int ex = e & 0x03;
3059823f7f3ba43c7c6bc1fa8c600b093ecb4236aacaryclark@google.com            int ey = e >> 2;
3159823f7f3ba43c7c6bc1fa8c600b093ecb4236aacaryclark@google.com            for (int f = e ; f < 16; ++f) {
3259823f7f3ba43c7c6bc1fa8c600b093ecb4236aacaryclark@google.com                int fx = f & 0x03;
3359823f7f3ba43c7c6bc1fa8c600b093ecb4236aacaryclark@google.com                int fy = f >> 2;
3459823f7f3ba43c7c6bc1fa8c600b093ecb4236aacaryclark@google.com                for (int g = f ; g < 16; ++g) {
3559823f7f3ba43c7c6bc1fa8c600b093ecb4236aacaryclark@google.com                    int gx = g & 0x03;
3659823f7f3ba43c7c6bc1fa8c600b093ecb4236aacaryclark@google.com                    int gy = g >> 2;
3759823f7f3ba43c7c6bc1fa8c600b093ecb4236aacaryclark@google.com                    for (int h = g ; h < 16; ++h) {
3859823f7f3ba43c7c6bc1fa8c600b093ecb4236aacaryclark@google.com                        int hx = h & 0x03;
3959823f7f3ba43c7c6bc1fa8c600b093ecb4236aacaryclark@google.com                        int hy = h >> 2;
4059823f7f3ba43c7c6bc1fa8c600b093ecb4236aacaryclark@google.com                        SkPath path, out;
4159823f7f3ba43c7c6bc1fa8c600b093ecb4236aacaryclark@google.com                        path.setFillType(SkPath::kWinding_FillType);
4259823f7f3ba43c7c6bc1fa8c600b093ecb4236aacaryclark@google.com                        path.moveTo(ax, ay);
4359823f7f3ba43c7c6bc1fa8c600b093ecb4236aacaryclark@google.com                        path.quadTo(bx, by, cx, cy);
4459823f7f3ba43c7c6bc1fa8c600b093ecb4236aacaryclark@google.com                        path.lineTo(dx, dy);
4559823f7f3ba43c7c6bc1fa8c600b093ecb4236aacaryclark@google.com                        path.close();
4659823f7f3ba43c7c6bc1fa8c600b093ecb4236aacaryclark@google.com                        path.moveTo(ex, ey);
4759823f7f3ba43c7c6bc1fa8c600b093ecb4236aacaryclark@google.com                        path.lineTo(fx, fy);
4859823f7f3ba43c7c6bc1fa8c600b093ecb4236aacaryclark@google.com                        path.quadTo(gx, gy, hx, hy);
4959823f7f3ba43c7c6bc1fa8c600b093ecb4236aacaryclark@google.com                        path.close();
5059823f7f3ba43c7c6bc1fa8c600b093ecb4236aacaryclark@google.com                        if (1) {  // gdb: set print elements 400
5159823f7f3ba43c7c6bc1fa8c600b093ecb4236aacaryclark@google.com                            char* str = pathStr;
5259823f7f3ba43c7c6bc1fa8c600b093ecb4236aacaryclark@google.com                            str += sprintf(str, "    path.moveTo(%d, %d);\n", ax, ay);
5359823f7f3ba43c7c6bc1fa8c600b093ecb4236aacaryclark@google.com                            str += sprintf(str, "    path.quadTo(%d, %d, %d, %d);\n", bx, by, cx, cy);
5459823f7f3ba43c7c6bc1fa8c600b093ecb4236aacaryclark@google.com                            str += sprintf(str, "    path.lineTo(%d, %d);\n", dx, dy);
5559823f7f3ba43c7c6bc1fa8c600b093ecb4236aacaryclark@google.com                            str += sprintf(str, "    path.close();\n");
5659823f7f3ba43c7c6bc1fa8c600b093ecb4236aacaryclark@google.com                            str += sprintf(str, "    path.moveTo(%d, %d);\n", ex, ey);
5759823f7f3ba43c7c6bc1fa8c600b093ecb4236aacaryclark@google.com                            str += sprintf(str, "    path.lineTo(%d, %d);\n", fx, fy);
5859823f7f3ba43c7c6bc1fa8c600b093ecb4236aacaryclark@google.com                            str += sprintf(str, "    path.quadTo(%d, %d, %d, %d);\n", gx, gy, hx, hy);
5959823f7f3ba43c7c6bc1fa8c600b093ecb4236aacaryclark@google.com                            str += sprintf(str, "    path.close();\n");
6059823f7f3ba43c7c6bc1fa8c600b093ecb4236aacaryclark@google.com                        }
6124bec79d6f3d71ff97b50db72461a3892bd4f6b5caryclark@google.com                        outputProgress(state, pathStr, SkPath::kWinding_FillType);
6224bec79d6f3d71ff97b50db72461a3892bd4f6b5caryclark@google.com                        testSimplifyx(path, false, out, state, pathStr);
6359823f7f3ba43c7c6bc1fa8c600b093ecb4236aacaryclark@google.com                        state.testsRun++;
6459823f7f3ba43c7c6bc1fa8c600b093ecb4236aacaryclark@google.com                        path.setFillType(SkPath::kEvenOdd_FillType);
6559823f7f3ba43c7c6bc1fa8c600b093ecb4236aacaryclark@google.com                        outputProgress(state, pathStr, SkPath::kEvenOdd_FillType);
6659823f7f3ba43c7c6bc1fa8c600b093ecb4236aacaryclark@google.com                        testSimplifyx(path, true, out, state, pathStr);
6759823f7f3ba43c7c6bc1fa8c600b093ecb4236aacaryclark@google.com                        state.testsRun++;
68fa0588ff672564af1c235a63589573829035a60bcaryclark@google.com                    }
69fa0588ff672564af1c235a63589573829035a60bcaryclark@google.com                }
70fa0588ff672564af1c235a63589573829035a60bcaryclark@google.com            }
71fa0588ff672564af1c235a63589573829035a60bcaryclark@google.com        }
7259823f7f3ba43c7c6bc1fa8c600b093ecb4236aacaryclark@google.com    } while (runNextTestSet(state));
73fa0588ff672564af1c235a63589573829035a60bcaryclark@google.com    return NULL;
74fa0588ff672564af1c235a63589573829035a60bcaryclark@google.com}
75fa0588ff672564af1c235a63589573829035a60bcaryclark@google.com
7624bec79d6f3d71ff97b50db72461a3892bd4f6b5caryclark@google.comvoid Simplify4x4QuadraticsThreaded_Test(int& testsRun)
77fa0588ff672564af1c235a63589573829035a60bcaryclark@google.com{
7859823f7f3ba43c7c6bc1fa8c600b093ecb4236aacaryclark@google.com    SkDebugf("%s\n", __FUNCTION__);
7959823f7f3ba43c7c6bc1fa8c600b093ecb4236aacaryclark@google.com#ifdef SK_DEBUG
8059823f7f3ba43c7c6bc1fa8c600b093ecb4236aacaryclark@google.com    gDebugMaxWindSum = 4; // FIXME: 3?
8159823f7f3ba43c7c6bc1fa8c600b093ecb4236aacaryclark@google.com    gDebugMaxWindValue = 4;
8259823f7f3ba43c7c6bc1fa8c600b093ecb4236aacaryclark@google.com#endif
8359823f7f3ba43c7c6bc1fa8c600b093ecb4236aacaryclark@google.com    const char testStr[] = "testQuadratic";
8459823f7f3ba43c7c6bc1fa8c600b093ecb4236aacaryclark@google.com    initializeTests(testStr, sizeof(testStr));
8524bec79d6f3d71ff97b50db72461a3892bd4f6b5caryclark@google.com    int testsStart = testsRun;
868f9f468b0555e95b8fc3cf4e6ee1f1fbf5492a1bcaryclark@google.com    int a = 0;
878f9f468b0555e95b8fc3cf4e6ee1f1fbf5492a1bcaryclark@google.com#define SKIP_A 0
888f9f468b0555e95b8fc3cf4e6ee1f1fbf5492a1bcaryclark@google.com#if SKIP_A
898f9f468b0555e95b8fc3cf4e6ee1f1fbf5492a1bcaryclark@google.com    a = 2;
908f9f468b0555e95b8fc3cf4e6ee1f1fbf5492a1bcaryclark@google.com#endif
918f9f468b0555e95b8fc3cf4e6ee1f1fbf5492a1bcaryclark@google.com    for (; a < 16; ++a) {
92fa0588ff672564af1c235a63589573829035a60bcaryclark@google.com        for (int b = a ; b < 16; ++b) {
93fa0588ff672564af1c235a63589573829035a60bcaryclark@google.com            for (int c = b ; c < 16; ++c) {
94d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com                for (int d = c; d < 16; ++d) {
9559823f7f3ba43c7c6bc1fa8c600b093ecb4236aacaryclark@google.com                    testsRun += dispatchTest4(testSimplify4x4QuadraticsMain,
9659823f7f3ba43c7c6bc1fa8c600b093ecb4236aacaryclark@google.com                            a, b, c, d);
97fa0588ff672564af1c235a63589573829035a60bcaryclark@google.com                }
9859823f7f3ba43c7c6bc1fa8c600b093ecb4236aacaryclark@google.com                if (!gRunTestsInOneThread) SkDebugf(".");
99fa0588ff672564af1c235a63589573829035a60bcaryclark@google.com            }
10059823f7f3ba43c7c6bc1fa8c600b093ecb4236aacaryclark@google.com            if (!gRunTestsInOneThread) SkDebugf("%d", b);
101fa0588ff672564af1c235a63589573829035a60bcaryclark@google.com        }
10259823f7f3ba43c7c6bc1fa8c600b093ecb4236aacaryclark@google.com        if (!gRunTestsInOneThread) SkDebugf("\n%d", a);
103fa0588ff672564af1c235a63589573829035a60bcaryclark@google.com    }
10459823f7f3ba43c7c6bc1fa8c600b093ecb4236aacaryclark@google.com    testsRun += waitForCompletion();
10524bec79d6f3d71ff97b50db72461a3892bd4f6b5caryclark@google.com    SkDebugf("%s tests=%d total=%d\n", __FUNCTION__, testsRun - testsStart, testsRun);
106fa0588ff672564af1c235a63589573829035a60bcaryclark@google.com}
107