caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 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" |
caryclark@google.com | a5e5592 | 2013-05-07 18:51:31 +0000 | [diff] [blame] | 9 | #include "SkPath.h" |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 10 | |
| 11 | #if defined SK_DEBUG || !FORCE_RELEASE |
| 12 | |
caryclark@google.com | 570863f | 2013-09-16 15:55:01 +0000 | [diff] [blame] | 13 | int SkPathOpsDebug::gMaxWindSum = SK_MaxS32; |
| 14 | int SkPathOpsDebug::gMaxWindValue = SK_MaxS32; |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 15 | |
caryclark@google.com | 570863f | 2013-09-16 15:55:01 +0000 | [diff] [blame] | 16 | const char* SkPathOpsDebug::kLVerbStr[] = {"", "line", "quad", "cubic"}; |
| 17 | int SkPathOpsDebug::gContourID; |
| 18 | int SkPathOpsDebug::gSegmentID; |
| 19 | |
| 20 | #if DEBUG_SORT || DEBUG_SWAP_TOP |
| 21 | int SkPathOpsDebug::gSortCountDefault = SK_MaxS32; |
| 22 | int SkPathOpsDebug::gSortCount; |
| 23 | #endif |
| 24 | |
| 25 | #if DEBUG_ACTIVE_OP |
| 26 | const char* SkPathOpsDebug::kPathOpStr[] = {"diff", "sect", "union", "xor"}; |
| 27 | #endif |
| 28 | |
| 29 | void SkPathOpsDebug::MathematicaIze(char* str, size_t bufferLen) { |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 30 | 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.com | 570863f | 2013-09-16 15:55:01 +0000 | [diff] [blame] | 46 | bool SkPathOpsDebug::ValidWind(int wind) { |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 47 | return wind > SK_MinS32 + 0xFFFF && wind < SK_MaxS32 - 0xFFFF; |
| 48 | } |
| 49 | |
caryclark@google.com | 570863f | 2013-09-16 15:55:01 +0000 | [diff] [blame] | 50 | void SkPathOpsDebug::WindingPrintf(int wind) { |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 51 | if (wind == SK_MinS32) { |
| 52 | SkDebugf("?"); |
| 53 | } else { |
| 54 | SkDebugf("%d", wind); |
| 55 | } |
| 56 | } |
caryclark@google.com | a5e5592 | 2013-05-07 18:51:31 +0000 | [diff] [blame] | 57 | |
caryclark@google.com | 07e97fc | 2013-07-08 17:17:02 +0000 | [diff] [blame] | 58 | #if DEBUG_SHOW_TEST_NAME |
caryclark@google.com | 570863f | 2013-09-16 15:55:01 +0000 | [diff] [blame] | 59 | void* SkPathOpsDebug::CreateNameStr() { |
caryclark@google.com | 07e97fc | 2013-07-08 17:17:02 +0000 | [diff] [blame] | 60 | return SkNEW_ARRAY(char, DEBUG_FILENAME_STRING_LENGTH); |
| 61 | } |
| 62 | |
caryclark@google.com | 570863f | 2013-09-16 15:55:01 +0000 | [diff] [blame] | 63 | void SkPathOpsDebug::DeleteNameStr(void* v) { |
caryclark@google.com | 07e97fc | 2013-07-08 17:17:02 +0000 | [diff] [blame] | 64 | SkDELETE_ARRAY(reinterpret_cast<char* >(v)); |
| 65 | } |
| 66 | |
caryclark@google.com | 570863f | 2013-09-16 15:55:01 +0000 | [diff] [blame] | 67 | void SkPathOpsDebug::BumpTestName(char* test) { |
caryclark@google.com | 07e97fc | 2013-07-08 17:17:02 +0000 | [diff] [blame] | 68 | char* num = test + strlen(test); |
| 69 | while (num[-1] >= '0' && num[-1] <= '9') { |
| 70 | --num; |
caryclark@google.com | a5e5592 | 2013-05-07 18:51:31 +0000 | [diff] [blame] | 71 | } |
caryclark@google.com | 07e97fc | 2013-07-08 17:17:02 +0000 | [diff] [blame] | 72 | 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.com | a5e5592 | 2013-05-07 18:51:31 +0000 | [diff] [blame] | 81 | } |
| 82 | #endif |
caryclark@google.com | 570863f | 2013-09-16 15:55:01 +0000 | [diff] [blame] | 83 | |
| 84 | #include "SkOpSegment.h" |
| 85 | |
| 86 | void 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.com | 7eaa53d | 2013-10-02 14:49:34 +0000 | [diff] [blame] | 92 | |
| 93 | void 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.com | 570863f | 2013-09-16 15:55:01 +0000 | [diff] [blame] | 99 | #endif // SK_DEBUG || !FORCE_RELEASE |
| 100 | |
| 101 | #ifdef SK_DEBUG |
| 102 | void SkOpSpan::dump() const { |
| 103 | SkDebugf("t="); |
| 104 | DebugDumpDouble(fT); |
| 105 | SkDebugf(" pt="); |
caryclark@google.com | a2bbc6e | 2013-11-01 17:36:03 +0000 | [diff] [blame] | 106 | SkDPoint::dump(fPt); |
caryclark@google.com | 570863f | 2013-09-16 15:55:01 +0000 | [diff] [blame] | 107 | 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.com | 570863f | 2013-09-16 15:55:01 +0000 | [diff] [blame] | 137 | SkDebugf("\n"); |
| 138 | } |
caryclark@google.com | 7eaa53d | 2013-10-02 14:49:34 +0000 | [diff] [blame] | 139 | |
| 140 | void Dump(const SkTArray<class SkOpAngle, true>& angles) { |
| 141 | SkPathOpsDebug::DumpAngles(angles); |
| 142 | } |
| 143 | |
| 144 | void Dump(const SkTArray<class SkOpAngle* , true>& angles) { |
| 145 | SkPathOpsDebug::DumpAngles(angles); |
| 146 | } |
| 147 | |
| 148 | void Dump(const SkTArray<class SkOpAngle, true>* angles) { |
| 149 | SkPathOpsDebug::DumpAngles(*angles); |
| 150 | } |
| 151 | |
| 152 | void Dump(const SkTArray<class SkOpAngle* , true>* angles) { |
| 153 | SkPathOpsDebug::DumpAngles(*angles); |
| 154 | } |
| 155 | |
caryclark@google.com | 570863f | 2013-09-16 15:55:01 +0000 | [diff] [blame] | 156 | #endif |
caryclark@google.com | a2bbc6e | 2013-11-01 17:36:03 +0000 | [diff] [blame] | 157 | |
| 158 | #if !FORCE_RELEASE && 0 // enable when building without extended test |
| 159 | void SkPathOpsDebug::ShowPath(const SkPath& one, const SkPath& two, SkPathOp op, const char* name) { |
| 160 | } |
| 161 | #endif |