Bug 1257121 part 1 - Use struct for passing some params of font metrics. r=jfkthame
authorXidorn Quan <quanxunzhen@gmail.com>
Mon, 21 Mar 2016 11:59:36 +0800
changeset 327506 4af78cb017495e521731f0c60895289d051bc536
parent 327505 d5efe76a40b3e7d22a85e738b11cd1e567c1de16
child 327507 c3a24f3d0e6e22361e2d65777b85e2676b13808b
push id6048
push userkmoir@mozilla.com
push dateMon, 06 Jun 2016 19:02:08 +0000
treeherdermozilla-beta@46d72a56c57d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjfkthame
bugs1257121
milestone48.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1257121 part 1 - Use struct for passing some params of font metrics. r=jfkthame MozReview-Commit-ID: FTJlYS3bbTa
dom/canvas/CanvasRenderingContext2D.cpp
gfx/src/nsDeviceContext.cpp
gfx/src/nsDeviceContext.h
gfx/src/nsFontMetrics.cpp
gfx/src/nsFontMetrics.h
layout/base/nsLayoutUtils.cpp
layout/base/nsPresShell.cpp
layout/generic/MathMLTextRunFactory.cpp
layout/generic/nsPageFrame.cpp
layout/mathml/nsMathMLChar.cpp
layout/style/nsRuleNode.cpp
--- a/dom/canvas/CanvasRenderingContext2D.cpp
+++ b/dom/canvas/CanvasRenderingContext2D.cpp
@@ -2463,22 +2463,23 @@ public:
   virtual float GetEmLength() const override
   {
     return NSAppUnitsToFloatPixels(mFont.size,
                                    nsPresContext::AppUnitsPerCSSPixel());
   }
 
   virtual float GetExLength() const override
   {
-    gfxTextPerfMetrics* tp = mPresContext->GetTextPerfMetrics();
     RefPtr<nsFontMetrics> fontMetrics;
     nsDeviceContext* dc = mPresContext->DeviceContext();
-    dc->GetMetricsFor(mFont, mFontLanguage, mExplicitLanguage,
-                      gfxFont::eHorizontal, nullptr, tp,
-                      *getter_AddRefs(fontMetrics));
+    nsFontMetrics::Params params;
+    params.language = mFontLanguage;
+    params.explicitLanguage = mExplicitLanguage;
+    params.textPerf = mPresContext->GetTextPerfMetrics();
+    dc->GetMetricsFor(mFont, params, *getter_AddRefs(fontMetrics));
     return NSAppUnitsToFloatPixels(fontMetrics->XHeight(),
                                    nsPresContext::AppUnitsPerCSSPixel());
   }
 
   virtual gfx::Size GetSize() const override
   { return Size(mSize); }
 
 private:
@@ -3225,23 +3226,23 @@ CanvasRenderingContext2D::SetFontInterna
   // device pixels, to avoid being affected by page zoom. nsFontMetrics will
   // convert nsFont size in app units to device pixels for the font group, so
   // here we first apply to the size the equivalent of a conversion from device
   // pixels to CSS pixels, to adjust for the difference in expectations from
   // other nsFontMetrics clients.
   resizedFont.size =
     (fontStyle->mSize * c->AppUnitsPerDevPixel()) / c->AppUnitsPerCSSPixel();
 
+  nsFontMetrics::Params params;
+  params.language = fontStyle->mLanguage;
+  params.explicitLanguage = fontStyle->mExplicitLanguage;
+  params.userFontSet = c->GetUserFontSet();
+  params.textPerf = c->GetTextPerfMetrics();
   RefPtr<nsFontMetrics> metrics;
