Bug 1290782 - Force using image size as SVG's viewport size when drawing the border and the SVG doesn't have fixed ratio. r?dholbert draft
authorLouis Chang <lochang@mozilla.com>
Tue, 22 Aug 2017 11:23:34 +0800
changeset 650255 9d7a201f571bc8da606956ac14be424e4d61f620
parent 649622 7dddbd85047c6dc73ddbe1e423cd643a217845b3
child 727337 2fa107b79cf45b6e68535bf5f9f09f130095d5cb
push id75311
push userlochang@mozilla.com
push dateTue, 22 Aug 2017 03:29:39 +0000
reviewersdholbert
bugs1290782
milestone57.0a1
Bug 1290782 - Force using image size as SVG's viewport size when drawing the border and the SVG doesn't have fixed ratio. r?dholbert MozReview-Commit-ID: 4w3tEkVAMWd
layout/base/nsLayoutUtils.cpp
layout/reftests/border-image/reftest.list
layout/reftests/border-image/svg-as-border-image-4.html
layout/reftests/border-image/svg-as-border-image-4a.html
layout/reftests/border-image/svg-as-border-image-4b.html
--- a/layout/base/nsLayoutUtils.cpp
+++ b/layout/base/nsLayoutUtils.cpp
@@ -6542,17 +6542,22 @@ ComputeSnappedImageDrawingParameters(gfx
 
   nsIntSize intImageSize =
     aImage->OptimalImageSizeForDest(snappedDestSize,
                                     imgIContainer::FRAME_CURRENT,
                                     aSamplingFilter, aImageFlags);
   gfxSize imageSize(intImageSize.width, intImageSize.height);
 
   // XXX(seth): May be buggy; see bug 1151016.
-  CSSIntSize svgViewportSize = currentMatrix.IsIdentity()
+  // For images with FLAG_FORCE_UNIFORM_SCALING, the ratio of the viewport size
+  // should not be changed. Therefore, the svgViewportSize in that case is
+  // assigned to an uniformly-scaled size from OptimalImageSizeForDest.
+  CSSIntSize svgViewportSize =
+    (currentMatrix.IsIdentity() ||
+    (aImageFlags & imgIContainer::FLAG_FORCE_UNIFORM_SCALING))
     ? CSSIntSize(intImageSize.width, intImageSize.height)
     : CSSIntSize::Truncate(devPixelDest.width, devPixelDest.height);
 
   // Compute the set of pixels that would be sampled by an ideal rendering
   gfxPoint subimageTopLeft =
     MapToFloatImagePixels(imageSize, devPixelDest, devPixelFill.TopLeft());
   gfxPoint subimageBottomRight =
     MapToFloatImagePixels(imageSize, devPixelDest, devPixelFill.BottomRight());
--- a/layout/reftests/border-image/reftest.list
+++ b/layout/reftests/border-image/reftest.list
@@ -82,11 +82,12 @@ fuzzy(1,1054) fails-if(OSX) fuzzy-if(ski
 
 # border-image-source (-moz-)element
 fuzzy(125,5808) == border-image-element.html border-image-element-ref.html
 
 # svg-as-border-image
 == svg-as-border-image-1a.html svg-as-border-image-1-ref.html
 == svg-as-border-image-1b.html svg-as-border-image-1-ref.html
 == svg-as-border-image-1c.html svg-as-border-image-1-ref.html
-fails-if(webrender) == svg-as-border-image-2.html svg-as-border-image-2-ref.html # see bug 1151016. The svg viewport size may be wrong
+== svg-as-border-image-2.html svg-as-border-image-2-ref.html
 == svg-as-border-image-3.html svg-as-border-image-3-ref.html
-== svg-as-border-image-4.html svg-as-border-image-4-ref.html
+== svg-as-border-image-4a.html svg-as-border-image-4-ref.html
+fuzzy(2,2) == svg-as-border-image-4b.html svg-as-border-image-4-ref.html
rename from layout/reftests/border-image/svg-as-border-image-4.html
rename to layout/reftests/border-image/svg-as-border-image-4a.html
new file mode 100644
--- /dev/null
+++ b/layout/reftests/border-image/svg-as-border-image-4b.html
@@ -0,0 +1,19 @@
+<html>
+<head>
+<title>test of svg-as-border-image</title>
+<style type="text/css">
+div {
+  width: 100px;
+  height: 100px;
+  margin: 30px;
+  border-width: 30px;
+  border-style: solid;
+  border-image: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg"><circle cx="50%" cy="50%" r="50%" fill="red"/></svg>') 5% stretch;
+  will-change: opacity;
+}
+</style>
+</head>
+<body>
+<div></div>
+</body>
+</html>