Bug 1355570 - Respect aSrc when building WebRender gradients r?mattwoodrow
MozReview-Commit-ID: 6YfNRGYnHcK
--- 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()),