Bug 1346265 - Part 2. Pass gfxContext to nsImageRenderer::DrawableForElement.
It's ok to pass aRenderingContext to DrawableForElement, since DrawableForElement
only use aRenderingContext to create a similiar draw target. Replace
aRenderingContext by ctx make code more consistent since the draw call
bellow(nsLayoutUtils::DrawImage) use ctx.
MozReview-Commit-ID: 6n0nYfcFPui
--- a/layout/painting/nsImageRenderer.cpp
+++ b/layout/painting/nsImageRenderer.cpp
@@ -511,18 +511,17 @@ nsImageRenderer::Draw(nsPresContext*
nsCSSRendering::PaintGradient(aPresContext, *ctx,
mGradientData, aDirtyRect,
aDest, aFill, aRepeatSize, aSrc, mSize,
aOpacity);
break;
}
case eStyleImageType_Element:
{
- RefPtr<gfxDrawable> drawable = DrawableForElement(aDest,
- aRenderingContext);
+ RefPtr<gfxDrawable> drawable = DrawableForElement(aDest, *ctx);
if (!drawable) {
NS_WARNING("Could not create drawable for element");
return DrawResult::TEMPORARY_ERROR;
}
nsCOMPtr<imgIContainer> image(ImageOps::CreateFromDrawable(drawable));
result =
nsLayoutUtils::DrawImage(*ctx,
@@ -558,17 +557,17 @@ nsImageRenderer::Draw(nsPresContext*
DrawOptions(1.0f, aRenderingContext.ThebesContext()->CurrentOp()));
}
return result;
}
already_AddRefed<gfxDrawable>
nsImageRenderer::DrawableForElement(const nsRect& aImageRect,
- nsRenderingContext& aRenderingContext)
+ gfxContext& aContext)
{
NS_ASSERTION(mType == eStyleImageType_Element,
"DrawableForElement only makes sense if backed by an element");
if (mPaintServerFrame) {
// XXX(seth): In order to not pass FLAG_SYNC_DECODE_IMAGES here,
// DrawableFromPaintServer would have to return a DrawResult indicating
// whether any images could not be painted because they weren't fully
// decoded. Even always passing FLAG_SYNC_DECODE_IMAGES won't eliminate all
@@ -576,18 +575,18 @@ nsImageRenderer::DrawableForElement(cons
// loading, but it's better than nothing.
int32_t appUnitsPerDevPixel = mForFrame->PresContext()->AppUnitsPerDevPixel();
nsRect destRect = aImageRect - aImageRect.TopLeft();
nsIntSize roundedOut = destRect.ToOutsidePixels(appUnitsPerDevPixel).Size();
IntSize imageSize(roundedOut.width, roundedOut.height);
RefPtr<gfxDrawable> drawable =
nsSVGIntegrationUtils::DrawableFromPaintServer(
mPaintServerFrame, mForFrame, mSize, imageSize,
- aRenderingContext.GetDrawTarget(),
- aRenderingContext.ThebesContext()->CurrentMatrix(),
+ aContext.GetDrawTarget(),
+ aContext.CurrentMatrix(),
nsSVGIntegrationUtils::FLAG_SYNC_DECODE_IMAGES);
return drawable.forget();
}
NS_ASSERTION(mImageElementSurface.GetSourceSurface(), "Surface should be ready.");
RefPtr<gfxDrawable> drawable = new gfxSurfaceDrawable(
mImageElementSurface.GetSourceSurface().get(),
mImageElementSurface.mSize);
@@ -770,18 +769,19 @@ nsImageRenderer::DrawBorderImageComponen
// This path, for eStyleImageType_Element, is currently slower than it
// needs to be because we don't cache anything. (In particular, if we have
// to draw to a temporary surface inside ClippedImage, we don't cache that
// temporary surface since we immediately throw the ClippedImage we create
// here away.) However, if we did cache, we'd need to know when to
// invalidate that cache, and it's not clear that it's worth the trouble
// since using border-image with -moz-element is rare.
- RefPtr<gfxDrawable> drawable = DrawableForElement(nsRect(nsPoint(), mSize),
- aRenderingContext);
+ RefPtr<gfxDrawable> drawable =
+ DrawableForElement(nsRect(nsPoint(), mSize),
+ *aRenderingContext.ThebesContext());
if (!drawable) {
NS_WARNING("Could not create drawable for element");
return DrawResult::TEMPORARY_ERROR;
}
nsCOMPtr<imgIContainer> image(ImageOps::CreateFromDrawable(drawable));
subImage = ImageOps::Clip(image, srcRect, aSVGViewportSize);
}
--- a/layout/painting/nsImageRenderer.h
+++ b/layout/painting/nsImageRenderer.h
@@ -257,17 +257,17 @@ private:
/**
* Helper method for creating a gfxDrawable from mPaintServerFrame or
* mImageElementSurface.
* Requires mType is eStyleImageType_Element.
* Returns null if we cannot create the drawable.
*/
already_AddRefed<gfxDrawable> DrawableForElement(const nsRect& aImageRect,
- nsRenderingContext& aRenderingContext);
+ gfxContext& aContext);
nsIFrame* mForFrame;
const nsStyleImage* mImage;
nsStyleImageType mType;
nsCOMPtr<imgIContainer> mImageContainer;
RefPtr<nsStyleGradient> mGradientData;
nsIFrame* mPaintServerFrame;
nsLayoutUtils::SurfaceFromElementResult mImageElementSurface;