From 9c015b9b38a466c3e9ad8a9d90d7a983a6a8f900 Mon Sep 17 00:00:00 2001 From: "Robert O'Callahan ext:(.)" Date: Sat, 17 Sep 2011 09:29:51 +0100 Subject: [PATCH] Bug 647687 - Fix filter SourceImage bounds. r=longsonr --- layout/reftests/svg/filter-bounds-01.svg | 24 ++++++++++++++++++++ layout/reftests/svg/filter-bounds-02.svg | 25 +++++++++++++++++++++ layout/reftests/svg/reftest.list | 2 ++ layout/svg/base/src/nsSVGFilterFrame.cpp | 10 ++++++++- layout/svg/base/src/nsSVGFilterInstance.cpp | 1 + layout/svg/base/src/nsSVGFilterInstance.h | 4 ++++ 6 files changed, 65 insertions(+), 1 deletion(-) create mode 100644 layout/reftests/svg/filter-bounds-01.svg create mode 100644 layout/reftests/svg/filter-bounds-02.svg diff --git a/layout/reftests/svg/filter-bounds-01.svg b/layout/reftests/svg/filter-bounds-01.svg new file mode 100644 index 00000000000..17bfeb60c1e --- /dev/null +++ b/layout/reftests/svg/filter-bounds-01.svg @@ -0,0 +1,24 @@ + + + + Testcase for checking that filter bounds include stroke width + + + + + + + + + + + + + + + diff --git a/layout/reftests/svg/filter-bounds-02.svg b/layout/reftests/svg/filter-bounds-02.svg new file mode 100644 index 00000000000..d9c0d474c9c --- /dev/null +++ b/layout/reftests/svg/filter-bounds-02.svg @@ -0,0 +1,25 @@ + + + + Testcase for checking that filter bounds include stroke width + + + + + + + + + + + + + + + + diff --git a/layout/reftests/svg/reftest.list b/layout/reftests/svg/reftest.list index 2a424a1e858..e7c4c3b46c9 100644 --- a/layout/reftests/svg/reftest.list +++ b/layout/reftests/svg/reftest.list @@ -111,6 +111,8 @@ random == dynamic-use-nested-01.svg dynamic-use-nested-01-ref.svg # bug 467498 == filter-basic-01.svg pass.svg == filter-basic-02.svg pass.svg == filter-basic-03.svg pass.svg +== filter-bounds-01.svg pass.svg +== filter-bounds-02.svg pass.svg == filter-foreignObject-01.svg pass.svg == filter-invalidation-01.svg pass.svg == filter-scaled-01.svg pass.svg diff --git a/layout/svg/base/src/nsSVGFilterFrame.cpp b/layout/svg/base/src/nsSVGFilterFrame.cpp index 214b3bd80e5..4d0efabff20 100644 --- a/layout/svg/base/src/nsSVGFilterFrame.cpp +++ b/layout/svg/base/src/nsSVGFilterFrame.cpp @@ -206,11 +206,19 @@ nsAutoFilterInstance::nsAutoFilterInstance(nsIFrame *aTarget, MapDeviceRectToFilterSpace(deviceToFilterSpace, filterRes, aDirtyOutputRect); nsIntRect dirtyInputRect = MapDeviceRectToFilterSpace(deviceToFilterSpace, filterRes, aDirtyInputRect); + nsIntRect targetBoundsDeviceSpace; + nsISVGChildFrame* svgTarget = do_QueryFrame(aTarget); + if (svgTarget) { + targetBoundsDeviceSpace.UnionRect(targetBoundsDeviceSpace, + svgTarget->GetCoveredRegion().ToOutsidePixels(aTarget->PresContext()->AppUnitsPerDevPixel())); + } + nsIntRect targetBoundsFilterSpace = + MapDeviceRectToFilterSpace(deviceToFilterSpace, filterRes, &targetBoundsDeviceSpace); // Setup instance data mInstance = new nsSVGFilterInstance(aTarget, aPaint, filter, bbox, filterRegion, nsIntSize(filterRes.width, filterRes.height), - filterToDeviceSpace, + filterToDeviceSpace, targetBoundsFilterSpace, dirtyOutputRect, dirtyInputRect, primitiveUnits); } diff --git a/layout/svg/base/src/nsSVGFilterInstance.cpp b/layout/svg/base/src/nsSVGFilterInstance.cpp index 84477da69ba..c91af0b5a4f 100644 --- a/layout/svg/base/src/nsSVGFilterInstance.cpp +++ b/layout/svg/base/src/nsSVGFilterInstance.cpp @@ -189,6 +189,7 @@ nsSVGFilterInstance::BuildSources() // Detect possible float->int overflow if (!gfxUtils::GfxRectToIntRect(sourceBounds, &sourceBoundsInt)) return NS_ERROR_FAILURE; + sourceBoundsInt.UnionRect(sourceBoundsInt, mTargetBounds); mSourceColorAlpha.mResultBoundingBox = sourceBoundsInt; mSourceAlpha.mResultBoundingBox = sourceBoundsInt; diff --git a/layout/svg/base/src/nsSVGFilterInstance.h b/layout/svg/base/src/nsSVGFilterInstance.h index b45708f6305..2d80d837672 100644 --- a/layout/svg/base/src/nsSVGFilterInstance.h +++ b/layout/svg/base/src/nsSVGFilterInstance.h @@ -70,6 +70,7 @@ public: const gfxRect& aFilterRect, const nsIntSize& aFilterSpaceSize, const gfxMatrix &aFilterSpaceToDeviceSpaceTransform, + const nsIntRect& aTargetBounds, const nsIntRect& aDirtyOutputRect, const nsIntRect& aDirtyInputRect, PRUint16 aPrimitiveUnits) : @@ -80,6 +81,7 @@ public: mFilterSpaceToDeviceSpaceTransform(aFilterSpaceToDeviceSpaceTransform), mFilterRect(aFilterRect), mFilterSpaceSize(aFilterSpaceSize), + mTargetBounds(aTargetBounds), mDirtyOutputRect(aDirtyOutputRect), mDirtyInputRect(aDirtyInputRect), mSurfaceRect(nsIntPoint(0, 0), aFilterSpaceSize), @@ -209,6 +211,8 @@ private: gfxMatrix mFilterSpaceToDeviceSpaceTransform; gfxRect mFilterRect; nsIntSize mFilterSpaceSize; + // Filter-space bounds of the target image (SourceAlpha/SourceGraphic) + nsIntRect mTargetBounds; nsIntRect mDirtyOutputRect; nsIntRect mDirtyInputRect; nsIntRect mSurfaceRect;