aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/PDFPrimitivesTest.cpp
diff options
context:
space:
mode:
authorGravatar senorblanco <senorblanco@chromium.org>2014-10-20 14:03:12 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2014-10-20 14:03:13 -0700
commitb0e89dcc1d8c1c2f9f7ffb45e8609cdb4a68104b (patch)
tree1661cc79e593b0225c6224664d08ad192c5b2902 /tests/PDFPrimitivesTest.cpp
parent1d932663e12dc5f56a66bb764c9f36eb3bab9502 (diff)
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
Diffstat (limited to 'tests/PDFPrimitivesTest.cpp')
-rw-r--r--tests/PDFPrimitivesTest.cpp52
1 files changed, 52 insertions, 0 deletions
diff --git a/tests/PDFPrimitivesTest.cpp b/tests/PDFPrimitivesTest.cpp
index b1d482ffa2..05677cd1ab 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 @@ DEF_TEST(PDFPrimitives, reporter) {
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());
+}