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

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

Issue 1894023002: CC Animation: Make ElementAnimations a ref-counted object. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
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_host.h ('k') | cc/animation/animation_player.h » ('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/animation_host.h" 5 #include "cc/animation/animation_host.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/memory/ptr_util.h" 10 #include "base/memory/ptr_util.h"
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 } 199 }
200 200
201 void AnimationHost::RemoveAnimationTimeline( 201 void AnimationHost::RemoveAnimationTimeline(
202 scoped_refptr<AnimationTimeline> timeline) { 202 scoped_refptr<AnimationTimeline> timeline) {
203 DCHECK(timeline->id()); 203 DCHECK(timeline->id());
204 EraseTimeline(timeline); 204 EraseTimeline(timeline);
205 id_to_timeline_map_.erase(timeline->id()); 205 id_to_timeline_map_.erase(timeline->id());
206 } 206 }
207 207
208 void AnimationHost::RegisterLayer(int layer_id, LayerTreeType tree_type) { 208 void AnimationHost::RegisterLayer(int layer_id, LayerTreeType tree_type) {
209 ElementAnimations* element_animations = 209 scoped_refptr<ElementAnimations> element_animations =
210 GetElementAnimationsForLayerId(layer_id); 210 GetElementAnimationsForLayerId(layer_id);
211 if (element_animations) 211 if (element_animations)
212 element_animations->LayerRegistered(layer_id, tree_type); 212 element_animations->LayerRegistered(layer_id, tree_type);
213 } 213 }
214 214
215 void AnimationHost::UnregisterLayer(int layer_id, LayerTreeType tree_type) { 215 void AnimationHost::UnregisterLayer(int layer_id, LayerTreeType tree_type) {
216 ElementAnimations* element_animations = 216 scoped_refptr<ElementAnimations> element_animations =
217 GetElementAnimationsForLayerId(layer_id); 217 GetElementAnimationsForLayerId(layer_id);
218 if (element_animations) 218 if (element_animations)
219 element_animations->LayerUnregistered(layer_id, tree_type); 219 element_animations->LayerUnregistered(layer_id, tree_type);
220 } 220 }
221 221
222 void AnimationHost::RegisterPlayerForLayer(int layer_id, 222 void AnimationHost::RegisterPlayerForLayer(int layer_id,
223 AnimationPlayer* player) { 223 AnimationPlayer* player) {
224 DCHECK(layer_id); 224 DCHECK(layer_id);
225 DCHECK(player); 225 DCHECK(player);
226 226
227 ElementAnimations* element_animations = 227 scoped_refptr<ElementAnimations> element_animations =
228 GetElementAnimationsForLayerId(layer_id); 228 GetElementAnimationsForLayerId(layer_id);
229 if (!element_animations) { 229 if (!element_animations) {
230 auto new_element_animations = ElementAnimations::Create(this); 230 element_animations = ElementAnimations::Create(this);
231 element_animations = new_element_animations.get(); 231 layer_to_element_animations_map_[layer_id] = element_animations;
232 232
233 layer_to_element_animations_map_[layer_id] =
234 std::move(new_element_animations);
235 element_animations->CreateLayerAnimationController(layer_id); 233 element_animations->CreateLayerAnimationController(layer_id);
236 } 234 }
237 235
238 DCHECK(element_animations); 236 DCHECK(element_animations);
239 element_animations->AddPlayer(player); 237 element_animations->AddPlayer(player);
240 } 238 }
241 239
242 void AnimationHost::UnregisterPlayerForLayer(int layer_id, 240 void AnimationHost::UnregisterPlayerForLayer(int layer_id,
243 AnimationPlayer* player) { 241 AnimationPlayer* player) {
244 DCHECK(layer_id); 242 DCHECK(layer_id);
245 DCHECK(player); 243 DCHECK(player);
246 244
247 ElementAnimations* element_animations = 245 scoped_refptr<ElementAnimations> element_animations =
248 GetElementAnimationsForLayerId(layer_id); 246 GetElementAnimationsForLayerId(layer_id);
249 DCHECK(element_animations); 247 DCHECK(element_animations);
250 element_animations->RemovePlayer(player); 248 element_animations->RemovePlayer(player);
251 249
252 if (element_animations->IsEmpty()) { 250 if (element_animations->IsEmpty()) {
253 element_animations->DestroyLayerAnimationController(); 251 element_animations->DestroyLayerAnimationController();
254 layer_to_element_animations_map_.erase(layer_id); 252 layer_to_element_animations_map_.erase(layer_id);
255 element_animations = nullptr;
256 } 253 }
257 } 254 }
258 255
259 void AnimationHost::SetMutatorHostClient(MutatorHostClient* client) { 256 void AnimationHost::SetMutatorHostClient(MutatorHostClient* client) {
260 if (mutator_host_client_ == client) 257 if (mutator_host_client_ == client)
261 return; 258 return;
262 259
263 mutator_host_client_ = client; 260 mutator_host_client_ = client;
264 } 261 }
265 262
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
314 for (auto& kv : id_to_timeline_map_) { 311 for (auto& kv : id_to_timeline_map_) {
315 AnimationTimeline* timeline = kv.second.get(); 312 AnimationTimeline* timeline = kv.second.get();
316 AnimationTimeline* timeline_impl = 313 AnimationTimeline* timeline_impl =
317 host_impl->GetTimelineById(timeline->id()); 314 host_impl->GetTimelineById(timeline->id());
318 if (timeline_impl) 315 if (timeline_impl)
319 timeline->PushPropertiesTo(timeline_impl); 316 timeline->PushPropertiesTo(timeline_impl);
320 } 317 }
321 318
322 // Secondly, sync properties for created layer animation controllers. 319 // Secondly, sync properties for created layer animation controllers.
323 for (auto& kv : layer_to_element_animations_map_) { 320 for (auto& kv : layer_to_element_animations_map_) {
324 ElementAnimations* element_animations = kv.second.get(); 321 const auto& element_animations = kv.second;
325 ElementAnimations* element_animations_impl = 322 auto element_animations_impl =
326 host_impl->GetElementAnimationsForLayerId(kv.first); 323 host_impl->GetElementAnimationsForLayerId(kv.first);
327 if (element_animations_impl) 324 if (element_animations_impl)
328 element_animations->PushPropertiesTo(element_animations_impl); 325 element_animations->PushPropertiesTo(std::move(element_animations_impl));
329 } 326 }
330 } 327 }
331 328
332 LayerAnimationController* AnimationHost::GetControllerForLayerId( 329 LayerAnimationController* AnimationHost::GetControllerForLayerId(
333 int layer_id) const { 330 int layer_id) const {
334 const ElementAnimations* element_animations = 331 const scoped_refptr<ElementAnimations> element_animations =
335 GetElementAnimationsForLayerId(layer_id); 332 GetElementAnimationsForLayerId(layer_id);
336 if (!element_animations) 333 if (!element_animations)
337 return nullptr; 334 return nullptr;
338 335
339 return element_animations->layer_animation_controller_.get(); 336 return element_animations->layer_animation_controller_.get();
340 } 337 }
341 338
342 ElementAnimations* AnimationHost::GetElementAnimationsForLayerId( 339 scoped_refptr<ElementAnimations> AnimationHost::GetElementAnimationsForLayerId(
343 int layer_id) const { 340 int layer_id) const {
344 DCHECK(layer_id); 341 DCHECK(layer_id);
345 auto iter = layer_to_element_animations_map_.find(layer_id); 342 auto iter = layer_to_element_animations_map_.find(layer_id);
346 return iter == layer_to_element_animations_map_.end() ? nullptr 343 return iter == layer_to_element_animations_map_.end() ? nullptr
347 : iter->second.get(); 344 : iter->second;
348 } 345 }
349 346
350 void AnimationHost::SetSupportsScrollAnimations( 347 void AnimationHost::SetSupportsScrollAnimations(
351 bool supports_scroll_animations) { 348 bool supports_scroll_animations) {
352 supports_scroll_animations_ = supports_scroll_animations; 349 supports_scroll_animations_ = supports_scroll_animations;
353 } 350 }
354 351
355 bool AnimationHost::SupportsScrollAnimations() const { 352 bool AnimationHost::SupportsScrollAnimations() const {
356 return supports_scroll_animations_; 353 return supports_scroll_animations_;
357 } 354 }
(...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after
707 AnimationHost::active_animation_controllers_for_testing() const { 704 AnimationHost::active_animation_controllers_for_testing() const {
708 return active_animation_controllers_; 705 return active_animation_controllers_;
709 } 706 }
710 707
711 const AnimationHost::AnimationControllerMap& 708 const AnimationHost::AnimationControllerMap&
712 AnimationHost::all_animation_controllers_for_testing() const { 709 AnimationHost::all_animation_controllers_for_testing() const {
713 return all_animation_controllers_; 710 return all_animation_controllers_;
714 } 711 }
715 712
716 } // namespace cc 713 } // namespace cc
OLDNEW
« no previous file with comments | « cc/animation/animation_host.h ('k') | cc/animation/animation_player.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698