OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "cc/animation/layer_animation_controller.h" | 5 #include "cc/animation/layer_animation_controller.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <vector> | 10 #include <vector> |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
59 bool was_potentially_animating_transform_for_active_observers = | 59 bool was_potentially_animating_transform_for_active_observers = |
60 potentially_animating_transform_for_active_observers_; | 60 potentially_animating_transform_for_active_observers_; |
61 bool was_potentially_animating_transform_for_pending_observers = | 61 bool was_potentially_animating_transform_for_pending_observers = |
62 potentially_animating_transform_for_pending_observers_; | 62 potentially_animating_transform_for_pending_observers_; |
63 | 63 |
64 potentially_animating_transform_for_active_observers_ = false; | 64 potentially_animating_transform_for_active_observers_ = false; |
65 potentially_animating_transform_for_pending_observers_ = false; | 65 potentially_animating_transform_for_pending_observers_ = false; |
66 | 66 |
67 for (const auto& animation : animations_) { | 67 for (const auto& animation : animations_) { |
68 if (!animation->is_finished() && | 68 if (!animation->is_finished() && |
69 animation->target_property() == Animation::TRANSFORM) { | 69 animation->target_property() == TargetProperty::TRANSFORM) { |
70 potentially_animating_transform_for_active_observers_ |= | 70 potentially_animating_transform_for_active_observers_ |= |
71 animation->affects_active_observers(); | 71 animation->affects_active_observers(); |
72 potentially_animating_transform_for_pending_observers_ |= | 72 potentially_animating_transform_for_pending_observers_ |= |
73 animation->affects_pending_observers(); | 73 animation->affects_pending_observers(); |
74 } | 74 } |
75 } | 75 } |
76 | 76 |
77 bool changed_for_active_observers = | 77 bool changed_for_active_observers = |
78 was_potentially_animating_transform_for_active_observers != | 78 was_potentially_animating_transform_for_active_observers != |
79 potentially_animating_transform_for_active_observers_; | 79 potentially_animating_transform_for_active_observers_; |
(...skipping 12 matching lines...) Expand all Loading... |
92 bool removed_transform_animation = false; | 92 bool removed_transform_animation = false; |
93 // Since we want to use the animations that we're going to remove, we need to | 93 // Since we want to use the animations that we're going to remove, we need to |
94 // use a stable_parition here instead of remove_if. Remove_if leaves the | 94 // use a stable_parition here instead of remove_if. Remove_if leaves the |
95 // removed items in an unspecified state. | 95 // removed items in an unspecified state. |
96 auto animations_to_remove = std::stable_partition( | 96 auto animations_to_remove = std::stable_partition( |
97 animations_.begin(), animations_.end(), | 97 animations_.begin(), animations_.end(), |
98 [animation_id](const scoped_ptr<Animation>& animation) { | 98 [animation_id](const scoped_ptr<Animation>& animation) { |
99 return animation->id() != animation_id; | 99 return animation->id() != animation_id; |
100 }); | 100 }); |
101 for (auto it = animations_to_remove; it != animations_.end(); ++it) { | 101 for (auto it = animations_to_remove; it != animations_.end(); ++it) { |
102 if ((*it)->target_property() == Animation::SCROLL_OFFSET) { | 102 if ((*it)->target_property() == TargetProperty::SCROLL_OFFSET) { |
103 scroll_offset_animation_was_interrupted_ = true; | 103 scroll_offset_animation_was_interrupted_ = true; |
104 } else if ((*it)->target_property() == Animation::TRANSFORM && | 104 } else if ((*it)->target_property() == TargetProperty::TRANSFORM && |
105 !(*it)->is_finished()) { | 105 !(*it)->is_finished()) { |
106 removed_transform_animation = true; | 106 removed_transform_animation = true; |
107 } | 107 } |
108 } | 108 } |
109 | 109 |
110 animations_.erase(animations_to_remove, animations_.end()); | 110 animations_.erase(animations_to_remove, animations_.end()); |
111 UpdateActivation(NORMAL_ACTIVATION); | 111 UpdateActivation(NORMAL_ACTIVATION); |
112 if (removed_transform_animation) | 112 if (removed_transform_animation) |
113 UpdatePotentiallyAnimatingTransform(); | 113 UpdatePotentiallyAnimatingTransform(); |
114 } | 114 } |
115 | 115 |
116 void LayerAnimationController::AbortAnimation(int animation_id) { | 116 void LayerAnimationController::AbortAnimation(int animation_id) { |
117 bool aborted_transform_animation = false; | 117 bool aborted_transform_animation = false; |
118 if (Animation* animation = GetAnimationById(animation_id)) { | 118 if (Animation* animation = GetAnimationById(animation_id)) { |
119 if (!animation->is_finished()) { | 119 if (!animation->is_finished()) { |
120 animation->SetRunState(Animation::ABORTED, last_tick_time_); | 120 animation->SetRunState(Animation::ABORTED, last_tick_time_); |
121 if (animation->target_property() == Animation::TRANSFORM) | 121 if (animation->target_property() == TargetProperty::TRANSFORM) |
122 aborted_transform_animation = true; | 122 aborted_transform_animation = true; |
123 } | 123 } |
124 } | 124 } |
125 if (aborted_transform_animation) | 125 if (aborted_transform_animation) |
126 UpdatePotentiallyAnimatingTransform(); | 126 UpdatePotentiallyAnimatingTransform(); |
127 } | 127 } |
128 | 128 |
129 void LayerAnimationController::AbortAnimations( | 129 void LayerAnimationController::AbortAnimations( |
130 Animation::TargetProperty target_property) { | 130 TargetProperty::Type target_property) { |
131 bool aborted_transform_animation = false; | 131 bool aborted_transform_animation = false; |
132 for (size_t i = 0; i < animations_.size(); ++i) { | 132 for (size_t i = 0; i < animations_.size(); ++i) { |
133 if (animations_[i]->target_property() == target_property && | 133 if (animations_[i]->target_property() == target_property && |
134 !animations_[i]->is_finished()) { | 134 !animations_[i]->is_finished()) { |
135 animations_[i]->SetRunState(Animation::ABORTED, last_tick_time_); | 135 animations_[i]->SetRunState(Animation::ABORTED, last_tick_time_); |
136 if (target_property == Animation::TRANSFORM) | 136 if (target_property == TargetProperty::TRANSFORM) |
137 aborted_transform_animation = true; | 137 aborted_transform_animation = true; |
138 } | 138 } |
139 } | 139 } |
140 if (aborted_transform_animation) | 140 if (aborted_transform_animation) |
141 UpdatePotentiallyAnimatingTransform(); | 141 UpdatePotentiallyAnimatingTransform(); |
142 } | 142 } |
143 | 143 |
144 // Ensures that the list of active animations on the main thread and the impl | 144 // Ensures that the list of active animations on the main thread and the impl |
145 // thread are kept in sync. | 145 // thread are kept in sync. |
146 void LayerAnimationController::PushAnimationUpdatesTo( | 146 void LayerAnimationController::PushAnimationUpdatesTo( |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 Animation* animation = animations_[i].get(); | 183 Animation* animation = animations_[i].get(); |
184 if (!animation->is_impl_only()) | 184 if (!animation->is_impl_only()) |
185 continue; | 185 continue; |
186 | 186 |
187 if (!animation->InEffect(monotonic_time)) | 187 if (!animation->InEffect(monotonic_time)) |
188 continue; | 188 continue; |
189 | 189 |
190 base::TimeDelta trimmed = | 190 base::TimeDelta trimmed = |
191 animation->TrimTimeToCurrentIteration(monotonic_time); | 191 animation->TrimTimeToCurrentIteration(monotonic_time); |
192 switch (animation->target_property()) { | 192 switch (animation->target_property()) { |
193 case Animation::OPACITY: { | 193 case TargetProperty::OPACITY: { |
194 AnimationEvent event(AnimationEvent::PROPERTY_UPDATE, id_, | 194 AnimationEvent event(AnimationEvent::PROPERTY_UPDATE, id_, |
195 animation->group(), Animation::OPACITY, | 195 animation->group(), TargetProperty::OPACITY, |
196 monotonic_time); | 196 monotonic_time); |
197 const FloatAnimationCurve* float_animation_curve = | 197 const FloatAnimationCurve* float_animation_curve = |
198 animation->curve()->ToFloatAnimationCurve(); | 198 animation->curve()->ToFloatAnimationCurve(); |
199 event.opacity = float_animation_curve->GetValue(trimmed); | 199 event.opacity = float_animation_curve->GetValue(trimmed); |
200 event.is_impl_only = true; | 200 event.is_impl_only = true; |
201 events->events_.push_back(event); | 201 events->events_.push_back(event); |
202 break; | 202 break; |
203 } | 203 } |
204 | 204 |
205 case Animation::TRANSFORM: { | 205 case TargetProperty::TRANSFORM: { |
206 AnimationEvent event(AnimationEvent::PROPERTY_UPDATE, id_, | 206 AnimationEvent event(AnimationEvent::PROPERTY_UPDATE, id_, |
207 animation->group(), Animation::TRANSFORM, | 207 animation->group(), TargetProperty::TRANSFORM, |
208 monotonic_time); | 208 monotonic_time); |
209 const TransformAnimationCurve* transform_animation_curve = | 209 const TransformAnimationCurve* transform_animation_curve = |
210 animation->curve()->ToTransformAnimationCurve(); | 210 animation->curve()->ToTransformAnimationCurve(); |
211 event.transform = transform_animation_curve->GetValue(trimmed); | 211 event.transform = transform_animation_curve->GetValue(trimmed); |
212 event.is_impl_only = true; | 212 event.is_impl_only = true; |
213 events->events_.push_back(event); | 213 events->events_.push_back(event); |
214 break; | 214 break; |
215 } | 215 } |
216 | 216 |
217 case Animation::FILTER: { | 217 case TargetProperty::FILTER: { |
218 AnimationEvent event(AnimationEvent::PROPERTY_UPDATE, id_, | 218 AnimationEvent event(AnimationEvent::PROPERTY_UPDATE, id_, |
219 animation->group(), Animation::FILTER, | 219 animation->group(), TargetProperty::FILTER, |
220 monotonic_time); | 220 monotonic_time); |
221 const FilterAnimationCurve* filter_animation_curve = | 221 const FilterAnimationCurve* filter_animation_curve = |
222 animation->curve()->ToFilterAnimationCurve(); | 222 animation->curve()->ToFilterAnimationCurve(); |
223 event.filters = filter_animation_curve->GetValue(trimmed); | 223 event.filters = filter_animation_curve->GetValue(trimmed); |
224 event.is_impl_only = true; | 224 event.is_impl_only = true; |
225 events->events_.push_back(event); | 225 events->events_.push_back(event); |
226 break; | 226 break; |
227 } | 227 } |
228 | 228 |
229 case Animation::BACKGROUND_COLOR: { | 229 case TargetProperty::BACKGROUND_COLOR: { |
230 break; | 230 break; |
231 } | 231 } |
232 | 232 |
233 case Animation::SCROLL_OFFSET: { | 233 case TargetProperty::SCROLL_OFFSET: { |
234 // Impl-side changes to scroll offset are already sent back to the | 234 // Impl-side changes to scroll offset are already sent back to the |
235 // main thread (e.g. for user-driven scrolling), so a PROPERTY_UPDATE | 235 // main thread (e.g. for user-driven scrolling), so a PROPERTY_UPDATE |
236 // isn't needed. | 236 // isn't needed. |
237 break; | 237 break; |
238 } | 238 } |
239 } | 239 } |
240 } | 240 } |
241 } | 241 } |
242 | 242 |
243 void LayerAnimationController::UpdateState(bool start_ready_animations, | 243 void LayerAnimationController::UpdateState(bool start_ready_animations, |
(...skipping 20 matching lines...) Expand all Loading... |
264 AccumulatePropertyUpdates(last_tick_time_, events); | 264 AccumulatePropertyUpdates(last_tick_time_, events); |
265 | 265 |
266 UpdateActivation(NORMAL_ACTIVATION); | 266 UpdateActivation(NORMAL_ACTIVATION); |
267 } | 267 } |
268 | 268 |
269 void LayerAnimationController::ActivateAnimations() { | 269 void LayerAnimationController::ActivateAnimations() { |
270 bool changed_transform_animation = false; | 270 bool changed_transform_animation = false; |
271 for (size_t i = 0; i < animations_.size(); ++i) { | 271 for (size_t i = 0; i < animations_.size(); ++i) { |
272 if (animations_[i]->affects_active_observers() != | 272 if (animations_[i]->affects_active_observers() != |
273 animations_[i]->affects_pending_observers() && | 273 animations_[i]->affects_pending_observers() && |
274 animations_[i]->target_property() == Animation::TRANSFORM) | 274 animations_[i]->target_property() == TargetProperty::TRANSFORM) |
275 changed_transform_animation = true; | 275 changed_transform_animation = true; |
276 animations_[i]->set_affects_active_observers( | 276 animations_[i]->set_affects_active_observers( |
277 animations_[i]->affects_pending_observers()); | 277 animations_[i]->affects_pending_observers()); |
278 } | 278 } |
279 auto affects_no_observers = [](const scoped_ptr<Animation>& animation) { | 279 auto affects_no_observers = [](const scoped_ptr<Animation>& animation) { |
280 return !animation->affects_active_observers() && | 280 return !animation->affects_active_observers() && |
281 !animation->affects_pending_observers(); | 281 !animation->affects_pending_observers(); |
282 }; | 282 }; |
283 animations_.erase(std::remove_if(animations_.begin(), animations_.end(), | 283 animations_.erase(std::remove_if(animations_.begin(), animations_.end(), |
284 affects_no_observers), | 284 affects_no_observers), |
285 animations_.end()); | 285 animations_.end()); |
286 scroll_offset_animation_was_interrupted_ = false; | 286 scroll_offset_animation_was_interrupted_ = false; |
287 UpdateActivation(NORMAL_ACTIVATION); | 287 UpdateActivation(NORMAL_ACTIVATION); |
288 if (changed_transform_animation) | 288 if (changed_transform_animation) |
289 UpdatePotentiallyAnimatingTransform(); | 289 UpdatePotentiallyAnimatingTransform(); |
290 } | 290 } |
291 | 291 |
292 void LayerAnimationController::AddAnimation(scoped_ptr<Animation> animation) { | 292 void LayerAnimationController::AddAnimation(scoped_ptr<Animation> animation) { |
293 bool added_transform_animation = | 293 bool added_transform_animation = |
294 animation->target_property() == Animation::TRANSFORM; | 294 animation->target_property() == TargetProperty::TRANSFORM; |
295 animations_.push_back(std::move(animation)); | 295 animations_.push_back(std::move(animation)); |
296 needs_to_start_animations_ = true; | 296 needs_to_start_animations_ = true; |
297 UpdateActivation(NORMAL_ACTIVATION); | 297 UpdateActivation(NORMAL_ACTIVATION); |
298 if (added_transform_animation) | 298 if (added_transform_animation) |
299 UpdatePotentiallyAnimatingTransform(); | 299 UpdatePotentiallyAnimatingTransform(); |
300 } | 300 } |
301 | 301 |
302 Animation* LayerAnimationController::GetAnimation( | 302 Animation* LayerAnimationController::GetAnimation( |
303 Animation::TargetProperty target_property) const { | 303 TargetProperty::Type target_property) const { |
304 for (size_t i = 0; i < animations_.size(); ++i) { | 304 for (size_t i = 0; i < animations_.size(); ++i) { |
305 size_t index = animations_.size() - i - 1; | 305 size_t index = animations_.size() - i - 1; |
306 if (animations_[index]->target_property() == target_property) | 306 if (animations_[index]->target_property() == target_property) |
307 return animations_[index].get(); | 307 return animations_[index].get(); |
308 } | 308 } |
309 return nullptr; | 309 return nullptr; |
310 } | 310 } |
311 | 311 |
312 Animation* LayerAnimationController::GetAnimationById(int animation_id) const { | 312 Animation* LayerAnimationController::GetAnimationById(int animation_id) const { |
313 for (size_t i = 0; i < animations_.size(); ++i) | 313 for (size_t i = 0; i < animations_.size(); ++i) |
314 if (animations_[i]->id() == animation_id) | 314 if (animations_[i]->id() == animation_id) |
315 return animations_[i].get(); | 315 return animations_[i].get(); |
316 return nullptr; | 316 return nullptr; |
317 } | 317 } |
318 | 318 |
319 bool LayerAnimationController::HasActiveAnimation() const { | 319 bool LayerAnimationController::HasActiveAnimation() const { |
320 for (size_t i = 0; i < animations_.size(); ++i) { | 320 for (size_t i = 0; i < animations_.size(); ++i) { |
321 if (!animations_[i]->is_finished()) | 321 if (!animations_[i]->is_finished()) |
322 return true; | 322 return true; |
323 } | 323 } |
324 return false; | 324 return false; |
325 } | 325 } |
326 | 326 |
327 bool LayerAnimationController::IsPotentiallyAnimatingProperty( | 327 bool LayerAnimationController::IsPotentiallyAnimatingProperty( |
328 Animation::TargetProperty target_property, | 328 TargetProperty::Type target_property, |
329 ObserverType observer_type) const { | 329 ObserverType observer_type) const { |
330 for (size_t i = 0; i < animations_.size(); ++i) { | 330 for (size_t i = 0; i < animations_.size(); ++i) { |
331 if (!animations_[i]->is_finished() && | 331 if (!animations_[i]->is_finished() && |
332 animations_[i]->target_property() == target_property) { | 332 animations_[i]->target_property() == target_property) { |
333 if ((observer_type == ObserverType::ACTIVE && | 333 if ((observer_type == ObserverType::ACTIVE && |
334 animations_[i]->affects_active_observers()) || | 334 animations_[i]->affects_active_observers()) || |
335 (observer_type == ObserverType::PENDING && | 335 (observer_type == ObserverType::PENDING && |
336 animations_[i]->affects_pending_observers())) | 336 animations_[i]->affects_pending_observers())) |
337 return true; | 337 return true; |
338 } | 338 } |
339 } | 339 } |
340 return false; | 340 return false; |
341 } | 341 } |
342 | 342 |
343 bool LayerAnimationController::IsCurrentlyAnimatingProperty( | 343 bool LayerAnimationController::IsCurrentlyAnimatingProperty( |
344 Animation::TargetProperty target_property, | 344 TargetProperty::Type target_property, |
345 ObserverType observer_type) const { | 345 ObserverType observer_type) const { |
346 for (size_t i = 0; i < animations_.size(); ++i) { | 346 for (size_t i = 0; i < animations_.size(); ++i) { |
347 if (!animations_[i]->is_finished() && | 347 if (!animations_[i]->is_finished() && |
348 animations_[i]->InEffect(last_tick_time_) && | 348 animations_[i]->InEffect(last_tick_time_) && |
349 animations_[i]->target_property() == target_property) { | 349 animations_[i]->target_property() == target_property) { |
350 if ((observer_type == ObserverType::ACTIVE && | 350 if ((observer_type == ObserverType::ACTIVE && |
351 animations_[i]->affects_active_observers()) || | 351 animations_[i]->affects_active_observers()) || |
352 (observer_type == ObserverType::PENDING && | 352 (observer_type == ObserverType::PENDING && |
353 animations_[i]->affects_pending_observers())) | 353 animations_[i]->affects_pending_observers())) |
354 return true; | 354 return true; |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
428 const AnimationEvent& event) { | 428 const AnimationEvent& event) { |
429 bool aborted_transform_animation = false; | 429 bool aborted_transform_animation = false; |
430 for (size_t i = 0; i < animations_.size(); ++i) { | 430 for (size_t i = 0; i < animations_.size(); ++i) { |
431 if (animations_[i]->group() == event.group_id && | 431 if (animations_[i]->group() == event.group_id && |
432 animations_[i]->target_property() == event.target_property) { | 432 animations_[i]->target_property() == event.target_property) { |
433 animations_[i]->SetRunState(Animation::ABORTED, event.monotonic_time); | 433 animations_[i]->SetRunState(Animation::ABORTED, event.monotonic_time); |
434 animations_[i]->set_received_finished_event(true); | 434 animations_[i]->set_received_finished_event(true); |
435 if (layer_animation_delegate_) | 435 if (layer_animation_delegate_) |
436 layer_animation_delegate_->NotifyAnimationAborted( | 436 layer_animation_delegate_->NotifyAnimationAborted( |
437 event.monotonic_time, event.target_property, event.group_id); | 437 event.monotonic_time, event.target_property, event.group_id); |
438 if (event.target_property == Animation::TRANSFORM) | 438 if (event.target_property == TargetProperty::TRANSFORM) |
439 aborted_transform_animation = true; | 439 aborted_transform_animation = true; |
440 } | 440 } |
441 } | 441 } |
442 if (aborted_transform_animation) | 442 if (aborted_transform_animation) |
443 UpdatePotentiallyAnimatingTransform(); | 443 UpdatePotentiallyAnimatingTransform(); |
444 } | 444 } |
445 | 445 |
446 void LayerAnimationController::NotifyAnimationPropertyUpdate( | 446 void LayerAnimationController::NotifyAnimationPropertyUpdate( |
447 const AnimationEvent& event) { | 447 const AnimationEvent& event) { |
448 bool notify_active_observers = true; | 448 bool notify_active_observers = true; |
449 bool notify_pending_observers = true; | 449 bool notify_pending_observers = true; |
450 switch (event.target_property) { | 450 switch (event.target_property) { |
451 case Animation::OPACITY: | 451 case TargetProperty::OPACITY: |
452 NotifyObserversOpacityAnimated( | 452 NotifyObserversOpacityAnimated( |
453 event.opacity, notify_active_observers, notify_pending_observers); | 453 event.opacity, notify_active_observers, notify_pending_observers); |
454 break; | 454 break; |
455 case Animation::TRANSFORM: | 455 case TargetProperty::TRANSFORM: |
456 NotifyObserversTransformAnimated( | 456 NotifyObserversTransformAnimated( |
457 event.transform, notify_active_observers, notify_pending_observers); | 457 event.transform, notify_active_observers, notify_pending_observers); |
458 break; | 458 break; |
459 default: | 459 default: |
460 NOTREACHED(); | 460 NOTREACHED(); |
461 } | 461 } |
462 } | 462 } |
463 | 463 |
464 void LayerAnimationController::AddValueObserver( | 464 void LayerAnimationController::AddValueObserver( |
465 LayerAnimationValueObserver* observer) { | 465 LayerAnimationValueObserver* observer) { |
(...skipping 13 matching lines...) Expand all Loading... |
479 } | 479 } |
480 | 480 |
481 void LayerAnimationController::RemoveEventObserver( | 481 void LayerAnimationController::RemoveEventObserver( |
482 LayerAnimationEventObserver* observer) { | 482 LayerAnimationEventObserver* observer) { |
483 event_observers_.RemoveObserver(observer); | 483 event_observers_.RemoveObserver(observer); |
484 } | 484 } |
485 | 485 |
486 bool LayerAnimationController::HasFilterAnimationThatInflatesBounds() const { | 486 bool LayerAnimationController::HasFilterAnimationThatInflatesBounds() const { |
487 for (size_t i = 0; i < animations_.size(); ++i) { | 487 for (size_t i = 0; i < animations_.size(); ++i) { |
488 if (!animations_[i]->is_finished() && | 488 if (!animations_[i]->is_finished() && |
489 animations_[i]->target_property() == Animation::FILTER && | 489 animations_[i]->target_property() == TargetProperty::FILTER && |
490 animations_[i] | 490 animations_[i] |
491 ->curve() | 491 ->curve() |
492 ->ToFilterAnimationCurve() | 492 ->ToFilterAnimationCurve() |
493 ->HasFilterThatMovesPixels()) | 493 ->HasFilterThatMovesPixels()) |
494 return true; | 494 return true; |
495 } | 495 } |
496 | 496 |
497 return false; | 497 return false; |
498 } | 498 } |
499 | 499 |
500 bool LayerAnimationController::HasTransformAnimationThatInflatesBounds() const { | 500 bool LayerAnimationController::HasTransformAnimationThatInflatesBounds() const { |
501 return IsCurrentlyAnimatingProperty(Animation::TRANSFORM, | 501 return IsCurrentlyAnimatingProperty(TargetProperty::TRANSFORM, |
502 ObserverType::ACTIVE) || | 502 ObserverType::ACTIVE) || |
503 IsCurrentlyAnimatingProperty(Animation::TRANSFORM, | 503 IsCurrentlyAnimatingProperty(TargetProperty::TRANSFORM, |
504 ObserverType::PENDING); | 504 ObserverType::PENDING); |
505 } | 505 } |
506 | 506 |
507 bool LayerAnimationController::FilterAnimationBoundsForBox( | 507 bool LayerAnimationController::FilterAnimationBoundsForBox( |
508 const gfx::BoxF& box, gfx::BoxF* bounds) const { | 508 const gfx::BoxF& box, gfx::BoxF* bounds) const { |
509 // TODO(avallee): Implement. | 509 // TODO(avallee): Implement. |
510 return false; | 510 return false; |
511 } | 511 } |
512 | 512 |
513 bool LayerAnimationController::TransformAnimationBoundsForBox( | 513 bool LayerAnimationController::TransformAnimationBoundsForBox( |
514 const gfx::BoxF& box, | 514 const gfx::BoxF& box, |
515 gfx::BoxF* bounds) const { | 515 gfx::BoxF* bounds) const { |
516 DCHECK(HasTransformAnimationThatInflatesBounds()) | 516 DCHECK(HasTransformAnimationThatInflatesBounds()) |
517 << "TransformAnimationBoundsForBox will give incorrect results if there " | 517 << "TransformAnimationBoundsForBox will give incorrect results if there " |
518 << "are no transform animations affecting bounds, non-animated transform " | 518 << "are no transform animations affecting bounds, non-animated transform " |
519 << "is not known"; | 519 << "is not known"; |
520 | 520 |
521 // Compute bounds based on animations for which is_finished() is false. | 521 // Compute bounds based on animations for which is_finished() is false. |
522 // Do nothing if there are no such animations; in this case, it is assumed | 522 // Do nothing if there are no such animations; in this case, it is assumed |
523 // that callers will take care of computing bounds based on the owning layer's | 523 // that callers will take care of computing bounds based on the owning layer's |
524 // actual transform. | 524 // actual transform. |
525 *bounds = gfx::BoxF(); | 525 *bounds = gfx::BoxF(); |
526 for (size_t i = 0; i < animations_.size(); ++i) { | 526 for (size_t i = 0; i < animations_.size(); ++i) { |
527 if (animations_[i]->is_finished() || | 527 if (animations_[i]->is_finished() || |
528 animations_[i]->target_property() != Animation::TRANSFORM) | 528 animations_[i]->target_property() != TargetProperty::TRANSFORM) |
529 continue; | 529 continue; |
530 | 530 |
531 const TransformAnimationCurve* transform_animation_curve = | 531 const TransformAnimationCurve* transform_animation_curve = |
532 animations_[i]->curve()->ToTransformAnimationCurve(); | 532 animations_[i]->curve()->ToTransformAnimationCurve(); |
533 gfx::BoxF animation_bounds; | 533 gfx::BoxF animation_bounds; |
534 bool success = | 534 bool success = |
535 transform_animation_curve->AnimatedBoundsForBox(box, &animation_bounds); | 535 transform_animation_curve->AnimatedBoundsForBox(box, &animation_bounds); |
536 if (!success) | 536 if (!success) |
537 return false; | 537 return false; |
538 bounds->Union(animation_bounds); | 538 bounds->Union(animation_bounds); |
539 } | 539 } |
540 | 540 |
541 return true; | 541 return true; |
542 } | 542 } |
543 | 543 |
544 bool LayerAnimationController::HasAnimationThatAffectsScale() const { | 544 bool LayerAnimationController::HasAnimationThatAffectsScale() const { |
545 for (size_t i = 0; i < animations_.size(); ++i) { | 545 for (size_t i = 0; i < animations_.size(); ++i) { |
546 if (animations_[i]->is_finished() || | 546 if (animations_[i]->is_finished() || |
547 animations_[i]->target_property() != Animation::TRANSFORM) | 547 animations_[i]->target_property() != TargetProperty::TRANSFORM) |
548 continue; | 548 continue; |
549 | 549 |
550 const TransformAnimationCurve* transform_animation_curve = | 550 const TransformAnimationCurve* transform_animation_curve = |
551 animations_[i]->curve()->ToTransformAnimationCurve(); | 551 animations_[i]->curve()->ToTransformAnimationCurve(); |
552 if (transform_animation_curve->AffectsScale()) | 552 if (transform_animation_curve->AffectsScale()) |
553 return true; | 553 return true; |
554 } | 554 } |
555 | 555 |
556 return false; | 556 return false; |
557 } | 557 } |
558 | 558 |
559 bool LayerAnimationController::HasOnlyTranslationTransforms( | 559 bool LayerAnimationController::HasOnlyTranslationTransforms( |
560 ObserverType observer_type) const { | 560 ObserverType observer_type) const { |
561 for (size_t i = 0; i < animations_.size(); ++i) { | 561 for (size_t i = 0; i < animations_.size(); ++i) { |
562 if (animations_[i]->is_finished() || | 562 if (animations_[i]->is_finished() || |
563 animations_[i]->target_property() != Animation::TRANSFORM) | 563 animations_[i]->target_property() != TargetProperty::TRANSFORM) |
564 continue; | 564 continue; |
565 | 565 |
566 if ((observer_type == ObserverType::ACTIVE && | 566 if ((observer_type == ObserverType::ACTIVE && |
567 !animations_[i]->affects_active_observers()) || | 567 !animations_[i]->affects_active_observers()) || |
568 (observer_type == ObserverType::PENDING && | 568 (observer_type == ObserverType::PENDING && |
569 !animations_[i]->affects_pending_observers())) | 569 !animations_[i]->affects_pending_observers())) |
570 continue; | 570 continue; |
571 | 571 |
572 const TransformAnimationCurve* transform_animation_curve = | 572 const TransformAnimationCurve* transform_animation_curve = |
573 animations_[i]->curve()->ToTransformAnimationCurve(); | 573 animations_[i]->curve()->ToTransformAnimationCurve(); |
574 if (!transform_animation_curve->IsTranslation()) | 574 if (!transform_animation_curve->IsTranslation()) |
575 return false; | 575 return false; |
576 } | 576 } |
577 | 577 |
578 return true; | 578 return true; |
579 } | 579 } |
580 | 580 |
581 bool LayerAnimationController::AnimationsPreserveAxisAlignment() const { | 581 bool LayerAnimationController::AnimationsPreserveAxisAlignment() const { |
582 for (size_t i = 0; i < animations_.size(); ++i) { | 582 for (size_t i = 0; i < animations_.size(); ++i) { |
583 if (animations_[i]->is_finished() || | 583 if (animations_[i]->is_finished() || |
584 animations_[i]->target_property() != Animation::TRANSFORM) | 584 animations_[i]->target_property() != TargetProperty::TRANSFORM) |
585 continue; | 585 continue; |
586 | 586 |
587 const TransformAnimationCurve* transform_animation_curve = | 587 const TransformAnimationCurve* transform_animation_curve = |
588 animations_[i]->curve()->ToTransformAnimationCurve(); | 588 animations_[i]->curve()->ToTransformAnimationCurve(); |
589 if (!transform_animation_curve->PreservesAxisAlignment()) | 589 if (!transform_animation_curve->PreservesAxisAlignment()) |
590 return false; | 590 return false; |
591 } | 591 } |
592 | 592 |
593 return true; | 593 return true; |
594 } | 594 } |
595 | 595 |
596 bool LayerAnimationController::AnimationStartScale(ObserverType observer_type, | 596 bool LayerAnimationController::AnimationStartScale(ObserverType observer_type, |
597 float* start_scale) const { | 597 float* start_scale) const { |
598 *start_scale = 0.f; | 598 *start_scale = 0.f; |
599 for (size_t i = 0; i < animations_.size(); ++i) { | 599 for (size_t i = 0; i < animations_.size(); ++i) { |
600 if (animations_[i]->is_finished() || | 600 if (animations_[i]->is_finished() || |
601 animations_[i]->target_property() != Animation::TRANSFORM) | 601 animations_[i]->target_property() != TargetProperty::TRANSFORM) |
602 continue; | 602 continue; |
603 | 603 |
604 if ((observer_type == ObserverType::ACTIVE && | 604 if ((observer_type == ObserverType::ACTIVE && |
605 !animations_[i]->affects_active_observers()) || | 605 !animations_[i]->affects_active_observers()) || |
606 (observer_type == ObserverType::PENDING && | 606 (observer_type == ObserverType::PENDING && |
607 !animations_[i]->affects_pending_observers())) | 607 !animations_[i]->affects_pending_observers())) |
608 continue; | 608 continue; |
609 | 609 |
610 bool forward_direction = true; | 610 bool forward_direction = true; |
611 switch (animations_[i]->direction()) { | 611 switch (animations_[i]->direction()) { |
(...skipping 16 matching lines...) Expand all Loading... |
628 *start_scale = std::max(*start_scale, animation_start_scale); | 628 *start_scale = std::max(*start_scale, animation_start_scale); |
629 } | 629 } |
630 return true; | 630 return true; |
631 } | 631 } |
632 | 632 |
633 bool LayerAnimationController::MaximumTargetScale(ObserverType observer_type, | 633 bool LayerAnimationController::MaximumTargetScale(ObserverType observer_type, |
634 float* max_scale) const { | 634 float* max_scale) const { |
635 *max_scale = 0.f; | 635 *max_scale = 0.f; |
636 for (size_t i = 0; i < animations_.size(); ++i) { | 636 for (size_t i = 0; i < animations_.size(); ++i) { |
637 if (animations_[i]->is_finished() || | 637 if (animations_[i]->is_finished() || |
638 animations_[i]->target_property() != Animation::TRANSFORM) | 638 animations_[i]->target_property() != TargetProperty::TRANSFORM) |
639 continue; | 639 continue; |
640 | 640 |
641 if ((observer_type == ObserverType::ACTIVE && | 641 if ((observer_type == ObserverType::ACTIVE && |
642 !animations_[i]->affects_active_observers()) || | 642 !animations_[i]->affects_active_observers()) || |
643 (observer_type == ObserverType::PENDING && | 643 (observer_type == ObserverType::PENDING && |
644 !animations_[i]->affects_pending_observers())) | 644 !animations_[i]->affects_pending_observers())) |
645 continue; | 645 continue; |
646 | 646 |
647 bool forward_direction = true; | 647 bool forward_direction = true; |
648 switch (animations_[i]->direction()) { | 648 switch (animations_[i]->direction()) { |
(...skipping 22 matching lines...) Expand all Loading... |
671 void LayerAnimationController::PushNewAnimationsToImplThread( | 671 void LayerAnimationController::PushNewAnimationsToImplThread( |
672 LayerAnimationController* controller_impl) const { | 672 LayerAnimationController* controller_impl) const { |
673 // Any new animations owned by the main thread's controller are cloned and | 673 // Any new animations owned by the main thread's controller are cloned and |
674 // add to the impl thread's controller. | 674 // add to the impl thread's controller. |
675 for (size_t i = 0; i < animations_.size(); ++i) { | 675 for (size_t i = 0; i < animations_.size(); ++i) { |
676 // If the animation is already running on the impl thread, there is no | 676 // If the animation is already running on the impl thread, there is no |
677 // need to copy it over. | 677 // need to copy it over. |
678 if (controller_impl->GetAnimationById(animations_[i]->id())) | 678 if (controller_impl->GetAnimationById(animations_[i]->id())) |
679 continue; | 679 continue; |
680 | 680 |
681 if (animations_[i]->target_property() == Animation::SCROLL_OFFSET && | 681 if (animations_[i]->target_property() == TargetProperty::SCROLL_OFFSET && |
682 !animations_[i] | 682 !animations_[i] |
683 ->curve() | 683 ->curve() |
684 ->ToScrollOffsetAnimationCurve() | 684 ->ToScrollOffsetAnimationCurve() |
685 ->HasSetInitialValue()) { | 685 ->HasSetInitialValue()) { |
686 gfx::ScrollOffset current_scroll_offset; | 686 gfx::ScrollOffset current_scroll_offset; |
687 if (controller_impl->value_provider_) { | 687 if (controller_impl->value_provider_) { |
688 current_scroll_offset = | 688 current_scroll_offset = |
689 controller_impl->value_provider_->ScrollOffsetForAnimation(); | 689 controller_impl->value_provider_->ScrollOffsetForAnimation(); |
690 } else { | 690 } else { |
691 // The owning layer isn't yet in the active tree, so the main thread | 691 // The owning layer isn't yet in the active tree, so the main thread |
(...skipping 29 matching lines...) Expand all Loading... |
721 LayerAnimationController* controller_impl) const { | 721 LayerAnimationController* controller_impl) const { |
722 bool removed_transform_animation = false; | 722 bool removed_transform_animation = false; |
723 // Animations removed on the main thread should no longer affect pending | 723 // Animations removed on the main thread should no longer affect pending |
724 // observers, and should stop affecting active observers after the next call | 724 // observers, and should stop affecting active observers after the next call |
725 // to ActivateAnimations. If already WAITING_FOR_DELETION, they can be removed | 725 // to ActivateAnimations. If already WAITING_FOR_DELETION, they can be removed |
726 // immediately. | 726 // immediately. |
727 auto& animations = controller_impl->animations_; | 727 auto& animations = controller_impl->animations_; |
728 for (const auto& animation : animations) { | 728 for (const auto& animation : animations) { |
729 if (IsCompleted(animation.get(), this)) { | 729 if (IsCompleted(animation.get(), this)) { |
730 animation->set_affects_pending_observers(false); | 730 animation->set_affects_pending_observers(false); |
731 if (animation->target_property() == Animation::TRANSFORM) | 731 if (animation->target_property() == TargetProperty::TRANSFORM) |
732 removed_transform_animation = true; | 732 removed_transform_animation = true; |
733 } | 733 } |
734 } | 734 } |
735 auto affects_active_only_and_is_waiting_for_deletion = []( | 735 auto affects_active_only_and_is_waiting_for_deletion = []( |
736 const scoped_ptr<Animation>& animation) { | 736 const scoped_ptr<Animation>& animation) { |
737 return animation->run_state() == Animation::WAITING_FOR_DELETION && | 737 return animation->run_state() == Animation::WAITING_FOR_DELETION && |
738 !animation->affects_pending_observers(); | 738 !animation->affects_pending_observers(); |
739 }; | 739 }; |
740 animations.erase( | 740 animations.erase( |
741 std::remove_if(animations.begin(), animations.end(), | 741 std::remove_if(animations.begin(), animations.end(), |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
877 } | 877 } |
878 } | 878 } |
879 | 879 |
880 void LayerAnimationController::MarkFinishedAnimations( | 880 void LayerAnimationController::MarkFinishedAnimations( |
881 base::TimeTicks monotonic_time) { | 881 base::TimeTicks monotonic_time) { |
882 bool finished_transform_animation = false; | 882 bool finished_transform_animation = false; |
883 for (size_t i = 0; i < animations_.size(); ++i) { | 883 for (size_t i = 0; i < animations_.size(); ++i) { |
884 if (!animations_[i]->is_finished() && | 884 if (!animations_[i]->is_finished() && |
885 animations_[i]->IsFinishedAt(monotonic_time)) { | 885 animations_[i]->IsFinishedAt(monotonic_time)) { |
886 animations_[i]->SetRunState(Animation::FINISHED, monotonic_time); | 886 animations_[i]->SetRunState(Animation::FINISHED, monotonic_time); |
887 if (animations_[i]->target_property() == Animation::TRANSFORM) { | 887 if (animations_[i]->target_property() == TargetProperty::TRANSFORM) { |
888 finished_transform_animation = true; | 888 finished_transform_animation = true; |
889 } | 889 } |
890 } | 890 } |
891 } | 891 } |
892 if (finished_transform_animation) | 892 if (finished_transform_animation) |
893 UpdatePotentiallyAnimatingTransform(); | 893 UpdatePotentiallyAnimatingTransform(); |
894 } | 894 } |
895 | 895 |
896 void LayerAnimationController::MarkAnimationsForDeletion( | 896 void LayerAnimationController::MarkAnimationsForDeletion( |
897 base::TimeTicks monotonic_time, | 897 base::TimeTicks monotonic_time, |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
999 auto& animations_impl = controller_impl->animations_; | 999 auto& animations_impl = controller_impl->animations_; |
1000 for (const auto& animation_impl : animations_impl) { | 1000 for (const auto& animation_impl : animations_impl) { |
1001 // If the animation has been aborted on the main thread, mark it for | 1001 // If the animation has been aborted on the main thread, mark it for |
1002 // deletion. | 1002 // deletion. |
1003 if (Animation* animation = GetAnimationById(animation_impl->id())) { | 1003 if (Animation* animation = GetAnimationById(animation_impl->id())) { |
1004 if (animation->run_state() == Animation::ABORTED) { | 1004 if (animation->run_state() == Animation::ABORTED) { |
1005 animation_impl->SetRunState(Animation::WAITING_FOR_DELETION, | 1005 animation_impl->SetRunState(Animation::WAITING_FOR_DELETION, |
1006 controller_impl->last_tick_time_); | 1006 controller_impl->last_tick_time_); |
1007 animation->SetRunState(Animation::WAITING_FOR_DELETION, | 1007 animation->SetRunState(Animation::WAITING_FOR_DELETION, |
1008 last_tick_time_); | 1008 last_tick_time_); |
1009 if (animation_impl->target_property() == Animation::TRANSFORM) { | 1009 if (animation_impl->target_property() == TargetProperty::TRANSFORM) { |
1010 aborted_transform_animation = true; | 1010 aborted_transform_animation = true; |
1011 } | 1011 } |
1012 } | 1012 } |
1013 } | 1013 } |
1014 } | 1014 } |
1015 | 1015 |
1016 if (aborted_transform_animation) | 1016 if (aborted_transform_animation) |
1017 controller_impl->UpdatePotentiallyAnimatingTransform(); | 1017 controller_impl->UpdatePotentiallyAnimatingTransform(); |
1018 } | 1018 } |
1019 | 1019 |
(...skipping 11 matching lines...) Expand all Loading... |
1031 if (animations_[i]->run_state() == Animation::STARTING || | 1031 if (animations_[i]->run_state() == Animation::STARTING || |
1032 animations_[i]->run_state() == Animation::RUNNING || | 1032 animations_[i]->run_state() == Animation::RUNNING || |
1033 animations_[i]->run_state() == Animation::PAUSED) { | 1033 animations_[i]->run_state() == Animation::PAUSED) { |
1034 if (!animations_[i]->InEffect(monotonic_time)) | 1034 if (!animations_[i]->InEffect(monotonic_time)) |
1035 continue; | 1035 continue; |
1036 | 1036 |
1037 base::TimeDelta trimmed = | 1037 base::TimeDelta trimmed = |
1038 animations_[i]->TrimTimeToCurrentIteration(monotonic_time); | 1038 animations_[i]->TrimTimeToCurrentIteration(monotonic_time); |
1039 | 1039 |
1040 switch (animations_[i]->target_property()) { | 1040 switch (animations_[i]->target_property()) { |
1041 case Animation::TRANSFORM: { | 1041 case TargetProperty::TRANSFORM: { |
1042 const TransformAnimationCurve* transform_animation_curve = | 1042 const TransformAnimationCurve* transform_animation_curve = |
1043 animations_[i]->curve()->ToTransformAnimationCurve(); | 1043 animations_[i]->curve()->ToTransformAnimationCurve(); |
1044 const gfx::Transform transform = | 1044 const gfx::Transform transform = |
1045 transform_animation_curve->GetValue(trimmed); | 1045 transform_animation_curve->GetValue(trimmed); |
1046 NotifyObserversTransformAnimated( | 1046 NotifyObserversTransformAnimated( |
1047 transform, | 1047 transform, |
1048 animations_[i]->affects_active_observers(), | 1048 animations_[i]->affects_active_observers(), |
1049 animations_[i]->affects_pending_observers()); | 1049 animations_[i]->affects_pending_observers()); |
1050 break; | 1050 break; |
1051 } | 1051 } |
1052 | 1052 |
1053 case Animation::OPACITY: { | 1053 case TargetProperty::OPACITY: { |
1054 const FloatAnimationCurve* float_animation_curve = | 1054 const FloatAnimationCurve* float_animation_curve = |
1055 animations_[i]->curve()->ToFloatAnimationCurve(); | 1055 animations_[i]->curve()->ToFloatAnimationCurve(); |
1056 const float opacity = std::max( | 1056 const float opacity = std::max( |
1057 std::min(float_animation_curve->GetValue(trimmed), 1.0f), 0.f); | 1057 std::min(float_animation_curve->GetValue(trimmed), 1.0f), 0.f); |
1058 NotifyObserversOpacityAnimated( | 1058 NotifyObserversOpacityAnimated( |
1059 opacity, | 1059 opacity, |
1060 animations_[i]->affects_active_observers(), | 1060 animations_[i]->affects_active_observers(), |
1061 animations_[i]->affects_pending_observers()); | 1061 animations_[i]->affects_pending_observers()); |
1062 break; | 1062 break; |
1063 } | 1063 } |
1064 | 1064 |
1065 case Animation::FILTER: { | 1065 case TargetProperty::FILTER: { |
1066 const FilterAnimationCurve* filter_animation_curve = | 1066 const FilterAnimationCurve* filter_animation_curve = |
1067 animations_[i]->curve()->ToFilterAnimationCurve(); | 1067 animations_[i]->curve()->ToFilterAnimationCurve(); |
1068 const FilterOperations filter = | 1068 const FilterOperations filter = |
1069 filter_animation_curve->GetValue(trimmed); | 1069 filter_animation_curve->GetValue(trimmed); |
1070 NotifyObserversFilterAnimated( | 1070 NotifyObserversFilterAnimated( |
1071 filter, | 1071 filter, |
1072 animations_[i]->affects_active_observers(), | 1072 animations_[i]->affects_active_observers(), |
1073 animations_[i]->affects_pending_observers()); | 1073 animations_[i]->affects_pending_observers()); |
1074 break; | 1074 break; |
1075 } | 1075 } |
1076 | 1076 |
1077 case Animation::BACKGROUND_COLOR: { | 1077 case TargetProperty::BACKGROUND_COLOR: { |
1078 // Not yet implemented. | 1078 // Not yet implemented. |
1079 break; | 1079 break; |
1080 } | 1080 } |
1081 | 1081 |
1082 case Animation::SCROLL_OFFSET: { | 1082 case TargetProperty::SCROLL_OFFSET: { |
1083 const ScrollOffsetAnimationCurve* scroll_offset_animation_curve = | 1083 const ScrollOffsetAnimationCurve* scroll_offset_animation_curve = |
1084 animations_[i]->curve()->ToScrollOffsetAnimationCurve(); | 1084 animations_[i]->curve()->ToScrollOffsetAnimationCurve(); |
1085 const gfx::ScrollOffset scroll_offset = | 1085 const gfx::ScrollOffset scroll_offset = |
1086 scroll_offset_animation_curve->GetValue(trimmed); | 1086 scroll_offset_animation_curve->GetValue(trimmed); |
1087 NotifyObserversScrollOffsetAnimated( | 1087 NotifyObserversScrollOffsetAnimated( |
1088 scroll_offset, | 1088 scroll_offset, |
1089 animations_[i]->affects_active_observers(), | 1089 animations_[i]->affects_active_observers(), |
1090 animations_[i]->affects_pending_observers()); | 1090 animations_[i]->affects_pending_observers()); |
1091 break; | 1091 break; |
1092 } | 1092 } |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1222 &value_observers_); | 1222 &value_observers_); |
1223 LayerAnimationValueObserver* obs; | 1223 LayerAnimationValueObserver* obs; |
1224 while ((obs = it.GetNext()) != nullptr) | 1224 while ((obs = it.GetNext()) != nullptr) |
1225 if (obs->IsActive()) | 1225 if (obs->IsActive()) |
1226 return true; | 1226 return true; |
1227 } | 1227 } |
1228 return false; | 1228 return false; |
1229 } | 1229 } |
1230 | 1230 |
1231 } // namespace cc | 1231 } // namespace cc |
OLD | NEW |