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 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 179 m_runState = RunState::RunningOnCompositorButNeedsUpdate; | 179 m_runState = RunState::RunningOnCompositorButNeedsUpdate; |
| 180 return true; | 180 return true; |
| 181 } | 181 } |
| 182 | 182 |
| 183 if ((targetPos - currentPosition()).isZero()) | 183 if ((targetPos - currentPosition()).isZero()) |
| 184 return false; | 184 return false; |
| 185 | 185 |
| 186 m_targetOffset = targetPos; | 186 m_targetOffset = targetPos; |
| 187 m_startTime = m_timeFunction(); | 187 m_startTime = m_timeFunction(); |
| 188 | 188 |
| 189 if (registerAndScheduleAnimation()) | 189 if (registerAndScheduleAnimation()) { |
| 190 m_runState = RunState::WaitingToSendToCompositor; | 190 if (m_scrollableArea->shouldScrollOnMainThread()) { |
| 191 createAnimationCurve(); | |
| 192 m_runState = RunState::RunningOnMainThread; | |
| 193 } else { | |
| 194 m_runState = RunState::WaitingToSendToCompositor; | |
| 195 } | |
| 196 } | |
| 191 | 197 |
| 192 return true; | 198 return true; |
| 193 } | 199 } |
| 194 | 200 |
| 195 void ScrollAnimator::adjustAnimationAndSetScrollPosition( | 201 void ScrollAnimator::adjustAnimationAndSetScrollPosition( |
| 196 IntSize adjustment, ScrollType scrollType) | 202 IntSize adjustment, ScrollType scrollType) |
| 197 { | 203 { |
| 198 DoublePoint adjustedPos = m_scrollableArea->clampScrollPosition( | 204 DoublePoint adjustedPos = m_scrollableArea->clampScrollPosition( |
| 199 m_scrollableArea->scrollPositionDouble() + adjustment); | 205 m_scrollableArea->scrollPositionDouble() + adjustment); |
| 200 IntSize actualAdjustment = roundedIntPoint(adjustedPos) - | 206 IntSize actualAdjustment = roundedIntPoint(adjustedPos) - |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 280 bool sentToCompositor = addAnimation(std::move(animation)); | 286 bool sentToCompositor = addAnimation(std::move(animation)); |
| 281 if (sentToCompositor) { | 287 if (sentToCompositor) { |
| 282 m_runState = RunState::RunningOnCompositor; | 288 m_runState = RunState::RunningOnCompositor; |
| 283 m_compositorAnimationId = animationId; | 289 m_compositorAnimationId = animationId; |
| 284 m_compositorAnimationGroupId = animationGroupId; | 290 m_compositorAnimationGroupId = animationGroupId; |
| 285 } | 291 } |
| 286 | 292 |
| 287 return sentToCompositor; | 293 return sentToCompositor; |
| 288 } | 294 } |
| 289 | 295 |
| 296 void ScrollAnimator::createAnimationCurve() | |
| 297 { | |
| 298 DCHECK(!m_animationCurve); | |
| 299 m_animationCurve = adoptPtr(CompositorFactory::current().createScrollOffsetA nimationCurve( | |
| 300 compositorOffsetFromBlinkOffset(m_targetOffset), | |
| 301 m_lastGranularity == ScrollByPixel ? | |
| 302 CompositorScrollOffsetAnimationCurve::ScrollDurationInverseDelta : | |
| 303 CompositorScrollOffsetAnimationCurve::ScrollDurationConstant)); | |
| 304 m_animationCurve->setInitialValue(compositorOffsetFromBlinkOffset(currentPos ition())); | |
| 305 } | |
| 306 | |
| 290 void ScrollAnimator::updateCompositorAnimations() | 307 void ScrollAnimator::updateCompositorAnimations() |
| 291 { | 308 { |
| 292 ScrollAnimatorCompositorCoordinator::updateCompositorAnimations(); | 309 ScrollAnimatorCompositorCoordinator::updateCompositorAnimations(); |
| 310 if (m_runState == RunState::RunningOnMainThread) { | |
| 311 // We add a temporary main thread scrolling reason so that subsequent | |
| 312 // scrolls get handled on the main thread. This is removed when the | |
| 313 // animation is finished in ::tickAnimation. | |
| 314 addMainThreadScrollingReason(); | |
| 315 return; | |
| 316 } | |
| 317 | |
| 293 if (m_runState == RunState::PostAnimationCleanup) { | 318 if (m_runState == RunState::PostAnimationCleanup) { |
| 294 postAnimationCleanupAndReset(); | 319 postAnimationCleanupAndReset(); |
| 295 return; | 320 return; |
| 296 } | 321 } |
| 297 | 322 |
| 298 if (m_runState == RunState::WaitingToCancelOnCompositor) { | 323 if (m_runState == RunState::WaitingToCancelOnCompositor) { |
| 299 DCHECK(m_compositorAnimationId); | 324 DCHECK(m_compositorAnimationId); |
| 300 abortAnimation(); | 325 abortAnimation(); |
| 301 postAnimationCleanupAndReset(); | 326 postAnimationCleanupAndReset(); |
| 302 return; | 327 return; |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 331 if (m_runState == RunState::WaitingToCancelOnCompositorButNewScroll) | 356 if (m_runState == RunState::WaitingToCancelOnCompositorButNewScroll) |
| 332 m_animationCurve->setInitialValue(compositorOffsetFromBlinkOffset(cu rrentPosition())); | 357 m_animationCurve->setInitialValue(compositorOffsetFromBlinkOffset(cu rrentPosition())); |
| 333 | 358 |
| 334 m_runState = RunState::WaitingToSendToCompositor; | 359 m_runState = RunState::WaitingToSendToCompositor; |
| 335 } | 360 } |
| 336 | 361 |
| 337 if (m_runState == RunState::WaitingToSendToCompositor) { | 362 if (m_runState == RunState::WaitingToSendToCompositor) { |
| 338 if (!m_compositorAnimationAttachedToLayerId) | 363 if (!m_compositorAnimationAttachedToLayerId) |
| 339 reattachCompositorPlayerIfNeeded(getScrollableArea()->compositorAnim ationTimeline()); | 364 reattachCompositorPlayerIfNeeded(getScrollableArea()->compositorAnim ationTimeline()); |
| 340 | 365 |
| 341 if (!m_animationCurve) { | 366 if (!m_animationCurve) |
| 342 m_animationCurve = adoptPtr(CompositorFactory::current().createScrol lOffsetAnimationCurve( | 367 createAnimationCurve(); |
| 343 compositorOffsetFromBlinkOffset(m_targetOffset), | |
| 344 m_lastGranularity == ScrollByPixel ? | |
| 345 CompositorScrollOffsetAnimationCurve::ScrollDurationInverseD elta : | |
| 346 CompositorScrollOffsetAnimationCurve::ScrollDurationConstant )); | |
| 347 m_animationCurve->setInitialValue(compositorOffsetFromBlinkOffset(cu rrentPosition())); | |
| 348 } | |
| 349 | 368 |
| 350 bool runningOnMainThread = false; | 369 bool runningOnMainThread = false; |
| 351 bool sentToCompositor = sendAnimationToCompositor(); | 370 bool sentToCompositor = sendAnimationToCompositor(); |
| 352 if (!sentToCompositor) { | 371 if (!sentToCompositor) { |
| 353 runningOnMainThread = registerAndScheduleAnimation(); | 372 runningOnMainThread = registerAndScheduleAnimation(); |
| 354 if (runningOnMainThread) | 373 if (runningOnMainThread) |
| 355 m_runState = RunState::RunningOnMainThread; | 374 m_runState = RunState::RunningOnMainThread; |
| 356 } | 375 } |
| 357 | 376 |
| 358 // Main thread should deal with the scroll animations it started. | 377 // Main thread should deal with the scroll animations it started. |
| 359 if (sentToCompositor || runningOnMainThread) | 378 if (sentToCompositor || runningOnMainThread) |
| 360 addMainThreadScrollingReason(); | 379 addMainThreadScrollingReason(); |
| 361 else | 380 else |
| 362 removeMainThreadScrollingReason(); | 381 removeMainThreadScrollingReason(); |
| 363 } | 382 } |
| 364 } | 383 } |
| 365 | 384 |
| 366 void ScrollAnimator::addMainThreadScrollingReason() | 385 void ScrollAnimator::addMainThreadScrollingReason() |
| 367 { | 386 { |
| 368 if (WebLayer* scrollLayer = toWebLayer(getScrollableArea()->layerForScrollin g())) { | 387 if (WebLayer* scrollLayer = toWebLayer(getScrollableArea()->layerForScrollin g())) { |
| 388 uint32_t reasons = scrollLayer->mainThreadScrollingReasons(); | |
| 389 if (reasons & MainThreadScrollingReason::kAnimatingScrollOnMainThread) | |
| 390 return; | |
|
ajuma
2016/06/02 14:07:27
cc::Layer::AddMainThreadScrollingReasons already e
ymalik
2016/06/02 14:13:10
We essentially call this function every time we're
ajuma
2016/06/02 14:20:27
The call to mainThreadScrollingReasons() winds up
ymalik
2016/06/02 14:30:08
Removed.
| |
| 369 scrollLayer->addMainThreadScrollingReasons( | 391 scrollLayer->addMainThreadScrollingReasons( |
| 370 MainThreadScrollingReason::kAnimatingScrollOnMainThread); | 392 MainThreadScrollingReason::kAnimatingScrollOnMainThread); |
| 371 } | 393 } |
| 372 } | 394 } |
| 373 | 395 |
| 374 void ScrollAnimator::removeMainThreadScrollingReason() | 396 void ScrollAnimator::removeMainThreadScrollingReason() |
| 375 { | 397 { |
| 376 if (WebLayer* scrollLayer = toWebLayer(getScrollableArea()->layerForScrollin g())) { | 398 if (WebLayer* scrollLayer = toWebLayer(getScrollableArea()->layerForScrollin g())) { |
| 377 scrollLayer->clearMainThreadScrollingReasons( | 399 scrollLayer->clearMainThreadScrollingReasons( |
| 378 MainThreadScrollingReason::kAnimatingScrollOnMainThread); | 400 MainThreadScrollingReason::kAnimatingScrollOnMainThread); |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 444 } | 466 } |
| 445 return true; | 467 return true; |
| 446 } | 468 } |
| 447 | 469 |
| 448 DEFINE_TRACE(ScrollAnimator) | 470 DEFINE_TRACE(ScrollAnimator) |
| 449 { | 471 { |
| 450 ScrollAnimatorBase::trace(visitor); | 472 ScrollAnimatorBase::trace(visitor); |
| 451 } | 473 } |
| 452 | 474 |
| 453 } // namespace blink | 475 } // namespace blink |
| OLD | NEW |