Bug 1027645 - Eliminate all nsRenderingContext::AppUnitsPerDevPixel() callers and all non-propagating nsRenderingContext::DeviceContext() callers. r=roc

This commit is contained in:
Jonathan Watt 2014-06-20 07:42:30 +01:00
parent 128d884dc9
commit f1d16eb1ff
13 changed files with 64 additions and 35 deletions

View File

@ -53,7 +53,6 @@ public:
gfxContext *ThebesContext() { return mThebes; }
DrawTarget *GetDrawTarget() { return mThebes->GetDrawTarget(); }
nsDeviceContext *DeviceContext() { return mDeviceContext; }
int32_t AppUnitsPerDevPixel() { return NSToIntRound(mP2A); }
// Graphics state

View File

@ -3549,12 +3549,15 @@ FrameLayerBuilder::GetThebesLayerScaleForFrame(nsIFrame* aFrame)
}
#ifdef MOZ_DUMP_PAINTING
static void DebugPaintItem(nsRenderingContext* aDest, nsDisplayItem *aItem, nsDisplayListBuilder* aBuilder)
static void DebugPaintItem(nsRenderingContext* aDest,
nsPresContext* aPresContext,
nsDisplayItem *aItem,
nsDisplayListBuilder* aBuilder)
{
bool snap;
nsRect appUnitBounds = aItem->GetBounds(aBuilder, &snap);
gfxRect bounds(appUnitBounds.x, appUnitBounds.y, appUnitBounds.width, appUnitBounds.height);
bounds.ScaleInverse(aDest->AppUnitsPerDevPixel());
bounds.ScaleInverse(aPresContext->AppUnitsPerDevPixel());
nsRefPtr<gfxASurface> surf =
gfxPlatform::GetPlatform()->CreateOffscreenSurface(IntSize(bounds.width, bounds.height),
@ -3693,7 +3696,7 @@ FrameLayerBuilder::PaintItems(nsTArray<ClippedDisplayItem>& aItems,
#ifdef MOZ_DUMP_PAINTING
if (gfxUtils::sDumpPainting) {
DebugPaintItem(aRC, cdi->mItem, aBuilder);
DebugPaintItem(aRC, aPresContext, cdi->mItem, aBuilder);
} else {
#else
{

View File

@ -4785,7 +4785,8 @@ nsImageRenderer::Draw(nsPresContext* aPresContext,
switch (mType) {
case eStyleImageType_Image:
{
nsLayoutUtils::DrawSingleImage(&aRenderingContext, mImageContainer,
nsLayoutUtils::DrawSingleImage(&aRenderingContext, aPresContext,
mImageContainer,
graphicsFilter, aFill, aDirtyRect,
nullptr,
ConvertImageRendererToDrawFlags(mFlags));
@ -4806,7 +4807,8 @@ nsImageRenderer::Draw(nsPresContext* aPresContext,
NS_WARNING("Could not create drawable for element");
return;
}
nsLayoutUtils::DrawPixelSnapped(&aRenderingContext, drawable, graphicsFilter,
nsLayoutUtils::DrawPixelSnapped(&aRenderingContext, aPresContext,
drawable, graphicsFilter,
aDest, aFill, aDest.TopLeft(), aDirtyRect);
return;
}
@ -4865,7 +4867,8 @@ nsImageRenderer::DrawBackground(nsPresContext* aPresContext,
GraphicsFilter graphicsFilter =
nsLayoutUtils::GetGraphicsFilterForFrame(mForFrame);
nsLayoutUtils::DrawBackgroundImage(&aRenderingContext, mImageContainer,
nsLayoutUtils::DrawBackgroundImage(&aRenderingContext, aPresContext,
mImageContainer,
nsIntSize(nsPresContext::AppUnitsToIntCSSPixels(mSize.width),
nsPresContext::AppUnitsToIntCSSPixels(mSize.height)),
graphicsFilter,
@ -4986,6 +4989,7 @@ nsImageRenderer::DrawBorderImageComponent(nsPresContext* aPresContext,
if (!RequiresScaling(aFill, aHFill, aVFill, aUnitSize)) {
nsLayoutUtils::DrawSingleImage(&aRenderingContext,
aPresContext,
subImage,
graphicsFilter,
aFill, aDirtyRect,
@ -4996,6 +5000,7 @@ nsImageRenderer::DrawBorderImageComponent(nsPresContext* aPresContext,
nsRect tile = ComputeTile(aFill, aHFill, aVFill, aUnitSize);
nsLayoutUtils::DrawImage(&aRenderingContext,
aPresContext,
subImage,
graphicsFilter,
tile, aFill, tile.TopLeft(), aDirtyRect,
@ -5067,7 +5072,8 @@ nsImageRenderer::DrawBorderImageComponent(nsPresContext* aPresContext,
gfxIntSize(srcRect.width, srcRect.height));
nsPoint anchor(nsPresContext::CSSPixelsToAppUnits(aSrc.x),
nsPresContext::CSSPixelsToAppUnits(aSrc.y));
nsLayoutUtils::DrawPixelSnapped(&aRenderingContext, srcSliceDrawable,
nsLayoutUtils::DrawPixelSnapped(&aRenderingContext, aPresContext,
srcSliceDrawable,
graphicsFilter, destTile, aFill,
anchor, aDirtyRect);

View File

@ -4999,6 +4999,7 @@ ComputeSnappedImageDrawingParameters(gfxContext* aCtx,
static nsresult
DrawImageInternal(nsRenderingContext* aRenderingContext,
nsPresContext* aPresContext,
imgIContainer* aImage,
GraphicsFilter aGraphicsFilter,
const nsRect& aDest,
@ -5012,7 +5013,8 @@ DrawImageInternal(nsRenderingContext* aRenderingContext,
if (aDest.Contains(aFill)) {
aImageFlags |= imgIContainer::FLAG_CLAMP;
}
int32_t appUnitsPerDevPixel = aRenderingContext->AppUnitsPerDevPixel();
int32_t appUnitsPerDevPixel =
aPresContext->AppUnitsPerDevPixel();
gfxContext* ctx = aRenderingContext->ThebesContext();
SnappedImageDrawingParameters drawingParams =
@ -5035,6 +5037,7 @@ DrawImageInternal(nsRenderingContext* aRenderingContext,
/* static */ void
nsLayoutUtils::DrawPixelSnapped(nsRenderingContext* aRenderingContext,
nsPresContext* aPresContext,
gfxDrawable* aDrawable,
GraphicsFilter aFilter,
const nsRect& aDest,
@ -5042,7 +5045,8 @@ nsLayoutUtils::DrawPixelSnapped(nsRenderingContext* aRenderingContext,
const nsPoint& aAnchor,
const nsRect& aDirty)
{
int32_t appUnitsPerDevPixel = aRenderingContext->AppUnitsPerDevPixel();
int32_t appUnitsPerDevPixel =
aPresContext->AppUnitsPerDevPixel();
gfxContext* ctx = aRenderingContext->ThebesContext();
gfxIntSize drawableSize = aDrawable->Size();
nsIntSize imageSize(drawableSize.width, drawableSize.height);
@ -5076,6 +5080,7 @@ nsLayoutUtils::DrawPixelSnapped(nsRenderingContext* aRenderingContext,
/* static */ nsresult
nsLayoutUtils::DrawSingleUnscaledImage(nsRenderingContext* aRenderingContext,
nsPresContext* aPresContext,
imgIContainer* aImage,
GraphicsFilter aGraphicsFilter,
const nsPoint& aDest,
@ -5105,13 +5110,15 @@ 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, aImage, aGraphicsFilter,
return DrawImageInternal(aRenderingContext, aPresContext,
aImage, aGraphicsFilter,
dest, fill, aDest, aDirty ? *aDirty : dest,
imageSize, nullptr, aImageFlags);
}
/* static */ nsresult
nsLayoutUtils::DrawSingleImage(nsRenderingContext* aRenderingContext,
nsPresContext* aPresContext,
imgIContainer* aImage,
GraphicsFilter aGraphicsFilter,
const nsRect& aDest,
@ -5125,7 +5132,8 @@ nsLayoutUtils::DrawSingleImage(nsRenderingContext* aRenderingContext,
// We choose a size for vector images that emulates a raster image which
// is perfectly sized for the destination rect: each pixel in the image
// maps exactly to a single pixel on-screen.
nscoord appUnitsPerDevPx = aRenderingContext->AppUnitsPerDevPixel();
nscoord appUnitsPerDevPx =
aPresContext->AppUnitsPerDevPixel();
imageSize.width = NSAppUnitsToIntPixels(aDest.width, appUnitsPerDevPx);
imageSize.height = NSAppUnitsToIntPixels(aDest.height, appUnitsPerDevPx);
} else {
@ -5151,7 +5159,8 @@ nsLayoutUtils::DrawSingleImage(nsRenderingContext* aRenderingContext,
// transform but we don't want to actually tile the image.
nsRect fill;
fill.IntersectRect(aDest, dest);
return DrawImageInternal(aRenderingContext, aImage, aGraphicsFilter, dest, fill,
return DrawImageInternal(aRenderingContext, aPresContext, aImage,
aGraphicsFilter, dest, fill,
fill.TopLeft(), aDirty, imageSize, aSVGContext, aImageFlags);
}
@ -5178,6 +5187,7 @@ nsLayoutUtils::ComputeSizeForDrawing(imgIContainer *aImage,
/* static */ nsresult
nsLayoutUtils::DrawBackgroundImage(nsRenderingContext* aRenderingContext,
nsPresContext* aPresContext,
imgIContainer* aImage,
const nsIntSize& aImageSize,
GraphicsFilter aGraphicsFilter,
@ -5194,13 +5204,15 @@ nsLayoutUtils::DrawBackgroundImage(nsRenderingContext* aRenderingContext,
aGraphicsFilter = GraphicsFilter::FILTER_NEAREST;
}
return DrawImageInternal(aRenderingContext, aImage, aGraphicsFilter,
return DrawImageInternal(aRenderingContext, aPresContext, aImage,
aGraphicsFilter,
aDest, aFill, aAnchor, aDirty,
aImageSize, nullptr, aImageFlags);
}
/* static */ nsresult
nsLayoutUtils::DrawImage(nsRenderingContext* aRenderingContext,
nsPresContext* aPresContext,
imgIContainer* aImage,
GraphicsFilter aGraphicsFilter,
const nsRect& aDest,
@ -5243,7 +5255,8 @@ nsLayoutUtils::DrawImage(nsRenderingContext* aRenderingContext,
imageSize.height = nsPresContext::AppUnitsToIntCSSPixels(aFill.height);
}
return DrawImageInternal(aRenderingContext, aImage, aGraphicsFilter,
return DrawImageInternal(aRenderingContext, aPresContext, aImage,
aGraphicsFilter,
aDest, aFill, aAnchor, aDirty,
imageSize, nullptr, aImageFlags);
}

View File

@ -1445,6 +1445,7 @@ public:
* @param aImageFlags Image flags of the imgIContainer::FLAG_* variety
*/
static nsresult DrawBackgroundImage(nsRenderingContext* aRenderingContext,
nsPresContext* aPresContext,
imgIContainer* aImage,
const nsIntSize& aImageSize,
GraphicsFilter aGraphicsFilter,
@ -1470,6 +1471,7 @@ public:
* @param aImageFlags Image flags of the imgIContainer::FLAG_* variety
*/
static nsresult DrawImage(nsRenderingContext* aRenderingContext,
nsPresContext* aPresContext,
imgIContainer* aImage,
GraphicsFilter aGraphicsFilter,
const nsRect& aDest,
@ -1500,6 +1502,7 @@ public:
* @param aDirty Pixels outside this area may be skipped.
*/
static void DrawPixelSnapped(nsRenderingContext* aRenderingContext,
nsPresContext* aPresContext,
gfxDrawable* aDrawable,
GraphicsFilter aFilter,
const nsRect& aDest,
@ -1524,6 +1527,7 @@ public:
* be aligned with image pixels.
*/
static nsresult DrawSingleUnscaledImage(nsRenderingContext* aRenderingContext,
nsPresContext* aPresContext,
imgIContainer* aImage,
GraphicsFilter aGraphicsFilter,
const nsPoint& aDest,
@ -1552,6 +1556,7 @@ public:
* be aligned with image pixels.
*/
static nsresult DrawSingleImage(nsRenderingContext* aRenderingContext,
nsPresContext* aPresContext,
imgIContainer* aImage,
GraphicsFilter aGraphicsFilter,
const nsRect& aDest,

View File

@ -302,7 +302,7 @@ nsBulletFrame::PaintBullet(nsRenderingContext& aRenderingContext, nsPoint aPt,
nsRect dest(mPadding.left, mPadding.top,
mRect.width - (mPadding.left + mPadding.right),
mRect.height - (mPadding.top + mPadding.bottom));
nsLayoutUtils::DrawSingleImage(&aRenderingContext,
nsLayoutUtils::DrawSingleImage(&aRenderingContext, PresContext(),
imageCon, nsLayoutUtils::GetGraphicsFilterForFrame(this),
dest + aPt, aDirtyRect, nullptr, aFlags);
return;

View File

@ -1196,7 +1196,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, imgCon,
nsLayoutUtils::DrawSingleImage(&aRenderingContext, PresContext(), imgCon,
nsLayoutUtils::GetGraphicsFilterForFrame(this), dest, aDirtyRect,
nullptr, imgIContainer::FLAG_NONE);
iconUsed = true;
@ -1411,7 +1411,7 @@ nsImageFrame::PaintImage(nsRenderingContext& aRenderingContext, nsPoint aPt,
nsRect dest(inner.TopLeft(), mComputedSize);
dest.y -= GetContinuationOffset();
nsLayoutUtils::DrawSingleImage(&aRenderingContext, aImage,
nsLayoutUtils::DrawSingleImage(&aRenderingContext, PresContext(), aImage,
nsLayoutUtils::GetGraphicsFilterForFrame(this), dest, aDirtyRect,
nullptr, aFlags);

View File

@ -386,6 +386,7 @@ nsSVGImageFrame::PaintSVG(nsRenderingContext *aContext,
// and that's not always true for TYPE_VECTOR images.
nsLayoutUtils::DrawSingleImage(
aContext,
PresContext(),
mImageContainer,
nsLayoutUtils::GetGraphicsFilterForFrame(this),
destRect,
@ -395,6 +396,7 @@ nsSVGImageFrame::PaintSVG(nsRenderingContext *aContext,
} else { // mImageContainer->GetType() == TYPE_RASTER
nsLayoutUtils::DrawSingleUnscaledImage(
aContext,
PresContext(),
mImageContainer,
nsLayoutUtils::GetGraphicsFilterForFrame(this),
nsPoint(0, 0),

View File

@ -336,7 +336,7 @@ nsImageBoxFrame::PaintImage(nsRenderingContext& aRenderingContext,
if (imgCon) {
bool hasSubRect = !mUseSrcAttr && (mSubRect.width > 0 || mSubRect.height > 0);
nsLayoutUtils::DrawSingleImage(&aRenderingContext, imgCon,
nsLayoutUtils::DrawSingleImage(&aRenderingContext, PresContext(), imgCon,
nsLayoutUtils::GetGraphicsFilterForFrame(this),
rect, dirty, nullptr, aFlags, hasSubRect ? &mSubRect : nullptr);
}

View File

@ -3381,7 +3381,8 @@ nsTreeBodyFrame::PaintTwisty(int32_t aRowIndex,
}
// Paint the image.
nsLayoutUtils::DrawSingleUnscaledImage(&aRenderingContext, image,
nsLayoutUtils::DrawSingleUnscaledImage(&aRenderingContext,
aPresContext, image,
GraphicsFilter::FILTER_NEAREST, pt, &aDirtyRect,
imgIContainer::FLAG_NONE, &imageSize);
}
@ -3520,7 +3521,7 @@ nsTreeBodyFrame::PaintImage(int32_t aRowIndex,
ctx->PushGroup(gfxContentType::COLOR_ALPHA);
}
nsLayoutUtils::DrawImage(&aRenderingContext, image,
nsLayoutUtils::DrawImage(&aRenderingContext, aPresContext, image,
nsLayoutUtils::GetGraphicsFilterForFrame(this),
wholeImageDest, destRect, destRect.TopLeft(), aDirtyRect,
imgIContainer::FLAG_NONE);
@ -3702,8 +3703,8 @@ nsTreeBodyFrame::PaintCheckbox(int32_t aRowIndex,
}
// Paint the image.
nsLayoutUtils::DrawSingleUnscaledImage(&aRenderingContext, image,
GraphicsFilter::FILTER_NEAREST, pt, &aDirtyRect,
nsLayoutUtils::DrawSingleUnscaledImage(&aRenderingContext, aPresContext,
image, GraphicsFilter::FILTER_NEAREST, pt, &aDirtyRect,
imgIContainer::FLAG_NONE, &imageSize);
}
}
@ -3767,7 +3768,7 @@ nsTreeBodyFrame::PaintProgressMeter(int32_t aRowIndex,
image->GetHeight(&height);
nsSize size(width*nsDeviceContext::AppUnitsPerCSSPixel(),
height*nsDeviceContext::AppUnitsPerCSSPixel());
nsLayoutUtils::DrawImage(&aRenderingContext, image,
nsLayoutUtils::DrawImage(&aRenderingContext, aPresContext, image,
nsLayoutUtils::GetGraphicsFilterForFrame(this),
nsRect(meterRect.TopLeft(), size), meterRect, meterRect.TopLeft(),
aDirtyRect, imgIContainer::FLAG_NONE);
@ -3788,7 +3789,7 @@ nsTreeBodyFrame::PaintProgressMeter(int32_t aRowIndex,
image->GetHeight(&height);
nsSize size(width*nsDeviceContext::AppUnitsPerCSSPixel(),
height*nsDeviceContext::AppUnitsPerCSSPixel());
nsLayoutUtils::DrawImage(&aRenderingContext, image,
nsLayoutUtils::DrawImage(&aRenderingContext, aPresContext, image,
nsLayoutUtils::GetGraphicsFilterForFrame(this),
nsRect(meterRect.TopLeft(), size), meterRect, meterRect.TopLeft(),
aDirtyRect, imgIContainer::FLAG_NONE);

View File

@ -2107,10 +2107,10 @@ nsNativeThemeCocoa::IsParentScrollbarRolledOver(nsIFrame* aFrame)
}
static bool
IsHiDPIContext(nsDeviceContext* aContext)
IsHiDPIContext(nsPresContext* aContext)
{
return nsPresContext::AppUnitsPerCSSPixel() >=
2 * aContext->UnscaledAppUnitsPerDevPixel();
2 * aContext->DeviceContext()->UnscaledAppUnitsPerDevPixel();
}
NS_IMETHODIMP
@ -2123,7 +2123,7 @@ nsNativeThemeCocoa::DrawWidgetBackground(nsRenderingContext* aContext,
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
// setup to draw into the correct port
int32_t p2a = aContext->AppUnitsPerDevPixel();
int32_t p2a = aFrame->PresContext()->AppUnitsPerDevPixel();
gfxRect nativeDirtyRect(aDirtyRect.x, aDirtyRect.y,
aDirtyRect.width, aDirtyRect.height);
@ -2140,7 +2140,7 @@ nsNativeThemeCocoa::DrawWidgetBackground(nsRenderingContext* aContext,
gfxContextMatrixAutoSaveRestore save(thebesCtx);
bool hidpi = IsHiDPIContext(aContext->DeviceContext());
bool hidpi = IsHiDPIContext(aFrame->PresContext());
if (hidpi) {
// Use high-resolution drawing.
nativeWidgetRect.ScaleInverse(2.0f);
@ -2844,7 +2844,7 @@ nsNativeThemeCocoa::GetWidgetBorder(nsDeviceContext* aContext,
break;
}
if (IsHiDPIContext(aContext)) {
if (IsHiDPIContext(aFrame->PresContext())) {
*aResult = *aResult + *aResult; // doubled
}
@ -2882,7 +2882,7 @@ bool
nsNativeThemeCocoa::GetWidgetOverflow(nsDeviceContext* aContext, nsIFrame* aFrame,
uint8_t aWidgetType, nsRect* aOverflowRect)
{
int32_t p2a = aContext->AppUnitsPerDevPixel();
int32_t p2a = aFrame->PresContext()->AppUnitsPerDevPixel();
switch (aWidgetType) {
case NS_THEME_BUTTON:
case NS_THEME_MOZ_MAC_HELP_BUTTON:
@ -3223,7 +3223,7 @@ nsNativeThemeCocoa::GetMinimumWidgetSize(nsRenderingContext* aContext,
}
}
if (IsHiDPIContext(aContext->DeviceContext())) {
if (IsHiDPIContext(aFrame->PresContext())) {
*aResult = *aResult * 2;
}

View File

@ -1236,7 +1236,7 @@ nsNativeThemeGTK::GetMinimumWidgetSize(nsRenderingContext* aContext,
{
// Just include our border, and let the box code augment the size.
nsIntMargin border;
nsNativeThemeGTK::GetWidgetBorder(aContext->DeviceContext(),
nsNativeThemeGTK::GetWidgetBorder(aFrame->PresContext()->DeviceContext(),
aFrame, aWidgetType, &border);
aResult->width = border.left + border.right;
aResult->height = border.top + border.bottom;

View File

@ -1598,7 +1598,7 @@ nsNativeThemeWin::DrawWidgetBackground(nsRenderingContext* aContext,
return NS_OK;
}
gfxFloat p2a = gfxFloat(aContext->AppUnitsPerDevPixel());
gfxFloat p2a = gfxFloat(aFrame->PresContext()->AppUnitsPerDevPixel());
RECT widgetRect;
RECT clipRect;
gfxRect tr(aRect.x, aRect.y, aRect.width, aRect.height),
@ -3573,7 +3573,7 @@ nsresult nsNativeThemeWin::ClassicDrawWidgetBackground(nsRenderingContext* aCont
return NS_OK;
}
gfxFloat p2a = gfxFloat(aContext->AppUnitsPerDevPixel());
gfxFloat p2a = gfxFloat(aFrame->PresContext()->AppUnitsPerDevPixel());
RECT widgetRect;
gfxRect tr(aRect.x, aRect.y, aRect.width, aRect.height),
dr(aDirtyRect.x, aDirtyRect.y, aDirtyRect.width, aDirtyRect.height);