| 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 "platform/scroll/ProgrammaticScrollAnimator.h" | 5 #include "platform/scroll/ProgrammaticScrollAnimator.h" |
| 6 | 6 |
| 7 #include "platform/animation/CompositorAnimation.h" |
| 8 #include "platform/animation/CompositorScrollOffsetAnimationCurve.h" |
| 7 #include "platform/geometry/IntPoint.h" | 9 #include "platform/geometry/IntPoint.h" |
| 10 #include "platform/graphics/CompositorFactory.h" |
| 8 #include "platform/graphics/GraphicsLayer.h" | 11 #include "platform/graphics/GraphicsLayer.h" |
| 9 #include "platform/scroll/ScrollableArea.h" | 12 #include "platform/scroll/ScrollableArea.h" |
| 10 #include "public/platform/Platform.h" | 13 #include "public/platform/Platform.h" |
| 11 #include "public/platform/WebCompositorAnimation.h" | |
| 12 #include "public/platform/WebCompositorSupport.h" | 14 #include "public/platform/WebCompositorSupport.h" |
| 13 #include "public/platform/WebScrollOffsetAnimationCurve.h" | |
| 14 | 15 |
| 15 namespace blink { | 16 namespace blink { |
| 16 | 17 |
| 17 PassOwnPtrWillBeRawPtr<ProgrammaticScrollAnimator> ProgrammaticScrollAnimator::c
reate(ScrollableArea* scrollableArea) | 18 PassOwnPtrWillBeRawPtr<ProgrammaticScrollAnimator> ProgrammaticScrollAnimator::c
reate(ScrollableArea* scrollableArea) |
| 18 { | 19 { |
| 19 return adoptPtrWillBeNoop(new ProgrammaticScrollAnimator(scrollableArea)); | 20 return adoptPtrWillBeNoop(new ProgrammaticScrollAnimator(scrollableArea)); |
| 20 } | 21 } |
| 21 | 22 |
| 22 ProgrammaticScrollAnimator::ProgrammaticScrollAnimator(ScrollableArea* scrollabl
eArea) | 23 ProgrammaticScrollAnimator::ProgrammaticScrollAnimator(ScrollableArea* scrollabl
eArea) |
| 23 : m_scrollableArea(scrollableArea) | 24 : m_scrollableArea(scrollableArea) |
| (...skipping 23 matching lines...) Expand all Loading... |
| 47 notifyPositionChanged(offset); | 48 notifyPositionChanged(offset); |
| 48 } | 49 } |
| 49 | 50 |
| 50 void ProgrammaticScrollAnimator::animateToOffset(FloatPoint offset) | 51 void ProgrammaticScrollAnimator::animateToOffset(FloatPoint offset) |
| 51 { | 52 { |
| 52 if (m_runState == RunState::PostAnimationCleanup) | 53 if (m_runState == RunState::PostAnimationCleanup) |
| 53 resetAnimationState(); | 54 resetAnimationState(); |
| 54 | 55 |
| 55 m_startTime = 0.0; | 56 m_startTime = 0.0; |
| 56 m_targetOffset = offset; | 57 m_targetOffset = offset; |
| 57 m_animationCurve = adoptPtr(Platform::current()->compositorSupport()->create
ScrollOffsetAnimationCurve( | 58 m_animationCurve = adoptPtr(CompositorFactory::current().createScrollOffsetA
nimationCurve( |
| 58 m_targetOffset, | 59 m_targetOffset, |
| 59 WebCompositorAnimationCurve::TimingFunctionTypeEaseInOut, | 60 CompositorAnimationCurve::TimingFunctionTypeEaseInOut, |
| 60 WebScrollOffsetAnimationCurve::ScrollDurationDeltaBased)); | 61 CompositorScrollOffsetAnimationCurve::ScrollDurationDeltaBased)); |
| 61 | 62 |
| 62 m_scrollableArea->registerForAnimation(); | 63 m_scrollableArea->registerForAnimation(); |
| 63 if (!m_scrollableArea->scheduleAnimation()) { | 64 if (!m_scrollableArea->scheduleAnimation()) { |
| 64 resetAnimationState(); | 65 resetAnimationState(); |
| 65 notifyPositionChanged(IntPoint(offset.x(), offset.y())); | 66 notifyPositionChanged(IntPoint(offset.x(), offset.y())); |
| 66 } | 67 } |
| 67 m_runState = RunState::WaitingToSendToCompositor; | 68 m_runState = RunState::WaitingToSendToCompositor; |
| 68 } | 69 } |
| 69 | 70 |
| 70 void ProgrammaticScrollAnimator::cancelAnimation() | 71 void ProgrammaticScrollAnimator::cancelAnimation() |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 if (m_runState == RunState::WaitingToCancelOnCompositor) { | 117 if (m_runState == RunState::WaitingToCancelOnCompositor) { |
| 117 resetAnimationState(); | 118 resetAnimationState(); |
| 118 return; | 119 return; |
| 119 } | 120 } |
| 120 } | 121 } |
| 121 | 122 |
| 122 if (m_runState == RunState::WaitingToSendToCompositor) { | 123 if (m_runState == RunState::WaitingToSendToCompositor) { |
| 123 bool sentToCompositor = false; | 124 bool sentToCompositor = false; |
| 124 | 125 |
| 125 if (!m_scrollableArea->shouldScrollOnMainThread()) { | 126 if (!m_scrollableArea->shouldScrollOnMainThread()) { |
| 126 OwnPtr<WebCompositorAnimation> animation = adoptPtr(Platform::curren
t()->compositorSupport()->createAnimation(*m_animationCurve, WebCompositorAnimat
ion::TargetPropertyScrollOffset)); | 127 OwnPtr<CompositorAnimation> animation = adoptPtr(CompositorFactory::
current().createAnimation(*m_animationCurve, CompositorAnimation::TargetProperty
ScrollOffset)); |
| 127 | 128 |
| 128 int animationId = animation->id(); | 129 int animationId = animation->id(); |
| 129 int animationGroupId = animation->group(); | 130 int animationGroupId = animation->group(); |
| 130 | 131 |
| 131 if (addAnimation(animation.release())) { | 132 if (addAnimation(animation.release())) { |
| 132 sentToCompositor = true; | 133 sentToCompositor = true; |
| 133 m_runState = RunState::RunningOnCompositor; | 134 m_runState = RunState::RunningOnCompositor; |
| 134 m_compositorAnimationId = animationId; | 135 m_compositorAnimationId = animationId; |
| 135 m_compositorAnimationGroupId = animationGroupId; | 136 m_compositorAnimationGroupId = animationGroupId; |
| 136 } | 137 } |
| 137 } | 138 } |
| 138 | 139 |
| 139 if (!sentToCompositor) { | 140 if (!sentToCompositor) { |
| 140 m_runState = RunState::RunningOnMainThread; | 141 m_runState = RunState::RunningOnMainThread; |
| 141 m_animationCurve->setInitialValue(FloatPoint(m_scrollableArea->scrol
lPosition())); | 142 m_animationCurve->setInitialValue(FloatPoint(m_scrollableArea->scrol
lPosition())); |
| 142 if (!m_scrollableArea->scheduleAnimation()) { | 143 if (!m_scrollableArea->scheduleAnimation()) { |
| 143 notifyPositionChanged(IntPoint(m_targetOffset.x(), m_targetOffse
t.y())); | 144 notifyPositionChanged(IntPoint(m_targetOffset.x(), m_targetOffse
t.y())); |
| 144 resetAnimationState(); | 145 resetAnimationState(); |
| 145 } | 146 } |
| 146 } | 147 } |
| 147 } | 148 } |
| 148 } | 149 } |
| 149 | 150 |
| 150 void ProgrammaticScrollAnimator::layerForCompositedScrollingDidChange(WebComposi
torAnimationTimeline* timeline) | 151 void ProgrammaticScrollAnimator::layerForCompositedScrollingDidChange(Compositor
AnimationTimeline* timeline) |
| 151 { | 152 { |
| 152 reattachCompositorPlayerIfNeeded(timeline); | 153 reattachCompositorPlayerIfNeeded(timeline); |
| 153 | 154 |
| 154 // If the composited scrolling layer is lost during a composited animation, | 155 // If the composited scrolling layer is lost during a composited animation, |
| 155 // continue the animation on the main thread. | 156 // continue the animation on the main thread. |
| 156 if (m_runState == RunState::RunningOnCompositor && !m_scrollableArea->layerF
orScrolling()) { | 157 if (m_runState == RunState::RunningOnCompositor && !m_scrollableArea->layerF
orScrolling()) { |
| 157 m_runState = RunState::RunningOnMainThread; | 158 m_runState = RunState::RunningOnMainThread; |
| 158 m_compositorAnimationId = 0; | 159 m_compositorAnimationId = 0; |
| 159 m_compositorAnimationGroupId = 0; | 160 m_compositorAnimationGroupId = 0; |
| 160 m_animationCurve->setInitialValue(FloatPoint(m_scrollableArea->scrollPos
ition())); | 161 m_animationCurve->setInitialValue(FloatPoint(m_scrollableArea->scrollPos
ition())); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 172 ScrollAnimatorCompositorCoordinator::compositorAnimationFinished(groupId); | 173 ScrollAnimatorCompositorCoordinator::compositorAnimationFinished(groupId); |
| 173 } | 174 } |
| 174 | 175 |
| 175 DEFINE_TRACE(ProgrammaticScrollAnimator) | 176 DEFINE_TRACE(ProgrammaticScrollAnimator) |
| 176 { | 177 { |
| 177 visitor->trace(m_scrollableArea); | 178 visitor->trace(m_scrollableArea); |
| 178 ScrollAnimatorCompositorCoordinator::trace(visitor); | 179 ScrollAnimatorCompositorCoordinator::trace(visitor); |
| 179 } | 180 } |
| 180 | 181 |
| 181 } // namespace blink | 182 } // namespace blink |
| OLD | NEW |