| 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/ScrollAnimatorCompositorCoordinator.h" | 5 #include "platform/scroll/ScrollAnimatorCompositorCoordinator.h" |
| 6 | 6 |
| 7 #include "platform/RuntimeEnabledFeatures.h" | 7 #include "platform/RuntimeEnabledFeatures.h" |
| 8 #include "platform/graphics/GraphicsLayer.h" | 8 #include "platform/graphics/GraphicsLayer.h" |
| 9 #include "platform/scroll/MainThreadScrollingReason.h" |
| 9 #include "platform/scroll/ScrollableArea.h" | 10 #include "platform/scroll/ScrollableArea.h" |
| 10 #include "public/platform/Platform.h" | 11 #include "public/platform/Platform.h" |
| 11 #include "public/platform/WebCompositorAnimationPlayer.h" | 12 #include "public/platform/WebCompositorAnimationPlayer.h" |
| 12 #include "public/platform/WebCompositorAnimationTimeline.h" | 13 #include "public/platform/WebCompositorAnimationTimeline.h" |
| 13 #include "public/platform/WebCompositorSupport.h" | 14 #include "public/platform/WebCompositorSupport.h" |
| 14 | 15 |
| 15 namespace blink { | 16 namespace blink { |
| 16 | 17 |
| 18 WebLayer* toWebLayer(blink::GraphicsLayer* layer) |
| 19 { |
| 20 return layer ? layer->platformLayer() : nullptr; |
| 21 } |
| 22 |
| 17 ScrollAnimatorCompositorCoordinator::ScrollAnimatorCompositorCoordinator() | 23 ScrollAnimatorCompositorCoordinator::ScrollAnimatorCompositorCoordinator() |
| 18 : m_compositorAnimationAttachedToLayerId(0) | 24 : m_compositorAnimationAttachedToLayerId(0) |
| 19 , m_runState(RunState::Idle) | 25 , m_runState(RunState::Idle) |
| 20 , m_compositorAnimationId(0) | 26 , m_compositorAnimationId(0) |
| 21 , m_compositorAnimationGroupId(0) | 27 , m_compositorAnimationGroupId(0) |
| 28 , m_clearMainThreadScrollingReasons(false) |
| 22 { | 29 { |
| 23 if (RuntimeEnabledFeatures::compositorAnimationTimelinesEnabled()) { | 30 if (RuntimeEnabledFeatures::compositorAnimationTimelinesEnabled()) { |
| 24 ASSERT(Platform::current()->compositorSupport()); | 31 ASSERT(Platform::current()->compositorSupport()); |
| 25 m_compositorPlayer = adoptPtr(Platform::current()->compositorSupport()->
createAnimationPlayer()); | 32 m_compositorPlayer = adoptPtr(Platform::current()->compositorSupport()->
createAnimationPlayer()); |
| 26 ASSERT(m_compositorPlayer); | 33 ASSERT(m_compositorPlayer); |
| 27 m_compositorPlayer->setAnimationDelegate(this); | 34 m_compositorPlayer->setAnimationDelegate(this); |
| 28 } | 35 } |
| 29 } | 36 } |
| 30 | 37 |
| 31 ScrollAnimatorCompositorCoordinator::~ScrollAnimatorCompositorCoordinator() | 38 ScrollAnimatorCompositorCoordinator::~ScrollAnimatorCompositorCoordinator() |
| 32 { | 39 { |
| 33 if (m_compositorPlayer) { | 40 if (m_compositorPlayer) { |
| 34 m_compositorPlayer->setAnimationDelegate(nullptr); | 41 m_compositorPlayer->setAnimationDelegate(nullptr); |
| 35 m_compositorPlayer.clear(); | 42 m_compositorPlayer.clear(); |
| 36 } | 43 } |
| 37 } | 44 } |
| 38 | 45 |
| 39 void ScrollAnimatorCompositorCoordinator::resetAnimationState() | 46 void ScrollAnimatorCompositorCoordinator::resetAnimationState() |
| 40 { | 47 { |
| 41 m_runState = RunState::Idle; | 48 m_runState = RunState::Idle; |
| 42 m_compositorAnimationId = 0; | 49 m_compositorAnimationId = 0; |
| 43 m_compositorAnimationGroupId = 0; | 50 m_compositorAnimationGroupId = 0; |
| 51 |
| 52 // While there was a running animation, a temporary main thread scrolling |
| 53 // reason may have been added for the animation to complete on the main |
| 54 // thread. |
| 55 clearMainThreadScrollingReasonsOnLayer(); |
| 56 } |
| 57 |
| 58 void ScrollAnimatorCompositorCoordinator::clearMainThreadScrollingReasonsOnLayer
() |
| 59 { |
| 60 if (WebLayer* scrollLayer = toWebLayer(scrollableArea()->layerForScrolling()
)) { |
| 61 if (m_clearMainThreadScrollingReasons) { |
| 62 scrollLayer->clearMainThreadScrollingReasons(); |
| 63 m_clearMainThreadScrollingReasons = false; |
| 64 } else { |
| 65 scrollLayer->clearMainThreadScrollingReasons( |
| 66 MainThreadScrollingReason::kContinuingMainThreadScroll); |
| 67 } |
| 68 } |
| 69 } |
| 70 |
| 71 void ScrollAnimatorCompositorCoordinator::clearMainThreadScrollingReasons(bool c
lear) |
| 72 { |
| 73 m_clearMainThreadScrollingReasons = clear; |
| 74 if (!clear) |
| 75 return; |
| 76 if (!hasRunningAnimation()) { |
| 77 clearMainThreadScrollingReasonsOnLayer(); |
| 78 } else if (WebLayer* scrollLayer = toWebLayer(scrollableArea()->layerForScro
lling())) { |
| 79 // If there is a running animation, finish it on main thread before |
| 80 // clearing main thread scrolling reasons. In the mean time, add |
| 81 // a temporary main thread scrolling reason that ensures that the cc |
| 82 // doesn't start another scroll animation that will compete with this |
| 83 // animation (see crbug.com/581875). |
| 84 scrollLayer->addMainThreadScrollingReasons( |
| 85 MainThreadScrollingReason::kContinuingMainThreadScroll); |
| 86 } |
| 44 } | 87 } |
| 45 | 88 |
| 46 bool ScrollAnimatorCompositorCoordinator::hasAnimationThatRequiresService() cons
t | 89 bool ScrollAnimatorCompositorCoordinator::hasAnimationThatRequiresService() cons
t |
| 47 { | 90 { |
| 48 switch (m_runState) { | 91 switch (m_runState) { |
| 49 case RunState::Idle: | 92 case RunState::Idle: |
| 50 case RunState::RunningOnCompositor: | 93 case RunState::RunningOnCompositor: |
| 51 return false; | 94 return false; |
| 52 case RunState::WaitingToSendToCompositor: | 95 case RunState::WaitingToSendToCompositor: |
| 53 case RunState::RunningOnMainThread: | 96 case RunState::RunningOnMainThread: |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 189 // animation. | 232 // animation. |
| 190 notifyCompositorAnimationFinished(group); | 233 notifyCompositorAnimationFinished(group); |
| 191 } | 234 } |
| 192 | 235 |
| 193 WebCompositorAnimationPlayer* ScrollAnimatorCompositorCoordinator::compositorPla
yer() const | 236 WebCompositorAnimationPlayer* ScrollAnimatorCompositorCoordinator::compositorPla
yer() const |
| 194 { | 237 { |
| 195 return m_compositorPlayer.get(); | 238 return m_compositorPlayer.get(); |
| 196 } | 239 } |
| 197 | 240 |
| 198 } // namespace blink | 241 } // namespace blink |
| OLD | NEW |