OLD | NEW |
---|---|
(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/animation_player.h" | |
6 | |
7 #include "base/atomic_sequence_num.h" | |
8 #include "cc/animation/animation_timeline.h" | |
9 #include "cc/layers/layer.h" | |
10 #include "cc/trees/layer_tree_mutators_client.h" | |
11 | |
12 namespace cc { | |
13 | |
14 base::StaticAtomicSequenceNumber g_next_animation_player_id; | |
15 | |
16 scoped_refptr<AnimationPlayer> AnimationPlayer::Create(int id) { | |
17 return make_scoped_refptr(new AnimationPlayer(id)); | |
18 } | |
19 | |
20 AnimationPlayer::AnimationPlayer(int id) | |
21 : animation_timeline_(), | |
22 layer_animation_delegate_(), | |
23 id_(id), | |
24 layer_id_(0) { | |
25 if (id_ == 0) | |
26 id_ = g_next_animation_player_id.GetNext() + 1; | |
ajuma
2015/02/23 16:36:44
Having a combination of provided and automatically
loyso (OOO)
2015/02/25 04:37:03
I agree. That's trivial.
| |
27 } | |
28 | |
29 AnimationPlayer::~AnimationPlayer() { | |
30 DCHECK(!animation_timeline()); | |
31 if (layer_animation_controller_) | |
32 DetachLayer(); | |
33 } | |
34 | |
35 scoped_refptr<AnimationPlayer> AnimationPlayer::CreateImplInstance() const { | |
36 scoped_refptr<AnimationPlayer> to_return = AnimationPlayer::Create(id()); | |
37 to_return->pending_value_observer_ = | |
38 make_scoped_ptr(new AnimationPlayerPendingValueObserver(to_return.get())); | |
39 return to_return; | |
40 } | |
41 | |
42 void AnimationPlayer::SetAnimationTimeline(AnimationTimeline* timeline) { | |
43 animation_timeline_ = timeline; | |
44 if (layer_animation_controller_) | |
45 layer_animation_controller_->SetAnimationRegistrar( | |
46 animation_timeline_ | |
47 ? animation_timeline_->layer_tree_mutators_client() | |
48 ->GetAnimationRegistrar() | |
49 : nullptr); | |
50 } | |
51 | |
52 void AnimationPlayer::set_layer_animation_delegate( | |
53 AnimationDelegate* delegate) { | |
54 layer_animation_delegate_ = delegate; | |
55 if (layer_animation_controller_) | |
56 layer_animation_controller_->set_layer_animation_delegate(delegate); | |
57 } | |
58 | |
59 void AnimationPlayer::AttachLayer(int layer_id) { | |
60 DCHECK_EQ(layer_id_, 0); | |
61 DCHECK_NE(layer_id, 0); | |
62 layer_id_ = layer_id; | |
63 | |
64 layer_animation_controller_ = LayerAnimationController::Create(layer_id_); | |
65 layer_animation_controller_->AddValueObserver(this); | |
66 layer_animation_controller_->set_value_provider(this); | |
67 layer_animation_controller_->set_layer_animation_delegate( | |
68 layer_animation_delegate_); | |
69 if (animation_timeline_) | |
70 layer_animation_controller_->SetAnimationRegistrar( | |
71 animation_timeline_->layer_tree_mutators_client() | |
72 ->GetAnimationRegistrar()); | |
73 | |
74 if (pending_value_observer_) | |
75 layer_animation_controller_->AddValueObserver( | |
76 pending_value_observer_.get()); | |
ajuma
2015/02/23 16:36:44
The asymmetry between active and pending observers
loyso (OOO)
2015/02/25 04:37:03
This is messy intermediate solution. We get rid of
ajuma
2015/02/25 14:57:25
We should aim to keep things as clean and readable
loyso (OOO)
2015/02/26 03:04:44
No, not at all. We can spawn many nested classes.
| |
77 } | |
78 | |
79 void AnimationPlayer::DetachLayer() { | |
80 DCHECK_NE(layer_id_, 0); | |
81 DCHECK(layer_animation_controller_); | |
82 | |
83 if (pending_value_observer_) | |
84 layer_animation_controller_->RemoveValueObserver( | |
85 pending_value_observer_.get()); | |
86 | |
87 layer_animation_controller_->RemoveValueObserver(this); | |
88 layer_animation_controller_->remove_value_provider(this); | |
89 layer_animation_controller_->set_layer_animation_delegate(nullptr); | |
90 layer_animation_controller_->SetAnimationRegistrar(nullptr); | |
91 layer_animation_controller_ = nullptr; | |
92 | |
93 layer_id_ = 0; | |
94 } | |
95 | |
96 void AnimationPlayer::AddAnimation(scoped_ptr<Animation> animation) { | |
97 DCHECK(layer_animation_controller_); | |
98 layer_animation_controller_->AddAnimation(animation.Pass()); | |
99 SetNeedsCommit(); | |
100 } | |
101 | |
102 void AnimationPlayer::PauseAnimation(int animation_id, double time_offset) { | |
103 DCHECK(layer_animation_controller_); | |
104 layer_animation_controller_->PauseAnimation( | |
105 animation_id, base::TimeDelta::FromSecondsD(time_offset)); | |
106 SetNeedsCommit(); | |
107 } | |
108 | |
109 void AnimationPlayer::RemoveAnimation(int animation_id) { | |
110 DCHECK(layer_animation_controller_); | |
111 layer_animation_controller_->RemoveAnimation(animation_id); | |
112 SetNeedsCommit(); | |
113 } | |
114 | |
115 void AnimationPlayer::PushPropertiesTo(AnimationPlayer* player_impl) { | |
116 if (!layer_animation_controller()) { | |
117 if (player_impl->layer_animation_controller()) | |
118 player_impl->DetachLayer(); | |
119 return; | |
120 } | |
121 | |
122 DCHECK_NE(layer_id_, 0); | |
123 if (!player_impl->layer_animation_controller()) | |
124 player_impl->AttachLayer(layer_id_); | |
125 | |
126 DCHECK(player_impl->layer_animation_controller()); | |
127 layer_animation_controller_->PushAnimationUpdatesTo( | |
128 player_impl->layer_animation_controller()); | |
129 } | |
130 | |
131 void AnimationPlayer::SetNeedsCommit() { | |
132 DCHECK(animation_timeline_); | |
133 animation_timeline_->layer_tree_mutators_client()->SetMutatorsNeedCommit(); | |
134 } | |
135 | |
136 void AnimationPlayer::SetFilterMutated(bool active_tree, | |
137 const FilterOperations& filters) { | |
138 if (animation_timeline() && layer_id_) { | |
ajuma
2015/02/23 16:36:44
Should the check for layer_id_ really be a DCHECK?
loyso (OOO)
2015/02/25 04:37:03
Yes, we can go with DCHECK here.
| |
139 DCHECK(animation_timeline()->layer_tree_mutators_client()); | |
140 animation_timeline()->layer_tree_mutators_client()->SetLayerFilterMutated( | |
141 layer_id_, active_tree, filters); | |
142 } | |
143 } | |
144 | |
145 void AnimationPlayer::SetOpacityMutated(bool active_tree, float opacity) { | |
146 if (animation_timeline() && layer_id_) { | |
147 DCHECK(animation_timeline()->layer_tree_mutators_client()); | |
148 animation_timeline()->layer_tree_mutators_client()->SetLayerOpacityMutated( | |
149 layer_id_, active_tree, opacity); | |
150 } | |
151 } | |
152 | |
153 void AnimationPlayer::SetTransformMutated(bool active_tree, | |
154 const gfx::Transform& transform) { | |
155 if (animation_timeline() && layer_id_) { | |
156 DCHECK(animation_timeline()->layer_tree_mutators_client()); | |
157 animation_timeline() | |
158 ->layer_tree_mutators_client() | |
159 ->SetLayerTransformMutated(layer_id_, active_tree, transform); | |
160 } | |
161 } | |
162 | |
163 gfx::ScrollOffset AnimationPlayer::ScrollOffsetForAnimation() const { | |
164 // TODO(loyso): implement it. | |
165 return gfx::ScrollOffset(); | |
166 } | |
167 | |
168 void AnimationPlayer::OnFilterAnimated(const FilterOperations& filters) { | |
169 SetFilterMutated(true, filters); | |
170 } | |
171 | |
172 void AnimationPlayer::OnOpacityAnimated(float opacity) { | |
173 SetOpacityMutated(true, opacity); | |
174 } | |
175 | |
176 void AnimationPlayer::OnTransformAnimated(const gfx::Transform& transform) { | |
177 SetTransformMutated(true, transform); | |
178 } | |
179 | |
180 void AnimationPlayer::OnScrollOffsetAnimated( | |
181 const gfx::ScrollOffset& scroll_offset) { | |
182 // TODO(loyso): implement it. | |
183 } | |
184 | |
185 void AnimationPlayer::OnAnimationWaitingForDeletion() { | |
186 // TODO(loyso): implement it. | |
187 } | |
188 | |
189 bool AnimationPlayer::IsActive() const { | |
190 return true; | |
191 } | |
192 | |
193 AnimationPlayerPendingValueObserver::AnimationPlayerPendingValueObserver( | |
194 AnimationPlayer* player) | |
195 : player_(player) { | |
196 DCHECK(player_); | |
197 } | |
198 | |
199 void AnimationPlayerPendingValueObserver::OnFilterAnimated( | |
200 const FilterOperations& filters) { | |
201 player_->SetFilterMutated(false, filters); | |
202 } | |
203 | |
204 void AnimationPlayerPendingValueObserver::OnOpacityAnimated(float opacity) { | |
205 player_->SetOpacityMutated(false, opacity); | |
206 } | |
207 | |
208 void AnimationPlayerPendingValueObserver::OnTransformAnimated( | |
209 const gfx::Transform& transform) { | |
210 player_->SetTransformMutated(false, transform); | |
211 } | |
212 | |
213 void AnimationPlayerPendingValueObserver::OnScrollOffsetAnimated( | |
214 const gfx::ScrollOffset& scroll_offset) { | |
215 // TODO(loyso): implement it. | |
216 } | |
217 | |
218 void AnimationPlayerPendingValueObserver::OnAnimationWaitingForDeletion() { | |
219 // TODO(loyso): implement it. | |
220 } | |
221 | |
222 bool AnimationPlayerPendingValueObserver::IsActive() const { | |
223 return false; | |
224 } | |
225 | |
226 } // namespace cc | |
OLD | NEW |