Bug 1195180 part 10 - Remove refresh driver observing machinery from CommonAnimationManager; r=heycam
authorBrian Birtles <birtles@gmail.com>
Mon, 28 Sep 2015 12:38:41 +0900
changeset 264674 19e81f18c957819b098b6a47781c5df929e427b3
parent 264673 3aa2e3b0f240e50c5fb3bbcc941a3bb6a595b24d
child 264675 005e98e2c5c9e04d7bb8b982a00b6f8d7a0ebe9f
push id29444
push usercbook@mozilla.com
push dateMon, 28 Sep 2015 12:17:21 +0000
treeherdermozilla-central@031db40e2b55 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersheycam
bugs1195180
milestone44.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 1195180 part 10 - Remove refresh driver observing machinery from CommonAnimationManager; r=heycam This patch removes a lot of code involved with observing the refresh driver from nsAnimationManager and nsTransitionManager now that we no longer need to do this. The one piece it does not remove, however, is AnimationCollection::mNeedsRefreshes since this flag actually serves a secondary purpose in telling us when the animation style has not changed and so does not need to be updated. A subsequent patch in this series will rename this and update the code that makes use of it.
layout/style/AnimationCommon.cpp
layout/style/AnimationCommon.h
layout/style/nsAnimationManager.h
--- a/layout/style/AnimationCommon.cpp
+++ b/layout/style/AnimationCommon.cpp
@@ -48,17 +48,16 @@ IsGeometricProperty(nsCSSProperty aPrope
       return true;
     default:
       return false;
   }
 }
 
 CommonAnimationManager::CommonAnimationManager(nsPresContext *aPresContext)
   : mPresContext(aPresContext)
-  , mIsObservingRefreshDriver(false)
 {
 }
 
 CommonAnimationManager::~CommonAnimationManager()
 {
   MOZ_ASSERT(!mPresContext, "Disconnect should have been called");
 }
 
@@ -69,70 +68,27 @@ CommonAnimationManager::Disconnect()
   RemoveAllElementCollections();
 
   mPresContext = nullptr;
 }
 
 void
 CommonAnimationManager::AddElementCollection(AnimationCollection* aCollection)
 {
-  if (!mIsObservingRefreshDriver) {
-    NS_ASSERTION(aCollection->mNeedsRefreshes,
-      "Added data which doesn't need refreshing?");
-    // We need to observe the refresh driver.
-    mPresContext->RefreshDriver()->AddRefreshObserver(this, Flush_Style);
-    mIsObservingRefreshDriver = true;
-  }
-
   mElementCollections.insertBack(aCollection);
 }
 
 void
 CommonAnimationManager::RemoveAllElementCollections()
 {
  while (AnimationCollection* head = mElementCollections.getFirst()) {
    head->Destroy(); // Note: this removes 'head' from mElementCollections.
  }
 }
 
-void
-CommonAnimationManager::MaybeStartObservingRefreshDriver()
-{
-  if (mIsObservingRefreshDriver || !NeedsRefresh()) {
-    return;
-  }
-
-  mPresContext->RefreshDriver()->AddRefreshObserver(this, Flush_Style);
-  mIsObservingRefreshDriver = true;
-}
-
-void
-CommonAnimationManager::MaybeStartOrStopObservingRefreshDriver()
-{
-  bool needsRefresh = NeedsRefresh();
-  if (needsRefresh && !mIsObservingRefreshDriver) {
-    mPresContext->RefreshDriver()->AddRefreshObserver(this, Flush_Style);
-  } else if (!needsRefresh && mIsObservingRefreshDriver) {
-    mPresContext->RefreshDriver()->RemoveRefreshObserver(this, Flush_Style);
-  }
-  mIsObservingRefreshDriver = needsRefresh;
-}
-
-bool
-CommonAnimationManager::NeedsRefresh() const
-{
-  for (const AnimationCollection* collection = mElementCollections.getFirst();
-       collection; collection = collection->getNext()) {
-    if (collection->mNeedsRefreshes) {
-      return true;
-    }
-  }
-  return false;
-}
-
 AnimationCollection*
 CommonAnimationManager::GetAnimationCollection(const nsIFrame* aFrame)
 {
   nsIContent* content = aFrame->GetContent();
   if (!content) {
     return nullptr;
   }
   nsIAtom* animProp;
@@ -407,34 +363,16 @@ CommonAnimationManager::GetAnimationRule
   }
 
   collection->EnsureStyleRuleFor(
     mPresContext->RefreshDriver()->MostRecentRefresh());
 
   return collection->mStyleRule;
 }
 
