Bug 1385861 - Part 2. Save the state of input context in SVGTextFrame::PaintSVG only when need. draft
authorcku <cku@mozilla.com>
Mon, 31 Jul 2017 20:17:06 +0800
changeset 619044 04ed3483cbb2a42a2774118d492ff2e75508a634
parent 619043 e0018d66e1b34a5e8ff864abbed6fe2400f06f9b
child 619045 ffc1421f987cd02ac47c0c6d512ce54856499f7c
push id71556
push userbmo:cku@mozilla.com
push dateTue, 01 Aug 2017 13:55:40 +0000
bugs1385861
milestone56.0a1
Bug 1385861 - Part 2. Save the state of input context in SVGTextFrame::PaintSVG only when need. Unless we need to draw stroke of glyphs, which will change the state of the target context, we only need to save & restore transform matrix of the target context. MozReview-Commit-ID: LLKnxrKrDaT
layout/svg/SVGTextFrame.cpp
--- a/layout/svg/SVGTextFrame.cpp
+++ b/layout/svg/SVGTextFrame.cpp
@@ -3633,25 +3633,26 @@ SVGTextFrame::PaintSVG(gfxContext& aCont
   // dev pixels. Here we multiply a CSS-px-to-dev-pixel factor onto aTransform
   // so our non-SVG nsTextFrame children paint correctly.
   auto auPerDevPx = presContext->AppUnitsPerDevPixel();
   float cssPxPerDevPx = presContext->AppUnitsToFloatCSSPixels(auPerDevPx);
   gfxMatrix canvasTMForChildren = aTransform;
   canvasTMForChildren.PreScale(cssPxPerDevPx, cssPxPerDevPx);
   initialMatrix.PreScale(1 / cssPxPerDevPx, 1 / cssPxPerDevPx);
 
-  gfxContextAutoSaveRestore save(&aContext);
+  gfxContextMatrixAutoSaveRestore matSR(&aContext);
   aContext.NewPath();
   aContext.Multiply(canvasTMForChildren);
   gfxMatrix currentMatrix = aContext.CurrentMatrix();
 
   RefPtr<nsCaret> caret = presContext->PresShell()->GetCaret();
   nsRect caretRect;
   nsIFrame* caretFrame = caret->GetPaintGeometry(&caretRect);
 
+  gfxContextAutoSaveRestore ctxSR;
   TextRenderedRunIterator it(this, TextRenderedRunIterator::eVisibleFrames);
   TextRenderedRun run = it.Current();
 
   SVGContextPaint* outerContextPaint =
     SVGContextPaint::GetContextPaint(mContent);
 
   while (run.mFrame) {
     nsTextFrame* frame = run.mFrame;
@@ -3665,16 +3666,17 @@ SVGTextFrame::PaintSVG(gfxContext& aCont
     aContext.SetMatrix(initialMatrix);
 
     RefPtr<SVGContextPaintImpl> contextPaint = new SVGContextPaintImpl();
     DrawMode drawMode = contextPaint->Init(&aDrawTarget,
                                            aContext.CurrentMatrix(),
                                            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::SetupCairoStrokeGeometry(frame, &aContext, outerContextPaint);
     }
 
     // Set up the transform for painting the text frame for the substring
     // indicated by the run.
     gfxMatrix runTransform =