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