From eb4243e0c666e3c6376962f85716e871a6800bea Mon Sep 17 00:00:00 2001 From: Mats Palmgren Date: Fri, 3 Apr 2015 19:48:12 +0000 Subject: [PATCH] Bug 1149222 part 1 - Make nsLayoutUtils::DrawBackgroundImage and SVGImageContext use CSSIntSize instead of unitless nsIntSize. r=dholbert --- dom/canvas/CanvasRenderingContext2D.cpp | 4 +++- image/src/ClippedImage.cpp | 2 +- image/src/OrientedImage.cpp | 2 +- image/src/VectorImage.cpp | 9 +++++++-- layout/base/nsCSSRendering.cpp | 4 ++-- layout/base/nsLayoutUtils.cpp | 14 +++++++------- layout/base/nsLayoutUtils.h | 2 +- layout/svg/SVGImageContext.h | 7 ++++--- layout/svg/nsSVGImageFrame.cpp | 2 +- 9 files changed, 27 insertions(+), 19 deletions(-) diff --git a/dom/canvas/CanvasRenderingContext2D.cpp b/dom/canvas/CanvasRenderingContext2D.cpp index 302ef5f4e248..76f9cb05ab4e 100644 --- a/dom/canvas/CanvasRenderingContext2D.cpp +++ b/dom/canvas/CanvasRenderingContext2D.cpp @@ -113,6 +113,7 @@ #include "nsSVGLength2.h" #include "nsDeviceContext.h" #include "nsFontMetrics.h" +#include "Units.h" #undef free // apparently defined by some windows header, clashing with a free() // method in SkTypes.h @@ -4463,7 +4464,8 @@ CanvasRenderingContext2D::DrawDirectlyToCanvas( // FLAG_CLAMP is added for increased performance, since we never tile here. uint32_t modifiedFlags = image.mDrawingFlags | imgIContainer::FLAG_CLAMP; - SVGImageContext svgContext(scaledImageSize, Nothing(), CurrentState().globalAlpha); + CSSIntSize sz(scaledImageSize.width, scaledImageSize.height); // XXX hmm is scaledImageSize really in CSS pixels? + SVGImageContext svgContext(sz, Nothing(), CurrentState().globalAlpha); auto result = image.mImgContainer-> Draw(context, scaledImageSize, diff --git a/image/src/ClippedImage.cpp b/image/src/ClippedImage.cpp index e88d3f415167..c967294ff219 100644 --- a/image/src/ClippedImage.cpp +++ b/image/src/ClippedImage.cpp @@ -345,7 +345,7 @@ UnclipViewport(const SVGImageContext& aOldContext, // Map the viewport to the inner image. (Note that we don't take the aSize // parameter of Draw into account, just the clipping region.) - nsIntSize vSize(aOldContext.GetViewportSize()); + CSSIntSize vSize(aOldContext.GetViewportSize()); vSize.width = ceil(vSize.width * double(innerSize.width) / clipSize.width); vSize.height = ceil(vSize.height * double(innerSize.height) / clipSize.height); diff --git a/image/src/OrientedImage.cpp b/image/src/OrientedImage.cpp index 149a092ce2c5..a53e89c71316 100644 --- a/image/src/OrientedImage.cpp +++ b/image/src/OrientedImage.cpp @@ -241,7 +241,7 @@ static SVGImageContext OrientViewport(const SVGImageContext& aOldContext, const Orientation& aOrientation) { - nsIntSize viewportSize(aOldContext.GetViewportSize()); + CSSIntSize viewportSize(aOldContext.GetViewportSize()); if (aOrientation.SwapsWidthAndHeight()) { swap(viewportSize.width, viewportSize.height); } diff --git a/image/src/VectorImage.cpp b/image/src/VectorImage.cpp index e549aa502a28..790326cde9b6 100644 --- a/image/src/VectorImage.cpp +++ b/image/src/VectorImage.cpp @@ -719,11 +719,16 @@ struct SVGDrawingParameters , region(aRegion) , filter(aFilter) , svgContext(aSVGContext) - , viewportSize(aSVGContext ? aSVGContext->GetViewportSize() : aSize) + , viewportSize(aSize) , animationTime(aAnimationTime) , flags(aFlags) , opacity(aSVGContext ? aSVGContext->GetGlobalOpacity() : 1.0) - { } + { + if (aSVGContext) { + CSSIntSize sz = aSVGContext->GetViewportSize(); + viewportSize = nsIntSize(sz.width, sz.height); // XXX losing unit + } + } gfxContext* context; IntSize size; diff --git a/layout/base/nsCSSRendering.cpp b/layout/base/nsCSSRendering.cpp index 2ffb3b1e7a45..ee99cf8b9c97 100644 --- a/layout/base/nsCSSRendering.cpp +++ b/layout/base/nsCSSRendering.cpp @@ -4917,8 +4917,8 @@ nsImageRenderer::Draw(nsPresContext* aPresContext, switch (mType) { case eStyleImageType_Image: { - nsIntSize imageSize(nsPresContext::AppUnitsToIntCSSPixels(mSize.width), - nsPresContext::AppUnitsToIntCSSPixels(mSize.height)); + CSSIntSize imageSize(nsPresContext::AppUnitsToIntCSSPixels(mSize.width), + nsPresContext::AppUnitsToIntCSSPixels(mSize.height)); return nsLayoutUtils::DrawBackgroundImage(*aRenderingContext.ThebesContext(), aPresContext, diff --git a/layout/base/nsLayoutUtils.cpp b/layout/base/nsLayoutUtils.cpp index c4b663726e0d..e7979f2ccbd9 100644 --- a/layout/base/nsLayoutUtils.cpp +++ b/layout/base/nsLayoutUtils.cpp @@ -5746,7 +5746,7 @@ struct SnappedImageDrawingParameters { // 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; + CSSIntSize svgViewportSize; // Whether there's anything to draw at all. bool shouldDraw; @@ -5758,7 +5758,7 @@ struct SnappedImageDrawingParameters { SnappedImageDrawingParameters(const gfxMatrix& aImageSpaceToDeviceSpace, const nsIntSize& aSize, const ImageRegion& aRegion, - const nsIntSize& aSVGViewportSize) + const CSSIntSize& aSVGViewportSize) : imageSpaceToDeviceSpace(aImageSpaceToDeviceSpace) , size(aSize) , region(aRegion) @@ -5884,10 +5884,10 @@ 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)); + CSSIntSize svgViewportSize = currentMatrix.IsIdentity() + ? CSSIntSize(intImageSize.width, intImageSize.height) + : CSSIntSize(NSAppUnitsToIntPixels(dest.width, aAppUnitsPerDevPixel), //XXX BUG! + NSAppUnitsToIntPixels(dest.height, aAppUnitsPerDevPixel)); //XXX BUG! // Compute the set of pixels that would be sampled by an ideal rendering gfxPoint subimageTopLeft = @@ -6194,7 +6194,7 @@ nsLayoutUtils::ComputeSizeForDrawingWithFallback(imgIContainer* aImage, nsLayoutUtils::DrawBackgroundImage(gfxContext& aContext, nsPresContext* aPresContext, imgIContainer* aImage, - const nsIntSize& aImageSize, + const CSSIntSize& aImageSize, GraphicsFilter aGraphicsFilter, const nsRect& aDest, const nsRect& aFill, diff --git a/layout/base/nsLayoutUtils.h b/layout/base/nsLayoutUtils.h index 6ec5734153a0..516968af5ace 100644 --- a/layout/base/nsLayoutUtils.h +++ b/layout/base/nsLayoutUtils.h @@ -1667,7 +1667,7 @@ public: static DrawResult DrawBackgroundImage(gfxContext& aContext, nsPresContext* aPresContext, imgIContainer* aImage, - const nsIntSize& aImageSize, + const CSSIntSize& aImageSize, GraphicsFilter aGraphicsFilter, const nsRect& aDest, const nsRect& aFill, diff --git a/layout/svg/SVGImageContext.h b/layout/svg/SVGImageContext.h index c6265e0bc2d2..d285666651cb 100644 --- a/layout/svg/SVGImageContext.h +++ b/layout/svg/SVGImageContext.h @@ -8,6 +8,7 @@ #include "mozilla/Maybe.h" #include "SVGPreserveAspectRatio.h" +#include "Units.h" namespace mozilla { @@ -23,7 +24,7 @@ public: : mGlobalOpacity(1.0) { } - SVGImageContext(nsIntSize aViewportSize, + SVGImageContext(CSSIntSize aViewportSize, Maybe aPreserveAspectRatio, gfxFloat aOpacity = 1.0) : mViewportSize(aViewportSize) @@ -31,7 +32,7 @@ public: , mGlobalOpacity(aOpacity) { } - const nsIntSize& GetViewportSize() const { + const CSSIntSize& GetViewportSize() const { return mViewportSize; } @@ -65,7 +66,7 @@ private: return aPAR.Hash(); } - nsIntSize mViewportSize; + CSSIntSize mViewportSize; Maybe mPreserveAspectRatio; gfxFloat mGlobalOpacity; }; diff --git a/layout/svg/nsSVGImageFrame.cpp b/layout/svg/nsSVGImageFrame.cpp index 1071f9c90497..8c1363cc435b 100644 --- a/layout/svg/nsSVGImageFrame.cpp +++ b/layout/svg/nsSVGImageFrame.cpp @@ -366,7 +366,7 @@ nsSVGImageFrame::PaintSVG(gfxContext& aContext, if (mImageContainer->GetType() == imgIContainer::TYPE_VECTOR) { // Package up the attributes of this image element which can override the // attributes of mImageContainer's internal SVG document. - SVGImageContext context(nsIntSize(width, height), + SVGImageContext context(CSSIntSize(width, height), Some(imgElem->mPreserveAspectRatio.GetAnimValue())); nsRect destRect(0, 0,