Bug 933057 - Part 1: Correct scaling of SVG images in nsLayoutUtils::DrawSingleImage. r=dholbert, a=lsblakk
authorSeth Fowler <seth@mozilla.com>
Fri, 08 Nov 2013 15:14:53 -0800
changeset 166535 6600291b61b096f8ad9e48eec0632b91420b6733
parent 166534 d37821195af4a78674e0d36538dc1bd28c490260
child 166536 ebe9766a0fb6bd7856d4c8537f1bfcbaa8a8a5a2
push id3066
push userakeybl@mozilla.com
push dateMon, 09 Dec 2013 19:58:46 +0000
treeherdermozilla-beta@a31a0dce83aa [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdholbert, lsblakk
bugs933057
milestone27.0a2
Bug 933057 - Part 1: Correct scaling of SVG images in nsLayoutUtils::DrawSingleImage. r=dholbert, a=lsblakk
layout/base/nsLayoutUtils.cpp
layout/svg/nsSVGImageFrame.cpp
--- a/layout/base/nsLayoutUtils.cpp
+++ b/layout/base/nsLayoutUtils.cpp
@@ -4299,19 +4299,24 @@ nsLayoutUtils::DrawSingleImage(nsRenderi
                                const nsRect&          aDest,
                                const nsRect&          aDirty,
                                const SVGImageContext* aSVGContext,
                                uint32_t               aImageFlags,
                                const nsRect*          aSourceArea)
 {
   nsIntSize imageSize;
   if (aImage->GetType() == imgIContainer::TYPE_VECTOR) {
-    imageSize.width  = nsPresContext::AppUnitsToIntCSSPixels(aDest.width);
-    imageSize.height = nsPresContext::AppUnitsToIntCSSPixels(aDest.height);
+    // We choose a size for vector images that emulates a raster image which
+    // is perfectly sized for the destination rect: each pixel in the image
+    // maps exactly to a single pixel on-screen.
+    nscoord appUnitsPerDevPx = aRenderingContext->AppUnitsPerDevPixel();
+    imageSize.width = NSAppUnitsToIntPixels(aDest.width, appUnitsPerDevPx);
+    imageSize.height = NSAppUnitsToIntPixels(aDest.height, appUnitsPerDevPx);
   } else {
+    // Raster images have an intrinsic size, so we just use that.
     aImage->GetWidth(&imageSize.width);
     aImage->GetHeight(&imageSize.height);
   }
   NS_ENSURE_TRUE(imageSize.width > 0 && imageSize.height > 0, NS_ERROR_FAILURE);
 
   nsRect source;
   if (aSourceArea) {
     source = *aSourceArea;
--- a/layout/svg/nsSVGImageFrame.cpp
+++ b/layout/svg/nsSVGImageFrame.cpp
@@ -268,29 +268,29 @@ nsSVGImageFrame::TransformContextForPain
     if (NS_FAILED(mImageContainer->GetWidth(&nativeWidth)) ||
         NS_FAILED(mImageContainer->GetHeight(&nativeHeight)) ||
         nativeWidth == 0 || nativeHeight == 0) {
       return false;
     }
     imageTransform =
       GetRasterImageTransform(nativeWidth, nativeHeight, FOR_PAINTING,
                               aTransformRoot);
+
+    // NOTE: We need to cancel out the effects of Full-Page-Zoom, or else
+    // it'll get applied an extra time by DrawSingleUnscaledImage.
+    nscoord appUnitsPerDevPx = PresContext()->AppUnitsPerDevPixel();
+    gfxFloat pageZoomFactor =
+      nsPresContext::AppUnitsToFloatCSSPixels(appUnitsPerDevPx);
+    imageTransform.Scale(pageZoomFactor, pageZoomFactor);
   }
 
   if (imageTransform.IsSingular()) {
     return false;
   }
 
-  // NOTE: We need to cancel out the effects of Full-Page-Zoom, or else
-  // it'll get applied an extra time by DrawSingleUnscaledImage.
-  nscoord appUnitsPerDevPx = PresContext()->AppUnitsPerDevPixel();
-  gfxFloat pageZoomFactor =
-    nsPresContext::AppUnitsToFloatCSSPixels(appUnitsPerDevPx);
-  imageTransform.Scale(pageZoomFactor, pageZoomFactor);
-
   aGfxContext->Multiply(imageTransform);
   return true;
 }
 
 //----------------------------------------------------------------------
 // nsISVGChildFrame methods:
 NS_IMETHODIMP
 nsSVGImageFrame::PaintSVG(nsRenderingContext *aContext,