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