Bug 1274692 - skip CG image height limitation check draft
authorCJKu <cku@mozilla.com>
Tue, 31 May 2016 00:48:18 +0800
changeset 372927 481b1c001f7df0a005e7095b12d11439c9ca87fe
parent 372909 3435dd7ad71fe9003bdeee18fd38d815e033beef
child 522286 3cbc298b25fa136e0ce9746757babaaab1ebd6f6
push id19637
push usercku@mozilla.com
push dateMon, 30 May 2016 16:48:42 +0000
bugs1274692
milestone49.0a1
Bug 1274692 - skip CG image height limitation check MozReview-Commit-ID: L24JWDB9aQj
gfx/thebes/gfxASurface.cpp
gfx/thebes/gfxASurface.h
layout/svg/nsSVGUtils.cpp
layout/svg/nsSVGUtils.h
--- a/gfx/thebes/gfxASurface.cpp
+++ b/gfx/thebes/gfxASurface.cpp
@@ -375,33 +375,34 @@ gfxASurface::CairoStatus()
     if (!mSurfaceValid)
         return -1;
 
     return cairo_surface_status(mSurface);
 }
 
 /* static */
 bool
-gfxASurface::CheckSurfaceSize(const IntSize& sz, int32_t limit)
+gfxASurface::CheckSurfaceSize(const IntSize& sz, int32_t limit,
+                              bool aCheckPlatfromLimitation)
 {
     if (sz.width < 0 || sz.height < 0) {
         NS_WARNING("Surface width or height < 0!");
         return false;
     }
 
     // reject images with sides bigger than limit
     if (limit && (sz.width > limit || sz.height > limit)) {
         NS_WARNING("Surface size too large (exceeds caller's limit)!");
         return false;
     }
 
 #if defined(XP_MACOSX)
     // CoreGraphics is limited to images < 32K in *height*,
     // so clamp all surfaces on the Mac to that height
-    if (sz.height > SHRT_MAX) {
+    if (aCheckPlatfromLimitation && sz.height > SHRT_MAX) {
         NS_WARNING("Surface size too large (exceeds CoreGraphics limit)!");
         return false;
     }
 #endif
 
     // make sure the surface area doesn't overflow a int32_t
     CheckedInt<int32_t> tmp = sz.width;
     tmp *= sz.height;
--- a/gfx/thebes/gfxASurface.h
+++ b/gfx/thebes/gfxASurface.h
@@ -113,17 +113,17 @@ public:
     already_AddRefed<gfxImageSurface> CopyToARGB32ImageSurface();
 
     int CairoStatus();
 
     /* Make sure that the given dimensions don't overflow a 32-bit signed int
      * using 4 bytes per pixel; optionally, make sure that either dimension
      * doesn't exceed the given limit.
      */
-    static bool CheckSurfaceSize(const mozilla::gfx::IntSize& sz, int32_t limit = 0);
+    static bool CheckSurfaceSize(const mozilla::gfx::IntSize& sz, int32_t limit = 0, bool aCheckPlatfromLimitation = true);
 
     /* Provide a stride value that will respect all alignment requirements of
      * the accelerated image-rendering code.
      */
     static int32_t FormatStrideForWidth(gfxImageFormat format, int32_t width);
 
     static gfxContentType ContentFromFormat(gfxImageFormat format);
 
--- a/layout/svg/nsSVGUtils.cpp
+++ b/layout/svg/nsSVGUtils.cpp
@@ -840,24 +840,25 @@ nsSVGUtils::TransformFrameRectToOuterSVG
   gfxRect r(aRect.x, aRect.y, aRect.width, aRect.height);
   r.Scale(1.0 / nsPresContext::AppUnitsPerCSSPixel());
   return nsLayoutUtils::RoundGfxRectToAppRect(
     aMatrix.TransformBounds(r), aPresContext->AppUnitsPerDevPixel());
 }
 
 IntSize
 nsSVGUtils::ConvertToSurfaceSize(const gfxSize& aSize,
-                                 bool *aResultOverflows)
+                                 bool *aResultOverflows,
+                                 bool aCheckPlatfromLimitation)
 {
   IntSize surfaceSize(ClampToInt(ceil(aSize.width)), ClampToInt(ceil(aSize.height)));
 
   *aResultOverflows = surfaceSize.width != ceil(aSize.width) ||
     surfaceSize.height != ceil(aSize.height);
 
-  if (!gfxASurface::CheckSurfaceSize(surfaceSize)) {
+  if (!gfxASurface::CheckSurfaceSize(surfaceSize, 0, aCheckPlatfromLimitation)) {
     surfaceSize.width = std::min(NS_SVG_OFFSCREEN_MAX_DIMENSION,
                                surfaceSize.width);
     surfaceSize.height = std::min(NS_SVG_OFFSCREEN_MAX_DIMENSION,
                                 surfaceSize.height);
     *aResultOverflows = true;
   }
 
   return surfaceSize;
--- a/layout/svg/nsSVGUtils.h
+++ b/layout/svg/nsSVGUtils.h
@@ -339,20 +339,22 @@ 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.
    *
    * @param aSize the desired surface size
    * @param aResultOverflows true if the desired surface size is too big
+   * @param aCheckPlatfromLimitation true if need to check platform image size
    * @return the surface size to use
    */
   static mozilla::gfx::IntSize ConvertToSurfaceSize(const gfxSize& aSize,
-                                                    bool *aResultOverflows);
+                                                    bool *aResultOverflows,
+                                                    bool aCheckPlatfromLimitation = false);
 
   /*
    * Hit test a given rectangle/matrix.
    */
   static bool
   HitTestRect(const mozilla::gfx::Matrix &aMatrix,
               float aRX, float aRY, float aRWidth, float aRHeight,
               float aX, float aY);