OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "PathOpsExtendedTest.h" | 8 #include "PathOpsExtendedTest.h" |
9 #include "PathOpsThreadedCommon.h" | 9 #include "PathOpsThreadedCommon.h" |
10 #include "SkBitmap.h" | 10 #include "SkBitmap.h" |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 static bool gComparePathsAssert = true; | 45 static bool gComparePathsAssert = true; |
46 static bool gPathStrAssert = true; | 46 static bool gPathStrAssert = true; |
47 | 47 |
48 static const char* gFillTypeStr[] = { | 48 static const char* gFillTypeStr[] = { |
49 "kWinding_FillType", | 49 "kWinding_FillType", |
50 "kEvenOdd_FillType", | 50 "kEvenOdd_FillType", |
51 "kInverseWinding_FillType", | 51 "kInverseWinding_FillType", |
52 "kInverseEvenOdd_FillType" | 52 "kInverseEvenOdd_FillType" |
53 }; | 53 }; |
54 | 54 |
| 55 static void output_scalar(SkScalar num) { |
| 56 if (num == (int) num) { |
| 57 SkDebugf("%d", (int) num); |
| 58 } else { |
| 59 SkString str; |
| 60 str.printf("%1.9g", num); |
| 61 int width = str.size(); |
| 62 const char* cStr = str.c_str(); |
| 63 while (cStr[width - 1] == '0') { |
| 64 --width; |
| 65 } |
| 66 str.resize(width); |
| 67 SkDebugf("%sf", str.c_str()); |
| 68 } |
| 69 } |
| 70 |
| 71 static void output_points(const SkPoint* pts, int count) { |
| 72 for (int index = 0; index < count; ++index) { |
| 73 output_scalar(pts[index].fX); |
| 74 SkDebugf(", "); |
| 75 output_scalar(pts[index].fY); |
| 76 if (index + 1 < count) { |
| 77 SkDebugf(", "); |
| 78 } |
| 79 } |
| 80 SkDebugf(");\n"); |
| 81 } |
| 82 |
55 static void showPathContours(SkPath::RawIter& iter, const char* pathName) { | 83 static void showPathContours(SkPath::RawIter& iter, const char* pathName) { |
56 uint8_t verb; | 84 uint8_t verb; |
57 SkPoint pts[4]; | 85 SkPoint pts[4]; |
58 while ((verb = iter.next(pts)) != SkPath::kDone_Verb) { | 86 while ((verb = iter.next(pts)) != SkPath::kDone_Verb) { |
59 switch (verb) { | 87 switch (verb) { |
60 case SkPath::kMove_Verb: | 88 case SkPath::kMove_Verb: |
61 SkDebugf(" %s.moveTo(%#1.9gf, %#1.9gf);\n", pathName, pts[0].
fX, pts[0].fY); | 89 SkDebugf(" %s.moveTo(", pathName); |
| 90 output_points(&pts[0], 1); |
62 continue; | 91 continue; |
63 case SkPath::kLine_Verb: | 92 case SkPath::kLine_Verb: |
64 SkDebugf(" %s.lineTo(%#1.9gf, %#1.9gf);\n", pathName, pts[1].
fX, pts[1].fY); | 93 SkDebugf(" %s.lineTo(", pathName); |
| 94 output_points(&pts[1], 1); |
65 break; | 95 break; |
66 case SkPath::kQuad_Verb: | 96 case SkPath::kQuad_Verb: |
67 SkDebugf(" %s.quadTo(%#1.9gf, %#1.9gf, %#1.9gf, %#1.9gf);\n",
pathName, | 97 SkDebugf(" %s.quadTo(", pathName); |
68 pts[1].fX, pts[1].fY, pts[2].fX, pts[2].fY); | 98 output_points(&pts[1], 2); |
69 break; | 99 break; |
70 case SkPath::kCubic_Verb: | 100 case SkPath::kCubic_Verb: |
71 SkDebugf(" %s.cubicTo(%#1.9gf, %#1.9gf, %#1.9gf, %#1.9gf, %#1
.9gf, %#1.9gf);\n", | 101 SkDebugf(" %s.cubicTo(", pathName); |
72 pathName, pts[1].fX, pts[1].fY, pts[2].fX, pts[2].fY, pts[3]
.fX, pts[3].fY); | 102 output_points(&pts[1], 3); |
73 break; | 103 break; |
74 case SkPath::kClose_Verb: | 104 case SkPath::kClose_Verb: |
75 SkDebugf(" %s.close();\n", pathName); | 105 SkDebugf(" %s.close();\n", pathName); |
76 break; | 106 break; |
77 default: | 107 default: |
78 SkDEBUGFAIL("bad verb"); | 108 SkDEBUGFAIL("bad verb"); |
79 return; | 109 return; |
80 } | 110 } |
81 } | 111 } |
82 } | 112 } |
(...skipping 26 matching lines...) Expand all Loading... |
109 SkDebugf(" %s.setFillType(SkPath::%s);\n", pathName, gFillTypeStr[fillTyp
e]); | 139 SkDebugf(" %s.setFillType(SkPath::%s);\n", pathName, gFillTypeStr[fillTyp
e]); |
110 iter.setPath(path); | 140 iter.setPath(path); |
111 showPathContours(iter, pathName); | 141 showPathContours(iter, pathName); |
112 } | 142 } |
113 | 143 |
114 #if DEBUG_SHOW_TEST_NAME | 144 #if DEBUG_SHOW_TEST_NAME |
115 static void showPathData(const SkPath& path) { | 145 static void showPathData(const SkPath& path) { |
116 SkPath::RawIter iter(path); | 146 SkPath::RawIter iter(path); |
117 uint8_t verb; | 147 uint8_t verb; |
118 SkPoint pts[4]; | 148 SkPoint pts[4]; |
| 149 SkPoint firstPt, lastPt; |
| 150 bool firstPtSet = false; |
| 151 bool lastPtSet = true; |
119 while ((verb = iter.next(pts)) != SkPath::kDone_Verb) { | 152 while ((verb = iter.next(pts)) != SkPath::kDone_Verb) { |
120 switch (verb) { | 153 switch (verb) { |
121 case SkPath::kMove_Verb: | 154 case SkPath::kMove_Verb: |
| 155 firstPt = pts[0]; |
| 156 firstPtSet = true; |
122 continue; | 157 continue; |
123 case SkPath::kLine_Verb: | 158 case SkPath::kLine_Verb: |
124 SkDebugf("{{%1.9g,%1.9g}, {%1.9g,%1.9g}},\n", pts[0].fX, pts[0].
fY, | 159 SkDebugf("{{%1.9g,%1.9g}, {%1.9g,%1.9g}},\n", pts[0].fX, pts[0].
fY, |
125 pts[1].fX, pts[1].fY); | 160 pts[1].fX, pts[1].fY); |
| 161 lastPt = pts[1]; |
| 162 lastPtSet = true; |
126 break; | 163 break; |
127 case SkPath::kQuad_Verb: | 164 case SkPath::kQuad_Verb: |
128 SkDebugf("{{%1.9g,%1.9g}, {%1.9g,%1.9g}, {%1.9g,%1.9g}},\n", | 165 SkDebugf("{{%1.9g,%1.9g}, {%1.9g,%1.9g}, {%1.9g,%1.9g}},\n", |
129 pts[0].fX, pts[0].fY, pts[1].fX, pts[1].fY, pts[2].fX, p
ts[2].fY); | 166 pts[0].fX, pts[0].fY, pts[1].fX, pts[1].fY, pts[2].fX, p
ts[2].fY); |
| 167 lastPt = pts[2]; |
| 168 lastPtSet = true; |
130 break; | 169 break; |
131 case SkPath::kCubic_Verb: | 170 case SkPath::kCubic_Verb: |
132 SkDebugf("{{%1.9g,%1.9g}, {%1.9g,%1.9g}, {%1.9g,%1.9g}, {%1.9g,%
1.9g}},\n", | 171 SkDebugf("{{%1.9g,%1.9g}, {%1.9g,%1.9g}, {%1.9g,%1.9g}, {%1.9g,%
1.9g}},\n", |
133 pts[0].fX, pts[0].fY, pts[1].fX, pts[1].fY, pts[2].fX, p
ts[2].fY, | 172 pts[0].fX, pts[0].fY, pts[1].fX, pts[1].fY, pts[2].fX, p
ts[2].fY, |
134 pts[3].fX, pts[3].fY); | 173 pts[3].fX, pts[3].fY); |
| 174 lastPt = pts[3]; |
| 175 lastPtSet = true; |
135 break; | 176 break; |
136 case SkPath::kClose_Verb: | 177 case SkPath::kClose_Verb: |
| 178 if (firstPtSet && lastPtSet && firstPt != lastPt) { |
| 179 SkDebugf("{{%1.9g,%1.9g}, {%1.9g,%1.9g}},\n", lastPt.fX, las
tPt.fY, |
| 180 firstPt.fX, firstPt.fY); |
| 181 } |
| 182 firstPtSet = lastPtSet = false; |
137 break; | 183 break; |
138 default: | 184 default: |
139 SkDEBUGFAIL("bad verb"); | 185 SkDEBUGFAIL("bad verb"); |
140 return; | 186 return; |
141 } | 187 } |
142 } | 188 } |
143 } | 189 } |
144 #endif | 190 #endif |
145 | 191 |
146 void showOp(const SkPathOp op) { | 192 void showOp(const SkPathOp op) { |
(...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
514 showPath(a, "path", true); | 560 showPath(a, "path", true); |
515 showPath(b, "pathB", true); | 561 showPath(b, "pathB", true); |
516 ShowOp(shapeOp, "path", "pathB"); | 562 ShowOp(shapeOp, "path", "pathB"); |
517 } | 563 } |
518 #endif | 564 #endif |
519 | 565 |
520 bool testPathOp(skiatest::Reporter* reporter, const SkPath& a, const SkPath& b, | 566 bool testPathOp(skiatest::Reporter* reporter, const SkPath& a, const SkPath& b, |
521 const SkPathOp shapeOp, const char* testName) { | 567 const SkPathOp shapeOp, const char* testName) { |
522 #if DEBUG_SHOW_TEST_NAME | 568 #if DEBUG_SHOW_TEST_NAME |
523 if (testName == NULL) { | 569 if (testName == NULL) { |
| 570 SkDebugf("\n"); |
524 showPathData(a); | 571 showPathData(a); |
525 showOp(shapeOp); | 572 showOp(shapeOp); |
526 showPathData(b); | 573 showPathData(b); |
527 } else { | 574 } else { |
528 DebugShowPath(a, b, shapeOp, testName); | 575 DebugShowPath(a, b, shapeOp, testName); |
529 } | 576 } |
530 #endif | 577 #endif |
531 SkPath out; | 578 SkPath out; |
532 if (!Op(a, b, shapeOp, &out) ) { | 579 if (!Op(a, b, shapeOp, &out) ) { |
533 SkDebugf("%s did not expect failure\n", __FUNCTION__); | 580 SkDebugf("%s did not expect failure\n", __FUNCTION__); |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
638 } | 685 } |
639 if (tests[index].fun == stopTest) { | 686 if (tests[index].fun == stopTest) { |
640 SkDebugf("lastTest\n"); | 687 SkDebugf("lastTest\n"); |
641 } | 688 } |
642 if (index == last) { | 689 if (index == last) { |
643 break; | 690 break; |
644 } | 691 } |
645 index += reverse ? -1 : 1; | 692 index += reverse ? -1 : 1; |
646 } while (true); | 693 } while (true); |
647 } | 694 } |
OLD | NEW |