Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (c) 2011, Google Inc. All rights reserved. | 2 * Copyright (c) 2011, 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 12 matching lines...) Expand all Loading... | |
| 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 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 "platform/scroll/ScrollAnimator.h" | 31 #include "platform/scroll/ScrollAnimator.h" |
| 32 | 32 |
| 33 #include "cc/animation/scroll_offset_animation_curve.h" | |
| 33 #include "platform/TraceEvent.h" | 34 #include "platform/TraceEvent.h" |
| 34 #include "platform/animation/CompositorAnimation.h" | 35 #include "platform/animation/CompositorAnimation.h" |
| 35 #include "platform/graphics/CompositorFactory.h" | 36 #include "platform/graphics/CompositorFactory.h" |
| 36 #include "platform/graphics/GraphicsLayer.h" | 37 #include "platform/graphics/GraphicsLayer.h" |
| 37 #include "platform/scroll/MainThreadScrollingReason.h" | 38 #include "platform/scroll/MainThreadScrollingReason.h" |
| 38 #include "platform/scroll/ScrollableArea.h" | 39 #include "platform/scroll/ScrollableArea.h" |
| 39 #include "public/platform/Platform.h" | 40 #include "public/platform/Platform.h" |
| 40 #include "public/platform/WebCompositorSupport.h" | 41 #include "public/platform/WebCompositorSupport.h" |
| 41 #include "wtf/CurrentTime.h" | 42 #include "wtf/CurrentTime.h" |
| 42 #include "wtf/PassRefPtr.h" | 43 #include "wtf/PassRefPtr.h" |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 113 return ScrollAnimatorBase::userScroll(orientation, granularity, step, de lta); | 114 return ScrollAnimatorBase::userScroll(orientation, granularity, step, de lta); |
| 114 } | 115 } |
| 115 | 116 |
| 116 float usedPixelDelta = computeDeltaToConsume(orientation, step * delta); | 117 float usedPixelDelta = computeDeltaToConsume(orientation, step * delta); |
| 117 FloatPoint pixelDelta = (orientation == VerticalScrollbar | 118 FloatPoint pixelDelta = (orientation == VerticalScrollbar |
| 118 ? FloatPoint(0, usedPixelDelta) : FloatPoint(usedPixelDelta, 0)); | 119 ? FloatPoint(0, usedPixelDelta) : FloatPoint(usedPixelDelta, 0)); |
| 119 | 120 |
| 120 FloatPoint targetPos = desiredTargetPosition(); | 121 FloatPoint targetPos = desiredTargetPosition(); |
| 121 targetPos.moveBy(pixelDelta); | 122 targetPos.moveBy(pixelDelta); |
| 122 | 123 |
| 124 if (willAnimateToOffset(targetPos)) { | |
| 125 m_lastGranularity = granularity; | |
| 126 // Report unused delta only if there is no animation running. See | |
| 127 // comment below regarding scroll latching. | |
| 128 return ScrollResultOneDimensional(/* didScroll */ true, /* unusedScrollD elta */ 0); | |
| 129 } | |
| 130 // Report unused delta only if there is no animation and we are not | |
| 131 // starting one. This ensures we latch for the duration of the | |
| 132 // animation rather than animating multiple scrollers at the same time. | |
| 133 return ScrollResultOneDimensional(/* didScroll */ false, delta); | |
| 134 } | |
| 135 | |
| 136 bool ScrollAnimator::willAnimateToOffset(const FloatPoint& targetPos) | |
| 137 { | |
| 123 if (m_runState == RunState::PostAnimationCleanup) | 138 if (m_runState == RunState::PostAnimationCleanup) |
| 124 resetAnimationState(); | 139 resetAnimationState(); |
| 125 | 140 |
| 126 if (m_animationCurve && m_runState != RunState::WaitingToCancelOnCompositor) { | 141 if (m_animationCurve && m_runState != RunState::WaitingToCancelOnCompositor) { |
| 127 if ((targetPos - m_targetOffset).isZero()) { | 142 if ((targetPos - m_targetOffset).isZero()) |
| 128 // Report unused delta only if there is no animation running. See | 143 return true; |
|
ajuma
2016/02/26 23:56:54
Should this return false? (We're already at the ta
ymalik
2016/02/29 16:31:09
Ideally yes, but this was originally there for scr
| |
| 129 // comment below regarding scroll latching. | |
| 130 return ScrollResultOneDimensional(/* didScroll */ true, /* unusedScr ollDelta */ 0); | |
| 131 } | |
| 132 | 144 |
| 133 m_targetOffset = targetPos; | 145 m_targetOffset = targetPos; |
| 134 ASSERT(m_runState == RunState::RunningOnMainThread | 146 ASSERT(m_runState == RunState::RunningOnMainThread |
| 135 || m_runState == RunState::RunningOnCompositor | 147 || m_runState == RunState::RunningOnCompositor |
| 136 || m_runState == RunState::RunningOnCompositorButNeedsUpdate); | 148 || m_runState == RunState::RunningOnCompositorButNeedsUpdate); |
| 137 | 149 |
| 138 if (m_runState == RunState::RunningOnCompositor | 150 if (m_runState == RunState::RunningOnCompositor |
| 139 || m_runState == RunState::RunningOnCompositorButNeedsUpdate) { | 151 || m_runState == RunState::RunningOnCompositorButNeedsUpdate) { |
| 140 if (registerAndScheduleAnimation()) | 152 if (registerAndScheduleAnimation()) |
| 141 m_runState = RunState::RunningOnCompositorButNeedsUpdate; | 153 m_runState = RunState::RunningOnCompositorButNeedsUpdate; |
| 142 return ScrollResultOneDimensional(/* didScroll */ true, /* unusedScr ollDelta */ 0); | 154 return true; |
| 143 } | 155 } |
| 144 | 156 |
| 145 // Running on the main thread, simply update the target offset instead | 157 // Running on the main thread, simply update the target offset instead |
| 146 // of sending to the compositor. | 158 // of sending to the compositor. |
| 147 m_animationCurve->updateTarget(m_timeFunction() - m_startTime, targetPos ); | 159 m_animationCurve->updateTarget(m_timeFunction() - m_startTime, targetPos ); |
| 148 return ScrollResultOneDimensional(/* didScroll */ true, /* unusedScrollD elta */ 0); | 160 return true; |
| 149 } | 161 } |
| 150 | 162 |
| 151 if ((targetPos - currentPosition()).isZero()) { | 163 if ((targetPos - currentPosition()).isZero()) |
| 152 // Report unused delta only if there is no animation and we are not | 164 return false; |
| 153 // starting one. This ensures we latch for the duration of the | |
| 154 // animation rather than animating multiple scrollers at the same time. | |
| 155 return ScrollResultOneDimensional(/* didScroll */ false, delta); | |
| 156 } | |
| 157 | 165 |
| 158 m_targetOffset = targetPos; | 166 m_targetOffset = targetPos; |
| 159 m_startTime = m_timeFunction(); | 167 m_startTime = m_timeFunction(); |
| 160 m_lastGranularity = granularity; | |
| 161 | 168 |
| 162 if (registerAndScheduleAnimation()) | 169 if (registerAndScheduleAnimation()) |
| 163 m_runState = RunState::WaitingToSendToCompositor; | 170 m_runState = RunState::WaitingToSendToCompositor; |
| 164 | 171 |
| 165 return ScrollResultOneDimensional(/* didScroll */ true, /* unusedScrollDelta */ 0); | 172 return true; |
| 166 } | 173 } |
| 167 | 174 |
| 168 void ScrollAnimator::scrollToOffsetWithoutAnimation(const FloatPoint& offset) | 175 void ScrollAnimator::scrollToOffsetWithoutAnimation(const FloatPoint& offset) |
| 169 { | 176 { |
| 170 m_currentPosX = offset.x(); | 177 m_currentPosX = offset.x(); |
| 171 m_currentPosY = offset.y(); | 178 m_currentPosY = offset.y(); |
| 172 | 179 |
| 173 resetAnimationState(); | 180 resetAnimationState(); |
| 174 notifyPositionChanged(); | 181 notifyPositionChanged(); |
| 175 } | 182 } |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 321 // An animation aborted by the compositor is treated as a finished | 328 // An animation aborted by the compositor is treated as a finished |
| 322 // animation. | 329 // animation. |
| 323 ScrollAnimatorCompositorCoordinator::compositorAnimationFinished(groupId); | 330 ScrollAnimatorCompositorCoordinator::compositorAnimationFinished(groupId); |
| 324 } | 331 } |
| 325 | 332 |
| 326 void ScrollAnimator::notifyCompositorAnimationFinished(int groupId) | 333 void ScrollAnimator::notifyCompositorAnimationFinished(int groupId) |
| 327 { | 334 { |
| 328 ScrollAnimatorCompositorCoordinator::compositorAnimationFinished(groupId); | 335 ScrollAnimatorCompositorCoordinator::compositorAnimationFinished(groupId); |
| 329 } | 336 } |
| 330 | 337 |
| 338 void ScrollAnimator::notifyAnimationTakeover( | |
| 339 double monotonicTime, | |
| 340 double animationStartTime, | |
| 341 scoped_ptr<cc::AnimationCurve> curve) | |
| 342 { | |
| 343 // If there is already an animation running and the compositor asks to take | |
| 344 // over an animation, do nothing to avoid jidder. | |
|
ajuma
2016/02/26 23:56:54
"judder"? or maybe "jitter"?
ymalik
2016/02/29 16:31:09
Done.
| |
| 345 if (hasRunningAnimation()) | |
| 346 return; | |
| 347 | |
| 348 cc::ScrollOffsetAnimationCurve* scrollOffsetAnimationCurve = | |
| 349 curve->ToScrollOffsetAnimationCurve(); | |
| 350 FloatPoint targetValue(scrollOffsetAnimationCurve->target_value().x(), | |
| 351 scrollOffsetAnimationCurve->target_value().y()); | |
| 352 if (willAnimateToOffset(targetValue)) { | |
| 353 m_animationCurve = adoptPtr( | |
| 354 CompositorFactory::current().createScrollOffsetAnimationCurve( | |
| 355 std::move(scrollOffsetAnimationCurve))); | |
| 356 m_startTime = animationStartTime; | |
| 357 } | |
| 358 } | |
| 359 | |
| 331 void ScrollAnimator::cancelAnimation() | 360 void ScrollAnimator::cancelAnimation() |
| 332 { | 361 { |
| 333 ScrollAnimatorCompositorCoordinator::cancelAnimation(); | 362 ScrollAnimatorCompositorCoordinator::cancelAnimation(); |
| 334 } | 363 } |
| 335 | 364 |
| 336 void ScrollAnimator::layerForCompositedScrollingDidChange( | 365 void ScrollAnimator::layerForCompositedScrollingDidChange( |
| 337 CompositorAnimationTimeline* timeline) | 366 CompositorAnimationTimeline* timeline) |
| 338 { | 367 { |
| 339 if (reattachCompositorPlayerIfNeeded(timeline) && m_animationCurve) | 368 if (reattachCompositorPlayerIfNeeded(timeline) && m_animationCurve) |
| 340 addMainThreadScrollingReason(); | 369 addMainThreadScrollingReason(); |
| 341 } | 370 } |
| 342 | 371 |
| 343 bool ScrollAnimator::registerAndScheduleAnimation() | 372 bool ScrollAnimator::registerAndScheduleAnimation() |
| 344 { | 373 { |
| 345 scrollableArea()->registerForAnimation(); | 374 scrollableArea()->registerForAnimation(); |
| 346 if (!m_scrollableArea->scheduleAnimation()) { | 375 if (!m_scrollableArea->scheduleAnimation()) { |
| 347 scrollToOffsetWithoutAnimation(m_targetOffset); | 376 scrollToOffsetWithoutAnimation(m_targetOffset); |
| 348 resetAnimationState(); | 377 resetAnimationState(); |
| 349 return false; | 378 return false; |
| 350 } | 379 } |
| 351 return true; | 380 return true; |
| 352 } | 381 } |
| 353 | 382 |
| 354 DEFINE_TRACE(ScrollAnimator) | 383 DEFINE_TRACE(ScrollAnimator) |
| 355 { | 384 { |
| 356 ScrollAnimatorBase::trace(visitor); | 385 ScrollAnimatorBase::trace(visitor); |
| 357 } | 386 } |
| 358 | 387 |
| 359 } // namespace blink | 388 } // namespace blink |
| OLD | NEW |