michael@0: /* michael@0: * Copyright 2013 Google Inc. michael@0: * michael@0: * Use of this source code is governed by a BSD-style license that can be michael@0: * found in the LICENSE file. michael@0: */ michael@0: michael@0: #include "SkPathOpsDebug.h" michael@0: #include "SkPath.h" michael@0: michael@0: #if defined SK_DEBUG || !FORCE_RELEASE michael@0: michael@0: int SkPathOpsDebug::gMaxWindSum = SK_MaxS32; michael@0: int SkPathOpsDebug::gMaxWindValue = SK_MaxS32; michael@0: michael@0: const char* SkPathOpsDebug::kLVerbStr[] = {"", "line", "quad", "cubic"}; michael@0: int SkPathOpsDebug::gContourID; michael@0: int SkPathOpsDebug::gSegmentID; michael@0: michael@0: #if DEBUG_SORT || DEBUG_SWAP_TOP michael@0: int SkPathOpsDebug::gSortCountDefault = SK_MaxS32; michael@0: int SkPathOpsDebug::gSortCount; michael@0: #endif michael@0: michael@0: #if DEBUG_ACTIVE_OP michael@0: const char* SkPathOpsDebug::kPathOpStr[] = {"diff", "sect", "union", "xor"}; michael@0: #endif michael@0: michael@0: void SkPathOpsDebug::MathematicaIze(char* str, size_t bufferLen) { michael@0: size_t len = strlen(str); michael@0: bool num = false; michael@0: for (size_t idx = 0; idx < len; ++idx) { michael@0: if (num && str[idx] == 'e') { michael@0: if (len + 2 >= bufferLen) { michael@0: return; michael@0: } michael@0: memmove(&str[idx + 2], &str[idx + 1], len - idx); michael@0: str[idx] = '*'; michael@0: str[idx + 1] = '^'; michael@0: ++len; michael@0: } michael@0: num = str[idx] >= '0' && str[idx] <= '9'; michael@0: } michael@0: } michael@0: michael@0: bool SkPathOpsDebug::ValidWind(int wind) { michael@0: return wind > SK_MinS32 + 0xFFFF && wind < SK_MaxS32 - 0xFFFF; michael@0: } michael@0: michael@0: void SkPathOpsDebug::WindingPrintf(int wind) { michael@0: if (wind == SK_MinS32) { michael@0: SkDebugf("?"); michael@0: } else { michael@0: SkDebugf("%d", wind); michael@0: } michael@0: } michael@0: michael@0: #if DEBUG_SHOW_TEST_NAME michael@0: void* SkPathOpsDebug::CreateNameStr() { michael@0: return SkNEW_ARRAY(char, DEBUG_FILENAME_STRING_LENGTH); michael@0: } michael@0: michael@0: void SkPathOpsDebug::DeleteNameStr(void* v) { michael@0: SkDELETE_ARRAY(reinterpret_cast(v)); michael@0: } michael@0: michael@0: void SkPathOpsDebug::BumpTestName(char* test) { michael@0: char* num = test + strlen(test); michael@0: while (num[-1] >= '0' && num[-1] <= '9') { michael@0: --num; michael@0: } michael@0: if (num[0] == '\0') { michael@0: return; michael@0: } michael@0: int dec = atoi(num); michael@0: if (dec == 0) { michael@0: return; michael@0: } michael@0: ++dec; michael@0: SK_SNPRINTF(num, DEBUG_FILENAME_STRING_LENGTH - (num - test), "%d", dec); michael@0: } michael@0: #endif michael@0: michael@0: #include "SkOpSegment.h" michael@0: michael@0: void SkPathOpsDebug::DumpAngles(const SkTArray& angles) { michael@0: int count = angles.count(); michael@0: for (int index = 0; index < count; ++index) { michael@0: angles[index].dump(); michael@0: } michael@0: } michael@0: michael@0: void SkPathOpsDebug::DumpAngles(const SkTArray& angles) { michael@0: int count = angles.count(); michael@0: for (int index = 0; index < count; ++index) { michael@0: angles[index]->dump(); michael@0: } michael@0: } michael@0: #endif // SK_DEBUG || !FORCE_RELEASE michael@0: michael@0: #ifdef SK_DEBUG michael@0: void SkOpSpan::dump() const { michael@0: SkDebugf("t="); michael@0: DebugDumpDouble(fT); michael@0: SkDebugf(" pt="); michael@0: SkDPoint::dump(fPt); michael@0: SkDebugf(" other.fID=%d", fOther->debugID()); michael@0: SkDebugf(" [%d] otherT=", fOtherIndex); michael@0: DebugDumpDouble(fOtherT); michael@0: SkDebugf(" windSum="); michael@0: SkPathOpsDebug::WindingPrintf(fWindSum); michael@0: if (SkPathOpsDebug::ValidWind(fOppSum) || fOppValue != 0) { michael@0: SkDebugf(" oppSum="); michael@0: SkPathOpsDebug::WindingPrintf(fOppSum); michael@0: } michael@0: SkDebugf(" windValue=%d", fWindValue); michael@0: if (SkPathOpsDebug::ValidWind(fOppSum) || fOppValue != 0) { michael@0: SkDebugf(" oppValue=%d", fOppValue); michael@0: } michael@0: if (fDone) { michael@0: SkDebugf(" done"); michael@0: } michael@0: if (fUnsortableStart) { michael@0: SkDebugf(" unsortable-start"); michael@0: } michael@0: if (fUnsortableEnd) { michael@0: SkDebugf(" unsortable-end"); michael@0: } michael@0: if (fTiny) { michael@0: SkDebugf(" tiny"); michael@0: } else if (fSmall) { michael@0: SkDebugf(" small"); michael@0: } michael@0: if (fLoop) { michael@0: SkDebugf(" loop"); michael@0: } michael@0: SkDebugf("\n"); michael@0: } michael@0: michael@0: void Dump(const SkTArray& angles) { michael@0: SkPathOpsDebug::DumpAngles(angles); michael@0: } michael@0: michael@0: void Dump(const SkTArray& angles) { michael@0: SkPathOpsDebug::DumpAngles(angles); michael@0: } michael@0: michael@0: void Dump(const SkTArray* angles) { michael@0: SkPathOpsDebug::DumpAngles(*angles); michael@0: } michael@0: michael@0: void Dump(const SkTArray* angles) { michael@0: SkPathOpsDebug::DumpAngles(*angles); michael@0: } michael@0: michael@0: #endif michael@0: michael@0: #if !FORCE_RELEASE && 0 // enable when building without extended test michael@0: void SkPathOpsDebug::ShowPath(const SkPath& one, const SkPath& two, SkPathOp op, const char* name) { michael@0: } michael@0: #endif