OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 27 matching lines...) Expand all Loading... |
38 #include "core/page/Page.h" | 38 #include "core/page/Page.h" |
39 #include "platform/TraceEvent.h" | 39 #include "platform/TraceEvent.h" |
40 | 40 |
41 namespace WebCore { | 41 namespace WebCore { |
42 | 42 |
43 // This value represents 1 frame at 30Hz plus a little bit of wiggle room. | 43 // This value represents 1 frame at 30Hz plus a little bit of wiggle room. |
44 // TODO: Plumb a nominal framerate through and derive this value from that. | 44 // TODO: Plumb a nominal framerate through and derive this value from that. |
45 const double DocumentTimeline::s_minimumDelay = 0.04; | 45 const double DocumentTimeline::s_minimumDelay = 0.04; |
46 | 46 |
47 | 47 |
48 PassRefPtr<DocumentTimeline> DocumentTimeline::create(Document* document, PassOw
nPtr<PlatformTiming> timing) | 48 PassRefPtrWillBeRawPtr<DocumentTimeline> DocumentTimeline::create(Document* docu
ment, PassOwnPtrWillBeRawPtr<PlatformTiming> timing) |
49 { | 49 { |
50 return adoptRef(new DocumentTimeline(document, timing)); | 50 return adoptRefWillBeNoop(new DocumentTimeline(document, timing)); |
51 } | 51 } |
52 | 52 |
53 DocumentTimeline::DocumentTimeline(Document* document, PassOwnPtr<PlatformTiming
> timing) | 53 DocumentTimeline::DocumentTimeline(Document* document, PassOwnPtrWillBeRawPtr<Pl
atformTiming> timing) |
54 : m_zeroTime(nullValue()) | 54 : m_zeroTime(nullValue()) |
55 , m_document(document) | 55 , m_document(document) |
56 { | 56 { |
57 if (!timing) | 57 if (!timing) |
58 m_timing = adoptPtr(new DocumentTimelineTiming(this)); | 58 m_timing = adoptPtrWillBeNoop(new DocumentTimelineTiming(this)); |
59 else | 59 else |
60 m_timing = timing; | 60 m_timing = timing; |
61 | 61 |
62 ASSERT(document); | 62 ASSERT(document); |
63 } | 63 } |
64 | 64 |
65 DocumentTimeline::~DocumentTimeline() | 65 DocumentTimeline::~DocumentTimeline() |
66 { | 66 { |
| 67 #if !ENABLE(OILPAN) |
67 for (HashSet<AnimationPlayer*>::iterator it = m_players.begin(); it != m_pla
yers.end(); ++it) | 68 for (HashSet<AnimationPlayer*>::iterator it = m_players.begin(); it != m_pla
yers.end(); ++it) |
68 (*it)->timelineDestroyed(); | 69 (*it)->timelineDestroyed(); |
| 70 #endif |
69 } | 71 } |
70 | 72 |
71 AnimationPlayer* DocumentTimeline::createAnimationPlayer(TimedItem* child) | 73 AnimationPlayer* DocumentTimeline::createAnimationPlayer(TimedItem* child) |
72 { | 74 { |
73 RefPtr<AnimationPlayer> player = AnimationPlayer::create(*this, child); | 75 RefPtrWillBeRawPtr<AnimationPlayer> player = AnimationPlayer::create(*this,
child); |
74 AnimationPlayer* result = player.get(); | 76 AnimationPlayer* result = player.get(); |
75 m_players.add(result); | 77 m_players.add(result); |
76 setOutdatedAnimationPlayer(result); | 78 setOutdatedAnimationPlayer(result); |
77 return result; | 79 return result; |
78 } | 80 } |
79 | 81 |
80 AnimationPlayer* DocumentTimeline::play(TimedItem* child) | 82 AnimationPlayer* DocumentTimeline::play(TimedItem* child) |
81 { | 83 { |
82 if (!m_document) | 84 if (!m_document) |
83 return 0; | 85 return 0; |
84 AnimationPlayer* player = createAnimationPlayer(child); | 86 AnimationPlayer* player = createAnimationPlayer(child); |
85 player->setStartTimeInternal(effectiveTime()); | 87 player->setStartTimeInternal(effectiveTime()); |
86 m_document->compositorPendingAnimations().add(player); | 88 m_document->compositorPendingAnimations().add(player); |
87 return player; | 89 return player; |
88 } | 90 } |
89 | 91 |
90 void DocumentTimeline::wake() | 92 void DocumentTimeline::wake() |
91 { | 93 { |
92 m_timing->serviceOnNextFrame(); | 94 m_timing->serviceOnNextFrame(); |
93 } | 95 } |
94 | 96 |
95 void DocumentTimeline::serviceAnimations(TimingUpdateReason reason) | 97 void DocumentTimeline::serviceAnimations(TimingUpdateReason reason) |
96 { | 98 { |
97 TRACE_EVENT0("webkit", "DocumentTimeline::serviceAnimations"); | 99 TRACE_EVENT0("webkit", "DocumentTimeline::serviceAnimations"); |
98 | 100 |
99 m_timing->cancelWake(); | 101 m_timing->cancelWake(); |
100 | 102 |
101 double timeToNextEffect = std::numeric_limits<double>::infinity(); | 103 double timeToNextEffect = std::numeric_limits<double>::infinity(); |
102 Vector<AnimationPlayer*> players; | 104 WillBeHeapVector<RawPtrWillBeMember<AnimationPlayer> > players; |
103 for (HashSet<RefPtr<AnimationPlayer> >::iterator it = m_playersNeedingUpdate
.begin(); it != m_playersNeedingUpdate.end(); ++it) | 105 for (WillBeHeapHashSet<RefPtrWillBeMember<AnimationPlayer> >::iterator it =
m_playersNeedingUpdate.begin(); it != m_playersNeedingUpdate.end(); ++it) |
104 players.append(it->get()); | 106 players.append(it->get()); |
105 | 107 |
106 std::sort(players.begin(), players.end(), AnimationPlayer::hasLowerPriority)
; | 108 std::sort(players.begin(), players.end(), AnimationPlayer::hasLowerPriority)
; |
107 | 109 |
108 for (size_t i = 0; i < players.size(); ++i) { | 110 for (size_t i = 0; i < players.size(); ++i) { |
109 AnimationPlayer* player = players[i]; | 111 AnimationPlayer* player = players[i]; |
110 if (player->update(reason)) | 112 if (player->update(reason)) |
111 timeToNextEffect = std::min(timeToNextEffect, player->timeToEffectCh
ange()); | 113 timeToNextEffect = std::min(timeToNextEffect, player->timeToEffectCh
ange()); |
112 else | 114 else |
113 m_playersNeedingUpdate.remove(player); | 115 m_playersNeedingUpdate.remove(player); |
(...skipping 24 matching lines...) Expand all Loading... |
138 { | 140 { |
139 m_timer.stop(); | 141 m_timer.stop(); |
140 } | 142 } |
141 | 143 |
142 void DocumentTimeline::DocumentTimelineTiming::serviceOnNextFrame() | 144 void DocumentTimeline::DocumentTimelineTiming::serviceOnNextFrame() |
143 { | 145 { |
144 if (m_timeline->m_document && m_timeline->m_document->view()) | 146 if (m_timeline->m_document && m_timeline->m_document->view()) |
145 m_timeline->m_document->view()->scheduleAnimation(); | 147 m_timeline->m_document->view()->scheduleAnimation(); |
146 } | 148 } |
147 | 149 |
| 150 void DocumentTimeline::DocumentTimelineTiming::trace(Visitor* visitor) |
| 151 { |
| 152 visitor->trace(m_timeline); |
| 153 } |
| 154 |
148 double DocumentTimeline::currentTime(bool& isNull) | 155 double DocumentTimeline::currentTime(bool& isNull) |
149 { | 156 { |
150 return currentTimeInternal(isNull) * 1000; | 157 return currentTimeInternal(isNull) * 1000; |
151 } | 158 } |
152 | 159 |
153 double DocumentTimeline::currentTimeInternal(bool& isNull) | 160 double DocumentTimeline::currentTimeInternal(bool& isNull) |
154 { | 161 { |
155 if (!m_document) { | 162 if (!m_document) { |
156 isNull = true; | 163 isNull = true; |
157 return std::numeric_limits<double>::quiet_NaN(); | 164 return std::numeric_limits<double>::quiet_NaN(); |
(...skipping 15 matching lines...) Expand all Loading... |
173 } | 180 } |
174 | 181 |
175 double DocumentTimeline::effectiveTime() | 182 double DocumentTimeline::effectiveTime() |
176 { | 183 { |
177 double time = currentTimeInternal(); | 184 double time = currentTimeInternal(); |
178 return std::isnan(time) ? 0 : time; | 185 return std::isnan(time) ? 0 : time; |
179 } | 186 } |
180 | 187 |
181 void DocumentTimeline::pauseAnimationsForTesting(double pauseTime) | 188 void DocumentTimeline::pauseAnimationsForTesting(double pauseTime) |
182 { | 189 { |
183 for (HashSet<RefPtr<AnimationPlayer> >::iterator it = m_playersNeedingUpdate
.begin(); it != m_playersNeedingUpdate.end(); ++it) | 190 for (WillBeHeapHashSet<RefPtrWillBeMember<AnimationPlayer> >::iterator it =
m_playersNeedingUpdate.begin(); it != m_playersNeedingUpdate.end(); ++it) |
184 (*it)->pauseForTesting(pauseTime); | 191 (*it)->pauseForTesting(pauseTime); |
185 serviceAnimations(TimingUpdateOnDemand); | 192 serviceAnimations(TimingUpdateOnDemand); |
186 } | 193 } |
187 | 194 |
188 bool DocumentTimeline::hasOutdatedAnimationPlayer() const | 195 bool DocumentTimeline::hasOutdatedAnimationPlayer() const |
189 { | 196 { |
190 for (HashSet<RefPtr<AnimationPlayer> >::iterator it = m_playersNeedingUpdate
.begin(); it != m_playersNeedingUpdate.end(); ++it) { | 197 for (WillBeHeapHashSet<RefPtrWillBeMember<AnimationPlayer> >::iterator it =
m_playersNeedingUpdate.begin(); it != m_playersNeedingUpdate.end(); ++it) { |
191 if ((*it)->outdated()) | 198 if ((*it)->outdated()) |
192 return true; | 199 return true; |
193 } | 200 } |
194 return false; | 201 return false; |
195 } | 202 } |
196 | 203 |
197 void DocumentTimeline::setOutdatedAnimationPlayer(AnimationPlayer* player) | 204 void DocumentTimeline::setOutdatedAnimationPlayer(AnimationPlayer* player) |
198 { | 205 { |
199 ASSERT(player->outdated()); | 206 ASSERT(player->outdated()); |
200 m_playersNeedingUpdate.add(player); | 207 m_playersNeedingUpdate.add(player); |
201 if (m_document && m_document->page() && !m_document->page()->animator().isSe
rvicingAnimations()) | 208 if (m_document && m_document->page() && !m_document->page()->animator().isSe
rvicingAnimations()) |
202 m_timing->serviceOnNextFrame(); | 209 m_timing->serviceOnNextFrame(); |
203 } | 210 } |
204 | 211 |
205 size_t DocumentTimeline::numberOfActiveAnimationsForTesting() const | 212 size_t DocumentTimeline::numberOfActiveAnimationsForTesting() const |
206 { | 213 { |
207 // Includes all players whose directly associated timed items | 214 // Includes all players whose directly associated timed items |
208 // are current or in effect. | 215 // are current or in effect. |
209 if (isNull(m_zeroTime)) | 216 if (isNull(m_zeroTime)) |
210 return 0; | 217 return 0; |
211 size_t count = 0; | 218 size_t count = 0; |
212 for (HashSet<RefPtr<AnimationPlayer> >::iterator it = m_playersNeedingUpdate
.begin(); it != m_playersNeedingUpdate.end(); ++it) { | 219 for (WillBeHeapHashSet<RefPtrWillBeMember<AnimationPlayer> >::iterator it =
m_playersNeedingUpdate.begin(); it != m_playersNeedingUpdate.end(); ++it) { |
213 const TimedItem* timedItem = (*it)->source(); | 220 const TimedItem* timedItem = (*it)->source(); |
214 if ((*it)->hasStartTime()) | 221 if ((*it)->hasStartTime()) |
215 count += (timedItem && (timedItem->isCurrent() || timedItem->isInEff
ect())); | 222 count += (timedItem && (timedItem->isCurrent() || timedItem->isInEff
ect())); |
216 } | 223 } |
217 return count; | 224 return count; |
218 } | 225 } |
219 | 226 |
220 void DocumentTimeline::detachFromDocument() { | 227 #if !ENABLE(OILPAN) |
| 228 void DocumentTimeline::detachFromDocument() |
| 229 { |
221 // FIXME: DocumentTimeline should keep Document alive. | 230 // FIXME: DocumentTimeline should keep Document alive. |
222 m_document = 0; | 231 m_document = nullptr; |
| 232 } |
| 233 #endif |
| 234 |
| 235 void DocumentTimeline::trace(Visitor* visitor) |
| 236 { |
| 237 visitor->trace(m_document); |
| 238 visitor->trace(m_timing); |
| 239 visitor->trace(m_playersNeedingUpdate); |
| 240 visitor->trace(m_players); |
223 } | 241 } |
224 | 242 |
225 } // namespace | 243 } // namespace |
OLD | NEW |