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 11 matching lines...) Expand all Loading... |
22 "\n" | 22 "\n" |
23 "<script type=\"text/javascript\">\n" | 23 "<script type=\"text/javascript\">\n" |
24 "\n" | 24 "\n" |
25 "var testDivs = [\n"; | 25 "var testDivs = [\n"; |
26 | 26 |
27 static const char* opStrs[] = { | 27 static const char* opStrs[] = { |
28 "kDifference_PathOp", | 28 "kDifference_PathOp", |
29 "kIntersect_PathOp", | 29 "kIntersect_PathOp", |
30 "kUnion_PathOp", | 30 "kUnion_PathOp", |
31 "kXor_PathOp", | 31 "kXor_PathOp", |
| 32 "kReverseDifference_PathOp", |
32 }; | 33 }; |
33 | 34 |
34 static const char* opSuffixes[] = { | 35 static const char* opSuffixes[] = { |
35 "d", | 36 "d", |
36 "i", | 37 "i", |
37 "u", | 38 "u", |
38 "o", | 39 "o", |
39 }; | 40 }; |
40 | 41 |
41 static bool gShowPath = false; | 42 static bool gShowPath = false; |
42 static bool gComparePaths = true; | 43 static bool gComparePaths = true; |
43 static bool gComparePathsAssert = true; | 44 static bool gComparePathsAssert = true; |
44 static bool gPathStrAssert = true; | 45 static bool gPathStrAssert = true; |
45 | 46 |
46 static void showPathContour(SkPath::Iter& iter) { | 47 static void showPathContours(SkPath::Iter& iter) { |
47 uint8_t verb; | 48 uint8_t verb; |
48 SkPoint pts[4]; | 49 SkPoint pts[4]; |
49 while ((verb = iter.next(pts)) != SkPath::kDone_Verb) { | 50 while ((verb = iter.next(pts)) != SkPath::kDone_Verb) { |
50 switch (verb) { | 51 switch (verb) { |
51 case SkPath::kMove_Verb: | 52 case SkPath::kMove_Verb: |
52 SkDebugf("path.moveTo(%1.9g,%1.9g);\n", pts[0].fX, pts[0].fY); | 53 SkDebugf("path.moveTo(%1.9g,%1.9g);\n", pts[0].fX, pts[0].fY); |
53 continue; | 54 continue; |
54 case SkPath::kLine_Verb: | 55 case SkPath::kLine_Verb: |
55 SkDebugf("path.lineTo(%1.9g,%1.9g);\n", pts[1].fX, pts[1].fY); | 56 SkDebugf("path.lineTo(%1.9g,%1.9g);\n", pts[1].fX, pts[1].fY); |
56 break; | 57 break; |
(...skipping 13 matching lines...) Expand all Loading... |
70 return; | 71 return; |
71 } | 72 } |
72 } | 73 } |
73 } | 74 } |
74 | 75 |
75 void showPath(const SkPath& path, const char* str) { | 76 void showPath(const SkPath& path, const char* str) { |
76 SkDebugf("%s\n", !str ? "original:" : str); | 77 SkDebugf("%s\n", !str ? "original:" : str); |
77 showPath(path); | 78 showPath(path); |
78 } | 79 } |
79 | 80 |
| 81 const char* fillTypeStr[] = { |
| 82 "kWinding_FillType", |
| 83 "kEvenOdd_FillType", |
| 84 "kInverseWinding_FillType", |
| 85 "kInverseEvenOdd_FillType" |
| 86 }; |
| 87 |
80 void showPath(const SkPath& path) { | 88 void showPath(const SkPath& path) { |
81 SkPath::Iter iter(path, true); | 89 SkPath::Iter iter(path, true); |
82 #define SUPPORT_RECT_CONTOUR_DETECTION 0 | 90 #define SUPPORT_RECT_CONTOUR_DETECTION 0 |
83 #if SUPPORT_RECT_CONTOUR_DETECTION | 91 #if SUPPORT_RECT_CONTOUR_DETECTION |
84 int rectCount = path.isRectContours() ? path.rectContours(NULL, NULL) : 0; | 92 int rectCount = path.isRectContours() ? path.rectContours(NULL, NULL) : 0; |
85 if (rectCount > 0) { | 93 if (rectCount > 0) { |
86 SkTDArray<SkRect> rects; | 94 SkTDArray<SkRect> rects; |
87 SkTDArray<SkPath::Direction> directions; | 95 SkTDArray<SkPath::Direction> directions; |
88 rects.setCount(rectCount); | 96 rects.setCount(rectCount); |
89 directions.setCount(rectCount); | 97 directions.setCount(rectCount); |
90 path.rectContours(rects.begin(), directions.begin()); | 98 path.rectContours(rects.begin(), directions.begin()); |
91 for (int contour = 0; contour < rectCount; ++contour) { | 99 for (int contour = 0; contour < rectCount; ++contour) { |
92 const SkRect& rect = rects[contour]; | 100 const SkRect& rect = rects[contour]; |
93 SkDebugf("path.addRect(%1.9g, %1.9g, %1.9g, %1.9g, %s);\n", rect.fLe
ft, rect.fTop, | 101 SkDebugf("path.addRect(%1.9g, %1.9g, %1.9g, %1.9g, %s);\n", rect.fLe
ft, rect.fTop, |
94 rect.fRight, rect.fBottom, directions[contour] == SkPath::kC
CW_Direction | 102 rect.fRight, rect.fBottom, directions[contour] == SkPath::kC
CW_Direction |
95 ? "SkPath::kCCW_Direction" : "SkPath::kCW_Direction"); | 103 ? "SkPath::kCCW_Direction" : "SkPath::kCW_Direction"); |
96 } | 104 } |
97 return; | 105 return; |
98 } | 106 } |
99 #endif | 107 #endif |
| 108 SkPath::FillType fillType = path.getFillType(); |
| 109 SkASSERT(fillType >= SkPath::kWinding_FillType && fillType <= SkPath::kInver
seEvenOdd_FillType); |
| 110 SkDebugf("path.setFillType(%s);\n", fillTypeStr[fillType]); |
100 iter.setPath(path, true); | 111 iter.setPath(path, true); |
101 showPathContour(iter); | 112 showPathContours(iter); |
102 } | 113 } |
103 | 114 |
104 void showPathData(const SkPath& path) { | 115 void showPathData(const SkPath& path) { |
105 SkPath::Iter iter(path, true); | 116 SkPath::Iter iter(path, true); |
106 uint8_t verb; | 117 uint8_t verb; |
107 SkPoint pts[4]; | 118 SkPoint pts[4]; |
108 while ((verb = iter.next(pts)) != SkPath::kDone_Verb) { | 119 while ((verb = iter.next(pts)) != SkPath::kDone_Verb) { |
109 switch (verb) { | 120 switch (verb) { |
110 case SkPath::kMove_Verb: | 121 case SkPath::kMove_Verb: |
111 continue; | 122 continue; |
(...skipping 26 matching lines...) Expand all Loading... |
138 break; | 149 break; |
139 case kIntersect_PathOp: | 150 case kIntersect_PathOp: |
140 SkDebugf("op intersect\n"); | 151 SkDebugf("op intersect\n"); |
141 break; | 152 break; |
142 case kUnion_PathOp: | 153 case kUnion_PathOp: |
143 SkDebugf("op union\n"); | 154 SkDebugf("op union\n"); |
144 break; | 155 break; |
145 case kXOR_PathOp: | 156 case kXOR_PathOp: |
146 SkDebugf("op xor\n"); | 157 SkDebugf("op xor\n"); |
147 break; | 158 break; |
| 159 case kReverseDifference_PathOp: |
| 160 SkDebugf("op reverse difference\n"); |
| 161 break; |
148 default: | 162 default: |
149 SkASSERT(0); | 163 SkASSERT(0); |
150 } | 164 } |
151 } | 165 } |
152 | 166 |
153 static void showPath(const SkPath& path, const char* str, const SkMatrix& scale)
{ | 167 static void showPath(const SkPath& path, const char* str, const SkMatrix& scale)
{ |
154 SkPath scaled; | 168 SkPath scaled; |
155 SkMatrix inverse; | 169 SkMatrix inverse; |
156 bool success = scale.invert(&inverse); | 170 bool success = scale.invert(&inverse); |
157 if (!success) { | 171 if (!success) { |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
349 drawAsciiPaths(scaledOne, scaledTwo, true); | 363 drawAsciiPaths(scaledOne, scaledTwo, true); |
350 } | 364 } |
351 | 365 |
352 static int comparePaths(skiatest::Reporter* reporter, const SkPath& one, const S
kPath& scaledOne, | 366 static int comparePaths(skiatest::Reporter* reporter, const SkPath& one, const S
kPath& scaledOne, |
353 const SkPath& two, const SkPath& scaledTwo, SkBitmap& bi
tmap, | 367 const SkPath& two, const SkPath& scaledTwo, SkBitmap& bi
tmap, |
354 const SkPath& a, const SkPath& b, const SkPathOp shapeOp
, | 368 const SkPath& a, const SkPath& b, const SkPathOp shapeOp
, |
355 const SkMatrix& scale) { | 369 const SkMatrix& scale) { |
356 int errors2x2; | 370 int errors2x2; |
357 int errors = pathsDrawTheSame(bitmap, scaledOne, scaledTwo, errors2x2); | 371 int errors = pathsDrawTheSame(bitmap, scaledOne, scaledTwo, errors2x2); |
358 if (errors2x2 == 0) { | 372 if (errors2x2 == 0) { |
| 373 if (gShowPath) { |
| 374 showPathOpPath(one, two, a, b, scaledOne, scaledTwo, shapeOp, scale)
; |
| 375 } |
359 return 0; | 376 return 0; |
360 } | 377 } |
361 const int MAX_ERRORS = 8; | 378 const int MAX_ERRORS = 8; |
362 if (errors2x2 == MAX_ERRORS || errors2x2 == MAX_ERRORS - 1) { | 379 if (gShowPath || errors2x2 == MAX_ERRORS || errors2x2 == MAX_ERRORS - 1) { |
363 showPathOpPath(one, two, a, b, scaledOne, scaledTwo, shapeOp, scale); | 380 showPathOpPath(one, two, a, b, scaledOne, scaledTwo, shapeOp, scale); |
364 } | 381 } |
365 if (errors2x2 > MAX_ERRORS && gComparePathsAssert) { | 382 if (errors2x2 > MAX_ERRORS && gComparePathsAssert) { |
366 SkDebugf("%s errors=%d\n", __FUNCTION__, errors); | 383 SkDebugf("%s errors=%d\n", __FUNCTION__, errors); |
367 showPathOpPath(one, two, a, b, scaledOne, scaledTwo, shapeOp, scale); | 384 showPathOpPath(one, two, a, b, scaledOne, scaledTwo, shapeOp, scale); |
368 REPORTER_ASSERT(reporter, 0); | 385 REPORTER_ASSERT(reporter, 0); |
369 } | 386 } |
370 return errors2x2 > MAX_ERRORS ? errors2x2 : 0; | 387 return errors2x2 > MAX_ERRORS ? errors2x2 : 0; |
371 } | 388 } |
372 | 389 |
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
584 } | 601 } |
585 if (tests[index].fun == stopTest) { | 602 if (tests[index].fun == stopTest) { |
586 SkDebugf("lastTest\n"); | 603 SkDebugf("lastTest\n"); |
587 } | 604 } |
588 if (index == last) { | 605 if (index == last) { |
589 break; | 606 break; |
590 } | 607 } |
591 index += reverse ? -1 : 1; | 608 index += reverse ? -1 : 1; |
592 } while (true); | 609 } while (true); |
593 } | 610 } |
OLD | NEW |