From b24a5d67c86460ad161344730d062e79c95c3d31 Mon Sep 17 00:00:00 2001 From: Daniel Holbert Date: Wed, 8 Sep 2010 13:40:39 -0700 Subject: [PATCH] Bug 276431 Patch 5: Move two nsSVGUtils methods to header file so they can be inlined in non-gklayout code. r=roc a=blocking --- layout/svg/base/src/nsSVGUtils.cpp | 23 -------------------- layout/svg/base/src/nsSVGUtils.h | 35 ++++++++++++++++++++++++++++-- 2 files changed, 33 insertions(+), 25 deletions(-) diff --git a/layout/svg/base/src/nsSVGUtils.cpp b/layout/svg/base/src/nsSVGUtils.cpp index 2f2c962cc09..f05be60176c 100644 --- a/layout/svg/base/src/nsSVGUtils.cpp +++ b/layout/svg/base/src/nsSVGUtils.cpp @@ -1181,29 +1181,6 @@ nsSVGUtils::ToAppPixelRect(nsPresContext *aPresContext, const gfxRect& rect) aPresContext->DevPixelsToAppUnits(NSToIntCeil(rect.YMost()) - NSToIntFloor(rect.Y()))); } -static PRInt32 -ClampToInt(double aVal) -{ - return NS_lround(NS_MAX(double(PR_INT32_MIN), NS_MIN(double(PR_INT32_MAX), aVal))); -} - -gfxIntSize -nsSVGUtils::ConvertToSurfaceSize(const gfxSize& aSize, PRBool *aResultOverflows) -{ - gfxIntSize surfaceSize(ClampToInt(aSize.width), ClampToInt(aSize.height)); - - *aResultOverflows = surfaceSize.width != NS_round(aSize.width) || - surfaceSize.height != NS_round(aSize.height); - - if (!gfxASurface::CheckSurfaceSize(surfaceSize)) { - surfaceSize.width = NS_MIN(NS_SVG_OFFSCREEN_MAX_DIMENSION, surfaceSize.width); - surfaceSize.height = NS_MIN(NS_SVG_OFFSCREEN_MAX_DIMENSION, surfaceSize.height); - *aResultOverflows = PR_TRUE; - } - - return surfaceSize; -} - gfxMatrix nsSVGUtils::ConvertSVGMatrixToThebes(nsIDOMSVGMatrix *aMatrix) { diff --git a/layout/svg/base/src/nsSVGUtils.h b/layout/svg/base/src/nsSVGUtils.h index 547e25114a8..aab1a77ec0f 100644 --- a/layout/svg/base/src/nsSVGUtils.h +++ b/layout/svg/base/src/nsSVGUtils.h @@ -426,12 +426,33 @@ public: * Convert a surface size to an integer for use by thebes * possibly making it smaller in the process so the surface does not * use excessive memory. + * + * XXXdholbert Putting impl in header file so that imagelib can call this + * method. Once we switch to a libxul-only world, this can go back into + * the .cpp file. + * * @param aSize the desired surface size * @param aResultOverflows true if the desired surface size is too big * @return the surface size to use */ - static gfxIntSize - ConvertToSurfaceSize(const gfxSize& aSize, PRBool *aResultOverflows); + static gfxIntSize ConvertToSurfaceSize(const gfxSize& aSize, + PRBool *aResultOverflows) + { + gfxIntSize surfaceSize(ClampToInt(aSize.width), ClampToInt(aSize.height)); + + *aResultOverflows = surfaceSize.width != NS_round(aSize.width) || + surfaceSize.height != NS_round(aSize.height); + + if (!gfxASurface::CheckSurfaceSize(surfaceSize)) { + surfaceSize.width = NS_MIN(NS_SVG_OFFSCREEN_MAX_DIMENSION, + surfaceSize.width); + surfaceSize.height = NS_MIN(NS_SVG_OFFSCREEN_MAX_DIMENSION, + surfaceSize.height); + *aResultOverflows = PR_TRUE; + } + + return surfaceSize; + } /* * Convert a nsIDOMSVGMatrix to a gfxMatrix. @@ -563,6 +584,16 @@ public: static PRBool NumberFromString(const nsAString& aString, float* aValue, PRBool aAllowPercentages = PR_FALSE); + /** + * Convert a floating-point value to a 32-bit integer value, clamping to + * the range of valid integers. + */ + static PRInt32 ClampToInt(double aVal) + { + return NS_lround(NS_MAX(double(PR_INT32_MIN), + NS_MIN(double(PR_INT32_MAX), aVal))); + } + private: /* Computational (nil) surfaces */ static gfxASurface *gThebesComputationalSurface;