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
--- 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 =