Bug 1232577 part 13 - Move EnsureStyleRuleFor from AnimationCollection to EffectCompositor
authorBrian Birtles <birtles@gmail.com>
Wed, 13 Jan 2016 07:54:55 +0900
changeset 314808 69236594a8efb2f16e9369ae5e1964bb97a1bd55
parent 314807 04ea9a6a29a545149380b1ace53211830a5c6f4c
child 314809 ddfdec87e4488578497c0e20b998a2c6c4babb91
push id5703
push userraliiev@mozilla.com
push dateMon, 07 Mar 2016 14:18:41 +0000
treeherdermozilla-beta@31e373ad5b5f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs1232577
milestone46.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 1232577 part 13 - Move EnsureStyleRuleFor from AnimationCollection to EffectCompositor
dom/animation/EffectCompositor.cpp
layout/style/AnimationCommon.cpp
layout/style/AnimationCommon.h
layout/style/nsAnimationManager.cpp
layout/style/nsTransitionManager.cpp
--- a/dom/animation/EffectCompositor.cpp
+++ b/dom/animation/EffectCompositor.cpp
@@ -189,16 +189,31 @@ EffectCompositor::PostRestyleForAnimatio
 }
 
 void
 EffectCompositor::MaybeUpdateAnimationRule(dom::Element* aElement,
                                            nsCSSPseudoElements::Type
                                              aPseudoType,
                                            CascadeLevel aCascadeLevel)
 {
+  // First update cascade results since that may cause some elements to
+  // be marked as needing a restyle.
+
+  nsStyleContext* styleContext = nullptr;
+  {
+    dom::Element* elementToRestyle = GetElementToRestyle(aElement, aPseudoType);
+    if (elementToRestyle) {
+      nsIFrame* frame = elementToRestyle->GetPrimaryFrame();
+      if (frame) {
+        styleContext = frame->StyleContext();
+      }
+    }
+  }
+  MaybeUpdateCascadeResults(aElement, aPseudoType, styleContext);
+
   auto& elementsToRestyle = mElementsToRestyle[aCascadeLevel];
   PseudoElementHashKey key = { aElement, aPseudoType };
 
   if (!mPresContext || !elementsToRestyle.Contains(key)) {
     return;
   }
 
   ComposeAnimationRule(aElement, aPseudoType, aCascadeLevel,
--- a/layout/style/AnimationCommon.cpp
+++ b/layout/style/AnimationCommon.cpp
@@ -230,19 +230,30 @@ CommonAnimationManager::SizeOfExcludingT
 CommonAnimationManager::SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const
 {
   return aMallocSizeOf(this) + SizeOfExcludingThis(aMallocSizeOf);
 }
 
 void
 CommonAnimationManager::AddStyleUpdatesTo(RestyleTracker& aTracker)
 {
+  // FIXME: This is not quite right but is only temporary until we move
+  // this method into EffectCompositor.
+  EffectCompositor::CascadeLevel cascadeLevel =
+    IsAnimationManager() ?
+    EffectCompositor::CascadeLevel::Animations :
+    EffectCompositor::CascadeLevel::Transitions;
+
   for (AnimationCollection* collection = mElementCollections.getFirst();
        collection; collection = collection->getNext()) {
-    collection->EnsureStyleRuleFor();
+
+    mPresContext->EffectCompositor()
+                ->MaybeUpdateAnimationRule(collection->mElement,
+                                           collection->PseudoElementType(),
+                                           cascadeLevel);
 
     dom::Element* elementToRestyle = collection->GetElementToRestyle();
     if (elementToRestyle) {
       nsRestyleHint rshint = collection->IsForTransitions()
         ? eRestyle_CSSTransitions : eRestyle_CSSAnimations;
       aTracker.AddPendingRestyle(elementToRestyle, rshint, nsChangeHint(0));
     }
   }
@@ -320,26 +331,32 @@ CommonAnimationManager::GetAnimationRule
     return nullptr;
   }
 
   RestyleManager* restyleManager = mPresContext->RestyleManager();
   if (restyleManager->SkipAnimationRules()) {
     return nullptr;
   }
 
-  collection->EnsureStyleRuleFor();
+  // FIXME: This is not quite right but is only temporary until we move
+  // this method into EffectCompositor.
+  EffectCompositor::CascadeLevel cascadeLevel =
+    IsAnimationManager() ?
+    EffectCompositor::CascadeLevel::Animations :
+    EffectCompositor::CascadeLevel::Transitions;
+  mPresContext->EffectCompositor()->MaybeUpdateAnimationRule(aElement,
+                                                             aPseudoType,
+                                                             cascadeLevel);
 
   EffectSet* effectSet = EffectSet::GetEffectSet(aElement, aPseudoType);
   if (!effectSet) {
     return nullptr;
   }
 
-  return IsAnimationManager() ?
-         effectSet->AnimationRule(EffectCompositor::CascadeLevel::Animations) :
-         effectSet->AnimationRule(EffectCompositor::CascadeLevel::Transitions);
+  return effectSet->AnimationRule(cascadeLevel);
 }
 
 void
 CommonAnimationManager::ClearIsRunningOnCompositor(const nsIFrame* aFrame,
                                                    nsCSSProperty aProperty)
 {
   EffectSet* effects = EffectSet::GetEffectSet(aFrame);
   if (!effects) {
@@ -417,50 +434,16 @@ AnimationCollection::Tick()
 {
   for (size_t animIdx = 0, animEnd = mAnimations.Length();
        animIdx != animEnd; animIdx++) {
     mAnimations[animIdx]->Tick();
   }
 }
 
 void
-AnimationCollection::EnsureStyleRuleFor()
-{
-  nsPresContext* presContext = mManager->PresContext();
-  if (!presContext) {
-    // Pres context will be null after the manager is disconnected.
-    return;
-  }
-
-  // Update cascade results before updating the style rule, since the
-  // cascade results can influence the style rule.
-  nsStyleContext* styleContext = nullptr;
-  {
-    dom::Element* elementToRestyle = GetElementToRestyle();
-    if (elementToRestyle) {
-      nsIFrame* frame = elementToRestyle->GetPrimaryFrame();
-      if (frame) {
-        styleContext = frame->StyleContext();
-      }
-    }
-  }
-  EffectCompositor::MaybeUpdateCascadeResults(mElement,
-                                              PseudoElementType(),
-                                              styleContext);
-
-  EffectCompositor::CascadeLevel cascadeLevel =
-    IsForAnimations() ?
-    EffectCompositor::CascadeLevel::Animations :
-    EffectCompositor::CascadeLevel::Transitions;
-  presContext->EffectCompositor()->MaybeUpdateAnimationRule(mElement,
-                                                            PseudoElementType(),
-                                                            cascadeLevel);
-}
-
-void
 AnimationCollection::UpdateCheckGeneration(
   nsPresContext* aPresContext)
 {
   mCheckGeneration = aPresContext->RestyleManager()->GetAnimationGeneration();
 }
 
 nsPresContext*
 OwningElementRef::GetRenderedPresContext() const
--- a/layout/style/AnimationCommon.h
+++ b/layout/style/AnimationCommon.h
@@ -163,18 +163,16 @@ struct AnimationCollection : public Link
     mElement->DeleteProperty(mElementProperty);
   }
 
   static void PropertyDtor(void *aObject, nsIAtom *aPropertyName,
                            void *aPropertyValue, void *aData);
 
   void Tick();
 
-  void EnsureStyleRuleFor();
-
 public:
   // True if this animation can be performed on the compositor thread.
   //
   // Returns whether the state of this element's animations at the current
   // refresh driver time contains animation data that can be done on the
   // compositor thread.  (This is used for determining whether a layer
   // should be active, or whether to send data to the layer.)
   //
--- a/layout/style/nsAnimationManager.cpp
+++ b/layout/style/nsAnimationManager.cpp
@@ -532,17 +532,23 @@ nsAnimationManager::CheckAnimationRule(n
   for (size_t newAnimIdx = newAnimations.Length(); newAnimIdx-- != 0; ) {
     newAnimations[newAnimIdx]->CancelFromStyle();
   }
 
   EffectCompositor::UpdateCascadeResults(aElement,
                                          aStyleContext->GetPseudoType(),
                                          aStyleContext);
 
-  collection->EnsureStyleRuleFor();
+  EffectCompositor::CascadeLevel cascadeLevel =
+    EffectCompositor::CascadeLevel::Animations;
+  mPresContext->EffectCompositor()
+              ->MaybeUpdateAnimationRule(aElement,
+                                         aStyleContext->GetPseudoType(),
+                                         cascadeLevel);
+
   // We don't actually dispatch the pending events now.  We'll either
   // dispatch them the next time we get a refresh driver notification
   // or the next time somebody calls
   // nsPresShell::FlushPendingNotifications.
   if (mEventDispatcher.HasQueuedEvents()) {
     mPresContext->Document()->SetNeedStyleFlush();
   }
 
--- a/layout/style/nsTransitionManager.cpp
+++ b/layout/style/nsTransitionManager.cpp
@@ -468,33 +468,36 @@ nsTransitionManager::StyleContextChanged
       collection->Destroy();
       collection = nullptr;
     }
   }
 
   MOZ_ASSERT(!startedAny || collection,
              "must have element transitions if we started any transitions");
 
+  EffectCompositor::CascadeLevel cascadeLevel =
+    EffectCompositor::CascadeLevel::Transitions;
+
   if (collection) {
     EffectCompositor::UpdateCascadeResults(aElement, pseudoType,
                                            newStyleContext);
 
     collection->UpdateCheckGeneration(mPresContext);
-    collection->EnsureStyleRuleFor();
+    mPresContext->EffectCompositor()->MaybeUpdateAnimationRule(aElement,
+                                                               pseudoType,
+                                                               cascadeLevel);
   }
 
   // We want to replace the new style context with the after-change style.
   *aNewStyleContext = afterChangeStyle;
   if (collection) {
     // Since we have transition styles, we have to undo this replacement.
     // The check of collection->mCheckGeneration against the restyle
     // manager's GetAnimationGeneration() will ensure that we don't go
     // through the rest of this function again when we do.
-    EffectCompositor::CascadeLevel cascadeLevel =
-      EffectCompositor::CascadeLevel::Transitions;
     mPresContext->EffectCompositor()->PostRestyleForAnimation(aElement,
                                                               pseudoType,
                                                               cascadeLevel);
   }
 }
 
 void
 nsTransitionManager::ConsiderStartingTransition(