Bug 1106602 (Part 1) - Use pretransform dest rect as default SVG-as-image viewport. r=dholbert

This commit is contained in:
Seth Fowler 2014-12-15 15:44:13 -08:00
parent d9fbcee0e5
commit 6764e463f9

View File

@ -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<SVGImageContext> 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;
}