Bug 1188251 part 6 - Unify FlushAnimations and FlushTransitions; r=dholbert
authorBrian Birtles <birtles@gmail.com>
Mon, 17 Aug 2015 13:59:44 +0900
changeset 258000 8cbb80c89aefa630ac067191b17d5e2a67bb43d2
parent 257999 754717f00c5e1f31fde952cd96a0680c20b7c64e
child 258001 2be8060a496921b76fad7c48c47bf4ff195d6401
push id29238
push userryanvm@gmail.com
push dateMon, 17 Aug 2015 13:06:57 +0000
treeherdermozilla-central@a6eeb28458fd [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdholbert
bugs1188251
milestone43.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 1188251 part 6 - Unify FlushAnimations and FlushTransitions; r=dholbert The implementations of FlushAnimations and FlushTransitions should now be all but equivalent so this patch combines them into a single implementation on CommonAnimationManager. Regarding some of the minor differences between the two methods: * The combined implementation drops the check for an empty list of collections found only in FlushTransitions. This seems like a very minor optimization that could possibly cause us to fail to unregister from the refresh driver if we forgot to do so when removing the last collection. * The combined implementation uses the loop implementation from FlushAnimations since it is more compact. This patch also removes the extra nested scope since it doesn't seem necessary.
layout/base/nsPresShell.cpp
layout/style/AnimationCommon.cpp
layout/style/AnimationCommon.h
layout/style/nsAnimationManager.cpp
layout/style/nsAnimationManager.h
layout/style/nsTransitionManager.cpp
layout/style/nsTransitionManager.h
--- a/layout/base/nsPresShell.cpp
+++ b/layout/base/nsPresShell.cpp
@@ -4084,17 +4084,17 @@ PresShell::FlushPendingNotifications(moz
       if (aFlush.mFlushAnimations &&
           !mPresContext->StyleUpdateForAllAnimationsIsUpToDate()) {
         if (mPresContext->AnimationManager()) {
           mPresContext->AnimationManager()->
             FlushAnimations(CommonAnimationManager::Cannot_Throttle);
         }
         if (mPresContext->TransitionManager()) {
           mPresContext->TransitionManager()->
-            FlushTransitions(CommonAnimationManager::Cannot_Throttle);
+            FlushAnimations(CommonAnimationManager::Cannot_Throttle);
         }
         mPresContext->TickLastStyleUpdateForAllAnimations();
       }
 
       // The FlushResampleRequests() above flushed style changes.
       if (!mIsDestroying) {
         nsAutoScriptBlocker scriptBlocker;
         mPresContext->RestyleManager()->ProcessPendingRestyles();
--- a/layout/style/AnimationCommon.cpp
+++ b/layout/style/AnimationCommon.cpp
@@ -373,16 +373,47 @@ CommonAnimationManager::GetAnimations(do
     }
 
     AddElementCollection(collection);
   }
 
   return collection;
 }
 
+void
+CommonAnimationManager::FlushAnimations(FlushFlags aFlags)
+{
+  TimeStamp now = mPresContext->RefreshDriver()->MostRecentRefresh();
+  for (PRCList *l = PR_LIST_HEAD(&mElementCollections);
+       l != &mElementCollections;
+       l = PR_NEXT_LINK(l)) {
+    AnimationCollection* collection = static_cast<AnimationCollection*>(l);
+
+    if (collection->mStyleRuleRefreshTime == now) {
+      continue;
+    }
+
+    nsAutoAnimationMutationBatch mb(collection->mElement);
+    collection->Tick();
+
+    bool canThrottleTick = aFlags == Can_Throttle;
+    for (auto iter = collection->mAnimations.cbegin();
+         canThrottleTick && iter != collection->mAnimations.cend();
+         ++iter) {
+      canThrottleTick &= (*iter)->CanThrottle();
+    }
+
+    collection->RequestRestyle(canThrottleTick ?
+                               AnimationCollection::RestyleType::Throttled :
+                               AnimationCollection::RestyleType::Standard);
+  }
+
+  MaybeStartOrStopObservingRefreshDriver();
+}
+
 nsIStyleRule*
 CommonAnimationManager::GetAnimationRule(mozilla::dom::Element* aElement,
                                          nsCSSPseudoElements::Type aPseudoType)
 {
   MOZ_ASSERT(
     aPseudoType == nsCSSPseudoElements::ePseudo_NotPseudoElement ||
     aPseudoType == nsCSSPseudoElements::ePseudo_before ||
     aPseudoType == nsCSSPseudoElements::ePseudo_after,
--- a/layout/style/AnimationCommon.h
+++ b/layout/style/AnimationCommon.h
@@ -100,16 +100,17 @@ public:
   // Notify this manager that one of its collections of animations,
   // has been updated.
   void NotifyCollectionUpdated(AnimationCollection& aCollection);
 
   enum FlushFlags {
     Can_Throttle,
     Cannot_Throttle
   };
+  void FlushAnimations(FlushFlags aFlags);
 
   nsIStyleRule* GetAnimationRule(dom::Element* aElement,
                                  nsCSSPseudoElements::Type aPseudoType);
 
   static bool ExtractComputedValueForTransition(
                   nsCSSProperty aProperty,
                   nsStyleContext* aStyleContext,
                   StyleAnimationValue& aComputedValue);
--- a/layout/style/nsAnimationManager.cpp
+++ b/layout/style/nsAnimationManager.cpp
@@ -952,41 +952,8 @@ nsAnimationManager::WillRefresh(mozilla:
     // this case.  But do get rid of all our transitions so we stop
     // triggering refreshes.
     RemoveAllElementCollections();
     return;
   }
 
   FlushAnimations(Can_Throttle);
 }
-
-void
-nsAnimationManager::FlushAnimations(FlushFlags aFlags)
-{
-  TimeStamp now = mPresContext->RefreshDriver()->MostRecentRefresh();
-  for (PRCList *l = PR_LIST_HEAD(&mElementCollections);
-       l != &mElementCollections;
-       l = PR_NEXT_LINK(l)) {
-    AnimationCollection* collection = static_cast<AnimationCollection*>(l);
-
-    if (collection->mStyleRuleRefreshTime == now) {
-      continue;
-    }
-
-    nsAutoAnimationMutationBatch mb(collection->mElement);
-
-    collection->Tick();
-
-    bool canThrottleTick = aFlags == Can_Throttle;
-
-    for (auto iter = collection->mAnimations.cbegin();
-         canThrottleTick && iter != collection->mAnimations.cend();
-         ++iter) {
-      canThrottleTick &= (*iter)->CanThrottle();
-    }
-
-    collection->RequestRestyle(canThrottleTick ?
-                               AnimationCollection::RestyleType::Throttled :
-                               AnimationCollection::RestyleType::Standard);
-  }
-
-  MaybeStartOrStopObservingRefreshDriver();
-}
--- a/layout/style/nsAnimationManager.h
+++ b/layout/style/nsAnimationManager.h
@@ -253,18 +253,16 @@ public:
   virtual size_t SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf)
     const MOZ_MUST_OVERRIDE override;
   virtual size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf)
     const MOZ_MUST_OVERRIDE override;
 
   // nsARefreshObserver
   virtual void WillRefresh(mozilla::TimeStamp aTime) override;
 
