blob: b68ab2acf889bb2cf88be3445038ae45384cb6d5 [file] [log] [blame]
caryclark@google.com07393ca2013-04-08 11:47:37 +00001/*
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"
caryclark@google.coma5e55922013-05-07 18:51:31 +00009#include "SkPath.h"
caryclark@google.com07393ca2013-04-08 11:47:37 +000010
11#if defined SK_DEBUG || !FORCE_RELEASE
12
caryclark@google.com570863f2013-09-16 15:55:01 +000013int SkPathOpsDebug::gMaxWindSum = SK_MaxS32;
14int SkPathOpsDebug::gMaxWindValue = SK_MaxS32;
caryclark@google.com07393ca2013-04-08 11:47:37 +000015
caryclark@google.com570863f2013-09-16 15:55:01 +000016const char* SkPathOpsDebug::kLVerbStr[] = {"", "line", "quad", "cubic"};
17int SkPathOpsDebug::gContourID;
18int SkPathOpsDebug::gSegmentID;
19
20#if DEBUG_SORT || DEBUG_SWAP_TOP
21int SkPathOpsDebug::gSortCountDefault = SK_MaxS32;
22int SkPathOpsDebug::gSortCount;
23#endif
24
25#if DEBUG_ACTIVE_OP
26const char* SkPathOpsDebug::kPathOpStr[] = {"diff", "sect", "union", "xor"};
27#endif
28
29void SkPathOpsDebug::MathematicaIze(char* str, size_t bufferLen) {
caryclark@google.com07393ca2013-04-08 11:47:37 +000030 size_t len = strlen(str);
31 bool num = false;
32 for (size_t idx = 0; idx < len; ++idx) {
33 if (num && str[idx] == 'e') {
34 if (len + 2 >= bufferLen) {
35 return;
36 }
37 memmove(&str[idx + 2], &str[idx + 1], len - idx);
38 str[idx] = '*';
39 str[idx + 1] = '^';
40 ++len;
41 }
42 num = str[idx] >= '0' && str[idx] <= '9';
43 }
44}
45
caryclark@google.com570863f2013-09-16 15:55:01 +000046bool SkPathOpsDebug::ValidWind(int wind) {
caryclark@google.com07393ca2013-04-08 11:47:37 +000047 return wind > SK_MinS32 + 0xFFFF && wind < SK_MaxS32 - 0xFFFF;
48}
49
caryclark@google.com570863f2013-09-16 15:55:01 +000050void SkPathOpsDebug::WindingPrintf(int wind) {
caryclark@google.com07393ca2013-04-08 11:47:37 +000051 if (wind == SK_MinS32) {
52 SkDebugf("?");
53 } else {
54 SkDebugf("%d", wind);
55 }
56}
caryclark@google.coma5e55922013-05-07 18:51:31 +000057
caryclark@google.com07e97fc2013-07-08 17:17:02 +000058#if DEBUG_SHOW_TEST_NAME
caryclark@google.com570863f2013-09-16 15:55:01 +000059void* SkPathOpsDebug::CreateNameStr() {
caryclark@google.com07e97fc2013-07-08 17:17:02 +000060 return SkNEW_ARRAY(char, DEBUG_FILENAME_STRING_LENGTH);
61}
62
caryclark@google.com570863f2013-09-16 15:55:01 +000063void SkPathOpsDebug::DeleteNameStr(void* v) {
caryclark@google.com07e97fc2013-07-08 17:17:02 +000064 SkDELETE_ARRAY(reinterpret_cast<char* >(v));
65}
66
caryclark@google.com570863f2013-09-16 15:55:01 +000067void SkPathOpsDebug::BumpTestName(char* test) {
caryclark@google.com07e97fc2013-07-08 17:17:02 +000068 char* num = test + strlen(test);
69 while (num[-1] >= '0' && num[-1] <= '9') {
70 --num;
caryclark@google.coma5e55922013-05-07 18:51:31 +000071 }
caryclark@google.com07e97fc2013-07-08 17:17:02 +000072 if (num[0] == '\0') {
73 return;
74 }
75 int dec = atoi(num);
76 if (dec == 0) {
77 return;
78 }
79 ++dec;
80 SK_SNPRINTF(num, DEBUG_FILENAME_STRING_LENGTH - (num - test), "%d", dec);
caryclark@google.coma5e55922013-05-07 18:51:31 +000081}
82#endif
caryclark@google.com570863f2013-09-16 15:55:01 +000083
84#include "SkOpSegment.h"
85
86void SkPathOpsDebug::DumpAngles(const SkTArray<SkOpAngle, true>& angles) {
87 int count = angles.count();
88 for (int index = 0; index < count; ++index) {
89 angles[index].dump();
90 }
91}
caryclark@google.com7eaa53d2013-10-02 14:49:34 +000092
93void SkPathOpsDebug::DumpAngles(const SkTArray<SkOpAngle* , true>& angles) {
94 int count = angles.count();
95 for (int index = 0; index < count; ++index) {
96 angles[index]->dump();
97 }
98}
caryclark@google.com570863f2013-09-16 15:55:01 +000099#endif // SK_DEBUG || !FORCE_RELEASE
100
101#ifdef SK_DEBUG
102void SkOpSpan::dump() const {
103 SkDebugf("t=");
104 DebugDumpDouble(fT);
105 SkDebugf(" pt=");
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +0000106 SkDPoint::dump(fPt);
caryclark@google.com570863f2013-09-16 15:55:01 +0000107 SkDebugf(" other.fID=%d", fOther->debugID());
108 SkDebugf(" [%d] otherT=", fOtherIndex);
109 DebugDumpDouble(fOtherT);
110 SkDebugf(" windSum=");
111 SkPathOpsDebug::WindingPrintf(fWindSum);
112 if (SkPathOpsDebug::ValidWind(fOppSum) || fOppValue != 0) {
113 SkDebugf(" oppSum=");
114 SkPathOpsDebug::WindingPrintf(fOppSum);
115 }
116 SkDebugf(" windValue=%d", fWindValue);
117 if (SkPathOpsDebug::ValidWind(fOppSum) || fOppValue != 0) {
118 SkDebugf(" oppValue=%d", fOppValue);
119 }
120 if (fDone) {
121 SkDebugf(" done");
122 }
123 if (fUnsortableStart) {
124 SkDebugf(" unsortable-start");
125 }
126 if (fUnsortableEnd) {
127 SkDebugf(" unsortable-end");
128 }
129 if (fTiny) {
130 SkDebugf(" tiny");
131 } else if (fSmall) {
132 SkDebugf(" small");
133 }
134 if (fLoop) {
135 SkDebugf(" loop");
136 }
caryclark@google.com570863f2013-09-16 15:55:01 +0000137 SkDebugf("\n");
138}
caryclark@google.com7eaa53d2013-10-02 14:49:34 +0000139
140void Dump(const SkTArray<class SkOpAngle, true>& angles) {
141 SkPathOpsDebug::DumpAngles(angles);
142}
143
144void Dump(const SkTArray<class SkOpAngle* , true>& angles) {
145 SkPathOpsDebug::DumpAngles(angles);
146}
147
148void Dump(const SkTArray<class SkOpAngle, true>* angles) {
149 SkPathOpsDebug::DumpAngles(*angles);
150}
151
152void Dump(const SkTArray<class SkOpAngle* , true>* angles) {
153 SkPathOpsDebug::DumpAngles(*angles);
154}
155
caryclark@google.com570863f2013-09-16 15:55:01 +0000156#endif
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +0000157
158#if !FORCE_RELEASE && 0 // enable when building without extended test
159void SkPathOpsDebug::ShowPath(const SkPath& one, const SkPath& two, SkPathOp op, const char* name) {
160}
161#endif