Bug 1112480 part 2 - Factor out ResumeAt; r=jwatt
authorBrian Birtles <birtles@gmail.com>
Fri, 09 Jan 2015 07:57:58 +0900
changeset 222843 dfba5219541ff18c96f1b43e52f4d54bd4bc707d
parent 222842 15f5148fe5892f1267f298ea6a09d8a6f64dc647
child 222844 73091940bedfc769250e199d9489e3545ccf235e
push id10731
push usercbook@mozilla.com
push dateFri, 09 Jan 2015 14:51:37 +0000
treeherderfx-team@e6756043d930 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjwatt
bugs1112480
milestone37.0a1
Bug 1112480 part 2 - Factor out ResumeAt; r=jwatt In addition to AnimationPlayer::StartNow, this patch series also makes AnimationPlayer::Tick start animations. Since these methods will share a lot of code we first factor out a common ResumeAt method to encapsulate the common code.
dom/animation/AnimationPlayer.cpp
dom/animation/AnimationPlayer.h
--- a/dom/animation/AnimationPlayer.cpp
+++ b/dom/animation/AnimationPlayer.cpp
@@ -138,49 +138,22 @@ AnimationPlayer::Tick()
   // animation now.
 
   UpdateSourceContent();
 }
 
 void
 AnimationPlayer::StartNow()
 {
-  // This method is only expected to be called for an animation that is
-  // waiting to play. We can easily adapt it to handle other states
-  // but it's currently not necessary.
   MOZ_ASSERT(PlayState() == AnimationPlayState::Pending,
              "Expected to start a pending player");
-  MOZ_ASSERT(!mHoldTime.IsNull(),
-             "A player in the pending state should have a resolved hold time");
-
-  Nullable<TimeDuration> readyTime = mTimeline->GetCurrentTime();
+  MOZ_ASSERT(mTimeline && !mTimeline->GetCurrentTime().IsNull(),
+             "Expected an active timeline");
 
-  // FIXME (bug 1096776): If readyTime.IsNull(), we should return early here.
-  // This will leave mIsPending = true but the caller will remove us from the
-  // PendingPlayerTracker if we were added there.
-  // Then, in Tick(), if we have:
-  // - a resolved timeline, and
-  // - mIsPending = true, and
-  // - *no* document or we are *not* in the PendingPlayerTracker
-  // then we should call StartNow.
-  //
-  // For now, however, we don't support inactive/missing timelines so
-  // |readyTime| should be resolved.
-  MOZ_ASSERT(!readyTime.IsNull(), "Missing or inactive timeline");
-
-  mStartTime.SetValue(readyTime.Value() - mHoldTime.Value());
-  mHoldTime.SetNull();
-  mIsPending = false;
-
-  UpdateSourceContent();
-  PostUpdate();
-
-  if (mReady) {
-    mReady->MaybeResolve(this);
-  }
+  ResumeAt(mTimeline->GetCurrentTime().Value());
 }
 
 void
 AnimationPlayer::Cancel()
 {
   if (mIsPending) {
     CancelPendingPlay();
     if (mReady) {
@@ -309,16 +282,39 @@ AnimationPlayer::DoPause()
   mIsRunningOnCompositor = false;
 
   // Bug 1109390 - check for null result here and go to pending state
   mHoldTime = GetCurrentTime();
   mStartTime.SetNull();
 }
 
 void
+AnimationPlayer::ResumeAt(const TimeDuration& aResumeTime)
+{
+  // This method is only expected to be called for a player that is
+  // waiting to play. We can easily adapt it to handle other states
+  // but it's currently not necessary.
+  MOZ_ASSERT(PlayState() == AnimationPlayState::Pending,
+             "Expected to resume a pending player");
+  MOZ_ASSERT(!mHoldTime.IsNull(),
+             "A player in the pending state should have a resolved hold time");
+
+  mStartTime.SetValue(aResumeTime - mHoldTime.Value());
+  mHoldTime.SetNull();
+  mIsPending = false;
+
+  UpdateSourceContent();
+  PostUpdate();
+
+  if (mReady) {
+    mReady->MaybeResolve(this);
+  }
+}
+
+void
 AnimationPlayer::UpdateSourceContent()
 {
   if (mSource) {
     mSource->SetParentTime(GetCurrentTime());
   }
 }
 
 void
--- a/dom/animation/AnimationPlayer.h
+++ b/dom/animation/AnimationPlayer.h
@@ -150,16 +150,17 @@ public:
   // is running and has source content to sample).
   void ComposeStyle(nsRefPtr<css::AnimValuesStyleRule>& aStyleRule,
                     nsCSSPropertySet& aSetProperties,
                     bool& aNeedsRefreshes);
 
 protected:
   void DoPlay();
   void DoPause();
+  void ResumeAt(const TimeDuration& aResumeTime);
 
   void UpdateSourceContent();
   void FlushStyle() const;
   void PostUpdate();
   // Remove this player from the pending player tracker and resets mIsPending
   // as necessary. The caller is responsible for resolving or aborting the
   // mReady promise as necessary.
   void CancelPendingPlay();