Bug 276431 Patch 5: Move two nsSVGUtils methods to header file so they can be inlined in non-gklayout code. r=roc a=blocking
authorDaniel Holbert <dholbert@cs.stanford.edu>
Wed, 08 Sep 2010 13:40:39 -0700
changeset 52210 827cba9e267131c49c6f497ef725a77e9c67729f
parent 52209 58df4c112b6d34ed869b04630a03412e82e85246
child 52211 9711d082d0ed574c9cfe1e3cf0dd5f7247cb0262
push id15573
push userdholbert@mozilla.com
push dateWed, 08 Sep 2010 20:57:52 +0000
treeherdermozilla-central@ec53c1b41f3c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersroc, blocking
bugs276431
milestone2.0b6pre
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
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
layout/svg/base/src/nsSVGUtils.h
--- a/layout/svg/base/src/nsSVGUtils.cpp
+++ b/layout/svg/base/src/nsSVGUtils.cpp
@@ -1176,39 +1176,16 @@ nsRect
 nsSVGUtils::ToAppPixelRect(nsPresContext *aPresContext, const gfxRect& rect)
 {
   return nsRect(aPresContext->DevPixelsToAppUnits(NSToIntFloor(rect.X())),
                 aPresContext->DevPixelsToAppUnits(NSToIntFloor(rect.Y())),
                 aPresContext->DevPixelsToAppUnits(NSToIntCeil(rect.XMost()) - NSToIntFloor(rect.X())),
                 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)
 {
   if (!aMatrix) {
     return gfxMatrix();
   }
   float A, B, C, D, E, F;
   aMatrix->GetA(&A);
--- a/layout/svg/base/src/nsSVGUtils.h
+++ b/layout/svg/base/src/nsSVGUtils.h
@@ -421,22 +421,43 @@ public:
                  double xmin, double ymin, double xmax, double ymax);
   static nsRect
   ToAppPixelRect(nsPresContext *aPresContext, const gfxRect& rect);
 
   /*
    * 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.
    */
   static gfxMatrix
   ConvertSVGMatrixToThebes(nsIDOMSVGMatrix *aMatrix);
 
   /*
@@ -558,14 +579,24 @@ public:
    * number as a float.
    *
    * This helper returns PR_TRUE if a number was successfully parsed from the
    * string and no characters were left, else it returns PR_FALSE.
    */
   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;
 };
 
 #endif