From 6019443efe72d72e105ec247357b597161d6799f Mon Sep 17 00:00:00 2001 From: Nicolas Silva Date: Wed, 23 Mar 2022 20:28:55 +0000 Subject: [PATCH] Bug 1761002 - Restore the clip rect in webrenderized images. r=mstange In bug 1758942 there was a bit of clipping logic for webrenderized svg images that was removed because we didn't know what it was useful for. I still don't quite know, other than that it caused layout/reftests/svg/image/image-preserveAspectRatio-01-raster.svg and layout/reftests/svg/image/image-preserveAspectRatio-02-raster.svg to start failing when the gfx.webrender.svg-images pref is enabled, so let's revert it. Depends on D141847 Differential Revision: https://phabricator.services.mozilla.com/D141848 --- layout/svg/SVGImageFrame.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/layout/svg/SVGImageFrame.cpp b/layout/svg/SVGImageFrame.cpp index 89bb92fe6056..7eafc1213743 100644 --- a/layout/svg/SVGImageFrame.cpp +++ b/layout/svg/SVGImageFrame.cpp @@ -497,7 +497,16 @@ bool SVGImageFrame::CreateWebRenderCommands( appUnitsPerCSSPixel); appRect += toReferenceFrame; auto destRect = LayoutDeviceRect::FromAppUnits(appRect, appUnitsPerDevPx); + auto clipRect = destRect; + if (StyleDisplay()->IsScrollableOverflow()) { + // Apply potential non-trivial clip + auto cssClip = SVGUtils::GetClipRectForFrame(this, 0, 0, width, height); + auto appClip = + nsLayoutUtils::RoundGfxRectToAppRect(cssClip, appUnitsPerCSSPixel); + appClip += toReferenceFrame; + clipRect = LayoutDeviceRect::FromAppUnits(appClip, appUnitsPerDevPx); + // Apply preserveAspectRatio if (mImageContainer->GetType() == imgIContainer::TYPE_RASTER) { int32_t nativeWidth, nativeHeight; @@ -611,7 +620,7 @@ bool SVGImageFrame::CreateWebRenderCommands( Maybe region; IntSize decodeSize = nsLayoutUtils::ComputeImageContainerDrawingParameters( - mImageContainer, this, destRect, destRect, aSc, flags, svgContext, + mImageContainer, this, destRect, clipRect, aSc, flags, svgContext, region); RefPtr provider; @@ -644,7 +653,7 @@ bool SVGImageFrame::CreateWebRenderCommands( if (provider) { aManager->CommandBuilder().PushImageProvider(aItem, provider, drawResult, aBuilder, aResources, - destRect, destRect); + destRect, clipRect); } nsDisplayItemGenericImageGeometry::UpdateDrawResult(aItem, drawResult);