| 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 13 matching lines...) Expand all Loading... |
| 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 */ | 29 */ |
| 30 | 30 |
| 31 #include "config.h" | 31 #include "config.h" |
| 32 #include "core/animation/CompositorPendingAnimations.h" | 32 #include "core/animation/CompositorPendingAnimations.h" |
| 33 | 33 |
| 34 #include "core/animation/Animation.h" | |
| 35 #include "core/animation/AnimationTimeline.h" | 34 #include "core/animation/AnimationTimeline.h" |
| 35 #include "core/animation/KeyframeEffect.h" |
| 36 #include "core/dom/Document.h" | 36 #include "core/dom/Document.h" |
| 37 #include "core/frame/FrameView.h" | 37 #include "core/frame/FrameView.h" |
| 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 blink { | 41 namespace blink { |
| 42 | 42 |
| 43 void CompositorPendingAnimations::add(AnimationPlayer* player) | 43 void CompositorPendingAnimations::add(Animation* animation) |
| 44 { | 44 { |
| 45 ASSERT(player); | 45 ASSERT(animation); |
| 46 ASSERT(m_pending.find(player) == kNotFound); | 46 ASSERT(m_pending.find(animation) == kNotFound); |
| 47 m_pending.append(player); | 47 m_pending.append(animation); |
| 48 | 48 |
| 49 Document* document = player->timeline()->document(); | 49 Document* document = animation->timeline()->document(); |
| 50 if (document->view()) | 50 if (document->view()) |
| 51 document->view()->scheduleAnimation(); | 51 document->view()->scheduleAnimation(); |
| 52 | 52 |
| 53 bool visible = document->page() && document->page()->visibilityState() == Pa
geVisibilityStateVisible; | 53 bool visible = document->page() && document->page()->visibilityState() == Pa
geVisibilityStateVisible; |
| 54 if (!visible && !m_timer.isActive()) { | 54 if (!visible && !m_timer.isActive()) { |
| 55 m_timer.startOneShot(0, FROM_HERE); | 55 m_timer.startOneShot(0, FROM_HERE); |
| 56 } | 56 } |
| 57 } | 57 } |
| 58 | 58 |
| 59 bool CompositorPendingAnimations::update(bool startOnCompositor) | 59 bool CompositorPendingAnimations::update(bool startOnCompositor) |
| 60 { | 60 { |
| 61 WillBeHeapVector<RawPtrWillBeMember<AnimationPlayer>> waitingForStartTime; | 61 WillBeHeapVector<RawPtrWillBeMember<Animation>> waitingForStartTime; |
| 62 bool startedSynchronizedOnCompositor = false; | 62 bool startedSynchronizedOnCompositor = false; |
| 63 | 63 |
| 64 WillBeHeapVector<RefPtrWillBeMember<AnimationPlayer>> players; | 64 WillBeHeapVector<RefPtrWillBeMember<Animation>> animations; |
| 65 players.swap(m_pending); | 65 animations.swap(m_pending); |
| 66 int compositorGroup = ++m_compositorGroup; | 66 int compositorGroup = ++m_compositorGroup; |
| 67 if (compositorGroup == 0) { | 67 if (compositorGroup == 0) { |
| 68 // Wrap around, skipping 0. | 68 // Wrap around, skipping 0. |
| 69 compositorGroup = ++m_compositorGroup; | 69 compositorGroup = ++m_compositorGroup; |
| 70 } | 70 } |
| 71 | 71 |
| 72 for (auto& player : players) { | 72 for (auto& animation : animations) { |
| 73 bool hadCompositorAnimation = player->hasActiveAnimationsOnCompositor(); | 73 bool hadCompositorAnimation = animation->hasActiveAnimationsOnCompositor
(); |
| 74 player->preCommit(compositorGroup, startOnCompositor); | 74 animation->preCommit(compositorGroup, startOnCompositor); |
| 75 if (player->hasActiveAnimationsOnCompositor() && !hadCompositorAnimation
) { | 75 if (animation->hasActiveAnimationsOnCompositor() && !hadCompositorAnimat
ion) { |
| 76 startedSynchronizedOnCompositor = true; | 76 startedSynchronizedOnCompositor = true; |
| 77 } | 77 } |
| 78 | 78 |
| 79 if (player->playing() && !player->hasStartTime()) { | 79 if (animation->playing() && !animation->hasStartTime()) { |
| 80 waitingForStartTime.append(player.get()); | 80 waitingForStartTime.append(animation.get()); |
| 81 } | 81 } |
| 82 } | 82 } |
| 83 | 83 |
| 84 // If any synchronized animations were started on the compositor, all | 84 // If any synchronized animations were started on the compositor, all |
| 85 // remaning synchronized animations need to wait for the synchronized | 85 // remaning synchronized animations need to wait for the synchronized |
| 86 // start time. Otherwise they may start immediately. | 86 // start time. Otherwise they may start immediately. |
| 87 if (startedSynchronizedOnCompositor) { | 87 if (startedSynchronizedOnCompositor) { |
| 88 for (auto& player : waitingForStartTime) { | 88 for (auto& animation : waitingForStartTime) { |
| 89 if (!player->hasStartTime()) { | 89 if (!animation->hasStartTime()) { |
| 90 m_waitingForCompositorAnimationStart.append(player); | 90 m_waitingForCompositorAnimationStart.append(animation); |
| 91 } | 91 } |
| 92 } | 92 } |
| 93 } else { | 93 } else { |
| 94 for (auto& player : waitingForStartTime) { | 94 for (auto& animation : waitingForStartTime) { |
| 95 if (!player->hasStartTime()) { | 95 if (!animation->hasStartTime()) { |
| 96 player->notifyCompositorStartTime(player->timeline()->currentTim
eInternal()); | 96 animation->notifyCompositorStartTime(animation->timeline()->curr
entTimeInternal()); |
| 97 } | 97 } |
| 98 } | 98 } |
| 99 } | 99 } |
| 100 | 100 |
| 101 // FIXME: The postCommit should happen *after* the commit, not before. | 101 // FIXME: The postCommit should happen *after* the commit, not before. |
| 102 for (auto& player : players) | 102 for (auto& animation : animations) |
| 103 player->postCommit(player->timeline()->currentTimeInternal()); | 103 animation->postCommit(animation->timeline()->currentTimeInternal()); |
| 104 | 104 |
| 105 ASSERT(m_pending.isEmpty()); | 105 ASSERT(m_pending.isEmpty()); |
| 106 | 106 |
| 107 if (startedSynchronizedOnCompositor) | 107 if (startedSynchronizedOnCompositor) |
| 108 return true; | 108 return true; |
| 109 | 109 |
| 110 if (m_waitingForCompositorAnimationStart.isEmpty()) | 110 if (m_waitingForCompositorAnimationStart.isEmpty()) |
| 111 return false; | 111 return false; |
| 112 | 112 |
| 113 // Check if we're still waiting for any compositor animations to start. | 113 // Check if we're still waiting for any compositor animations to start. |
| 114 for (auto& player : m_waitingForCompositorAnimationStart) { | 114 for (auto& animation : m_waitingForCompositorAnimationStart) { |
| 115 if (player->hasActiveAnimationsOnCompositor()) | 115 if (animation->hasActiveAnimationsOnCompositor()) |
| 116 return true; | 116 return true; |
| 117 } | 117 } |
| 118 | 118 |
| 119 // If not, go ahead and start any animations that were waiting. | 119 // If not, go ahead and start any animations that were waiting. |
| 120 notifyCompositorAnimationStarted(monotonicallyIncreasingTime()); | 120 notifyCompositorAnimationStarted(monotonicallyIncreasingTime()); |
| 121 | 121 |
| 122 ASSERT(m_pending.isEmpty()); | 122 ASSERT(m_pending.isEmpty()); |
| 123 return false; | 123 return false; |
| 124 } | 124 } |
| 125 | 125 |
| 126 void CompositorPendingAnimations::notifyCompositorAnimationStarted(double monoto
nicAnimationStartTime, int compositorGroup) | 126 void CompositorPendingAnimations::notifyCompositorAnimationStarted(double monoto
nicAnimationStartTime, int compositorGroup) |
| 127 { | 127 { |
| 128 TRACE_EVENT0("blink", "CompositorPendingAnimations::notifyCompositorAnimatio
nStarted"); | 128 TRACE_EVENT0("blink", "CompositorPendingAnimations::notifyCompositorAnimatio
nStarted"); |
| 129 WillBeHeapVector<RefPtrWillBeMember<AnimationPlayer>> players; | 129 WillBeHeapVector<RefPtrWillBeMember<Animation>> animations; |
| 130 players.swap(m_waitingForCompositorAnimationStart); | 130 animations.swap(m_waitingForCompositorAnimationStart); |
| 131 | 131 |
| 132 for (auto player : players) { | 132 for (auto animation : animations) { |
| 133 if (player->hasStartTime() || player->playStateInternal() != AnimationPl
ayer::Pending) { | 133 if (animation->hasStartTime() || animation->playStateInternal() != Anima
tion::Pending) { |
| 134 // Already started or no longer relevant. | 134 // Already started or no longer relevant. |
| 135 continue; | 135 continue; |
| 136 } | 136 } |
| 137 if (compositorGroup && player->compositorGroup() != compositorGroup) { | 137 if (compositorGroup && animation->compositorGroup() != compositorGroup)
{ |
| 138 // Still waiting. | 138 // Still waiting. |
| 139 m_waitingForCompositorAnimationStart.append(player); | 139 m_waitingForCompositorAnimationStart.append(animation); |
| 140 continue; | 140 continue; |
| 141 } | 141 } |
| 142 player->notifyCompositorStartTime(monotonicAnimationStartTime - player->
timeline()->zeroTime()); | 142 animation->notifyCompositorStartTime(monotonicAnimationStartTime - anima
tion->timeline()->zeroTime()); |
| 143 } | 143 } |
| 144 | 144 |
| 145 } | 145 } |
| 146 | 146 |
| 147 DEFINE_TRACE(CompositorPendingAnimations) | 147 DEFINE_TRACE(CompositorPendingAnimations) |
| 148 { | 148 { |
| 149 visitor->trace(m_pending); | 149 visitor->trace(m_pending); |
| 150 visitor->trace(m_waitingForCompositorAnimationStart); | 150 visitor->trace(m_waitingForCompositorAnimationStart); |
| 151 } | 151 } |
| 152 | 152 |
| 153 } // namespace | 153 } // namespace |
| OLD | NEW |