| 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 <algorithm> | 7 #include <algorithm> | 
| 8 #include <vector> | 8 #include <vector> | 
| 9 | 9 | 
| 10 #include "cc/animation/animation.h" | 10 #include "cc/animation/animation.h" | 
| (...skipping 27 matching lines...) Expand all  Loading... | 
| 38 | 38 | 
| 39 scoped_refptr<LayerAnimationController> LayerAnimationController::Create( | 39 scoped_refptr<LayerAnimationController> LayerAnimationController::Create( | 
| 40     int id) { | 40     int id) { | 
| 41   return make_scoped_refptr(new LayerAnimationController(id)); | 41   return make_scoped_refptr(new LayerAnimationController(id)); | 
| 42 } | 42 } | 
| 43 | 43 | 
| 44 void LayerAnimationController::PauseAnimation(int animation_id, | 44 void LayerAnimationController::PauseAnimation(int animation_id, | 
| 45                                               base::TimeDelta time_offset) { | 45                                               base::TimeDelta time_offset) { | 
| 46   for (size_t i = 0; i < animations_.size(); ++i) { | 46   for (size_t i = 0; i < animations_.size(); ++i) { | 
| 47     if (animations_[i]->id() == animation_id) { | 47     if (animations_[i]->id() == animation_id) { | 
| 48       animations_[i]->SetRunState(Animation::Paused, | 48       animations_[i]->SetRunState(Animation::PAUSED, | 
| 49                                   time_offset + animations_[i]->start_time()); | 49                                   time_offset + animations_[i]->start_time()); | 
| 50     } | 50     } | 
| 51   } | 51   } | 
| 52 } | 52 } | 
| 53 | 53 | 
| 54 struct HasAnimationId { | 54 struct HasAnimationId { | 
| 55   explicit HasAnimationId(int id) : id_(id) {} | 55   explicit HasAnimationId(int id) : id_(id) {} | 
| 56   bool operator()(Animation* animation) const { | 56   bool operator()(Animation* animation) const { | 
| 57     return animation->id() == id_; | 57     return animation->id() == id_; | 
| 58   } | 58   } | 
| 59 | 59 | 
| 60  private: | 60  private: | 
| 61   int id_; | 61   int id_; | 
| 62 }; | 62 }; | 
| 63 | 63 | 
| 64 void LayerAnimationController::RemoveAnimation(int animation_id) { | 64 void LayerAnimationController::RemoveAnimation(int animation_id) { | 
| 65   auto animations_to_remove = | 65   auto animations_to_remove = | 
| 66       animations_.remove_if(HasAnimationId(animation_id)); | 66       animations_.remove_if(HasAnimationId(animation_id)); | 
| 67   for (auto it = animations_to_remove; it != animations_.end(); ++it) { | 67   for (auto it = animations_to_remove; it != animations_.end(); ++it) { | 
| 68     if ((*it)->target_property() == Animation::ScrollOffset) { | 68     if ((*it)->target_property() == Animation::SCROLL_OFFSET) { | 
| 69       scroll_offset_animation_was_interrupted_ = true; | 69       scroll_offset_animation_was_interrupted_ = true; | 
| 70       break; | 70       break; | 
| 71     } | 71     } | 
| 72   } | 72   } | 
| 73   animations_.erase(animations_to_remove, animations_.end()); | 73   animations_.erase(animations_to_remove, animations_.end()); | 
| 74   UpdateActivation(NormalActivation); | 74   UpdateActivation(NORMAL_ACTIVATION); | 
| 75 } | 75 } | 
| 76 | 76 | 
| 77 struct HasAnimationIdAndProperty { | 77 struct HasAnimationIdAndProperty { | 
| 78   HasAnimationIdAndProperty(int id, Animation::TargetProperty target_property) | 78   HasAnimationIdAndProperty(int id, Animation::TargetProperty target_property) | 
| 79       : id_(id), target_property_(target_property) {} | 79       : id_(id), target_property_(target_property) {} | 
| 80   bool operator()(Animation* animation) const { | 80   bool operator()(Animation* animation) const { | 
| 81     return animation->id() == id_ && | 81     return animation->id() == id_ && | 
| 82         animation->target_property() == target_property_; | 82         animation->target_property() == target_property_; | 
| 83   } | 83   } | 
| 84 | 84 | 
| 85  private: | 85  private: | 
| 86   int id_; | 86   int id_; | 
| 87   Animation::TargetProperty target_property_; | 87   Animation::TargetProperty target_property_; | 
| 88 }; | 88 }; | 
| 89 | 89 | 
| 90 void LayerAnimationController::RemoveAnimation( | 90 void LayerAnimationController::RemoveAnimation( | 
| 91     int animation_id, | 91     int animation_id, | 
| 92     Animation::TargetProperty target_property) { | 92     Animation::TargetProperty target_property) { | 
| 93   auto animations_to_remove = animations_.remove_if( | 93   auto animations_to_remove = animations_.remove_if( | 
| 94       HasAnimationIdAndProperty(animation_id, target_property)); | 94       HasAnimationIdAndProperty(animation_id, target_property)); | 
| 95   if (target_property == Animation::ScrollOffset && | 95   if (target_property == Animation::SCROLL_OFFSET && | 
| 96       animations_to_remove != animations_.end()) | 96       animations_to_remove != animations_.end()) | 
| 97     scroll_offset_animation_was_interrupted_ = true; | 97     scroll_offset_animation_was_interrupted_ = true; | 
| 98 | 98 | 
| 99   animations_.erase(animations_to_remove, animations_.end()); | 99   animations_.erase(animations_to_remove, animations_.end()); | 
| 100   UpdateActivation(NormalActivation); | 100   UpdateActivation(NORMAL_ACTIVATION); | 
| 101 } | 101 } | 
| 102 | 102 | 
| 103 void LayerAnimationController::AbortAnimations( | 103 void LayerAnimationController::AbortAnimations( | 
| 104     Animation::TargetProperty target_property) { | 104     Animation::TargetProperty target_property) { | 
| 105   for (size_t i = 0; i < animations_.size(); ++i) { | 105   for (size_t i = 0; i < animations_.size(); ++i) { | 
| 106     if (animations_[i]->target_property() == target_property && | 106     if (animations_[i]->target_property() == target_property && | 
| 107         !animations_[i]->is_finished()) | 107         !animations_[i]->is_finished()) | 
| 108       animations_[i]->SetRunState(Animation::Aborted, last_tick_time_); | 108       animations_[i]->SetRunState(Animation::ABORTED, last_tick_time_); | 
| 109   } | 109   } | 
| 110 } | 110 } | 
| 111 | 111 | 
| 112 // Ensures that the list of active animations on the main thread and the impl | 112 // Ensures that the list of active animations on the main thread and the impl | 
| 113 // thread are kept in sync. | 113 // thread are kept in sync. | 
| 114 void LayerAnimationController::PushAnimationUpdatesTo( | 114 void LayerAnimationController::PushAnimationUpdatesTo( | 
| 115     LayerAnimationController* controller_impl) { | 115     LayerAnimationController* controller_impl) { | 
| 116   DCHECK(this != controller_impl); | 116   DCHECK(this != controller_impl); | 
| 117   if (!has_any_animation() && !controller_impl->has_any_animation()) | 117   if (!has_any_animation() && !controller_impl->has_any_animation()) | 
| 118     return; | 118     return; | 
| 119   PurgeAnimationsMarkedForDeletion(); | 119   PurgeAnimationsMarkedForDeletion(); | 
| 120   PushNewAnimationsToImplThread(controller_impl); | 120   PushNewAnimationsToImplThread(controller_impl); | 
| 121 | 121 | 
| 122   // Remove finished impl side animations only after pushing, | 122   // Remove finished impl side animations only after pushing, | 
| 123   // and only after the animations are deleted on the main thread | 123   // and only after the animations are deleted on the main thread | 
| 124   // this insures we will never push an animation twice. | 124   // this insures we will never push an animation twice. | 
| 125   RemoveAnimationsCompletedOnMainThread(controller_impl); | 125   RemoveAnimationsCompletedOnMainThread(controller_impl); | 
| 126 | 126 | 
| 127   PushPropertiesToImplThread(controller_impl); | 127   PushPropertiesToImplThread(controller_impl); | 
| 128   controller_impl->UpdateActivation(NormalActivation); | 128   controller_impl->UpdateActivation(NORMAL_ACTIVATION); | 
| 129   UpdateActivation(NormalActivation); | 129   UpdateActivation(NORMAL_ACTIVATION); | 
| 130 } | 130 } | 
| 131 | 131 | 
| 132 void LayerAnimationController::Animate(base::TimeTicks monotonic_time) { | 132 void LayerAnimationController::Animate(base::TimeTicks monotonic_time) { | 
| 133   DCHECK(!monotonic_time.is_null()); | 133   DCHECK(!monotonic_time.is_null()); | 
| 134   if (!HasValueObserver()) | 134   if (!HasValueObserver()) | 
| 135     return; | 135     return; | 
| 136 | 136 | 
| 137   if (needs_to_start_animations_) | 137   if (needs_to_start_animations_) | 
| 138     StartAnimations(monotonic_time); | 138     StartAnimations(monotonic_time); | 
| 139   TickAnimations(monotonic_time); | 139   TickAnimations(monotonic_time); | 
| (...skipping 10 matching lines...) Expand all  Loading... | 
| 150     Animation* animation = animations_[i]; | 150     Animation* animation = animations_[i]; | 
| 151     if (!animation->is_impl_only()) | 151     if (!animation->is_impl_only()) | 
| 152       continue; | 152       continue; | 
| 153 | 153 | 
| 154     if (!animation->InEffect(monotonic_time)) | 154     if (!animation->InEffect(monotonic_time)) | 
| 155       continue; | 155       continue; | 
| 156 | 156 | 
| 157     base::TimeDelta trimmed = | 157     base::TimeDelta trimmed = | 
| 158         animation->TrimTimeToCurrentIteration(monotonic_time); | 158         animation->TrimTimeToCurrentIteration(monotonic_time); | 
| 159     switch (animation->target_property()) { | 159     switch (animation->target_property()) { | 
| 160       case Animation::Opacity: { | 160       case Animation::OPACITY: { | 
| 161         AnimationEvent event(AnimationEvent::PropertyUpdate, | 161         AnimationEvent event(AnimationEvent::PROPERTY_UPDATE, id_, | 
| 162                              id_, | 162                              animation->group(), Animation::OPACITY, | 
| 163                              animation->group(), |  | 
| 164                              Animation::Opacity, |  | 
| 165                              monotonic_time); | 163                              monotonic_time); | 
| 166         const FloatAnimationCurve* float_animation_curve = | 164         const FloatAnimationCurve* float_animation_curve = | 
| 167             animation->curve()->ToFloatAnimationCurve(); | 165             animation->curve()->ToFloatAnimationCurve(); | 
| 168         event.opacity = float_animation_curve->GetValue(trimmed); | 166         event.opacity = float_animation_curve->GetValue(trimmed); | 
| 169         event.is_impl_only = true; | 167         event.is_impl_only = true; | 
| 170         events->push_back(event); | 168         events->push_back(event); | 
| 171         break; | 169         break; | 
| 172       } | 170       } | 
| 173 | 171 | 
| 174       case Animation::Transform: { | 172       case Animation::TRANSFORM: { | 
| 175         AnimationEvent event(AnimationEvent::PropertyUpdate, | 173         AnimationEvent event(AnimationEvent::PROPERTY_UPDATE, id_, | 
| 176                              id_, | 174                              animation->group(), Animation::TRANSFORM, | 
| 177                              animation->group(), |  | 
| 178                              Animation::Transform, |  | 
| 179                              monotonic_time); | 175                              monotonic_time); | 
| 180         const TransformAnimationCurve* transform_animation_curve = | 176         const TransformAnimationCurve* transform_animation_curve = | 
| 181             animation->curve()->ToTransformAnimationCurve(); | 177             animation->curve()->ToTransformAnimationCurve(); | 
| 182         event.transform = transform_animation_curve->GetValue(trimmed); | 178         event.transform = transform_animation_curve->GetValue(trimmed); | 
| 183         event.is_impl_only = true; | 179         event.is_impl_only = true; | 
| 184         events->push_back(event); | 180         events->push_back(event); | 
| 185         break; | 181         break; | 
| 186       } | 182       } | 
| 187 | 183 | 
| 188       case Animation::Filter: { | 184       case Animation::FILTER: { | 
| 189         AnimationEvent event(AnimationEvent::PropertyUpdate, | 185         AnimationEvent event(AnimationEvent::PROPERTY_UPDATE, id_, | 
| 190                              id_, | 186                              animation->group(), Animation::FILTER, | 
| 191                              animation->group(), |  | 
| 192                              Animation::Filter, |  | 
| 193                              monotonic_time); | 187                              monotonic_time); | 
| 194         const FilterAnimationCurve* filter_animation_curve = | 188         const FilterAnimationCurve* filter_animation_curve = | 
| 195             animation->curve()->ToFilterAnimationCurve(); | 189             animation->curve()->ToFilterAnimationCurve(); | 
| 196         event.filters = filter_animation_curve->GetValue(trimmed); | 190         event.filters = filter_animation_curve->GetValue(trimmed); | 
| 197         event.is_impl_only = true; | 191         event.is_impl_only = true; | 
| 198         events->push_back(event); | 192         events->push_back(event); | 
| 199         break; | 193         break; | 
| 200       } | 194       } | 
| 201 | 195 | 
| 202       case Animation::BackgroundColor: { break; } | 196       case Animation::BACKGROUND_COLOR: { | 
|  | 197         break; | 
|  | 198       } | 
| 203 | 199 | 
| 204       case Animation::ScrollOffset: { | 200       case Animation::SCROLL_OFFSET: { | 
| 205         // Impl-side changes to scroll offset are already sent back to the | 201         // Impl-side changes to scroll offset are already sent back to the | 
| 206         // main thread (e.g. for user-driven scrolling), so a PropertyUpdate | 202         // main thread (e.g. for user-driven scrolling), so a PROPERTY_UPDATE | 
| 207         // isn't needed. | 203         // isn't needed. | 
| 208         break; | 204         break; | 
| 209       } | 205       } | 
| 210 |  | 
| 211       case Animation::TargetPropertyEnumSize: |  | 
| 212         NOTREACHED(); |  | 
| 213     } | 206     } | 
| 214   } | 207   } | 
| 215 } | 208 } | 
| 216 | 209 | 
| 217 void LayerAnimationController::UpdateState(bool start_ready_animations, | 210 void LayerAnimationController::UpdateState(bool start_ready_animations, | 
| 218                                            AnimationEventsVector* events) { | 211                                            AnimationEventsVector* events) { | 
| 219   if (!HasActiveValueObserver()) | 212   if (!HasActiveValueObserver()) | 
| 220     return; | 213     return; | 
| 221 | 214 | 
| 222   // Animate hasn't been called, this happens if an observer has been added | 215   // Animate hasn't been called, this happens if an observer has been added | 
| 223   // between the Commit and Draw phases. | 216   // between the Commit and Draw phases. | 
| 224   if (last_tick_time_ == base::TimeTicks()) | 217   if (last_tick_time_ == base::TimeTicks()) | 
| 225     return; | 218     return; | 
| 226 | 219 | 
| 227   if (start_ready_animations) | 220   if (start_ready_animations) | 
| 228     PromoteStartedAnimations(last_tick_time_, events); | 221     PromoteStartedAnimations(last_tick_time_, events); | 
| 229 | 222 | 
| 230   MarkFinishedAnimations(last_tick_time_); | 223   MarkFinishedAnimations(last_tick_time_); | 
| 231   MarkAnimationsForDeletion(last_tick_time_, events); | 224   MarkAnimationsForDeletion(last_tick_time_, events); | 
| 232 | 225 | 
| 233   if (needs_to_start_animations_ && start_ready_animations) { | 226   if (needs_to_start_animations_ && start_ready_animations) { | 
| 234     StartAnimations(last_tick_time_); | 227     StartAnimations(last_tick_time_); | 
| 235     PromoteStartedAnimations(last_tick_time_, events); | 228     PromoteStartedAnimations(last_tick_time_, events); | 
| 236   } | 229   } | 
| 237 | 230 | 
| 238   AccumulatePropertyUpdates(last_tick_time_, events); | 231   AccumulatePropertyUpdates(last_tick_time_, events); | 
| 239 | 232 | 
| 240   UpdateActivation(NormalActivation); | 233   UpdateActivation(NORMAL_ACTIVATION); | 
| 241 } | 234 } | 
| 242 | 235 | 
| 243 struct AffectsNoObservers { | 236 struct AffectsNoObservers { | 
| 244   bool operator()(Animation* animation) const { | 237   bool operator()(Animation* animation) const { | 
| 245     return !animation->affects_active_observers() && | 238     return !animation->affects_active_observers() && | 
| 246            !animation->affects_pending_observers(); | 239            !animation->affects_pending_observers(); | 
| 247   } | 240   } | 
| 248 }; | 241 }; | 
| 249 | 242 | 
| 250 void LayerAnimationController::ActivateAnimations() { | 243 void LayerAnimationController::ActivateAnimations() { | 
| 251   for (size_t i = 0; i < animations_.size(); ++i) { | 244   for (size_t i = 0; i < animations_.size(); ++i) { | 
| 252     animations_[i]->set_affects_active_observers( | 245     animations_[i]->set_affects_active_observers( | 
| 253         animations_[i]->affects_pending_observers()); | 246         animations_[i]->affects_pending_observers()); | 
| 254   } | 247   } | 
| 255   animations_.erase(cc::remove_if(&animations_, | 248   animations_.erase(cc::remove_if(&animations_, | 
| 256                                   animations_.begin(), | 249                                   animations_.begin(), | 
| 257                                   animations_.end(), | 250                                   animations_.end(), | 
| 258                                   AffectsNoObservers()), | 251                                   AffectsNoObservers()), | 
| 259                     animations_.end()); | 252                     animations_.end()); | 
| 260   scroll_offset_animation_was_interrupted_ = false; | 253   scroll_offset_animation_was_interrupted_ = false; | 
| 261   UpdateActivation(NormalActivation); | 254   UpdateActivation(NORMAL_ACTIVATION); | 
| 262 } | 255 } | 
| 263 | 256 | 
| 264 void LayerAnimationController::AddAnimation(scoped_ptr<Animation> animation) { | 257 void LayerAnimationController::AddAnimation(scoped_ptr<Animation> animation) { | 
| 265   animations_.push_back(animation.Pass()); | 258   animations_.push_back(animation.Pass()); | 
| 266   needs_to_start_animations_ = true; | 259   needs_to_start_animations_ = true; | 
| 267   UpdateActivation(NormalActivation); | 260   UpdateActivation(NORMAL_ACTIVATION); | 
| 268 } | 261 } | 
| 269 | 262 | 
| 270 Animation* LayerAnimationController::GetAnimation( | 263 Animation* LayerAnimationController::GetAnimation( | 
| 271     Animation::TargetProperty target_property) const { | 264     Animation::TargetProperty target_property) const { | 
| 272   for (size_t i = 0; i < animations_.size(); ++i) { | 265   for (size_t i = 0; i < animations_.size(); ++i) { | 
| 273     size_t index = animations_.size() - i - 1; | 266     size_t index = animations_.size() - i - 1; | 
| 274     if (animations_[index]->target_property() == target_property) | 267     if (animations_[index]->target_property() == target_property) | 
| 275       return animations_[index]; | 268       return animations_[index]; | 
| 276   } | 269   } | 
| 277   return 0; | 270   return 0; | 
| (...skipping 30 matching lines...) Expand all  Loading... | 
| 308   if (registrar_ == registrar) | 301   if (registrar_ == registrar) | 
| 309     return; | 302     return; | 
| 310 | 303 | 
| 311   if (registrar_) | 304   if (registrar_) | 
| 312     registrar_->UnregisterAnimationController(this); | 305     registrar_->UnregisterAnimationController(this); | 
| 313 | 306 | 
| 314   registrar_ = registrar; | 307   registrar_ = registrar; | 
| 315   if (registrar_) | 308   if (registrar_) | 
| 316     registrar_->RegisterAnimationController(this); | 309     registrar_->RegisterAnimationController(this); | 
| 317 | 310 | 
| 318   UpdateActivation(ForceActivation); | 311   UpdateActivation(FORCE_ACTIVATION); | 
| 319 } | 312 } | 
| 320 | 313 | 
| 321 void LayerAnimationController::NotifyAnimationStarted( | 314 void LayerAnimationController::NotifyAnimationStarted( | 
| 322     const AnimationEvent& event) { | 315     const AnimationEvent& event) { | 
| 323   if (event.is_impl_only) { | 316   if (event.is_impl_only) { | 
| 324     FOR_EACH_OBSERVER(LayerAnimationEventObserver, event_observers_, | 317     FOR_EACH_OBSERVER(LayerAnimationEventObserver, event_observers_, | 
| 325                       OnAnimationStarted(event)); | 318                       OnAnimationStarted(event)); | 
| 326     if (layer_animation_delegate_) | 319     if (layer_animation_delegate_) | 
| 327       layer_animation_delegate_->NotifyAnimationStarted( | 320       layer_animation_delegate_->NotifyAnimationStarted( | 
| 328           event.monotonic_time, event.target_property, event.group_id); | 321           event.monotonic_time, event.target_property, event.group_id); | 
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 368       return; | 361       return; | 
| 369     } | 362     } | 
| 370   } | 363   } | 
| 371 } | 364 } | 
| 372 | 365 | 
| 373 void LayerAnimationController::NotifyAnimationAborted( | 366 void LayerAnimationController::NotifyAnimationAborted( | 
| 374     const AnimationEvent& event) { | 367     const AnimationEvent& event) { | 
| 375   for (size_t i = 0; i < animations_.size(); ++i) { | 368   for (size_t i = 0; i < animations_.size(); ++i) { | 
| 376     if (animations_[i]->group() == event.group_id && | 369     if (animations_[i]->group() == event.group_id && | 
| 377         animations_[i]->target_property() == event.target_property) { | 370         animations_[i]->target_property() == event.target_property) { | 
| 378       animations_[i]->SetRunState(Animation::Aborted, event.monotonic_time); | 371       animations_[i]->SetRunState(Animation::ABORTED, event.monotonic_time); | 
| 379     } | 372     } | 
| 380   } | 373   } | 
| 381 } | 374 } | 
| 382 | 375 | 
| 383 void LayerAnimationController::NotifyAnimationPropertyUpdate( | 376 void LayerAnimationController::NotifyAnimationPropertyUpdate( | 
| 384     const AnimationEvent& event) { | 377     const AnimationEvent& event) { | 
| 385   bool notify_active_observers = true; | 378   bool notify_active_observers = true; | 
| 386   bool notify_pending_observers = true; | 379   bool notify_pending_observers = true; | 
| 387   switch (event.target_property) { | 380   switch (event.target_property) { | 
| 388     case Animation::Opacity: | 381     case Animation::OPACITY: | 
| 389       NotifyObserversOpacityAnimated( | 382       NotifyObserversOpacityAnimated( | 
| 390           event.opacity, notify_active_observers, notify_pending_observers); | 383           event.opacity, notify_active_observers, notify_pending_observers); | 
| 391       break; | 384       break; | 
| 392     case Animation::Transform: | 385     case Animation::TRANSFORM: | 
| 393       NotifyObserversTransformAnimated( | 386       NotifyObserversTransformAnimated( | 
| 394           event.transform, notify_active_observers, notify_pending_observers); | 387           event.transform, notify_active_observers, notify_pending_observers); | 
| 395       break; | 388       break; | 
| 396     default: | 389     default: | 
| 397       NOTREACHED(); | 390       NOTREACHED(); | 
| 398   } | 391   } | 
| 399 } | 392 } | 
| 400 | 393 | 
| 401 void LayerAnimationController::AddValueObserver( | 394 void LayerAnimationController::AddValueObserver( | 
| 402     LayerAnimationValueObserver* observer) { | 395     LayerAnimationValueObserver* observer) { | 
| (...skipping 13 matching lines...) Expand all  Loading... | 
| 416 } | 409 } | 
| 417 | 410 | 
| 418 void LayerAnimationController::RemoveEventObserver( | 411 void LayerAnimationController::RemoveEventObserver( | 
| 419     LayerAnimationEventObserver* observer) { | 412     LayerAnimationEventObserver* observer) { | 
| 420   event_observers_.RemoveObserver(observer); | 413   event_observers_.RemoveObserver(observer); | 
| 421 } | 414 } | 
| 422 | 415 | 
| 423 bool LayerAnimationController::HasFilterAnimationThatInflatesBounds() const { | 416 bool LayerAnimationController::HasFilterAnimationThatInflatesBounds() const { | 
| 424   for (size_t i = 0; i < animations_.size(); ++i) { | 417   for (size_t i = 0; i < animations_.size(); ++i) { | 
| 425     if (!animations_[i]->is_finished() && | 418     if (!animations_[i]->is_finished() && | 
| 426         animations_[i]->target_property() == Animation::Filter && | 419         animations_[i]->target_property() == Animation::FILTER && | 
| 427         animations_[i] | 420         animations_[i] | 
| 428             ->curve() | 421             ->curve() | 
| 429             ->ToFilterAnimationCurve() | 422             ->ToFilterAnimationCurve() | 
| 430             ->HasFilterThatMovesPixels()) | 423             ->HasFilterThatMovesPixels()) | 
| 431       return true; | 424       return true; | 
| 432   } | 425   } | 
| 433 | 426 | 
| 434   return false; | 427   return false; | 
| 435 } | 428 } | 
| 436 | 429 | 
| 437 bool LayerAnimationController::HasTransformAnimationThatInflatesBounds() const { | 430 bool LayerAnimationController::HasTransformAnimationThatInflatesBounds() const { | 
| 438   return IsAnimatingProperty(Animation::Transform); | 431   return IsAnimatingProperty(Animation::TRANSFORM); | 
| 439 } | 432 } | 
| 440 | 433 | 
| 441 bool LayerAnimationController::FilterAnimationBoundsForBox( | 434 bool LayerAnimationController::FilterAnimationBoundsForBox( | 
| 442     const gfx::BoxF& box, gfx::BoxF* bounds) const { | 435     const gfx::BoxF& box, gfx::BoxF* bounds) const { | 
| 443   // TODO(avallee): Implement. | 436   // TODO(avallee): Implement. | 
| 444   return false; | 437   return false; | 
| 445 } | 438 } | 
| 446 | 439 | 
| 447 bool LayerAnimationController::TransformAnimationBoundsForBox( | 440 bool LayerAnimationController::TransformAnimationBoundsForBox( | 
| 448     const gfx::BoxF& box, | 441     const gfx::BoxF& box, | 
| 449     gfx::BoxF* bounds) const { | 442     gfx::BoxF* bounds) const { | 
| 450   DCHECK(HasTransformAnimationThatInflatesBounds()) | 443   DCHECK(HasTransformAnimationThatInflatesBounds()) | 
| 451       << "TransformAnimationBoundsForBox will give incorrect results if there " | 444       << "TransformAnimationBoundsForBox will give incorrect results if there " | 
| 452       << "are no transform animations affecting bounds, non-animated transform " | 445       << "are no transform animations affecting bounds, non-animated transform " | 
| 453       << "is not known"; | 446       << "is not known"; | 
| 454 | 447 | 
| 455   // Compute bounds based on animations for which is_finished() is false. | 448   // Compute bounds based on animations for which is_finished() is false. | 
| 456   // Do nothing if there are no such animations; in this case, it is assumed | 449   // Do nothing if there are no such animations; in this case, it is assumed | 
| 457   // that callers will take care of computing bounds based on the owning layer's | 450   // that callers will take care of computing bounds based on the owning layer's | 
| 458   // actual transform. | 451   // actual transform. | 
| 459   *bounds = gfx::BoxF(); | 452   *bounds = gfx::BoxF(); | 
| 460   for (size_t i = 0; i < animations_.size(); ++i) { | 453   for (size_t i = 0; i < animations_.size(); ++i) { | 
| 461     if (animations_[i]->is_finished() || | 454     if (animations_[i]->is_finished() || | 
| 462         animations_[i]->target_property() != Animation::Transform) | 455         animations_[i]->target_property() != Animation::TRANSFORM) | 
| 463       continue; | 456       continue; | 
| 464 | 457 | 
| 465     const TransformAnimationCurve* transform_animation_curve = | 458     const TransformAnimationCurve* transform_animation_curve = | 
| 466         animations_[i]->curve()->ToTransformAnimationCurve(); | 459         animations_[i]->curve()->ToTransformAnimationCurve(); | 
| 467     gfx::BoxF animation_bounds; | 460     gfx::BoxF animation_bounds; | 
| 468     bool success = | 461     bool success = | 
| 469         transform_animation_curve->AnimatedBoundsForBox(box, &animation_bounds); | 462         transform_animation_curve->AnimatedBoundsForBox(box, &animation_bounds); | 
| 470     if (!success) | 463     if (!success) | 
| 471       return false; | 464       return false; | 
| 472     bounds->Union(animation_bounds); | 465     bounds->Union(animation_bounds); | 
| 473   } | 466   } | 
| 474 | 467 | 
| 475   return true; | 468   return true; | 
| 476 } | 469 } | 
| 477 | 470 | 
| 478 bool LayerAnimationController::HasAnimationThatAffectsScale() const { | 471 bool LayerAnimationController::HasAnimationThatAffectsScale() const { | 
| 479   for (size_t i = 0; i < animations_.size(); ++i) { | 472   for (size_t i = 0; i < animations_.size(); ++i) { | 
| 480     if (animations_[i]->is_finished() || | 473     if (animations_[i]->is_finished() || | 
| 481         animations_[i]->target_property() != Animation::Transform) | 474         animations_[i]->target_property() != Animation::TRANSFORM) | 
| 482       continue; | 475       continue; | 
| 483 | 476 | 
| 484     const TransformAnimationCurve* transform_animation_curve = | 477     const TransformAnimationCurve* transform_animation_curve = | 
| 485         animations_[i]->curve()->ToTransformAnimationCurve(); | 478         animations_[i]->curve()->ToTransformAnimationCurve(); | 
| 486     if (transform_animation_curve->AffectsScale()) | 479     if (transform_animation_curve->AffectsScale()) | 
| 487       return true; | 480       return true; | 
| 488   } | 481   } | 
| 489 | 482 | 
| 490   return false; | 483   return false; | 
| 491 } | 484 } | 
| 492 | 485 | 
| 493 bool LayerAnimationController::HasOnlyTranslationTransforms() const { | 486 bool LayerAnimationController::HasOnlyTranslationTransforms() const { | 
| 494   for (size_t i = 0; i < animations_.size(); ++i) { | 487   for (size_t i = 0; i < animations_.size(); ++i) { | 
| 495     if (animations_[i]->is_finished() || | 488     if (animations_[i]->is_finished() || | 
| 496         animations_[i]->target_property() != Animation::Transform) | 489         animations_[i]->target_property() != Animation::TRANSFORM) | 
| 497       continue; | 490       continue; | 
| 498 | 491 | 
| 499     const TransformAnimationCurve* transform_animation_curve = | 492     const TransformAnimationCurve* transform_animation_curve = | 
| 500         animations_[i]->curve()->ToTransformAnimationCurve(); | 493         animations_[i]->curve()->ToTransformAnimationCurve(); | 
| 501     if (!transform_animation_curve->IsTranslation()) | 494     if (!transform_animation_curve->IsTranslation()) | 
| 502       return false; | 495       return false; | 
| 503   } | 496   } | 
| 504 | 497 | 
| 505   return true; | 498   return true; | 
| 506 } | 499 } | 
| 507 | 500 | 
| 508 bool LayerAnimationController::AnimationsPreserveAxisAlignment() const { | 501 bool LayerAnimationController::AnimationsPreserveAxisAlignment() const { | 
| 509   for (size_t i = 0; i < animations_.size(); ++i) { | 502   for (size_t i = 0; i < animations_.size(); ++i) { | 
| 510     if (animations_[i]->is_finished() || | 503     if (animations_[i]->is_finished() || | 
| 511         animations_[i]->target_property() != Animation::Transform) | 504         animations_[i]->target_property() != Animation::TRANSFORM) | 
| 512       continue; | 505       continue; | 
| 513 | 506 | 
| 514     const TransformAnimationCurve* transform_animation_curve = | 507     const TransformAnimationCurve* transform_animation_curve = | 
| 515         animations_[i]->curve()->ToTransformAnimationCurve(); | 508         animations_[i]->curve()->ToTransformAnimationCurve(); | 
| 516     if (!transform_animation_curve->PreservesAxisAlignment()) | 509     if (!transform_animation_curve->PreservesAxisAlignment()) | 
| 517       return false; | 510       return false; | 
| 518   } | 511   } | 
| 519 | 512 | 
| 520   return true; | 513   return true; | 
| 521 } | 514 } | 
| 522 | 515 | 
| 523 bool LayerAnimationController::MaximumTargetScale(float* max_scale) const { | 516 bool LayerAnimationController::MaximumTargetScale(float* max_scale) const { | 
| 524   *max_scale = 0.f; | 517   *max_scale = 0.f; | 
| 525   for (size_t i = 0; i < animations_.size(); ++i) { | 518   for (size_t i = 0; i < animations_.size(); ++i) { | 
| 526     if (animations_[i]->is_finished() || | 519     if (animations_[i]->is_finished() || | 
| 527         animations_[i]->target_property() != Animation::Transform) | 520         animations_[i]->target_property() != Animation::TRANSFORM) | 
| 528       continue; | 521       continue; | 
| 529 | 522 | 
| 530     bool forward_direction = true; | 523     bool forward_direction = true; | 
| 531     switch (animations_[i]->direction()) { | 524     switch (animations_[i]->direction()) { | 
| 532       case Animation::Normal: | 525       case Animation::DIRECTION_NORMAL: | 
| 533       case Animation::Alternate: | 526       case Animation::DIRECTION_ALTERNATE: | 
| 534         forward_direction = animations_[i]->playback_rate() >= 0.0; | 527         forward_direction = animations_[i]->playback_rate() >= 0.0; | 
| 535         break; | 528         break; | 
| 536       case Animation::Reverse: | 529       case Animation::DIRECTION_REVERSE: | 
| 537       case Animation::AlternateReverse: | 530       case Animation::DIRECTION_ALTERNATE_REVERSE: | 
| 538         forward_direction = animations_[i]->playback_rate() < 0.0; | 531         forward_direction = animations_[i]->playback_rate() < 0.0; | 
| 539         break; | 532         break; | 
| 540     } | 533     } | 
| 541 | 534 | 
| 542     const TransformAnimationCurve* transform_animation_curve = | 535     const TransformAnimationCurve* transform_animation_curve = | 
| 543         animations_[i]->curve()->ToTransformAnimationCurve(); | 536         animations_[i]->curve()->ToTransformAnimationCurve(); | 
| 544     float animation_scale = 0.f; | 537     float animation_scale = 0.f; | 
| 545     if (!transform_animation_curve->MaximumTargetScale(forward_direction, | 538     if (!transform_animation_curve->MaximumTargetScale(forward_direction, | 
| 546                                                        &animation_scale)) | 539                                                        &animation_scale)) | 
| 547       return false; | 540       return false; | 
| (...skipping 16 matching lines...) Expand all  Loading... | 
| 564     // If the animation is not running on the impl thread, it does not | 557     // If the animation is not running on the impl thread, it does not | 
| 565     // necessarily mean that it needs to be copied over and started; it may | 558     // necessarily mean that it needs to be copied over and started; it may | 
| 566     // have already finished. In this case, the impl thread animation will | 559     // have already finished. In this case, the impl thread animation will | 
| 567     // have already notified that it has started and the main thread animation | 560     // have already notified that it has started and the main thread animation | 
| 568     // will no longer need | 561     // will no longer need | 
| 569     // a synchronized start time. | 562     // a synchronized start time. | 
| 570     if (!animations_[i]->needs_synchronized_start_time()) | 563     if (!animations_[i]->needs_synchronized_start_time()) | 
| 571       continue; | 564       continue; | 
| 572 | 565 | 
| 573     // Scroll animations always start at the current scroll offset. | 566     // Scroll animations always start at the current scroll offset. | 
| 574     if (animations_[i]->target_property() == Animation::ScrollOffset) { | 567     if (animations_[i]->target_property() == Animation::SCROLL_OFFSET) { | 
| 575       gfx::ScrollOffset current_scroll_offset; | 568       gfx::ScrollOffset current_scroll_offset; | 
| 576       if (controller_impl->value_provider_) { | 569       if (controller_impl->value_provider_) { | 
| 577         current_scroll_offset = | 570         current_scroll_offset = | 
| 578             controller_impl->value_provider_->ScrollOffsetForAnimation(); | 571             controller_impl->value_provider_->ScrollOffsetForAnimation(); | 
| 579       } else { | 572       } else { | 
| 580         // The owning layer isn't yet in the active tree, so the main thread | 573         // The owning layer isn't yet in the active tree, so the main thread | 
| 581         // scroll offset will be up-to-date. | 574         // scroll offset will be up-to-date. | 
| 582         current_scroll_offset = value_provider_->ScrollOffsetForAnimation(); | 575         current_scroll_offset = value_provider_->ScrollOffsetForAnimation(); | 
| 583       } | 576       } | 
| 584       animations_[i]->curve()->ToScrollOffsetAnimationCurve()->SetInitialValue( | 577       animations_[i]->curve()->ToScrollOffsetAnimationCurve()->SetInitialValue( | 
| 585           current_scroll_offset); | 578           current_scroll_offset); | 
| 586     } | 579     } | 
| 587 | 580 | 
| 588     // The new animation should be set to run as soon as possible. | 581     // The new animation should be set to run as soon as possible. | 
| 589     Animation::RunState initial_run_state = | 582     Animation::RunState initial_run_state = | 
| 590         Animation::WaitingForTargetAvailability; | 583         Animation::WAITING_FOR_TARGET_AVAILABILITY; | 
| 591     scoped_ptr<Animation> to_add( | 584     scoped_ptr<Animation> to_add( | 
| 592         animations_[i]->CloneAndInitialize(initial_run_state)); | 585         animations_[i]->CloneAndInitialize(initial_run_state)); | 
| 593     DCHECK(!to_add->needs_synchronized_start_time()); | 586     DCHECK(!to_add->needs_synchronized_start_time()); | 
| 594     to_add->set_affects_active_observers(false); | 587     to_add->set_affects_active_observers(false); | 
| 595     controller_impl->AddAnimation(to_add.Pass()); | 588     controller_impl->AddAnimation(to_add.Pass()); | 
| 596   } | 589   } | 
| 597 } | 590 } | 
| 598 | 591 | 
| 599 static bool IsCompleted( | 592 static bool IsCompleted( | 
| 600     Animation* animation, | 593     Animation* animation, | 
| 601     const LayerAnimationController* main_thread_controller) { | 594     const LayerAnimationController* main_thread_controller) { | 
| 602   if (animation->is_impl_only()) { | 595   if (animation->is_impl_only()) { | 
| 603     return (animation->run_state() == Animation::WaitingForDeletion); | 596     return (animation->run_state() == Animation::WAITING_FOR_DELETION); | 
| 604   } else { | 597   } else { | 
| 605     return !main_thread_controller->GetAnimationById(animation->id()); | 598     return !main_thread_controller->GetAnimationById(animation->id()); | 
| 606   } | 599   } | 
| 607 } | 600 } | 
| 608 | 601 | 
| 609 static bool AffectsActiveOnlyAndIsWaitingForDeletion(Animation* animation) { | 602 static bool AffectsActiveOnlyAndIsWaitingForDeletion(Animation* animation) { | 
| 610   return animation->run_state() == Animation::WaitingForDeletion && | 603   return animation->run_state() == Animation::WAITING_FOR_DELETION && | 
| 611          !animation->affects_pending_observers(); | 604          !animation->affects_pending_observers(); | 
| 612 } | 605 } | 
| 613 | 606 | 
| 614 void LayerAnimationController::RemoveAnimationsCompletedOnMainThread( | 607 void LayerAnimationController::RemoveAnimationsCompletedOnMainThread( | 
| 615     LayerAnimationController* controller_impl) const { | 608     LayerAnimationController* controller_impl) const { | 
| 616   // Animations removed on the main thread should no longer affect pending | 609   // Animations removed on the main thread should no longer affect pending | 
| 617   // observers, and should stop affecting active observers after the next call | 610   // observers, and should stop affecting active observers after the next call | 
| 618   // to ActivateAnimations. If already WaitingForDeletion, they can be removed | 611   // to ActivateAnimations. If already WAITING_FOR_DELETION, they can be removed | 
| 619   // immediately. | 612   // immediately. | 
| 620   ScopedPtrVector<Animation>& animations = controller_impl->animations_; | 613   ScopedPtrVector<Animation>& animations = controller_impl->animations_; | 
| 621   for (size_t i = 0; i < animations.size(); ++i) { | 614   for (size_t i = 0; i < animations.size(); ++i) { | 
| 622     if (IsCompleted(animations[i], this)) | 615     if (IsCompleted(animations[i], this)) | 
| 623       animations[i]->set_affects_pending_observers(false); | 616       animations[i]->set_affects_pending_observers(false); | 
| 624   } | 617   } | 
| 625   animations.erase(cc::remove_if(&animations, | 618   animations.erase(cc::remove_if(&animations, | 
| 626                                  animations.begin(), | 619                                  animations.begin(), | 
| 627                                  animations.end(), | 620                                  animations.end(), | 
| 628                                  AffectsActiveOnlyAndIsWaitingForDeletion), | 621                                  AffectsActiveOnlyAndIsWaitingForDeletion), | 
| (...skipping 16 matching lines...) Expand all  Loading... | 
| 645 void LayerAnimationController::StartAnimations(base::TimeTicks monotonic_time) { | 638 void LayerAnimationController::StartAnimations(base::TimeTicks monotonic_time) { | 
| 646   DCHECK(needs_to_start_animations_); | 639   DCHECK(needs_to_start_animations_); | 
| 647   needs_to_start_animations_ = false; | 640   needs_to_start_animations_ = false; | 
| 648   // First collect running properties affecting each type of observer. | 641   // First collect running properties affecting each type of observer. | 
| 649   TargetProperties blocked_properties_for_active_observers; | 642   TargetProperties blocked_properties_for_active_observers; | 
| 650   TargetProperties blocked_properties_for_pending_observers; | 643   TargetProperties blocked_properties_for_pending_observers; | 
| 651   std::vector<size_t> animations_waiting_for_target; | 644   std::vector<size_t> animations_waiting_for_target; | 
| 652 | 645 | 
| 653   animations_waiting_for_target.reserve(animations_.size()); | 646   animations_waiting_for_target.reserve(animations_.size()); | 
| 654   for (size_t i = 0; i < animations_.size(); ++i) { | 647   for (size_t i = 0; i < animations_.size(); ++i) { | 
| 655     if (animations_[i]->run_state() == Animation::Starting || | 648     if (animations_[i]->run_state() == Animation::STARTING || | 
| 656         animations_[i]->run_state() == Animation::Running) { | 649         animations_[i]->run_state() == Animation::RUNNING) { | 
| 657       if (animations_[i]->affects_active_observers()) { | 650       if (animations_[i]->affects_active_observers()) { | 
| 658         blocked_properties_for_active_observers.insert( | 651         blocked_properties_for_active_observers.insert( | 
| 659             animations_[i]->target_property()); | 652             animations_[i]->target_property()); | 
| 660       } | 653       } | 
| 661       if (animations_[i]->affects_pending_observers()) { | 654       if (animations_[i]->affects_pending_observers()) { | 
| 662         blocked_properties_for_pending_observers.insert( | 655         blocked_properties_for_pending_observers.insert( | 
| 663             animations_[i]->target_property()); | 656             animations_[i]->target_property()); | 
| 664       } | 657       } | 
| 665     } else if (animations_[i]->run_state() == | 658     } else if (animations_[i]->run_state() == | 
| 666                Animation::WaitingForTargetAvailability) { | 659                Animation::WAITING_FOR_TARGET_AVAILABILITY) { | 
| 667       animations_waiting_for_target.push_back(i); | 660       animations_waiting_for_target.push_back(i); | 
| 668     } | 661     } | 
| 669   } | 662   } | 
| 670 | 663 | 
| 671   for (size_t i = 0; i < animations_waiting_for_target.size(); ++i) { | 664   for (size_t i = 0; i < animations_waiting_for_target.size(); ++i) { | 
| 672       // Collect all properties for animations with the same group id (they | 665       // Collect all properties for animations with the same group id (they | 
| 673       // should all also be in the list of animations). | 666       // should all also be in the list of animations). | 
| 674     size_t animation_index = animations_waiting_for_target[i]; | 667     size_t animation_index = animations_waiting_for_target[i]; | 
| 675     Animation* animation_waiting_for_target = animations_[animation_index]; | 668     Animation* animation_waiting_for_target = animations_[animation_index]; | 
| 676     // Check for the run state again even though the animation was waiting | 669     // Check for the run state again even though the animation was waiting | 
| 677     // for target because it might have changed the run state while handling | 670     // for target because it might have changed the run state while handling | 
| 678     // previous animation in this loop (if they belong to same group). | 671     // previous animation in this loop (if they belong to same group). | 
| 679     if (animation_waiting_for_target->run_state() == | 672     if (animation_waiting_for_target->run_state() == | 
| 680         Animation::WaitingForTargetAvailability) { | 673         Animation::WAITING_FOR_TARGET_AVAILABILITY) { | 
| 681       TargetProperties enqueued_properties; | 674       TargetProperties enqueued_properties; | 
| 682       bool affects_active_observers = | 675       bool affects_active_observers = | 
| 683           animation_waiting_for_target->affects_active_observers(); | 676           animation_waiting_for_target->affects_active_observers(); | 
| 684       bool affects_pending_observers = | 677       bool affects_pending_observers = | 
| 685           animation_waiting_for_target->affects_pending_observers(); | 678           animation_waiting_for_target->affects_pending_observers(); | 
| 686       enqueued_properties.insert( | 679       enqueued_properties.insert( | 
| 687           animation_waiting_for_target->target_property()); | 680           animation_waiting_for_target->target_property()); | 
| 688       for (size_t j = animation_index + 1; j < animations_.size(); ++j) { | 681       for (size_t j = animation_index + 1; j < animations_.size(); ++j) { | 
| 689         if (animation_waiting_for_target->group() == animations_[j]->group()) { | 682         if (animation_waiting_for_target->group() == animations_[j]->group()) { | 
| 690           enqueued_properties.insert(animations_[j]->target_property()); | 683           enqueued_properties.insert(animations_[j]->target_property()); | 
| (...skipping 17 matching lines...) Expand all  Loading... | 
| 708             !blocked_properties_for_active_observers.insert(*p_iter).second) | 701             !blocked_properties_for_active_observers.insert(*p_iter).second) | 
| 709           null_intersection = false; | 702           null_intersection = false; | 
| 710         if (affects_pending_observers && | 703         if (affects_pending_observers && | 
| 711             !blocked_properties_for_pending_observers.insert(*p_iter).second) | 704             !blocked_properties_for_pending_observers.insert(*p_iter).second) | 
| 712           null_intersection = false; | 705           null_intersection = false; | 
| 713       } | 706       } | 
| 714 | 707 | 
| 715       // If the intersection is null, then we are free to start the animations | 708       // If the intersection is null, then we are free to start the animations | 
| 716       // in the group. | 709       // in the group. | 
| 717       if (null_intersection) { | 710       if (null_intersection) { | 
| 718         animation_waiting_for_target->SetRunState(Animation::Starting, | 711         animation_waiting_for_target->SetRunState(Animation::STARTING, | 
| 719                                                   monotonic_time); | 712                                                   monotonic_time); | 
| 720         for (size_t j = animation_index + 1; j < animations_.size(); ++j) { | 713         for (size_t j = animation_index + 1; j < animations_.size(); ++j) { | 
| 721           if (animation_waiting_for_target->group() == | 714           if (animation_waiting_for_target->group() == | 
| 722               animations_[j]->group()) { | 715               animations_[j]->group()) { | 
| 723             animations_[j]->SetRunState(Animation::Starting, monotonic_time); | 716             animations_[j]->SetRunState(Animation::STARTING, monotonic_time); | 
| 724           } | 717           } | 
| 725         } | 718         } | 
| 726       } else { | 719       } else { | 
| 727         needs_to_start_animations_ = true; | 720         needs_to_start_animations_ = true; | 
| 728       } | 721       } | 
| 729     } | 722     } | 
| 730   } | 723   } | 
| 731 } | 724 } | 
| 732 | 725 | 
| 733 void LayerAnimationController::PromoteStartedAnimations( | 726 void LayerAnimationController::PromoteStartedAnimations( | 
| 734     base::TimeTicks monotonic_time, | 727     base::TimeTicks monotonic_time, | 
| 735     AnimationEventsVector* events) { | 728     AnimationEventsVector* events) { | 
| 736   for (size_t i = 0; i < animations_.size(); ++i) { | 729   for (size_t i = 0; i < animations_.size(); ++i) { | 
| 737     if (animations_[i]->run_state() == Animation::Starting && | 730     if (animations_[i]->run_state() == Animation::STARTING && | 
| 738         animations_[i]->affects_active_observers()) { | 731         animations_[i]->affects_active_observers()) { | 
| 739       animations_[i]->SetRunState(Animation::Running, monotonic_time); | 732       animations_[i]->SetRunState(Animation::RUNNING, monotonic_time); | 
| 740       if (!animations_[i]->has_set_start_time() && | 733       if (!animations_[i]->has_set_start_time() && | 
| 741           !animations_[i]->needs_synchronized_start_time()) | 734           !animations_[i]->needs_synchronized_start_time()) | 
| 742         animations_[i]->set_start_time(monotonic_time); | 735         animations_[i]->set_start_time(monotonic_time); | 
| 743       if (events) { | 736       if (events) { | 
| 744         AnimationEvent started_event(AnimationEvent::Started, | 737         AnimationEvent started_event( | 
| 745                                      id_, | 738             AnimationEvent::STARTED, id_, animations_[i]->group(), | 
| 746                                      animations_[i]->group(), | 739             animations_[i]->target_property(), monotonic_time); | 
| 747                                      animations_[i]->target_property(), |  | 
| 748                                      monotonic_time); |  | 
| 749         started_event.is_impl_only = animations_[i]->is_impl_only(); | 740         started_event.is_impl_only = animations_[i]->is_impl_only(); | 
| 750         if (started_event.is_impl_only) | 741         if (started_event.is_impl_only) | 
| 751           NotifyAnimationStarted(started_event); | 742           NotifyAnimationStarted(started_event); | 
| 752         else | 743         else | 
| 753           events->push_back(started_event); | 744           events->push_back(started_event); | 
| 754       } | 745       } | 
| 755     } | 746     } | 
| 756   } | 747   } | 
| 757 } | 748 } | 
| 758 | 749 | 
| 759 void LayerAnimationController::MarkFinishedAnimations( | 750 void LayerAnimationController::MarkFinishedAnimations( | 
| 760     base::TimeTicks monotonic_time) { | 751     base::TimeTicks monotonic_time) { | 
| 761   for (size_t i = 0; i < animations_.size(); ++i) { | 752   for (size_t i = 0; i < animations_.size(); ++i) { | 
| 762     if (animations_[i]->IsFinishedAt(monotonic_time) && | 753     if (animations_[i]->IsFinishedAt(monotonic_time) && | 
| 763         animations_[i]->run_state() != Animation::Aborted && | 754         animations_[i]->run_state() != Animation::ABORTED && | 
| 764         animations_[i]->run_state() != Animation::WaitingForDeletion) | 755         animations_[i]->run_state() != Animation::WAITING_FOR_DELETION) | 
| 765       animations_[i]->SetRunState(Animation::Finished, monotonic_time); | 756       animations_[i]->SetRunState(Animation::FINISHED, monotonic_time); | 
| 766   } | 757   } | 
| 767 } | 758 } | 
| 768 | 759 | 
| 769 void LayerAnimationController::MarkAnimationsForDeletion( | 760 void LayerAnimationController::MarkAnimationsForDeletion( | 
| 770     base::TimeTicks monotonic_time, | 761     base::TimeTicks monotonic_time, | 
| 771     AnimationEventsVector* events) { | 762     AnimationEventsVector* events) { | 
| 772   bool marked_animations_for_deletions = false; | 763   bool marked_animations_for_deletions = false; | 
| 773   std::vector<size_t> animations_with_same_group_id; | 764   std::vector<size_t> animations_with_same_group_id; | 
| 774 | 765 | 
| 775   animations_with_same_group_id.reserve(animations_.size()); | 766   animations_with_same_group_id.reserve(animations_.size()); | 
| 776   // Non-aborted animations are marked for deletion after a corresponding | 767   // Non-aborted animations are marked for deletion after a corresponding | 
| 777   // AnimationEvent::Finished event is sent or received. This means that if | 768   // AnimationEvent::FINISHED event is sent or received. This means that if | 
| 778   // we don't have an events vector, we must ensure that non-aborted animations | 769   // we don't have an events vector, we must ensure that non-aborted animations | 
| 779   // have received a finished event before marking them for deletion. | 770   // have received a finished event before marking them for deletion. | 
| 780   for (size_t i = 0; i < animations_.size(); i++) { | 771   for (size_t i = 0; i < animations_.size(); i++) { | 
| 781     int group_id = animations_[i]->group(); | 772     int group_id = animations_[i]->group(); | 
| 782     if (animations_[i]->run_state() == Animation::Aborted) { | 773     if (animations_[i]->run_state() == Animation::ABORTED) { | 
| 783       if (events && !animations_[i]->is_impl_only()) { | 774       if (events && !animations_[i]->is_impl_only()) { | 
| 784         AnimationEvent aborted_event(AnimationEvent::Aborted, | 775         AnimationEvent aborted_event(AnimationEvent::ABORTED, id_, group_id, | 
| 785                                      id_, |  | 
| 786                                      group_id, |  | 
| 787                                      animations_[i]->target_property(), | 776                                      animations_[i]->target_property(), | 
| 788                                      monotonic_time); | 777                                      monotonic_time); | 
| 789         events->push_back(aborted_event); | 778         events->push_back(aborted_event); | 
| 790       } | 779       } | 
| 791       animations_[i]->SetRunState(Animation::WaitingForDeletion, | 780       animations_[i]->SetRunState(Animation::WAITING_FOR_DELETION, | 
| 792                                   monotonic_time); | 781                                   monotonic_time); | 
| 793       marked_animations_for_deletions = true; | 782       marked_animations_for_deletions = true; | 
| 794       continue; | 783       continue; | 
| 795     } | 784     } | 
| 796 | 785 | 
| 797     bool all_anims_with_same_id_are_finished = false; | 786     bool all_anims_with_same_id_are_finished = false; | 
| 798 | 787 | 
| 799     // Since deleting an animation on the main thread leads to its deletion | 788     // Since deleting an animation on the main thread leads to its deletion | 
| 800     // on the impl thread, we only mark a Finished main thread animation for | 789     // on the impl thread, we only mark a FINISHED main thread animation for | 
| 801     // deletion once it has received a Finished event from the impl thread. | 790     // deletion once it has received a FINISHED event from the impl thread. | 
| 802     bool animation_i_will_send_or_has_received_finish_event = | 791     bool animation_i_will_send_or_has_received_finish_event = | 
| 803         events || animations_[i]->received_finished_event(); | 792         events || animations_[i]->received_finished_event(); | 
| 804     // If an animation is finished, and not already marked for deletion, | 793     // If an animation is finished, and not already marked for deletion, | 
| 805     // find out if all other animations in the same group are also finished. | 794     // find out if all other animations in the same group are also finished. | 
| 806     if (animations_[i]->run_state() == Animation::Finished && | 795     if (animations_[i]->run_state() == Animation::FINISHED && | 
| 807         animation_i_will_send_or_has_received_finish_event) { | 796         animation_i_will_send_or_has_received_finish_event) { | 
| 808       // Clear the animations_with_same_group_id if it was added for | 797       // Clear the animations_with_same_group_id if it was added for | 
| 809       // the previous animation's iteration. | 798       // the previous animation's iteration. | 
| 810       if (animations_with_same_group_id.size() > 0) | 799       if (animations_with_same_group_id.size() > 0) | 
| 811         animations_with_same_group_id.clear(); | 800         animations_with_same_group_id.clear(); | 
| 812       all_anims_with_same_id_are_finished = true; | 801       all_anims_with_same_id_are_finished = true; | 
| 813       for (size_t j = 0; j < animations_.size(); ++j) { | 802       for (size_t j = 0; j < animations_.size(); ++j) { | 
| 814         bool animation_j_will_send_or_has_received_finish_event = | 803         bool animation_j_will_send_or_has_received_finish_event = | 
| 815             events || animations_[j]->received_finished_event(); | 804             events || animations_[j]->received_finished_event(); | 
| 816         if (group_id == animations_[j]->group()) { | 805         if (group_id == animations_[j]->group()) { | 
| 817           if (!animations_[j]->is_finished() || | 806           if (!animations_[j]->is_finished() || | 
| 818               (animations_[j]->run_state() == Animation::Finished && | 807               (animations_[j]->run_state() == Animation::FINISHED && | 
| 819                !animation_j_will_send_or_has_received_finish_event)) { | 808                !animation_j_will_send_or_has_received_finish_event)) { | 
| 820             all_anims_with_same_id_are_finished = false; | 809             all_anims_with_same_id_are_finished = false; | 
| 821             break; | 810             break; | 
| 822           } else if (j >= i && | 811           } else if (j >= i && | 
| 823                      animations_[j]->run_state() != Animation::Aborted) { | 812                      animations_[j]->run_state() != Animation::ABORTED) { | 
| 824             // Mark down the animations which belong to the same group | 813             // Mark down the animations which belong to the same group | 
| 825             // and is not yet aborted. If this current iteration finds that all | 814             // and is not yet aborted. If this current iteration finds that all | 
| 826             // animations with same ID are finished, then the marked | 815             // animations with same ID are finished, then the marked | 
| 827             // animations below will be set to WaitingForDeletion in next | 816             // animations below will be set to WAITING_FOR_DELETION in next | 
| 828             // iteration. | 817             // iteration. | 
| 829             animations_with_same_group_id.push_back(j); | 818             animations_with_same_group_id.push_back(j); | 
| 830           } | 819           } | 
| 831         } | 820         } | 
| 832       } | 821       } | 
| 833     } | 822     } | 
| 834     if (all_anims_with_same_id_are_finished) { | 823     if (all_anims_with_same_id_are_finished) { | 
| 835       // We now need to remove all animations with the same group id as | 824       // We now need to remove all animations with the same group id as | 
| 836       // group_id (and send along animation finished notifications, if | 825       // group_id (and send along animation finished notifications, if | 
| 837       // necessary). | 826       // necessary). | 
| 838       for (size_t j = 0; j < animations_with_same_group_id.size(); j++) { | 827       for (size_t j = 0; j < animations_with_same_group_id.size(); j++) { | 
| 839         size_t animation_index = animations_with_same_group_id[j]; | 828         size_t animation_index = animations_with_same_group_id[j]; | 
| 840           if (events) { | 829           if (events) { | 
| 841             AnimationEvent finished_event( | 830             AnimationEvent finished_event( | 
| 842                 AnimationEvent::Finished, | 831                 AnimationEvent::FINISHED, id_, | 
| 843                 id_, |  | 
| 844                 animations_[animation_index]->group(), | 832                 animations_[animation_index]->group(), | 
| 845                 animations_[animation_index]->target_property(), | 833                 animations_[animation_index]->target_property(), | 
| 846                 monotonic_time); | 834                 monotonic_time); | 
| 847             finished_event.is_impl_only = | 835             finished_event.is_impl_only = | 
| 848                 animations_[animation_index]->is_impl_only(); | 836                 animations_[animation_index]->is_impl_only(); | 
| 849             if (finished_event.is_impl_only) | 837             if (finished_event.is_impl_only) | 
| 850               NotifyAnimationFinished(finished_event); | 838               NotifyAnimationFinished(finished_event); | 
| 851             else | 839             else | 
| 852               events->push_back(finished_event); | 840               events->push_back(finished_event); | 
| 853           } | 841           } | 
| 854           animations_[animation_index]->SetRunState( | 842           animations_[animation_index]->SetRunState( | 
| 855               Animation::WaitingForDeletion, monotonic_time); | 843               Animation::WAITING_FOR_DELETION, monotonic_time); | 
| 856       } | 844       } | 
| 857       marked_animations_for_deletions = true; | 845       marked_animations_for_deletions = true; | 
| 858     } | 846     } | 
| 859   } | 847   } | 
| 860   if (marked_animations_for_deletions) | 848   if (marked_animations_for_deletions) | 
| 861     NotifyObserversAnimationWaitingForDeletion(); | 849     NotifyObserversAnimationWaitingForDeletion(); | 
| 862 } | 850 } | 
| 863 | 851 | 
| 864 static bool IsWaitingForDeletion(Animation* animation) { | 852 static bool IsWaitingForDeletion(Animation* animation) { | 
| 865   return animation->run_state() == Animation::WaitingForDeletion; | 853   return animation->run_state() == Animation::WAITING_FOR_DELETION; | 
| 866 } | 854 } | 
| 867 | 855 | 
| 868 void LayerAnimationController::PurgeAnimationsMarkedForDeletion() { | 856 void LayerAnimationController::PurgeAnimationsMarkedForDeletion() { | 
| 869   animations_.erase(cc::remove_if(&animations_, | 857   animations_.erase(cc::remove_if(&animations_, | 
| 870                                   animations_.begin(), | 858                                   animations_.begin(), | 
| 871                                   animations_.end(), | 859                                   animations_.end(), | 
| 872                                   IsWaitingForDeletion), | 860                                   IsWaitingForDeletion), | 
| 873                     animations_.end()); | 861                     animations_.end()); | 
| 874 } | 862 } | 
| 875 | 863 | 
| 876 void LayerAnimationController::TickAnimations(base::TimeTicks monotonic_time) { | 864 void LayerAnimationController::TickAnimations(base::TimeTicks monotonic_time) { | 
| 877   for (size_t i = 0; i < animations_.size(); ++i) { | 865   for (size_t i = 0; i < animations_.size(); ++i) { | 
| 878     if (animations_[i]->run_state() == Animation::Starting || | 866     if (animations_[i]->run_state() == Animation::STARTING || | 
| 879         animations_[i]->run_state() == Animation::Running || | 867         animations_[i]->run_state() == Animation::RUNNING || | 
| 880         animations_[i]->run_state() == Animation::Paused) { | 868         animations_[i]->run_state() == Animation::PAUSED) { | 
| 881       if (!animations_[i]->InEffect(monotonic_time)) | 869       if (!animations_[i]->InEffect(monotonic_time)) | 
| 882         continue; | 870         continue; | 
| 883 | 871 | 
| 884       base::TimeDelta trimmed = | 872       base::TimeDelta trimmed = | 
| 885           animations_[i]->TrimTimeToCurrentIteration(monotonic_time); | 873           animations_[i]->TrimTimeToCurrentIteration(monotonic_time); | 
| 886 | 874 | 
| 887       switch (animations_[i]->target_property()) { | 875       switch (animations_[i]->target_property()) { | 
| 888         case Animation::Transform: { | 876         case Animation::TRANSFORM: { | 
| 889           const TransformAnimationCurve* transform_animation_curve = | 877           const TransformAnimationCurve* transform_animation_curve = | 
| 890               animations_[i]->curve()->ToTransformAnimationCurve(); | 878               animations_[i]->curve()->ToTransformAnimationCurve(); | 
| 891           const gfx::Transform transform = | 879           const gfx::Transform transform = | 
| 892               transform_animation_curve->GetValue(trimmed); | 880               transform_animation_curve->GetValue(trimmed); | 
| 893           NotifyObserversTransformAnimated( | 881           NotifyObserversTransformAnimated( | 
| 894               transform, | 882               transform, | 
| 895               animations_[i]->affects_active_observers(), | 883               animations_[i]->affects_active_observers(), | 
| 896               animations_[i]->affects_pending_observers()); | 884               animations_[i]->affects_pending_observers()); | 
| 897           break; | 885           break; | 
| 898         } | 886         } | 
| 899 | 887 | 
| 900         case Animation::Opacity: { | 888         case Animation::OPACITY: { | 
| 901           const FloatAnimationCurve* float_animation_curve = | 889           const FloatAnimationCurve* float_animation_curve = | 
| 902               animations_[i]->curve()->ToFloatAnimationCurve(); | 890               animations_[i]->curve()->ToFloatAnimationCurve(); | 
| 903           const float opacity = std::max( | 891           const float opacity = std::max( | 
| 904               std::min(float_animation_curve->GetValue(trimmed), 1.0f), 0.f); | 892               std::min(float_animation_curve->GetValue(trimmed), 1.0f), 0.f); | 
| 905           NotifyObserversOpacityAnimated( | 893           NotifyObserversOpacityAnimated( | 
| 906               opacity, | 894               opacity, | 
| 907               animations_[i]->affects_active_observers(), | 895               animations_[i]->affects_active_observers(), | 
| 908               animations_[i]->affects_pending_observers()); | 896               animations_[i]->affects_pending_observers()); | 
| 909           break; | 897           break; | 
| 910         } | 898         } | 
| 911 | 899 | 
| 912         case Animation::Filter: { | 900         case Animation::FILTER: { | 
| 913           const FilterAnimationCurve* filter_animation_curve = | 901           const FilterAnimationCurve* filter_animation_curve = | 
| 914               animations_[i]->curve()->ToFilterAnimationCurve(); | 902               animations_[i]->curve()->ToFilterAnimationCurve(); | 
| 915           const FilterOperations filter = | 903           const FilterOperations filter = | 
| 916               filter_animation_curve->GetValue(trimmed); | 904               filter_animation_curve->GetValue(trimmed); | 
| 917           NotifyObserversFilterAnimated( | 905           NotifyObserversFilterAnimated( | 
| 918               filter, | 906               filter, | 
| 919               animations_[i]->affects_active_observers(), | 907               animations_[i]->affects_active_observers(), | 
| 920               animations_[i]->affects_pending_observers()); | 908               animations_[i]->affects_pending_observers()); | 
| 921           break; | 909           break; | 
| 922         } | 910         } | 
| 923 | 911 | 
| 924         case Animation::BackgroundColor: { | 912         case Animation::BACKGROUND_COLOR: { | 
| 925           // Not yet implemented. | 913           // Not yet implemented. | 
| 926           break; | 914           break; | 
| 927         } | 915         } | 
| 928 | 916 | 
| 929         case Animation::ScrollOffset: { | 917         case Animation::SCROLL_OFFSET: { | 
| 930           const ScrollOffsetAnimationCurve* scroll_offset_animation_curve = | 918           const ScrollOffsetAnimationCurve* scroll_offset_animation_curve = | 
| 931               animations_[i]->curve()->ToScrollOffsetAnimationCurve(); | 919               animations_[i]->curve()->ToScrollOffsetAnimationCurve(); | 
| 932           const gfx::ScrollOffset scroll_offset = | 920           const gfx::ScrollOffset scroll_offset = | 
| 933               scroll_offset_animation_curve->GetValue(trimmed); | 921               scroll_offset_animation_curve->GetValue(trimmed); | 
| 934           NotifyObserversScrollOffsetAnimated( | 922           NotifyObserversScrollOffsetAnimated( | 
| 935               scroll_offset, | 923               scroll_offset, | 
| 936               animations_[i]->affects_active_observers(), | 924               animations_[i]->affects_active_observers(), | 
| 937               animations_[i]->affects_pending_observers()); | 925               animations_[i]->affects_pending_observers()); | 
| 938           break; | 926           break; | 
| 939         } | 927         } | 
| 940 |  | 
| 941         // Do nothing for sentinel value. |  | 
| 942         case Animation::TargetPropertyEnumSize: |  | 
| 943           NOTREACHED(); |  | 
| 944       } | 928       } | 
| 945     } | 929     } | 
| 946   } | 930   } | 
| 947 } | 931 } | 
| 948 | 932 | 
| 949 void LayerAnimationController::UpdateActivation(UpdateActivationType type) { | 933 void LayerAnimationController::UpdateActivation(UpdateActivationType type) { | 
| 950   bool force = type == ForceActivation; | 934   bool force = type == FORCE_ACTIVATION; | 
| 951   if (registrar_) { | 935   if (registrar_) { | 
| 952     bool was_active = is_active_; | 936     bool was_active = is_active_; | 
| 953     is_active_ = false; | 937     is_active_ = false; | 
| 954     for (size_t i = 0; i < animations_.size(); ++i) { | 938     for (size_t i = 0; i < animations_.size(); ++i) { | 
| 955       if (animations_[i]->run_state() != Animation::WaitingForDeletion) { | 939       if (animations_[i]->run_state() != Animation::WAITING_FOR_DELETION) { | 
| 956         is_active_ = true; | 940         is_active_ = true; | 
| 957         break; | 941         break; | 
| 958       } | 942       } | 
| 959     } | 943     } | 
| 960 | 944 | 
| 961     if (is_active_ && (!was_active || force)) | 945     if (is_active_ && (!was_active || force)) | 
| 962       registrar_->DidActivateAnimationController(this); | 946       registrar_->DidActivateAnimationController(this); | 
| 963     else if (!is_active_ && (was_active || force)) | 947     else if (!is_active_ && (was_active || force)) | 
| 964       registrar_->DidDeactivateAnimationController(this); | 948       registrar_->DidDeactivateAnimationController(this); | 
| 965   } | 949   } | 
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 1054         value_observers_); | 1038         value_observers_); | 
| 1055     LayerAnimationValueObserver* obs; | 1039     LayerAnimationValueObserver* obs; | 
| 1056     while ((obs = it.GetNext()) != nullptr) | 1040     while ((obs = it.GetNext()) != nullptr) | 
| 1057       if (obs->IsActive()) | 1041       if (obs->IsActive()) | 
| 1058         return true; | 1042         return true; | 
| 1059   } | 1043   } | 
| 1060   return false; | 1044   return false; | 
| 1061 } | 1045 } | 
| 1062 | 1046 | 
| 1063 }  // namespace cc | 1047 }  // namespace cc | 
| OLD | NEW | 
|---|