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(AnimationPlayer::UpdateReason reason) | 97 void DocumentTimeline::serviceAnimations(AnimationPlayer::UpdateReason 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 m_hasOutdatedAnimationPlayer = false; | 102 m_hasOutdatedAnimationPlayer = false; |
101 | 103 |
102 double timeToNextEffect = std::numeric_limits<double>::infinity(); | 104 double timeToNextEffect = std::numeric_limits<double>::infinity(); |
103 Vector<AnimationPlayer*> players; | 105 WillBeHeapVector<RawPtrWillBeMember<AnimationPlayer> > players; |
104 for (HashSet<RefPtr<AnimationPlayer> >::iterator it = m_playersNeedingUpdate
.begin(); it != m_playersNeedingUpdate.end(); ++it) | 106 for (WillBeHeapHashSet<RefPtrWillBeMember<AnimationPlayer> >::iterator it =
m_playersNeedingUpdate.begin(); it != m_playersNeedingUpdate.end(); ++it) |
105 players.append(it->get()); | 107 players.append(it->get()); |
106 | 108 |
107 std::sort(players.begin(), players.end(), AnimationPlayer::hasLowerPriority)
; | 109 std::sort(players.begin(), players.end(), AnimationPlayer::hasLowerPriority)
; |
108 | 110 |
109 for (size_t i = 0; i < players.size(); ++i) { | 111 for (size_t i = 0; i < players.size(); ++i) { |
110 AnimationPlayer* player = players[i]; | 112 AnimationPlayer* player = players[i]; |
111 if (player->update(reason)) | 113 if (player->update(reason)) |
112 timeToNextEffect = std::min(timeToNextEffect, player->timeToEffectCh
ange()); | 114 timeToNextEffect = std::min(timeToNextEffect, player->timeToEffectCh
ange()); |
113 else | 115 else |
114 m_playersNeedingUpdate.remove(player); | 116 m_playersNeedingUpdate.remove(player); |
(...skipping 24 matching lines...) Expand all Loading... |
139 { | 141 { |
140 m_timer.stop(); | 142 m_timer.stop(); |
141 } | 143 } |
142 | 144 |
143 void DocumentTimeline::DocumentTimelineTiming::serviceOnNextFrame() | 145 void DocumentTimeline::DocumentTimelineTiming::serviceOnNextFrame() |
144 { | 146 { |
145 if (m_timeline->m_document && m_timeline->m_document->view()) | 147 if (m_timeline->m_document && m_timeline->m_document->view()) |
146 m_timeline->m_document->view()->scheduleAnimation(); | 148 m_timeline->m_document->view()->scheduleAnimation(); |
147 } | 149 } |
148 | 150 |
| 151 void DocumentTimeline::DocumentTimelineTiming::trace(Visitor* visitor) |
| 152 { |
| 153 visitor->trace(m_timeline); |
| 154 } |
| 155 |
149 double DocumentTimeline::currentTime(bool& isNull) | 156 double DocumentTimeline::currentTime(bool& isNull) |
150 { | 157 { |
151 return currentTimeInternal(isNull) * 1000; | 158 return currentTimeInternal(isNull) * 1000; |
152 } | 159 } |
153 | 160 |
154 double DocumentTimeline::currentTimeInternal(bool& isNull) | 161 double DocumentTimeline::currentTimeInternal(bool& isNull) |
155 { | 162 { |
156 if (!m_document) { | 163 if (!m_document) { |
157 isNull = true; | 164 isNull = true; |
158 return std::numeric_limits<double>::quiet_NaN(); | 165 return std::numeric_limits<double>::quiet_NaN(); |
(...skipping 15 matching lines...) Expand all Loading... |
174 } | 181 } |
175 | 182 |
176 double DocumentTimeline::effectiveTime() | 183 double DocumentTimeline::effectiveTime() |
177 { | 184 { |
178 double time = currentTimeInternal(); | 185 double time = currentTimeInternal(); |
179 return std::isnan(time) ? 0 : time; | 186 return std::isnan(time) ? 0 : time; |
180 } | 187 } |
181 | 188 |
182 void DocumentTimeline::pauseAnimationsForTesting(double pauseTime) | 189 void DocumentTimeline::pauseAnimationsForTesting(double pauseTime) |
183 { | 190 { |
184 for (HashSet<RefPtr<AnimationPlayer> >::iterator it = m_playersNeedingUpdate
.begin(); it != m_playersNeedingUpdate.end(); ++it) | 191 for (WillBeHeapHashSet<RefPtrWillBeMember<AnimationPlayer> >::iterator it =
m_playersNeedingUpdate.begin(); it != m_playersNeedingUpdate.end(); ++it) |
185 (*it)->pauseForTesting(pauseTime); | 192 (*it)->pauseForTesting(pauseTime); |
186 serviceAnimations(AnimationPlayer::UpdateOnDemand); | 193 serviceAnimations(AnimationPlayer::UpdateOnDemand); |
187 } | 194 } |
188 | 195 |
189 void DocumentTimeline::setOutdatedAnimationPlayer(AnimationPlayer* player) | 196 void DocumentTimeline::setOutdatedAnimationPlayer(AnimationPlayer* player) |
190 { | 197 { |
191 m_playersNeedingUpdate.add(player); | 198 m_playersNeedingUpdate.add(player); |
192 m_hasOutdatedAnimationPlayer = true; | 199 m_hasOutdatedAnimationPlayer = true; |
193 if (m_document && m_document->page() && !m_document->page()->animator().isSe
rvicingAnimations()) | 200 if (m_document && m_document->page() && !m_document->page()->animator().isSe
rvicingAnimations()) |
194 m_timing->serviceOnNextFrame(); | 201 m_timing->serviceOnNextFrame(); |
195 } | 202 } |
196 | 203 |
197 size_t DocumentTimeline::numberOfActiveAnimationsForTesting() const | 204 size_t DocumentTimeline::numberOfActiveAnimationsForTesting() const |
198 { | 205 { |
199 // Includes all players whose directly associated timed items | 206 // Includes all players whose directly associated timed items |
200 // are current or in effect. | 207 // are current or in effect. |
201 if (isNull(m_zeroTime)) | 208 if (isNull(m_zeroTime)) |
202 return 0; | 209 return 0; |
203 size_t count = 0; | 210 size_t count = 0; |
204 for (HashSet<RefPtr<AnimationPlayer> >::iterator it = m_playersNeedingUpdate
.begin(); it != m_playersNeedingUpdate.end(); ++it) { | 211 for (WillBeHeapHashSet<RefPtrWillBeMember<AnimationPlayer> >::iterator it =
m_playersNeedingUpdate.begin(); it != m_playersNeedingUpdate.end(); ++it) { |
205 const TimedItem* timedItem = (*it)->source(); | 212 const TimedItem* timedItem = (*it)->source(); |
206 if ((*it)->hasStartTime()) | 213 if ((*it)->hasStartTime()) |
207 count += (timedItem && (timedItem->isCurrent() || timedItem->isInEff
ect())); | 214 count += (timedItem && (timedItem->isCurrent() || timedItem->isInEff
ect())); |
208 } | 215 } |
209 return count; | 216 return count; |
210 } | 217 } |
211 | 218 |
212 void DocumentTimeline::detachFromDocument() { | 219 void DocumentTimeline::detachFromDocument() |
| 220 { |
213 // FIXME: DocumentTimeline should keep Document alive. | 221 // FIXME: DocumentTimeline should keep Document alive. |
214 m_document = 0; | 222 m_document = 0; |
215 } | 223 } |
216 | 224 |
| 225 void DocumentTimeline::trace(Visitor* visitor) |
| 226 { |
| 227 visitor->trace(m_timing); |
| 228 visitor->trace(m_playersNeedingUpdate); |
| 229 visitor->trace(m_players); |
| 230 } |
| 231 |
217 } // namespace | 232 } // namespace |
OLD | NEW |