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

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: todo + nit 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 14 matching lines...) Expand all
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)
jbroman 2016/02/10 20:36:37 Please make this a static function or enclose it i
ymalik 2016/02/10 21:57:58 Done. Thanks!
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 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 188
183 if (isFinished) 189 if (isFinished)
184 m_runState = RunState::PostAnimationCleanup; 190 m_runState = RunState::PostAnimationCleanup;
185 else 191 else
186 scrollableArea()->scheduleAnimation(); 192 scrollableArea()->scheduleAnimation();
187 193
188 TRACE_EVENT0("blink", "ScrollAnimator::notifyPositionChanged"); 194 TRACE_EVENT0("blink", "ScrollAnimator::notifyPositionChanged");
189 notifyPositionChanged(); 195 notifyPositionChanged();
190 } 196 }
191 197
198 void ScrollAnimator::postAnimationCleanupAndReset()
199 {
200 // Remove the temporary main thread scrolling reason that was added while
201 // main thread had scheduled an animation.
202 removeMainThreadScrollingReason();
203
204 resetAnimationState();
205 }
206
192 void ScrollAnimator::updateCompositorAnimations() 207 void ScrollAnimator::updateCompositorAnimations()
193 { 208 {
194 if (m_runState == RunState::PostAnimationCleanup) 209 if (m_runState == RunState::PostAnimationCleanup) {
195 return resetAnimationState(); 210 postAnimationCleanupAndReset();
211 return;
212 }
196 213
197 if (m_compositorAnimationId && m_runState != RunState::RunningOnCompositor 214 if (m_compositorAnimationId && m_runState != RunState::RunningOnCompositor
198 && m_runState != RunState::RunningOnCompositorButNeedsUpdate) { 215 && m_runState != RunState::RunningOnCompositorButNeedsUpdate) {
199 // If the current run state is WaitingToSendToCompositor but we have a 216 // If the current run state is WaitingToSendToCompositor but we have a
200 // non-zero compositor animation id, there's a currently running 217 // non-zero compositor animation id, there's a currently running
201 // compositor animation that needs to be removed here before the new 218 // compositor animation that needs to be removed here before the new
202 // animation is added below. 219 // animation is added below.
203 ASSERT(m_runState == RunState::WaitingToCancelOnCompositor 220 ASSERT(m_runState == RunState::WaitingToCancelOnCompositor
204 || m_runState == RunState::WaitingToSendToCompositor); 221 || m_runState == RunState::WaitingToSendToCompositor);
205 222
206 abortAnimation(); 223 abortAnimation();
207 224
208 m_compositorAnimationId = 0; 225 m_compositorAnimationId = 0;
209 m_compositorAnimationGroupId = 0; 226 m_compositorAnimationGroupId = 0;
210 if (m_runState == RunState::WaitingToCancelOnCompositor) { 227 if (m_runState == RunState::WaitingToCancelOnCompositor) {
211 return resetAnimationState(); 228 postAnimationCleanupAndReset();
229 return;
212 } 230 }
213 } 231 }
214 232
215 if (m_runState == RunState::WaitingToSendToCompositor 233 if (m_runState == RunState::WaitingToSendToCompositor
216 || m_runState == RunState::RunningOnCompositorButNeedsUpdate) { 234 || m_runState == RunState::RunningOnCompositorButNeedsUpdate) {
217 if (m_runState == RunState::RunningOnCompositorButNeedsUpdate) { 235 if (m_runState == RunState::RunningOnCompositorButNeedsUpdate) {
218 // Abort the running animation before a new one with an updated 236 // Abort the running animation before a new one with an updated
219 // target is added. 237 // target is added.
220 abortAnimation(); 238 abortAnimation();
221 239
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
256 int animationGroupId = animation->group(); 274 int animationGroupId = animation->group();
257 275
258 sentToCompositor = addAnimation(animation.release()); 276 sentToCompositor = addAnimation(animation.release());
259 if (sentToCompositor) { 277 if (sentToCompositor) {
260 m_runState = RunState::RunningOnCompositor; 278 m_runState = RunState::RunningOnCompositor;
261 m_compositorAnimationId = animationId; 279 m_compositorAnimationId = animationId;
262 m_compositorAnimationGroupId = animationGroupId; 280 m_compositorAnimationGroupId = animationGroupId;
263 } 281 }
264 } 282 }
265 283
284 bool runningOnMainThread = false;
266 if (!sentToCompositor) { 285 if (!sentToCompositor) {
267 if (registerAndScheduleAnimation()) 286 runningOnMainThread = registerAndScheduleAnimation();
287 if (runningOnMainThread)
268 m_runState = RunState::RunningOnMainThread; 288 m_runState = RunState::RunningOnMainThread;
269 } 289 }
290
291 // Main thread should deal with the scroll animations it started.
292 if (sentToCompositor || runningOnMainThread)
293 addMainThreadScrollingReason();
294 else
295 removeMainThreadScrollingReason();
270 } 296 }
271 } 297 }
272 298
299 void ScrollAnimator::addMainThreadScrollingReason()
300 {
301 if (WebLayer* scrollLayer = toWebLayer(scrollableArea()->layerForScrolling() )) {
302 scrollLayer->addMainThreadScrollingReasons(
303 MainThreadScrollingReason::kAnimatingScollOnMainThread);
304 }
305 }
306
307 void ScrollAnimator::removeMainThreadScrollingReason()
308 {
309 if (WebLayer* scrollLayer = toWebLayer(scrollableArea()->layerForScrolling() )) {
310 scrollLayer->clearMainThreadScrollingReasons(
311 MainThreadScrollingReason::kAnimatingScollOnMainThread);
312 }
313 }
314
273 void ScrollAnimator::notifyCompositorAnimationAborted(int groupId) 315 void ScrollAnimator::notifyCompositorAnimationAborted(int groupId)
274 { 316 {
275 // An animation aborted by the compositor is treated as a finished 317 // An animation aborted by the compositor is treated as a finished
276 // animation. 318 // animation.
277 ScrollAnimatorCompositorCoordinator::compositorAnimationFinished(groupId); 319 ScrollAnimatorCompositorCoordinator::compositorAnimationFinished(groupId);
278 } 320 }
279 321
280 void ScrollAnimator::notifyCompositorAnimationFinished(int groupId) 322 void ScrollAnimator::notifyCompositorAnimationFinished(int groupId)
281 { 323 {
282 ScrollAnimatorCompositorCoordinator::compositorAnimationFinished(groupId); 324 ScrollAnimatorCompositorCoordinator::compositorAnimationFinished(groupId);
283 } 325 }
284 326
285 void ScrollAnimator::cancelAnimation() 327 void ScrollAnimator::cancelAnimation()
286 { 328 {
287 ScrollAnimatorCompositorCoordinator::cancelAnimation(); 329 ScrollAnimatorCompositorCoordinator::cancelAnimation();
288 } 330 }
289 331
290 void ScrollAnimator::layerForCompositedScrollingDidChange( 332 void ScrollAnimator::layerForCompositedScrollingDidChange(
291 WebCompositorAnimationTimeline* timeline) 333 WebCompositorAnimationTimeline* timeline)
292 { 334 {
293 reattachCompositorPlayerIfNeeded(timeline); 335 if (reattachCompositorPlayerIfNeeded(timeline) && m_animationCurve)
336 addMainThreadScrollingReason();
294 } 337 }
295 338
296 bool ScrollAnimator::registerAndScheduleAnimation() 339 bool ScrollAnimator::registerAndScheduleAnimation()
297 { 340 {
298 scrollableArea()->registerForAnimation(); 341 scrollableArea()->registerForAnimation();
299 if (!m_scrollableArea->scheduleAnimation()) { 342 if (!m_scrollableArea->scheduleAnimation()) {
300 scrollToOffsetWithoutAnimation(m_targetOffset); 343 scrollToOffsetWithoutAnimation(m_targetOffset);
301 resetAnimationState(); 344 resetAnimationState();
302 return false; 345 return false;
303 } 346 }
304 return true; 347 return true;
305 } 348 }
306 349
307 DEFINE_TRACE(ScrollAnimator) 350 DEFINE_TRACE(ScrollAnimator)
308 { 351 {
309 ScrollAnimatorBase::trace(visitor); 352 ScrollAnimatorBase::trace(visitor);
310 } 353 }
311 354
312 } // namespace blink 355 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698