| 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 23 matching lines...) Expand all Loading... |
| 34 #include "platform/TraceEvent.h" | 34 #include "platform/TraceEvent.h" |
| 35 #include "platform/animation/CompositorAnimation.h" | 35 #include "platform/animation/CompositorAnimation.h" |
| 36 #include "platform/graphics/CompositorFactory.h" | 36 #include "platform/graphics/CompositorFactory.h" |
| 37 #include "platform/graphics/GraphicsLayer.h" | 37 #include "platform/graphics/GraphicsLayer.h" |
| 38 #include "platform/scroll/MainThreadScrollingReason.h" | 38 #include "platform/scroll/MainThreadScrollingReason.h" |
| 39 #include "platform/scroll/ScrollableArea.h" | 39 #include "platform/scroll/ScrollableArea.h" |
| 40 #include "public/platform/Platform.h" | 40 #include "public/platform/Platform.h" |
| 41 #include "public/platform/WebCompositorSupport.h" | 41 #include "public/platform/WebCompositorSupport.h" |
| 42 #include "wtf/CurrentTime.h" | 42 #include "wtf/CurrentTime.h" |
| 43 #include "wtf/PassRefPtr.h" | 43 #include "wtf/PassRefPtr.h" |
| 44 #include "wtf/PtrUtil.h" |
| 45 #include <memory> |
| 44 | 46 |
| 45 namespace blink { | 47 namespace blink { |
| 46 | 48 |
| 47 namespace { | 49 namespace { |
| 48 | 50 |
| 49 WebLayer* toWebLayer(GraphicsLayer* layer) | 51 WebLayer* toWebLayer(GraphicsLayer* layer) |
| 50 { | 52 { |
| 51 return layer ? layer->platformLayer() : nullptr; | 53 return layer ? layer->platformLayer() : nullptr; |
| 52 } | 54 } |
| 53 | 55 |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 261 removeMainThreadScrollingReason(); | 263 removeMainThreadScrollingReason(); |
| 262 | 264 |
| 263 resetAnimationState(); | 265 resetAnimationState(); |
| 264 } | 266 } |
| 265 | 267 |
| 266 bool ScrollAnimator::sendAnimationToCompositor() | 268 bool ScrollAnimator::sendAnimationToCompositor() |
| 267 { | 269 { |
| 268 if (m_scrollableArea->shouldScrollOnMainThread()) | 270 if (m_scrollableArea->shouldScrollOnMainThread()) |
| 269 return false; | 271 return false; |
| 270 | 272 |
| 271 OwnPtr<CompositorAnimation> animation = adoptPtr( | 273 std::unique_ptr<CompositorAnimation> animation = wrapUnique( |
| 272 CompositorFactory::current().createAnimation( | 274 CompositorFactory::current().createAnimation( |
| 273 *m_animationCurve, | 275 *m_animationCurve, |
| 274 CompositorTargetProperty::SCROLL_OFFSET)); | 276 CompositorTargetProperty::SCROLL_OFFSET)); |
| 275 // Being here means that either there is an animation that needs | 277 // Being here means that either there is an animation that needs |
| 276 // to be sent to the compositor, or an animation that needs to | 278 // to be sent to the compositor, or an animation that needs to |
| 277 // be updated (a new scroll event before the previous animation | 279 // be updated (a new scroll event before the previous animation |
| 278 // is finished). In either case, the start time is when the | 280 // is finished). In either case, the start time is when the |
| 279 // first animation was initiated. This re-targets the animation | 281 // first animation was initiated. This re-targets the animation |
| 280 // using the current time on main thread. | 282 // using the current time on main thread. |
| 281 animation->setStartTime(m_startTime); | 283 animation->setStartTime(m_startTime); |
| 282 | 284 |
| 283 int animationId = animation->id(); | 285 int animationId = animation->id(); |
| 284 int animationGroupId = animation->group(); | 286 int animationGroupId = animation->group(); |
| 285 | 287 |
| 286 bool sentToCompositor = addAnimation(std::move(animation)); | 288 bool sentToCompositor = addAnimation(std::move(animation)); |
| 287 if (sentToCompositor) { | 289 if (sentToCompositor) { |
| 288 m_runState = RunState::RunningOnCompositor; | 290 m_runState = RunState::RunningOnCompositor; |
| 289 m_compositorAnimationId = animationId; | 291 m_compositorAnimationId = animationId; |
| 290 m_compositorAnimationGroupId = animationGroupId; | 292 m_compositorAnimationGroupId = animationGroupId; |
| 291 } | 293 } |
| 292 | 294 |
| 293 return sentToCompositor; | 295 return sentToCompositor; |
| 294 } | 296 } |
| 295 | 297 |
| 296 void ScrollAnimator::createAnimationCurve() | 298 void ScrollAnimator::createAnimationCurve() |
| 297 { | 299 { |
| 298 DCHECK(!m_animationCurve); | 300 DCHECK(!m_animationCurve); |
| 299 m_animationCurve = adoptPtr(CompositorFactory::current().createScrollOffsetA
nimationCurve( | 301 m_animationCurve = wrapUnique(CompositorFactory::current().createScrollOffse
tAnimationCurve( |
| 300 compositorOffsetFromBlinkOffset(m_targetOffset), | 302 compositorOffsetFromBlinkOffset(m_targetOffset), |
| 301 m_lastGranularity == ScrollByPixel ? | 303 m_lastGranularity == ScrollByPixel ? |
| 302 CompositorScrollOffsetAnimationCurve::ScrollDurationInverseDelta : | 304 CompositorScrollOffsetAnimationCurve::ScrollDurationInverseDelta : |
| 303 CompositorScrollOffsetAnimationCurve::ScrollDurationConstant)); | 305 CompositorScrollOffsetAnimationCurve::ScrollDurationConstant)); |
| 304 m_animationCurve->setInitialValue(compositorOffsetFromBlinkOffset(currentPos
ition())); | 306 m_animationCurve->setInitialValue(compositorOffsetFromBlinkOffset(currentPos
ition())); |
| 305 } | 307 } |
| 306 | 308 |
| 307 void ScrollAnimator::updateCompositorAnimations() | 309 void ScrollAnimator::updateCompositorAnimations() |
| 308 { | 310 { |
| 309 ScrollAnimatorCompositorCoordinator::updateCompositorAnimations(); | 311 ScrollAnimatorCompositorCoordinator::updateCompositorAnimations(); |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 418 // If there is already an animation running and the compositor asks to take | 420 // If there is already an animation running and the compositor asks to take |
| 419 // over an animation, do nothing to avoid judder. | 421 // over an animation, do nothing to avoid judder. |
| 420 if (hasRunningAnimation()) | 422 if (hasRunningAnimation()) |
| 421 return; | 423 return; |
| 422 | 424 |
| 423 cc::ScrollOffsetAnimationCurve* scrollOffsetAnimationCurve = | 425 cc::ScrollOffsetAnimationCurve* scrollOffsetAnimationCurve = |
| 424 curve->ToScrollOffsetAnimationCurve(); | 426 curve->ToScrollOffsetAnimationCurve(); |
| 425 FloatPoint targetValue(scrollOffsetAnimationCurve->target_value().x(), | 427 FloatPoint targetValue(scrollOffsetAnimationCurve->target_value().x(), |
| 426 scrollOffsetAnimationCurve->target_value().y()); | 428 scrollOffsetAnimationCurve->target_value().y()); |
| 427 if (willAnimateToOffset(targetValue)) { | 429 if (willAnimateToOffset(targetValue)) { |
| 428 m_animationCurve = adoptPtr( | 430 m_animationCurve = wrapUnique( |
| 429 CompositorFactory::current().createScrollOffsetAnimationCurve( | 431 CompositorFactory::current().createScrollOffsetAnimationCurve( |
| 430 std::move(scrollOffsetAnimationCurve))); | 432 std::move(scrollOffsetAnimationCurve))); |
| 431 m_startTime = animationStartTime; | 433 m_startTime = animationStartTime; |
| 432 } | 434 } |
| 433 } | 435 } |
| 434 | 436 |
| 435 void ScrollAnimator::cancelAnimation() | 437 void ScrollAnimator::cancelAnimation() |
| 436 { | 438 { |
| 437 ScrollAnimatorCompositorCoordinator::cancelAnimation(); | 439 ScrollAnimatorCompositorCoordinator::cancelAnimation(); |
| 438 } | 440 } |
| (...skipping 24 matching lines...) Expand all Loading... |
| 463 } | 465 } |
| 464 return true; | 466 return true; |
| 465 } | 467 } |
| 466 | 468 |
| 467 DEFINE_TRACE(ScrollAnimator) | 469 DEFINE_TRACE(ScrollAnimator) |
| 468 { | 470 { |
| 469 ScrollAnimatorBase::trace(visitor); | 471 ScrollAnimatorBase::trace(visitor); |
| 470 } | 472 } |
| 471 | 473 |
| 472 } // namespace blink | 474 } // namespace blink |
| OLD | NEW |