Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(96)

Side by Side Diff: cc/animation/animation_registrar.cc

Issue 1881373002: CC Animation: Erase AnimationRegistrar (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@private
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « cc/animation/animation_registrar.h ('k') | cc/animation/element_animations.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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.
4
5 #include "cc/animation/animation_registrar.h"
6
7 #include <stddef.h>
8
9 #include "base/memory/ptr_util.h"
10 #include "base/trace_event/trace_event.h"
11 #include "base/trace_event/trace_event_argument.h"
12 #include "cc/animation/animation_events.h"
13 #include "cc/animation/layer_animation_controller.h"
14
15 namespace cc {
16
17 AnimationRegistrar::AnimationRegistrar() : supports_scroll_animations_(false) {
18 }
19
20 AnimationRegistrar::~AnimationRegistrar() {
21 AnimationControllerMap copy = all_animation_controllers_;
22 for (AnimationControllerMap::iterator iter = copy.begin();
23 iter != copy.end();
24 ++iter)
25 (*iter).second->SetAnimationRegistrar(nullptr);
26 }
27
28 scoped_refptr<LayerAnimationController>
29 AnimationRegistrar::GetAnimationControllerForId(int id) {
30 scoped_refptr<LayerAnimationController> to_return;
31 if (!ContainsKey(all_animation_controllers_, id)) {
32 to_return = LayerAnimationController::Create(id);
33 to_return->SetAnimationRegistrar(this);
34 all_animation_controllers_[id] = to_return.get();
35 } else {
36 to_return = all_animation_controllers_[id];
37 }
38 return to_return;
39 }
40
41 void AnimationRegistrar::DidActivateAnimationController(
42 LayerAnimationController* controller) {
43 active_animation_controllers_[controller->id()] = controller;
44 }
45
46 void AnimationRegistrar::DidDeactivateAnimationController(
47 LayerAnimationController* controller) {
48 if (ContainsKey(active_animation_controllers_, controller->id()))
49 active_animation_controllers_.erase(controller->id());
50 }
51
52 void AnimationRegistrar::RegisterAnimationController(
53 LayerAnimationController* controller) {
54 all_animation_controllers_[controller->id()] = controller;
55 }
56
57 void AnimationRegistrar::UnregisterAnimationController(
58 LayerAnimationController* controller) {
59 if (ContainsKey(all_animation_controllers_, controller->id()))
60 all_animation_controllers_.erase(controller->id());
61 DidDeactivateAnimationController(controller);
62 }
63
64 bool AnimationRegistrar::ActivateAnimations() {
65 if (!needs_animate_layers())
66 return false;
67
68 TRACE_EVENT0("cc", "AnimationRegistrar::ActivateAnimations");
69 AnimationControllerMap active_controllers_copy =
70 active_animation_controllers_;
71 for (auto& it : active_controllers_copy)
72 it.second->ActivateAnimations();
73
74 return true;
75 }
76
77 bool AnimationRegistrar::AnimateLayers(base::TimeTicks monotonic_time) {
78 if (!needs_animate_layers())
79 return false;
80
81 TRACE_EVENT0("cc", "AnimationRegistrar::AnimateLayers");
82 AnimationControllerMap controllers_copy = active_animation_controllers_;
83 for (auto& it : controllers_copy)
84 it.second->Animate(monotonic_time);
85
86 return true;
87 }
88
89 bool AnimationRegistrar::UpdateAnimationState(bool start_ready_animations,
90 AnimationEvents* events) {
91 if (!needs_animate_layers())
92 return false;
93
94 TRACE_EVENT0("cc", "AnimationRegistrar::UpdateAnimationState");
95 AnimationControllerMap active_controllers_copy =
96 active_animation_controllers_;
97 for (auto& it : active_controllers_copy)
98 it.second->UpdateState(start_ready_animations, events);
99
100 return true;
101 }
102
103 std::unique_ptr<AnimationEvents> AnimationRegistrar::CreateEvents() {
104 return base::WrapUnique(new AnimationEvents());
105 }
106
107 void AnimationRegistrar::SetAnimationEvents(
108 std::unique_ptr<AnimationEvents> events) {
109 for (size_t event_index = 0; event_index < events->events_.size();
110 ++event_index) {
111 int event_layer_id = events->events_[event_index].layer_id;
112
113 // Use the map of all controllers, not just active ones, since non-active
114 // controllers may still receive events for impl-only animations.
115 const AnimationRegistrar::AnimationControllerMap& animation_controllers =
116 all_animation_controllers_;
117 auto iter = animation_controllers.find(event_layer_id);
118 if (iter != animation_controllers.end()) {
119 switch (events->events_[event_index].type) {
120 case AnimationEvent::STARTED:
121 (*iter).second->NotifyAnimationStarted(events->events_[event_index]);
122 break;
123
124 case AnimationEvent::FINISHED:
125 (*iter).second->NotifyAnimationFinished(events->events_[event_index]);
126 break;
127
128 case AnimationEvent::ABORTED:
129 (*iter).second->NotifyAnimationAborted(events->events_[event_index]);
130 break;
131
132 case AnimationEvent::PROPERTY_UPDATE:
133 (*iter).second->NotifyAnimationPropertyUpdate(
134 events->events_[event_index]);
135 break;
136
137 case AnimationEvent::TAKEOVER:
138 (*iter).second->NotifyAnimationTakeover(events->events_[event_index]);
139 break;
140 }
141 }
142 }
143 }
144
145 } // namespace cc
OLDNEW
« no previous file with comments | « cc/animation/animation_registrar.h ('k') | cc/animation/element_animations.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698