Bug 1416540 - Avoid unnecessary use of double-based types in GenerateAndPushTextMask. r?jfkthame
The code here feeds into gfxContext::mTransform which is float-based, so
using double-based rects and matrices here is unnecessary.
MozReview-Commit-ID: CbeMM8003DA
--- a/layout/painting/nsDisplayList.cpp
+++ b/layout/painting/nsDisplayList.cpp
@@ -759,24 +759,24 @@ GenerateAndPushTextMask(nsIFrame* aFrame
// 2. Generate a mask by all descendant text frames
// 3. Push the generated mask into aContext.
//
// TBD: we actually generate display list of aFrame twice here. It's better
// to reuse the same display list and paint that one twice, one for selection
// background, one for generating text mask.
gfxContext* sourceCtx = aContext;
- gfxRect bounds =
- nsLayoutUtils::RectToGfxRect(aFillRect,
- aFrame->PresContext()->AppUnitsPerDevPixel());
+ LayoutDeviceRect bounds =
+ LayoutDeviceRect::FromAppUnits(aFillRect,
+ aFrame->PresContext()->AppUnitsPerDevPixel());
{
// Paint text selection background into sourceCtx.
gfxContextMatrixAutoSaveRestore save(sourceCtx);
- sourceCtx->SetMatrixDouble(sourceCtx->CurrentMatrixDouble().PreTranslate(bounds.TopLeft()));
+ sourceCtx->SetMatrix(sourceCtx->CurrentMatrix().PreTranslate(bounds.TopLeft().ToUnknownPoint()));
nsLayoutUtils::PaintFrame(aContext, aFrame,
nsRect(nsPoint(0, 0), aFrame->GetSize()),
NS_RGB(255, 255, 255),
nsDisplayListBuilderMode::PAINTING_SELECTION_BACKGROUND);
}
// Evaluate required surface size.
@@ -788,30 +788,30 @@ GenerateAndPushTextMask(nsIFrame* aFrame
RefPtr<DrawTarget> maskDT =
sourceTarget->CreateSimilarDrawTarget(drawRect.Size(),
SurfaceFormat::A8);
if (!maskDT || !maskDT->IsValid()) {
return false;
}
RefPtr<gfxContext> maskCtx = gfxContext::CreatePreservingTransformOrNull(maskDT);
MOZ_ASSERT(maskCtx);
- gfxMatrix currentMatrix = sourceCtx->CurrentMatrixDouble();
- maskCtx->SetMatrixDouble(gfxMatrix::Translation(bounds.TopLeft()) *
- currentMatrix *
- gfxMatrix::Translation(-drawRect.TopLeft()));
+ Matrix currentMatrix = sourceCtx->CurrentMatrix();
+ maskCtx->SetMatrix(Matrix::Translation(bounds.TopLeft().ToUnknownPoint()) *
+ currentMatrix *
+ Matrix::Translation(-drawRect.TopLeft()));
// Shade text shape into mask A8 surface.
nsLayoutUtils::PaintFrame(maskCtx, aFrame,
nsRect(nsPoint(0, 0), aFrame->GetSize()),
NS_RGB(255, 255, 255),
nsDisplayListBuilderMode::GENERATE_GLYPH);
// Push the generated mask into aContext, so that the caller can pop and
// blend with it.
- Matrix maskTransform = ToMatrix(currentMatrix) *
+ Matrix maskTransform = currentMatrix *
Matrix::Translation(-drawRect.x, -drawRect.y);
maskTransform.Invert();
RefPtr<SourceSurface> maskSurface = maskDT->Snapshot();
sourceCtx->PushGroupForBlendBack(gfxContentType::COLOR_ALPHA, 1.0, maskSurface, maskTransform);
return true;
}