Bug 1355570 - Respect aSrc when building WebRender gradients r?mattwoodrow draft
authorRyan Hunt <rhunt@eqrion.net>
Tue, 11 Apr 2017 14:30:33 -0400
changeset 560654 b99fec9dd9042618c66da3e9b26b70a5f2c8ebcf
parent 560653 8e94071eadf839ec765fb1d52c5bb4db83fa9d42
child 623771 1e18debdab54e2ad4c9574f6642fb51922fb0b63
push id53497
push userbmo:rhunt@eqrion.net
push dateTue, 11 Apr 2017 18:52:32 +0000
reviewersmattwoodrow
bugs1355570
milestone55.0a1
Bug 1355570 - Respect aSrc when building WebRender gradients r?mattwoodrow MozReview-Commit-ID: 6YfNRGYnHcK
layout/painting/nsCSSRenderingGradients.cpp
--- a/layout/painting/nsCSSRenderingGradients.cpp
+++ b/layout/painting/nsCSSRenderingGradients.cpp
@@ -1061,27 +1061,43 @@ nsCSSGradientRenderer::BuildWebRenderDis
   // Calculate the tile spacing, which is the repeat size minus the tile size
   LayoutDeviceSize tileSpacing = tileRepeat - firstTileBounds.Size();
 
   // Make the rects relative to the parent stacking context
   clipBounds = LayoutDeviceRect::FromUnknownRect(aLayer->RelativeToParent(clipBounds.ToUnknownRect()));
   firstTileBounds = LayoutDeviceRect::FromUnknownRect(aLayer->RelativeToParent(firstTileBounds.ToUnknownRect()));
   gradientBounds = LayoutDeviceRect::FromUnknownRect(aLayer->RelativeToParent(gradientBounds.ToUnknownRect()));
 
+  // srcTransform is used for scaling the gradient to match aSrc
+  LayoutDeviceRect srcTransform = LayoutDeviceRect(mPresContext->CSSPixelsToAppUnits(aSrc.x),
+                                                   mPresContext->CSSPixelsToAppUnits(aSrc.y),
+                                                   aDest.width / ((float)mPresContext->CSSPixelsToAppUnits(aSrc.width)),
+                                                   aDest.height / ((float)mPresContext->CSSPixelsToAppUnits(aSrc.height)));
+
   if (mGradient->mShape == NS_STYLE_GRADIENT_SHAPE_LINEAR) {
+    lineStart.x = (lineStart.x - srcTransform.x) * srcTransform.width;
+    lineStart.y = (lineStart.y - srcTransform.y) * srcTransform.height;
+    lineEnd.x = (lineEnd.x - srcTransform.x) * srcTransform.width;
+    lineEnd.y = (lineEnd.y - srcTransform.y) * srcTransform.height;
+
     aBuilder.PushLinearGradient(
       mozilla::wr::ToWrRect(gradientBounds),
       aBuilder.BuildClipRegion(mozilla::wr::ToWrRect(clipBounds)),
       mozilla::wr::ToWrPoint(lineStart),
       mozilla::wr::ToWrPoint(lineEnd),
       stops,
       extendMode,
       mozilla::wr::ToWrSize(firstTileBounds.Size()),
       mozilla::wr::ToWrSize(tileSpacing));
   } else {
+    lineStart.x = (lineStart.x - srcTransform.x) * srcTransform.width;
+    lineStart.y = (lineStart.y - srcTransform.y) * srcTransform.height;
+    gradientRadius.width *= srcTransform.width;
+    gradientRadius.height *= srcTransform.height;
+
     aBuilder.PushRadialGradient(
       mozilla::wr::ToWrRect(gradientBounds),
       aBuilder.BuildClipRegion(mozilla::wr::ToWrRect(clipBounds)),
       mozilla::wr::ToWrPoint(lineStart),
       mozilla::wr::ToWrSize(gradientRadius),
       stops,
       extendMode,
       mozilla::wr::ToWrSize(firstTileBounds.Size()),