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

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

Issue 947033002: CC Animations: Establish AnimationHost, AnimationTimeline and AnimationPlayer (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Move MutatorHostClient back to cc/trees/ Created 5 years, 5 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
OLDNEW
(Empty)
1 // Copyright 2015 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/element_animations.h"
6
7 #include "cc/animation/animation_host.h"
8 #include "cc/animation/animation_player.h"
9 #include "cc/animation/animation_registrar.h"
10 #include "cc/animation/layer_animation_value_observer.h"
11 #include "cc/trees/mutator_host_client.h"
12
13 namespace cc {
14
15 class ElementAnimations::ValueObserver : public LayerAnimationValueObserver {
16 public:
17 ValueObserver(ElementAnimations* element_animation, LayerTreeType tree_type)
18 : element_animation_(element_animation), tree_type_(tree_type) {
19 DCHECK(element_animation_);
20 }
21
22 // LayerAnimationValueObserver implementation.
23 void OnFilterAnimated(const FilterOperations& filters) override {
24 element_animation_->SetFilterMutated(tree_type_, filters);
25 }
26
27 void OnOpacityAnimated(float opacity) override {
28 element_animation_->SetOpacityMutated(tree_type_, opacity);
29 }
30
31 void OnTransformAnimated(const gfx::Transform& transform) override {
32 element_animation_->SetTransformMutated(tree_type_, transform);
33 }
34
35 void OnScrollOffsetAnimated(const gfx::ScrollOffset& scroll_offset) override {
36 element_animation_->SetScrollOffsetMutated(tree_type_, scroll_offset);
37 }
38
39 void OnAnimationWaitingForDeletion() override {
40 // TODO(loyso): implement it.
41 }
42
43 bool IsActive() const override { return tree_type_ == LayerTreeType::ACTIVE; }
44
45 private:
46 ElementAnimations* element_animation_;
47 const LayerTreeType tree_type_;
48
49 DISALLOW_COPY_AND_ASSIGN(ValueObserver);
50 };
51
52 ElementAnimations::ElementAnimations(AnimationHost* host)
53 : players_list_(make_scoped_ptr(new PlayersList())), animation_host_(host) {
54 DCHECK(animation_host_);
55 }
56
57 ElementAnimations::~ElementAnimations() {
58 DCHECK(!layer_animation_controller_);
59 }
60
61 void ElementAnimations::CreateLayerAnimationController(int layer_id) {
62 DCHECK(layer_id);
63 DCHECK(!layer_animation_controller_);
64 DCHECK(animation_host_);
65
66 AnimationRegistrar* registrar = animation_host_->animation_registrar();
67 DCHECK(registrar);
68
69 layer_animation_controller_ =
70 registrar->GetAnimationControllerForId(layer_id);
71 layer_animation_controller_->SetAnimationRegistrar(registrar);
72 layer_animation_controller_->set_layer_animation_delegate(this);
73 layer_animation_controller_->set_value_provider(this);
74
75 DCHECK(animation_host_->mutator_host_client());
76 if (animation_host_->mutator_host_client()->IsLayerInTree(
77 layer_id, LayerTreeType::ACTIVE))
78 CreateActiveValueObserver();
79 if (animation_host_->mutator_host_client()->IsLayerInTree(
80 layer_id, LayerTreeType::PENDING))
81 CreatePendingValueObserver();
82 }
83
84 void ElementAnimations::DestroyLayerAnimationController() {
85 DCHECK(animation_host_);
86
87 DestroyPendingValueObserver();
88 DestroyActiveValueObserver();
89
90 if (layer_animation_controller_) {
91 layer_animation_controller_->remove_value_provider(this);
92 layer_animation_controller_->remove_layer_animation_delegate(this);
93 layer_animation_controller_->SetAnimationRegistrar(nullptr);
94 layer_animation_controller_ = nullptr;
95 }
96 }
97
98 void ElementAnimations::LayerRegistered(int layer_id, LayerTreeType tree_type) {
99 DCHECK(layer_animation_controller_);
100 DCHECK_EQ(layer_animation_controller_->id(), layer_id);
101
102 if (tree_type == LayerTreeType::ACTIVE) {
103 if (!active_value_observer_)
104 CreateActiveValueObserver();
105 } else {
106 if (!pending_value_observer_)
107 CreatePendingValueObserver();
108 }
109 }
110
111 void ElementAnimations::LayerUnregistered(int layer_id,
112 LayerTreeType tree_type) {
113 DCHECK_EQ(this->layer_id(), layer_id);
114 tree_type == LayerTreeType::ACTIVE ? DestroyActiveValueObserver()
115 : DestroyPendingValueObserver();
116 }
117
118 void ElementAnimations::AddPlayer(AnimationPlayer* player) {
119 players_list_->Append(player);
120 }
121
122 void ElementAnimations::RemovePlayer(AnimationPlayer* player) {
123 for (PlayersListNode* node = players_list_->head();
124 node != players_list_->end(); node = node->next()) {
125 if (node->value() == player) {
126 node->RemoveFromList();
127 return;
128 }
129 }
130 }
131
132 bool ElementAnimations::IsEmpty() const {
133 return players_list_->empty();
134 }
135
136 void ElementAnimations::PushPropertiesTo(
137 ElementAnimations* element_animations_impl) {
138 DCHECK(layer_animation_controller_);
139 DCHECK(element_animations_impl->layer_animation_controller());
140
141 layer_animation_controller_->PushAnimationUpdatesTo(
142 element_animations_impl->layer_animation_controller());
143 }
144
145 void ElementAnimations::SetFilterMutated(LayerTreeType tree_type,
146 const FilterOperations& filters) {
147 DCHECK(layer_id());
148 DCHECK(animation_host());
149 DCHECK(animation_host()->mutator_host_client());
150 animation_host()->mutator_host_client()->SetLayerFilterMutated(
151 layer_id(), tree_type, filters);
152 }
153
154 void ElementAnimations::SetOpacityMutated(LayerTreeType tree_type,
155 float opacity) {
156 DCHECK(layer_id());
157 DCHECK(animation_host());
158 DCHECK(animation_host()->mutator_host_client());
159 animation_host()->mutator_host_client()->SetLayerOpacityMutated(
160 layer_id(), tree_type, opacity);
161 }
162
163 void ElementAnimations::SetTransformMutated(LayerTreeType tree_type,
164 const gfx::Transform& transform) {
165 DCHECK(layer_id());
166 DCHECK(animation_host());
167 DCHECK(animation_host()->mutator_host_client());
168 animation_host()->mutator_host_client()->SetLayerTransformMutated(
169 layer_id(), tree_type, transform);
170 }
171
172 void ElementAnimations::SetScrollOffsetMutated(
173 LayerTreeType tree_type,
174 const gfx::ScrollOffset& scroll_offset) {
175 DCHECK(layer_id());
176 DCHECK(animation_host());
177 DCHECK(animation_host()->mutator_host_client());
178 animation_host()->mutator_host_client()->SetLayerScrollOffsetMutated(
179 layer_id(), tree_type, scroll_offset);
180 }
181
182 void ElementAnimations::CreateActiveValueObserver() {
183 DCHECK(layer_animation_controller_);
184 DCHECK(!active_value_observer_);
185 active_value_observer_ =
186 make_scoped_ptr(new ValueObserver(this, LayerTreeType::ACTIVE));
187 layer_animation_controller_->AddValueObserver(active_value_observer_.get());
188 }
189
190 void ElementAnimations::DestroyActiveValueObserver() {
191 if (layer_animation_controller_ && active_value_observer_)
192 layer_animation_controller_->RemoveValueObserver(
193 active_value_observer_.get());
194 active_value_observer_ = nullptr;
195 }
196
197 void ElementAnimations::CreatePendingValueObserver() {
198 DCHECK(layer_animation_controller_);
199 DCHECK(!pending_value_observer_);
200 pending_value_observer_ =
201 make_scoped_ptr(new ValueObserver(this, LayerTreeType::PENDING));
202 layer_animation_controller_->AddValueObserver(pending_value_observer_.get());
203 }
204
205 void ElementAnimations::DestroyPendingValueObserver() {
206 if (layer_animation_controller_ && pending_value_observer_)
207 layer_animation_controller_->RemoveValueObserver(
208 pending_value_observer_.get());
209 pending_value_observer_ = nullptr;
210 }
211
212 void ElementAnimations::NotifyAnimationStarted(
213 base::TimeTicks monotonic_time,
214 Animation::TargetProperty target_property,
215 int group) {
216 for (PlayersListNode* node = players_list_->head();
217 node != players_list_->end(); node = node->next()) {
218 AnimationPlayer* player = node->value();
219 player->NotifyAnimationStarted(monotonic_time, target_property, group);
220 }
221 }
222
223 void ElementAnimations::NotifyAnimationFinished(
224 base::TimeTicks monotonic_time,
225 Animation::TargetProperty target_property,
226 int group) {
227 for (PlayersListNode* node = players_list_->head();
228 node != players_list_->end(); node = node->next()) {
229 AnimationPlayer* player = node->value();
230 player->NotifyAnimationFinished(monotonic_time, target_property, group);
231 }
232 }
233
234 gfx::ScrollOffset ElementAnimations::ScrollOffsetForAnimation() const {
235 // TODO(loyso): implement it.
236 return gfx::ScrollOffset();
237 }
238
239 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698