| 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 14 matching lines...) Expand all Loading... |
| 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 "platform/TraceEvent.h" | 33 #include "platform/TraceEvent.h" |
| 34 #include "platform/graphics/GraphicsLayer.h" | 34 #include "platform/graphics/GraphicsLayer.h" |
| 35 #include "platform/scroll/MainThreadScrollingReason.h" |
| 35 #include "platform/scroll/ScrollableArea.h" | 36 #include "platform/scroll/ScrollableArea.h" |
| 36 #include "public/platform/Platform.h" | 37 #include "public/platform/Platform.h" |
| 37 #include "public/platform/WebCompositorAnimation.h" | 38 #include "public/platform/WebCompositorAnimation.h" |
| 38 #include "public/platform/WebCompositorSupport.h" | 39 #include "public/platform/WebCompositorSupport.h" |
| 39 #include "wtf/CurrentTime.h" | 40 #include "wtf/CurrentTime.h" |
| 40 #include "wtf/PassRefPtr.h" | 41 #include "wtf/PassRefPtr.h" |
| 41 | 42 |
| 42 namespace blink { | 43 namespace blink { |
| 43 | 44 |
| 45 WebLayer* toWebLayer(blink::GraphicsLayer* layer) |
| 46 { |
| 47 return layer ? layer->platformLayer() : nullptr; |
| 48 } |
| 49 |
| 44 PassOwnPtrWillBeRawPtr<ScrollAnimatorBase> ScrollAnimatorBase::create(Scrollable
Area* scrollableArea) | 50 PassOwnPtrWillBeRawPtr<ScrollAnimatorBase> ScrollAnimatorBase::create(Scrollable
Area* scrollableArea) |
| 45 { | 51 { |
| 46 if (scrollableArea && scrollableArea->scrollAnimatorEnabled()) | 52 if (scrollableArea && scrollableArea->scrollAnimatorEnabled()) |
| 47 return adoptPtrWillBeNoop(new ScrollAnimator(scrollableArea)); | 53 return adoptPtrWillBeNoop(new ScrollAnimator(scrollableArea)); |
| 48 return adoptPtrWillBeNoop(new ScrollAnimatorBase(scrollableArea)); | 54 return adoptPtrWillBeNoop(new ScrollAnimatorBase(scrollableArea)); |
| 49 } | 55 } |
| 50 | 56 |
| 51 ScrollAnimator::ScrollAnimator(ScrollableArea* scrollableArea, WTF::TimeFunction
timeFunction) | 57 ScrollAnimator::ScrollAnimator(ScrollableArea* scrollableArea, WTF::TimeFunction
timeFunction) |
| 52 : ScrollAnimatorBase(scrollableArea) | 58 : ScrollAnimatorBase(scrollableArea) |
| 53 , m_timeFunction(timeFunction) | 59 , m_timeFunction(timeFunction) |
| (...skipping 24 matching lines...) Expand all Loading... |
| 78 float newPos = clampScrollPosition(orientation, currentPos + pixelDelta); | 84 float newPos = clampScrollPosition(orientation, currentPos + pixelDelta); |
| 79 return (currentPos == newPos) ? 0.0f : (newPos - currentPos); | 85 return (currentPos == newPos) ? 0.0f : (newPos - currentPos); |
| 80 } | 86 } |
| 81 | 87 |
| 82 void ScrollAnimator::resetAnimationState() | 88 void ScrollAnimator::resetAnimationState() |
| 83 { | 89 { |
| 84 ScrollAnimatorCompositorCoordinator::resetAnimationState(); | 90 ScrollAnimatorCompositorCoordinator::resetAnimationState(); |
| 85 if (m_animationCurve) | 91 if (m_animationCurve) |
| 86 m_animationCurve.clear(); | 92 m_animationCurve.clear(); |
| 87 m_startTime = 0.0; | 93 m_startTime = 0.0; |
| 94 |
| 95 // Remove the temporary main thread scrolling reason that was added while |
| 96 // main thread had scheduled an animation. |
| 97 removeMainThreadScrollingReason(); |
| 88 } | 98 } |
| 89 | 99 |
| 90 ScrollResultOneDimensional ScrollAnimator::userScroll( | 100 ScrollResultOneDimensional ScrollAnimator::userScroll( |
| 91 ScrollbarOrientation orientation, ScrollGranularity granularity, float step,
float delta) | 101 ScrollbarOrientation orientation, ScrollGranularity granularity, float step,
float delta) |
| 92 { | 102 { |
| 93 if (!m_scrollableArea->scrollAnimatorEnabled()) | 103 if (!m_scrollableArea->scrollAnimatorEnabled()) |
| 94 return ScrollAnimatorBase::userScroll(orientation, granularity, step, de
lta); | 104 return ScrollAnimatorBase::userScroll(orientation, granularity, step, de
lta); |
| 95 | 105 |
| 96 TRACE_EVENT0("blink", "ScrollAnimator::scroll"); | 106 TRACE_EVENT0("blink", "ScrollAnimator::scroll"); |
| 97 | 107 |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 252 int animationGroupId = animation->group(); | 262 int animationGroupId = animation->group(); |
| 253 | 263 |
| 254 sentToCompositor = addAnimation(animation.release()); | 264 sentToCompositor = addAnimation(animation.release()); |
| 255 if (sentToCompositor) { | 265 if (sentToCompositor) { |
| 256 m_runState = RunState::RunningOnCompositor; | 266 m_runState = RunState::RunningOnCompositor; |
| 257 m_compositorAnimationId = animationId; | 267 m_compositorAnimationId = animationId; |
| 258 m_compositorAnimationGroupId = animationGroupId; | 268 m_compositorAnimationGroupId = animationGroupId; |
| 259 } | 269 } |
| 260 } | 270 } |
| 261 | 271 |
| 272 bool runningOnMainThread = false; |
| 262 if (!sentToCompositor) { | 273 if (!sentToCompositor) { |
| 263 if (registerAndScheduleAnimation()) | 274 runningOnMainThread = registerAndScheduleAnimation(); |
| 275 if (runningOnMainThread) |
| 264 m_runState = RunState::RunningOnMainThread; | 276 m_runState = RunState::RunningOnMainThread; |
| 265 } | 277 } |
| 278 |
| 279 // Main thread should deal with the scroll animations it started. |
| 280 if (sentToCompositor || runningOnMainThread) |
| 281 addMainThreadScrollingReason(); |
| 266 } | 282 } |
| 267 } | 283 } |
| 268 | 284 |
| 285 void ScrollAnimator::addMainThreadScrollingReason() |
| 286 { |
| 287 if (WebLayer* scrollLayer = toWebLayer(scrollableArea()->layerForScrolling()
)) { |
| 288 scrollLayer->addMainThreadScrollingReasons( |
| 289 MainThreadScrollingReason::kAnimatingScollOnMainThread); |
| 290 } |
| 291 } |
| 292 |
| 293 void ScrollAnimator::removeMainThreadScrollingReason() |
| 294 { |
| 295 if (WebLayer* scrollLayer = toWebLayer(scrollableArea()->layerForScrolling()
)) { |
| 296 scrollLayer->clearMainThreadScrollingReasons( |
| 297 MainThreadScrollingReason::kAnimatingScollOnMainThread); |
| 298 } |
| 299 } |
| 300 |
| 269 void ScrollAnimator::notifyCompositorAnimationAborted(int groupId) | 301 void ScrollAnimator::notifyCompositorAnimationAborted(int groupId) |
| 270 { | 302 { |
| 271 // An animation aborted by the compositor is treated as a finished | 303 // An animation aborted by the compositor is treated as a finished |
| 272 // animation. | 304 // animation. |
| 273 ScrollAnimatorCompositorCoordinator::compositorAnimationFinished(groupId); | 305 ScrollAnimatorCompositorCoordinator::compositorAnimationFinished(groupId); |
| 274 } | 306 } |
| 275 | 307 |
| 276 void ScrollAnimator::notifyCompositorAnimationFinished(int groupId) | 308 void ScrollAnimator::notifyCompositorAnimationFinished(int groupId) |
| 277 { | 309 { |
| 278 ScrollAnimatorCompositorCoordinator::compositorAnimationFinished(groupId); | 310 ScrollAnimatorCompositorCoordinator::compositorAnimationFinished(groupId); |
| 279 } | 311 } |
| 280 | 312 |
| 281 void ScrollAnimator::cancelAnimation() | 313 void ScrollAnimator::cancelAnimation() |
| 282 { | 314 { |
| 283 ScrollAnimatorCompositorCoordinator::cancelAnimation(); | 315 ScrollAnimatorCompositorCoordinator::cancelAnimation(); |
| 284 } | 316 } |
| 285 | 317 |
| 286 void ScrollAnimator::layerForCompositedScrollingDidChange( | 318 void ScrollAnimator::layerForCompositedScrollingDidChange( |
| 287 WebCompositorAnimationTimeline* timeline) | 319 WebCompositorAnimationTimeline* timeline) |
| 288 { | 320 { |
| 321 if (hasRunningAnimation()) |
| 322 addMainThreadScrollingReason(); |
| 289 reattachCompositorPlayerIfNeeded(timeline); | 323 reattachCompositorPlayerIfNeeded(timeline); |
| 290 } | 324 } |
| 291 | 325 |
| 292 bool ScrollAnimator::registerAndScheduleAnimation() | 326 bool ScrollAnimator::registerAndScheduleAnimation() |
| 293 { | 327 { |
| 294 scrollableArea()->registerForAnimation(); | 328 scrollableArea()->registerForAnimation(); |
| 295 if (!m_scrollableArea->scheduleAnimation()) { | 329 if (!m_scrollableArea->scheduleAnimation()) { |
| 296 scrollToOffsetWithoutAnimation(m_targetOffset); | 330 scrollToOffsetWithoutAnimation(m_targetOffset); |
| 297 resetAnimationState(); | 331 resetAnimationState(); |
| 298 return false; | 332 return false; |
| 299 } | 333 } |
| 300 return true; | 334 return true; |
| 301 } | 335 } |
| 302 | 336 |
| 303 DEFINE_TRACE(ScrollAnimator) | 337 DEFINE_TRACE(ScrollAnimator) |
| 304 { | 338 { |
| 305 ScrollAnimatorBase::trace(visitor); | 339 ScrollAnimatorBase::trace(visitor); |
| 306 } | 340 } |
| 307 | 341 |
| 308 } // namespace blink | 342 } // namespace blink |
| OLD | NEW |