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.
This commit is contained in:
Brian Birtles 2015-03-27 15:56:45 +09:00
parent c9c21cdcde
commit 030dcb3a08
2 changed files with 53 additions and 11 deletions

View File

@ -13,15 +13,19 @@ 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
@ -30,15 +34,17 @@ PendingPlayerTracker::AddPlayPending(dom::AnimationPlayer& aPlayer)
}
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

View File

@ -25,13 +25,41 @@ 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;
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() { }
@ -41,7 +69,15 @@ private:
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;
};