-/* virtual */ void
-CommonAnimationManager::WillRefresh(TimeStamp aTime)
-{
-  MOZ_ASSERT(mPresContext,
-             "refresh driver should not notify additional observers "
-             "after pres context has been destroyed");
-  if (!mPresContext->GetPresShell()) {
-    // 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 animations so we stop
-    // triggering refreshes.
-    RemoveAllElementCollections();
-    return;
-  }
-
-  MaybeStartOrStopObservingRefreshDriver();
-}
-
 void
 CommonAnimationManager::ClearIsRunningOnCompositor(const nsIFrame* aFrame,
                                                    nsCSSProperty aProperty)
 {
   AnimationCollection* collection = GetAnimationCollection(aFrame);
   if (collection) {
     collection->ClearIsRunningOnCompositor(aProperty);
   }
@@ -785,18 +723,16 @@ AnimationCollection::EnsureStyleRuleFor(
   // animation which occurs last in the value of animation-name wins.
   // As a result, we iterate from last animation to first and, if a
   // property has already been set, we don't leave it.
   nsCSSPropertySet properties;
 
   for (size_t animIdx = mAnimations.Length(); animIdx-- != 0; ) {
     mAnimations[animIdx]->ComposeStyle(mStyleRule, properties, mNeedsRefreshes);
   }
-
-  mManager->MaybeStartObservingRefreshDriver();
 }
 
 bool
 AnimationCollection::CanThrottleTransformChanges(TimeStamp aTime)
 {
   if (!nsLayoutUtils::AreAsyncAnimationsEnabled()) {
     return false;
   }
@@ -901,20 +837,17 @@ AnimationCollection::RequestRestyle(Rest
     // Pres context will be null after the manager is disconnected.
     return;
   }
 
   // Steps for Restyle::Layer:
 
   if (aRestyleType == RestyleType::Layer) {
     mStyleRuleRefreshTime = TimeStamp();
-    // FIXME: We should be able to remove these two lines once we move
-    // ticking to animation timelines as part of bug 1151731.
     mNeedsRefreshes = true;
-    mManager->MaybeStartObservingRefreshDriver();
 
     // Prompt layers to re-sync their animations.
     presContext->ClearLastStyleUpdateForAllAnimations();
     presContext->RestyleManager()->IncrementAnimationGeneration();
     UpdateAnimationGeneration(presContext);
   }
 
   // Steps for RestyleType::Standard and above:
--- a/layout/style/AnimationCommon.h
+++ b/layout/style/AnimationCommon.h
@@ -4,17 +4,16 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef mozilla_css_AnimationCommon_h
 #define mozilla_css_AnimationCommon_h
 
 #include <algorithm> // For <std::stable_sort>
 #include "nsIStyleRuleProcessor.h"
 #include "nsIStyleRule.h"
-#include "nsRefreshDriver.h"
 #include "nsChangeHint.h"
 #include "nsCSSProperty.h"
 #include "nsDisplayList.h" // For nsDisplayItem::Type
 #include "mozilla/AnimationComparator.h"
 #include "mozilla/EventDispatcher.h"
 #include "mozilla/LinkedList.h"
 #include "mozilla/MemoryReporting.h"
 #include "mozilla/StyleAnimationValue.h"
@@ -35,18 +34,17 @@ class nsPresContext;
 
 namespace mozilla {
 
 class RestyleTracker;
 struct AnimationCollection;
 
 bool IsGeometricProperty(nsCSSProperty aProperty);
 
-class CommonAnimationManager : public nsIStyleRuleProcessor,
-                               public nsARefreshObserver {
+class CommonAnimationManager : public nsIStyleRuleProcessor {
 public:
   explicit CommonAnimationManager(nsPresContext *aPresContext);
 
   // nsIStyleRuleProcessor (parts)
   virtual nsRestyleHint HasStateDependentStyle(StateRuleProcessorData* aData) override;
   virtual nsRestyleHint HasStateDependentStyle(PseudoElementStateRuleProcessorData* aData) override;
   virtual bool HasDocumentStateDependentStyle(StateRuleProcessorData* aData) override;
   virtual nsRestyleHint
@@ -59,19 +57,16 @@ public:
 #ifdef MOZ_XUL
   virtual void RulesMatching(XULTreeRuleProcessorData* aData) override;
 #endif
   virtual size_t SizeOfExcludingThis(MallocSizeOf aMallocSizeOf)
     const MOZ_MUST_OVERRIDE override;
   virtual size_t SizeOfIncludingThis(MallocSizeOf aMallocSizeOf)
     const MOZ_MUST_OVERRIDE override;
 
-  // nsARefreshObserver
-  void WillRefresh(TimeStamp aTime) override;
-
   // NOTE:  This can return null after Disconnect().
   nsPresContext* PresContext() const { return mPresContext; }
 
   /**
    * Notify the manager that the pres context is going away.
    */
   void Disconnect();
 
@@ -113,42 +108,32 @@ public:
   // For CSS properties that may be animated on a separate layer, represents
   // a record of the corresponding layer type and change hint.
   struct LayerAnimationRecord {
     nsCSSProperty mProperty;
     nsDisplayItem::Type mLayerType;
     nsChangeHint mChangeHint;
   };
 
+  virtual bool IsAnimationManager() {
+    return false;
+  }
+
 protected:
   virtual ~CommonAnimationManager();
 
-  // For ElementCollectionRemoved
-  friend struct AnimationCollection;
-
   void AddElementCollection(AnimationCollection* aCollection);
-  void ElementCollectionRemoved() { MaybeStartOrStopObservingRefreshDriver(); }
   void RemoveAllElementCollections();
 
-  // We should normally only call MaybeStartOrStopObservingRefreshDriver in
-  // situations where we will also queue events since otherwise we may stop
-  // getting refresh driver ticks before we queue the necessary events.
-  void MaybeStartObservingRefreshDriver();
-  void MaybeStartOrStopObservingRefreshDriver();
   bool NeedsRefresh() const;
 
   virtual nsIAtom* GetAnimationsAtom() = 0;
   virtual nsIAtom* GetAnimationsBeforeAtom() = 0;
   virtual nsIAtom* GetAnimationsAfterAtom() = 0;
 
-  virtual bool IsAnimationManager() {
-    return false;
-  }
-
-
 public:
   // Return an AnimationCollection* if we have an animation for
   // the frame aFrame that can be performed on the compositor thread (as
   // defined by AnimationCollection::CanPerformOnCompositorThread).
   //
   // Note that this does not test whether the frame's layer uses
   // off-main-thread compositing, although it does check whether
   // off-main-thread compositing is enabled as a whole.
@@ -162,17 +147,16 @@ public:
   AnimationCollection*
   GetAnimationCollection(const nsIFrame* aFrame);
 
   void ClearIsRunningOnCompositor(const nsIFrame *aFrame,
                                   nsCSSProperty aProperty);
 protected:
   LinkedList<AnimationCollection> mElementCollections;
   nsPresContext *mPresContext; // weak (non-null from ctor to Disconnect)
-  bool mIsObservingRefreshDriver;
 };
 
 /**
  * A style rule that maps property-StyleAnimationValue pairs.
  */
 class AnimValuesStyleRule final : public nsIStyleRule
 {
 public:
@@ -238,17 +222,16 @@ struct AnimationCollection : public Link
     MOZ_COUNT_CTOR(AnimationCollection);
   }
   ~AnimationCollection()
   {
     MOZ_ASSERT(mCalledPropertyDtor,
                "must call destructor through element property dtor");
     MOZ_COUNT_DTOR(AnimationCollection);
     remove();
-    mManager->ElementCollectionRemoved();
   }
 
   void Destroy()
   {
     // This will call our destructor.
     mElement->DeleteProperty(mElementProperty);
   }
 
--- a/layout/style/nsAnimationManager.h
+++ b/layout/style/nsAnimationManager.h
@@ -334,31 +334,32 @@ public:
   void ClearEventQueue() { mEventDispatcher.ClearEventQueue(); }
 
   // Stop animations on the element. This method takes the real element
   // rather than the element for the generated content for animations on
   // ::before and ::after.
   void StopAnimationsForElement(mozilla::dom::Element* aElement,
                                 nsCSSPseudoElements::Type aPseudoType);
 
+  bool IsAnimationManager() override {
+    return true;
+  }
+
 protected:
   virtual ~nsAnimationManager() {}
 
   virtual nsIAtom* GetAnimationsAtom() override {
     return nsGkAtoms::animationsProperty;
   }
   virtual nsIAtom* GetAnimationsBeforeAtom() override {
     return nsGkAtoms::animationsOfBeforeProperty;
   }
   virtual nsIAtom* GetAnimationsAfterAtom() override {
     return nsGkAtoms::animationsOfAfterProperty;
   }
-  virtual bool IsAnimationManager() override {
-    return true;
-  }
 
   mozilla::DelayedEventDispatcher<mozilla::AnimationEventInfo> mEventDispatcher;
 
 private:
   void BuildAnimations(nsStyleContext* aStyleContext,
                        mozilla::dom::Element* aTarget,
                        mozilla::dom::AnimationTimeline* aTimeline,
                        mozilla::AnimationPtrArray& aAnimations);