Bug 1385861 - Part 4. Define contextPaint as a local variable. draft
authorcku <cku@mozilla.com>
Mon, 31 Jul 2017 22:16:09 +0800
changeset 618492 c8c5b992a59da0e5dc0cf11f1d7242afed8a9054
parent 618491 3f3d051191a038bb4229306e91b4da852ed3fbf6
child 618493 a1e167ca51f2a6e3a71bff08c3ecd247926e059a
push id71358
push userbmo:cku@mozilla.com
push dateMon, 31 Jul 2017 15:45:26 +0000
bugs1385861
milestone56.0a1
Bug 1385861 - Part 4. Define contextPaint as a local variable. To prevent heap allocation in painting. MozReview-Commit-ID: DVssJdWuvk0
layout/svg/SVGTextFrame.cpp
--- a/layout/svg/SVGTextFrame.cpp
+++ b/layout/svg/SVGTextFrame.cpp
@@ -3660,21 +3660,21 @@ SVGTextFrame::PaintSVG(gfxContext& aCont
     // 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(),
-                                           frame, outerContextPaint,
-                                           aImgParams);
+    SVGContextPaintImpl contextPaint;
+    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::SetupStrokeGeometry(frame, &aContext, outerContextPaint);
     }
 
     // Set up the transform for painting the text frame for the substring
@@ -3685,26 +3685,25 @@ SVGTextFrame::PaintSVG(gfxContext& aCont
     aContext.SetMatrix(runTransform);
 
     if (drawMode != DrawMode(0)) {
       bool paintSVGGlyphs;
       nsTextFrame::PaintTextParams params(&aContext);
       params.framePt = gfxPoint();
       params.dirtyRect = LayoutDevicePixel::
         FromAppUnits(frame->GetVisualOverflowRect(), auPerDevPx);
-      params.contextPaint = contextPaint;
+      params.contextPaint = &contextPaint;
       if (ShouldRenderAsPath(frame, paintSVGGlyphs)) {
         SVGTextDrawPathCallbacks callbacks(this, aContext, frame,
                                            matrixForPaintServers,
                                            paintSVGGlyphs);
         params.callbacks = &callbacks;
-        frame->PaintText(params, item);
-      } else {
-        frame->PaintText(params, item);
       }
+
+      frame->PaintText(params, item);
     }
 
     if (frame == caretFrame && ShouldPaintCaret(run, caret)) {
       ctxSR.EnsureSaved(&aContext);
       // XXX Should we be looking at the fill/stroke colours to paint the
       // caret with, rather than using the color property?
       caret->PaintCaret(aDrawTarget, frame, nsPoint());
       aContext.NewPath();