Bug 1416540 - Avoid unnecessary use of double-based types in GenerateAndPushTextMask. r?jfkthame draft
authorKartikaya Gupta <kgupta@mozilla.com>
Sun, 12 Nov 2017 18:37:32 -0500
changeset 696905 53914fdad8eabcc6654fbfc237a4b93c9a604639
parent 696850 aabfc14671b55983e1c3053989a4c3b7c5691aaa
child 696906 8fe17cd35f04a1386ce047f6a45393e660947e6d
push id88821
push userkgupta@mozilla.com
push dateSun, 12 Nov 2017 23:37:55 +0000
reviewersjfkthame
bugs1416540
milestone58.0a1
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
layout/painting/nsDisplayList.cpp
--- 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;
 }