Bumping manifests a=b2g-bump
[gecko.git] / dom / animation / PendingPlayerTracker.cpp
blob7fb7d872b92b66482d398fe3b5f282a62bbb6efd
1 /* vim: set shiftwidth=2 tabstop=8 autoindent cindent expandtab: */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
4 * You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #include "PendingPlayerTracker.h"
8 #include "mozilla/dom/AnimationTimeline.h"
9 #include "nsIFrame.h"
10 #include "nsIPresShell.h"
12 using namespace mozilla;
14 namespace mozilla {
16 NS_IMPL_CYCLE_COLLECTION(PendingPlayerTracker, mPlayPendingSet, mDocument)
18 NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(PendingPlayerTracker, AddRef)
19 NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(PendingPlayerTracker, Release)
21 void
22 PendingPlayerTracker::AddPlayPending(dom::AnimationPlayer& aPlayer)
24 mPlayPendingSet.PutEntry(&aPlayer);
26 // Schedule a paint. Otherwise animations that don't trigger a paint by
27 // themselves (e.g. CSS animations with an empty keyframes rule) won't
28 // start until something else paints.
29 EnsurePaintIsScheduled();
32 void
33 PendingPlayerTracker::RemovePlayPending(dom::AnimationPlayer& aPlayer)
35 mPlayPendingSet.RemoveEntry(&aPlayer);
38 bool
39 PendingPlayerTracker::IsWaitingToPlay(dom::AnimationPlayer const& aPlayer) const
41 return mPlayPendingSet.Contains(const_cast<dom::AnimationPlayer*>(&aPlayer));
44 PLDHashOperator
45 StartPlayerAtTime(nsRefPtrHashKey<dom::AnimationPlayer>* aKey,
46 void* aReadyTime)
48 dom::AnimationPlayer* player = aKey->GetKey();
49 dom::AnimationTimeline* timeline = player->Timeline();
51 // When the timeline's refresh driver is under test control, its values
52 // have no correspondance to wallclock times so we shouldn't try to convert
53 // aReadyTime (which is a wallclock time) to a timeline value. Instead, the
54 // animation player will be started when the refresh driver is next
55 // advanced since this will trigger a call to StartPendingPlayersNow.
56 if (timeline->IsUnderTestControl()) {
57 return PL_DHASH_NEXT;
60 Nullable<TimeDuration> readyTime =
61 timeline->ToTimelineTime(*static_cast<const TimeStamp*>(aReadyTime));
62 player->StartOnNextTick(readyTime);
64 return PL_DHASH_REMOVE;
67 void
68 PendingPlayerTracker::StartPendingPlayersOnNextTick(const TimeStamp& aReadyTime)
70 mPlayPendingSet.EnumerateEntries(StartPlayerAtTime,
71 const_cast<TimeStamp*>(&aReadyTime));
74 PLDHashOperator
75 StartPlayerNow(nsRefPtrHashKey<dom::AnimationPlayer>* aKey, void*)
77 aKey->GetKey()->StartNow();
78 return PL_DHASH_NEXT;
81 void
82 PendingPlayerTracker::StartPendingPlayersNow()
84 mPlayPendingSet.EnumerateEntries(StartPlayerNow, nullptr);
85 mPlayPendingSet.Clear();
88 void
89 PendingPlayerTracker::EnsurePaintIsScheduled()
91 if (!mDocument) {
92 return;
95 nsIPresShell* presShell = mDocument->GetShell();
96 if (!presShell) {
97 return;
100 nsIFrame* rootFrame = presShell->GetRootFrame();
101 if (!rootFrame) {
102 return;
105 rootFrame->SchedulePaint();
108 } // namespace mozilla