From 53f338200b6643bb2c35ffc40dfcaf6b523256b9 Mon Sep 17 00:00:00 2001 From: Jonathan Watt Date: Sat, 1 Nov 2014 10:45:09 +0000 Subject: [PATCH] Bug 1091323 - Convert the nsLayoutUtils helpers that paint images and take an nsRenderingContext to take a gfxContext instead. r=seth --- layout/base/nsCSSRendering.cpp | 10 ++++++---- layout/base/nsLayoutUtils.cpp | 27 +++++++++++++-------------- layout/base/nsLayoutUtils.h | 8 ++++---- layout/generic/nsBulletFrame.cpp | 3 ++- layout/generic/nsImageFrame.cpp | 5 +++-- layout/svg/nsSVGImageFrame.cpp | 7 ++----- layout/xul/nsImageBoxFrame.cpp | 3 ++- layout/xul/tree/nsTreeBodyFrame.cpp | 13 ++++++++----- 8 files changed, 40 insertions(+), 36 deletions(-) diff --git a/layout/base/nsCSSRendering.cpp b/layout/base/nsCSSRendering.cpp index bf8b84acc492..d42c05d18aa9 100644 --- a/layout/base/nsCSSRendering.cpp +++ b/layout/base/nsCSSRendering.cpp @@ -4915,7 +4915,8 @@ nsImageRenderer::Draw(nsPresContext* aPresContext, { nsIntSize imageSize(nsPresContext::AppUnitsToIntCSSPixels(mSize.width), nsPresContext::AppUnitsToIntCSSPixels(mSize.height)); - nsLayoutUtils::DrawBackgroundImage(&aRenderingContext, aPresContext, + nsLayoutUtils::DrawBackgroundImage(*aRenderingContext.ThebesContext(), + aPresContext, mImageContainer, imageSize, filter, aDest, aFill, aAnchor, aDirtyRect, ConvertImageRendererToDrawFlags(mFlags)); @@ -4945,7 +4946,8 @@ nsImageRenderer::Draw(nsPresContext* aPresContext, } nsCOMPtr image(ImageOps::CreateFromDrawable(drawable)); - nsLayoutUtils::DrawImage(&aRenderingContext, aPresContext, image, + nsLayoutUtils::DrawImage(*aRenderingContext.ThebesContext(), + aPresContext, image, filter, aDest, aFill, aAnchor, aDirtyRect, ConvertImageRendererToDrawFlags(mFlags)); @@ -5139,7 +5141,7 @@ nsImageRenderer::DrawBorderImageComponent(nsPresContext* aPresContext, nsLayoutUtils::GetGraphicsFilterForFrame(mForFrame); if (!RequiresScaling(aFill, aHFill, aVFill, aUnitSize)) { - nsLayoutUtils::DrawSingleImage(&aRenderingContext, + nsLayoutUtils::DrawSingleImage(*aRenderingContext.ThebesContext(), aPresContext, subImage, graphicsFilter, @@ -5150,7 +5152,7 @@ nsImageRenderer::DrawBorderImageComponent(nsPresContext* aPresContext, } nsRect tile = ComputeTile(aFill, aHFill, aVFill, aUnitSize); - nsLayoutUtils::DrawImage(&aRenderingContext, + nsLayoutUtils::DrawImage(*aRenderingContext.ThebesContext(), aPresContext, subImage, graphicsFilter, diff --git a/layout/base/nsLayoutUtils.cpp b/layout/base/nsLayoutUtils.cpp index d8fe7826a3af..0a0a8879ef71 100644 --- a/layout/base/nsLayoutUtils.cpp +++ b/layout/base/nsLayoutUtils.cpp @@ -5375,7 +5375,7 @@ ComputeSnappedImageDrawingParameters(gfxContext* aCtx, static nsresult -DrawImageInternal(nsRenderingContext* aRenderingContext, +DrawImageInternal(gfxContext& aContext, nsPresContext* aPresContext, imgIContainer* aImage, GraphicsFilter aGraphicsFilter, @@ -5396,27 +5396,26 @@ DrawImageInternal(nsRenderingContext* aRenderingContext, } int32_t appUnitsPerDevPixel = aPresContext->AppUnitsPerDevPixel(); - gfxContext* ctx = aRenderingContext->ThebesContext(); SnappedImageDrawingParameters params = - ComputeSnappedImageDrawingParameters(ctx, appUnitsPerDevPixel, aDest, + ComputeSnappedImageDrawingParameters(&aContext, appUnitsPerDevPixel, aDest, aFill, aAnchor, aDirty, aImage, aGraphicsFilter, aImageFlags); if (!params.shouldDraw) return NS_OK; - gfxContextMatrixAutoSaveRestore contextMatrixRestorer(ctx); - ctx->SetMatrix(params.imageSpaceToDeviceSpace); + gfxContextMatrixAutoSaveRestore contextMatrixRestorer(&aContext); + aContext.SetMatrix(params.imageSpaceToDeviceSpace); - aImage->Draw(ctx, params.size, params.region, imgIContainer::FRAME_CURRENT, + aImage->Draw(&aContext, params.size, params.region, imgIContainer::FRAME_CURRENT, aGraphicsFilter, ToMaybe(aSVGContext), aImageFlags); return NS_OK; } /* static */ nsresult -nsLayoutUtils::DrawSingleUnscaledImage(nsRenderingContext* aRenderingContext, +nsLayoutUtils::DrawSingleUnscaledImage(gfxContext& aContext, nsPresContext* aPresContext, imgIContainer* aImage, GraphicsFilter aGraphicsFilter, @@ -5447,14 +5446,14 @@ nsLayoutUtils::DrawSingleUnscaledImage(nsRenderingContext* aRenderingContext, // outside the image bounds, we want to honor the aSourceArea-to-aDest // translation but we don't want to actually tile the image. fill.IntersectRect(fill, dest); - return DrawImageInternal(aRenderingContext, aPresContext, + return DrawImageInternal(aContext, aPresContext, aImage, aGraphicsFilter, dest, fill, aDest, aDirty ? *aDirty : dest, nullptr, aImageFlags); } /* static */ nsresult -nsLayoutUtils::DrawSingleImage(nsRenderingContext* aRenderingContext, +nsLayoutUtils::DrawSingleImage(gfxContext& aContext, nsPresContext* aPresContext, imgIContainer* aImage, GraphicsFilter aGraphicsFilter, @@ -5496,7 +5495,7 @@ nsLayoutUtils::DrawSingleImage(nsRenderingContext* aRenderingContext, // transform but we don't want to actually tile the image. nsRect fill; fill.IntersectRect(aDest, dest); - return DrawImageInternal(aRenderingContext, aPresContext, image, + return DrawImageInternal(aContext, aPresContext, image, aGraphicsFilter, dest, fill, fill.TopLeft(), aDirty, aSVGContext, aImageFlags); } @@ -5565,7 +5564,7 @@ nsLayoutUtils::ComputeSizeForDrawingWithFallback(imgIContainer* aImage, } /* static */ nsresult -nsLayoutUtils::DrawBackgroundImage(nsRenderingContext* aRenderingContext, +nsLayoutUtils::DrawBackgroundImage(gfxContext& aContext, nsPresContext* aPresContext, imgIContainer* aImage, const nsIntSize& aImageSize, @@ -5585,13 +5584,13 @@ nsLayoutUtils::DrawBackgroundImage(nsRenderingContext* aRenderingContext, SVGImageContext svgContext(aImageSize, Nothing()); - return DrawImageInternal(aRenderingContext, aPresContext, aImage, + return DrawImageInternal(aContext, aPresContext, aImage, aGraphicsFilter, aDest, aFill, aAnchor, aDirty, &svgContext, aImageFlags); } /* static */ nsresult -nsLayoutUtils::DrawImage(nsRenderingContext* aRenderingContext, +nsLayoutUtils::DrawImage(gfxContext& aContext, nsPresContext* aPresContext, imgIContainer* aImage, GraphicsFilter aGraphicsFilter, @@ -5601,7 +5600,7 @@ nsLayoutUtils::DrawImage(nsRenderingContext* aRenderingContext, const nsRect& aDirty, uint32_t aImageFlags) { - return DrawImageInternal(aRenderingContext, aPresContext, aImage, + return DrawImageInternal(aContext, aPresContext, aImage, aGraphicsFilter, aDest, aFill, aAnchor, aDirty, nullptr, aImageFlags); } diff --git a/layout/base/nsLayoutUtils.h b/layout/base/nsLayoutUtils.h index 3c54f9182d3e..0e9046b56402 100644 --- a/layout/base/nsLayoutUtils.h +++ b/layout/base/nsLayoutUtils.h @@ -1491,7 +1491,7 @@ public: * @param aDirty Pixels outside this area may be skipped. * @param aImageFlags Image flags of the imgIContainer::FLAG_* variety */ - static nsresult DrawBackgroundImage(nsRenderingContext* aRenderingContext, + static nsresult DrawBackgroundImage(gfxContext& aContext, nsPresContext* aPresContext, imgIContainer* aImage, const nsIntSize& aImageSize, @@ -1517,7 +1517,7 @@ public: * @param aDirty Pixels outside this area may be skipped. * @param aImageFlags Image flags of the imgIContainer::FLAG_* variety */ - static nsresult DrawImage(nsRenderingContext* aRenderingContext, + static nsresult DrawImage(gfxContext& aContext, nsPresContext* aPresContext, imgIContainer* aImage, GraphicsFilter aGraphicsFilter, @@ -1571,7 +1571,7 @@ public: * in appunits. For best results it should * be aligned with image pixels. */ - static nsresult DrawSingleUnscaledImage(nsRenderingContext* aRenderingContext, + static nsresult DrawSingleUnscaledImage(gfxContext& aContext, nsPresContext* aPresContext, imgIContainer* aImage, GraphicsFilter aGraphicsFilter, @@ -1600,7 +1600,7 @@ public: * in appunits. For best results it should * be aligned with image pixels. */ - static nsresult DrawSingleImage(nsRenderingContext* aRenderingContext, + static nsresult DrawSingleImage(gfxContext& aContext, nsPresContext* aPresContext, imgIContainer* aImage, GraphicsFilter aGraphicsFilter, diff --git a/layout/generic/nsBulletFrame.cpp b/layout/generic/nsBulletFrame.cpp index a5e263834f79..8d8c95846436 100644 --- a/layout/generic/nsBulletFrame.cpp +++ b/layout/generic/nsBulletFrame.cpp @@ -309,7 +309,8 @@ nsBulletFrame::PaintBullet(nsRenderingContext& aRenderingContext, nsPoint aPt, nsRect dest(padding.left, padding.top, mRect.width - (padding.left + padding.right), mRect.height - (padding.top + padding.bottom)); - nsLayoutUtils::DrawSingleImage(&aRenderingContext, PresContext(), + nsLayoutUtils::DrawSingleImage(*aRenderingContext.ThebesContext(), + PresContext(), imageCon, nsLayoutUtils::GetGraphicsFilterForFrame(this), dest + aPt, aDirtyRect, nullptr, aFlags); return; diff --git a/layout/generic/nsImageFrame.cpp b/layout/generic/nsImageFrame.cpp index 564c265671ec..153fceb3e57d 100644 --- a/layout/generic/nsImageFrame.cpp +++ b/layout/generic/nsImageFrame.cpp @@ -1260,7 +1260,7 @@ nsImageFrame::DisplayAltFeedback(nsRenderingContext& aRenderingContext, nsRect dest((vis->mDirection == NS_STYLE_DIRECTION_RTL) ? inner.XMost() - size : inner.x, inner.y, size, size); - nsLayoutUtils::DrawSingleImage(&aRenderingContext, PresContext(), imgCon, + nsLayoutUtils::DrawSingleImage(*gfx, PresContext(), imgCon, nsLayoutUtils::GetGraphicsFilterForFrame(this), dest, aDirtyRect, nullptr, imgIContainer::FLAG_NONE); iconUsed = true; @@ -1491,7 +1491,8 @@ nsImageFrame::PaintImage(nsRenderingContext& aRenderingContext, nsPoint aPt, nsRect dest(inner.TopLeft(), mComputedSize); dest.y -= GetContinuationOffset(); - nsLayoutUtils::DrawSingleImage(&aRenderingContext, PresContext(), aImage, + nsLayoutUtils::DrawSingleImage(*aRenderingContext.ThebesContext(), + PresContext(), aImage, nsLayoutUtils::GetGraphicsFilterForFrame(this), dest, aDirtyRect, nullptr, aFlags); diff --git a/layout/svg/nsSVGImageFrame.cpp b/layout/svg/nsSVGImageFrame.cpp index d36a970894c4..57b5387fc421 100644 --- a/layout/svg/nsSVGImageFrame.cpp +++ b/layout/svg/nsSVGImageFrame.cpp @@ -11,7 +11,6 @@ #include "nsContainerFrame.h" #include "nsIImageLoadingContent.h" #include "nsLayoutUtils.h" -#include "nsRenderingContext.h" #include "imgINotificationObserver.h" #include "nsSVGEffects.h" #include "nsSVGPathGeometryFrame.h" @@ -362,8 +361,6 @@ nsSVGImageFrame::PaintSVG(gfxContext& aContext, // force sync probably just isn't worth it, so always pass FLAG_SYNC_DECODE uint32_t drawFlags = imgIContainer::FLAG_SYNC_DECODE; - nsRenderingContext rendCtx(&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. @@ -378,7 +375,7 @@ nsSVGImageFrame::PaintSVG(gfxContext& aContext, // That method needs our image to have a fixed native width & height, // and that's not always true for TYPE_VECTOR images. nsLayoutUtils::DrawSingleImage( - &rendCtx, + aContext, PresContext(), mImageContainer, nsLayoutUtils::GetGraphicsFilterForFrame(this), @@ -388,7 +385,7 @@ nsSVGImageFrame::PaintSVG(gfxContext& aContext, drawFlags); } else { // mImageContainer->GetType() == TYPE_RASTER nsLayoutUtils::DrawSingleUnscaledImage( - &rendCtx, + aContext, PresContext(), mImageContainer, nsLayoutUtils::GetGraphicsFilterForFrame(this), diff --git a/layout/xul/nsImageBoxFrame.cpp b/layout/xul/nsImageBoxFrame.cpp index 675c4c0a62e1..0609cdc4ade2 100644 --- a/layout/xul/nsImageBoxFrame.cpp +++ b/layout/xul/nsImageBoxFrame.cpp @@ -339,7 +339,8 @@ nsImageBoxFrame::PaintImage(nsRenderingContext& aRenderingContext, if (imgCon) { bool hasSubRect = !mUseSrcAttr && (mSubRect.width > 0 || mSubRect.height > 0); - nsLayoutUtils::DrawSingleImage(&aRenderingContext, PresContext(), imgCon, + nsLayoutUtils::DrawSingleImage(*aRenderingContext.ThebesContext(), + PresContext(), imgCon, nsLayoutUtils::GetGraphicsFilterForFrame(this), rect, dirty, nullptr, aFlags, hasSubRect ? &mSubRect : nullptr); } diff --git a/layout/xul/tree/nsTreeBodyFrame.cpp b/layout/xul/tree/nsTreeBodyFrame.cpp index 647e6bc7e8c6..d726a586e4c7 100644 --- a/layout/xul/tree/nsTreeBodyFrame.cpp +++ b/layout/xul/tree/nsTreeBodyFrame.cpp @@ -3390,7 +3390,7 @@ nsTreeBodyFrame::PaintTwisty(int32_t aRowIndex, } // Paint the image. - nsLayoutUtils::DrawSingleUnscaledImage(&aRenderingContext, + nsLayoutUtils::DrawSingleUnscaledImage(*aRenderingContext.ThebesContext(), aPresContext, image, GraphicsFilter::FILTER_NEAREST, pt, &aDirtyRect, imgIContainer::FLAG_NONE, &imageSize); @@ -3530,7 +3530,7 @@ nsTreeBodyFrame::PaintImage(int32_t aRowIndex, ctx->PushGroup(gfxContentType::COLOR_ALPHA); } - nsLayoutUtils::DrawImage(&aRenderingContext, aPresContext, image, + nsLayoutUtils::DrawImage(*ctx, aPresContext, image, nsLayoutUtils::GetGraphicsFilterForFrame(this), wholeImageDest, destRect, destRect.TopLeft(), aDirtyRect, imgIContainer::FLAG_NONE); @@ -3728,7 +3728,8 @@ nsTreeBodyFrame::PaintCheckbox(int32_t aRowIndex, } // Paint the image. - nsLayoutUtils::DrawSingleUnscaledImage(&aRenderingContext, aPresContext, + nsLayoutUtils::DrawSingleUnscaledImage(*aRenderingContext.ThebesContext(), + aPresContext, image, GraphicsFilter::FILTER_NEAREST, pt, &aDirtyRect, imgIContainer::FLAG_NONE, &imageSize); } @@ -3790,7 +3791,8 @@ nsTreeBodyFrame::PaintProgressMeter(int32_t aRowIndex, image->GetHeight(&height); nsSize size(width*nsDeviceContext::AppUnitsPerCSSPixel(), height*nsDeviceContext::AppUnitsPerCSSPixel()); - nsLayoutUtils::DrawImage(&aRenderingContext, aPresContext, image, + nsLayoutUtils::DrawImage(*aRenderingContext.ThebesContext(), + aPresContext, image, nsLayoutUtils::GetGraphicsFilterForFrame(this), nsRect(meterRect.TopLeft(), size), meterRect, meterRect.TopLeft(), aDirtyRect, imgIContainer::FLAG_NONE); @@ -3816,7 +3818,8 @@ nsTreeBodyFrame::PaintProgressMeter(int32_t aRowIndex, image->GetHeight(&height); nsSize size(width*nsDeviceContext::AppUnitsPerCSSPixel(), height*nsDeviceContext::AppUnitsPerCSSPixel()); - nsLayoutUtils::DrawImage(&aRenderingContext, aPresContext, image, + nsLayoutUtils::DrawImage(*aRenderingContext.ThebesContext(), + aPresContext, image, nsLayoutUtils::GetGraphicsFilterForFrame(this), nsRect(meterRect.TopLeft(), size), meterRect, meterRect.TopLeft(), aDirtyRect, imgIContainer::FLAG_NONE);