Bug 1379404 - Part 2. Prevent using gfxContext::Save/Restore in gfxFont. draft
authorcku <cku@mozilla.com>
Sun, 09 Jul 2017 00:24:37 +0800
changeset 605960 c1255ef2980c265e486e22d591659b98499a94fe
parent 605959 77b761e144bc345b6f30a67029f5fa5832e1e41b
child 605961 7dd59aa052aea4b54afc1596de187660243a4aca
push id67564
push userbmo:cku@mozilla.com
push dateMon, 10 Jul 2017 05:06:36 +0000
bugs1379404
milestone56.0a1
Bug 1379404 - Part 2. Prevent using gfxContext::Save/Restore in gfxFont. MozReview-Commit-ID: 7uIQDfK8gG2
gfx/thebes/gfxFont.cpp
--- a/gfx/thebes/gfxFont.cpp
+++ b/gfx/thebes/gfxFont.cpp
@@ -2065,20 +2065,22 @@ gfxFont::Draw(const gfxTextRun *aTextRun
 
     fontParams.haveSVGGlyphs = GetFontEntry()->TryGetSVGData(this);
     fontParams.haveColorGlyphs = GetFontEntry()->TryGetColorGlyphs();
     fontParams.contextPaint = aRunParams.runContextPaint;
     fontParams.isVerticalFont =
         aOrientation == gfx::ShapedTextFlags::TEXT_ORIENT_VERTICAL_UPRIGHT;
 
     bool sideways = false;
+    gfxContextMatrixAutoSaveRestore matrixRestore;
+
     gfxPoint origPt = *aPt;
     if (aRunParams.isVerticalRun && !fontParams.isVerticalFont) {
         sideways = true;
-        aRunParams.context->Save();
+        matrixRestore.SetContext(aRunParams.context);
         gfxPoint p(aPt->x * aRunParams.devPerApp,
                    aPt->y * aRunParams.devPerApp);
         const Metrics& metrics = GetMetrics(eHorizontal);
         // Get a matrix we can use to draw the (horizontally-shaped) textrun
         // with 90-degree CW rotation.
         const gfxFloat
             rotation = (aOrientation ==
                         gfx::ShapedTextFlags::TEXT_ORIENT_VERTICAL_SIDEWAYS_LEFT)
@@ -2193,17 +2195,16 @@ gfxFont::Draw(const gfxTextRun *aTextRun
     if (aRunParams.callbacks && emittedGlyphs) {
         aRunParams.callbacks->NotifyGlyphPathEmitted();
     }
 
     aRunParams.dt->SetTransform(oldMat);
     aRunParams.dt->SetPermitSubpixelAA(oldSubpixelAA);
 
     if (sideways) {
-        aRunParams.context->Restore();
         // adjust updated aPt to account for the transform we were using
         gfxFloat advance = aPt->x - origPt.x;
         if (aOrientation ==
             gfx::ShapedTextFlags::TEXT_ORIENT_VERTICAL_SIDEWAYS_LEFT) {
             *aPt = gfxPoint(origPt.x, origPt.y - advance);
         } else {
             *aPt = gfxPoint(origPt.x, origPt.y + advance);
         }
@@ -2217,25 +2218,23 @@ gfxFont::RenderSVGGlyph(gfxContext *aCon
     if (!GetFontEntry()->HasSVGGlyph(aGlyphId)) {
         return false;
     }
 
     const gfxFloat devUnitsPerSVGUnit =
         GetAdjustedSize() / GetFontEntry()->UnitsPerEm();
     gfxContextMatrixAutoSaveRestore matrixRestore(aContext);
 
-    aContext->Save();
     aContext->SetMatrix(
       aContext->CurrentMatrix().PreTranslate(aPoint.x, aPoint.y).
                                 PreScale(devUnitsPerSVGUnit, devUnitsPerSVGUnit));
 
     aContextPaint->InitStrokeGeometry(aContext, devUnitsPerSVGUnit);
 
     GetFontEntry()->RenderSVGGlyph(aContext, aGlyphId, aContextPaint);
-    aContext->Restore();
     aContext->NewPath();
     return true;
 }
 
 bool
 gfxFont::RenderSVGGlyph(gfxContext *aContext, gfxPoint aPoint,
                         uint32_t aGlyphId, SVGContextPaint* aContextPaint,
                         gfxTextRunDrawCallbacks *aCallbacks,