| OLD | NEW |
| 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_timeline.h" | 5 #include "cc/animation/animation_timeline.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "cc/animation/animation_host.h" | |
| 10 #include "cc/animation/animation_player.h" | 9 #include "cc/animation/animation_player.h" |
| 11 | 10 |
| 12 namespace cc { | 11 namespace cc { |
| 13 | 12 |
| 14 scoped_refptr<AnimationTimeline> AnimationTimeline::Create(int id) { | 13 scoped_refptr<AnimationTimeline> AnimationTimeline::Create(int id) { |
| 15 return make_scoped_refptr(new AnimationTimeline(id)); | 14 return make_scoped_refptr(new AnimationTimeline(id)); |
| 16 } | 15 } |
| 17 | 16 |
| 18 AnimationTimeline::AnimationTimeline(int id) | 17 AnimationTimeline::AnimationTimeline(int id) |
| 19 : id_(id), | 18 : id_(id), animation_host_(), is_impl_only_(false) { |
| 20 animation_host_(), | 19 } |
| 21 needs_push_properties_(false), | |
| 22 is_impl_only_(false) {} | |
| 23 | 20 |
| 24 AnimationTimeline::~AnimationTimeline() { | 21 AnimationTimeline::~AnimationTimeline() { |
| 25 for (auto& kv : id_to_player_map_) | 22 for (auto& kv : id_to_player_map_) |
| 26 kv.second->SetAnimationTimeline(nullptr); | 23 kv.second->SetAnimationTimeline(nullptr); |
| 27 } | 24 } |
| 28 | 25 |
| 29 scoped_refptr<AnimationTimeline> AnimationTimeline::CreateImplInstance() const { | 26 scoped_refptr<AnimationTimeline> AnimationTimeline::CreateImplInstance() const { |
| 30 scoped_refptr<AnimationTimeline> timeline = AnimationTimeline::Create(id()); | 27 scoped_refptr<AnimationTimeline> timeline = AnimationTimeline::Create(id()); |
| 31 return timeline; | 28 return timeline; |
| 32 } | 29 } |
| 33 | 30 |
| 34 void AnimationTimeline::SetAnimationHost(AnimationHost* animation_host) { | 31 void AnimationTimeline::SetAnimationHost(AnimationHost* animation_host) { |
| 35 if (animation_host_ == animation_host) | |
| 36 return; | |
| 37 | |
| 38 animation_host_ = animation_host; | 32 animation_host_ = animation_host; |
| 39 for (auto& kv : id_to_player_map_) | 33 for (auto& kv : id_to_player_map_) |
| 40 kv.second->SetAnimationHost(animation_host); | 34 kv.second->SetAnimationHost(animation_host); |
| 41 | |
| 42 SetNeedsPushProperties(); | |
| 43 } | 35 } |
| 44 | 36 |
| 45 void AnimationTimeline::AttachPlayer(scoped_refptr<AnimationPlayer> player) { | 37 void AnimationTimeline::AttachPlayer(scoped_refptr<AnimationPlayer> player) { |
| 46 DCHECK(player->id()); | 38 DCHECK(player->id()); |
| 47 player->SetAnimationHost(animation_host_); | 39 player->SetAnimationHost(animation_host_); |
| 48 player->SetAnimationTimeline(this); | 40 player->SetAnimationTimeline(this); |
| 49 id_to_player_map_.insert(std::make_pair(player->id(), std::move(player))); | 41 id_to_player_map_.insert(std::make_pair(player->id(), std::move(player))); |
| 50 | |
| 51 SetNeedsPushProperties(); | |
| 52 } | 42 } |
| 53 | 43 |
| 54 void AnimationTimeline::DetachPlayer(scoped_refptr<AnimationPlayer> player) { | 44 void AnimationTimeline::DetachPlayer(scoped_refptr<AnimationPlayer> player) { |
| 55 DCHECK(player->id()); | 45 DCHECK(player->id()); |
| 56 ErasePlayer(player); | 46 ErasePlayer(player); |
| 57 id_to_player_map_.erase(player->id()); | 47 id_to_player_map_.erase(player->id()); |
| 58 | |
| 59 SetNeedsPushProperties(); | |
| 60 } | 48 } |
| 61 | 49 |
| 62 AnimationPlayer* AnimationTimeline::GetPlayerById(int player_id) const { | 50 AnimationPlayer* AnimationTimeline::GetPlayerById(int player_id) const { |
| 63 auto f = id_to_player_map_.find(player_id); | 51 auto f = id_to_player_map_.find(player_id); |
| 64 return f == id_to_player_map_.end() ? nullptr : f->second.get(); | 52 return f == id_to_player_map_.end() ? nullptr : f->second.get(); |
| 65 } | 53 } |
| 66 | 54 |
| 67 void AnimationTimeline::ClearPlayers() { | 55 void AnimationTimeline::ClearPlayers() { |
| 68 for (auto& kv : id_to_player_map_) | 56 for (auto& kv : id_to_player_map_) |
| 69 ErasePlayer(kv.second); | 57 ErasePlayer(kv.second); |
| 70 id_to_player_map_.clear(); | 58 id_to_player_map_.clear(); |
| 71 | |
| 72 SetNeedsPushProperties(); | |
| 73 } | |
| 74 | |
| 75 void AnimationTimeline::SetNeedsPushProperties() { | |
| 76 needs_push_properties_ = true; | |
| 77 if (animation_host_) | |
| 78 animation_host_->SetNeedsPushProperties(); | |
| 79 } | 59 } |
| 80 | 60 |
| 81 void AnimationTimeline::PushPropertiesTo(AnimationTimeline* timeline_impl) { | 61 void AnimationTimeline::PushPropertiesTo(AnimationTimeline* timeline_impl) { |
| 82 if (needs_push_properties_) { | 62 PushAttachedPlayersToImplThread(timeline_impl); |
| 83 needs_push_properties_ = false; | 63 RemoveDetachedPlayersFromImplThread(timeline_impl); |
| 84 PushAttachedPlayersToImplThread(timeline_impl); | 64 PushPropertiesToImplThread(timeline_impl); |
| 85 RemoveDetachedPlayersFromImplThread(timeline_impl); | |
| 86 PushPropertiesToImplThread(timeline_impl); | |
| 87 } | |
| 88 } | 65 } |
| 89 | 66 |
| 90 void AnimationTimeline::PushAttachedPlayersToImplThread( | 67 void AnimationTimeline::PushAttachedPlayersToImplThread( |
| 91 AnimationTimeline* timeline_impl) const { | 68 AnimationTimeline* timeline_impl) const { |
| 92 for (auto& kv : id_to_player_map_) { | 69 for (auto& kv : id_to_player_map_) { |
| 93 auto& player = kv.second; | 70 auto& player = kv.second; |
| 94 AnimationPlayer* player_impl = timeline_impl->GetPlayerById(player->id()); | 71 AnimationPlayer* player_impl = timeline_impl->GetPlayerById(player->id()); |
| 95 if (player_impl) | 72 if (player_impl) |
| 96 continue; | 73 continue; |
| 97 | 74 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 119 if (player->element_animations()) | 96 if (player->element_animations()) |
| 120 player->DetachElement(); | 97 player->DetachElement(); |
| 121 player->SetAnimationTimeline(nullptr); | 98 player->SetAnimationTimeline(nullptr); |
| 122 player->SetAnimationHost(nullptr); | 99 player->SetAnimationHost(nullptr); |
| 123 } | 100 } |
| 124 | 101 |
| 125 void AnimationTimeline::PushPropertiesToImplThread( | 102 void AnimationTimeline::PushPropertiesToImplThread( |
| 126 AnimationTimeline* timeline_impl) { | 103 AnimationTimeline* timeline_impl) { |
| 127 for (auto& kv : id_to_player_map_) { | 104 for (auto& kv : id_to_player_map_) { |
| 128 AnimationPlayer* player = kv.second.get(); | 105 AnimationPlayer* player = kv.second.get(); |
| 129 if (player->needs_push_properties()) { | 106 AnimationPlayer* player_impl = timeline_impl->GetPlayerById(player->id()); |
| 130 AnimationPlayer* player_impl = timeline_impl->GetPlayerById(player->id()); | 107 if (player_impl) |
| 131 if (player_impl) | 108 player->PushPropertiesTo(player_impl); |
| 132 player->PushPropertiesTo(player_impl); | |
| 133 } | |
| 134 } | 109 } |
| 135 } | 110 } |
| 136 | 111 |
| 137 } // namespace cc | 112 } // namespace cc |
| OLD | NEW |