OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 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 "Test.h" | 8 #include "Test.h" |
9 #include "SkCanvas.h" | 9 #include "SkCanvas.h" |
10 #include "SkPaint.h" | 10 #include "SkPaint.h" |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
120 } | 120 } |
121 | 121 |
122 static void test_android_specific_behavior(skiatest::Reporter* reporter) { | 122 static void test_android_specific_behavior(skiatest::Reporter* reporter) { |
123 #ifdef SK_BUILD_FOR_ANDROID | 123 #ifdef SK_BUILD_FOR_ANDROID |
124 // Make sure we treat fGenerationID and fSourcePath correctly for each of | 124 // Make sure we treat fGenerationID and fSourcePath correctly for each of |
125 // copy, assign, rewind, reset, and swap. | 125 // copy, assign, rewind, reset, and swap. |
126 SkPath original, source, anotherSource; | 126 SkPath original, source, anotherSource; |
127 original.setSourcePath(&source); | 127 original.setSourcePath(&source); |
128 original.moveTo(0, 0); | 128 original.moveTo(0, 0); |
129 original.lineTo(1, 1); | 129 original.lineTo(1, 1); |
130 REPORTER_ASSERT(reporter, original.getGenerationID() > 0); | |
131 REPORTER_ASSERT(reporter, original.getSourcePath() == &source); | 130 REPORTER_ASSERT(reporter, original.getSourcePath() == &source); |
132 | 131 |
133 uint32_t copyID, assignID; | 132 uint32_t copyID, assignID; |
134 | 133 |
135 // Test copy constructor. Copy generation ID, copy source path. | 134 // Test copy constructor. Copy generation ID, copy source path. |
136 SkPath copy(original); | 135 SkPath copy(original); |
137 REPORTER_ASSERT(reporter, copy.getGenerationID() == original.getGenerationID
()); | 136 REPORTER_ASSERT(reporter, copy.getGenerationID() == original.getGenerationID
()); |
138 REPORTER_ASSERT(reporter, copy.getSourcePath() == original.getSourcePath()); | 137 REPORTER_ASSERT(reporter, copy.getSourcePath() == original.getSourcePath()); |
139 | 138 |
140 // Test assigment operator. Increment generation ID, copy source path. | 139 // Test assigment operator. Change generation ID, copy source path. |
141 SkPath assign; | 140 SkPath assign; |
142 assignID = assign.getGenerationID(); | 141 assignID = assign.getGenerationID(); |
143 assign = original; | 142 assign = original; |
144 REPORTER_ASSERT(reporter, assign.getGenerationID() > assignID); | 143 REPORTER_ASSERT(reporter, assign.getGenerationID() != assignID); |
145 REPORTER_ASSERT(reporter, assign.getSourcePath() == original.getSourcePath()
); | 144 REPORTER_ASSERT(reporter, assign.getSourcePath() == original.getSourcePath()
); |
146 | 145 |
147 // Test rewind. Increment generation ID, don't touch source path. | 146 // Test rewind. Change generation ID, don't touch source path. |
148 copyID = copy.getGenerationID(); | 147 copyID = copy.getGenerationID(); |
149 copy.rewind(); | 148 copy.rewind(); |
150 REPORTER_ASSERT(reporter, copy.getGenerationID() > copyID); | 149 REPORTER_ASSERT(reporter, copy.getGenerationID() != copyID); |
151 REPORTER_ASSERT(reporter, copy.getSourcePath() == original.getSourcePath()); | 150 REPORTER_ASSERT(reporter, copy.getSourcePath() == original.getSourcePath()); |
152 | 151 |
153 // Test reset. Increment generation ID, don't touch source path. | 152 // Test reset. Change generation ID, don't touch source path. |
154 assignID = assign.getGenerationID(); | 153 assignID = assign.getGenerationID(); |
155 assign.reset(); | 154 assign.reset(); |
156 REPORTER_ASSERT(reporter, assign.getGenerationID() > assignID); | 155 REPORTER_ASSERT(reporter, assign.getGenerationID() != assignID); |
157 REPORTER_ASSERT(reporter, assign.getSourcePath() == original.getSourcePath()
); | 156 REPORTER_ASSERT(reporter, assign.getSourcePath() == original.getSourcePath()
); |
158 | 157 |
159 // Test swap. Increment both generation IDs, swap source paths. | 158 // Test swap. Swap the generation IDs, swap source paths. |
| 159 copy.reset(); |
| 160 copy.moveTo(2, 2); |
160 copy.setSourcePath(&anotherSource); | 161 copy.setSourcePath(&anotherSource); |
161 copyID = copy.getGenerationID(); | 162 copyID = copy.getGenerationID(); |
| 163 assign.moveTo(3, 3); |
162 assignID = assign.getGenerationID(); | 164 assignID = assign.getGenerationID(); |
163 copy.swap(assign); | 165 copy.swap(assign); |
164 REPORTER_ASSERT(reporter, copy.getGenerationID() > copyID); | 166 REPORTER_ASSERT(reporter, copy.getGenerationID() != copyID); |
165 REPORTER_ASSERT(reporter, assign.getGenerationID() > assignID); | 167 REPORTER_ASSERT(reporter, assign.getGenerationID() != assignID); |
166 REPORTER_ASSERT(reporter, copy.getSourcePath() == original.getSourcePath()); | 168 REPORTER_ASSERT(reporter, copy.getSourcePath() == original.getSourcePath()); |
167 REPORTER_ASSERT(reporter, assign.getSourcePath() == &anotherSource); | 169 REPORTER_ASSERT(reporter, assign.getSourcePath() == &anotherSource); |
168 #endif | 170 #endif |
169 } | 171 } |
170 | 172 |
| 173 static void test_gen_id(skiatest::Reporter* reporter) { |
| 174 SkPath a, b; |
| 175 REPORTER_ASSERT(reporter, a.getGenerationID() == b.getGenerationID()); |
| 176 |
| 177 a.moveTo(0, 0); |
| 178 const uint32_t z = a.getGenerationID(); |
| 179 REPORTER_ASSERT(reporter, z != b.getGenerationID()); |
| 180 |
| 181 a.reset(); |
| 182 REPORTER_ASSERT(reporter, a.getGenerationID() == b.getGenerationID()); |
| 183 |
| 184 a.moveTo(1, 1); |
| 185 const uint32_t y = a.getGenerationID(); |
| 186 REPORTER_ASSERT(reporter, z != y); |
| 187 |
| 188 b.moveTo(2, 2); |
| 189 const uint32_t x = b.getGenerationID(); |
| 190 REPORTER_ASSERT(reporter, x != y && x != z); |
| 191 |
| 192 a.swap(b); |
| 193 REPORTER_ASSERT(reporter, b.getGenerationID() == y && a.getGenerationID() ==
x); |
| 194 |
| 195 b = a; |
| 196 REPORTER_ASSERT(reporter, b.getGenerationID() == x); |
| 197 |
| 198 SkPath c(a); |
| 199 REPORTER_ASSERT(reporter, c.getGenerationID() == x); |
| 200 |
| 201 c.lineTo(3, 3); |
| 202 const uint32_t w = c.getGenerationID(); |
| 203 REPORTER_ASSERT(reporter, b.getGenerationID() == x); |
| 204 REPORTER_ASSERT(reporter, a.getGenerationID() == x); |
| 205 REPORTER_ASSERT(reporter, w != x); |
| 206 |
| 207 #ifdef SK_BUILD_FOR_ANDROID |
| 208 static bool kExpectGenIDToIgnoreFill = false; |
| 209 #else |
| 210 static bool kExpectGenIDToIgnoreFill = true; |
| 211 #endif |
| 212 |
| 213 c.toggleInverseFillType(); |
| 214 const uint32_t v = c.getGenerationID(); |
| 215 REPORTER_ASSERT(reporter, (v == w) == kExpectGenIDToIgnoreFill); |
| 216 |
| 217 c.rewind(); |
| 218 REPORTER_ASSERT(reporter, v != c.getGenerationID()); |
| 219 } |
| 220 |
171 // This used to assert in the debug build, as the edges did not all line-up. | 221 // This used to assert in the debug build, as the edges did not all line-up. |
172 static void test_bad_cubic_crbug234190() { | 222 static void test_bad_cubic_crbug234190() { |
173 SkPath path; | 223 SkPath path; |
174 path.moveTo(13.8509f, 3.16858f); | 224 path.moveTo(13.8509f, 3.16858f); |
175 path.cubicTo(-2.35893e+08f, -4.21044e+08f, | 225 path.cubicTo(-2.35893e+08f, -4.21044e+08f, |
176 -2.38991e+08f, -4.26573e+08f, | 226 -2.38991e+08f, -4.26573e+08f, |
177 -2.41016e+08f, -4.30188e+08f); | 227 -2.41016e+08f, -4.30188e+08f); |
178 | 228 |
179 SkPaint paint; | 229 SkPaint paint; |
180 paint.setAntiAlias(true); | 230 paint.setAntiAlias(true); |
(...skipping 2432 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2613 test_isfinite_after_transform(reporter); | 2663 test_isfinite_after_transform(reporter); |
2614 test_arb_round_rect_is_convex(reporter); | 2664 test_arb_round_rect_is_convex(reporter); |
2615 test_arb_zero_rad_round_rect_is_rect(reporter); | 2665 test_arb_zero_rad_round_rect_is_rect(reporter); |
2616 test_addrect_isfinite(reporter); | 2666 test_addrect_isfinite(reporter); |
2617 test_tricky_cubic(); | 2667 test_tricky_cubic(); |
2618 test_clipped_cubic(); | 2668 test_clipped_cubic(); |
2619 test_crbug_170666(); | 2669 test_crbug_170666(); |
2620 test_bad_cubic_crbug229478(); | 2670 test_bad_cubic_crbug229478(); |
2621 test_bad_cubic_crbug234190(); | 2671 test_bad_cubic_crbug234190(); |
2622 test_android_specific_behavior(reporter); | 2672 test_android_specific_behavior(reporter); |
| 2673 test_gen_id(reporter); |
2623 test_path_close_issue1474(reporter); | 2674 test_path_close_issue1474(reporter); |
2624 test_path_to_region(reporter); | 2675 test_path_to_region(reporter); |
2625 } | 2676 } |
2626 | 2677 |
2627 #include "TestClassDef.h" | 2678 #include "TestClassDef.h" |
2628 DEFINE_TESTCLASS("Path", PathTestClass, TestPath) | 2679 DEFINE_TESTCLASS("Path", PathTestClass, TestPath) |
OLD | NEW |