diff --git a/layout/base/nsLayoutUtils.cpp b/layout/base/nsLayoutUtils.cpp index f5580c0c888..6ec0b9fb99d 100644 --- a/layout/base/nsLayoutUtils.cpp +++ b/layout/base/nsLayoutUtils.cpp @@ -5538,6 +5538,11 @@ struct SnappedImageDrawingParameters { // The region in tiled image space which will be drawn, with an associated // region to which sampling should be restricted. ImageRegion region; + // The default viewport size for SVG images, which we use unless a different + // one has been explicitly specified. This is the same as |size| except that + // it does not take into account any transformation on the gfxContext we're + // drawing to - for example, CSS transforms are not taken into account. + nsIntSize svgViewportSize; // Whether there's anything to draw at all. bool shouldDraw; @@ -5548,10 +5553,12 @@ struct SnappedImageDrawingParameters { SnappedImageDrawingParameters(const gfxMatrix& aImageSpaceToDeviceSpace, const nsIntSize& aSize, - const ImageRegion& aRegion) + const ImageRegion& aRegion, + const nsIntSize& aSVGViewportSize) : imageSpaceToDeviceSpace(aImageSpaceToDeviceSpace) , size(aSize) , region(aRegion) + , svgViewportSize(aSVGViewportSize) , shouldDraw(true) {} }; @@ -5666,6 +5673,11 @@ ComputeSnappedImageDrawingParameters(gfxContext* aCtx, aGraphicsFilter, aImageFlags); gfxSize imageSize(intImageSize.width, intImageSize.height); + nsIntSize svgViewportSize = currentMatrix.IsIdentity() + ? intImageSize + : nsIntSize(NSAppUnitsToIntPixels(dest.width, aAppUnitsPerDevPixel), + NSAppUnitsToIntPixels(dest.height, aAppUnitsPerDevPixel)); + // Compute the set of pixels that would be sampled by an ideal rendering gfxPoint subimageTopLeft = MapToFloatImagePixels(imageSize, devPixelDest, devPixelFill.TopLeft()); @@ -5743,7 +5755,9 @@ ComputeSnappedImageDrawingParameters(gfxContext* aCtx, ImageRegion region = ImageRegion::CreateWithSamplingRestriction(imageSpaceFill, subimage); - return SnappedImageDrawingParameters(transform, intImageSize, region); + + return SnappedImageDrawingParameters(transform, intImageSize, + region, svgViewportSize); } @@ -5781,8 +5795,14 @@ DrawImageInternal(gfxContext& aContext, gfxContextMatrixAutoSaveRestore contextMatrixRestorer(&aContext); aContext.SetMatrix(params.imageSpaceToDeviceSpace); + Maybe svgContext = ToMaybe(aSVGContext); + if (!svgContext) { + // Use the default viewport. + svgContext = Some(SVGImageContext(params.svgViewportSize, Nothing())); + } + aImage->Draw(&aContext, params.size, params.region, imgIContainer::FRAME_CURRENT, - aGraphicsFilter, ToMaybe(aSVGContext), aImageFlags); + aGraphicsFilter, svgContext, aImageFlags); return NS_OK; }