Fix SkPicture path bound optimization to handle inverse filled paths.
authorjunov@chromium.org <junov@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>
Tue, 7 May 2013 13:26:18 +0000 (13:26 +0000)
committerjunov@chromium.org <junov@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>
Tue, 7 May 2013 13:26:18 +0000 (13:26 +0000)
BUG=crbug.com/229011
TEST=Picture unit test

Review URL: https://codereview.chromium.org/14819008

git-svn-id: http://skia.googlecode.com/svn/trunk@9031 2bbb7eff-a529-9590-31e7-b0007b416f81

src/core/SkPictureRecord.cpp
tests/PictureTest.cpp

index 375bf426629d390ea3951179c3d87a5e59746fbb..c8386438c5d8b2234eb31241b433372686d70364 100644 (file)
@@ -783,7 +783,11 @@ bool SkPictureRecord::clipPath(const SkPath& path, SkRegion::Op op, bool doAA) {
     validate(initialOffset, size);
 
     if (fRecordFlags & SkPicture::kUsePathBoundsForClip_RecordingFlag) {
-        return this->INHERITED::clipRect(path.getBounds(), op, doAA);
+        if (path.isInverseFillType()) {
+            return this->getClipDeviceBounds(NULL);
+        } else {
+            return this->INHERITED::clipRect(path.getBounds(), op, doAA);
+        }
     } else {
         return this->INHERITED::clipPath(path, op, doAA);
     }
index c702e9426ed82bc8746dc4d11b1873449706d2cb..c92f11cfcffc1b60a2066dcde4590f7aff01c7c1 100644 (file)
@@ -449,6 +449,26 @@ static void test_clone_empty(skiatest::Reporter* reporter) {
     }
 }
 
+static void test_inverse_fill_clip_opt(skiatest::Reporter* reporter) {
+    // Regression test for crbug.com/229011
+    SkPicture picture;
+    SkCanvas* canvas = picture.beginRecording(10, 10,
+        SkPicture::kUsePathBoundsForClip_RecordingFlag);
+    SkRect rect = SkRect::MakeXYWH(SkIntToScalar(4), SkIntToScalar(4),
+                                   SkIntToScalar(2), SkIntToScalar(2));
+    SkPath path;
+    path.addRect(rect);
+    path.setFillType(SkPath::kInverseEvenOdd_FillType);
+    canvas->clipPath(path);
+    SkIRect clipBounds;
+    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);
+}
+
 static void TestPicture(skiatest::Reporter* reporter) {
 #ifdef SK_DEBUG
     test_deleting_empty_playback();
@@ -460,6 +480,7 @@ static void TestPicture(skiatest::Reporter* reporter) {
     test_gatherpixelrefs(reporter);
     test_bitmap_with_encoded_data(reporter);
     test_clone_empty(reporter);
+    test_inverse_fill_clip_opt(reporter);
 }
 
 #include "TestClassDef.h"