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 #ifndef SkPathOpsDebug_DEFINED 8 #define SkPathOpsDebug_DEFINED 9 10 #include "SkPathOps.h" 11 #include "SkTypes.h" 12 #include <stdio.h> 13 14 #ifdef SK_RELEASE 15 #define FORCE_RELEASE 1 16 #else 17 #define FORCE_RELEASE 1 // set force release to 1 for multiple thread -- no debugging 18 #endif 19 20 #define ONE_OFF_DEBUG 0 21 #define ONE_OFF_DEBUG_MATHEMATICA 0 22 23 #if defined(SK_BUILD_FOR_WIN) || defined(SK_BUILD_FOR_ANDROID) 24 #define SK_RAND(seed) rand() 25 #else 26 #define SK_RAND(seed) rand_r(&seed) 27 #endif 28 #ifdef SK_BUILD_FOR_WIN 29 #define SK_SNPRINTF _snprintf 30 #else 31 #define SK_SNPRINTF snprintf 32 #endif 33 34 #define WIND_AS_STRING(x) char x##Str[12]; \ 35 if (!SkPathOpsDebug::ValidWind(x)) strcpy(x##Str, "?"); \ 36 else SK_SNPRINTF(x##Str, sizeof(x##Str), "%d", x) 37 38 #if FORCE_RELEASE 39 40 #define DEBUG_ACTIVE_OP 0 41 #define DEBUG_ACTIVE_SPANS 0 42 #define DEBUG_ADD_INTERSECTING_TS 0 43 #define DEBUG_ADD_T 0 44 #define DEBUG_ANGLE 0 45 #define DEBUG_ASSEMBLE 0 46 #define DEBUG_CUBIC_BINARY_SEARCH 0 47 #define DEBUG_CUBIC_SPLIT 0 48 #define DEBUG_DUMP_SEGMENTS 0 49 #define DEBUG_FLOW 0 50 #define DEBUG_LIMIT_WIND_SUM 0 51 #define DEBUG_MARK_DONE 0 52 #define DEBUG_PATH_CONSTRUCTION 0 53 #define DEBUG_PERP 0 54 #define DEBUG_SHOW_TEST_NAME 0 55 #define DEBUG_SORT 0 56 #define DEBUG_T_SECT 0 57 #define DEBUG_T_SECT_DUMP 0 58 #define DEBUG_VALIDATE 0 59 #define DEBUG_WINDING 0 60 #define DEBUG_WINDING_AT_T 0 61 62 #else 63 64 #define DEBUG_ACTIVE_OP 1 65 #define DEBUG_ACTIVE_SPANS 1 66 #define DEBUG_ADD_INTERSECTING_TS 1 67 #define DEBUG_ADD_T 1 68 #define DEBUG_ANGLE 1 69 #define DEBUG_ASSEMBLE 1 70 #define DEBUG_CUBIC_BINARY_SEARCH 0 71 #define DEBUG_CUBIC_SPLIT 1 72 #define DEBUG_DUMP_SEGMENTS 1 73 #define DEBUG_FLOW 1 74 #define DEBUG_LIMIT_WIND_SUM 5 75 #define DEBUG_MARK_DONE 1 76 #define DEBUG_PATH_CONSTRUCTION 1 77 #define DEBUG_PERP 1 78 #define DEBUG_SHOW_TEST_NAME 1 79 #define DEBUG_SORT 1 80 #define DEBUG_T_SECT 0 81 #define DEBUG_T_SECT_DUMP 0 82 #define DEBUG_VALIDATE 1 83 #define DEBUG_WINDING 1 84 #define DEBUG_WINDING_AT_T 1 85 86 #endif 87 88 #ifdef SK_RELEASE 89 #define SkDEBUGRELEASE(a, b) b 90 #define SkDEBUGPARAMS(...) 91 #define SkDEBUGCODE_(...) 92 #else 93 #define SkDEBUGRELEASE(a, b) a 94 #define SkDEBUGPARAMS(...) , __VA_ARGS__ 95 #define SkDEBUGCODE_(...) __VA_ARGS__ // temporary until SkDEBUGCODE is fixed 96 #endif 97 98 #if DEBUG_T_SECT == 0 99 #define PATH_OPS_DEBUG_T_SECT_RELEASE(a, b) b 100 #define PATH_OPS_DEBUG_T_SECT_PARAMS(...) 101 #define PATH_OPS_DEBUG_T_SECT_CODE(...) 102 #else 103 #define PATH_OPS_DEBUG_T_SECT_RELEASE(a, b) a 104 #define PATH_OPS_DEBUG_T_SECT_PARAMS(...) , __VA_ARGS__ 105 #define PATH_OPS_DEBUG_T_SECT_CODE(...) __VA_ARGS__ 106 #endif 107 108 #if DEBUG_T_SECT_DUMP > 1 109 extern int gDumpTSectNum; 110 #endif 111 112 #define CUBIC_DEBUG_STR "{{{%1.9g,%1.9g}, {%1.9g,%1.9g}, {%1.9g,%1.9g}, {%1.9g,%1.9g}}}" 113 #define CONIC_DEBUG_STR "{{{{%1.9g,%1.9g}, {%1.9g,%1.9g}, {%1.9g,%1.9g}}}, %1.9g}" 114 #define QUAD_DEBUG_STR "{{{%1.9g,%1.9g}, {%1.9g,%1.9g}, {%1.9g,%1.9g}}}" 115 #define LINE_DEBUG_STR "{{{%1.9g,%1.9g}, {%1.9g,%1.9g}}}" 116 #define PT_DEBUG_STR "{{%1.9g,%1.9g}}" 117 118 #define T_DEBUG_STR(t, n) #t "[" #n "]=%1.9g" 119 #define TX_DEBUG_STR(t) #t "[%d]=%1.9g" 120 #define CUBIC_DEBUG_DATA(c) c[0].fX, c[0].fY, c[1].fX, c[1].fY, c[2].fX, c[2].fY, c[3].fX, c[3].fY 121 #define CONIC_DEBUG_DATA(c, w) c[0].fX, c[0].fY, c[1].fX, c[1].fY, c[2].fX, c[2].fY, w 122 #define QUAD_DEBUG_DATA(q) q[0].fX, q[0].fY, q[1].fX, q[1].fY, q[2].fX, q[2].fY 123 #define LINE_DEBUG_DATA(l) l[0].fX, l[0].fY, l[1].fX, l[1].fY 124 #define PT_DEBUG_DATA(i, n) i.pt(n).asSkPoint().fX, i.pt(n).asSkPoint().fY 125 126 #ifndef DEBUG_TEST 127 #define DEBUG_TEST 0 128 #endif 129 130 #if DEBUG_SHOW_TEST_NAME 131 #include "SkTLS.h" 132 #endif 133 134 class SkPathOpsDebug { 135 public: 136 static const char* kLVerbStr[]; 137 138 #if defined(SK_DEBUG) || !FORCE_RELEASE 139 static int gContourID; 140 static int gSegmentID; 141 #endif 142 143 #if DEBUG_SORT 144 static int gSortCountDefault; 145 static int gSortCount; 146 #endif 147 148 #if DEBUG_ACTIVE_OP 149 static const char* kPathOpStr[]; 150 #endif 151 152 static void MathematicaIze(char* str, size_t bufferSize); 153 static bool ValidWind(int winding); 154 static void WindingPrintf(int winding); 155 156 #if DEBUG_SHOW_TEST_NAME 157 static void* CreateNameStr(); 158 static void DeleteNameStr(void* v); 159 #define DEBUG_FILENAME_STRING_LENGTH 64 160 #define DEBUG_FILENAME_STRING (reinterpret_cast<char* >(SkTLS::Get(SkPathOpsDebug::CreateNameStr, \ 161 SkPathOpsDebug::DeleteNameStr))) 162 static void BumpTestName(char* ); 163 #endif 164 static const char* OpStr(SkPathOp ); 165 static void ShowOnePath(const SkPath& path, const char* name, bool includeDeclaration); 166 static void ShowPath(const SkPath& one, const SkPath& two, SkPathOp op, const char* name); 167 168 static bool ChaseContains(const SkTDArray<class SkOpSpanBase*>& , const class SkOpSpanBase* ); 169 170 static const struct SkOpAngle* DebugAngleAngle(const struct SkOpAngle*, int id); 171 static class SkOpContour* DebugAngleContour(struct SkOpAngle*, int id); 172 static const class SkOpPtT* DebugAnglePtT(const struct SkOpAngle*, int id); 173 static const class SkOpSegment* DebugAngleSegment(const struct SkOpAngle*, int id); 174 static const class SkOpSpanBase* DebugAngleSpan(const struct SkOpAngle*, int id); 175 176 static const struct SkOpAngle* DebugContourAngle(class SkOpContour*, int id); 177 static class SkOpContour* DebugContourContour(class SkOpContour*, int id); 178 static const class SkOpPtT* DebugContourPtT(class SkOpContour*, int id); 179 static const class SkOpSegment* DebugContourSegment(class SkOpContour*, int id); 180 static const class SkOpSpanBase* DebugContourSpan(class SkOpContour*, int id); 181 182 static const struct SkOpAngle* DebugPtTAngle(const class SkOpPtT*, int id); 183 static class SkOpContour* DebugPtTContour(class SkOpPtT*, int id); 184 static const class SkOpPtT* DebugPtTPtT(const class SkOpPtT*, int id); 185 static const class SkOpSegment* DebugPtTSegment(const class SkOpPtT*, int id); 186 static const class SkOpSpanBase* DebugPtTSpan(const class SkOpPtT*, int id); 187 188 static const struct SkOpAngle* DebugSegmentAngle(const class SkOpSegment*, int id); 189 static class SkOpContour* DebugSegmentContour(class SkOpSegment*, int id); 190 static const class SkOpPtT* DebugSegmentPtT(const class SkOpSegment*, int id); 191 static const class SkOpSegment* DebugSegmentSegment(const class SkOpSegment*, int id); 192 static const class SkOpSpanBase* DebugSegmentSpan(const class SkOpSegment*, int id); 193 194 static const struct SkOpAngle* DebugSpanAngle(const class SkOpSpanBase*, int id); 195 static class SkOpContour* DebugSpanContour(class SkOpSpanBase*, int id); 196 static const class SkOpPtT* DebugSpanPtT(const class SkOpSpanBase*, int id); 197 static const class SkOpSegment* DebugSpanSegment(const class SkOpSpanBase*, int id); 198 static const class SkOpSpanBase* DebugSpanSpan(const class SkOpSpanBase*, int id); 199 }; 200 201 struct SkDQuad; 202 203 // generates tools/path_sorter.htm and path_visualizer.htm compatible data 204 void DumpQ(const SkDQuad& quad1, const SkDQuad& quad2, int testNo); 205 void DumpT(const SkDQuad& quad, double t); 206 207 #endif 208