aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/pathops/SkPathOpsDebug.cpp
blob: 95e2204c33b606ee8e54b8e39a8dcdca9509c9af (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
/*
 * Copyright 2013 Google Inc.
 *
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

#include "SkPathOpsDebug.h"
#include "SkPath.h"

#if defined SK_DEBUG || !FORCE_RELEASE

int SkPathOpsDebug::gMaxWindSum = SK_MaxS32;
int SkPathOpsDebug::gMaxWindValue = SK_MaxS32;

const char* SkPathOpsDebug::kLVerbStr[] = {"", "line", "quad", "cubic"};
int SkPathOpsDebug::gContourID;
int SkPathOpsDebug::gSegmentID;

#if DEBUG_SORT || DEBUG_SWAP_TOP
int SkPathOpsDebug::gSortCountDefault = SK_MaxS32;
int SkPathOpsDebug::gSortCount;
#endif

#if DEBUG_ACTIVE_OP
const char* SkPathOpsDebug::kPathOpStr[] = {"diff", "sect", "union", "xor"};
#endif

void SkPathOpsDebug::MathematicaIze(char* str, size_t bufferLen) {
    size_t len = strlen(str);
    bool num = false;
    for (size_t idx = 0; idx < len; ++idx) {
        if (num && str[idx] == 'e') {
            if (len + 2 >= bufferLen) {
                return;
            }
            memmove(&str[idx + 2], &str[idx + 1], len - idx);
            str[idx] = '*';
            str[idx + 1] = '^';
            ++len;
        }
        num = str[idx] >= '0' && str[idx] <= '9';
    }
}

bool SkPathOpsDebug::ValidWind(int wind) {
    return wind > SK_MinS32 + 0xFFFF && wind < SK_MaxS32 - 0xFFFF;
}

void SkPathOpsDebug::WindingPrintf(int wind) {
    if (wind == SK_MinS32) {
        SkDebugf("?");
    } else {
        SkDebugf("%d", wind);
    }
}

#if DEBUG_SHOW_TEST_NAME
void* SkPathOpsDebug::CreateNameStr() {
    return SkNEW_ARRAY(char, DEBUG_FILENAME_STRING_LENGTH);
}

void SkPathOpsDebug::DeleteNameStr(void* v) {
    SkDELETE_ARRAY(reinterpret_cast<char* >(v));
}

void SkPathOpsDebug::BumpTestName(char* test) {
    char* num = test + strlen(test);
    while (num[-1] >= '0' && num[-1] <= '9') {
        --num;
    }
    if (num[0] == '\0') {
        return;
    }
    int dec = atoi(num);
    if (dec == 0) {
        return;
    }
    ++dec;
    SK_SNPRINTF(num, DEBUG_FILENAME_STRING_LENGTH - (num - test), "%d", dec);
}
#endif

#include "SkOpSegment.h"

void SkPathOpsDebug::DumpAngles(const SkTArray<SkOpAngle, true>& angles) {
    int count = angles.count();
    for (int index = 0; index < count; ++index) {
        angles[index].dump();
    }
}

void SkPathOpsDebug::DumpAngles(const SkTArray<SkOpAngle* , true>& angles) {
    int count = angles.count();
    for (int index = 0; index < count; ++index) {
        angles[index]->dump();
    }
}
#endif  // SK_DEBUG || !FORCE_RELEASE

#ifdef SK_DEBUG
void SkOpSpan::dump() const {
    SkDebugf("t=");
    DebugDumpDouble(fT);
    SkDebugf(" pt=");
    SkDPoint::dump(fPt);
    SkDebugf(" other.fID=%d", fOther->debugID());
    SkDebugf(" [%d] otherT=", fOtherIndex);
    DebugDumpDouble(fOtherT);
    SkDebugf(" windSum=");
    SkPathOpsDebug::WindingPrintf(fWindSum);
    if (SkPathOpsDebug::ValidWind(fOppSum) || fOppValue != 0) {
        SkDebugf(" oppSum=");
        SkPathOpsDebug::WindingPrintf(fOppSum);
    }
    SkDebugf(" windValue=%d", fWindValue);
    if (SkPathOpsDebug::ValidWind(fOppSum) || fOppValue != 0) {
        SkDebugf(" oppValue=%d", fOppValue);
    }
    if (fDone) {
        SkDebugf(" done");
    }
    if (fUnsortableStart) {
        SkDebugf("  unsortable-start");
    }
    if (fUnsortableEnd) {
        SkDebugf(" unsortable-end");
    }
    if (fTiny) {
        SkDebugf(" tiny");
    } else if (fSmall) {
        SkDebugf(" small");
    }
    if (fLoop) {
        SkDebugf(" loop");
    }
    if (fNear) {
        SkDebugf(" near");
    }
    SkDebugf("\n");
}

void Dump(const SkTArray<class SkOpAngle, true>& angles) {
    SkPathOpsDebug::DumpAngles(angles);
}

void Dump(const SkTArray<class SkOpAngle* , true>& angles) {
    SkPathOpsDebug::DumpAngles(angles);
}

void Dump(const SkTArray<class SkOpAngle, true>* angles) {
    SkPathOpsDebug::DumpAngles(*angles);
}

void Dump(const SkTArray<class SkOpAngle* , true>* angles) {
    SkPathOpsDebug::DumpAngles(*angles);
}

#endif

#if !FORCE_RELEASE && 0  // enable when building without extended test
void SkPathOpsDebug::ShowPath(const SkPath& one, const SkPath& two, SkPathOp op, const char* name) {
}
#endif