Bug 1384824 - Part 0: Consolidate lazy style resolution entrypoints. r=bholley, a=lizzard
authorCameron McCormack <cam@mcc.id.au>
Fri, 04 Aug 2017 19:26:03 +1000
changeset 423473 9dcc92f77512a04ae074d9965daf742e08b146f5
parent 423472 7f9c0489c233d437b23f2810c80b383f59106de5
child 423474 38f18620cfea2dba7c8189b05e3ced8e2755a77b
push id1517
push userjlorenzo@mozilla.com
push dateThu, 14 Sep 2017 16:50:54 +0000
treeherdermozilla-release@3b41fd564418 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbholley, lizzard
bugs1384824
milestone56.0
Bug 1384824 - Part 0: Consolidate lazy style resolution entrypoints. r=bholley, a=lizzard MozReview-Commit-ID: HPdviA570N1
dom/canvas/CanvasRenderingContext2D.cpp
layout/style/ServoStyleSet.cpp
layout/style/ServoStyleSet.h
layout/style/nsComputedDOMStyle.cpp
--- a/dom/canvas/CanvasRenderingContext2D.cpp
+++ b/dom/canvas/CanvasRenderingContext2D.cpp
@@ -2875,23 +2875,23 @@ GetFontStyleForServo(Element* aElement, 
   ServoStyleSet* styleSet = aPresShell->StyleSet()->AsServo();
 
   RefPtr<ServoStyleContext> parentStyle;
   // have to get a parent style context for inherit-like relative
   // values (2em, bolder, etc.)
   if (aElement && aElement->IsInUncomposedDoc()) {
     // Inherit from the canvas element.
     aPresShell->FlushPendingNotifications(FlushType::Style);
-    // We need to use ResolveTransientServoStyle, which involves traversal,
-    // instead of ResolveServoStyle() because we need up-to-date style even if
+    // We need to use ResolveStyleLazily, which involves traversal,
+    // instead of ResolvestyleFor() because we need up-to-date style even if
     // the canvas element is display:none.
     parentStyle =
-      styleSet->ResolveTransientServoStyle(aElement,
-                                           CSSPseudoElementType::NotPseudo,
-                                           nullptr);
+      styleSet->ResolveStyleLazily(aElement,
+                                   CSSPseudoElementType::NotPseudo,
+                                   nullptr);
   } else {
     RefPtr<RawServoDeclarationBlock> declarations =
       CreateFontDeclarationForServo(NS_LITERAL_STRING("10px sans-serif"),
                                     aPresShell->GetDocument());
     MOZ_ASSERT(declarations);
 
     parentStyle = aPresShell->StyleSet()->AsServo()->
       ResolveForDeclarations(nullptr, declarations);
--- a/layout/style/ServoStyleSet.cpp
+++ b/layout/style/ServoStyleSet.cpp
@@ -174,17 +174,17 @@ ServoStyleSet::EndUpdate()
 already_AddRefed<ServoStyleContext>
 ServoStyleSet::ResolveStyleFor(Element* aElement,
                                ServoStyleContext* aParentContext,
                                LazyComputeBehavior aMayCompute)
 {
   RefPtr<ServoStyleContext> computedValues;
   if (aMayCompute == LazyComputeBehavior::Allow) {
     PreTraverseSync();
-    return ResolveStyleLazily(
+    return ResolveStyleLazilyInternal(
         aElement, CSSPseudoElementType::NotPseudo, nullptr, aParentContext);
   }
 
   return ResolveServoStyle(aElement, ServoTraversalFlags::Empty);
 }
 
 
 const ServoElementSnapshotTable&
@@ -424,35 +424,24 @@ ServoStyleSet::ResolvePseudoElementStyle
                                mRawSet.get()).Consume();
   }
 
   MOZ_ASSERT(computedValues);
   return computedValues.forget();
 }
 
 already_AddRefed<ServoStyleContext>
