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 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 if (m_runState == RunState::RunningOnCompositor |
| 151 || m_runState == RunState::RunningOnCompositorButNeedsUpdate) { |
| 152 if (registerAndScheduleAnimation()) |
| 153 m_runState = RunState::RunningOnCompositorButNeedsUpdate; |
| 154 return true; |
| 155 } |
150 | 156 |
151 // Running on the main thread, simply update the target offset instead | 157 // Running on the main thread, simply update the target offset instead |
152 // of sending to the compositor. | 158 // of sending to the compositor. |
153 if (m_runState == RunState::RunningOnMainThread) { | 159 m_animationCurve->updateTarget(m_timeFunction() - m_startTime, targetPos
); |
154 m_animationCurve->updateTarget(m_timeFunction() - m_startTime, targe
tPos); | |
155 return true; | |
156 } | |
157 | |
158 if (registerAndScheduleAnimation()) | |
159 m_runState = RunState::RunningOnCompositorButNeedsUpdate; | |
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 Loading... |
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 | |
249 void ScrollAnimator::updateCompositorAnimations() | 219 void ScrollAnimator::updateCompositorAnimations() |
250 { | 220 { |
251 if (m_runState == RunState::PostAnimationCleanup) { | 221 if (m_runState == RunState::PostAnimationCleanup) { |
252 postAnimationCleanupAndReset(); | 222 postAnimationCleanupAndReset(); |
253 return; | 223 return; |
254 } | 224 } |
255 | 225 |
256 if (m_compositorAnimationId && m_runState != RunState::RunningOnCompositor | 226 if (m_compositorAnimationId && m_runState != RunState::RunningOnCompositor |
257 && m_runState != RunState::RunningOnCompositorButNeedsUpdate) { | 227 && m_runState != RunState::RunningOnCompositorButNeedsUpdate) { |
258 // If the current run state is WaitingToSendToCompositor but we have a | 228 // If the current run state is WaitingToSendToCompositor but we have a |
259 // non-zero compositor animation id, there's a currently running | 229 // non-zero compositor animation id, there's a currently running |
260 // compositor animation that needs to be removed here before the new | 230 // compositor animation that needs to be removed here before the new |
261 // animation is added below. | 231 // animation is added below. |
262 ASSERT(m_runState == RunState::WaitingToCancelOnCompositor | 232 ASSERT(m_runState == RunState::WaitingToCancelOnCompositor |
263 || m_runState == RunState::WaitingToSendToCompositor | 233 || m_runState == RunState::WaitingToSendToCompositor); |
264 || m_runState == RunState::RunningOnCompositorButNeedsTakeover); | |
265 | 234 |
266 if (m_runState == RunState::RunningOnCompositorButNeedsTakeover) { | 235 abortAnimation(); |
267 // The animation is already aborted when the call to | |
268 // ::takeoverCompositorAnimation is made. | |
269 m_runState = RunState::WaitingToSendToCompositor; | |
270 } else { | |
271 abortAnimation(); | |
272 } | |
273 | 236 |
274 m_compositorAnimationId = 0; | 237 m_compositorAnimationId = 0; |
275 m_compositorAnimationGroupId = 0; | 238 m_compositorAnimationGroupId = 0; |
276 if (m_runState == RunState::WaitingToCancelOnCompositor) { | 239 if (m_runState == RunState::WaitingToCancelOnCompositor) { |
277 postAnimationCleanupAndReset(); | 240 postAnimationCleanupAndReset(); |
278 return; | 241 return; |
279 } | 242 } |
280 } | 243 } |
281 | 244 |
282 if (m_runState == RunState::WaitingToSendToCompositor | 245 if (m_runState == RunState::WaitingToSendToCompositor |
(...skipping 14 matching lines...) Expand all Loading... |
297 if (!m_animationCurve) { | 260 if (!m_animationCurve) { |
298 m_animationCurve = adoptPtr(CompositorFactory::current().createScrol
lOffsetAnimationCurve( | 261 m_animationCurve = adoptPtr(CompositorFactory::current().createScrol
lOffsetAnimationCurve( |
299 m_targetOffset, | 262 m_targetOffset, |
300 CompositorAnimationCurve::TimingFunctionTypeEaseInOut, | 263 CompositorAnimationCurve::TimingFunctionTypeEaseInOut, |
301 m_lastGranularity == ScrollByPixel ? | 264 m_lastGranularity == ScrollByPixel ? |
302 CompositorScrollOffsetAnimationCurve::ScrollDurationInverseD
elta : | 265 CompositorScrollOffsetAnimationCurve::ScrollDurationInverseD
elta : |
303 CompositorScrollOffsetAnimationCurve::ScrollDurationConstant
)); | 266 CompositorScrollOffsetAnimationCurve::ScrollDurationConstant
)); |
304 m_animationCurve->setInitialValue(currentPosition()); | 267 m_animationCurve->setInitialValue(currentPosition()); |
305 } | 268 } |
306 | 269 |
| 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 |
307 bool runningOnMainThread = false; | 295 bool runningOnMainThread = false; |
308 bool sentToCompositor = sendAnimationToCompositor(); | |
309 if (!sentToCompositor) { | 296 if (!sentToCompositor) { |
310 runningOnMainThread = registerAndScheduleAnimation(); | 297 runningOnMainThread = registerAndScheduleAnimation(); |
311 if (runningOnMainThread) | 298 if (runningOnMainThread) |
312 m_runState = RunState::RunningOnMainThread; | 299 m_runState = RunState::RunningOnMainThread; |
313 } | 300 } |
314 | 301 |
315 // Main thread should deal with the scroll animations it started. | 302 // Main thread should deal with the scroll animations it started. |
316 if (sentToCompositor || runningOnMainThread) | 303 if (sentToCompositor || runningOnMainThread) |
317 addMainThreadScrollingReason(); | 304 addMainThreadScrollingReason(); |
318 else | 305 else |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
368 std::move(scrollOffsetAnimationCurve))); | 355 std::move(scrollOffsetAnimationCurve))); |
369 m_startTime = animationStartTime; | 356 m_startTime = animationStartTime; |
370 } | 357 } |
371 } | 358 } |
372 | 359 |
373 void ScrollAnimator::cancelAnimation() | 360 void ScrollAnimator::cancelAnimation() |
374 { | 361 { |
375 ScrollAnimatorCompositorCoordinator::cancelAnimation(); | 362 ScrollAnimatorCompositorCoordinator::cancelAnimation(); |
376 } | 363 } |
377 | 364 |
378 void ScrollAnimator::takeoverCompositorAnimation() | |
379 { | |
380 if (m_runState == RunState::RunningOnCompositor | |
381 || m_runState == RunState::RunningOnCompositorButNeedsUpdate) | |
382 removeMainThreadScrollingReason(); | |
383 | |
384 ScrollAnimatorCompositorCoordinator::takeoverCompositorAnimation(); | |
385 } | |
386 | |
387 void ScrollAnimator::layerForCompositedScrollingDidChange( | 365 void ScrollAnimator::layerForCompositedScrollingDidChange( |
388 CompositorAnimationTimeline* timeline) | 366 CompositorAnimationTimeline* timeline) |
389 { | 367 { |
390 if (reattachCompositorPlayerIfNeeded(timeline) && m_animationCurve) | 368 if (reattachCompositorPlayerIfNeeded(timeline) && m_animationCurve) |
391 addMainThreadScrollingReason(); | 369 addMainThreadScrollingReason(); |
392 } | 370 } |
393 | 371 |
394 bool ScrollAnimator::registerAndScheduleAnimation() | 372 bool ScrollAnimator::registerAndScheduleAnimation() |
395 { | 373 { |
396 scrollableArea()->registerForAnimation(); | 374 scrollableArea()->registerForAnimation(); |
397 if (!m_scrollableArea->scheduleAnimation()) { | 375 if (!m_scrollableArea->scheduleAnimation()) { |
398 scrollToOffsetWithoutAnimation(m_targetOffset); | 376 scrollToOffsetWithoutAnimation(m_targetOffset); |
399 resetAnimationState(); | 377 resetAnimationState(); |
400 return false; | 378 return false; |
401 } | 379 } |
402 return true; | 380 return true; |
403 } | 381 } |
404 | 382 |
405 DEFINE_TRACE(ScrollAnimator) | 383 DEFINE_TRACE(ScrollAnimator) |
406 { | 384 { |
407 ScrollAnimatorBase::trace(visitor); | 385 ScrollAnimatorBase::trace(visitor); |
408 } | 386 } |
409 | 387 |
410 } // namespace blink | 388 } // namespace blink |
OLD | NEW |