blob: 0505965b467dae436869a7dfdf62e83a53d444f9 [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}
92#endif // SK_DEBUG || !FORCE_RELEASE
93
94#ifdef SK_DEBUG
95void SkOpSpan::dump() const {
96 SkDebugf("t=");
97 DebugDumpDouble(fT);
98 SkDebugf(" pt=");
99 SkDPoint::DumpSkPoint(fPt);
100 SkDebugf(" other.fID=%d", fOther->debugID());
101 SkDebugf(" [%d] otherT=", fOtherIndex);
102 DebugDumpDouble(fOtherT);
103 SkDebugf(" windSum=");
104 SkPathOpsDebug::WindingPrintf(fWindSum);
105 if (SkPathOpsDebug::ValidWind(fOppSum) || fOppValue != 0) {
106 SkDebugf(" oppSum=");
107 SkPathOpsDebug::WindingPrintf(fOppSum);
108 }
109 SkDebugf(" windValue=%d", fWindValue);
110 if (SkPathOpsDebug::ValidWind(fOppSum) || fOppValue != 0) {
111 SkDebugf(" oppValue=%d", fOppValue);
112 }
113 if (fDone) {
114 SkDebugf(" done");
115 }
116 if (fUnsortableStart) {
117 SkDebugf(" unsortable-start");
118 }
119 if (fUnsortableEnd) {
120 SkDebugf(" unsortable-end");
121 }
122 if (fTiny) {
123 SkDebugf(" tiny");
124 } else if (fSmall) {
125 SkDebugf(" small");
126 }
127 if (fLoop) {
128 SkDebugf(" loop");
129 }
130 if (fNear) {
131 SkDebugf(" near");
132 }
133 SkDebugf("\n");
134}
135#endif