Bug 1109390 part 6 - Generalize PendingPlayerTracker to support pausing as well; r=jwatt
authorBrian Birtles <birtles@gmail.com>
Fri, 27 Mar 2015 15:56:45 +0900
changeset 266392 ff6b730f3a891749c00940dda54595e4c3e0cab7
parent 266391 71e33f9c871eb86bc81c1586db6c0bb7f1b7441c
child 266393 92fd678cb47cdd74d12d22ded5656b76dc09a896
push id830
push userraliiev@mozilla.com
push dateFri, 19 Jun 2015 19:24:37 +0000
treeherdermozilla-release@932614382a68 [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 6 - Generalize PendingPlayerTracker to support pausing as well; r=jwatt This patch extends the PendingPlayerTracker which is currently used to record which animations are waiting to play, such that it can also handle animations which are waiting to complete a pause operation. It doesn't yet do anything with the pause-pending animations, that will come in another patch.
dom/animation/PendingPlayerTracker.cpp
dom/animation/PendingPlayerTracker.h
--- a/dom/animation/PendingPlayerTracker.cpp
+++ b/dom/animation/PendingPlayerTracker.cpp
@@ -8,42 +8,48 @@
 #include "mozilla/dom/AnimationTimeline.h"
 #include "nsIFrame.h"
 #include "nsIPresShell.h"
 
 using namespace mozilla;
 
 namespace mozilla {
 
-NS_IMPL_CYCLE_COLLECTION(PendingPlayerTracker, mPlayPendingSet, mDocument)
+NS_IMPL_CYCLE_COLLECTION(PendingPlayerTracker,
+                         mPlayPendingSet,
+                         mPausePendingSet,
+                         mDocument)
 
 NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(PendingPlayerTracker, AddRef)
 NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(PendingPlayerTracker, Release)
 
 void
-PendingPlayerTracker::AddPlayPending(dom::AnimationPlayer& aPlayer)
+PendingPlayerTracker::AddPending(dom::AnimationPlayer& aPlayer,
+                                 AnimationPlayerSet& aSet)
 {
-  mPlayPendingSet.PutEntry(&aPlayer);
+  aSet.PutEntry(&aPlayer);
 
   // Schedule a paint. Otherwise animations that don't trigger a paint by
   // themselves (e.g. CSS animations with an empty keyframes rule) won't
   // start until something else paints.
   EnsurePaintIsScheduled();
 }
 
 void
-PendingPlayerTracker::RemovePlayPending(dom::AnimationPlayer& aPlayer)
+PendingPlayerTracker::RemovePending(dom::AnimationPlayer& aPlayer,
+                                    AnimationPlayerSet& aSet)
 {
-  mPlayPendingSet.RemoveEntry(&aPlayer);
+  aSet.RemoveEntry(&aPlayer);
 }
 
 bool
-PendingPlayerTracker::IsWaitingToPlay(dom::AnimationPlayer const& aPlayer) const
+PendingPlayerTracker::IsWaiting(const dom::AnimationPlayer& aPlayer,
+                                const AnimationPlayerSet& aSet) const
 {
-  return mPlayPendingSet.Contains(const_cast<dom::AnimationPlayer*>(&aPlayer));
+  return aSet.Contains(const_cast<dom::AnimationPlayer*>(&aPlayer));
 }
 
 PLDHashOperator
 StartPlayerAtTime(nsRefPtrHashKey<dom::AnimationPlayer>* aKey,
                   void* aReadyTime)
 {
   dom::AnimationPlayer* player = aKey->GetKey();
   dom::AnimationTimeline* timeline = player->Timeline();
--- a/dom/animation/PendingPlayerTracker.h
+++ b/dom/animation/PendingPlayerTracker.h
@@ -20,31 +20,67 @@ class PendingPlayerTracker final
 public:
   explicit PendingPlayerTracker(nsIDocument* aDocument)
     : mDocument(aDocument)
   { }
 
   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;
+  void AddPlayPending(dom::AnimationPlayer& aPlayer)
+  {
+    MOZ_ASSERT(!IsWaitingToPause(aPlayer),
+               "Player is already waiting to pause");
+    AddPending(aPlayer, mPlayPendingSet);
+  }
+  void RemovePlayPending(dom::AnimationPlayer& aPlayer)
+  {
+    RemovePending(aPlayer, mPlayPendingSet);
+  }
+  bool IsWaitingToPlay(const dom::AnimationPlayer& aPlayer) const
+  {
+    return IsWaiting(aPlayer, mPlayPendingSet);
+  }
+
+  void AddPausePending(dom::AnimationPlayer& aPlayer)
+  {
+    MOZ_ASSERT(!IsWaitingToPlay(aPlayer),
+               "Player is already waiting to play");
+    AddPending(aPlayer, mPausePendingSet);
+  }
+  void RemovePausePending(dom::AnimationPlayer& aPlayer)
+  {
+    RemovePending(aPlayer, mPausePendingSet);
+  }
+  bool IsWaitingToPause(const dom::AnimationPlayer& aPlayer) const
+  {
+    return IsWaiting(aPlayer, mPausePendingSet);
+  }
 
   void StartPendingPlayersOnNextTick(const TimeStamp& aReadyTime);
   void StartPendingPlayersNow();
-  bool HasPendingPlayers() const { return mPlayPendingSet.Count() > 0; }
+  bool HasPendingPlayers() const {
+    return mPlayPendingSet.Count() > 0 || mPausePendingSet.Count() > 0;
+  }
 
 private:
   ~PendingPlayerTracker() { }
 
   void EnsurePaintIsScheduled();
 
   typedef nsTHashtable<nsRefPtrHashKey<dom::AnimationPlayer>>
     AnimationPlayerSet;
 
+  void AddPending(dom::AnimationPlayer& aPlayer,
+                  AnimationPlayerSet& aSet);
+  void RemovePending(dom::AnimationPlayer& aPlayer,
+                     AnimationPlayerSet& aSet);
+  bool IsWaiting(const dom::AnimationPlayer& aPlayer,
+                 const AnimationPlayerSet& aSet) const;
+
   AnimationPlayerSet mPlayPendingSet;
+  AnimationPlayerSet mPausePendingSet;
   nsCOMPtr<nsIDocument> mDocument;
 };
 
 } // namespace mozilla
 
 #endif // mozilla_dom_PendingPlayerTracker_h