Fix image filters for PDF backend.

Currently, the PDF backend does not support image filters (since PDF
does not have that functionality), so it simply removes them. This is
causing Chrome print preview to render incorrectly (see bug). The fix
here is to fall back to a raster device for image filters, as we used
to do in Blink. The resulting bitmap will be drawn to the destination
device as a normal main-memory-backed bitmap.

Note: this change invalidates the PDF results of all GMs containing
image filters (since they'll actually be rendered).

BUG=422144

Review URL: https://codereview.chromium.org/644323006
diff --git a/tests/PDFPrimitivesTest.cpp b/tests/PDFPrimitivesTest.cpp
index b1d482f..05677cd 100644
--- a/tests/PDFPrimitivesTest.cpp
+++ b/tests/PDFPrimitivesTest.cpp
@@ -15,6 +15,7 @@
 #include "SkPDFDevice.h"
 #include "SkPDFStream.h"
 #include "SkPDFTypes.h"
+#include "SkReadBuffer.h"
 #include "SkScalar.h"
 #include "SkStream.h"
 #include "SkTypes.h"
@@ -428,3 +429,54 @@
 
     TestImages(reporter);
 }
+
+namespace {
+
+class DummyImageFilter : public SkImageFilter {
+public:
+    DummyImageFilter(bool visited = false) : SkImageFilter(0, NULL), fVisited(visited) {}
+    virtual ~DummyImageFilter() SK_OVERRIDE {}
+    virtual bool onFilterImage(Proxy*, const SkBitmap& src, const Context&,
+                               SkBitmap* result, SkIPoint* offset) const {
+        fVisited = true;
+        offset->fX = offset->fY = 0;
+        *result = src;
+        return true;
+    }
+    SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(DummyImageFilter)
+#ifdef SK_SUPPORT_LEGACY_DEEPFLATTENING
+    explicit DummyImageFilter(SkReadBuffer& buffer) : SkImageFilter(0, NULL) {
+        fVisited = buffer.readBool();
+    }
+#endif
+    bool visited() const { return fVisited; }
+
+private:
+    mutable bool fVisited;
+};
+
+SkFlattenable* DummyImageFilter::CreateProc(SkReadBuffer& buffer) {
+    SK_IMAGEFILTER_UNFLATTEN_COMMON(common, 0);
+    bool visited = buffer.readBool();
+    return SkNEW_ARGS(DummyImageFilter, (visited));
+}
+
+};
+
+// Check that PDF rendering of image filters successfully falls back to
+// CPU rasterization.
+DEF_TEST(PDFImageFilter, reporter) {
+    SkISize pageSize = SkISize::Make(100, 100);
+    SkAutoTUnref<SkPDFDevice> device(new SkPDFDevice(pageSize, pageSize, SkMatrix::I()));
+    SkCanvas canvas(device.get());
+    SkAutoTUnref<DummyImageFilter> filter(new DummyImageFilter());
+
+    // Filter just created; should be unvisited.
+    REPORTER_ASSERT(reporter, !filter->visited());
+    SkPaint paint;
+    paint.setImageFilter(filter.get());
+    canvas.drawRect(SkRect::MakeWH(100, 100), paint);
+
+    // Filter was used in rendering; should be visited.
+    REPORTER_ASSERT(reporter, filter->visited());
+}