| 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" | 7 #include "platform/animation/CompositorAnimation.h" |
| 8 #include "platform/animation/CompositorScrollOffsetAnimationCurve.h" | 8 #include "platform/animation/CompositorScrollOffsetAnimationCurve.h" |
| 9 #include "platform/geometry/IntPoint.h" | 9 #include "platform/geometry/IntPoint.h" |
| 10 #include "platform/graphics/CompositorFactory.h" | 10 #include "platform/graphics/CompositorFactory.h" |
| 11 #include "platform/graphics/GraphicsLayer.h" | 11 #include "platform/graphics/GraphicsLayer.h" |
| 12 #include "platform/scroll/ScrollableArea.h" | 12 #include "platform/scroll/ScrollableArea.h" |
| 13 #include "public/platform/Platform.h" | 13 #include "public/platform/Platform.h" |
| 14 #include "public/platform/WebCompositorSupport.h" | 14 #include "public/platform/WebCompositorSupport.h" |
| 15 #include "wtf/PtrUtil.h" |
| 16 #include <memory> |
| 15 | 17 |
| 16 namespace blink { | 18 namespace blink { |
| 17 | 19 |
| 18 ProgrammaticScrollAnimator::ProgrammaticScrollAnimator(ScrollableArea* scrollabl
eArea) | 20 ProgrammaticScrollAnimator::ProgrammaticScrollAnimator(ScrollableArea* scrollabl
eArea) |
| 19 : m_scrollableArea(scrollableArea) | 21 : m_scrollableArea(scrollableArea) |
| 20 , m_startTime(0.0) | 22 , m_startTime(0.0) |
| 21 { | 23 { |
| 22 } | 24 } |
| 23 | 25 |
| 24 ProgrammaticScrollAnimator::~ProgrammaticScrollAnimator() | 26 ProgrammaticScrollAnimator::~ProgrammaticScrollAnimator() |
| (...skipping 18 matching lines...) Expand all Loading... |
| 43 notifyPositionChanged(offset); | 45 notifyPositionChanged(offset); |
| 44 } | 46 } |
| 45 | 47 |
| 46 void ProgrammaticScrollAnimator::animateToOffset(FloatPoint offset) | 48 void ProgrammaticScrollAnimator::animateToOffset(FloatPoint offset) |
| 47 { | 49 { |
| 48 if (m_runState == RunState::PostAnimationCleanup) | 50 if (m_runState == RunState::PostAnimationCleanup) |
| 49 resetAnimationState(); | 51 resetAnimationState(); |
| 50 | 52 |
| 51 m_startTime = 0.0; | 53 m_startTime = 0.0; |
| 52 m_targetOffset = offset; | 54 m_targetOffset = offset; |
| 53 m_animationCurve = adoptPtr(CompositorFactory::current().createScrollOffsetA
nimationCurve( | 55 m_animationCurve = wrapUnique(CompositorFactory::current().createScrollOffse
tAnimationCurve( |
| 54 compositorOffsetFromBlinkOffset(m_targetOffset), | 56 compositorOffsetFromBlinkOffset(m_targetOffset), |
| 55 CompositorScrollOffsetAnimationCurve::ScrollDurationDeltaBased)); | 57 CompositorScrollOffsetAnimationCurve::ScrollDurationDeltaBased)); |
| 56 | 58 |
| 57 m_scrollableArea->registerForAnimation(); | 59 m_scrollableArea->registerForAnimation(); |
| 58 if (!m_scrollableArea->scheduleAnimation()) { | 60 if (!m_scrollableArea->scheduleAnimation()) { |
| 59 resetAnimationState(); | 61 resetAnimationState(); |
| 60 notifyPositionChanged(IntPoint(offset.x(), offset.y())); | 62 notifyPositionChanged(IntPoint(offset.x(), offset.y())); |
| 61 } | 63 } |
| 62 m_runState = RunState::WaitingToSendToCompositor; | 64 m_runState = RunState::WaitingToSendToCompositor; |
| 63 } | 65 } |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 } | 116 } |
| 115 } | 117 } |
| 116 | 118 |
| 117 if (m_runState == RunState::WaitingToSendToCompositor) { | 119 if (m_runState == RunState::WaitingToSendToCompositor) { |
| 118 if (!m_compositorAnimationAttachedToLayerId) | 120 if (!m_compositorAnimationAttachedToLayerId) |
| 119 reattachCompositorPlayerIfNeeded(getScrollableArea()->compositorAnim
ationTimeline()); | 121 reattachCompositorPlayerIfNeeded(getScrollableArea()->compositorAnim
ationTimeline()); |
| 120 | 122 |
| 121 bool sentToCompositor = false; | 123 bool sentToCompositor = false; |
| 122 | 124 |
| 123 if (!m_scrollableArea->shouldScrollOnMainThread()) { | 125 if (!m_scrollableArea->shouldScrollOnMainThread()) { |
| 124 OwnPtr<CompositorAnimation> animation = adoptPtr(CompositorFactory::
current().createAnimation(*m_animationCurve, CompositorTargetProperty::SCROLL_OF
FSET)); | 126 std::unique_ptr<CompositorAnimation> animation = wrapUnique(Composit
orFactory::current().createAnimation(*m_animationCurve, CompositorTargetProperty
::SCROLL_OFFSET)); |
| 125 | 127 |
| 126 int animationId = animation->id(); | 128 int animationId = animation->id(); |
| 127 int animationGroupId = animation->group(); | 129 int animationGroupId = animation->group(); |
| 128 | 130 |
| 129 if (addAnimation(std::move(animation))) { | 131 if (addAnimation(std::move(animation))) { |
| 130 sentToCompositor = true; | 132 sentToCompositor = true; |
| 131 m_runState = RunState::RunningOnCompositor; | 133 m_runState = RunState::RunningOnCompositor; |
| 132 m_compositorAnimationId = animationId; | 134 m_compositorAnimationId = animationId; |
| 133 m_compositorAnimationGroupId = animationGroupId; | 135 m_compositorAnimationGroupId = animationGroupId; |
| 134 } | 136 } |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 172 ScrollAnimatorCompositorCoordinator::compositorAnimationFinished(groupId); | 174 ScrollAnimatorCompositorCoordinator::compositorAnimationFinished(groupId); |
| 173 } | 175 } |
| 174 | 176 |
| 175 DEFINE_TRACE(ProgrammaticScrollAnimator) | 177 DEFINE_TRACE(ProgrammaticScrollAnimator) |
| 176 { | 178 { |
| 177 visitor->trace(m_scrollableArea); | 179 visitor->trace(m_scrollableArea); |
| 178 ScrollAnimatorCompositorCoordinator::trace(visitor); | 180 ScrollAnimatorCompositorCoordinator::trace(visitor); |
| 179 } | 181 } |
| 180 | 182 |
| 181 } // namespace blink | 183 } // namespace blink |
| OLD | NEW |