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

Side by Side Diff: ui/compositor/layer_animator.cc

Issue 1944623002: CC Animation: Use ElementId to attach CC animation players. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@erasedomids
Patch Set: Let CC clients generate their own ElementIds locally. Created 4 years, 7 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
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "ui/compositor/layer_animator.h" 5 #include "ui/compositor/layer_animator.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <memory> 9 #include <memory>
10 10
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 if (collection) 132 if (collection)
133 collection->StartAnimator(this); 133 collection->StartAnimator(this);
134 } 134 }
135 } 135 }
136 136
137 void LayerAnimator::SwitchToLayer(scoped_refptr<cc::Layer> new_layer) { 137 void LayerAnimator::SwitchToLayer(scoped_refptr<cc::Layer> new_layer) {
138 // Release ElementAnimations state for old layer. 138 // Release ElementAnimations state for old layer.
139 element_animations_state_ = nullptr; 139 element_animations_state_ = nullptr;
140 140
141 if (delegate_) 141 if (delegate_)
142 DetachLayerFromAnimationPlayer(); 142 DetachElementFromAnimationPlayer();
143 if (new_layer) 143 if (new_layer) {
144 AttachLayerToAnimationPlayer(new_layer->id()); 144 if (!new_layer->element_id())
145 new_layer->SetElementId(Layer::NextElementId());
146 AttachElementToAnimationPlayer(new_layer->element_id());
147 }
145 } 148 }
146 149
147 void LayerAnimator::SetCompositor(Compositor* compositor) { 150 void LayerAnimator::SetCompositor(Compositor* compositor) {
148 DCHECK(compositor); 151 DCHECK(compositor);
149 152
150 cc::AnimationTimeline* timeline = compositor->GetAnimationTimeline(); 153 cc::AnimationTimeline* timeline = compositor->GetAnimationTimeline();
151 DCHECK(timeline); 154 DCHECK(timeline);
152 155
153 DCHECK(delegate_->GetCcLayer()); 156 DCHECK(delegate_->GetCcLayer());
154 157
155 // Register ElementAnimations so it will be picked up by 158 // Register ElementAnimations so it will be picked up by
156 // AnimationHost::RegisterPlayerForLayer via 159 // AnimationHost::RegisterPlayerForLayer via
157 // AnimationHost::GetElementAnimationsForLayerId. 160 // AnimationHost::GetElementAnimationsForLayerId.
158 if (element_animations_state_) { 161 if (element_animations_state_) {
159 DCHECK_EQ(element_animations_state_->element_id(), 162 DCHECK_EQ(element_animations_state_->element_id(),
160 delegate_->GetCcLayer()->id()); 163 delegate_->GetCcLayer()->element_id());
161 timeline->animation_host()->RegisterElementAnimations( 164 timeline->animation_host()->RegisterElementAnimations(
162 element_animations_state_.get()); 165 element_animations_state_.get());
163 } 166 }
164 167
165 timeline->AttachPlayer(animation_player_); 168 timeline->AttachPlayer(animation_player_);
166 169
167 AttachLayerToAnimationPlayer(delegate_->GetCcLayer()->id()); 170 AttachElementToAnimationPlayer(delegate_->GetCcLayer()->element_id());
168 171
169 // Release ElementAnimations state. 172 // Release ElementAnimations state.
170 element_animations_state_ = nullptr; 173 element_animations_state_ = nullptr;
171 } 174 }
172 175
173 void LayerAnimator::ResetCompositor(Compositor* compositor) { 176 void LayerAnimator::ResetCompositor(Compositor* compositor) {
174 DCHECK(compositor); 177 DCHECK(compositor);
175 178
176 cc::AnimationTimeline* timeline = compositor->GetAnimationTimeline(); 179 cc::AnimationTimeline* timeline = compositor->GetAnimationTimeline();
177 DCHECK(timeline); 180 DCHECK(timeline);
178 181
179 const int layer_id = animation_player_->element_id(); 182 const cc::ElementId element_id = animation_player_->element_id();
180 183
181 // Store a reference to ElementAnimations (if any) 184 // Store a reference to ElementAnimations (if any)
182 // so it may be picked up in LayerAnimator::SetCompositor. 185 // so it may be picked up in LayerAnimator::SetCompositor.
183 if (layer_id) { 186 if (element_id) {
184 element_animations_state_ = 187 element_animations_state_ =
185 timeline->animation_host()->GetElementAnimationsForElementId(layer_id); 188 timeline->animation_host()->GetElementAnimationsForElementId(
189 element_id);
186 } 190 }
187 191
188 DetachLayerFromAnimationPlayer(); 192 DetachElementFromAnimationPlayer();
189 193
190 timeline->DetachPlayer(animation_player_); 194 timeline->DetachPlayer(animation_player_);
191 } 195 }
192 196
193 void LayerAnimator::AttachLayerToAnimationPlayer(int layer_id) { 197 void LayerAnimator::AttachElementToAnimationPlayer(cc::ElementId element_id) {
198 DCHECK(element_id);
199
194 if (!animation_player_->element_id()) 200 if (!animation_player_->element_id())
195 animation_player_->AttachElement(layer_id); 201 animation_player_->AttachElement(element_id);
196 else 202 else
197 DCHECK_EQ(animation_player_->element_id(), layer_id); 203 DCHECK_EQ(animation_player_->element_id(), element_id);
198 204
199 animation_player_->set_animation_delegate(this); 205 animation_player_->set_animation_delegate(this);
200 } 206 }
201 207
202 void LayerAnimator::DetachLayerFromAnimationPlayer() { 208 void LayerAnimator::DetachElementFromAnimationPlayer() {
203 animation_player_->set_animation_delegate(nullptr); 209 animation_player_->set_animation_delegate(nullptr);
204 210
205 if (animation_player_->element_id()) 211 if (animation_player_->element_id())
206 animation_player_->DetachElement(); 212 animation_player_->DetachElement();
207 } 213 }
208 214
209 void LayerAnimator::AddThreadedAnimation( 215 void LayerAnimator::AddThreadedAnimation(
210 std::unique_ptr<cc::Animation> animation) { 216 std::unique_ptr<cc::Animation> animation) {
211 animation_player_->AddAnimation(std::move(animation)); 217 animation_player_->AddAnimation(std::move(animation));
212 } 218 }
(...skipping 751 matching lines...) Expand 10 before | Expand all | Expand 10 after
964 const base::WeakPtr<LayerAnimationSequence>& sequence) 970 const base::WeakPtr<LayerAnimationSequence>& sequence)
965 : sequence_(sequence) { 971 : sequence_(sequence) {
966 } 972 }
967 973
968 LayerAnimator::RunningAnimation::RunningAnimation( 974 LayerAnimator::RunningAnimation::RunningAnimation(
969 const RunningAnimation& other) = default; 975 const RunningAnimation& other) = default;
970 976
971 LayerAnimator::RunningAnimation::~RunningAnimation() { } 977 LayerAnimator::RunningAnimation::~RunningAnimation() { }
972 978
973 } // namespace ui 979 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698