-ServoStyleSet::ResolveTransientStyle(Element* aElement,
-                                     CSSPseudoElementType aPseudoType,
-                                     nsIAtom* aPseudoTag,
-                                     StyleRuleInclusion aRuleInclusion)
-{
-  RefPtr<ServoStyleContext> result =
-    ResolveTransientServoStyle(aElement, aPseudoType, aPseudoTag, aRuleInclusion);
-  return result.forget();
-}
-
-already_AddRefed<ServoStyleContext>
-ServoStyleSet::ResolveTransientServoStyle(
-    Element* aElement,
-    CSSPseudoElementType aPseudoType,
-    nsIAtom* aPseudoTag,
-    StyleRuleInclusion aRuleInclusion)
+ServoStyleSet::ResolveStyleLazily(Element* aElement,
+                                  CSSPseudoElementType aPseudoType,
+                                  nsIAtom* aPseudoTag,
+                                  StyleRuleInclusion aRuleInclusion)
 {
   PreTraverseSync();
-  return ResolveStyleLazily(aElement, aPseudoType, aPseudoTag, nullptr, aRuleInclusion);
+  return ResolveStyleLazilyInternal(aElement, aPseudoType, aPseudoTag,
+                                    nullptr, aRuleInclusion);
 }
 
 already_AddRefed<ServoStyleContext>
 ServoStyleSet::ResolveInheritingAnonymousBoxStyle(nsIAtom* aPseudoTag,
                                                   ServoStyleContext* aParentContext)
 {
   MOZ_ASSERT(nsCSSAnonBoxes::IsAnonBox(aPseudoTag) &&
              !nsCSSAnonBoxes::IsNonInheritingAnonBox(aPseudoTag));
@@ -1061,21 +1050,21 @@ void
 ServoStyleSet::ClearNonInheritingStyleContexts()
 {
   for (RefPtr<ServoStyleContext>& ptr : mNonInheritingStyleContexts) {
     ptr = nullptr;
   }
 }
 
 already_AddRefed<ServoStyleContext>
-ServoStyleSet::ResolveStyleLazily(Element* aElement,
-                                  CSSPseudoElementType aPseudoType,
-                                  nsIAtom* aPseudoTag,
-                                  const ServoStyleContext* aParentContext,
-                                  StyleRuleInclusion aRuleInclusion)
+ServoStyleSet::ResolveStyleLazilyInternal(Element* aElement,
+                                          CSSPseudoElementType aPseudoType,
+                                          nsIAtom* aPseudoTag,
+                                          const ServoStyleContext* aParentContext,
+                                          StyleRuleInclusion aRuleInclusion)
 {
   mPresContext->EffectCompositor()->PreTraverse(aElement, aPseudoType);
   MOZ_ASSERT(!StylistNeedsUpdate());
 
   AutoSetInServoTraversal guard(this);
 
   /**
    * NB: This is needed because we process animations and transitions on the
--- a/layout/style/ServoStyleSet.h
+++ b/layout/style/ServoStyleSet.h
@@ -177,34 +177,25 @@ public:
   // style attributes; otherwise, it is ignored.
   already_AddRefed<ServoStyleContext>
   ResolvePseudoElementStyle(dom::Element* aOriginatingElement,
                             CSSPseudoElementType aType,
                             ServoStyleContext* aParentContext,
                             dom::Element* aPseudoElement);
 
   // Resolves style for a (possibly-pseudo) Element without assuming that the
-  // style has been resolved, and without worrying about setting the style
-  // context up to live in the style context tree (a null parent is used).
-  // |aPeudoTag| and |aPseudoType| must match.
+  // style has been resolved. If the element was unstyled and a new style
+  // context was resolved, it is not stored in the DOM. (That is, the element
+  // remains unstyled.) |aPeudoTag| and |aPseudoType| must match.
   already_AddRefed<ServoStyleContext>
-  ResolveTransientStyle(dom::Element* aElement,
-                        CSSPseudoElementType aPseudoType,
-                        nsIAtom* aPseudoTag,
-                        StyleRuleInclusion aRules =
-                          StyleRuleInclusion::All);
-
-  // Similar to ResolveTransientStyle() but doesn't update the context state
-  // Unlike ResolveServoStyle() this function calls PreTraverseSync().
-  already_AddRefed<ServoStyleContext>
-  ResolveTransientServoStyle(dom::Element* aElement,
-                             CSSPseudoElementType aPseudoType,
-                             nsIAtom* aPseudoTag,
-                             StyleRuleInclusion aRules =
-                               StyleRuleInclusion::All);
+  ResolveStyleLazily(dom::Element* aElement,
+                     CSSPseudoElementType aPseudoType,
+                     nsIAtom* aPseudoTag,
+                     StyleRuleInclusion aRules =
+                       StyleRuleInclusion::All);
 
   // Get a style context for an anonymous box.  aPseudoTag is the pseudo-tag to
   // use and must be non-null.  It must be an anon box, and must be one that
   // inherits style from the given aParentContext.
   already_AddRefed<ServoStyleContext>
   ResolveInheritingAnonymousBoxStyle(nsIAtom* aPseudoTag,
                                      ServoStyleContext* aParentContext);
 
@@ -559,22 +550,22 @@ private:
   /**
    * Update the stylist as needed to ensure style data is up-to-date.
    *
    * This should only be called if StylistNeedsUpdate returns true.
    */
   void UpdateStylist();
 
   already_AddRefed<ServoStyleContext>
-    ResolveStyleLazily(dom::Element* aElement,
-                       CSSPseudoElementType aPseudoType,
-                       nsIAtom* aPseudoTag,
-                       const ServoStyleContext* aParentContext,
-                       StyleRuleInclusion aRules =
-                         StyleRuleInclusion::All);
+    ResolveStyleLazilyInternal(dom::Element* aElement,
+                               CSSPseudoElementType aPseudoType,
+                               nsIAtom* aPseudoTag,
+                               const ServoStyleContext* aParentContext,
+                               StyleRuleInclusion aRules =
+                                 StyleRuleInclusion::All);
 
   void RunPostTraversalTasks();
 
   void PrependSheetOfType(SheetType aType,
                           ServoStyleSheet* aSheet);
 
   void AppendSheetOfType(SheetType aType,
                          ServoStyleSheet* aSheet);
--- a/layout/style/nsComputedDOMStyle.cpp
+++ b/layout/style/nsComputedDOMStyle.cpp
@@ -661,17 +661,17 @@ nsComputedDOMStyle::DoGetStyleContextNoF
 
   // For Servo, compute the result directly without recursively building up
   // a throwaway style context chain.
   if (ServoStyleSet* servoSet = styleSet->GetAsServo()) {
     StyleRuleInclusion rules = aStyleType == eDefaultOnly
                                ? StyleRuleInclusion::DefaultOnly
                                : StyleRuleInclusion::All;
     RefPtr<ServoStyleContext> result =
-       servoSet->ResolveTransientStyle(aElement, pseudoType, aPseudo, rules);
+       servoSet->ResolveStyleLazily(aElement, pseudoType, aPseudo, rules);
     if (aAnimationFlag == eWithAnimation) {
       return result.forget();
     }
 
     return servoSet->GetBaseContextForElement(aElement, nullptr, presContext,
                                               aPseudo, pseudoType, result);
   }