Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(832)

Side by Side Diff: tests/GrShapeTest.cpp

Issue 2085913003: Canonicalize path fill types for stroked paths in GrShape. (Closed) Base URL: https://chromium.googlesource.com/skia.git@canonicalize_paths
Patch Set: minor cleanup Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« src/gpu/GrShape.cpp ('K') | « src/gpu/GrShape.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2016 Google Inc. 2 * Copyright 2016 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 <initializer_list> 8 #include <initializer_list>
9 #include <functional> 9 #include <functional>
10 #include "Test.h" 10 #include "Test.h"
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after
292 // Having a dash path effect can allow 'a' but not 'b' to turn a inverse fil l type into a 292 // Having a dash path effect can allow 'a' but not 'b' to turn a inverse fil l type into a
293 // non-inverse fill type (or vice versa). 293 // non-inverse fill type (or vice versa).
294 bool ignoreInversenessDifference = false; 294 bool ignoreInversenessDifference = false;
295 if (pathA.isInverseFillType() != pathB.isInverseFillType()) { 295 if (pathA.isInverseFillType() != pathB.isInverseFillType()) {
296 const GrShape* s1 = pathA.isInverseFillType() ? &a : &b; 296 const GrShape* s1 = pathA.isInverseFillType() ? &a : &b;
297 const GrShape* s2 = pathA.isInverseFillType() ? &b : &a; 297 const GrShape* s2 = pathA.isInverseFillType() ? &b : &a;
298 bool canDropInverse1 = s1->style().isDashed(); 298 bool canDropInverse1 = s1->style().isDashed();
299 bool canDropInverse2 = s2->style().isDashed(); 299 bool canDropInverse2 = s2->style().isDashed();
300 ignoreInversenessDifference = (canDropInverse1 != canDropInverse2); 300 ignoreInversenessDifference = (canDropInverse1 != canDropInverse2);
301 } 301 }
302 302 bool ignoreWindingVsEvenOdd = false;
303 if (SkPath::ConvertToNonInverseFillType(pathA.getFillType()) !=
304 SkPath::ConvertToNonInverseFillType(pathB.getFillType())) {
305 const SkStrokeRec::Style strokeRecStyleA = a.style().strokeRec().getSty le();
306 const SkStrokeRec::Style strokeRecStyleB = b.style().strokeRec().getSty le();
robertphillips 2016/06/23 18:47:54 add a "static bool can_change(const GrStyle, const
307 bool aCanChange = !a.style().hasNonDashPathEffect() &&
308 (strokeRecStyleA == SkStrokeRec::kStroke_Style ||
309 strokeRecStyleA == SkStrokeRec::kHairline_Style ||
310 (a.style().isSimpleFill() && pathA.isConvex()));
311 bool bCanChange = !b.style().hasNonDashPathEffect() &&
312 (strokeRecStyleB == SkStrokeRec::kStroke_Style ||
313 strokeRecStyleB == SkStrokeRec::kHairline_Style ||
314 (b.style().isSimpleFill() && pathB.isConvex()));
315 if (aCanChange != bCanChange) {
316 ignoreWindingVsEvenOdd = true;
317 }
318 }
303 if (allowSameRRectButDiffStartAndDir) { 319 if (allowSameRRectButDiffStartAndDir) {
304 REPORTER_ASSERT(r, rrectA == rrectB); 320 REPORTER_ASSERT(r, rrectA == rrectB);
305 REPORTER_ASSERT(r, paths_fill_same(pathA, pathB)); 321 REPORTER_ASSERT(r, paths_fill_same(pathA, pathB));
306 REPORTER_ASSERT(r, ignoreInversenessDifference || invertedA == invertedB ); 322 REPORTER_ASSERT(r, ignoreInversenessDifference || invertedA == invertedB );
307 } else { 323 } else {
308 SkPath pA = pathA; 324 SkPath pA = pathA;
309 SkPath pB = pathB; 325 SkPath pB = pathB;
310 if (ignoreInversenessDifference) { 326 if (ignoreInversenessDifference) {
311 pA.setFillType(SkPath::ConvertToNonInverseFillType(pathA.getFillType ())); 327 pA.setFillType(SkPath::ConvertToNonInverseFillType(pathA.getFillType ()));
312 pB.setFillType(SkPath::ConvertToNonInverseFillType(pathB.getFillType ())); 328 pB.setFillType(SkPath::ConvertToNonInverseFillType(pathB.getFillType ()));
329 }
330 if (ignoreWindingVsEvenOdd) {
331 pA.setFillType(pA.isInverseFillType() ? SkPath::kInverseEvenOdd_Fill Type
332 : SkPath::kEvenOdd_FillType);
333 pB.setFillType(pB.isInverseFillType() ? SkPath::kInverseEvenOdd_Fill Type
334 : SkPath::kEvenOdd_FillType);
335 }
336 if (!ignoreInversenessDifference && !ignoreWindingVsEvenOdd) {
337 REPORTER_ASSERT(r, keyA == keyB);
338 } else {
313 REPORTER_ASSERT(r, keyA != keyB); 339 REPORTER_ASSERT(r, keyA != keyB);
314 } else {
315 REPORTER_ASSERT(r, keyA == keyB);
316 } 340 }
317 if (a.style().isSimpleFill() != b.style().isSimpleFill()) { 341 if (a.style().isSimpleFill() != b.style().isSimpleFill()) {
318 // GrShape will close paths with simple fill style. Make the non-fil led path closed 342 // GrShape will close paths with simple fill style. Make the non-fil led path closed
319 // so that the comparision will succeed. Make sure both are closed b efore comparing. 343 // so that the comparision will succeed. Make sure both are closed b efore comparing.
320 pA.close(); 344 pA.close();
321 pB.close(); 345 pB.close();
322 } 346 }
323 REPORTER_ASSERT(r, pA == pB); 347 REPORTER_ASSERT(r, pA == pB);
324 REPORTER_ASSERT(r, aIsRRect == bIsRRect); 348 REPORTER_ASSERT(r, aIsRRect == bIsRRect);
325 if (aIsRRect) { 349 if (aIsRRect) {
(...skipping 509 matching lines...) Expand 10 before | Expand all | Expand 10 after
835 peCase.appliedPathEffectShape().asPath(&b); 859 peCase.appliedPathEffectShape().asPath(&b);
836 peCase.appliedFullStyleShape().asPath(&c); 860 peCase.appliedFullStyleShape().asPath(&c);
837 if (isNonPath) { 861 if (isNonPath) {
838 // RRect types can have a change in start index or direction after the P E is applied. This 862 // RRect types can have a change in start index or direction after the P E is applied. This
839 // is because once the PE is applied, GrShape may canonicalize the dir a nd index since it 863 // is because once the PE is applied, GrShape may canonicalize the dir a nd index since it
840 // is not germane to the styling any longer. 864 // is not germane to the styling any longer.
841 // Instead we just check that the paths would fill the same both before and after styling. 865 // Instead we just check that the paths would fill the same both before and after styling.
842 REPORTER_ASSERT(reporter, paths_fill_same(a, b)); 866 REPORTER_ASSERT(reporter, paths_fill_same(a, b));
843 REPORTER_ASSERT(reporter, paths_fill_same(a, c)); 867 REPORTER_ASSERT(reporter, paths_fill_same(a, c));
844 } else { 868 } else {
869 // The base shape cannot perform canonicalization on the path's fill typ e because of an
870 // unknown path effect. However, after the path effect is applied the re sulting hairline
871 // shape will canonicalize the path fill type since hairlines (and strok ing in general)
872 // don't distinguish between even/odd and non-zero winding.
873 a.setFillType(b.getFillType());
845 REPORTER_ASSERT(reporter, a == b); 874 REPORTER_ASSERT(reporter, a == b);
846 REPORTER_ASSERT(reporter, a == c); 875 REPORTER_ASSERT(reporter, a == c);
847 REPORTER_ASSERT(reporter, peCase.appliedPathEffectKey().empty()); 876 REPORTER_ASSERT(reporter, peCase.appliedPathEffectKey().empty());
848 REPORTER_ASSERT(reporter, peCase.appliedFullStyleKey().empty()); 877 REPORTER_ASSERT(reporter, peCase.appliedFullStyleKey().empty());
849 } 878 }
850 REPORTER_ASSERT(reporter, peCase.appliedPathEffectShape().style().isSimpleHa irline()); 879 REPORTER_ASSERT(reporter, peCase.appliedPathEffectShape().style().isSimpleHa irline());
851 REPORTER_ASSERT(reporter, peCase.appliedFullStyleShape().style().isSimpleHai rline()); 880 REPORTER_ASSERT(reporter, peCase.appliedFullStyleShape().style().isSimpleHai rline());
852 } 881 }
853 882
854 /** 883 /**
(...skipping 611 matching lines...) Expand 10 before | Expand all | Expand 10 after
1466 REPORTER_ASSERT(reporter, testPath.fIsLine == strokePathCase.baseShape() .asLine(nullptr)); 1495 REPORTER_ASSERT(reporter, testPath.fIsLine == strokePathCase.baseShape() .asLine(nullptr));
1467 } 1496 }
1468 1497
1469 // Test a volatile empty path. 1498 // Test a volatile empty path.
1470 test_volatile_path(reporter, SkPath(), true); 1499 test_volatile_path(reporter, SkPath(), true);
1471 1500
1472 test_empty_shape(reporter); 1501 test_empty_shape(reporter);
1473 } 1502 }
1474 1503
1475 #endif 1504 #endif
OLDNEW
« src/gpu/GrShape.cpp ('K') | « src/gpu/GrShape.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698