Require explicit disabling of cross process pictureimagefilters
authorrobertphillips <robertphillips@google.com>
Tue, 6 Jan 2015 17:17:02 +0000 (09:17 -0800)
committerCommit bot <commit-bot@chromium.org>
Tue, 6 Jan 2015 17:17:02 +0000 (09:17 -0800)
This is to allow capturing .skp files with their pictureimagefilters intact.

This is a companion to https://codereview.chromium.org/810933004/ (Provide a way of allowing cross process pictureimagefilters).

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

src/effects/SkPictureImageFilter.cpp
tests/ImageFilterTest.cpp

index 37d86ce..391af11 100644 (file)
@@ -39,12 +39,15 @@ SkFlattenable* SkPictureImageFilter::CreateProc(SkReadBuffer& buffer) {
     SkAutoTUnref<SkPicture> picture;
     SkRect cropRect;
 
-    if (!buffer.isCrossProcess()) {
+#ifdef SK_DISALLOW_CROSSPROCESS_PICTUREIMAGEFILTERS
+    if (buffer.isCrossProcess()) {
+        buffer.validate(!buffer.readBool());
+    } else 
+#endif
+    {
         if (buffer.readBool()) {
             picture.reset(SkPicture::CreateFromBuffer(buffer));
         }
-    } else {
-        buffer.validate(!buffer.readBool());
     }
     buffer.readRect(&cropRect);
     PictureResolution pictureResolution;
@@ -68,14 +71,17 @@ SkFlattenable* SkPictureImageFilter::CreateProc(SkReadBuffer& buffer) {
 }
 
 void SkPictureImageFilter::flatten(SkWriteBuffer& buffer) const {
-    if (!buffer.isCrossProcess()) {
+#ifdef SK_DISALLOW_CROSSPROCESS_PICTUREIMAGEFILTERS
+    if (buffer.isCrossProcess()) {
+        buffer.writeBool(false);
+    } else 
+#endif
+    {
         bool hasPicture = (fPicture != NULL);
         buffer.writeBool(hasPicture);
         if (hasPicture) {
             fPicture->flatten(buffer);
         }
-    } else {
-        buffer.writeBool(false);
     }
     buffer.writeRect(fCropRect);
     buffer.writeInt(fPictureResolution);
index b673836..add9e23 100644 (file)
@@ -802,8 +802,12 @@ DEF_TEST(ImageFilterCrossProcessPictureImageFilter, reporter) {
     canvas.clear(0x0);
     canvas.drawPicture(crossProcessPicture);
     pixel = *bitmap.getAddr32(0, 0);
+#ifdef SK_DISALLOW_CROSSPROCESS_PICTUREIMAGEFILTERS
     // The result here should not be green, since the filter draws nothing.
     REPORTER_ASSERT(reporter, pixel != SK_ColorGREEN);
+#else
+    REPORTER_ASSERT(reporter, pixel == SK_ColorGREEN);
+#endif
 }
 
 DEF_TEST(ImageFilterClippedPictureImageFilter, reporter) {