Bug 1109390 part 8 - Rename Start* methods in AnimationPlayer to Trigger*; r=jwatt
authorBrian Birtles <birtles@gmail.com>
Fri, 27 Mar 2015 15:56:45 +0900
changeset 264932 38f3018ddf8576c93f0ae3f972a42bf3583c9f45
parent 264931 92fd678cb47cdd74d12d22ded5656b76dc09a896
child 264933 de1b1fbecf37fac6e4682bd00c2a424f8538d832
push id4718
push userraliiev@mozilla.com
push dateMon, 11 May 2015 18:39:53 +0000
treeherdermozilla-beta@c20c4ef55f08 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjwatt
bugs1109390
milestone39.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 1109390 part 8 - Rename Start* methods in AnimationPlayer to Trigger*; r=jwatt
dom/animation/AnimationPlayer.cpp
dom/animation/AnimationPlayer.h
dom/animation/PendingPlayerTracker.cpp
--- a/dom/animation/AnimationPlayer.cpp
+++ b/dom/animation/AnimationPlayer.cpp
@@ -279,33 +279,32 @@ AnimationPlayer::Tick()
                "Orphaned pending players should have an active timeline");
     ResumeAt(mTimeline->GetCurrentTime().Value());
   }
 
   UpdateSourceContent();
 }
 
 void
-AnimationPlayer::StartOnNextTick(const Nullable<TimeDuration>& aReadyTime)
+AnimationPlayer::TriggerOnNextTick(const Nullable<TimeDuration>& aReadyTime)
 {
   // Normally we expect the play state to be pending but it's possible that,
-  // due to the handling of possibly orphaned players in Tick() [coming
-  // in a later patch in this series], this player got started whilst still
-  // being in another document's pending player map.
+  // due to the handling of possibly orphaned players in Tick(), this player got
+  // started whilst still being in another document's pending player map.
   if (PlayState() != AnimationPlayState::Pending) {
     return;
   }
 
   // If aReadyTime.IsNull() we'll detect this in Tick() where we check for
   // orphaned players and trigger this animation anyway
   mPendingReadyTime = aReadyTime;
 }
 
 void
-AnimationPlayer::StartNow()
+AnimationPlayer::TriggerNow()
 {
   MOZ_ASSERT(PlayState() == AnimationPlayState::Pending,
              "Expected to start a pending player");
   MOZ_ASSERT(mTimeline && !mTimeline->GetCurrentTime().IsNull(),
              "Expected an active timeline");
 
   ResumeAt(mTimeline->GetCurrentTime().Value());
 }
@@ -444,17 +443,17 @@ AnimationPlayer::DoPlay()
 
   // Clear the start time until we resolve a new one
   mStartTime.SetNull();
 
   mIsPending = true;
 
   nsIDocument* doc = GetRenderedDocument();
   if (!doc) {
-    StartOnNextTick(Nullable<TimeDuration>());
+    TriggerOnNextTick(Nullable<TimeDuration>());
     return;
   }
 
   PendingPlayerTracker* tracker = doc->GetOrCreatePendingPlayerTracker();
   tracker->AddPlayPending(*this);
 
   // We may have updated the current time when we set the hold time above
   // so notify source content.
--- a/dom/animation/AnimationPlayer.h
+++ b/dom/animation/AnimationPlayer.h
@@ -102,31 +102,33 @@ public:
   // in future we will likely have to flush style in
   // CSSAnimationPlayer::PauseFromJS so we leave it for now.
   void PauseFromJS() { Pause(); }
 
   void SetSource(Animation* aSource);
   void Tick();
 
   /**
+   * Set the time to use for starting or pausing a pending player.
+   *
    * Typically, when a player is played, it does not start immediately but is
    * added to a table of pending players on the document of its source content.
    * In the meantime it sets its hold time to the time from which playback
    * should begin.
    *
    * When the document finishes painting, any pending players in its table
    * are marked as being ready to start by calling StartOnNextTick.
    * The moment when the paint completed is also recorded, converted to a
    * timeline time, and passed to StartOnTick. This is so that when these
    * players do start, they can be timed from the point when painting
    * completed.
    *
-   * After calling StartOnNextTick, players remain in the pending state until
+   * After calling TriggerOnNextTick, players remain in the pending state until
    * the next refresh driver tick. At that time they transition out of the
-   * pending state using the time passed to StartOnNextTick as the effective
+   * pending state using the time passed to TriggerOnNextTick as the effective
    * time at which they resumed.
    *
    * This approach means that any setup time required for performing the
    * initial paint of an animation such as layerization is not deducted from
    * the running time of the animation. Without this we can easily drop the
    * first few frames of an animation, or, on slower devices, the whole
    * animation.
    *
@@ -140,30 +142,37 @@ public:
    *   time of the player but then we'd also have to update the timing and style
    *   of all animations connected to that timeline or else be stuck in an
    *   inconsistent state until the next refresh driver tick.
    *
    * - If we simply use the refresh driver time on its next tick, the lag
    *   between triggering an animation and its effective start is unacceptably
    *   long.
    *
+   * For pausing, we apply the same asynchronous approach. This is so that we
+   * synchronize with animations that are running on the compositor. Otherwise
+   * if the main thread lags behind the compositor there will be a noticeable
+   * jump backwards when the main thread takes over. Even though main thread
+   * animations could be paused immediately, we do it asynchronously for
+   * consistency and so that animations paused together end up in step.
+   *
    * Note that the caller of this method is responsible for removing the player
    * from any PendingPlayerTracker it may have been added to.
    */
