Bug 1032573 part 2 - Add a timeline member to ElementAnimations; r=dbaron
authorBrian Birtles <birtles@gmail.com>
Wed, 16 Jul 2014 09:02:30 +0900
changeset 216190 5a606567031850658300f470ffa1a9a26561e8ca
parent 216189 389f489afdb68e43c146e164920008c402adbf11
child 216191 35f359aca0c3021e3e385b697fe55ef6a0cbb541
push id515
push userraliiev@mozilla.com
push dateMon, 06 Oct 2014 12:51:51 +0000
treeherdermozilla-release@267c7a481bef [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdbaron
bugs1032573
milestone33.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 1032573 part 2 - Add a timeline member to ElementAnimations; r=dbaron When we expose ElementAnimation objects to script they need to have a parent object so they can be associated with a Window. This patch adds a pointer from an ElementAnimation to its AnimationTimeline.
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/style/AnimationCommon.cpp
+++ b/layout/style/AnimationCommon.cpp
@@ -7,16 +7,17 @@
 #include "nsTransitionManager.h"
 #include "nsAnimationManager.h"
 
 #include "ActiveLayerTracker.h"
 #include "gfxPlatform.h"
 #include "nsRuleData.h"
 #include "nsCSSPropertySet.h"
 #include "nsCSSValue.h"
+#include "nsCycleCollectionParticipant.h"
 #include "nsStyleContext.h"
 #include "nsIFrame.h"
 #include "nsLayoutUtils.h"
 #include "mozilla/LookAndFeel.h"
 #include "Layers.h"
 #include "FrameLayerBuilder.h"
 #include "nsDisplayList.h"
 #include "mozilla/MemoryReporting.h"
@@ -401,16 +402,20 @@ ComputedTimingFunction::GetValue(double 
 
 } /* end sub-namespace css */
 
 // In the Web Animations model, the time fraction can be outside the range
 // [0.0, 1.0] but it shouldn't be Infinity.
 const double ComputedTiming::kNullTimeFraction =
   mozilla::PositiveInfinity<double>();
 
+NS_IMPL_CYCLE_COLLECTION(ElementAnimation, mTimeline)
+NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(ElementAnimation, AddRef)
+NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(ElementAnimation, Release)
+
 bool
 ElementAnimation::IsRunningAt(TimeStamp aTime) const
 {
   if (IsPaused() || IsFinishedTransition()) {
     return false;
   }
 
   ComputedTiming computedTiming =
--- a/layout/style/AnimationCommon.h
+++ b/layout/style/AnimationCommon.h
@@ -8,22 +8,24 @@
 
 #include "nsIStyleRuleProcessor.h"
 #include "nsIStyleRule.h"
 #include "nsRefreshDriver.h"
 #include "prclist.h"
 #include "nsCSSProperty.h"
 #include "mozilla/MemoryReporting.h"
 #include "mozilla/StyleAnimationValue.h"
+#include "mozilla/dom/AnimationTimeline.h"
 #include "mozilla/dom/Element.h"
 #include "nsSMILKeySpline.h"
 #include "nsStyleStruct.h"
 #include "mozilla/Attributes.h"
 #include "mozilla/FloatingPoint.h"
 #include "nsCSSPseudoElements.h"
+#include "nsCycleCollectionParticipant.h"
 
 class nsIFrame;
 class nsPresContext;
 class nsStyleChangeList;
 
 
 namespace mozilla {
 
@@ -306,23 +308,27 @@ struct ComputedTiming
  * 'animation-name') running on an element.
  */
 struct ElementAnimation
 {
 protected:
   virtual ~ElementAnimation() { }
 
 public:
-  ElementAnimation()
+  explicit ElementAnimation(dom::AnimationTimeline* aTimeline)
     : mIsRunningOnCompositor(false)
     , mIsFinishedTransition(false)
     , mLastNotification(LAST_NOTIFICATION_NONE)
+    , mTimeline(aTimeline)
   {
   }
 
+  NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(ElementAnimation)
+  NS_DECL_CYCLE_COLLECTION_NATIVE_CLASS(ElementAnimation)
+
   // FIXME: If we succeed in moving transition-specific code to a type of
   // AnimationEffect (as per the Web Animations API) we should remove these
   // virtual methods.
   virtual ElementPropertyTransition* AsTransition() { return nullptr; }
   virtual const ElementPropertyTransition* AsTransition() const {
     return nullptr;
   }
 
@@ -392,17 +398,17 @@ public:
     LAST_NOTIFICATION_END = uint64_t(-2)
   };
   // One of the above constants, or an integer for the iteration
   // whose start we last notified on.
   uint64_t mLastNotification;
 
   InfallibleTArray<AnimationProperty> mProperties;
 
-  NS_INLINE_DECL_REFCOUNTING(ElementAnimation)
+  nsRefPtr<dom::AnimationTimeline> mTimeline;
 };
 
 typedef InfallibleTArray<nsRefPtr<ElementAnimation> > ElementAnimationPtrArray;
 
 enum EnsureStyleRuleFlags {
   EnsureStyleRule_IsThrottled,
   EnsureStyleRule_IsNotThrottled
 };
--- a/layout/style/nsAnimationManager.cpp
+++ b/layout/style/nsAnimationManager.cpp
@@ -236,18 +236,19 @@ nsAnimationManager::CheckAnimationRule(n
       GetElementAnimations(aElement, aStyleContext->GetPseudoType(), false);
     if (!collection &&
         disp->mAnimationNameCount == 1 &&
         disp->mAnimations[0].GetName().IsEmpty()) {
       return nullptr;
     }
 
     // build the animations list
+    dom::AnimationTimeline* timeline = aElement->OwnerDoc()->Timeline();
     ElementAnimationPtrArray newAnimations;
-    BuildAnimations(aStyleContext, newAnimations);
+    BuildAnimations(aStyleContext, timeline, newAnimations);
 
     if (newAnimations.IsEmpty()) {
       if (collection) {
         collection->Destroy();
       }
       return nullptr;
     }
 
@@ -378,16 +379,17 @@ ResolvedStyleCache::Get(nsPresContext *a
     mCache.Put(aKeyframe, resultStrong);
     result = resultStrong;
   }
   return result;
 }
 
 void
 nsAnimationManager::BuildAnimations(nsStyleContext* aStyleContext,
+                                    dom::AnimationTimeline* aTimeline,
                                     ElementAnimationPtrArray& aAnimations)
 {
   NS_ABORT_IF_FALSE(aAnimations.IsEmpty(), "expect empty array");
 
   ResolvedStyleCache resolvedStyles;
 
   const nsStyleDisplay *disp = aStyleContext->StyleDisplay();
   TimeStamp now = mPresContext->RefreshDriver()->MostRecentRefresh();
@@ -405,17 +407,17 @@ nsAnimationManager::BuildAnimations(nsSt
       ? nullptr
       : mPresContext->StyleSet()->KeyframesRuleForName(mPresContext,
                                                        src.GetName());
     if (!rule) {
       continue;
     }
 
     nsRefPtr<ElementAnimation> dest =
-      *aAnimations.AppendElement(new ElementAnimation());
+      *aAnimations.AppendElement(new ElementAnimation(aTimeline));
 
     dest->mName = src.GetName();
 
     dest->mTiming.mIterationDuration =
       TimeDuration::FromMilliseconds(src.GetDuration());
     dest->mTiming.mDelay = TimeDuration::FromMilliseconds(src.GetDelay());
     dest->mTiming.mIterationCount = src.GetIterationCount();
     dest->mTiming.mDirection = src.GetDirection();
--- a/layout/style/nsAnimationManager.h
+++ b/layout/style/nsAnimationManager.h
@@ -146,16 +146,17 @@ protected:
 
   /**
    * Check to see if we should stop or start observing the refresh driver
    */
   void CheckNeedsRefresh();
 
 private:
   void BuildAnimations(nsStyleContext* aStyleContext,
+                       mozilla::dom::AnimationTimeline* aTimeline,
                        mozilla::ElementAnimationPtrArray& aAnimations);
   bool BuildSegment(InfallibleTArray<mozilla::AnimationPropertySegment>&
                       aSegments,
                     nsCSSProperty aProperty,
                     const mozilla::StyleAnimation& aAnimation,
                     float aFromKey, nsStyleContext* aFromContext,
                     mozilla::css::Declaration* aFromDeclaration,
                     float aToKey, nsStyleContext* aToContext);
--- a/layout/style/nsTransitionManager.cpp
+++ b/layout/style/nsTransitionManager.cpp
@@ -402,17 +402,19 @@ nsTransitionManager::ConsiderStartingTra
     // http://lists.w3.org/Archives/Public/www-style/2009Aug/0109.html .
     return;
   }
 
   if (nsCSSProps::kAnimTypeTable[aProperty] == eStyleAnimType_None) {
     return;
   }
 
-  nsRefPtr<ElementPropertyTransition> pt = new ElementPropertyTransition();
+  dom::AnimationTimeline* timeline = aElement->OwnerDoc()->Timeline();
+  nsRefPtr<ElementPropertyTransition> pt =
+    new ElementPropertyTransition(timeline);
 
   StyleAnimationValue startValue, endValue, dummyValue;
   bool haveValues =
     ExtractComputedValueForTransition(aProperty, aOldStyleContext,
                                       startValue) &&
     ExtractComputedValueForTransition(aProperty, aNewStyleContext,
                                       endValue);
 
--- a/layout/style/nsTransitionManager.h
+++ b/layout/style/nsTransitionManager.h
@@ -25,16 +25,19 @@ struct StyleTransition;
 /*****************************************************************************
  * Per-Element data                                                          *
  *****************************************************************************/
 
 namespace mozilla {
 
 struct ElementPropertyTransition : public mozilla::ElementAnimation
 {
+  explicit ElementPropertyTransition(mozilla::dom::AnimationTimeline* aTimeline)
+    : mozilla::ElementAnimation(aTimeline) { }
+
   virtual ElementPropertyTransition* AsTransition() { return this; }
   virtual const ElementPropertyTransition* AsTransition() const { return this; }
 
   // This is the start value to be used for a check for whether a
   // transition is being reversed.  Normally the same as
   // mProperties[0].mSegments[0].mFromValue, except when this transition
   // started as the reversal of another in-progress transition.
   // Needed so we can handle two reverses in a row.