diff --git a/content/svg/content/src/nsSVGFilters.cpp b/content/svg/content/src/nsSVGFilters.cpp index 1415fc0de11f..c9edc01271c6 100644 --- a/content/svg/content/src/nsSVGFilters.cpp +++ b/content/svg/content/src/nsSVGFilters.cpp @@ -175,7 +175,7 @@ nsSVGFE::SetupScalingFilter(nsSVGFilterInstance *aInstance, r.Scale(scaledSize.width/aTarget->mImage->Width(), scaledSize.height/aTarget->mImage->Height()); r.RoundOut(); - if (NS_FAILED(nsSVGUtils::GfxRectToIntRect(r, &result.mDataRect))) + if (NS_FAILED(nsLayoutUtils::GfxRectToIntRect(r, &result.mDataRect))) return result; #ifdef DEBUG_tor @@ -2908,7 +2908,7 @@ nsSVGFETileElement::Filter(nsSVGFilterInstance *instance, // but nothing clips mFilterPrimitiveSubregion so this should be changed. nsIntRect tile; - nsresult res = nsSVGUtils::GfxRectToIntRect(aSources[0]->mFilterPrimitiveSubregion, &tile); + nsresult res = nsLayoutUtils::GfxRectToIntRect(aSources[0]->mFilterPrimitiveSubregion, &tile); NS_ENSURE_SUCCESS(res, res); // asserts on failure (not if (tile.IsEmpty()) diff --git a/layout/base/nsLayoutUtils.cpp b/layout/base/nsLayoutUtils.cpp index be3af44ac551..0dca3438ce45 100644 --- a/layout/base/nsLayoutUtils.cpp +++ b/layout/base/nsLayoutUtils.cpp @@ -892,6 +892,15 @@ nsLayoutUtils::InvertTransformsToRoot(nsIFrame *aFrame, return MatrixTransformPoint(aPoint, ctm.Invert(), aFrame->PresContext()->AppUnitsPerDevPixel()); } +nsresult +nsLayoutUtils::GfxRectToIntRect(const gfxRect& aIn, nsIntRect* aOut) +{ + *aOut = nsIntRect(PRInt32(aIn.X()), PRInt32(aIn.Y()), + PRInt32(aIn.Width()), PRInt32(aIn.Height())); + return gfxRect(aOut->x, aOut->y, aOut->width, aOut->height) == aIn + ? NS_OK : NS_ERROR_FAILURE; +} + static nsIntPoint GetWidgetOffset(nsIWidget* aWidget, nsIWidget*& aRootWidget) { nsIntPoint offset(0, 0); nsIWidget* parent = aWidget->GetParent(); diff --git a/layout/base/nsLayoutUtils.h b/layout/base/nsLayoutUtils.h index 5c08fbb61f8e..c550943578f5 100644 --- a/layout/base/nsLayoutUtils.h +++ b/layout/base/nsLayoutUtils.h @@ -474,6 +474,12 @@ public: */ static nsRect RoundGfxRectToAppRect(const gfxRect &aRect, float aFactor); + /** + * If aIn can be represented exactly using an nsIntRect (i.e. + * integer-aligned edges and coordinates in the PRInt32 range) then we + * set aOut to that rectangle, otherwise return failure. + */ + static nsresult GfxRectToIntRect(const gfxRect& aIn, nsIntRect* aOut); enum { PAINT_IN_TRANSFORM = 0x01, diff --git a/layout/svg/base/src/nsSVGFilterFrame.cpp b/layout/svg/base/src/nsSVGFilterFrame.cpp index f3ea3bb352e4..a75ac5d97f9d 100644 --- a/layout/svg/base/src/nsSVGFilterFrame.cpp +++ b/layout/svg/base/src/nsSVGFilterFrame.cpp @@ -67,7 +67,7 @@ MapDeviceRectToFilterSpace(const gfxMatrix& aMatrix, aDeviceRect->width, aDeviceRect->height)); r.RoundOut(); nsIntRect intRect; - if (NS_SUCCEEDED(nsSVGUtils::GfxRectToIntRect(r, &intRect))) { + if (NS_SUCCEEDED(nsLayoutUtils::GfxRectToIntRect(r, &intRect))) { rect = intRect; } } @@ -236,7 +236,7 @@ TransformFilterSpaceToDeviceSpace(nsSVGFilterInstance *aInstance, nsIntRect *aRe r = m.TransformBounds(r); r.RoundOut(); nsIntRect deviceRect; - nsresult rv = nsSVGUtils::GfxRectToIntRect(r, &deviceRect); + nsresult rv = nsLayoutUtils::GfxRectToIntRect(r, &deviceRect); if (NS_FAILED(rv)) return rv; *aRect = deviceRect; diff --git a/layout/svg/base/src/nsSVGFilterInstance.cpp b/layout/svg/base/src/nsSVGFilterInstance.cpp index ced89cddc445..d3400ca6685f 100644 --- a/layout/svg/base/src/nsSVGFilterInstance.cpp +++ b/layout/svg/base/src/nsSVGFilterInstance.cpp @@ -40,6 +40,7 @@ #include "gfxPlatform.h" #include "nsSVGFilterPaintCallback.h" #include "nsSVGFilterElement.h" +#include "nsLayoutUtils.h" static double Square(double aX) { @@ -164,7 +165,7 @@ nsSVGFilterInstance::BuildSources() gfxRect sourceBounds = UserSpaceToFilterSpace(mTargetBBox); sourceBounds.RoundOut(); // Detect possible float->int overflow - if (NS_FAILED(nsSVGUtils::GfxRectToIntRect(sourceBounds, &sourceBoundsInt))) + if (NS_FAILED(nsLayoutUtils::GfxRectToIntRect(sourceBounds, &sourceBoundsInt))) return NS_ERROR_FAILURE; mSourceColorAlpha.mResultBoundingBox = sourceBoundsInt; @@ -355,7 +356,7 @@ nsSVGFilterInstance::BuildSourceImages() r = m.TransformBounds(r); r.RoundOut(); nsIntRect dirty; - nsresult rv = nsSVGUtils::GfxRectToIntRect(r, &dirty); + nsresult rv = nsLayoutUtils::GfxRectToIntRect(r, &dirty); if (NS_FAILED(rv)) return rv; diff --git a/layout/svg/base/src/nsSVGUtils.cpp b/layout/svg/base/src/nsSVGUtils.cpp index 94b8aefdc383..86d7919ce9da 100644 --- a/layout/svg/base/src/nsSVGUtils.cpp +++ b/layout/svg/base/src/nsSVGUtils.cpp @@ -635,7 +635,7 @@ nsSVGUtils::FindFilterInvalidation(nsIFrame *aFrame, const nsRect& aRect) TransformBounds(gfxRect(x, y, width, height)); bounds.RoundOut(); nsIntRect r; - if (NS_SUCCEEDED(nsSVGUtils::GfxRectToIntRect(bounds, &r))) { + if (NS_SUCCEEDED(nsLayoutUtils::GfxRectToIntRect(bounds, &r))) { rect = r; } else { NS_NOTREACHED("Not going to invalidate the correct area"); @@ -953,7 +953,7 @@ public: gfxRect dirtyBounds = userToDeviceSpace.TransformBounds( gfxRect(aDirtyRect->x, aDirtyRect->y, aDirtyRect->width, aDirtyRect->height)); dirtyBounds.RoundOut(); - if (NS_SUCCEEDED(nsSVGUtils::GfxRectToIntRect(dirtyBounds, &tmpDirtyRect))) { + if (NS_SUCCEEDED(nsLayoutUtils::GfxRectToIntRect(dirtyBounds, &tmpDirtyRect))) { dirtyRect = &tmpDirtyRect; } } @@ -1347,15 +1347,6 @@ nsSVGUtils::ClipToGfxRect(nsIntRect* aRect, const gfxRect& aGfxRect) PRInt32(r.Width()), PRInt32(r.Height())); } -nsresult -nsSVGUtils::GfxRectToIntRect(const gfxRect& aIn, nsIntRect* aOut) -{ - *aOut = nsIntRect(PRInt32(aIn.X()), PRInt32(aIn.Y()), - PRInt32(aIn.Width()), PRInt32(aIn.Height())); - return gfxRect(aOut->x, aOut->y, aOut->width, aOut->height) == aIn - ? NS_OK : NS_ERROR_FAILURE; -} - gfxRect nsSVGUtils::GetBBox(nsIFrame *aFrame) { diff --git a/layout/svg/base/src/nsSVGUtils.h b/layout/svg/base/src/nsSVGUtils.h index 4e627a01471e..a609c40350b1 100644 --- a/layout/svg/base/src/nsSVGUtils.h +++ b/layout/svg/base/src/nsSVGUtils.h @@ -452,13 +452,6 @@ public: const gfxMatrix &aCTM, const gfxRect &aRect); - /** - * If aIn can be represented exactly using an nsIntRect (i.e. integer-aligned edges and - * coordinates in the PRInt32 range) then we set aOut to that rectangle, otherwise - * return failure. - */ - static nsresult GfxRectToIntRect(const gfxRect& aIn, nsIntRect* aOut); - /** * Restricts aRect to pixels that intersect aGfxRect. */