SkPathOpsDebug.cpp revision cffbcc3b9665f2c928544b6fc6b8a0e22a4210fb
1/*
2 * Copyright 2013 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
8#include "SkPathOpsDebug.h"
9#include "SkPath.h"
10
11#if defined SK_DEBUG || !FORCE_RELEASE
12
13int gDebugMaxWindSum = SK_MaxS32;
14int gDebugMaxWindValue = SK_MaxS32;
15
16void mathematica_ize(char* str, size_t bufferLen) {
17    size_t len = strlen(str);
18    bool num = false;
19    for (size_t idx = 0; idx < len; ++idx) {
20        if (num && str[idx] == 'e') {
21            if (len + 2 >= bufferLen) {
22                return;
23            }
24            memmove(&str[idx + 2], &str[idx + 1], len - idx);
25            str[idx] = '*';
26            str[idx + 1] = '^';
27            ++len;
28        }
29        num = str[idx] >= '0' && str[idx] <= '9';
30    }
31}
32#endif
33
34#if DEBUG_SORT || DEBUG_SWAP_TOP
35bool valid_wind(int wind) {
36    return wind > SK_MinS32 + 0xFFFF && wind < SK_MaxS32 - 0xFFFF;
37}
38
39void winding_printf(int wind) {
40    if (wind == SK_MinS32) {
41        SkDebugf("?");
42    } else {
43        SkDebugf("%d", wind);
44    }
45}
46#endif
47
48#if DEBUG_DUMP
49const char* kLVerbStr[] = {"", "line", "quad", "cubic"};
50// static const char* kUVerbStr[] = {"", "Line", "Quad", "Cubic"};
51int gContourID;
52int gSegmentID;
53#endif
54
55#if DEBUG_SORT || DEBUG_SWAP_TOP
56int gDebugSortCountDefault = SK_MaxS32;
57int gDebugSortCount;
58#endif
59
60#if DEBUG_ACTIVE_OP
61const char* kPathOpStr[] = {"diff", "sect", "union", "xor"};
62#endif
63
64#if DEBUG_SHOW_PATH
65static void showPathContours(SkPath::Iter& iter, const char* pathName) {
66    uint8_t verb;
67    SkPoint pts[4];
68    while ((verb = iter.next(pts)) != SkPath::kDone_Verb) {
69        switch (verb) {
70            case SkPath::kMove_Verb:
71                SkDebugf("    %s.moveTo(%#1.9gf, %#1.9gf);\n", pathName, pts[0].fX, pts[0].fY);
72                continue;
73            case SkPath::kLine_Verb:
74                SkDebugf("    %s.lineTo(%#1.9gf, %#1.9gf);\n", pathName, pts[1].fX, pts[1].fY);
75                break;
76            case SkPath::kQuad_Verb:
77                SkDebugf("    %s.quadTo(%#1.9gf, %#1.9gf, %#1.9gf, %#1.9gf);\n", pathName,
78                    pts[1].fX, pts[1].fY, pts[2].fX, pts[2].fY);
79                break;
80            case SkPath::kCubic_Verb:
81                SkDebugf("    %s.cubicTo(%#1.9gf, %#1.9gf, %#1.9gf, %#1.9gf, %#1.9gf, %#1.9gf);\n",
82                    pathName, pts[1].fX, pts[1].fY, pts[2].fX, pts[2].fY, pts[3].fX, pts[3].fY);
83                break;
84            case SkPath::kClose_Verb:
85                SkDebugf("    %s.close();\n", pathName);
86                break;
87            default:
88                SkDEBUGFAIL("bad verb");
89                return;
90        }
91    }
92}
93
94static const char* gFillTypeStr[] = {
95    "kWinding_FillType",
96    "kEvenOdd_FillType",
97    "kInverseWinding_FillType",
98    "kInverseEvenOdd_FillType"
99};
100
101
102void ShowFunctionHeader() {
103    SkDebugf("\nstatic void test#(skiatest::Reporter* reporter) {\n");
104}
105
106void ShowPath(const SkPath& path, const char* pathName) {
107    SkPath::Iter iter(path, true);
108    SkPath::FillType fillType = path.getFillType();
109    SkASSERT(fillType >= SkPath::kWinding_FillType && fillType <= SkPath::kInverseEvenOdd_FillType);
110    SkDebugf("    SkPath %s;\n", pathName);
111    SkDebugf("    %s.setFillType(SkPath::%s);\n", pathName, gFillTypeStr[fillType]);
112    iter.setPath(path, true);
113    showPathContours(iter, pathName);
114}
115
116static const char* gOpStrs[] = {
117    "kDifference_PathOp",
118    "kIntersect_PathOp",
119    "kUnion_PathOp",
120    "kXor_PathOp",
121    "kReverseDifference_PathOp",
122};
123
124void ShowOp(SkPathOp op, const char* pathOne, const char* pathTwo) {
125    SkDebugf("    testPathOp(reporter, %s, %s, %s);\n", pathOne, pathTwo, gOpStrs[op]);
126    SkDebugf("}\n");
127}
128#endif
129