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 |
| 280 // Main thread should deal with the scroll animations it started. |
| 281 if (sentToCompositor || runningOnMainThread) |
| 282 addMainThreadScrollingReason(); |
266 } | 283 } |
267 } | 284 } |
268 | 285 |
| 286 void ScrollAnimator::addMainThreadScrollingReason() |
| 287 { |
| 288 if (WebLayer* scrollLayer = toWebLayer(scrollableArea()->layerForScrolling()
)) { |
| 289 scrollLayer->addMainThreadScrollingReasons( |
| 290 MainThreadScrollingReason::kAnimatingScollOnMainThread); |
| 291 } |
| 292 } |
| 293 |
| 294 void ScrollAnimator::removeMainThreadScrollingReason() |
| 295 { |
| 296 if (WebLayer* scrollLayer = toWebLayer(scrollableArea()->layerForScrolling()
)) { |
| 297 scrollLayer->clearMainThreadScrollingReasons( |
| 298 MainThreadScrollingReason::kAnimatingScollOnMainThread); |
| 299 } |
| 300 } |
| 301 |
269 void ScrollAnimator::notifyCompositorAnimationAborted(int groupId) | 302 void ScrollAnimator::notifyCompositorAnimationAborted(int groupId) |
270 { | 303 { |
271 // An animation aborted by the compositor is treated as a finished | 304 // An animation aborted by the compositor is treated as a finished |
272 // animation. | 305 // animation. |
273 ScrollAnimatorCompositorCoordinator::compositorAnimationFinished(groupId); | 306 ScrollAnimatorCompositorCoordinator::compositorAnimationFinished(groupId); |
274 } | 307 } |
275 | 308 |
276 void ScrollAnimator::notifyCompositorAnimationFinished(int groupId) | 309 void ScrollAnimator::notifyCompositorAnimationFinished(int groupId) |
277 { | 310 { |
278 ScrollAnimatorCompositorCoordinator::compositorAnimationFinished(groupId); | 311 ScrollAnimatorCompositorCoordinator::compositorAnimationFinished(groupId); |
279 } | 312 } |
280 | 313 |
281 void ScrollAnimator::cancelAnimation() | 314 void ScrollAnimator::cancelAnimation() |
282 { | 315 { |
283 ScrollAnimatorCompositorCoordinator::cancelAnimation(); | 316 ScrollAnimatorCompositorCoordinator::cancelAnimation(); |
284 } | 317 } |
285 | 318 |
286 void ScrollAnimator::layerForCompositedScrollingDidChange( | 319 void ScrollAnimator::layerForCompositedScrollingDidChange( |
287 WebCompositorAnimationTimeline* timeline) | 320 WebCompositorAnimationTimeline* timeline) |
288 { | 321 { |
289 reattachCompositorPlayerIfNeeded(timeline); | 322 if (reattachCompositorPlayerIfNeeded(timeline) && m_animationCurve) |
| 323 addMainThreadScrollingReason(); |
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 |