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

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: nits 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
43 namespace {
44
45 blink::WebLayer* toWebLayer(blink::GraphicsLayer* layer)
jbroman 2016/02/10 22:42:55 nit: you can put the anonymous namespace inside th
ymalik 2016/02/12 17:55:52 Done.
46 {
47 return layer ? layer->platformLayer() : nullptr;
48 }
49
50 } // namespace
51
42 namespace blink { 52 namespace blink {
43 53
44 PassOwnPtrWillBeRawPtr<ScrollAnimatorBase> ScrollAnimatorBase::create(Scrollable Area* scrollableArea) 54 PassOwnPtrWillBeRawPtr<ScrollAnimatorBase> ScrollAnimatorBase::create(Scrollable Area* scrollableArea)
45 { 55 {
46 if (scrollableArea && scrollableArea->scrollAnimatorEnabled()) 56 if (scrollableArea && scrollableArea->scrollAnimatorEnabled())
47 return adoptPtrWillBeNoop(new ScrollAnimator(scrollableArea)); 57 return adoptPtrWillBeNoop(new ScrollAnimator(scrollableArea));
48 return adoptPtrWillBeNoop(new ScrollAnimatorBase(scrollableArea)); 58 return adoptPtrWillBeNoop(new ScrollAnimatorBase(scrollableArea));
49 } 59 }
50 60
51 ScrollAnimator::ScrollAnimator(ScrollableArea* scrollableArea, WTF::TimeFunction timeFunction) 61 ScrollAnimator::ScrollAnimator(ScrollableArea* scrollableArea, WTF::TimeFunction timeFunction)
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 192
183 if (isFinished) 193 if (isFinished)
184 m_runState = RunState::PostAnimationCleanup; 194 m_runState = RunState::PostAnimationCleanup;
185 else 195 else
186 scrollableArea()->scheduleAnimation(); 196 scrollableArea()->scheduleAnimation();
187 197
188 TRACE_EVENT0("blink", "ScrollAnimator::notifyPositionChanged"); 198 TRACE_EVENT0("blink", "ScrollAnimator::notifyPositionChanged");
189 notifyPositionChanged(); 199 notifyPositionChanged();
190 } 200 }
191 201
202 void ScrollAnimator::postAnimationCleanupAndReset()
203 {
204 // Remove the temporary main thread scrolling reason that was added while
205 // main thread had scheduled an animation.
206 removeMainThreadScrollingReason();
207
208 resetAnimationState();
209 }
210
192 void ScrollAnimator::updateCompositorAnimations() 211 void ScrollAnimator::updateCompositorAnimations()
193 { 212 {
194 if (m_runState == RunState::PostAnimationCleanup) 213 if (m_runState == RunState::PostAnimationCleanup) {
195 return resetAnimationState(); 214 postAnimationCleanupAndReset();
215 return;
216 }
196 217
197 if (m_compositorAnimationId && m_runState != RunState::RunningOnCompositor 218 if (m_compositorAnimationId && m_runState != RunState::RunningOnCompositor
198 && m_runState != RunState::RunningOnCompositorButNeedsUpdate) { 219 && m_runState != RunState::RunningOnCompositorButNeedsUpdate) {
199 // If the current run state is WaitingToSendToCompositor but we have a 220 // If the current run state is WaitingToSendToCompositor but we have a
200 // non-zero compositor animation id, there's a currently running 221 // non-zero compositor animation id, there's a currently running
201 // compositor animation that needs to be removed here before the new 222 // compositor animation that needs to be removed here before the new
202 // animation is added below. 223 // animation is added below.
203 ASSERT(m_runState == RunState::WaitingToCancelOnCompositor 224 ASSERT(m_runState == RunState::WaitingToCancelOnCompositor
204 || m_runState == RunState::WaitingToSendToCompositor); 225 || m_runState == RunState::WaitingToSendToCompositor);
205 226
206 abortAnimation(); 227 abortAnimation();
207 228
208 m_compositorAnimationId = 0; 229 m_compositorAnimationId = 0;
209 m_compositorAnimationGroupId = 0; 230 m_compositorAnimationGroupId = 0;
210 if (m_runState == RunState::WaitingToCancelOnCompositor) { 231 if (m_runState == RunState::WaitingToCancelOnCompositor) {
211 return resetAnimationState(); 232 postAnimationCleanupAndReset();
233 return;
212 } 234 }
213 } 235 }
214 236
215 if (m_runState == RunState::WaitingToSendToCompositor 237 if (m_runState == RunState::WaitingToSendToCompositor
216 || m_runState == RunState::RunningOnCompositorButNeedsUpdate) { 238 || m_runState == RunState::RunningOnCompositorButNeedsUpdate) {
217 if (m_runState == RunState::RunningOnCompositorButNeedsUpdate) { 239 if (m_runState == RunState::RunningOnCompositorButNeedsUpdate) {
218 // Abort the running animation before a new one with an updated 240 // Abort the running animation before a new one with an updated
219 // target is added. 241 // target is added.
220 abortAnimation(); 242 abortAnimation();
221 243
(...skipping 34 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 WebCompositorAnimationTimeline* timeline) 337 WebCompositorAnimationTimeline* 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