| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "config.h" | 5 #include "config.h" |
| 6 #include "platform/scroll/ProgrammaticScrollAnimator.h" | 6 #include "platform/scroll/ProgrammaticScrollAnimator.h" |
| 7 | 7 |
| 8 #include "platform/RuntimeEnabledFeatures.h" | 8 #include "platform/RuntimeEnabledFeatures.h" |
| 9 #include "platform/geometry/IntPoint.h" | 9 #include "platform/geometry/IntPoint.h" |
| 10 #include "platform/graphics/GraphicsLayer.h" | 10 #include "platform/graphics/GraphicsLayer.h" |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 return adoptPtr(new ProgrammaticScrollAnimator(scrollableArea)); | 23 return adoptPtr(new ProgrammaticScrollAnimator(scrollableArea)); |
| 24 } | 24 } |
| 25 | 25 |
| 26 ProgrammaticScrollAnimator::ProgrammaticScrollAnimator(ScrollableArea* scrollabl
eArea) | 26 ProgrammaticScrollAnimator::ProgrammaticScrollAnimator(ScrollableArea* scrollabl
eArea) |
| 27 : m_scrollableArea(scrollableArea) | 27 : m_scrollableArea(scrollableArea) |
| 28 , m_startTime(0.0) | 28 , m_startTime(0.0) |
| 29 , m_runState(RunState::Idle) | 29 , m_runState(RunState::Idle) |
| 30 , m_compositorAnimationId(0) | 30 , m_compositorAnimationId(0) |
| 31 , m_compositorAnimationGroupId(0) | 31 , m_compositorAnimationGroupId(0) |
| 32 { | 32 { |
| 33 if (RuntimeEnabledFeatures::compositorAnimationTimelinesEnabled() && Platfor
m::current()->compositorSupport()) { | 33 m_compositorPlayer = adoptPtr(Platform::current()->compositorSupport()->crea
teAnimationPlayer()); |
| 34 m_compositorPlayer = adoptPtr(Platform::current()->compositorSupport()->
createAnimationPlayer()); | 34 ASSERT(m_compositorPlayer); |
| 35 ASSERT(m_compositorPlayer); | 35 m_compositorPlayer->setAnimationDelegate(this); |
| 36 m_compositorPlayer->setAnimationDelegate(this); | |
| 37 } | |
| 38 } | 36 } |
| 39 | 37 |
| 40 ProgrammaticScrollAnimator::~ProgrammaticScrollAnimator() | 38 ProgrammaticScrollAnimator::~ProgrammaticScrollAnimator() |
| 41 { | 39 { |
| 42 if (m_compositorPlayer) { | 40 m_compositorPlayer->setAnimationDelegate(nullptr); |
| 43 m_compositorPlayer->setAnimationDelegate(nullptr); | |
| 44 m_compositorPlayer.clear(); | |
| 45 } | |
| 46 } | 41 } |
| 47 | 42 |
| 48 void ProgrammaticScrollAnimator::resetAnimationState() | 43 void ProgrammaticScrollAnimator::resetAnimationState() |
| 49 { | 44 { |
| 50 m_animationCurve.clear(); | 45 m_animationCurve.clear(); |
| 51 m_startTime = 0.0; | 46 m_startTime = 0.0; |
| 52 m_runState = RunState::Idle; | 47 m_runState = RunState::Idle; |
| 53 m_compositorAnimationId = 0; | 48 m_compositorAnimationId = 0; |
| 54 m_compositorAnimationGroupId = 0; | 49 m_compositorAnimationGroupId = 0; |
| 55 } | 50 } |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 | 126 |
| 132 void ProgrammaticScrollAnimator::updateCompositorAnimations() | 127 void ProgrammaticScrollAnimator::updateCompositorAnimations() |
| 133 { | 128 { |
| 134 if (m_compositorAnimationId && m_runState != RunState::RunningOnCompositor)
{ | 129 if (m_compositorAnimationId && m_runState != RunState::RunningOnCompositor)
{ |
| 135 // If the current run state is WaitingToSendToCompositor but we have a | 130 // If the current run state is WaitingToSendToCompositor but we have a |
| 136 // non-zero compositor animation id, there's a currently running | 131 // non-zero compositor animation id, there's a currently running |
| 137 // compositor animation that needs to be removed here before the new | 132 // compositor animation that needs to be removed here before the new |
| 138 // animation is added below. | 133 // animation is added below. |
| 139 ASSERT(m_runState == RunState::WaitingToCancelOnCompositor || m_runState
== RunState::WaitingToSendToCompositor); | 134 ASSERT(m_runState == RunState::WaitingToCancelOnCompositor || m_runState
== RunState::WaitingToSendToCompositor); |
| 140 | 135 |
| 141 if (m_compositorPlayer) { | 136 if (m_compositorPlayer->isLayerAttached()) |
| 142 if (m_compositorPlayer->isLayerAttached()) | 137 m_compositorPlayer->removeAnimation(m_compositorAnimationId); |
| 143 m_compositorPlayer->removeAnimation(m_compositorAnimationId); | |
| 144 } else { | |
| 145 if (GraphicsLayer* layer = m_scrollableArea->layerForScrolling()) | |
| 146 layer->removeAnimation(m_compositorAnimationId); | |
| 147 } | |
| 148 | 138 |
| 149 m_compositorAnimationId = 0; | 139 m_compositorAnimationId = 0; |
| 150 m_compositorAnimationGroupId = 0; | 140 m_compositorAnimationGroupId = 0; |
| 151 if (m_runState == RunState::WaitingToCancelOnCompositor) { | 141 if (m_runState == RunState::WaitingToCancelOnCompositor) { |
| 152 resetAnimationState(); | 142 resetAnimationState(); |
| 153 return; | 143 return; |
| 154 } | 144 } |
| 155 } | 145 } |
| 156 | 146 |
| 157 if (m_runState == RunState::WaitingToSendToCompositor) { | 147 if (m_runState == RunState::WaitingToSendToCompositor) { |
| 158 bool sentToCompositor = false; | 148 bool sentToCompositor = false; |
| 159 | 149 |
| 160 if (GraphicsLayer* layer = m_scrollableArea->layerForScrolling()) { | 150 if (GraphicsLayer* layer = m_scrollableArea->layerForScrolling()) { |
| 161 if (!layer->platformLayer()->shouldScrollOnMainThread()) { | 151 if (!layer->platformLayer()->shouldScrollOnMainThread()) { |
| 162 OwnPtr<WebCompositorAnimation> animation = adoptPtr(Platform::cu
rrent()->compositorSupport()->createAnimation(*m_animationCurve, WebCompositorAn
imation::TargetPropertyScrollOffset)); | 152 OwnPtr<WebCompositorAnimation> animation = adoptPtr(Platform::cu
rrent()->compositorSupport()->createAnimation(*m_animationCurve, WebCompositorAn
imation::TargetPropertyScrollOffset)); |
| 163 | 153 |
| 164 int animationId = animation->id(); | 154 int animationId = animation->id(); |
| 165 int animationGroupId = animation->group(); | 155 int animationGroupId = animation->group(); |
| 166 | 156 |
| 167 bool animatonAdded = false; | 157 if (m_compositorPlayer->isLayerAttached()) { |
| 168 if (m_compositorPlayer && m_compositorPlayer->isLayerAttached())
{ | |
| 169 m_compositorPlayer->addAnimation(animation.leakPtr()); | 158 m_compositorPlayer->addAnimation(animation.leakPtr()); |
| 170 animatonAdded = true; | |
| 171 } else { | |
| 172 animatonAdded = m_scrollableArea->layerForScrolling()->addAn
imation(animation.release()); | |
| 173 } | |
| 174 | |
| 175 if (animatonAdded) { | |
| 176 sentToCompositor = true; | 159 sentToCompositor = true; |
| 177 m_runState = RunState::RunningOnCompositor; | 160 m_runState = RunState::RunningOnCompositor; |
| 178 m_compositorAnimationId = animationId; | 161 m_compositorAnimationId = animationId; |
| 179 m_compositorAnimationGroupId = animationGroupId; | 162 m_compositorAnimationGroupId = animationGroupId; |
| 180 } | 163 } |
| 181 } | 164 } |
| 182 } | 165 } |
| 183 | 166 |
| 184 if (!sentToCompositor) { | 167 if (!sentToCompositor) { |
| 185 m_runState = RunState::RunningOnMainThread; | 168 m_runState = RunState::RunningOnMainThread; |
| 186 if (!m_scrollableArea->scheduleAnimation()) { | 169 if (!m_scrollableArea->scheduleAnimation()) { |
| 187 m_scrollableArea->notifyScrollPositionChanged(IntPoint(m_targetO
ffset.x(), m_targetOffset.y())); | 170 m_scrollableArea->notifyScrollPositionChanged(IntPoint(m_targetO
ffset.x(), m_targetOffset.y())); |
| 188 resetAnimationState(); | 171 resetAnimationState(); |
| 189 } | 172 } |
| 190 } | 173 } |
| 191 } | 174 } |
| 192 } | 175 } |
| 193 | 176 |
| 194 void ProgrammaticScrollAnimator::layerForCompositedScrollingDidChange(WebComposi
torAnimationTimeline* timeline) | 177 void ProgrammaticScrollAnimator::layerForCompositedScrollingDidChange(WebComposi
torAnimationTimeline* timeline) |
| 195 { | 178 { |
| 196 if (m_compositorPlayer && timeline) { | 179 if (m_compositorPlayer->isLayerAttached()) |
| 197 if (m_compositorPlayer->isLayerAttached()) | 180 m_compositorPlayer->detachLayer(); |
| 198 m_compositorPlayer->detachLayer(); | 181 |
| 199 timeline->playerDestroyed(*this); | 182 timeline->playerDestroyed(*this); |
| 200 } | |
| 201 | 183 |
| 202 // If the composited scrolling layer is lost during a composited animation, | 184 // If the composited scrolling layer is lost during a composited animation, |
| 203 // continue the animation on the main thread. | 185 // continue the animation on the main thread. |
| 204 if (m_runState == RunState::RunningOnCompositor && !m_scrollableArea->layerF
orScrolling()) { | 186 if (m_runState == RunState::RunningOnCompositor && !m_scrollableArea->layerF
orScrolling()) { |
| 205 m_runState = RunState::RunningOnMainThread; | 187 m_runState = RunState::RunningOnMainThread; |
| 206 m_compositorAnimationId = 0; | 188 m_compositorAnimationId = 0; |
| 207 m_compositorAnimationGroupId = 0; | 189 m_compositorAnimationGroupId = 0; |
| 208 m_animationCurve->setInitialValue(FloatPoint(m_scrollableArea->scrollPos
ition())); | 190 m_animationCurve->setInitialValue(FloatPoint(m_scrollableArea->scrollPos
ition())); |
| 209 m_scrollableArea->registerForAnimation(); | 191 m_scrollableArea->registerForAnimation(); |
| 210 if (!m_scrollableArea->scheduleAnimation()) { | 192 if (!m_scrollableArea->scheduleAnimation()) { |
| 211 resetAnimationState(); | 193 resetAnimationState(); |
| 212 m_scrollableArea->notifyScrollPositionChanged(IntPoint(m_targetOffse
t.x(), m_targetOffset.y())); | 194 m_scrollableArea->notifyScrollPositionChanged(IntPoint(m_targetOffse
t.x(), m_targetOffset.y())); |
| 213 } | 195 } |
| 214 } | 196 } |
| 215 | 197 |
| 216 if (m_compositorPlayer && timeline && m_scrollableArea->layerForScrolling())
{ | 198 if (m_scrollableArea->layerForScrolling()) { |
| 217 timeline->playerAttached(*this); | 199 timeline->playerAttached(*this); |
| 218 m_compositorPlayer->attachLayer(m_scrollableArea->layerForScrolling()->p
latformLayer()); | 200 m_compositorPlayer->attachLayer(m_scrollableArea->layerForScrolling()->p
latformLayer()); |
| 219 } | 201 } |
| 220 } | 202 } |
| 221 | 203 |
| 222 void ProgrammaticScrollAnimator::notifyCompositorAnimationFinished(int groupId) | 204 void ProgrammaticScrollAnimator::notifyAnimationStarted(double monotonicTime, in
t group) |
| 223 { | 205 { |
| 224 if (m_compositorAnimationGroupId != groupId) | 206 } |
| 207 |
| 208 void ProgrammaticScrollAnimator::notifyAnimationFinished(double monotonicTime, i
nt group) |
| 209 { |
| 210 if (m_compositorAnimationGroupId != group) |
| 225 return; | 211 return; |
| 226 | 212 |
| 227 m_compositorAnimationId = 0; | 213 m_compositorAnimationId = 0; |
| 228 m_compositorAnimationGroupId = 0; | 214 m_compositorAnimationGroupId = 0; |
| 229 | 215 |
| 230 switch (m_runState) { | 216 switch (m_runState) { |
| 231 case RunState::Idle: | 217 case RunState::Idle: |
| 232 case RunState::RunningOnMainThread: | 218 case RunState::RunningOnMainThread: |
| 233 ASSERT_NOT_REACHED(); | 219 ASSERT_NOT_REACHED(); |
| 234 break; | 220 break; |
| 235 case RunState::WaitingToSendToCompositor: | 221 case RunState::WaitingToSendToCompositor: |
| 236 break; | 222 break; |
| 237 case RunState::RunningOnCompositor: | 223 case RunState::RunningOnCompositor: |
| 238 case RunState::WaitingToCancelOnCompositor: | 224 case RunState::WaitingToCancelOnCompositor: |
| 239 resetAnimationState(); | 225 resetAnimationState(); |
| 240 } | 226 } |
| 241 } | 227 } |
| 242 | 228 |
| 243 void ProgrammaticScrollAnimator::notifyAnimationStarted(double monotonicTime, in
t group) | |
| 244 { | |
| 245 } | |
| 246 | |
| 247 void ProgrammaticScrollAnimator::notifyAnimationFinished(double monotonicTime, i
nt group) | |
| 248 { | |
| 249 notifyCompositorAnimationFinished(group); | |
| 250 } | |
| 251 | |
| 252 WebCompositorAnimationPlayer* ProgrammaticScrollAnimator::compositorPlayer() con
st | 229 WebCompositorAnimationPlayer* ProgrammaticScrollAnimator::compositorPlayer() con
st |
| 253 { | 230 { |
| 254 return m_compositorPlayer.get(); | 231 return m_compositorPlayer.get(); |
| 255 } | 232 } |
| 256 | 233 |
| 257 } // namespace blink | 234 } // namespace blink |
| OLD | NEW |