-  void StartOnNextTick(const Nullable<TimeDuration>& aReadyTime);
+  void TriggerOnNextTick(const Nullable<TimeDuration>& aReadyTime);
 
-  // Testing only: Start a pending player using the current timeline time.
-  // This is used to support existing tests that expect animations to begin
-  // immediately. Ideally we would rewrite the those tests and get rid of this
-  // method, but there are a lot of them.
+  // Testing only: Start or pause a pending player using the current timeline
+  // time. This is used to support existing tests that expect animations to
+  // begin immediately. Ideally we would rewrite the those tests and get rid of
+  // this method, but there are a lot of them.
   //
-  // As with StartOnNextTick, the caller of this method is responsible for
+  // As with TriggerOnNextTick, the caller of this method is responsible for
   // removing the player from any PendingPlayerTracker it may have been added
   // to.
-  void StartNow();
+  void TriggerNow();
 
   /**
    * When StartOnNextTick is called, we store the ready time but we don't apply
    * it until the next tick. In the meantime, GetStartTime() will return null.
    *
    * However, if we build layer animations again before the next tick, we
    * should initialize them with the start time that GetStartTime() will return
    * on the next tick.
--- a/dom/animation/PendingPlayerTracker.cpp
+++ b/dom/animation/PendingPlayerTracker.cpp
@@ -43,57 +43,57 @@ PendingPlayerTracker::RemovePending(dom:
 bool
 PendingPlayerTracker::IsWaiting(const dom::AnimationPlayer& aPlayer,
                                 const AnimationPlayerSet& aSet) const
 {
   return aSet.Contains(const_cast<dom::AnimationPlayer*>(&aPlayer));
 }
 
 PLDHashOperator
-StartPlayerAtTime(nsRefPtrHashKey<dom::AnimationPlayer>* aKey,
-                  void* aReadyTime)
+TriggerPlayerAtTime(nsRefPtrHashKey<dom::AnimationPlayer>* aKey,
+                    void* aReadyTime)
 {
   dom::AnimationPlayer* player = aKey->GetKey();
   dom::AnimationTimeline* timeline = player->Timeline();
 
   // When the timeline's refresh driver is under test control, its values
   // have no correspondance to wallclock times so we shouldn't try to convert
   // aReadyTime (which is a wallclock time) to a timeline value. Instead, the
-  // animation player will be started when the refresh driver is next
+  // animation player will be started/paused when the refresh driver is next
   // advanced since this will trigger a call to TriggerPendingPlayersNow.
   if (timeline->IsUnderTestControl()) {
     return PL_DHASH_NEXT;
   }
 
   Nullable<TimeDuration> readyTime =
     timeline->ToTimelineTime(*static_cast<const TimeStamp*>(aReadyTime));
-  player->StartOnNextTick(readyTime);
+  player->TriggerOnNextTick(readyTime);
 
   return PL_DHASH_REMOVE;
 }
 
 void
 PendingPlayerTracker::TriggerPendingPlayersOnNextTick(const TimeStamp&
                                                         aReadyTime)
 {
-  mPlayPendingSet.EnumerateEntries(StartPlayerAtTime,
+  mPlayPendingSet.EnumerateEntries(TriggerPlayerAtTime,
                                    const_cast<TimeStamp*>(&aReadyTime));
 }
 
 PLDHashOperator
-StartPlayerNow(nsRefPtrHashKey<dom::AnimationPlayer>* aKey, void*)
+TriggerPlayerNow(nsRefPtrHashKey<dom::AnimationPlayer>* aKey, void*)
 {
-  aKey->GetKey()->StartNow();
+  aKey->GetKey()->TriggerNow();
   return PL_DHASH_NEXT;
 }
 
 void
 PendingPlayerTracker::TriggerPendingPlayersNow()
 {
-  mPlayPendingSet.EnumerateEntries(StartPlayerNow, nullptr);
+  mPlayPendingSet.EnumerateEntries(TriggerPlayerNow, nullptr);
   mPlayPendingSet.Clear();
 }
 
 void
 PendingPlayerTracker::EnsurePaintIsScheduled()
 {
   if (!mDocument) {
     return;