Bug 927349 part 9 - Add PendingPlayerTracker::StartPendingPlayers; r=jwatt
authorBrian Birtles <birtles@gmail.com>
Mon, 22 Dec 2014 09:35:41 +0900
changeset 220804 f77e3d03e7e3444e07ebd17a2c8ed48d01dfb7f5
parent 220803 d7da8aa9ec743fd3eedad18e071aa0aa71fce920
child 220805 7df2255ce1e2b9e52cac824b7adf58649dae8067
push id28000
push usercbook@mozilla.com
push dateMon, 22 Dec 2014 12:13:57 +0000
treeherdermozilla-central@c82d5fcdc416 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjwatt
bugs927349
milestone37.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 927349 part 9 - Add PendingPlayerTracker::StartPendingPlayers; r=jwatt
dom/animation/PendingPlayerTracker.cpp
dom/animation/PendingPlayerTracker.h
--- a/dom/animation/PendingPlayerTracker.cpp
+++ b/dom/animation/PendingPlayerTracker.cpp
@@ -1,15 +1,17 @@
 /* vim: set shiftwidth=2 tabstop=8 autoindent cindent expandtab: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
  * You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "PendingPlayerTracker.h"
 
+#include "mozilla/dom/AnimationTimeline.h"
+
 using namespace mozilla;
 
 namespace mozilla {
 
 NS_IMPL_CYCLE_COLLECTION(PendingPlayerTracker, mPlayPendingSet)
 
 NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(PendingPlayerTracker, AddRef)
 NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(PendingPlayerTracker, Release)
@@ -27,9 +29,41 @@ PendingPlayerTracker::RemovePlayPending(
 }
 
 bool
 PendingPlayerTracker::IsWaitingToPlay(dom::AnimationPlayer const& aPlayer) const
 {
   return mPlayPendingSet.Contains(const_cast<dom::AnimationPlayer*>(&aPlayer));
 }
 
+PLDHashOperator
+StartPlayerAtTime(nsRefPtrHashKey<dom::AnimationPlayer>* aKey,
+                  void* aReadyTime)
+{
+  dom::AnimationPlayer* player = aKey->GetKey();
+
+  // For animations that are waiting until their first frame has rendered
+  // before starting, we record the moment when they finish painting
+  // as the "ready time" and make any pending layer animations start at
+  // that time.
+  //
+  // Here we fast-forward the player's timeline to the same "ready time" and
+  // then tell the player to start at the timeline's current time.
+  //
+  // Redundant calls to FastForward with the same ready time are ignored by
+  // AnimationTimeline.
+  dom::AnimationTimeline* timeline = player->Timeline();
+  timeline->FastForward(*static_cast<const TimeStamp*>(aReadyTime));
+
+  player->StartNow();
+
+  return PL_DHASH_NEXT;
+}
+
+void
+PendingPlayerTracker::StartPendingPlayers(const TimeStamp& aReadyTime)
+{
+  mPlayPendingSet.EnumerateEntries(StartPlayerAtTime,
+                                   const_cast<TimeStamp*>(&aReadyTime));
+  mPlayPendingSet.Clear();
+}
+
 } // namespace mozilla
--- a/dom/animation/PendingPlayerTracker.h
+++ b/dom/animation/PendingPlayerTracker.h
@@ -17,16 +17,20 @@ class PendingPlayerTracker MOZ_FINAL
 public:
   NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(PendingPlayerTracker)
   NS_DECL_CYCLE_COLLECTION_NATIVE_CLASS(PendingPlayerTracker)
 
   void AddPlayPending(dom::AnimationPlayer& aPlayer);
   void RemovePlayPending(dom::AnimationPlayer& aPlayer);
   bool IsWaitingToPlay(dom::AnimationPlayer const& aPlayer) const;
 
+  // Causes any pending players to resume at |aReadyTime| by first
+  // fast-forwarding their timeline to the corresponding time.
+  void StartPendingPlayers(const TimeStamp& aReadyTime);
+
 private:
   ~PendingPlayerTracker() { }
 
   typedef nsTHashtable<nsRefPtrHashKey<dom::AnimationPlayer>>
     AnimationPlayerSet;
 
   AnimationPlayerSet mPlayPendingSet;
 };