-  void FlushAnimations(FlushFlags aFlags);
-
   /**
    * Return the style rule that RulesMatching should add for
    * aStyleContext.  This might be different from what RulesMatching
    * actually added during aStyleContext's construction because the
    * element's animation-name may have changed.  (However, this does
    * return null during the non-animation restyling phase, as
    * RulesMatching does.)
    *
--- a/layout/style/nsTransitionManager.cpp
+++ b/layout/style/nsTransitionManager.cpp
@@ -898,53 +898,10 @@ nsTransitionManager::WillRefresh(mozilla
     // Someone might be keeping mPresContext alive past the point
     // where it has been torn down; don't bother doing anything in
     // this case.  But do get rid of all our transitions so we stop
     // triggering refreshes.
     RemoveAllElementCollections();
     return;
   }
 
-  FlushTransitions(Can_Throttle);
+  FlushAnimations(Can_Throttle);
 }
-
-void
-nsTransitionManager::FlushTransitions(FlushFlags aFlags)
-{
-  if (PR_CLIST_IS_EMPTY(&mElementCollections)) {
-    // no transitions, leave early
-    return;
-  }
-
-  TimeStamp now = mPresContext->RefreshDriver()->MostRecentRefresh();
-  // Post restyle events for frames that are transitioning.
-  {
-    PRCList *next = PR_LIST_HEAD(&mElementCollections);
-    while (next != &mElementCollections) {
-      AnimationCollection* collection = static_cast<AnimationCollection*>(next);
-      next = PR_NEXT_LINK(next);
-
-      if (collection->mStyleRuleRefreshTime == now) {
-        continue;
-      }
-
-      nsAutoAnimationMutationBatch mb(collection->mElement);
-
-      collection->Tick();
-
-      bool canThrottleTick = aFlags == Can_Throttle;
-
-      // Look for any transitions that can't be throttled because they
-      // may be starting or stopping
-      for (auto iter = collection->mAnimations.cbegin();
-           canThrottleTick && iter != collection->mAnimations.cend();
-           ++iter) {
-        canThrottleTick &= (*iter)->CanThrottle();
-      }
-
-      collection->RequestRestyle(canThrottleTick ?
-                                 AnimationCollection::RestyleType::Throttled :
-                                 AnimationCollection::RestyleType::Standard);
-    }
-  }
-
-  MaybeStartOrStopObservingRefreshDriver();
-}
--- a/layout/style/nsTransitionManager.h
+++ b/layout/style/nsTransitionManager.h
@@ -272,18 +272,16 @@ public:
   virtual size_t SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) const
     MOZ_MUST_OVERRIDE override;
   virtual size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const
     MOZ_MUST_OVERRIDE override;
 
   // nsARefreshObserver
   virtual void WillRefresh(mozilla::TimeStamp aTime) override;
 
-  void FlushTransitions(FlushFlags aFlags);
-
   void QueueEvent(mozilla::TransitionEventInfo&& aEventInfo)
   {
     mEventDispatcher.QueueEvent(
       mozilla::Forward<mozilla::TransitionEventInfo>(aEventInfo));
   }
 
   void DispatchEvents()  { mEventDispatcher.DispatchEvents(mPresContext); }
   void ClearEventQueue() { mEventDispatcher.ClearEventQueue(); }