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

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

Issue 1782563002: Takeover MT initiated animations from the compositor (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2661
Patch Set: Created 4 years, 9 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 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 if (m_runState == RunState::PostAnimationCleanup) 138 if (m_runState == RunState::PostAnimationCleanup)
139 resetAnimationState(); 139 resetAnimationState();
140 140
141 if (m_animationCurve && m_runState != RunState::WaitingToCancelOnCompositor) { 141 if (m_animationCurve && m_runState != RunState::WaitingToCancelOnCompositor) {
142 if ((targetPos - m_targetOffset).isZero()) 142 if ((targetPos - m_targetOffset).isZero())
143 return true; 143 return true;
144 144
145 m_targetOffset = targetPos; 145 m_targetOffset = targetPos;
146 ASSERT(m_runState == RunState::RunningOnMainThread 146 ASSERT(m_runState == RunState::RunningOnMainThread
147 || m_runState == RunState::RunningOnCompositor 147 || m_runState == RunState::RunningOnCompositor
148 || m_runState == RunState::RunningOnCompositorButNeedsUpdate); 148 || m_runState == RunState::RunningOnCompositorButNeedsUpdate
149 || m_runState == RunState::RunningOnCompositorButNeedsTakeover);
149 150
150 if (m_runState == RunState::RunningOnCompositor 151 // Running on the main thread, simply update the target offset instead
151 || m_runState == RunState::RunningOnCompositorButNeedsUpdate) { 152 // of sending to the compositor.
152 if (registerAndScheduleAnimation()) 153 if (m_runState == RunState::RunningOnMainThread) {
153 m_runState = RunState::RunningOnCompositorButNeedsUpdate; 154 m_animationCurve->updateTarget(m_timeFunction() - m_startTime, targe tPos);
154 return true; 155 return true;
155 } 156 }
156 157
157 // Running on the main thread, simply update the target offset instead 158 if (registerAndScheduleAnimation())
158 // of sending to the compositor. 159 m_runState = RunState::RunningOnCompositorButNeedsUpdate;
159 m_animationCurve->updateTarget(m_timeFunction() - m_startTime, targetPos );
160 return true; 160 return true;
161 } 161 }
162 162
163 if ((targetPos - currentPosition()).isZero()) 163 if ((targetPos - currentPosition()).isZero())
164 return false; 164 return false;
165 165
166 m_targetOffset = targetPos; 166 m_targetOffset = targetPos;
167 m_startTime = m_timeFunction(); 167 m_startTime = m_timeFunction();
168 168
169 if (registerAndScheduleAnimation()) 169 if (registerAndScheduleAnimation())
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 209
210 void ScrollAnimator::postAnimationCleanupAndReset() 210 void ScrollAnimator::postAnimationCleanupAndReset()
211 { 211 {
212 // Remove the temporary main thread scrolling reason that was added while 212 // Remove the temporary main thread scrolling reason that was added while
213 // main thread had scheduled an animation. 213 // main thread had scheduled an animation.
214 removeMainThreadScrollingReason(); 214 removeMainThreadScrollingReason();
215 215
216 resetAnimationState(); 216 resetAnimationState();
217 } 217 }
218 218
219 bool ScrollAnimator::sendAnimationToCompositor()
220 {
221 if (m_scrollableArea->shouldScrollOnMainThread())
222 return false;
223
224 OwnPtr<CompositorAnimation> animation = adoptPtr(
225 CompositorFactory::current().createAnimation(
226 *m_animationCurve,
227 CompositorTargetProperty::SCROLL_OFFSET));
228 // Being here means that either there is an animation that needs
229 // to be sent to the compositor, or an animation that needs to
230 // be updated (a new scroll event before the previous animation
231 // is finished). In either case, the start time is when the
232 // first animation was initiated. This re-targets the animation
233 // using the current time on main thread.
234 animation->setStartTime(m_startTime);
235
236 int animationId = animation->id();
237 int animationGroupId = animation->group();
238
239 bool sentToCompositor = addAnimation(animation.release());
240 if (sentToCompositor) {
241 m_runState = RunState::RunningOnCompositor;
242 m_compositorAnimationId = animationId;
243 m_compositorAnimationGroupId = animationGroupId;
244 }
245
246 return sentToCompositor;
247 }
248
219 void ScrollAnimator::updateCompositorAnimations() 249 void ScrollAnimator::updateCompositorAnimations()
220 { 250 {
221 if (m_runState == RunState::PostAnimationCleanup) { 251 if (m_runState == RunState::PostAnimationCleanup) {
222 postAnimationCleanupAndReset(); 252 postAnimationCleanupAndReset();
223 return; 253 return;
224 } 254 }
225 255
226 if (m_compositorAnimationId && m_runState != RunState::RunningOnCompositor 256 if (m_compositorAnimationId && m_runState != RunState::RunningOnCompositor
227 && m_runState != RunState::RunningOnCompositorButNeedsUpdate) { 257 && m_runState != RunState::RunningOnCompositorButNeedsUpdate) {
228 // If the current run state is WaitingToSendToCompositor but we have a 258 // If the current run state is WaitingToSendToCompositor but we have a
229 // non-zero compositor animation id, there's a currently running 259 // non-zero compositor animation id, there's a currently running
230 // compositor animation that needs to be removed here before the new 260 // compositor animation that needs to be removed here before the new
231 // animation is added below. 261 // animation is added below.
232 ASSERT(m_runState == RunState::WaitingToCancelOnCompositor 262 ASSERT(m_runState == RunState::WaitingToCancelOnCompositor
233 || m_runState == RunState::WaitingToSendToCompositor); 263 || m_runState == RunState::WaitingToSendToCompositor
264 || m_runState == RunState::RunningOnCompositorButNeedsTakeover);
234 265
235 abortAnimation(); 266 if (m_runState == RunState::RunningOnCompositorButNeedsTakeover) {
267 // The animation is already aborted when the call to
268 // ::takeoverCompositorAnimation is made.
269 m_runState = RunState::WaitingToSendToCompositor;
270 } else {
271 abortAnimation();
272 }
236 273
237 m_compositorAnimationId = 0; 274 m_compositorAnimationId = 0;
238 m_compositorAnimationGroupId = 0; 275 m_compositorAnimationGroupId = 0;
239 if (m_runState == RunState::WaitingToCancelOnCompositor) { 276 if (m_runState == RunState::WaitingToCancelOnCompositor) {
240 postAnimationCleanupAndReset(); 277 postAnimationCleanupAndReset();
241 return; 278 return;
242 } 279 }
243 } 280 }
244 281
245 if (m_runState == RunState::WaitingToSendToCompositor 282 if (m_runState == RunState::WaitingToSendToCompositor
(...skipping 14 matching lines...) Expand all
260 if (!m_animationCurve) { 297 if (!m_animationCurve) {
261 m_animationCurve = adoptPtr(CompositorFactory::current().createScrol lOffsetAnimationCurve( 298 m_animationCurve = adoptPtr(CompositorFactory::current().createScrol lOffsetAnimationCurve(
262 m_targetOffset, 299 m_targetOffset,
263 CompositorAnimationCurve::TimingFunctionTypeEaseInOut, 300 CompositorAnimationCurve::TimingFunctionTypeEaseInOut,
264 m_lastGranularity == ScrollByPixel ? 301 m_lastGranularity == ScrollByPixel ?
265 CompositorScrollOffsetAnimationCurve::ScrollDurationInverseD elta : 302 CompositorScrollOffsetAnimationCurve::ScrollDurationInverseD elta :
266 CompositorScrollOffsetAnimationCurve::ScrollDurationConstant )); 303 CompositorScrollOffsetAnimationCurve::ScrollDurationConstant ));
267 m_animationCurve->setInitialValue(currentPosition()); 304 m_animationCurve->setInitialValue(currentPosition());
268 } 305 }
269 306
270 bool sentToCompositor = false;
271 if (!m_scrollableArea->shouldScrollOnMainThread()) {
272 OwnPtr<CompositorAnimation> animation = adoptPtr(
273 CompositorFactory::current().createAnimation(
274 *m_animationCurve,
275 CompositorTargetProperty::SCROLL_OFFSET));
276 // Being here means that either there is an animation that needs
277 // to be sent to the compositor, or an animation that needs to
278 // be updated (a new scroll event before the previous animation
279 // is finished). In either case, the start time is when the
280 // first animation was initiated. This re-targets the animation
281 // using the current time on main thread.
282 animation->setStartTime(m_startTime);
283
284 int animationId = animation->id();
285 int animationGroupId = animation->group();
286
287 sentToCompositor = addAnimation(animation.release());
288 if (sentToCompositor) {
289 m_runState = RunState::RunningOnCompositor;
290 m_compositorAnimationId = animationId;
291 m_compositorAnimationGroupId = animationGroupId;
292 }
293 }
294
295 bool runningOnMainThread = false; 307 bool runningOnMainThread = false;
308 bool sentToCompositor = sendAnimationToCompositor();
296 if (!sentToCompositor) { 309 if (!sentToCompositor) {
297 runningOnMainThread = registerAndScheduleAnimation(); 310 runningOnMainThread = registerAndScheduleAnimation();
298 if (runningOnMainThread) 311 if (runningOnMainThread)
299 m_runState = RunState::RunningOnMainThread; 312 m_runState = RunState::RunningOnMainThread;
300 } 313 }
301 314
302 // Main thread should deal with the scroll animations it started. 315 // Main thread should deal with the scroll animations it started.
303 if (sentToCompositor || runningOnMainThread) 316 if (sentToCompositor || runningOnMainThread)
304 addMainThreadScrollingReason(); 317 addMainThreadScrollingReason();
305 else 318 else
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
355 std::move(scrollOffsetAnimationCurve))); 368 std::move(scrollOffsetAnimationCurve)));
356 m_startTime = animationStartTime; 369 m_startTime = animationStartTime;
357 } 370 }
358 } 371 }
359 372
360 void ScrollAnimator::cancelAnimation() 373 void ScrollAnimator::cancelAnimation()
361 { 374 {
362 ScrollAnimatorCompositorCoordinator::cancelAnimation(); 375 ScrollAnimatorCompositorCoordinator::cancelAnimation();
363 } 376 }
364 377
378 void ScrollAnimator::takeoverCompositorAnimation()
379 {
380 if (m_runState == RunState::RunningOnCompositor
381 || m_runState == RunState::RunningOnCompositorButNeedsUpdate)
382 removeMainThreadScrollingReason();
383
384 ScrollAnimatorCompositorCoordinator::takeoverCompositorAnimation();
385 }
386
365 void ScrollAnimator::layerForCompositedScrollingDidChange( 387 void ScrollAnimator::layerForCompositedScrollingDidChange(
366 CompositorAnimationTimeline* timeline) 388 CompositorAnimationTimeline* timeline)
367 { 389 {
368 if (reattachCompositorPlayerIfNeeded(timeline) && m_animationCurve) 390 if (reattachCompositorPlayerIfNeeded(timeline) && m_animationCurve)
369 addMainThreadScrollingReason(); 391 addMainThreadScrollingReason();
370 } 392 }
371 393
372 bool ScrollAnimator::registerAndScheduleAnimation() 394 bool ScrollAnimator::registerAndScheduleAnimation()
373 { 395 {
374 scrollableArea()->registerForAnimation(); 396 scrollableArea()->registerForAnimation();
375 if (!m_scrollableArea->scheduleAnimation()) { 397 if (!m_scrollableArea->scheduleAnimation()) {
376 scrollToOffsetWithoutAnimation(m_targetOffset); 398 scrollToOffsetWithoutAnimation(m_targetOffset);
377 resetAnimationState(); 399 resetAnimationState();
378 return false; 400 return false;
379 } 401 }
380 return true; 402 return true;
381 } 403 }
382 404
383 DEFINE_TRACE(ScrollAnimator) 405 DEFINE_TRACE(ScrollAnimator)
384 { 406 {
385 ScrollAnimatorBase::trace(visitor); 407 ScrollAnimatorBase::trace(visitor);
386 } 408 }
387 409
388 } // namespace blink 410 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698