-  c->DeviceContext()->GetMetricsFor(resizedFont,
-                                    fontStyle->mLanguage,
-                                    fontStyle->mExplicitLanguage,
-                                    gfxFont::eHorizontal,
-                                    c->GetUserFontSet(),
-                                    c->GetTextPerfMetrics(),
+  c->DeviceContext()->GetMetricsFor(resizedFont, params,
                                     *getter_AddRefs(metrics));
 
   gfxFontGroup* newFontGroup = metrics->GetThebesFontGroup();
   CurrentState().fontGroup = newFontGroup;
   NS_ASSERTION(CurrentState().fontGroup, "Could not get font group");
   CurrentState().font = usedFont;
   CurrentState().fontFont = fontStyle->mFont;
   CurrentState().fontFont.size = fontStyle->mSize;
--- a/gfx/src/nsDeviceContext.cpp
+++ b/gfx/src/nsDeviceContext.cpp
@@ -60,20 +60,17 @@ public:
 
     NS_DECL_ISUPPORTS
     NS_DECL_NSIOBSERVER
 
     void Init(nsDeviceContext* aContext);
     void Destroy();
 
     nsresult GetMetricsFor(const nsFont& aFont,
-                           nsIAtom* aLanguage, bool aExplicitLanguage,
-                           gfxFont::Orientation aOrientation,
-                           gfxUserFontSet* aUserFontSet,
-                           gfxTextPerfMetrics* aTextPerf,
+                           const nsFontMetrics::Params& aParams,
                            nsFontMetrics*& aMetrics);
 
     void FontMetricsDeleted(const nsFontMetrics* aFontMetrics);
     void Compact();
     void Flush();
 
 protected:
     ~nsFontCache()  { MOZ_COUNT_DTOR(nsFontCache); }
@@ -122,51 +119,51 @@ nsFontCache::Observe(nsISupports*, const
 {
     if (!nsCRT::strcmp(aTopic, "memory-pressure"))
         Compact();
     return NS_OK;
 }
 
 nsresult
 nsFontCache::GetMetricsFor(const nsFont& aFont,
-                           nsIAtom* aLanguage, bool aExplicitLanguage,
-                           gfxFont::Orientation aOrientation,
-                           gfxUserFontSet* aUserFontSet,
-                           gfxTextPerfMetrics* aTextPerf,
+                           const nsFontMetrics::Params& aParams,
                            nsFontMetrics*& aMetrics)
 {
-    if (!aLanguage)
-        aLanguage = mLocaleLanguage;
+    nsIAtom* language = aParams.language ? aParams.language
+                                         : mLocaleLanguage.get();
 
     // First check our cache
     // start from the end, which is where we put the most-recent-used element
 
     nsFontMetrics* fm;
     int32_t n = mFontMetrics.Length() - 1;
     for (int32_t i = n; i >= 0; --i) {
         fm = mFontMetrics[i];
-        if (fm->Font().Equals(aFont) && fm->GetUserFontSet() == aUserFontSet &&
-            fm->Language() == aLanguage && fm->Orientation() == aOrientation) {
+        if (fm->Font().Equals(aFont) &&
+            fm->GetUserFontSet() == aParams.userFontSet &&
+            fm->Language() == language &&
+            fm->Orientation() == aParams.orientation) {
             if (i != n) {
                 // promote it to the end of the cache
                 mFontMetrics.RemoveElementAt(i);
                 mFontMetrics.AppendElement(fm);
             }
             fm->GetThebesFontGroup()->UpdateUserFonts();
             NS_ADDREF(aMetrics = fm);
             return NS_OK;
         }
     }
 
     // It's not in the cache. Get font metrics and then cache them.
 
+    nsFontMetrics::Params params = aParams;
+    params.language = language;
     fm = new nsFontMetrics();
     NS_ADDREF(fm);
-    nsresult rv = fm->Init(aFont, aLanguage, aExplicitLanguage, aOrientation,
-                           mContext, aUserFontSet, aTextPerf);
+    nsresult rv = fm->Init(aFont, params, mContext);
     if (NS_SUCCEEDED(rv)) {
         // the mFontMetrics list has the "head" at the end, because append
         // is cheaper than insert
         mFontMetrics.AppendElement(fm);
         aMetrics = fm;
         NS_ADDREF(aMetrics);
         return NS_OK;
     }
@@ -175,18 +172,17 @@ nsFontCache::GetMetricsFor(const nsFont&
 
     // One reason why Init() fails is because the system is running out of
     // resources. e.g., on Win95/98 only a very limited number of GDI
     // objects are available. Compact the cache and try again.
 
     Compact();
     fm = new nsFontMetrics();
     NS_ADDREF(fm);
-    rv = fm->Init(aFont, aLanguage, aExplicitLanguage, aOrientation, mContext,
-                  aUserFontSet, aTextPerf);
+    rv = fm->Init(aFont, params, mContext);
     if (NS_SUCCEEDED(rv)) {
         mFontMetrics.AppendElement(fm);
         aMetrics = fm;
         return NS_OK;
     }
     fm->Destroy();
     NS_RELEASE(fm);
 
@@ -263,32 +259,26 @@ nsDeviceContext::~nsDeviceContext()
     if (mFontCache) {
         mFontCache->Destroy();
         NS_RELEASE(mFontCache);
     }
 }
 
 nsresult
 nsDeviceContext::GetMetricsFor(const nsFont& aFont,
-                               nsIAtom* aLanguage,
-                               bool aExplicitLanguage,
-                               gfxFont::Orientation aOrientation,
-                               gfxUserFontSet* aUserFontSet,
-                               gfxTextPerfMetrics* aTextPerf,
+                               const nsFontMetrics::Params& aParams,
                                nsFontMetrics*& aMetrics)
 {
     if (!mFontCache) {
         mFontCache = new nsFontCache();
         NS_ADDREF(mFontCache);
         mFontCache->Init(this);
     }
 
-    return mFontCache->GetMetricsFor(aFont, aLanguage, aExplicitLanguage,
-                                     aOrientation, aUserFontSet, aTextPerf,
-                                     aMetrics);
+    return mFontCache->GetMetricsFor(aFont, aParams, aMetrics);
 }
 
 nsresult
 nsDeviceContext::FlushFontCache(void)
 {
     if (mFontCache)
         mFontCache->Flush();
     return NS_OK;
--- a/gfx/src/nsDeviceContext.h
+++ b/gfx/src/nsDeviceContext.h
@@ -14,24 +14,24 @@
 #include "nsAutoPtr.h"                  // for nsRefPtr
 #include "nsCOMPtr.h"                   // for nsCOMPtr
 #include "nsCoord.h"                    // for nscoord
 #include "nsError.h"                    // for nsresult
 #include "nsISupports.h"                // for NS_INLINE_DECL_REFCOUNTING
 #include "nsMathUtils.h"                // for NS_round
 #include "nscore.h"                     // for char16_t, nsAString
 #include "mozilla/AppUnits.h"           // for AppUnits
+#include "nsFontMetrics.h"              // for nsFontMetrics::Params
 
 class gfxASurface;
 class gfxContext;
 class gfxTextPerfMetrics;
 class gfxUserFontSet;
 struct nsFont;
 class nsFontCache;
-class nsFontMetrics;
 class nsIAtom;
 class nsIDeviceContextSpec;
 class nsIScreen;
 class nsIScreenManager;
 class nsIWidget;
 struct nsRect;
 
 class nsDeviceContext final
@@ -108,26 +108,21 @@ public:
      */
     int32_t AppUnitsPerDevPixelAtUnitFullZoom() const
     { return mAppUnitsPerDevPixelAtUnitFullZoom; }
 
     /**
      * Get the nsFontMetrics that describe the properties of
      * an nsFont.
      * @param aFont font description to obtain metrics for
-     * @param aLanguage the language of the document
      * @param aMetrics out parameter for font metrics
-     * @param aUserFontSet user font set
      * @return error status
      */
     nsresult GetMetricsFor(const nsFont& aFont,
-                           nsIAtom* aLanguage, bool aExplicitLanguage,
-                           gfxFont::Orientation aOrientation,
-                           gfxUserFontSet* aUserFontSet,
-                           gfxTextPerfMetrics* aTextPerf,
+                           const nsFontMetrics::Params& aParams,
                            nsFontMetrics*& aMetrics);
 
     /**
      * Notification when a font metrics instance created for this device is
      * about to be deleted
      */
     nsresult FontMetricsDeleted(const nsFontMetrics* aFontMetrics);
 
--- a/gfx/src/nsFontMetrics.cpp
+++ b/gfx/src/nsFontMetrics.cpp
@@ -116,51 +116,47 @@ nsFontMetrics::nsFontMetrics()
 
 nsFontMetrics::~nsFontMetrics()
 {
     if (mDeviceContext)
         mDeviceContext->FontMetricsDeleted(this);
 }
 
 nsresult
-nsFontMetrics::Init(const nsFont& aFont,
-                    nsIAtom* aLanguage, bool aExplicitLanguage,
-                    gfxFont::Orientation aOrientation,
-                    nsDeviceContext *aContext,
-                    gfxUserFontSet *aUserFontSet,
-                    gfxTextPerfMetrics *aTextPerf)
+nsFontMetrics::Init(const nsFont& aFont, const Params& aParams,
+                    nsDeviceContext *aContext)
 {
     MOZ_ASSERT(mP2A == 0, "already initialized");
 
     mFont = aFont;
-    mLanguage = aLanguage;
-    mOrientation = aOrientation;
+    mLanguage = aParams.language;
+    mOrientation = aParams.orientation;
     mDeviceContext = aContext;
     mP2A = mDeviceContext->AppUnitsPerDevPixel();
 
     gfxFontStyle style(aFont.style,
                        aFont.weight,
                        aFont.stretch,
                        gfxFloat(aFont.size) / mP2A,
-                       aLanguage,
-                       aExplicitLanguage,
+                       aParams.language,
+                       aParams.explicitLanguage,
                        aFont.sizeAdjust,
                        aFont.systemFont,
                        mDeviceContext->IsPrinterSurface(),
                        aFont.synthesis & NS_FONT_SYNTHESIS_WEIGHT,
                        aFont.synthesis & NS_FONT_SYNTHESIS_STYLE,
                        aFont.languageOverride);
 
     aFont.AddFontFeaturesToStyle(&style);
 
     gfxFloat devToCssSize = gfxFloat(mP2A) /
         gfxFloat(mDeviceContext->AppUnitsPerCSSPixel());
     mFontGroup = gfxPlatform::GetPlatform()->
-        CreateFontGroup(aFont.fontlist, &style, aTextPerf,
-                        aUserFontSet, devToCssSize);
+        CreateFontGroup(aFont.fontlist, &style, aParams.textPerf,
+                        aParams.userFontSet, devToCssSize);
     return NS_OK;
 }
 
 void
 nsFontMetrics::Destroy()
 {
     mDeviceContext = nullptr;
 }
--- a/gfx/src/nsFontMetrics.h
+++ b/gfx/src/nsFontMetrics.h
@@ -44,32 +44,35 @@ struct nsBoundingMetrics;
  * reasonably well with the Western font that is loaded at Init time.
  */
 class nsFontMetrics final
 {
 public:
     typedef gfxTextRun::Range Range;
     typedef mozilla::gfx::DrawTarget DrawTarget;
 
+    struct Params
+    {
+      nsIAtom* language = nullptr;
+      bool explicitLanguage = false;
+      gfxFont::Orientation orientation = gfxFont::eHorizontal;
+      gfxUserFontSet* userFontSet = nullptr;
+      gfxTextPerfMetrics* textPerf = nullptr;
+    };
+
     nsFontMetrics();
 
     NS_INLINE_DECL_REFCOUNTING(nsFontMetrics)
 
     /**
      * Initialize the font metrics. Call this after creating the font metrics.
      * Font metrics you get from the font cache do NOT need to be initialized
-     *
-     * @see nsDeviceContext#GetMetricsFor()
      */
-    nsresult Init(const nsFont& aFont,
-                  nsIAtom* aLanguage, bool aExplicitLanguage,
-                  gfxFont::Orientation aOrientation,
-                  nsDeviceContext *aContext,
-                  gfxUserFontSet *aUserFontSet,
-                  gfxTextPerfMetrics *aTextPerf);
+    nsresult Init(const nsFont& aFont, const Params& aParams,
+                  nsDeviceContext *aContext);
 
     /**
      * Destroy this font metrics. This breaks the association between
      * the font metrics and the device context.
      */
     void Destroy();
 
     /**
--- a/layout/base/nsLayoutUtils.cpp
+++ b/layout/base/nsLayoutUtils.cpp
@@ -4034,46 +4034,43 @@ nsLayoutUtils::GetFontMetricsForFrame(co
                                                       aInflation);
 }
 
 nsresult
 nsLayoutUtils::GetFontMetricsForStyleContext(nsStyleContext* aStyleContext,
                                              nsFontMetrics** aFontMetrics,
                                              float aInflation)
 {
-  // pass the user font set object into the device context to pass along to CreateFontGroup
   nsPresContext* pc = aStyleContext->PresContext();
-  gfxUserFontSet* fs = pc->GetUserFontSet();
-  gfxTextPerfMetrics* tp = pc->GetTextPerfMetrics();
 
   WritingMode wm(aStyleContext);
-  gfxFont::Orientation orientation =
+  const nsStyleFont* styleFont = aStyleContext->StyleFont();
+  nsFontMetrics::Params params;
+  params.language = styleFont->mLanguage;
+  params.explicitLanguage = styleFont->mExplicitLanguage;
+  params.orientation =
     wm.IsVertical() && !wm.IsSideways() ? gfxFont::eVertical
                                         : gfxFont::eHorizontal;
-
-  const nsStyleFont* styleFont = aStyleContext->StyleFont();
+  // pass the user font set object into the device context to
+  // pass along to CreateFontGroup
+  params.userFontSet = pc->GetUserFontSet();
+  params.textPerf = pc->GetTextPerfMetrics();
 
   // When aInflation is 1.0, avoid making a local copy of the nsFont.
   // This also avoids running font.size through floats when it is large,
   // which would be lossy.  Fortunately, in such cases, aInflation is
   // guaranteed to be 1.0f.
   if (aInflation == 1.0f) {
-    return pc->DeviceContext()->GetMetricsFor(styleFont->mFont,
-                                              styleFont->mLanguage,
-                                              styleFont->mExplicitLanguage,
-                                              orientation, fs, tp,
+    return pc->DeviceContext()->GetMetricsFor(styleFont->mFont, params,
                                               *aFontMetrics);
   }
 
   nsFont font = styleFont->mFont;
   font.size = NSToCoordRound(font.size * aInflation);
-  return pc->DeviceContext()->GetMetricsFor(font, styleFont->mLanguage,
-                                            styleFont->mExplicitLanguage,
-                                            orientation, fs, tp,
-                                            *aFontMetrics);
+  return pc->DeviceContext()->GetMetricsFor(font, params, *aFontMetrics);
 }
 
 nsIFrame*
 nsLayoutUtils::FindChildContainingDescendant(nsIFrame* aParent, nsIFrame* aDescendantFrame)
 {
   nsIFrame* result = aDescendantFrame;
 
   while (result) {
--- a/layout/base/nsPresShell.cpp
+++ b/layout/base/nsPresShell.cpp
@@ -10336,20 +10336,22 @@ void ReflowCountMgr::PaintCount(const ch
       gfxPoint devPixelOffset =
         nsLayoutUtils::PointToGfxPoint(aOffset, appUnitsPerDevPixel);
       aRenderingContext->ThebesContext()->SetMatrix(
         aRenderingContext->ThebesContext()->CurrentMatrix().Translate(devPixelOffset));
 
       // We don't care about the document language or user fonts here;
       // just get a default Latin font.
       nsFont font(eFamily_serif, nsPresContext::CSSPixelsToAppUnits(11));
+      nsFontMetrics::Params params;
+      params.language = nsGkAtoms::x_western;
+      params.textPerf = aPresContext->GetTextPerfMetrics();
       RefPtr<nsFontMetrics> fm;
-      aPresContext->DeviceContext()->GetMetricsFor(font,
-        nsGkAtoms::x_western, false, gfxFont::eHorizontal, nullptr,
-        aPresContext->GetTextPerfMetrics(), *getter_AddRefs(fm));
+      aPresContext->DeviceContext()->
+        GetMetricsFor(font, params, *getter_AddRefs(fm));
 
       char buf[16];
       int len = snprintf_literal(buf, "%d", counter->mCount);
       nscoord x = 0, y = fm->MaxAscent();
       nscoord width, height = fm->MaxHeight();
       fm->SetTextRunRTL(false);
       width = fm->GetWidth(buf, len, drawTarget);
 
--- a/layout/generic/MathMLTextRunFactory.cpp
+++ b/layout/generic/MathMLTextRunFactory.cpp
@@ -736,24 +736,23 @@ MathMLTextRunFactory::RebuildTextRun(nsT
     font.weight = NS_FONT_WEIGHT_NORMAL;
   }
   gfxFontGroup* newFontGroup = nullptr;
 
   // Get the correct gfxFontGroup that corresponds to the earlier font changes.
   if (length) {
     font.size = NSToCoordRound(font.size * mFontInflation);
     nsPresContext* pc = styles[0]->mPresContext;
+    nsFontMetrics::Params params;
+    params.language = styles[0]->mLanguage;
+    params.explicitLanguage = styles[0]->mExplicitLanguage;
+    params.userFontSet = pc->GetUserFontSet();
+    params.textPerf = pc->GetTextPerfMetrics();
     RefPtr<nsFontMetrics> metrics;
-    pc->DeviceContext()->GetMetricsFor(font,
-                                       styles[0]->mLanguage,
-                                       styles[0]->mExplicitLanguage,
-                                       gfxFont::eHorizontal,
-                                       pc->GetUserFontSet(),
-                                       pc->GetTextPerfMetrics(),
-                                       *getter_AddRefs(metrics));
+    pc->DeviceContext()->GetMetricsFor(font, params, *getter_AddRefs(metrics));
     if (metrics) {
       newFontGroup = metrics->GetThebesFontGroup();
     }
   }
 
   if (!newFontGroup) {
     // If we can't get a new font group, fall back to the old one.  Rendering
     // will be incorrect, but not significantly so.
--- a/layout/generic/nsPageFrame.cpp
+++ b/layout/generic/nsPageFrame.cpp
@@ -625,21 +625,21 @@ nsPageFrame::PaintHeaderFooter(nsRenderi
 
   nsRect rect(aPt, mRect.Size());
   aRenderingContext.ThebesContext()->SetColor(Color(0.f, 0.f, 0.f));
 
   DrawTargetAutoDisableSubpixelAntialiasing
     disable(aRenderingContext.GetDrawTarget(), aDisableSubpixelAA);
 
   // Get the FontMetrics to determine width.height of strings
+  nsFontMetrics::Params params;
+  params.userFontSet = pc->GetUserFontSet();
+  params.textPerf = pc->GetTextPerfMetrics();
   RefPtr<nsFontMetrics> fontMet;
-  pc->DeviceContext()->GetMetricsFor(mPD->mHeadFootFont, nullptr, false,
-                                     gfxFont::eHorizontal,
-                                     pc->GetUserFontSet(),
-                                     pc->GetTextPerfMetrics(),
+  pc->DeviceContext()->GetMetricsFor(mPD->mHeadFootFont, params,
                                      *getter_AddRefs(fontMet));
 
   nscoord ascent = 0;
   nscoord visibleHeight = 0;
   if (fontMet) {
     visibleHeight = fontMet->MaxHeight();
     ascent = fontMet->MaxAscent();
   }
--- a/layout/mathml/nsMathMLChar.cpp
+++ b/layout/mathml/nsMathMLChar.cpp
@@ -986,25 +986,24 @@ nsMathMLChar::SetFontFamily(nsPresContex
 
   const FontFamilyList& familyList =
     aGlyphCode.font ? glyphCodeFont : aDefaultFamilyList;
 
   if (!*aFontGroup || !(aFont.fontlist == familyList)) {
     nsFont font = aFont;
     font.fontlist = familyList;
     const nsStyleFont* styleFont = mStyleContext->StyleFont();
+    nsFontMetrics::Params params;
+    params.language = styleFont->mLanguage;
+    params.explicitLanguage = styleFont->mExplicitLanguage;
+    params.userFontSet = aPresContext->GetUserFontSet();
+    params.textPerf = aPresContext->GetTextPerfMetrics();
     RefPtr<nsFontMetrics> fm;
     aPresContext->DeviceContext()->
-      GetMetricsFor(font,
-                    styleFont->mLanguage,
-                    styleFont->mExplicitLanguage,
-                    gfxFont::eHorizontal,
-                    aPresContext->GetUserFontSet(),
-                    aPresContext->GetTextPerfMetrics(),
-                    *getter_AddRefs(fm));
+      GetMetricsFor(font, params, *getter_AddRefs(fm));
     // Set the font if it is an unicode table
     // or if the same family name has been found
     gfxFont *firstFont = fm->GetThebesFontGroup()->GetFirstValidFont();
     FontFamilyList firstFontList;
     firstFontList.Append(
       FontFamilyName(firstFont->GetFontEntry()->FamilyName(), eUnquotedName));
     if (aGlyphTable == &gGlyphTableList->mUnicodeTable ||
         firstFontList == familyList) {
@@ -1528,25 +1527,24 @@ nsMathMLChar::StretchInternal(nsPresCont
 
   // Set default font and get the default bounding metrics
   // mStyleContext is a leaf context used only when stretching happens.
   // For the base size, the default font should come from the parent context
   nsFont font = mStyleContext->GetParent()->StyleFont()->mFont;
   NormalizeDefaultFont(font, aFontSizeInflation);
 
   const nsStyleFont* styleFont = mStyleContext->StyleFont();
+  nsFontMetrics::Params params;
+  params.language = styleFont->mLanguage;
+  params.explicitLanguage = styleFont->mExplicitLanguage;
+  params.userFontSet = aPresContext->GetUserFontSet();
+  params.textPerf = aPresContext->GetTextPerfMetrics();
   RefPtr<nsFontMetrics> fm;
   aPresContext->DeviceContext()->
-    GetMetricsFor(font,
-                  styleFont->mLanguage,
-                  styleFont->mExplicitLanguage,
-                  gfxFont::eHorizontal,
-                  aPresContext->GetUserFontSet(),
-                  aPresContext->GetTextPerfMetrics(),
-                  *getter_AddRefs(fm));
+    GetMetricsFor(font, params, *getter_AddRefs(fm));
   uint32_t len = uint32_t(mData.Length());
   nsAutoPtr<gfxTextRun> textRun;
   textRun = fm->GetThebesFontGroup()->
     MakeTextRun(static_cast<const char16_t*>(mData.get()), len, aDrawTarget,
                 aPresContext->AppUnitsPerDevPixel(), 0,
                 aPresContext->MissingFontRecorder());
   aDesiredStretchSize = MeasureTextRun(aDrawTarget, textRun);
   mGlyphs[0] = textRun;
--- a/layout/style/nsRuleNode.cpp
+++ b/layout/style/nsRuleNode.cpp
@@ -316,34 +316,33 @@ already_AddRefed<nsFontMetrics>
 GetMetricsFor(nsPresContext* aPresContext,
               nsStyleContext* aStyleContext,
               const nsStyleFont* aStyleFont,
               nscoord aFontSize, // overrides value from aStyleFont
               bool aUseUserFontSet)
 {
   nsFont font = aStyleFont->mFont;
   font.size = aFontSize;
-  gfxUserFontSet *fs = nullptr;
-  if (aUseUserFontSet) {
-    fs = aPresContext->GetUserFontSet();
-  }
-  gfxTextPerfMetrics *tp = aPresContext->GetTextPerfMetrics();
   gfxFont::Orientation orientation = gfxFont::eHorizontal;
   if (aStyleContext) {
     WritingMode wm(aStyleContext);
     if (wm.IsVertical() && !wm.IsSideways()) {
       orientation = gfxFont::eVertical;
     }
   }
+  nsFontMetrics::Params params;
+  params.language = aStyleFont->mLanguage;
+  params.explicitLanguage = aStyleFont->mExplicitLanguage;
+  params.orientation = orientation;
+  params.userFontSet =
+    aUseUserFontSet ? aPresContext->GetUserFontSet() : nullptr;
+  params.textPerf = aPresContext->GetTextPerfMetrics();
   RefPtr<nsFontMetrics> fm;
-  aPresContext->DeviceContext()->GetMetricsFor(font,
-                                               aStyleFont->mLanguage,
-                                               aStyleFont->mExplicitLanguage,
-                                               orientation,
-                                               fs, tp, *getter_AddRefs(fm));
+  aPresContext->DeviceContext()->
+    GetMetricsFor(font, params, *getter_AddRefs(fm));
   return fm.forget();
 }
 
 
 static nsSize CalcViewportUnitsScale(nsPresContext* aPresContext)
 {
   // The caller is making use of viewport units, so notify the pres context
   // that it will need to rebuild the rule tree if the size of the viewport