|
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 #if FORCE_RELEASE |
|
35 |
|
36 #define DEBUG_ACTIVE_OP 0 |
|
37 #define DEBUG_ACTIVE_SPANS 0 |
|
38 #define DEBUG_ACTIVE_SPANS_FIRST_ONLY 0 |
|
39 #define DEBUG_ACTIVE_SPANS_SHORT_FORM 1 |
|
40 #define DEBUG_ADD_INTERSECTING_TS 0 |
|
41 #define DEBUG_ADD_T_PAIR 0 |
|
42 #define DEBUG_ANGLE 0 |
|
43 #define DEBUG_AS_C_CODE 1 |
|
44 #define DEBUG_ASSEMBLE 0 |
|
45 #define DEBUG_CHECK_ENDS 0 |
|
46 #define DEBUG_CHECK_TINY 0 |
|
47 #define DEBUG_CONCIDENT 0 |
|
48 #define DEBUG_CROSS 0 |
|
49 #define DEBUG_FLAT_QUADS 0 |
|
50 #define DEBUG_FLOW 0 |
|
51 #define DEBUG_MARK_DONE 0 |
|
52 #define DEBUG_PATH_CONSTRUCTION 0 |
|
53 #define DEBUG_SHOW_TEST_NAME 0 |
|
54 #define DEBUG_SHOW_TEST_PROGRESS 0 |
|
55 #define DEBUG_SHOW_WINDING 0 |
|
56 #define DEBUG_SORT 0 |
|
57 #define DEBUG_SORT_COMPACT 0 |
|
58 #define DEBUG_SORT_RAW 0 |
|
59 #define DEBUG_SORT_SINGLE 0 |
|
60 #define DEBUG_SWAP_TOP 0 |
|
61 #define DEBUG_UNSORTABLE 0 |
|
62 #define DEBUG_VALIDATE 0 |
|
63 #define DEBUG_WIND_BUMP 0 |
|
64 #define DEBUG_WINDING 0 |
|
65 #define DEBUG_WINDING_AT_T 0 |
|
66 |
|
67 #else |
|
68 |
|
69 #define DEBUG_ACTIVE_OP 1 |
|
70 #define DEBUG_ACTIVE_SPANS 1 |
|
71 #define DEBUG_ACTIVE_SPANS_FIRST_ONLY 0 |
|
72 #define DEBUG_ACTIVE_SPANS_SHORT_FORM 1 |
|
73 #define DEBUG_ADD_INTERSECTING_TS 1 |
|
74 #define DEBUG_ADD_T_PAIR 1 |
|
75 #define DEBUG_ANGLE 1 |
|
76 #define DEBUG_AS_C_CODE 1 |
|
77 #define DEBUG_ASSEMBLE 1 |
|
78 #define DEBUG_CHECK_ENDS 1 |
|
79 #define DEBUG_CHECK_TINY 1 |
|
80 #define DEBUG_CONCIDENT 1 |
|
81 #define DEBUG_CROSS 01 |
|
82 #define DEBUG_FLAT_QUADS 0 |
|
83 #define DEBUG_FLOW 1 |
|
84 #define DEBUG_MARK_DONE 1 |
|
85 #define DEBUG_PATH_CONSTRUCTION 1 |
|
86 #define DEBUG_SHOW_TEST_NAME 1 |
|
87 #define DEBUG_SHOW_TEST_PROGRESS 1 |
|
88 #define DEBUG_SHOW_WINDING 0 |
|
89 #define DEBUG_SORT 1 |
|
90 #define DEBUG_SORT_COMPACT 0 |
|
91 #define DEBUG_SORT_RAW 0 |
|
92 #define DEBUG_SORT_SINGLE 0 |
|
93 #define DEBUG_SWAP_TOP 1 |
|
94 #define DEBUG_UNSORTABLE 1 |
|
95 #define DEBUG_VALIDATE 1 |
|
96 #define DEBUG_WIND_BUMP 0 |
|
97 #define DEBUG_WINDING 1 |
|
98 #define DEBUG_WINDING_AT_T 1 |
|
99 |
|
100 #endif |
|
101 |
|
102 #if DEBUG_AS_C_CODE |
|
103 #define CUBIC_DEBUG_STR "{{%1.9g,%1.9g}, {%1.9g,%1.9g}, {%1.9g,%1.9g}, {%1.9g,%1.9g}}" |
|
104 #define QUAD_DEBUG_STR "{{%1.9g,%1.9g}, {%1.9g,%1.9g}, {%1.9g,%1.9g}}" |
|
105 #define LINE_DEBUG_STR "{{%1.9g,%1.9g}, {%1.9g,%1.9g}}" |
|
106 #define PT_DEBUG_STR "{{%1.9g,%1.9g}}" |
|
107 #else |
|
108 #define CUBIC_DEBUG_STR "(%1.9g,%1.9g %1.9g,%1.9g %1.9g,%1.9g %1.9g,%1.9g)" |
|
109 #define QUAD_DEBUG_STR "(%1.9g,%1.9g %1.9g,%1.9g %1.9g,%1.9g)" |
|
110 #define LINE_DEBUG_STR "(%1.9g,%1.9g %1.9g,%1.9g)" |
|
111 #define PT_DEBUG_STR "(%1.9g,%1.9g)" |
|
112 #endif |
|
113 #define T_DEBUG_STR(t, n) #t "[" #n "]=%1.9g" |
|
114 #define TX_DEBUG_STR(t) #t "[%d]=%1.9g" |
|
115 #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 |
|
116 #define QUAD_DEBUG_DATA(q) q[0].fX, q[0].fY, q[1].fX, q[1].fY, q[2].fX, q[2].fY |
|
117 #define LINE_DEBUG_DATA(l) l[0].fX, l[0].fY, l[1].fX, l[1].fY |
|
118 #define PT_DEBUG_DATA(i, n) i.pt(n).fX, i.pt(n).fY |
|
119 |
|
120 #ifndef DEBUG_TEST |
|
121 #define DEBUG_TEST 0 |
|
122 #endif |
|
123 |
|
124 #if defined SK_DEBUG || !FORCE_RELEASE |
|
125 |
|
126 #if DEBUG_SHOW_TEST_NAME |
|
127 #include "SkTLS.h" |
|
128 #endif |
|
129 |
|
130 #include "SkTArray.h" |
|
131 |
|
132 class SkPathOpsDebug { |
|
133 public: |
|
134 static int gMaxWindSum; |
|
135 static int gMaxWindValue; |
|
136 |
|
137 static const char* kLVerbStr[]; |
|
138 static int gContourID; |
|
139 static int gSegmentID; |
|
140 |
|
141 #if DEBUG_SORT || DEBUG_SWAP_TOP |
|
142 static int gSortCountDefault; |
|
143 static int gSortCount; |
|
144 #endif |
|
145 |
|
146 #if DEBUG_ACTIVE_OP |
|
147 static const char* kPathOpStr[]; |
|
148 #endif |
|
149 |
|
150 static void MathematicaIze(char* str, size_t bufferSize); |
|
151 static bool ValidWind(int winding); |
|
152 static void WindingPrintf(int winding); |
|
153 |
|
154 #if DEBUG_SHOW_TEST_NAME |
|
155 static void* CreateNameStr(); |
|
156 static void DeleteNameStr(void* v); |
|
157 #define DEBUG_FILENAME_STRING_LENGTH 64 |
|
158 #define DEBUG_FILENAME_STRING (reinterpret_cast<char* >(SkTLS::Get(SkPathOpsDebug::CreateNameStr, \ |
|
159 SkPathOpsDebug::DeleteNameStr))) |
|
160 static void BumpTestName(char* ); |
|
161 static void ShowPath(const SkPath& one, const SkPath& two, SkPathOp op, const char* name); |
|
162 #endif |
|
163 static void DumpAngles(const SkTArray<class SkOpAngle, true>& angles); |
|
164 static void DumpAngles(const SkTArray<class SkOpAngle* , true>& angles); |
|
165 }; |
|
166 |
|
167 // shorthand for calling from debugger |
|
168 void Dump(const SkTArray<class SkOpAngle, true>& angles); |
|
169 void Dump(const SkTArray<class SkOpAngle* , true>& angles); |
|
170 void Dump(const SkTArray<class SkOpAngle, true>* angles); |
|
171 void Dump(const SkTArray<class SkOpAngle* , true>* angles); |
|
172 |
|
173 #endif // SK_DEBUG || !FORCE_RELEASE |
|
174 |
|
175 #endif |