Index: tests/PictureTest.cpp |
=================================================================== |
--- tests/PictureTest.cpp (revision 9033) |
+++ tests/PictureTest.cpp (working copy) |
@@ -449,6 +449,105 @@ |
} |
} |
+static void test_clip_bound_opt(skiatest::Reporter* reporter) { |
+ // Test for crbug.com/229011 |
+ SkRect rect1 = SkRect::MakeXYWH(SkIntToScalar(4), SkIntToScalar(4), |
+ SkIntToScalar(2), SkIntToScalar(2)); |
+ SkRect rect2 = SkRect::MakeXYWH(SkIntToScalar(7), SkIntToScalar(7), |
+ SkIntToScalar(1), SkIntToScalar(1)); |
+ SkRect rect3 = SkRect::MakeXYWH(SkIntToScalar(6), SkIntToScalar(6), |
+ SkIntToScalar(1), SkIntToScalar(1)); |
+ |
+ SkPath invPath; |
+ invPath.addOval(rect1); |
+ invPath.setFillType(SkPath::kInverseEvenOdd_FillType); |
+ SkPath path; |
+ path.addOval(rect2); |
+ SkPath path2; |
+ path2.addOval(rect3); |
+ SkIRect clipBounds; |
+ // Minimalist test set for 100% code coverage of |
+ // SkPictureRecord::updateClipConservativelyUsingBounds |
+ { |
+ SkPicture picture; |
+ SkCanvas* canvas = picture.beginRecording(10, 10, |
+ SkPicture::kUsePathBoundsForClip_RecordingFlag); |
+ canvas->clipPath(invPath, SkRegion::kIntersect_Op); |
+ bool nonEmpty = canvas->getClipDeviceBounds(&clipBounds); |
+ REPORTER_ASSERT(reporter, true == nonEmpty); |
+ REPORTER_ASSERT(reporter, 0 == clipBounds.fLeft); |
+ REPORTER_ASSERT(reporter, 0 == clipBounds.fTop); |
+ REPORTER_ASSERT(reporter, 10 == clipBounds.fBottom); |
+ REPORTER_ASSERT(reporter, 10 == clipBounds.fRight); |
+ } |
+ { |
+ SkPicture picture; |
+ SkCanvas* canvas = picture.beginRecording(10, 10, |
+ SkPicture::kUsePathBoundsForClip_RecordingFlag); |
+ canvas->clipPath(path, SkRegion::kIntersect_Op); |
+ canvas->clipPath(invPath, SkRegion::kIntersect_Op); |
+ bool nonEmpty = canvas->getClipDeviceBounds(&clipBounds); |
+ REPORTER_ASSERT(reporter, true == nonEmpty); |
+ REPORTER_ASSERT(reporter, 7 == clipBounds.fLeft); |
+ REPORTER_ASSERT(reporter, 7 == clipBounds.fTop); |
+ REPORTER_ASSERT(reporter, 8 == clipBounds.fBottom); |
+ REPORTER_ASSERT(reporter, 8 == clipBounds.fRight); |
+ } |
+ { |
+ SkPicture picture; |
+ SkCanvas* canvas = picture.beginRecording(10, 10, |
+ SkPicture::kUsePathBoundsForClip_RecordingFlag); |
+ canvas->clipPath(path, SkRegion::kIntersect_Op); |
+ canvas->clipPath(invPath, SkRegion::kUnion_Op); |
+ bool nonEmpty = canvas->getClipDeviceBounds(&clipBounds); |
+ REPORTER_ASSERT(reporter, true == nonEmpty); |
+ REPORTER_ASSERT(reporter, 0 == clipBounds.fLeft); |
+ REPORTER_ASSERT(reporter, 0 == clipBounds.fTop); |
+ REPORTER_ASSERT(reporter, 10 == clipBounds.fBottom); |
+ REPORTER_ASSERT(reporter, 10 == clipBounds.fRight); |
+ } |
+ { |
+ SkPicture picture; |
+ SkCanvas* canvas = picture.beginRecording(10, 10, |
+ SkPicture::kUsePathBoundsForClip_RecordingFlag); |
+ canvas->clipPath(path, SkRegion::kDifference_Op); |
+ bool nonEmpty = canvas->getClipDeviceBounds(&clipBounds); |
+ REPORTER_ASSERT(reporter, true == nonEmpty); |
+ REPORTER_ASSERT(reporter, 0 == clipBounds.fLeft); |
+ REPORTER_ASSERT(reporter, 0 == clipBounds.fTop); |
+ REPORTER_ASSERT(reporter, 10 == clipBounds.fBottom); |
+ REPORTER_ASSERT(reporter, 10 == clipBounds.fRight); |
+ } |
+ { |
+ SkPicture picture; |
+ SkCanvas* canvas = picture.beginRecording(10, 10, |
+ SkPicture::kUsePathBoundsForClip_RecordingFlag); |
+ canvas->clipPath(path, SkRegion::kReverseDifference_Op); |
+ bool nonEmpty = canvas->getClipDeviceBounds(&clipBounds); |
+ // True clip is actually empty in this case, but the best |
+ // determination we can make using only bounds as input is that the |
+ // clip is included in the bounds of 'path'. |
+ REPORTER_ASSERT(reporter, true == nonEmpty); |
+ REPORTER_ASSERT(reporter, 7 == clipBounds.fLeft); |
+ REPORTER_ASSERT(reporter, 7 == clipBounds.fTop); |
+ REPORTER_ASSERT(reporter, 8 == clipBounds.fBottom); |
+ REPORTER_ASSERT(reporter, 8 == clipBounds.fRight); |
+ } |
+ { |
+ SkPicture picture; |
+ SkCanvas* canvas = picture.beginRecording(10, 10, |
+ SkPicture::kUsePathBoundsForClip_RecordingFlag); |
+ canvas->clipPath(path, SkRegion::kIntersect_Op); |
+ canvas->clipPath(path2, SkRegion::kXOR_Op); |
+ bool nonEmpty = canvas->getClipDeviceBounds(&clipBounds); |
+ REPORTER_ASSERT(reporter, true == nonEmpty); |
+ REPORTER_ASSERT(reporter, 6 == clipBounds.fLeft); |
+ REPORTER_ASSERT(reporter, 6 == clipBounds.fTop); |
+ REPORTER_ASSERT(reporter, 8 == clipBounds.fBottom); |
+ REPORTER_ASSERT(reporter, 8 == clipBounds.fRight); |
+ } |
+} |
+ |
static void TestPicture(skiatest::Reporter* reporter) { |
#ifdef SK_DEBUG |
test_deleting_empty_playback(); |
@@ -460,6 +559,7 @@ |
test_gatherpixelrefs(reporter); |
test_bitmap_with_encoded_data(reporter); |
test_clone_empty(reporter); |
+ test_clip_bound_opt(reporter); |
} |
#include "TestClassDef.h" |