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

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

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

Powered by Google App Engine
This is Rietveld 408576698