| 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->setStartTime(effectiveTime()); | 87 player->setStartTime(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 if (!m_document) { | 158 if (!m_document) { |
| 152 isNull = true; | 159 isNull = true; |
| 153 return std::numeric_limits<double>::quiet_NaN(); | 160 return std::numeric_limits<double>::quiet_NaN(); |
| 154 } | 161 } |
| 155 double result = m_document->animationClock().currentTime() - m_zeroTime; | 162 double result = m_document->animationClock().currentTime() - m_zeroTime; |
| 156 isNull = std::isnan(result); | 163 isNull = std::isnan(result); |
| 157 return result; | 164 return result; |
| 158 } | 165 } |
| 159 | 166 |
| 160 double DocumentTimeline::currentTime() | 167 double DocumentTimeline::currentTime() |
| 161 { | 168 { |
| 162 bool isNull; | 169 bool isNull; |
| 163 return currentTime(isNull); | 170 return currentTime(isNull); |
| 164 } | 171 } |
| 165 | 172 |
| 166 double DocumentTimeline::effectiveTime() | 173 double DocumentTimeline::effectiveTime() |
| 167 { | 174 { |
| 168 double time = currentTime(); | 175 double time = currentTime(); |
| 169 return std::isnan(time) ? 0 : time; | 176 return std::isnan(time) ? 0 : time; |
| 170 } | 177 } |
| 171 | 178 |
| 172 void DocumentTimeline::pauseAnimationsForTesting(double pauseTime) | 179 void DocumentTimeline::pauseAnimationsForTesting(double pauseTime) |
| 173 { | 180 { |
| 174 for (HashSet<RefPtr<AnimationPlayer> >::iterator it = m_playersNeedingUpdate
.begin(); it != m_playersNeedingUpdate.end(); ++it) | 181 for (WillBeHeapHashSet<RefPtrWillBeMember<AnimationPlayer> >::iterator it =
m_playersNeedingUpdate.begin(); it != m_playersNeedingUpdate.end(); ++it) |
| 175 (*it)->pauseForTesting(pauseTime); | 182 (*it)->pauseForTesting(pauseTime); |
| 176 serviceAnimations(AnimationPlayer::UpdateOnDemand); | 183 serviceAnimations(AnimationPlayer::UpdateOnDemand); |
| 177 } | 184 } |
| 178 | 185 |
| 179 void DocumentTimeline::setOutdatedAnimationPlayer(AnimationPlayer* player) | 186 void DocumentTimeline::setOutdatedAnimationPlayer(AnimationPlayer* player) |
| 180 { | 187 { |
| 181 m_playersNeedingUpdate.add(player); | 188 m_playersNeedingUpdate.add(player); |
| 182 m_hasOutdatedAnimationPlayer = true; | 189 m_hasOutdatedAnimationPlayer = true; |
| 183 if (m_document && m_document->page() && !m_document->page()->animator().isSe
rvicingAnimations()) | 190 if (m_document && m_document->page() && !m_document->page()->animator().isSe
rvicingAnimations()) |
| 184 m_timing->serviceOnNextFrame(); | 191 m_timing->serviceOnNextFrame(); |
| 185 } | 192 } |
| 186 | 193 |
| 187 size_t DocumentTimeline::numberOfActiveAnimationsForTesting() const | 194 size_t DocumentTimeline::numberOfActiveAnimationsForTesting() const |
| 188 { | 195 { |
| 189 // Includes all players whose directly associated timed items | 196 // Includes all players whose directly associated timed items |
| 190 // are current or in effect. | 197 // are current or in effect. |
| 191 if (isNull(m_zeroTime)) | 198 if (isNull(m_zeroTime)) |
| 192 return 0; | 199 return 0; |
| 193 size_t count = 0; | 200 size_t count = 0; |
| 194 for (HashSet<RefPtr<AnimationPlayer> >::iterator it = m_playersNeedingUpdate
.begin(); it != m_playersNeedingUpdate.end(); ++it) { | 201 for (WillBeHeapHashSet<RefPtrWillBeMember<AnimationPlayer> >::iterator it =
m_playersNeedingUpdate.begin(); it != m_playersNeedingUpdate.end(); ++it) { |
| 195 const TimedItem* timedItem = (*it)->source(); | 202 const TimedItem* timedItem = (*it)->source(); |
| 196 if ((*it)->hasStartTime()) | 203 if ((*it)->hasStartTime()) |
| 197 count += (timedItem && (timedItem->isCurrent() || timedItem->isInEff
ect())); | 204 count += (timedItem && (timedItem->isCurrent() || timedItem->isInEff
ect())); |
| 198 } | 205 } |
| 199 return count; | 206 return count; |
| 200 } | 207 } |
| 201 | 208 |
| 202 void DocumentTimeline::detachFromDocument() { | 209 void DocumentTimeline::detachFromDocument() |
| 210 { |
| 203 // FIXME: DocumentTimeline should keep Document alive. | 211 // FIXME: DocumentTimeline should keep Document alive. |
| 204 m_document = 0; | 212 m_document = 0; |
| 205 } | 213 } |
| 206 | 214 |
| 215 void DocumentTimeline::trace(Visitor* visitor) |
| 216 { |
| 217 visitor->trace(m_timing); |
| 218 visitor->trace(m_playersNeedingUpdate); |
| 219 visitor->trace(m_players); |
| 220 } |
| 221 |
| 207 } // namespace | 222 } // namespace |
| OLD | NEW |