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
3 // found in the LICENSE file.
5 #include "cc/animation/animation_registrar.h"
7 #include "base/trace_event/trace_event_argument.h"
8 #include "cc/animation/layer_animation_controller.h"
12 AnimationRegistrar::AnimationRegistrar() : supports_scroll_animations_(false) {
15 AnimationRegistrar::~AnimationRegistrar() {
16 AnimationControllerMap copy
= all_animation_controllers_
;
17 for (AnimationControllerMap::iterator iter
= copy
.begin();
20 (*iter
).second
->SetAnimationRegistrar(nullptr);
23 scoped_refptr
<LayerAnimationController
>
24 AnimationRegistrar::GetAnimationControllerForId(int id
) {
25 scoped_refptr
<LayerAnimationController
> to_return
;
26 if (!ContainsKey(all_animation_controllers_
, id
)) {
27 to_return
= LayerAnimationController::Create(id
);
28 to_return
->SetAnimationRegistrar(this);
29 all_animation_controllers_
[id
] = to_return
.get();
31 to_return
= all_animation_controllers_
[id
];
36 void AnimationRegistrar::DidActivateAnimationController(
37 LayerAnimationController
* controller
) {
38 active_animation_controllers_
[controller
->id()] = controller
;
41 void AnimationRegistrar::DidDeactivateAnimationController(
42 LayerAnimationController
* controller
) {
43 if (ContainsKey(active_animation_controllers_
, controller
->id()))
44 active_animation_controllers_
.erase(controller
->id());
47 void AnimationRegistrar::RegisterAnimationController(
48 LayerAnimationController
* controller
) {
49 all_animation_controllers_
[controller
->id()] = controller
;
52 void AnimationRegistrar::UnregisterAnimationController(
53 LayerAnimationController
* controller
) {
54 if (ContainsKey(all_animation_controllers_
, controller
->id()))
55 all_animation_controllers_
.erase(controller
->id());
56 DidDeactivateAnimationController(controller
);
59 bool AnimationRegistrar::ActivateAnimations() {
60 if (!needs_animate_layers())
63 TRACE_EVENT0("cc", "AnimationRegistrar::ActivateAnimations");
64 AnimationControllerMap active_controllers_copy
=
65 active_animation_controllers_
;
66 for (auto& it
: active_controllers_copy
)
67 it
.second
->ActivateAnimations();
72 bool AnimationRegistrar::AnimateLayers(base::TimeTicks monotonic_time
) {
73 if (!needs_animate_layers())
76 TRACE_EVENT0("cc", "AnimationRegistrar::AnimateLayers");
77 AnimationControllerMap controllers_copy
= active_animation_controllers_
;
78 for (auto& it
: controllers_copy
)
79 it
.second
->Animate(monotonic_time
);
84 bool AnimationRegistrar::UpdateAnimationState(bool start_ready_animations
,
85 AnimationEventsVector
* events
) {
86 if (!needs_animate_layers())
89 TRACE_EVENT0("cc", "AnimationRegistrar::UpdateAnimationState");
90 AnimationControllerMap active_controllers_copy
=
91 active_animation_controllers_
;
92 for (auto& it
: active_controllers_copy
)
93 it
.second
->UpdateState(start_ready_animations
, events
);
98 void AnimationRegistrar::SetAnimationEvents(
99 scoped_ptr
<AnimationEventsVector
> events
) {
100 for (size_t event_index
= 0; event_index
< events
->size(); ++event_index
) {
101 int event_layer_id
= (*events
)[event_index
].layer_id
;
103 // Use the map of all controllers, not just active ones, since non-active
104 // controllers may still receive events for impl-only animations.
105 const AnimationRegistrar::AnimationControllerMap
& animation_controllers
=
106 all_animation_controllers_
;
107 auto iter
= animation_controllers
.find(event_layer_id
);
108 if (iter
!= animation_controllers
.end()) {
109 switch ((*events
)[event_index
].type
) {
110 case AnimationEvent::STARTED
:
111 (*iter
).second
->NotifyAnimationStarted((*events
)[event_index
]);
114 case AnimationEvent::FINISHED
:
115 (*iter
).second
->NotifyAnimationFinished((*events
)[event_index
]);
118 case AnimationEvent::ABORTED
:
119 (*iter
).second
->NotifyAnimationAborted((*events
)[event_index
]);
122 case AnimationEvent::PROPERTY_UPDATE
:
123 (*iter
).second
->NotifyAnimationPropertyUpdate((*events
)[event_index
]);