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

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

Issue 1882733005: CC Animation: Make LayerAnimationController to have just one value observer. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@privatelac
Patch Set: Fix codereview issues. 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/element_animations.h ('k') | cc/animation/element_animations_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 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 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/element_animations.h" 5 #include "cc/animation/element_animations.h"
6 6
7 #include "base/macros.h" 7 #include "base/macros.h"
8 #include "base/memory/ptr_util.h" 8 #include "base/memory/ptr_util.h"
9 #include "cc/animation/animation_host.h" 9 #include "cc/animation/animation_host.h"
10 #include "cc/animation/animation_player.h" 10 #include "cc/animation/animation_player.h"
11 #include "cc/animation/layer_animation_value_observer.h"
12 #include "cc/trees/mutator_host_client.h" 11 #include "cc/trees/mutator_host_client.h"
13 12
14 namespace cc { 13 namespace cc {
15 14
16 class ElementAnimations::ValueObserver : public LayerAnimationValueObserver {
17 public:
18 ValueObserver(ElementAnimations* element_animation, LayerTreeType tree_type)
19 : element_animations_(element_animation), tree_type_(tree_type) {
20 DCHECK(element_animations_);
21 }
22
23 // LayerAnimationValueObserver implementation.
24 void OnFilterAnimated(const FilterOperations& filters) override {
25 element_animations_->SetFilterMutated(tree_type_, filters);
26 }
27
28 void OnOpacityAnimated(float opacity) override {
29 element_animations_->SetOpacityMutated(tree_type_, opacity);
30 }
31
32 void OnTransformAnimated(const gfx::Transform& transform) override {
33 element_animations_->SetTransformMutated(tree_type_, transform);
34 }
35
36 void OnScrollOffsetAnimated(const gfx::ScrollOffset& scroll_offset) override {
37 element_animations_->SetScrollOffsetMutated(tree_type_, scroll_offset);
38 }
39
40 void OnAnimationWaitingForDeletion() override {
41 // TODO(loyso): See Layer::OnAnimationWaitingForDeletion. But we always do
42 // PushProperties for AnimationTimelines for now.
43 }
44
45 void OnTransformIsPotentiallyAnimatingChanged(bool is_animating) override {
46 element_animations_->SetTransformIsPotentiallyAnimatingChanged(
47 tree_type_, is_animating);
48 }
49
50 bool IsActive() const override { return tree_type_ == LayerTreeType::ACTIVE; }
51
52 private:
53 ElementAnimations* element_animations_;
54 const LayerTreeType tree_type_;
55
56 DISALLOW_COPY_AND_ASSIGN(ValueObserver);
57 };
58
59 std::unique_ptr<ElementAnimations> ElementAnimations::Create( 15 std::unique_ptr<ElementAnimations> ElementAnimations::Create(
60 AnimationHost* host) { 16 AnimationHost* host) {
61 return base::WrapUnique(new ElementAnimations(host)); 17 return base::WrapUnique(new ElementAnimations(host));
62 } 18 }
63 19
64 ElementAnimations::ElementAnimations(AnimationHost* host) 20 ElementAnimations::ElementAnimations(AnimationHost* host)
65 : players_list_(new PlayersList()), animation_host_(host) { 21 : players_list_(new PlayersList()), animation_host_(host) {
66 DCHECK(animation_host_); 22 DCHECK(animation_host_);
67 } 23 }
68 24
69 ElementAnimations::~ElementAnimations() { 25 ElementAnimations::~ElementAnimations() {
70 DCHECK(!layer_animation_controller_); 26 DCHECK(!layer_animation_controller_);
71 } 27 }
72 28
73 void ElementAnimations::CreateLayerAnimationController(int layer_id) { 29 void ElementAnimations::CreateLayerAnimationController(int layer_id) {
74 DCHECK(layer_id); 30 DCHECK(layer_id);
75 DCHECK(!layer_animation_controller_); 31 DCHECK(!layer_animation_controller_);
76 DCHECK(animation_host_); 32 DCHECK(animation_host_);
77 33
78 layer_animation_controller_ = 34 layer_animation_controller_ =
79 animation_host_->GetAnimationControllerForId(layer_id); 35 animation_host_->GetAnimationControllerForId(layer_id);
80 layer_animation_controller_->SetAnimationHost(animation_host_); 36 layer_animation_controller_->SetAnimationHost(animation_host_);
81 layer_animation_controller_->set_layer_animation_delegate(this); 37 layer_animation_controller_->set_layer_animation_delegate(this);
38 layer_animation_controller_->set_value_observer(this);
82 layer_animation_controller_->set_value_provider(this); 39 layer_animation_controller_->set_value_provider(this);
83 40
84 DCHECK(animation_host_->mutator_host_client()); 41 DCHECK(animation_host_->mutator_host_client());
85 if (animation_host_->mutator_host_client()->IsLayerInTree( 42 if (animation_host_->mutator_host_client()->IsLayerInTree(
86 layer_id, LayerTreeType::ACTIVE)) 43 layer_id, LayerTreeType::ACTIVE))
87 CreateActiveValueObserver(); 44 CreateActiveValueObserver();
88 if (animation_host_->mutator_host_client()->IsLayerInTree( 45 if (animation_host_->mutator_host_client()->IsLayerInTree(
89 layer_id, LayerTreeType::PENDING)) 46 layer_id, LayerTreeType::PENDING))
90 CreatePendingValueObserver(); 47 CreatePendingValueObserver();
91 } 48 }
92 49
93 void ElementAnimations::DestroyLayerAnimationController() { 50 void ElementAnimations::DestroyLayerAnimationController() {
94 DCHECK(animation_host_); 51 DCHECK(animation_host_);
95 52
96 if (active_value_observer_) 53 if (needs_active_value_observations())
97 SetTransformIsPotentiallyAnimatingChanged(LayerTreeType::ACTIVE, false); 54 OnTransformIsPotentiallyAnimatingChanged(LayerTreeType::ACTIVE, false);
98 if (pending_value_observer_) 55 if (needs_pending_value_observations())
99 SetTransformIsPotentiallyAnimatingChanged(LayerTreeType::PENDING, false); 56 OnTransformIsPotentiallyAnimatingChanged(LayerTreeType::PENDING, false);
100 57
101 DestroyPendingValueObserver(); 58 DestroyPendingValueObserver();
102 DestroyActiveValueObserver(); 59 DestroyActiveValueObserver();
103 60
104 if (layer_animation_controller_) { 61 if (layer_animation_controller_) {
105 layer_animation_controller_->remove_value_provider(this); 62 layer_animation_controller_->remove_value_provider(this);
63 layer_animation_controller_->set_value_observer(nullptr);
106 layer_animation_controller_->remove_layer_animation_delegate(this); 64 layer_animation_controller_->remove_layer_animation_delegate(this);
107 layer_animation_controller_->SetAnimationHost(nullptr); 65 layer_animation_controller_->SetAnimationHost(nullptr);
108 layer_animation_controller_ = nullptr; 66 layer_animation_controller_ = nullptr;
109 } 67 }
110 } 68 }
111 69
112 void ElementAnimations::LayerRegistered(int layer_id, LayerTreeType tree_type) { 70 void ElementAnimations::LayerRegistered(int layer_id, LayerTreeType tree_type) {
113 DCHECK(layer_animation_controller_); 71 DCHECK(layer_animation_controller_);
114 DCHECK_EQ(layer_animation_controller_->id(), layer_id); 72 DCHECK_EQ(layer_animation_controller_->id(), layer_id);
115 73
116 if (tree_type == LayerTreeType::ACTIVE) { 74 if (tree_type == LayerTreeType::ACTIVE)
117 if (!active_value_observer_) 75 layer_animation_controller_->set_needs_active_value_observations(true);
118 CreateActiveValueObserver(); 76 else
119 } else { 77 layer_animation_controller_->set_needs_pending_value_observations(true);
120 if (!pending_value_observer_)
121 CreatePendingValueObserver();
122 }
123 } 78 }
124 79
125 void ElementAnimations::LayerUnregistered(int layer_id, 80 void ElementAnimations::LayerUnregistered(int layer_id,
126 LayerTreeType tree_type) { 81 LayerTreeType tree_type) {
127 DCHECK_EQ(this->layer_id(), layer_id); 82 DCHECK_EQ(this->layer_id(), layer_id);
128 tree_type == LayerTreeType::ACTIVE ? DestroyActiveValueObserver() 83 tree_type == LayerTreeType::ACTIVE ? DestroyActiveValueObserver()
129 : DestroyPendingValueObserver(); 84 : DestroyPendingValueObserver();
130 } 85 }
131 86
132 void ElementAnimations::AddPlayer(AnimationPlayer* player) { 87 void ElementAnimations::AddPlayer(AnimationPlayer* player) {
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 void ElementAnimations::AddEventObserver( 146 void ElementAnimations::AddEventObserver(
192 LayerAnimationEventObserver* observer) { 147 LayerAnimationEventObserver* observer) {
193 layer_animation_controller_->AddEventObserver(observer); 148 layer_animation_controller_->AddEventObserver(observer);
194 } 149 }
195 150
196 void ElementAnimations::RemoveEventObserver( 151 void ElementAnimations::RemoveEventObserver(
197 LayerAnimationEventObserver* observer) { 152 LayerAnimationEventObserver* observer) {
198 layer_animation_controller_->RemoveEventObserver(observer); 153 layer_animation_controller_->RemoveEventObserver(observer);
199 } 154 }
200 155
201 void ElementAnimations::SetFilterMutated(LayerTreeType tree_type, 156 void ElementAnimations::OnFilterAnimated(LayerTreeType tree_type,
202 const FilterOperations& filters) { 157 const FilterOperations& filters) {
203 DCHECK(layer_id()); 158 DCHECK(layer_id());
204 DCHECK(animation_host()); 159 DCHECK(animation_host());
205 DCHECK(animation_host()->mutator_host_client()); 160 DCHECK(animation_host()->mutator_host_client());
206 animation_host()->mutator_host_client()->SetLayerFilterMutated( 161 animation_host()->mutator_host_client()->SetLayerFilterMutated(
207 layer_id(), tree_type, filters); 162 layer_id(), tree_type, filters);
208 } 163 }
209 164
210 void ElementAnimations::SetOpacityMutated(LayerTreeType tree_type, 165 void ElementAnimations::OnOpacityAnimated(LayerTreeType tree_type,
211 float opacity) { 166 float opacity) {
212 DCHECK(layer_id()); 167 DCHECK(layer_id());
213 DCHECK(animation_host()); 168 DCHECK(animation_host());
214 DCHECK(animation_host()->mutator_host_client()); 169 DCHECK(animation_host()->mutator_host_client());
215 animation_host()->mutator_host_client()->SetLayerOpacityMutated( 170 animation_host()->mutator_host_client()->SetLayerOpacityMutated(
216 layer_id(), tree_type, opacity); 171 layer_id(), tree_type, opacity);
217 } 172 }
218 173
219 void ElementAnimations::SetTransformMutated(LayerTreeType tree_type, 174 void ElementAnimations::OnTransformAnimated(LayerTreeType tree_type,
220 const gfx::Transform& transform) { 175 const gfx::Transform& transform) {
221 DCHECK(layer_id()); 176 DCHECK(layer_id());
222 DCHECK(animation_host()); 177 DCHECK(animation_host());
223 DCHECK(animation_host()->mutator_host_client()); 178 DCHECK(animation_host()->mutator_host_client());
224 animation_host()->mutator_host_client()->SetLayerTransformMutated( 179 animation_host()->mutator_host_client()->SetLayerTransformMutated(
225 layer_id(), tree_type, transform); 180 layer_id(), tree_type, transform);
226 } 181 }
227 182
228 void ElementAnimations::SetScrollOffsetMutated( 183 void ElementAnimations::OnScrollOffsetAnimated(
229 LayerTreeType tree_type, 184 LayerTreeType tree_type,
230 const gfx::ScrollOffset& scroll_offset) { 185 const gfx::ScrollOffset& scroll_offset) {
231 DCHECK(layer_id()); 186 DCHECK(layer_id());
232 DCHECK(animation_host()); 187 DCHECK(animation_host());
233 DCHECK(animation_host()->mutator_host_client()); 188 DCHECK(animation_host()->mutator_host_client());
234 animation_host()->mutator_host_client()->SetLayerScrollOffsetMutated( 189 animation_host()->mutator_host_client()->SetLayerScrollOffsetMutated(
235 layer_id(), tree_type, scroll_offset); 190 layer_id(), tree_type, scroll_offset);
236 } 191 }
237 192
238 void ElementAnimations::SetTransformIsPotentiallyAnimatingChanged( 193 void ElementAnimations::OnAnimationWaitingForDeletion() {
194 // TODO(loyso): See Layer::OnAnimationWaitingForDeletion. But we always do
195 // PushProperties for AnimationTimelines for now.
196 }
197
198 void ElementAnimations::OnTransformIsPotentiallyAnimatingChanged(
239 LayerTreeType tree_type, 199 LayerTreeType tree_type,
240 bool is_animating) { 200 bool is_animating) {
241 DCHECK(layer_id()); 201 DCHECK(layer_id());
242 DCHECK(animation_host()); 202 DCHECK(animation_host());
243 DCHECK(animation_host()->mutator_host_client()); 203 DCHECK(animation_host()->mutator_host_client());
244 animation_host() 204 animation_host()
245 ->mutator_host_client() 205 ->mutator_host_client()
246 ->LayerTransformIsPotentiallyAnimatingChanged(layer_id(), tree_type, 206 ->LayerTransformIsPotentiallyAnimatingChanged(layer_id(), tree_type,
247 is_animating); 207 is_animating);
248 } 208 }
249 209
250 void ElementAnimations::CreateActiveValueObserver() { 210 void ElementAnimations::CreateActiveValueObserver() {
251 DCHECK(layer_animation_controller_); 211 DCHECK(layer_animation_controller_);
252 DCHECK(!active_value_observer_); 212 DCHECK(!needs_active_value_observations());
253 active_value_observer_ = 213 layer_animation_controller_->set_needs_active_value_observations(true);
254 base::WrapUnique(new ValueObserver(this, LayerTreeType::ACTIVE));
255 layer_animation_controller_->AddValueObserver(active_value_observer_.get());
256 } 214 }
257 215
258 void ElementAnimations::DestroyActiveValueObserver() { 216 void ElementAnimations::DestroyActiveValueObserver() {
259 if (layer_animation_controller_ && active_value_observer_) 217 if (layer_animation_controller_)
260 layer_animation_controller_->RemoveValueObserver( 218 layer_animation_controller_->set_needs_active_value_observations(false);
261 active_value_observer_.get());
262 active_value_observer_ = nullptr;
263 } 219 }
264 220
265 void ElementAnimations::CreatePendingValueObserver() { 221 void ElementAnimations::CreatePendingValueObserver() {
266 DCHECK(layer_animation_controller_); 222 DCHECK(layer_animation_controller_);
267 DCHECK(!pending_value_observer_); 223 DCHECK(!needs_pending_value_observations());
268 pending_value_observer_ = 224 layer_animation_controller_->set_needs_pending_value_observations(true);
269 base::WrapUnique(new ValueObserver(this, LayerTreeType::PENDING));
270 layer_animation_controller_->AddValueObserver(pending_value_observer_.get());
271 } 225 }
272 226
273 void ElementAnimations::DestroyPendingValueObserver() { 227 void ElementAnimations::DestroyPendingValueObserver() {
274 if (layer_animation_controller_ && pending_value_observer_) 228 if (layer_animation_controller_)
275 layer_animation_controller_->RemoveValueObserver( 229 layer_animation_controller_->set_needs_pending_value_observations(false);
276 pending_value_observer_.get());
277 pending_value_observer_ = nullptr;
278 } 230 }
279 231
280 void ElementAnimations::NotifyAnimationStarted( 232 void ElementAnimations::NotifyAnimationStarted(
281 base::TimeTicks monotonic_time, 233 base::TimeTicks monotonic_time,
282 TargetProperty::Type target_property, 234 TargetProperty::Type target_property,
283 int group) { 235 int group) {
284 for (PlayersListNode* node = players_list_->head(); 236 for (PlayersListNode* node = players_list_->head();
285 node != players_list_->end(); node = node->next()) { 237 node != players_list_->end(); node = node->next()) {
286 AnimationPlayer* player = node->value(); 238 AnimationPlayer* player = node->value();
287 player->NotifyAnimationStarted(monotonic_time, target_property, group); 239 player->NotifyAnimationStarted(monotonic_time, target_property, group);
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
331 if (animation_host()) { 283 if (animation_host()) {
332 DCHECK(animation_host()->mutator_host_client()); 284 DCHECK(animation_host()->mutator_host_client());
333 return animation_host()->mutator_host_client()->GetScrollOffsetForAnimation( 285 return animation_host()->mutator_host_client()->GetScrollOffsetForAnimation(
334 layer_id()); 286 layer_id());
335 } 287 }
336 288
337 return gfx::ScrollOffset(); 289 return gfx::ScrollOffset();
338 } 290 }
339 291
340 } // namespace cc 292 } // namespace cc
OLDNEW
« no previous file with comments | « cc/animation/element_animations.h ('k') | cc/animation/element_animations_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698