OLD | NEW |
---|---|
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 Loading... | |
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 Loading... | |
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 bool sentToCompositor = false; | |
218 if (!m_scrollableArea->shouldScrollOnMainThread()) { | |
jbroman
2016/03/07 18:38:40
super-nit: this might be a little easier to read w
ymalik
2016/03/07 21:26:06
Agreed. Done!
| |
219 OwnPtr<CompositorAnimation> animation = adoptPtr( | |
220 CompositorFactory::current().createAnimation( | |
221 *m_animationCurve, | |
222 CompositorTargetProperty::SCROLL_OFFSET)); | |
223 // Being here means that either there is an animation that needs | |
224 // to be sent to the compositor, or an animation that needs to | |
225 // be updated (a new scroll event before the previous animation | |
226 // is finished). In either case, the start time is when the | |
227 // first animation was initiated. This re-targets the animation | |
228 // using the current time on main thread. | |
229 animation->setStartTime(m_startTime); | |
230 | |
231 int animationId = animation->id(); | |
232 int animationGroupId = animation->group(); | |
233 | |
234 sentToCompositor = addAnimation(animation.release()); | |
235 if (sentToCompositor) { | |
236 m_runState = RunState::RunningOnCompositor; | |
237 m_compositorAnimationId = animationId; | |
238 m_compositorAnimationGroupId = animationGroupId; | |
239 } | |
240 } | |
241 return sentToCompositor; | |
242 } | |
243 | |
215 void ScrollAnimator::updateCompositorAnimations() | 244 void ScrollAnimator::updateCompositorAnimations() |
216 { | 245 { |
217 if (m_runState == RunState::PostAnimationCleanup) { | 246 if (m_runState == RunState::PostAnimationCleanup) { |
218 postAnimationCleanupAndReset(); | 247 postAnimationCleanupAndReset(); |
219 return; | 248 return; |
220 } | 249 } |
221 | 250 |
222 if (m_compositorAnimationId && m_runState != RunState::RunningOnCompositor | 251 if (m_compositorAnimationId && m_runState != RunState::RunningOnCompositor |
223 && m_runState != RunState::RunningOnCompositorButNeedsUpdate) { | 252 && m_runState != RunState::RunningOnCompositorButNeedsUpdate) { |
224 // If the current run state is WaitingToSendToCompositor but we have a | 253 // If the current run state is WaitingToSendToCompositor but we have a |
225 // non-zero compositor animation id, there's a currently running | 254 // non-zero compositor animation id, there's a currently running |
226 // compositor animation that needs to be removed here before the new | 255 // compositor animation that needs to be removed here before the new |
227 // animation is added below. | 256 // animation is added below. |
228 ASSERT(m_runState == RunState::WaitingToCancelOnCompositor | 257 ASSERT(m_runState == RunState::WaitingToCancelOnCompositor |
229 || m_runState == RunState::WaitingToSendToCompositor); | 258 || m_runState == RunState::WaitingToSendToCompositor |
259 || m_runState == RunState::RunningOnCompositorButNeedsTakeover); | |
230 | 260 |
231 abortAnimation(); | 261 if (m_runState == RunState::RunningOnCompositorButNeedsTakeover) { |
262 // The animation is already aborted when the call to | |
263 // ::takeoverCompositorAnimation is made. | |
264 m_runState = RunState::WaitingToSendToCompositor; | |
265 } else { | |
266 abortAnimation(); | |
267 } | |
232 | 268 |
233 m_compositorAnimationId = 0; | 269 m_compositorAnimationId = 0; |
234 m_compositorAnimationGroupId = 0; | 270 m_compositorAnimationGroupId = 0; |
235 if (m_runState == RunState::WaitingToCancelOnCompositor) { | 271 if (m_runState == RunState::WaitingToCancelOnCompositor) { |
236 postAnimationCleanupAndReset(); | 272 postAnimationCleanupAndReset(); |
237 return; | 273 return; |
238 } | 274 } |
239 } | 275 } |
240 | 276 |
241 if (m_runState == RunState::WaitingToSendToCompositor | 277 if (m_runState == RunState::WaitingToSendToCompositor |
(...skipping 14 matching lines...) Expand all Loading... | |
256 if (!m_animationCurve) { | 292 if (!m_animationCurve) { |
257 m_animationCurve = adoptPtr(CompositorFactory::current().createScrol lOffsetAnimationCurve( | 293 m_animationCurve = adoptPtr(CompositorFactory::current().createScrol lOffsetAnimationCurve( |
258 m_targetOffset, | 294 m_targetOffset, |
259 CompositorAnimationCurve::TimingFunctionTypeEaseInOut, | 295 CompositorAnimationCurve::TimingFunctionTypeEaseInOut, |
260 m_lastGranularity == ScrollByPixel ? | 296 m_lastGranularity == ScrollByPixel ? |
261 CompositorScrollOffsetAnimationCurve::ScrollDurationInverseD elta : | 297 CompositorScrollOffsetAnimationCurve::ScrollDurationInverseD elta : |
262 CompositorScrollOffsetAnimationCurve::ScrollDurationConstant )); | 298 CompositorScrollOffsetAnimationCurve::ScrollDurationConstant )); |
263 m_animationCurve->setInitialValue(currentPosition()); | 299 m_animationCurve->setInitialValue(currentPosition()); |
264 } | 300 } |
265 | 301 |
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; | 302 bool runningOnMainThread = false; |
303 bool sentToCompositor = sendAnimationToCompositor(); | |
292 if (!sentToCompositor) { | 304 if (!sentToCompositor) { |
293 runningOnMainThread = registerAndScheduleAnimation(); | 305 runningOnMainThread = registerAndScheduleAnimation(); |
294 if (runningOnMainThread) | 306 if (runningOnMainThread) |
295 m_runState = RunState::RunningOnMainThread; | 307 m_runState = RunState::RunningOnMainThread; |
296 } | 308 } |
297 | 309 |
298 // Main thread should deal with the scroll animations it started. | 310 // Main thread should deal with the scroll animations it started. |
299 if (sentToCompositor || runningOnMainThread) | 311 if (sentToCompositor || runningOnMainThread) |
300 addMainThreadScrollingReason(); | 312 addMainThreadScrollingReason(); |
301 else | 313 else |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
351 std::move(scrollOffsetAnimationCurve))); | 363 std::move(scrollOffsetAnimationCurve))); |
352 m_startTime = animationStartTime; | 364 m_startTime = animationStartTime; |
353 } | 365 } |
354 } | 366 } |
355 | 367 |
356 void ScrollAnimator::cancelAnimation() | 368 void ScrollAnimator::cancelAnimation() |
357 { | 369 { |
358 ScrollAnimatorCompositorCoordinator::cancelAnimation(); | 370 ScrollAnimatorCompositorCoordinator::cancelAnimation(); |
359 } | 371 } |
360 | 372 |
373 void ScrollAnimator::takeoverCompositorAnimation() | |
374 { | |
375 if (m_runState == RunState::RunningOnCompositor | |
376 || m_runState == RunState::RunningOnCompositorButNeedsUpdate) | |
377 removeMainThreadScrollingReason(); | |
378 | |
379 ScrollAnimatorCompositorCoordinator::takeoverCompositorAnimation(); | |
380 } | |
381 | |
361 void ScrollAnimator::layerForCompositedScrollingDidChange( | 382 void ScrollAnimator::layerForCompositedScrollingDidChange( |
362 CompositorAnimationTimeline* timeline) | 383 CompositorAnimationTimeline* timeline) |
363 { | 384 { |
364 if (reattachCompositorPlayerIfNeeded(timeline) && m_animationCurve) | 385 if (reattachCompositorPlayerIfNeeded(timeline) && m_animationCurve) |
365 addMainThreadScrollingReason(); | 386 addMainThreadScrollingReason(); |
366 } | 387 } |
367 | 388 |
368 bool ScrollAnimator::registerAndScheduleAnimation() | 389 bool ScrollAnimator::registerAndScheduleAnimation() |
369 { | 390 { |
370 scrollableArea()->registerForAnimation(); | 391 scrollableArea()->registerForAnimation(); |
371 if (!m_scrollableArea->scheduleAnimation()) { | 392 if (!m_scrollableArea->scheduleAnimation()) { |
372 scrollToOffsetWithoutAnimation(m_targetOffset); | 393 scrollToOffsetWithoutAnimation(m_targetOffset); |
373 resetAnimationState(); | 394 resetAnimationState(); |
374 return false; | 395 return false; |
375 } | 396 } |
376 return true; | 397 return true; |
377 } | 398 } |
378 | 399 |
379 DEFINE_TRACE(ScrollAnimator) | 400 DEFINE_TRACE(ScrollAnimator) |
380 { | 401 { |
381 ScrollAnimatorBase::trace(visitor); | 402 ScrollAnimatorBase::trace(visitor); |
382 } | 403 } |
383 | 404 |
384 } // namespace blink | 405 } // namespace blink |
OLD | NEW |