OLD | NEW |
1 #include "SkOpContour.h" | 1 #include "SkOpContour.h" |
2 #include "SkIntersectionHelper.h" | 2 #include "SkIntersectionHelper.h" |
3 #include "SkOpSegment.h" | 3 #include "SkOpSegment.h" |
| 4 #include "SkString.h" |
4 | 5 |
5 inline void DebugDumpDouble(double x) { | 6 inline void DebugDumpDouble(double x) { |
6 if (x == floor(x)) { | 7 if (x == floor(x)) { |
7 SkDebugf("%.0f", x); | 8 SkDebugf("%.0f", x); |
8 } else { | 9 } else { |
9 SkDebugf("%1.19g", x); | 10 SkDebugf("%1.19g", x); |
10 } | 11 } |
11 } | 12 } |
12 | 13 |
13 inline void DebugDumpFloat(float x) { | 14 inline void DebugDumpFloat(float x) { |
14 if (x == floorf(x)) { | 15 if (x == floorf(x)) { |
15 SkDebugf("%.0f", x); | 16 SkDebugf("%.0f", x); |
16 } else { | 17 } else { |
17 SkDebugf("%1.9gf", x); | 18 SkDebugf("%1.9gf", x); |
18 } | 19 } |
19 } | 20 } |
20 | 21 |
| 22 |
| 23 #if DEBUG_SHOW_TEST_NAME |
| 24 |
| 25 static void output_scalar(SkScalar num) { |
| 26 if (num == (int) num) { |
| 27 SkDebugf("%d", (int) num); |
| 28 } else { |
| 29 SkString str; |
| 30 str.printf("%1.9g", num); |
| 31 int width = (int) str.size(); |
| 32 const char* cStr = str.c_str(); |
| 33 while (cStr[width - 1] == '0') { |
| 34 --width; |
| 35 } |
| 36 str.resize(width); |
| 37 SkDebugf("%sf", str.c_str()); |
| 38 } |
| 39 } |
| 40 |
| 41 static void output_points(const SkPoint* pts, int count) { |
| 42 for (int index = 0; index < count; ++index) { |
| 43 output_scalar(pts[index].fX); |
| 44 SkDebugf(", "); |
| 45 output_scalar(pts[index].fY); |
| 46 if (index + 1 < count) { |
| 47 SkDebugf(", "); |
| 48 } |
| 49 } |
| 50 SkDebugf(");\n"); |
| 51 } |
| 52 |
| 53 static void showPathContours(SkPath::RawIter& iter, const char* pathName) { |
| 54 uint8_t verb; |
| 55 SkPoint pts[4]; |
| 56 while ((verb = iter.next(pts)) != SkPath::kDone_Verb) { |
| 57 switch (verb) { |
| 58 case SkPath::kMove_Verb: |
| 59 SkDebugf(" %s.moveTo(", pathName); |
| 60 output_points(&pts[0], 1); |
| 61 continue; |
| 62 case SkPath::kLine_Verb: |
| 63 SkDebugf(" %s.lineTo(", pathName); |
| 64 output_points(&pts[1], 1); |
| 65 break; |
| 66 case SkPath::kQuad_Verb: |
| 67 SkDebugf(" %s.quadTo(", pathName); |
| 68 output_points(&pts[1], 2); |
| 69 break; |
| 70 case SkPath::kCubic_Verb: |
| 71 SkDebugf(" %s.cubicTo(", pathName); |
| 72 output_points(&pts[1], 3); |
| 73 break; |
| 74 case SkPath::kClose_Verb: |
| 75 SkDebugf(" %s.close();\n", pathName); |
| 76 break; |
| 77 default: |
| 78 SkDEBUGFAIL("bad verb"); |
| 79 return; |
| 80 } |
| 81 } |
| 82 } |
| 83 |
| 84 static const char* gFillTypeStr[] = { |
| 85 "kWinding_FillType", |
| 86 "kEvenOdd_FillType", |
| 87 "kInverseWinding_FillType", |
| 88 "kInverseEvenOdd_FillType" |
| 89 }; |
| 90 |
| 91 void SkPathOpsDebug::ShowOnePath(const SkPath& path, const char* name, bool incl
udeDeclaration) { |
| 92 SkPath::RawIter iter(path); |
| 93 #define SUPPORT_RECT_CONTOUR_DETECTION 0 |
| 94 #if SUPPORT_RECT_CONTOUR_DETECTION |
| 95 int rectCount = path.isRectContours() ? path.rectContours(NULL, NULL) : 0; |
| 96 if (rectCount > 0) { |
| 97 SkTDArray<SkRect> rects; |
| 98 SkTDArray<SkPath::Direction> directions; |
| 99 rects.setCount(rectCount); |
| 100 directions.setCount(rectCount); |
| 101 path.rectContours(rects.begin(), directions.begin()); |
| 102 for (int contour = 0; contour < rectCount; ++contour) { |
| 103 const SkRect& rect = rects[contour]; |
| 104 SkDebugf("path.addRect(%1.9g, %1.9g, %1.9g, %1.9g, %s);\n", rect.fLe
ft, rect.fTop, |
| 105 rect.fRight, rect.fBottom, directions[contour] == SkPath::kC
CW_Direction |
| 106 ? "SkPath::kCCW_Direction" : "SkPath::kCW_Direction"); |
| 107 } |
| 108 return; |
| 109 } |
| 110 #endif |
| 111 SkPath::FillType fillType = path.getFillType(); |
| 112 SkASSERT(fillType >= SkPath::kWinding_FillType && fillType <= SkPath::kInver
seEvenOdd_FillType); |
| 113 if (includeDeclaration) { |
| 114 SkDebugf(" SkPath %s;\n", name); |
| 115 } |
| 116 SkDebugf(" %s.setFillType(SkPath::%s);\n", name, gFillTypeStr[fillType]); |
| 117 iter.setPath(path); |
| 118 showPathContours(iter, name); |
| 119 } |
| 120 |
| 121 static void show_function_header(const char* functionName) { |
| 122 SkDebugf("\nstatic void %s(skiatest::Reporter* reporter, const char* filenam
e) {\n", functionName); |
| 123 if (strcmp("skphealth_com76", functionName) == 0) { |
| 124 SkDebugf("found it\n"); |
| 125 } |
| 126 } |
| 127 |
| 128 static const char* gOpStrs[] = { |
| 129 "kDifference_PathOp", |
| 130 "kIntersect_PathOp", |
| 131 "kUnion_PathOp", |
| 132 "kXor_PathOp", |
| 133 "kReverseDifference_PathOp", |
| 134 }; |
| 135 |
| 136 static void show_op(SkPathOp op, const char* pathOne, const char* pathTwo) { |
| 137 SkDebugf(" testPathOp(reporter, %s, %s, %s, filename);\n", pathOne, pathT
wo, gOpStrs[op]); |
| 138 SkDebugf("}\n"); |
| 139 } |
| 140 |
| 141 SK_DECLARE_STATIC_MUTEX(gTestMutex); |
| 142 |
| 143 void SkPathOpsDebug::ShowPath(const SkPath& a, const SkPath& b, SkPathOp shapeOp
, |
| 144 const char* testName) { |
| 145 SkAutoMutexAcquire ac(gTestMutex); |
| 146 show_function_header(testName); |
| 147 ShowOnePath(a, "path", true); |
| 148 ShowOnePath(b, "pathB", true); |
| 149 show_op(shapeOp, "path", "pathB"); |
| 150 } |
| 151 #endif |
| 152 |
21 // if not defined by PathOpsDebug.cpp ... | 153 // if not defined by PathOpsDebug.cpp ... |
22 #if !defined SK_DEBUG && FORCE_RELEASE | 154 #if !defined SK_DEBUG && FORCE_RELEASE |
23 bool SkPathOpsDebug::ValidWind(int wind) { | 155 bool SkPathOpsDebug::ValidWind(int wind) { |
24 return wind > SK_MinS32 + 0xFFFF && wind < SK_MaxS32 - 0xFFFF; | 156 return wind > SK_MinS32 + 0xFFFF && wind < SK_MaxS32 - 0xFFFF; |
25 } | 157 } |
26 | 158 |
27 void SkPathOpsDebug::WindingPrintf(int wind) { | 159 void SkPathOpsDebug::WindingPrintf(int wind) { |
28 if (wind == SK_MinS32) { | 160 if (wind == SK_MinS32) { |
29 SkDebugf("?"); | 161 SkDebugf("?"); |
30 } else { | 162 } else { |
(...skipping 703 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
734 dumpTestCase(quad1, quad2, testNo); | 866 dumpTestCase(quad1, quad2, testNo); |
735 dumpTestTrailer(); | 867 dumpTestTrailer(); |
736 dumpTestList(testNo, 0); | 868 dumpTestList(testNo, 0); |
737 SkDebugf("\n"); | 869 SkDebugf("\n"); |
738 } | 870 } |
739 | 871 |
740 void DumpT(const SkDQuad& quad, double t) { | 872 void DumpT(const SkDQuad& quad, double t) { |
741 SkDLine line = {{quad.ptAtT(t), quad[0]}}; | 873 SkDLine line = {{quad.ptAtT(t), quad[0]}}; |
742 line.dump(); | 874 line.dump(); |
743 } | 875 } |
OLD | NEW |