Bug 1344619 - Part 2: Introduce EffectCompositor::PreTraverse(). r?birtles draft
authorHiroyuki Ikezoe <hikezoe@mozilla.com>
Thu, 09 Mar 2017 05:20:17 +0900
changeset 495414 48003fcedcf38000574d9ab155b98949540bf4ef
parent 495413 cfdc21515b29190d9585e4baf990412c1b9ccc84
child 495415 fdb5bd9fe402ab843df1c7364cf67a2f1f8e48cc
push id48329
push userhikezoe@mozilla.com
push dateWed, 08 Mar 2017 20:20:57 +0000
reviewersbirtles
bugs1344619
milestone55.0a1
Bug 1344619 - Part 2: Introduce EffectCompositor::PreTraverse(). r?birtles MozReview-Commit-ID: 6ijDJttB9eo
dom/animation/EffectCompositor.cpp
dom/animation/EffectCompositor.h
--- a/dom/animation/EffectCompositor.cpp
+++ b/dom/animation/EffectCompositor.cpp
@@ -935,16 +935,50 @@ EffectCompositor::SetPerformanceWarning(
     return;
   }
 
   for (KeyframeEffectReadOnly* effect : *effects) {
     effect->SetPerformanceWarning(aProperty, aWarning);
   }
 }
 
+void
+EffectCompositor::PreTraverse()
+{
+  MOZ_ASSERT(NS_IsMainThread());
+  MOZ_ASSERT(mPresContext->RestyleManager()->IsServo());
+
+  for (auto& elementsToRestyle : mElementsToRestyle) {
+    for (auto iter = elementsToRestyle.Iter(); !iter.Done(); iter.Next()) {
+      bool postedRestyle = iter.Data();
+      // Ignore throttled restyle.
+      if (!postedRestyle) {
+        continue;
+      }
+
+      NonOwningAnimationTarget target = iter.Key();
+      EffectSet* effects =
+        EffectSet::GetEffectSet(target.mElement, target.mPseudoType);
+      if (!effects) {
+        // Drop the EffectSets that have been destroyed.
+        iter.Remove();
+        continue;
+      }
+
+      for (KeyframeEffectReadOnly* effect : *effects) {
+        effect->GetAnimation()->WillComposeStyle();
+      }
+
+      // Remove the element from the list of elements to restyle since we are
+      // about to restyle it.
+      iter.Remove();
+    }
+  }
+}
+
 // ---------------------------------------------------------
 //
 // Nested class: AnimationStyleRuleProcessor
 //
 // ---------------------------------------------------------
 
 NS_IMPL_ISUPPORTS(EffectCompositor::AnimationStyleRuleProcessor,
                   nsIStyleRuleProcessor)
--- a/dom/animation/EffectCompositor.h
+++ b/dom/animation/EffectCompositor.h
@@ -228,16 +228,21 @@ public:
 
   // Associates a performance warning with effects on |aFrame| that animates
   // |aProperty|.
   static void SetPerformanceWarning(
     const nsIFrame* aFrame,
     nsCSSPropertyID aProperty,
     const AnimationPerformanceWarning& aWarning);
 
+  // Do a bunch of stuff that we should avoid doing during the parallel
+  // traversal (e.g. changing member variables) for all elements that we expect
+  // to restyle on the next traversal.
+  void PreTraverse();
+
 private:
   ~EffectCompositor() = default;
 
   // Rebuilds the animation rule corresponding to |aCascadeLevel| on the
   // EffectSet associated with the specified (pseudo-)element.
   static void ComposeAnimationRule(dom::Element* aElement,
                                    CSSPseudoElementType aPseudoType,
                                    CascadeLevel aCascadeLevel);