Bug 1068881 - Inflate the dest rect to at least one device pixel when computing the optimal image size for drawing. r=roc, a=bajaj
authorSeth Fowler <seth@mozilla.com>
Thu, 26 Mar 2015 15:34:20 -0700
changeset 238289 b2c2ceb1152b5fce51a8331a7f2e2d6486357a6d
parent 238288 8fbdb08d1cef8a77cf8a46ee58c92b65cff4c03d
child 238290 8b83dbe19870386257f6c88e19defa6718510912
push id553
push userryanvm@gmail.com
push dateFri, 01 May 2015 01:40:09 +0000
treeherdermozilla-b2g37_v2_2@5fd55bc7cad8 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersroc, bajaj
bugs1068881
milestone37.0
Bug 1068881 - Inflate the dest rect to at least one device pixel when computing the optimal image size for drawing. r=roc, a=bajaj
layout/base/nsLayoutUtils.cpp
--- a/layout/base/nsLayoutUtils.cpp
+++ b/layout/base/nsLayoutUtils.cpp
@@ -5743,28 +5743,35 @@ ComputeSnappedImageDrawingParameters(gfx
     if (fill.IsEmpty()) {
       return SnappedImageDrawingParameters();
     }
   } else {
     didSnap = false;
     fill = devPixelFill;
   }
 
+  // Apply the context's scale to the dest rect.
   gfxSize destScale = didSnap ? gfxSize(currentMatrix._11, currentMatrix._22)
                               : gfxSize(1.0, 1.0);
   gfxSize appUnitScaledDest(dest.width * destScale.width,
                             dest.height * destScale.height);
   gfxSize scaledDest = appUnitScaledDest / aAppUnitsPerDevPixel;
+  if (scaledDest.IsEmpty()) {
+    return SnappedImageDrawingParameters();
+  }
+
+  // Compute a snapped version of the scaled dest rect, which we'll use to
+  // determine the optimal image size to draw with. We need to be sure that
+  // this rect is at least one pixel in width and height, or we'll end up
+  // drawing nothing even if we have a nonempty fill.
   gfxSize snappedScaledDest =
     gfxSize(NSAppUnitsToIntPixels(appUnitScaledDest.width, aAppUnitsPerDevPixel),
             NSAppUnitsToIntPixels(appUnitScaledDest.height, aAppUnitsPerDevPixel));
-
-  if (scaledDest.IsEmpty() || snappedScaledDest.IsEmpty()) {
-    return SnappedImageDrawingParameters();
-  }
+  snappedScaledDest.width = std::max(snappedScaledDest.width, 1.0);
+  snappedScaledDest.height = std::max(snappedScaledDest.height, 1.0);
 
   nsIntSize intImageSize =
     aImage->OptimalImageSizeForDest(snappedScaledDest,
                                     imgIContainer::FRAME_CURRENT,
                                     aGraphicsFilter, aImageFlags);
   gfxSize imageSize(intImageSize.width, intImageSize.height);
 
   nsIntSize svgViewportSize = currentMatrix.IsIdentity()