blob: 39d5a6dda83d55e6f048b4b38636a0ed6eb3dcc2 [file] [log] [blame]
caryclark@google.com07393ca2013-04-08 11:47:37 +00001/*
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.coma5e55922013-05-07 18:51:31 +000010#include "SkPathOps.h"
caryclark@google.com07393ca2013-04-08 11:47:37 +000011#include "SkTypes.h"
bungeman@google.comfab44db2013-10-11 18:50:45 +000012#include <stdio.h>
caryclark@google.com07393ca2013-04-08 11:47:37 +000013
14#ifdef SK_RELEASE
15#define FORCE_RELEASE 1
16#else
caryclark@google.comb3f09212013-04-17 15:49:16 +000017#define FORCE_RELEASE 1 // set force release to 1 for multiple thread -- no debugging
caryclark@google.com07393ca2013-04-08 11:47:37 +000018#endif
19
20#define ONE_OFF_DEBUG 0
21#define ONE_OFF_DEBUG_MATHEMATICA 0
22
caryclark@google.comdb60de72013-04-11 12:33:23 +000023#if defined(SK_BUILD_FOR_WIN) || defined(SK_BUILD_FOR_ANDROID)
caryclark@google.com07393ca2013-04-08 11:47:37 +000024 #define SK_RAND(seed) rand()
caryclark@google.com07393ca2013-04-08 11:47:37 +000025#else
26 #define SK_RAND(seed) rand_r(&seed)
caryclark@google.comdb60de72013-04-11 12:33:23 +000027#endif
28#ifdef SK_BUILD_FOR_WIN
29 #define SK_SNPRINTF _snprintf
30#else
skia.committer@gmail.com32840172013-04-09 07:01:27 +000031 #define SK_SNPRINTF snprintf
caryclark@google.com07393ca2013-04-08 11:47:37 +000032#endif
33
commit-bot@chromium.org4431e772014-04-14 17:08:59 +000034#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.com07393ca2013-04-08 11:47:37 +000038#if FORCE_RELEASE
39
40#define DEBUG_ACTIVE_OP 0
41#define DEBUG_ACTIVE_SPANS 0
caryclark@google.coma5e55922013-05-07 18:51:31 +000042#define DEBUG_ACTIVE_SPANS_FIRST_ONLY 0
43#define DEBUG_ACTIVE_SPANS_SHORT_FORM 1
caryclark@google.com07393ca2013-04-08 11:47:37 +000044#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.com570863f2013-09-16 15:55:01 +000049#define DEBUG_CHECK_ENDS 0
50#define DEBUG_CHECK_TINY 0
caryclark@google.com07393ca2013-04-08 11:47:37 +000051#define DEBUG_CONCIDENT 0
52#define DEBUG_CROSS 0
53#define DEBUG_FLAT_QUADS 0
54#define DEBUG_FLOW 0
commit-bot@chromium.org8cb1daa2014-04-25 12:59:11 +000055#define DEBUG_LIMIT_WIND_SUM 0
caryclark@google.com07393ca2013-04-08 11:47:37 +000056#define DEBUG_MARK_DONE 0
57#define DEBUG_PATH_CONSTRUCTION 0
caryclark@google.com03610322013-04-18 15:58:21 +000058#define DEBUG_SHOW_TEST_NAME 0
caryclark@google.com07393ca2013-04-08 11:47:37 +000059#define DEBUG_SHOW_TEST_PROGRESS 0
60#define DEBUG_SHOW_WINDING 0
61#define DEBUG_SORT 0
caryclark@google.comcffbcc32013-06-04 17:59:42 +000062#define DEBUG_SORT_COMPACT 0
caryclark@google.com570863f2013-09-16 15:55:01 +000063#define DEBUG_SORT_RAW 0
caryclark@google.coma5e55922013-05-07 18:51:31 +000064#define DEBUG_SORT_SINGLE 0
caryclark@google.com07393ca2013-04-08 11:47:37 +000065#define DEBUG_SWAP_TOP 0
66#define DEBUG_UNSORTABLE 0
caryclark@google.com4fdbb222013-07-23 15:27:41 +000067#define DEBUG_VALIDATE 0
caryclark@google.com07393ca2013-04-08 11:47:37 +000068#define DEBUG_WIND_BUMP 0
69#define DEBUG_WINDING 0
70#define DEBUG_WINDING_AT_T 0
71
72#else
73
74#define DEBUG_ACTIVE_OP 1
75#define DEBUG_ACTIVE_SPANS 1
caryclark@google.coma5e55922013-05-07 18:51:31 +000076#define DEBUG_ACTIVE_SPANS_FIRST_ONLY 0
caryclark@google.comcffbcc32013-06-04 17:59:42 +000077#define DEBUG_ACTIVE_SPANS_SHORT_FORM 1
caryclark@google.com07393ca2013-04-08 11:47:37 +000078#define DEBUG_ADD_INTERSECTING_TS 1
79#define DEBUG_ADD_T_PAIR 1
80#define DEBUG_ANGLE 1
81#define DEBUG_AS_C_CODE 1
82#define DEBUG_ASSEMBLE 1
caryclark@google.com570863f2013-09-16 15:55:01 +000083#define DEBUG_CHECK_ENDS 1
84#define DEBUG_CHECK_TINY 1
caryclark@google.com07393ca2013-04-08 11:47:37 +000085#define DEBUG_CONCIDENT 1
caryclark@google.com570863f2013-09-16 15:55:01 +000086#define DEBUG_CROSS 01
caryclark@google.com07393ca2013-04-08 11:47:37 +000087#define DEBUG_FLAT_QUADS 0
88#define DEBUG_FLOW 1
commit-bot@chromium.org8cb1daa2014-04-25 12:59:11 +000089#define DEBUG_LIMIT_WIND_SUM 4
caryclark@google.com07393ca2013-04-08 11:47:37 +000090#define DEBUG_MARK_DONE 1
91#define DEBUG_PATH_CONSTRUCTION 1
caryclark@google.com03610322013-04-18 15:58:21 +000092#define DEBUG_SHOW_TEST_NAME 1
caryclark@google.com07393ca2013-04-08 11:47:37 +000093#define DEBUG_SHOW_TEST_PROGRESS 1
94#define DEBUG_SHOW_WINDING 0
95#define DEBUG_SORT 1
caryclark@google.comcffbcc32013-06-04 17:59:42 +000096#define DEBUG_SORT_COMPACT 0
caryclark@google.com570863f2013-09-16 15:55:01 +000097#define DEBUG_SORT_RAW 0
caryclark@google.coma5e55922013-05-07 18:51:31 +000098#define DEBUG_SORT_SINGLE 0
caryclark@google.com07393ca2013-04-08 11:47:37 +000099#define DEBUG_SWAP_TOP 1
100#define DEBUG_UNSORTABLE 1
commit-bot@chromium.org8cb1daa2014-04-25 12:59:11 +0000101#define DEBUG_VALIDATE 0
caryclark@google.com07393ca2013-04-08 11:47:37 +0000102#define DEBUG_WIND_BUMP 0
103#define DEBUG_WINDING 1
104#define DEBUG_WINDING_AT_T 1
105
106#endif
107
caryclark@google.com07393ca2013-04-08 11:47:37 +0000108#if DEBUG_AS_C_CODE
caryclark@google.comfa2aeee2013-07-15 13:29:13 +0000109#define CUBIC_DEBUG_STR "{{%1.9g,%1.9g}, {%1.9g,%1.9g}, {%1.9g,%1.9g}, {%1.9g,%1.9g}}"
110#define QUAD_DEBUG_STR "{{%1.9g,%1.9g}, {%1.9g,%1.9g}, {%1.9g,%1.9g}}"
111#define LINE_DEBUG_STR "{{%1.9g,%1.9g}, {%1.9g,%1.9g}}"
112#define PT_DEBUG_STR "{{%1.9g,%1.9g}}"
caryclark@google.com07393ca2013-04-08 11:47:37 +0000113#else
114#define CUBIC_DEBUG_STR "(%1.9g,%1.9g %1.9g,%1.9g %1.9g,%1.9g %1.9g,%1.9g)"
115#define QUAD_DEBUG_STR "(%1.9g,%1.9g %1.9g,%1.9g %1.9g,%1.9g)"
116#define LINE_DEBUG_STR "(%1.9g,%1.9g %1.9g,%1.9g)"
117#define PT_DEBUG_STR "(%1.9g,%1.9g)"
118#endif
119#define T_DEBUG_STR(t, n) #t "[" #n "]=%1.9g"
120#define TX_DEBUG_STR(t) #t "[%d]=%1.9g"
121#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
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).fX, i.pt(n).fY
125
caryclark@google.com07e97fc2013-07-08 17:17:02 +0000126#ifndef DEBUG_TEST
127#define DEBUG_TEST 0
caryclark@google.coma5e55922013-05-07 18:51:31 +0000128#endif
129
caryclark@google.com570863f2013-09-16 15:55:01 +0000130#if DEBUG_SHOW_TEST_NAME
131#include "SkTLS.h"
132#endif
133
134#include "SkTArray.h"
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000135#include "SkTDArray.h"
caryclark@google.com570863f2013-09-16 15:55:01 +0000136
137class SkPathOpsDebug {
138public:
caryclark@google.com570863f2013-09-16 15:55:01 +0000139 static const char* kLVerbStr[];
commit-bot@chromium.org8cb1daa2014-04-25 12:59:11 +0000140
141#if defined(SK_DEBUG) || !FORCE_RELEASE
caryclark@google.com570863f2013-09-16 15:55:01 +0000142 static int gContourID;
143 static int gSegmentID;
commit-bot@chromium.org8cb1daa2014-04-25 12:59:11 +0000144#endif
caryclark@google.com570863f2013-09-16 15:55:01 +0000145
146#if DEBUG_SORT || DEBUG_SWAP_TOP
147 static int gSortCountDefault;
148 static int gSortCount;
149#endif
150
151#if DEBUG_ACTIVE_OP
152 static const char* kPathOpStr[];
153#endif
154
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000155 static bool ChaseContains(const SkTDArray<struct SkOpSpan *>& , const struct SkOpSpan * );
caryclark@google.com570863f2013-09-16 15:55:01 +0000156 static void MathematicaIze(char* str, size_t bufferSize);
157 static bool ValidWind(int winding);
158 static void WindingPrintf(int winding);
159
160#if DEBUG_SHOW_TEST_NAME
161 static void* CreateNameStr();
162 static void DeleteNameStr(void* v);
163#define DEBUG_FILENAME_STRING_LENGTH 64
164#define DEBUG_FILENAME_STRING (reinterpret_cast<char* >(SkTLS::Get(SkPathOpsDebug::CreateNameStr, \
165 SkPathOpsDebug::DeleteNameStr)))
166 static void BumpTestName(char* );
caryclark@google.com570863f2013-09-16 15:55:01 +0000167#endif
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000168 static void ShowPath(const SkPath& one, const SkPath& two, SkPathOp op, const char* name);
caryclark@google.com570863f2013-09-16 15:55:01 +0000169 static void DumpAngles(const SkTArray<class SkOpAngle, true>& angles);
caryclark@google.com7eaa53d2013-10-02 14:49:34 +0000170 static void DumpAngles(const SkTArray<class SkOpAngle* , true>& angles);
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000171 static void DumpContours(const SkTArray<class SkOpContour, true>& contours);
172 static void DumpContours(const SkTArray<class SkOpContour* , true>& contours);
173 static void DumpContourAngles(const SkTArray<class SkOpContour, true>& contours);
174 static void DumpContourAngles(const SkTArray<class SkOpContour* , true>& contours);
175 static void DumpContourPts(const SkTArray<class SkOpContour, true>& contours);
176 static void DumpContourPts(const SkTArray<class SkOpContour* , true>& contours);
177 static void DumpContourSpans(const SkTArray<class SkOpContour, true>& contours);
178 static void DumpContourSpans(const SkTArray<class SkOpContour* , true>& contours);
179 static void DumpSpans(const SkTDArray<struct SkOpSpan *>& );
180 static void DumpSpans(const SkTDArray<struct SkOpSpan *>* );
caryclark@google.com570863f2013-09-16 15:55:01 +0000181};
182
caryclark@google.com7eaa53d2013-10-02 14:49:34 +0000183// shorthand for calling from debugger
184void Dump(const SkTArray<class SkOpAngle, true>& angles);
185void Dump(const SkTArray<class SkOpAngle* , true>& angles);
186void Dump(const SkTArray<class SkOpAngle, true>* angles);
187void Dump(const SkTArray<class SkOpAngle* , true>* angles);
188
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000189void Dump(const SkTArray<class SkOpContour, true>& contours);
190void Dump(const SkTArray<class SkOpContour* , true>& contours);
191void Dump(const SkTArray<class SkOpContour, true>* contours);
192void Dump(const SkTArray<class SkOpContour* , true>* contours);
193
194void Dump(const SkTDArray<SkOpSpan *>& chaseArray);
195void Dump(const SkTDArray<SkOpSpan *>* chaseArray);
196
197void DumpAngles(const SkTArray<class SkOpContour, true>& contours);
198void DumpAngles(const SkTArray<class SkOpContour* , true>& contours);
199void DumpAngles(const SkTArray<class SkOpContour, true>* contours);
200void DumpAngles(const SkTArray<class SkOpContour* , true>* contours);
201
202void DumpPts(const SkTArray<class SkOpContour, true>& contours);
203void DumpPts(const SkTArray<class SkOpContour* , true>& contours);
204void DumpPts(const SkTArray<class SkOpContour, true>* contours);
205void DumpPts(const SkTArray<class SkOpContour* , true>* contours);
206
207void DumpSpans(const SkTArray<class SkOpContour, true>& contours);
208void DumpSpans(const SkTArray<class SkOpContour* , true>& contours);
209void DumpSpans(const SkTArray<class SkOpContour, true>* contours);
210void DumpSpans(const SkTArray<class SkOpContour* , true>* contours);
211
212// generates tools/path_sorter.htm and path_visualizer.htm compatible data
213void DumpQ(const struct SkDQuad& quad1, const struct SkDQuad& quad2, int testNo);
214
215void DumpT(const struct SkDQuad& quad, double t);
caryclark@google.com570863f2013-09-16 15:55:01 +0000216
caryclark@google.com07393ca2013-04-08 11:47:37 +0000217#endif