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

Unified Diff: tests/ClipStackTest.cpp

Issue 2175493002: Fix SkClipStack bug with inverse-filled difference elements (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/core/SkClipStack.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/ClipStackTest.cpp
diff --git a/tests/ClipStackTest.cpp b/tests/ClipStackTest.cpp
index 27753c44f4011187c6289a9f10477e55a7a7efa8..4d375ee8bcc41fd8a6a344d8088b3f8033147afd 100644
--- a/tests/ClipStackTest.cpp
+++ b/tests/ClipStackTest.cpp
@@ -794,6 +794,51 @@ static void test_quickContains(skiatest::Reporter* reporter) {
}
}
+static void set_region_to_stack(const SkClipStack& stack, const SkIRect& bounds, SkRegion* region) {
+ region->setRect(bounds);
+ SkClipStack::Iter iter(stack, SkClipStack::Iter::kBottom_IterStart);
+ while (const SkClipStack::Element *element = iter.next()) {
+ SkRegion elemRegion;
+ SkRegion boundsRgn(bounds);
+ SkPath path;
+
+ switch (element->getType()) {
+ case SkClipStack::Element::kEmpty_Type:
+ elemRegion.setEmpty();
+ break;
+ default:
+ element->asPath(&path);
+ elemRegion.setPath(path, boundsRgn);
+ break;
+ }
+ region->op(elemRegion, element->getOp());
+ }
+}
+
+static void test_invfill_diff_bug(skiatest::Reporter* reporter) {
+ SkClipStack stack;
+ stack.clipDevRect({10, 10, 20, 20}, SkRegion::kIntersect_Op, false);
+
+ SkPath path;
+ path.addRect({30, 10, 40, 20});
+ path.setFillType(SkPath::kInverseWinding_FillType);
+ stack.clipDevPath(path, SkRegion::kDifference_Op, false);
+
+ REPORTER_ASSERT(reporter, SkClipStack::kEmptyGenID == stack.getTopmostGenID());
+
+ SkRect stackBounds;
+ SkClipStack::BoundsType stackBoundsType;
+ stack.getBounds(&stackBounds, &stackBoundsType);
+
+ REPORTER_ASSERT(reporter, stackBounds.isEmpty());
+ REPORTER_ASSERT(reporter, SkClipStack::kNormal_BoundsType == stackBoundsType);
+
+ SkRegion region;
+ set_region_to_stack(stack, {0, 0, 50, 30}, &region);
+
+ REPORTER_ASSERT(reporter, region.isEmpty());
+}
+
///////////////////////////////////////////////////////////////////////////////////////////////////
#if SK_SUPPORT_GPU
@@ -859,25 +904,6 @@ static void add_elem_to_stack(const SkClipStack::Element& element, SkClipStack*
}
}
-static void add_elem_to_region(const SkClipStack::Element& element,
- const SkIRect& bounds,
- SkRegion* region) {
- SkRegion elemRegion;
- SkRegion boundsRgn(bounds);
- SkPath path;
-
- switch (element.getType()) {
- case SkClipStack::Element::kEmpty_Type:
- elemRegion.setEmpty();
- break;
- default:
- element.asPath(&path);
- elemRegion.setPath(path, boundsRgn);
- break;
- }
- region->op(elemRegion, element.getOp());
-}
-
static void test_reduced_clip_stack(skiatest::Reporter* reporter) {
// We construct random clip stacks, reduce them, and then rasterize both versions to verify that
// they are equal.
@@ -991,20 +1017,11 @@ static void test_reduced_clip_stack(skiatest::Reporter* reporter) {
// convert both the original stack and reduced stack to SkRegions and see if they're equal
SkRegion region;
- SkRegion reducedRegion;
+ set_region_to_stack(stack, inflatedIBounds, &region);
- region.setRect(inflatedIBounds);
- const SkClipStack::Element* element;
- SkClipStack::Iter iter(stack, SkClipStack::Iter::kBottom_IterStart);
- while ((element = iter.next())) {
- add_elem_to_region(*element, inflatedIBounds, &region);
- }
+ SkRegion reducedRegion;
+ set_region_to_stack(reducedStack, inflatedIBounds, &reducedRegion);
- reducedRegion.setRect(inflatedIBounds);
- iter.reset(reducedStack, SkClipStack::Iter::kBottom_IterStart);
- while ((element = iter.next())) {
- add_elem_to_region(*element, inflatedIBounds, &reducedRegion);
- }
SkString testCase;
testCase.printf("Iteration %d", i);
REPORTER_ASSERT_MESSAGE(reporter, region == reducedRegion, testCase.c_str());
@@ -1204,6 +1221,7 @@ DEF_TEST(ClipStack, reporter) {
test_rect_inverse_fill(reporter);
test_path_replace(reporter);
test_quickContains(reporter);
+ test_invfill_diff_bug(reporter);
#if SK_SUPPORT_GPU
test_reduced_clip_stack(reporter);
test_reduced_clip_stack_genid(reporter);
« no previous file with comments | « src/core/SkClipStack.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698