Bug 1403592 - Never flush the user font set when getting font metrics from style resolution. r=Manishearth, a=sledru
authorEmilio Cobos Álvarez <emilio@crisal.io>
Wed, 27 Sep 2017 18:09:31 +0200
changeset 434441 1322c11127a063fc0172f8519b06e04380917163
parent 434440 c786424818eae74178d9412cf999507be271d3cd
child 434442 f98a2bd7044165abb4e6244e1f6448596897fba8
push id1567
push userjlorenzo@mozilla.com
push dateThu, 02 Nov 2017 12:36:05 +0000
treeherdermozilla-release@e512c14a0406 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersManishearth, sledru
bugs1403592
milestone57.0
Bug 1403592 - Never flush the user font set when getting font metrics from style resolution. r=Manishearth, a=sledru In this case, the caller doesn't go through all the PreTraverseSync stuff (we don't really want it to do so), via GetComputedStyleNoFlush. It makes sense to not flush the user font set that case, we'll schedule a restyle properly if / when needed. Since the set should be flushed otherwise, let's just not flush it from the styling code. MozReview-Commit-ID: LLHfxemJ8QQ
layout/style/ServoBindings.cpp
layout/style/nsRuleNode.cpp
layout/style/nsRuleNode.h
--- a/layout/style/ServoBindings.cpp
+++ b/layout/style/ServoBindings.cpp
@@ -2477,19 +2477,20 @@ Gecko_GetFontMetrics(RawGeckoPresContext
   // and if so, appends PostTraversalTasks to the current ServoStyleSet
   // to be performed immediately after the traversal is finished.  This
   // works well for starting downloadable font loads, since we don't have
   // those fonts available to get metrics for anyway.  Platform fonts and
   // ArrayBuffer-backed FontFace objects are handled synchronously.
 
   nsPresContext* presContext = const_cast<nsPresContext*>(aPresContext);
   presContext->SetUsesExChUnits(true);
-  RefPtr<nsFontMetrics> fm = nsRuleNode::GetMetricsFor(presContext, aIsVertical,
-                                                       aFont, aFontSize,
-                                                       aUseUserFontSet);
+  RefPtr<nsFontMetrics> fm = nsRuleNode::GetMetricsFor(
+      presContext, aIsVertical, aFont, aFontSize, aUseUserFontSet,
+      nsRuleNode::FlushUserFontSet::No);
+
   ret.mXSize = fm->XHeight();
   gfxFloat zeroWidth = fm->GetThebesFontGroup()->GetFirstValidFont()->
                            GetMetrics(fm->Orientation()).zeroOrAveCharWidth;
   ret.mChSize = ceil(aPresContext->AppUnitsPerDevPixel() * zeroWidth);
   return ret;
 }
 
 int32_t
--- a/layout/style/nsRuleNode.cpp
+++ b/layout/style/nsRuleNode.cpp
@@ -372,28 +372,30 @@ static inline nscoord ScaleViewportCoord
 }
 
 /* static */
 already_AddRefed<nsFontMetrics>
 nsRuleNode::GetMetricsFor(nsPresContext* aPresContext,
                           bool aIsVertical,
                           const nsStyleFont* aStyleFont,
                           nscoord aFontSize,
-                          bool aUseUserFontSet)
+                          bool aUseUserFontSet,
+                          FlushUserFontSet aFlushUserFontSet)
 {
   nsFont font = aStyleFont->mFont;
   font.size = aFontSize;
   gfxFont::Orientation orientation
     = aIsVertical ? gfxFont::eVertical : gfxFont::eHorizontal;
   nsFontMetrics::Params params;
   params.language = aStyleFont->mLanguage;
   params.explicitLanguage = aStyleFont->mExplicitLanguage;
   params.orientation = orientation;
-  params.userFontSet =
-    aUseUserFontSet ? aPresContext->GetUserFontSet() : nullptr;
+  params.userFontSet = aUseUserFontSet
+    ? aPresContext->GetUserFontSet(aFlushUserFontSet == FlushUserFontSet::Yes)
+    : nullptr;
   params.textPerf = aPresContext->GetTextPerfMetrics();
   return aPresContext->DeviceContext()->GetMetricsFor(font, params);
 }
 
 /* static */
 already_AddRefed<nsFontMetrics>
 nsRuleNode::GetMetricsFor(nsPresContext* aPresContext,
                           nsStyleContext* aStyleContext,
@@ -403,18 +405,19 @@ nsRuleNode::GetMetricsFor(nsPresContext*
 {
   bool isVertical = false;
   if (aStyleContext) {
     WritingMode wm(aStyleContext);
     if (wm.IsVertical() && !wm.IsSideways()) {
       isVertical = true;
     }
   }
-  return nsRuleNode::GetMetricsFor(aPresContext, isVertical, aStyleFont,
-                                   aFontSize, aUseUserFontSet);
+  return nsRuleNode::GetMetricsFor(
+      aPresContext, isVertical, aStyleFont, aFontSize, aUseUserFontSet,
+      FlushUserFontSet::Yes);
 }
 
 /* static */
 void
 nsRuleNode::FixupNoneGeneric(nsFont* aFont,
                              const nsPresContext* aPresContext,
                              uint8_t aGenericFontID,
                              const nsFont* aDefaultVariableFont)
--- a/layout/style/nsRuleNode.h
+++ b/layout/style/nsRuleNode.h
@@ -802,21 +802,27 @@ private:
 public:
   // This is infallible; it will never return nullptr.
   static already_AddRefed<nsRuleNode> CreateRootNode(nsPresContext* aPresContext);
 
   static void EnsureBlockDisplay(mozilla::StyleDisplay& display,
                                  bool aConvertListItem = false);
   static void EnsureInlineDisplay(mozilla::StyleDisplay& display);
 
+  enum class FlushUserFontSet {
+    Yes,
+    No,
+  };
+
   static already_AddRefed<nsFontMetrics> GetMetricsFor(nsPresContext* aPresContext,
                                                        bool aIsVertical,
                                                        const nsStyleFont* aStyleFont,
                                                        nscoord aFontSize,
-                                                       bool aUseUserFontSet);
+                                                       bool aUseUserFontSet,
+                                                       FlushUserFontSet aFlushUserFontSet);
 
   static already_AddRefed<nsFontMetrics> GetMetricsFor(nsPresContext* aPresContext,
                                                        nsStyleContext* aStyleContext,
                                                        const nsStyleFont* aStyleFont,
                                                        nscoord aFontSize,
                                                        bool aUseUserFontSet);
 
   /**