Bug 1385861 - Part 4. Reduce usage of SetMatrix in SVGTextFrame::PaintSVG. draft
authorcku <cku@mozilla.com>
Mon, 31 Jul 2017 20:47:39 +0800
changeset 619046 2d2f051f435b8180a2c9c548552f2aa3aa8f903e
parent 619045 ffc1421f987cd02ac47c0c6d512ce54856499f7c
child 640281 8b14be3f9e27c0dcef303dcad9f33d67f241f4ac
push id71556
push userbmo:cku@mozilla.com
push dateTue, 01 Aug 2017 13:55:40 +0000
bugs1385861
milestone56.0a1
Bug 1385861 - Part 4. Reduce usage of SetMatrix in SVGTextFrame::PaintSVG. In while-loop [1], 1. The first SetMatrix call that I remvoed in this patch is totally useless, we can just pass initialMatrix to contextPaint, instead of set initialMatrix to aContenxt and read back from aContext and then pass it to contextPaint. 2. This function, SVGTextFrame::PaintSVG, is the only caller of SetupStrokeGeometry, and it does not need SetupStrokeGeometry to setup matrix at all, since it will be overwritten the transform matrix of aContext at several lines below[2]. [1] https://hg.mozilla.org/mozilla-central/file/5115e2dea29a/layout/svg/SVGTextFrame.cpp#l3658 [2] https://hg.mozilla.org/mozilla-central/file/5115e2dea29a/layout/svg/SVGTextFrame.cpp#l3685 MozReview-Commit-ID: AlKQh4abbpa
layout/svg/SVGTextFrame.cpp
layout/svg/nsSVGUtils.cpp
--- a/layout/svg/SVGTextFrame.cpp
+++ b/layout/svg/SVGTextFrame.cpp
@@ -3656,23 +3656,19 @@ SVGTextFrame::PaintSVG(gfxContext& aCont
 
   while (run.mFrame) {
     nsTextFrame* frame = run.mFrame;
 
     // Determine how much of the left and right edges of the text frame we
     // need to ignore.
     SVGCharClipDisplayItem item(run);
 
-    // Set up the fill and stroke so that SVG glyphs can get painted correctly
-    // when they use context-fill etc.
-    aContext.SetMatrix(initialMatrix);
-
     RefPtr<SVGContextPaintImpl> contextPaint = new SVGContextPaintImpl();
     DrawMode drawMode = contextPaint->Init(&aDrawTarget,
-                                           aContext.CurrentMatrix(),
+                                           initialMatrix,
                                            frame, outerContextPaint,
                                            aImgParams);
     if (drawMode & DrawMode::GLYPH_STROKE) {
       ctxSR.EnsureSaved(&aContext);
       // This may change the gfxContext's transform (for non-scaling stroke),
       // in which case this needs to happen before we call SetMatrix() below.
       nsSVGUtils::SetupStrokeGeometry(frame, &aContext, outerContextPaint);
     }
--- a/layout/svg/nsSVGUtils.cpp
+++ b/layout/svg/nsSVGUtils.cpp
@@ -1729,23 +1729,16 @@ nsSVGUtils::SetupStrokeGeometry(nsIFrame
                                 gfxContext *aContext,
                                 SVGContextPaint* aContextPaint)
 {
   float width = GetStrokeWidth(aFrame, aContextPaint);
   if (width <= 0)
     return;
   aContext->SetLineWidth(width);
 
-  // Apply any stroke-specific transform
-  gfxMatrix outerSVGToUser;
-  if (GetNonScalingStrokeTransform(aFrame, &outerSVGToUser) &&
-      outerSVGToUser.Invert()) {
-    aContext->Multiply(outerSVGToUser);
-  }
-
   const nsStyleSVG* style = aFrame->StyleSVG();
 
   switch (style->mStrokeLinecap) {
   case NS_STYLE_STROKE_LINECAP_BUTT:
     aContext->SetLineCap(CapStyle::BUTT);
     break;
   case NS_STYLE_STROKE_LINECAP_ROUND:
     aContext->SetLineCap(CapStyle::ROUND);