Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(484)

Side by Side Diff: third_party/WebKit/Source/platform/scroll/ScrollAnimator.cpp

Issue 1648293003: Fix smooth scroll jump when switching scroll handling between MT and CC (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: skip irrelevant test on mac Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 16 matching lines...) Expand all
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/animation/CompositorAnimation.h" 34 #include "platform/animation/CompositorAnimation.h"
35 #include "platform/graphics/CompositorFactory.h" 35 #include "platform/graphics/CompositorFactory.h"
36 #include "platform/graphics/GraphicsLayer.h" 36 #include "platform/graphics/GraphicsLayer.h"
37 #include "platform/scroll/MainThreadScrollingReason.h"
37 #include "platform/scroll/ScrollableArea.h" 38 #include "platform/scroll/ScrollableArea.h"
38 #include "public/platform/Platform.h" 39 #include "public/platform/Platform.h"
39 #include "public/platform/WebCompositorSupport.h" 40 #include "public/platform/WebCompositorSupport.h"
40 #include "wtf/CurrentTime.h" 41 #include "wtf/CurrentTime.h"
41 #include "wtf/PassRefPtr.h" 42 #include "wtf/PassRefPtr.h"
42 43
43 namespace blink { 44 namespace blink {
44 45
46 namespace {
47
48 WebLayer* toWebLayer(GraphicsLayer* layer)
49 {
50 return layer ? layer->platformLayer() : nullptr;
51 }
52
53 } // namespace
54
45 PassOwnPtrWillBeRawPtr<ScrollAnimatorBase> ScrollAnimatorBase::create(Scrollable Area* scrollableArea) 55 PassOwnPtrWillBeRawPtr<ScrollAnimatorBase> ScrollAnimatorBase::create(Scrollable Area* scrollableArea)
46 { 56 {
47 if (scrollableArea && scrollableArea->scrollAnimatorEnabled()) 57 if (scrollableArea && scrollableArea->scrollAnimatorEnabled())
48 return adoptPtrWillBeNoop(new ScrollAnimator(scrollableArea)); 58 return adoptPtrWillBeNoop(new ScrollAnimator(scrollableArea));
49 return adoptPtrWillBeNoop(new ScrollAnimatorBase(scrollableArea)); 59 return adoptPtrWillBeNoop(new ScrollAnimatorBase(scrollableArea));
50 } 60 }
51 61
52 ScrollAnimator::ScrollAnimator(ScrollableArea* scrollableArea, WTF::TimeFunction timeFunction) 62 ScrollAnimator::ScrollAnimator(ScrollableArea* scrollableArea, WTF::TimeFunction timeFunction)
53 : ScrollAnimatorBase(scrollableArea) 63 : ScrollAnimatorBase(scrollableArea)
54 , m_timeFunction(timeFunction) 64 , m_timeFunction(timeFunction)
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 193
184 if (isFinished) 194 if (isFinished)
185 m_runState = RunState::PostAnimationCleanup; 195 m_runState = RunState::PostAnimationCleanup;
186 else 196 else
187 scrollableArea()->scheduleAnimation(); 197 scrollableArea()->scheduleAnimation();
188 198
189 TRACE_EVENT0("blink", "ScrollAnimator::notifyPositionChanged"); 199 TRACE_EVENT0("blink", "ScrollAnimator::notifyPositionChanged");
190 notifyPositionChanged(); 200 notifyPositionChanged();
191 } 201 }
192 202
203 void ScrollAnimator::postAnimationCleanupAndReset()
204 {
205 // Remove the temporary main thread scrolling reason that was added while
206 // main thread had scheduled an animation.
207 removeMainThreadScrollingReason();
208
209 resetAnimationState();
210 }
211
193 void ScrollAnimator::updateCompositorAnimations() 212 void ScrollAnimator::updateCompositorAnimations()
194 { 213 {
195 if (m_runState == RunState::PostAnimationCleanup) 214 if (m_runState == RunState::PostAnimationCleanup) {
196 return resetAnimationState(); 215 postAnimationCleanupAndReset();
216 return;
217 }
197 218
198 if (m_compositorAnimationId && m_runState != RunState::RunningOnCompositor 219 if (m_compositorAnimationId && m_runState != RunState::RunningOnCompositor
199 && m_runState != RunState::RunningOnCompositorButNeedsUpdate) { 220 && m_runState != RunState::RunningOnCompositorButNeedsUpdate) {
200 // If the current run state is WaitingToSendToCompositor but we have a 221 // If the current run state is WaitingToSendToCompositor but we have a
201 // non-zero compositor animation id, there's a currently running 222 // non-zero compositor animation id, there's a currently running
202 // compositor animation that needs to be removed here before the new 223 // compositor animation that needs to be removed here before the new
203 // animation is added below. 224 // animation is added below.
204 ASSERT(m_runState == RunState::WaitingToCancelOnCompositor 225 ASSERT(m_runState == RunState::WaitingToCancelOnCompositor
205 || m_runState == RunState::WaitingToSendToCompositor); 226 || m_runState == RunState::WaitingToSendToCompositor);
206 227
207 abortAnimation(); 228 abortAnimation();
208 229
209 m_compositorAnimationId = 0; 230 m_compositorAnimationId = 0;
210 m_compositorAnimationGroupId = 0; 231 m_compositorAnimationGroupId = 0;
211 if (m_runState == RunState::WaitingToCancelOnCompositor) { 232 if (m_runState == RunState::WaitingToCancelOnCompositor) {
212 return resetAnimationState(); 233 postAnimationCleanupAndReset();
234 return;
213 } 235 }
214 } 236 }
215 237
216 if (m_runState == RunState::WaitingToSendToCompositor 238 if (m_runState == RunState::WaitingToSendToCompositor
217 || m_runState == RunState::RunningOnCompositorButNeedsUpdate) { 239 || m_runState == RunState::RunningOnCompositorButNeedsUpdate) {
218 if (m_runState == RunState::RunningOnCompositorButNeedsUpdate) { 240 if (m_runState == RunState::RunningOnCompositorButNeedsUpdate) {
219 // Abort the running animation before a new one with an updated 241 // Abort the running animation before a new one with an updated
220 // target is added. 242 // target is added.
221 abortAnimation(); 243 abortAnimation();
222 244
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
256 int animationGroupId = animation->group(); 278 int animationGroupId = animation->group();
257 279
258 sentToCompositor = addAnimation(animation.release()); 280 sentToCompositor = addAnimation(animation.release());
259 if (sentToCompositor) { 281 if (sentToCompositor) {
260 m_runState = RunState::RunningOnCompositor; 282 m_runState = RunState::RunningOnCompositor;
261 m_compositorAnimationId = animationId; 283 m_compositorAnimationId = animationId;
262 m_compositorAnimationGroupId = animationGroupId; 284 m_compositorAnimationGroupId = animationGroupId;
263 } 285 }
264 } 286 }
265 287
288 bool runningOnMainThread = false;
266 if (!sentToCompositor) { 289 if (!sentToCompositor) {
267 if (registerAndScheduleAnimation()) 290 runningOnMainThread = registerAndScheduleAnimation();
291 if (runningOnMainThread)
268 m_runState = RunState::RunningOnMainThread; 292 m_runState = RunState::RunningOnMainThread;
269 } 293 }
294
295 // Main thread should deal with the scroll animations it started.
296 if (sentToCompositor || runningOnMainThread)
297 addMainThreadScrollingReason();
298 else
299 removeMainThreadScrollingReason();
270 } 300 }
271 } 301 }
272 302
303 void ScrollAnimator::addMainThreadScrollingReason()
304 {
305 if (WebLayer* scrollLayer = toWebLayer(scrollableArea()->layerForScrolling() )) {
306 scrollLayer->addMainThreadScrollingReasons(
307 MainThreadScrollingReason::kAnimatingScrollOnMainThread);
308 }
309 }
310
311 void ScrollAnimator::removeMainThreadScrollingReason()
312 {
313 if (WebLayer* scrollLayer = toWebLayer(scrollableArea()->layerForScrolling() )) {
314 scrollLayer->clearMainThreadScrollingReasons(
315 MainThreadScrollingReason::kAnimatingScrollOnMainThread);
316 }
317 }
318
273 void ScrollAnimator::notifyCompositorAnimationAborted(int groupId) 319 void ScrollAnimator::notifyCompositorAnimationAborted(int groupId)
274 { 320 {
275 // An animation aborted by the compositor is treated as a finished 321 // An animation aborted by the compositor is treated as a finished
276 // animation. 322 // animation.
277 ScrollAnimatorCompositorCoordinator::compositorAnimationFinished(groupId); 323 ScrollAnimatorCompositorCoordinator::compositorAnimationFinished(groupId);
278 } 324 }
279 325
280 void ScrollAnimator::notifyCompositorAnimationFinished(int groupId) 326 void ScrollAnimator::notifyCompositorAnimationFinished(int groupId)
281 { 327 {
282 ScrollAnimatorCompositorCoordinator::compositorAnimationFinished(groupId); 328 ScrollAnimatorCompositorCoordinator::compositorAnimationFinished(groupId);
283 } 329 }
284 330
285 void ScrollAnimator::cancelAnimation() 331 void ScrollAnimator::cancelAnimation()
286 { 332 {
287 ScrollAnimatorCompositorCoordinator::cancelAnimation(); 333 ScrollAnimatorCompositorCoordinator::cancelAnimation();
288 } 334 }
289 335
290 void ScrollAnimator::layerForCompositedScrollingDidChange( 336 void ScrollAnimator::layerForCompositedScrollingDidChange(
291 CompositorAnimationTimeline* timeline) 337 CompositorAnimationTimeline* timeline)
292 { 338 {
293 reattachCompositorPlayerIfNeeded(timeline); 339 if (reattachCompositorPlayerIfNeeded(timeline) && m_animationCurve)
340 addMainThreadScrollingReason();
294 } 341 }
295 342
296 bool ScrollAnimator::registerAndScheduleAnimation() 343 bool ScrollAnimator::registerAndScheduleAnimation()
297 { 344 {
298 scrollableArea()->registerForAnimation(); 345 scrollableArea()->registerForAnimation();
299 if (!m_scrollableArea->scheduleAnimation()) { 346 if (!m_scrollableArea->scheduleAnimation()) {
300 scrollToOffsetWithoutAnimation(m_targetOffset); 347 scrollToOffsetWithoutAnimation(m_targetOffset);
301 resetAnimationState(); 348 resetAnimationState();
302 return false; 349 return false;
303 } 350 }
304 return true; 351 return true;
305 } 352 }
306 353
307 DEFINE_TRACE(ScrollAnimator) 354 DEFINE_TRACE(ScrollAnimator)
308 { 355 {
309 ScrollAnimatorBase::trace(visitor); 356 ScrollAnimatorBase::trace(visitor);
310 } 357 }
311 358
312 } // namespace blink 359 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698