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 | #ifndef SkPathOpsDebug_DEFINED |
| 8 | #define SkPathOpsDebug_DEFINED |
| 9 | |
caryclark@google.com | a5e5592 | 2013-05-07 18:51:31 +0000 | [diff] [blame] | 10 | #include "SkPathOps.h" |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 11 | #include "SkTypes.h" |
bungeman@google.com | fab44db | 2013-10-11 18:50:45 +0000 | [diff] [blame] | 12 | #include <stdio.h> |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 13 | |
| 14 | #ifdef SK_RELEASE |
| 15 | #define FORCE_RELEASE 1 |
| 16 | #else |
caryclark@google.com | b3f0921 | 2013-04-17 15:49:16 +0000 | [diff] [blame] | 17 | #define FORCE_RELEASE 1 // set force release to 1 for multiple thread -- no debugging |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 18 | #endif |
| 19 | |
| 20 | #define ONE_OFF_DEBUG 0 |
| 21 | #define ONE_OFF_DEBUG_MATHEMATICA 0 |
| 22 | |
caryclark@google.com | db60de7 | 2013-04-11 12:33:23 +0000 | [diff] [blame] | 23 | #if defined(SK_BUILD_FOR_WIN) || defined(SK_BUILD_FOR_ANDROID) |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 24 | #define SK_RAND(seed) rand() |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 25 | #else |
| 26 | #define SK_RAND(seed) rand_r(&seed) |
caryclark@google.com | db60de7 | 2013-04-11 12:33:23 +0000 | [diff] [blame] | 27 | #endif |
| 28 | #ifdef SK_BUILD_FOR_WIN |
| 29 | #define SK_SNPRINTF _snprintf |
| 30 | #else |
skia.committer@gmail.com | 3284017 | 2013-04-09 07:01:27 +0000 | [diff] [blame] | 31 | #define SK_SNPRINTF snprintf |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 32 | #endif |
| 33 | |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 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 | |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 38 | #if FORCE_RELEASE |
| 39 | |
| 40 | #define DEBUG_ACTIVE_OP 0 |
| 41 | #define DEBUG_ACTIVE_SPANS 0 |
caryclark@google.com | a5e5592 | 2013-05-07 18:51:31 +0000 | [diff] [blame] | 42 | #define DEBUG_ACTIVE_SPANS_FIRST_ONLY 0 |
| 43 | #define DEBUG_ACTIVE_SPANS_SHORT_FORM 1 |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 44 | #define DEBUG_ADD_INTERSECTING_TS 0 |
| 45 | #define DEBUG_ADD_T_PAIR 0 |
| 46 | #define DEBUG_ANGLE 0 |
| 47 | #define DEBUG_AS_C_CODE 1 |
| 48 | #define DEBUG_ASSEMBLE 0 |
caryclark@google.com | 570863f | 2013-09-16 15:55:01 +0000 | [diff] [blame] | 49 | #define DEBUG_CHECK_ENDS 0 |
| 50 | #define DEBUG_CHECK_TINY 0 |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 51 | #define DEBUG_CONCIDENT 0 |
| 52 | #define DEBUG_CROSS 0 |
commit-bot@chromium.org | 2db7fe7 | 2014-05-07 15:31:40 +0000 | [diff] [blame^] | 53 | #define DEBUG_CUBIC_BINARY_SEARCH 0 |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 54 | #define DEBUG_FLAT_QUADS 0 |
| 55 | #define DEBUG_FLOW 0 |
commit-bot@chromium.org | 8cb1daa | 2014-04-25 12:59:11 +0000 | [diff] [blame] | 56 | #define DEBUG_LIMIT_WIND_SUM 0 |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 57 | #define DEBUG_MARK_DONE 0 |
| 58 | #define DEBUG_PATH_CONSTRUCTION 0 |
caryclark@google.com | 0361032 | 2013-04-18 15:58:21 +0000 | [diff] [blame] | 59 | #define DEBUG_SHOW_TEST_NAME 0 |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 60 | #define DEBUG_SHOW_TEST_PROGRESS 0 |
| 61 | #define DEBUG_SHOW_WINDING 0 |
| 62 | #define DEBUG_SORT 0 |
caryclark@google.com | cffbcc3 | 2013-06-04 17:59:42 +0000 | [diff] [blame] | 63 | #define DEBUG_SORT_COMPACT 0 |
caryclark@google.com | 570863f | 2013-09-16 15:55:01 +0000 | [diff] [blame] | 64 | #define DEBUG_SORT_RAW 0 |
caryclark@google.com | a5e5592 | 2013-05-07 18:51:31 +0000 | [diff] [blame] | 65 | #define DEBUG_SORT_SINGLE 0 |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 66 | #define DEBUG_SWAP_TOP 0 |
| 67 | #define DEBUG_UNSORTABLE 0 |
caryclark@google.com | 4fdbb22 | 2013-07-23 15:27:41 +0000 | [diff] [blame] | 68 | #define DEBUG_VALIDATE 0 |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 69 | #define DEBUG_WIND_BUMP 0 |
| 70 | #define DEBUG_WINDING 0 |
| 71 | #define DEBUG_WINDING_AT_T 0 |
| 72 | |
| 73 | #else |
| 74 | |
| 75 | #define DEBUG_ACTIVE_OP 1 |
| 76 | #define DEBUG_ACTIVE_SPANS 1 |
caryclark@google.com | a5e5592 | 2013-05-07 18:51:31 +0000 | [diff] [blame] | 77 | #define DEBUG_ACTIVE_SPANS_FIRST_ONLY 0 |
caryclark@google.com | cffbcc3 | 2013-06-04 17:59:42 +0000 | [diff] [blame] | 78 | #define DEBUG_ACTIVE_SPANS_SHORT_FORM 1 |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 79 | #define DEBUG_ADD_INTERSECTING_TS 1 |
| 80 | #define DEBUG_ADD_T_PAIR 1 |
| 81 | #define DEBUG_ANGLE 1 |
| 82 | #define DEBUG_AS_C_CODE 1 |
| 83 | #define DEBUG_ASSEMBLE 1 |
caryclark@google.com | 570863f | 2013-09-16 15:55:01 +0000 | [diff] [blame] | 84 | #define DEBUG_CHECK_ENDS 1 |
| 85 | #define DEBUG_CHECK_TINY 1 |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 86 | #define DEBUG_CONCIDENT 1 |
caryclark@google.com | 570863f | 2013-09-16 15:55:01 +0000 | [diff] [blame] | 87 | #define DEBUG_CROSS 01 |
commit-bot@chromium.org | 2db7fe7 | 2014-05-07 15:31:40 +0000 | [diff] [blame^] | 88 | #define DEBUG_CUBIC_BINARY_SEARCH 1 |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 89 | #define DEBUG_FLAT_QUADS 0 |
| 90 | #define DEBUG_FLOW 1 |
commit-bot@chromium.org | 8cb1daa | 2014-04-25 12:59:11 +0000 | [diff] [blame] | 91 | #define DEBUG_LIMIT_WIND_SUM 4 |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 92 | #define DEBUG_MARK_DONE 1 |
| 93 | #define DEBUG_PATH_CONSTRUCTION 1 |
caryclark@google.com | 0361032 | 2013-04-18 15:58:21 +0000 | [diff] [blame] | 94 | #define DEBUG_SHOW_TEST_NAME 1 |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 95 | #define DEBUG_SHOW_TEST_PROGRESS 1 |
| 96 | #define DEBUG_SHOW_WINDING 0 |
| 97 | #define DEBUG_SORT 1 |
caryclark@google.com | cffbcc3 | 2013-06-04 17:59:42 +0000 | [diff] [blame] | 98 | #define DEBUG_SORT_COMPACT 0 |
caryclark@google.com | 570863f | 2013-09-16 15:55:01 +0000 | [diff] [blame] | 99 | #define DEBUG_SORT_RAW 0 |
caryclark@google.com | a5e5592 | 2013-05-07 18:51:31 +0000 | [diff] [blame] | 100 | #define DEBUG_SORT_SINGLE 0 |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 101 | #define DEBUG_SWAP_TOP 1 |
| 102 | #define DEBUG_UNSORTABLE 1 |
commit-bot@chromium.org | 8cb1daa | 2014-04-25 12:59:11 +0000 | [diff] [blame] | 103 | #define DEBUG_VALIDATE 0 |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 104 | #define DEBUG_WIND_BUMP 0 |
| 105 | #define DEBUG_WINDING 1 |
| 106 | #define DEBUG_WINDING_AT_T 1 |
| 107 | |
| 108 | #endif |
| 109 | |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 110 | #if DEBUG_AS_C_CODE |
caryclark@google.com | fa2aeee | 2013-07-15 13:29:13 +0000 | [diff] [blame] | 111 | #define CUBIC_DEBUG_STR "{{%1.9g,%1.9g}, {%1.9g,%1.9g}, {%1.9g,%1.9g}, {%1.9g,%1.9g}}" |
| 112 | #define QUAD_DEBUG_STR "{{%1.9g,%1.9g}, {%1.9g,%1.9g}, {%1.9g,%1.9g}}" |
| 113 | #define LINE_DEBUG_STR "{{%1.9g,%1.9g}, {%1.9g,%1.9g}}" |
| 114 | #define PT_DEBUG_STR "{{%1.9g,%1.9g}}" |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 115 | #else |
| 116 | #define CUBIC_DEBUG_STR "(%1.9g,%1.9g %1.9g,%1.9g %1.9g,%1.9g %1.9g,%1.9g)" |
| 117 | #define QUAD_DEBUG_STR "(%1.9g,%1.9g %1.9g,%1.9g %1.9g,%1.9g)" |
| 118 | #define LINE_DEBUG_STR "(%1.9g,%1.9g %1.9g,%1.9g)" |
| 119 | #define PT_DEBUG_STR "(%1.9g,%1.9g)" |
| 120 | #endif |
| 121 | #define T_DEBUG_STR(t, n) #t "[" #n "]=%1.9g" |
| 122 | #define TX_DEBUG_STR(t) #t "[%d]=%1.9g" |
| 123 | #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 |
| 124 | #define QUAD_DEBUG_DATA(q) q[0].fX, q[0].fY, q[1].fX, q[1].fY, q[2].fX, q[2].fY |
| 125 | #define LINE_DEBUG_DATA(l) l[0].fX, l[0].fY, l[1].fX, l[1].fY |
| 126 | #define PT_DEBUG_DATA(i, n) i.pt(n).fX, i.pt(n).fY |
| 127 | |
caryclark@google.com | 07e97fc | 2013-07-08 17:17:02 +0000 | [diff] [blame] | 128 | #ifndef DEBUG_TEST |
| 129 | #define DEBUG_TEST 0 |
caryclark@google.com | a5e5592 | 2013-05-07 18:51:31 +0000 | [diff] [blame] | 130 | #endif |
| 131 | |
caryclark@google.com | 570863f | 2013-09-16 15:55:01 +0000 | [diff] [blame] | 132 | #if DEBUG_SHOW_TEST_NAME |
| 133 | #include "SkTLS.h" |
| 134 | #endif |
| 135 | |
| 136 | #include "SkTArray.h" |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 137 | #include "SkTDArray.h" |
caryclark@google.com | 570863f | 2013-09-16 15:55:01 +0000 | [diff] [blame] | 138 | |
| 139 | class SkPathOpsDebug { |
| 140 | public: |
caryclark@google.com | 570863f | 2013-09-16 15:55:01 +0000 | [diff] [blame] | 141 | static const char* kLVerbStr[]; |
commit-bot@chromium.org | 8cb1daa | 2014-04-25 12:59:11 +0000 | [diff] [blame] | 142 | |
| 143 | #if defined(SK_DEBUG) || !FORCE_RELEASE |
caryclark@google.com | 570863f | 2013-09-16 15:55:01 +0000 | [diff] [blame] | 144 | static int gContourID; |
| 145 | static int gSegmentID; |
commit-bot@chromium.org | 8cb1daa | 2014-04-25 12:59:11 +0000 | [diff] [blame] | 146 | #endif |
caryclark@google.com | 570863f | 2013-09-16 15:55:01 +0000 | [diff] [blame] | 147 | |
| 148 | #if DEBUG_SORT || DEBUG_SWAP_TOP |
| 149 | static int gSortCountDefault; |
| 150 | static int gSortCount; |
| 151 | #endif |
| 152 | |
| 153 | #if DEBUG_ACTIVE_OP |
| 154 | static const char* kPathOpStr[]; |
| 155 | #endif |
| 156 | |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 157 | static bool ChaseContains(const SkTDArray<struct SkOpSpan *>& , const struct SkOpSpan * ); |
caryclark@google.com | 570863f | 2013-09-16 15:55:01 +0000 | [diff] [blame] | 158 | static void MathematicaIze(char* str, size_t bufferSize); |
| 159 | static bool ValidWind(int winding); |
| 160 | static void WindingPrintf(int winding); |
| 161 | |
| 162 | #if DEBUG_SHOW_TEST_NAME |
| 163 | static void* CreateNameStr(); |
| 164 | static void DeleteNameStr(void* v); |
| 165 | #define DEBUG_FILENAME_STRING_LENGTH 64 |
| 166 | #define DEBUG_FILENAME_STRING (reinterpret_cast<char* >(SkTLS::Get(SkPathOpsDebug::CreateNameStr, \ |
| 167 | SkPathOpsDebug::DeleteNameStr))) |
| 168 | static void BumpTestName(char* ); |
caryclark@google.com | 570863f | 2013-09-16 15:55:01 +0000 | [diff] [blame] | 169 | #endif |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 170 | static void ShowPath(const SkPath& one, const SkPath& two, SkPathOp op, const char* name); |
caryclark@google.com | 570863f | 2013-09-16 15:55:01 +0000 | [diff] [blame] | 171 | static void DumpAngles(const SkTArray<class SkOpAngle, true>& angles); |
caryclark@google.com | 7eaa53d | 2013-10-02 14:49:34 +0000 | [diff] [blame] | 172 | static void DumpAngles(const SkTArray<class SkOpAngle* , true>& angles); |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 173 | static void DumpContours(const SkTArray<class SkOpContour, true>& contours); |
| 174 | static void DumpContours(const SkTArray<class SkOpContour* , true>& contours); |
| 175 | static void DumpContourAngles(const SkTArray<class SkOpContour, true>& contours); |
| 176 | static void DumpContourAngles(const SkTArray<class SkOpContour* , true>& contours); |
| 177 | static void DumpContourPts(const SkTArray<class SkOpContour, true>& contours); |
| 178 | static void DumpContourPts(const SkTArray<class SkOpContour* , true>& contours); |
| 179 | static void DumpContourSpans(const SkTArray<class SkOpContour, true>& contours); |
| 180 | static void DumpContourSpans(const SkTArray<class SkOpContour* , true>& contours); |
| 181 | static void DumpSpans(const SkTDArray<struct SkOpSpan *>& ); |
| 182 | static void DumpSpans(const SkTDArray<struct SkOpSpan *>* ); |
caryclark@google.com | 570863f | 2013-09-16 15:55:01 +0000 | [diff] [blame] | 183 | }; |
| 184 | |
caryclark@google.com | 7eaa53d | 2013-10-02 14:49:34 +0000 | [diff] [blame] | 185 | // shorthand for calling from debugger |
| 186 | void Dump(const SkTArray<class SkOpAngle, true>& angles); |
| 187 | void Dump(const SkTArray<class SkOpAngle* , true>& angles); |
| 188 | void Dump(const SkTArray<class SkOpAngle, true>* angles); |
| 189 | void Dump(const SkTArray<class SkOpAngle* , true>* angles); |
| 190 | |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 191 | void Dump(const SkTArray<class SkOpContour, true>& contours); |
| 192 | void Dump(const SkTArray<class SkOpContour* , true>& contours); |
| 193 | void Dump(const SkTArray<class SkOpContour, true>* contours); |
| 194 | void Dump(const SkTArray<class SkOpContour* , true>* contours); |
| 195 | |
| 196 | void Dump(const SkTDArray<SkOpSpan *>& chaseArray); |
| 197 | void Dump(const SkTDArray<SkOpSpan *>* chaseArray); |
| 198 | |
| 199 | void DumpAngles(const SkTArray<class SkOpContour, true>& contours); |
| 200 | void DumpAngles(const SkTArray<class SkOpContour* , true>& contours); |
| 201 | void DumpAngles(const SkTArray<class SkOpContour, true>* contours); |
| 202 | void DumpAngles(const SkTArray<class SkOpContour* , true>* contours); |
| 203 | |
| 204 | void DumpPts(const SkTArray<class SkOpContour, true>& contours); |
| 205 | void DumpPts(const SkTArray<class SkOpContour* , true>& contours); |
| 206 | void DumpPts(const SkTArray<class SkOpContour, true>* contours); |
| 207 | void DumpPts(const SkTArray<class SkOpContour* , true>* contours); |
| 208 | |
| 209 | void DumpSpans(const SkTArray<class SkOpContour, true>& contours); |
| 210 | void DumpSpans(const SkTArray<class SkOpContour* , true>& contours); |
| 211 | void DumpSpans(const SkTArray<class SkOpContour, true>* contours); |
| 212 | void DumpSpans(const SkTArray<class SkOpContour* , true>* contours); |
| 213 | |
| 214 | // generates tools/path_sorter.htm and path_visualizer.htm compatible data |
| 215 | void DumpQ(const struct SkDQuad& quad1, const struct SkDQuad& quad2, int testNo); |
| 216 | |
| 217 | void DumpT(const struct SkDQuad& quad, double t); |
caryclark@google.com | 570863f | 2013-09-16 15:55:01 +0000 | [diff] [blame] | 218 | |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 219 | #endif |