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

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

Issue 1131593007: NOT FOR REVIEW Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 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
« no previous file with comments | « cc/animation/animation_host.h ('k') | cc/animation/animation_host_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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "cc/animation/animation_host.h"
6
7 #include <algorithm>
8
9 #include "cc/animation/animation_player.h"
10 #include "cc/animation/animation_registrar.h"
11 #include "cc/animation/animation_timeline.h"
12 #include "cc/trees/layer_tree_mutators_client.h"
13
14 namespace cc {
15
16 scoped_ptr<AnimationHost> AnimationHost::Create(bool is_impl_instance) {
17 return make_scoped_ptr(new AnimationHost(is_impl_instance));
18 }
19
20 AnimationHost::AnimationHost(bool is_impl_instance)
21 : animation_registrar_(AnimationRegistrar::Create()),
22 layer_tree_mutators_client_(),
23 is_impl_instance_(is_impl_instance) {
24 }
25
26 AnimationHost::~AnimationHost() {
27 ClearTimelines();
28 DCHECK(!layer_tree_mutators_client());
29 }
30
31 AnimationTimeline* AnimationHost::GetTimelineById(int timeline_id) const {
32 for (auto& timeline : timelines_)
33 if (timeline->id() == timeline_id)
34 return timeline.get();
35 return nullptr;
36 }
37
38 void AnimationHost::ClearTimelines() {
39 EraseTimelines(timelines_.begin(), timelines_.end());
40 }
41
42 void AnimationHost::EraseTimelines(AnimationTimelineList::iterator begin,
43 AnimationTimelineList::iterator end) {
44 for (auto i = begin; i != end; ++i) {
45 auto& timeline = *i;
46 timeline->ClearPlayers();
47 timeline->SetAnimationHost(nullptr);
48 }
49
50 timelines_.erase(begin, end);
51 }
52
53 void AnimationHost::AddAnimationTimeline(
54 scoped_refptr<AnimationTimeline> timeline) {
55 timeline->SetAnimationHost(this);
56 timelines_.push_back(timeline);
57 }
58
59 void AnimationHost::RemoveAnimationTimeline(
60 scoped_refptr<AnimationTimeline> timeline) {
61 for (auto iter = timelines_.begin(); iter != timelines_.end(); ++iter) {
62 if (iter->get() != timeline)
63 continue;
64
65 EraseTimelines(iter, iter + 1);
66 break;
67 }
68 }
69
70 void AnimationHost::RegisterLayer(int layer_id, bool is_active_tree) {
71 AnimationPlayer* player = GetPlayerForLayerId(layer_id);
72 if (player)
73 player->LayerRegistered(layer_id, is_active_tree);
74 }
75
76 void AnimationHost::UnregisterLayer(int layer_id, bool is_active_tree) {
77 AnimationPlayer* player = GetPlayerForLayerId(layer_id);
78 if (player)
79 player->LayerUnregistered(layer_id, is_active_tree);
80 }
81
82 void AnimationHost::RegisterPlayerForLayer(int layer_id,
83 AnimationPlayer* player) {
84 DCHECK(layer_id);
85 DCHECK(player);
86 layer_to_player_map_[layer_id] = player;
87 }
88
89 void AnimationHost::UnregisterPlayerForLayer(int layer_id,
90 AnimationPlayer* player) {
91 DCHECK(layer_id);
92 DCHECK(player);
93 auto iter = layer_to_player_map_.find(layer_id);
94 if (iter != layer_to_player_map_.end() && iter->second == player)
95 layer_to_player_map_.erase(iter);
96 }
97
98 void AnimationHost::SetLayerTreeMutatorsClient(
99 LayerTreeMutatorsClient* client) {
100 if (layer_tree_mutators_client_ == client)
101 return;
102
103 layer_tree_mutators_client_ = client;
104 }
105
106 void AnimationHost::SetNeedsCommit() {
107 DCHECK(layer_tree_mutators_client_);
108 layer_tree_mutators_client_->SetMutatorsNeedCommit();
109 }
110
111 void AnimationHost::PushPropertiesTo(AnimationHost* host_impl) {
112 PushTimelinesToImplThread(host_impl);
113 RemoveTimelinesFromImplThread(host_impl);
114 PushPropertiesToImplThread(host_impl);
115 }
116
117 void AnimationHost::PushTimelinesToImplThread(AnimationHost* host_impl) const {
118 for (auto& timeline : timelines_) {
119 AnimationTimeline* timeline_impl =
120 host_impl->GetTimelineById(timeline->id());
121 if (timeline_impl)
122 continue;
123
124 scoped_refptr<AnimationTimeline> to_add = timeline->CreateImplInstance();
125 host_impl->AddAnimationTimeline(to_add.get());
126 }
127 }
128
129 void AnimationHost::RemoveTimelinesFromImplThread(
130 AnimationHost* host_impl) const {
131 AnimationTimelineList& timelines_impl = host_impl->timelines_;
132
133 auto to_erase =
134 std::partition(timelines_impl.begin(), timelines_impl.end(),
135 [this](AnimationTimelineList::value_type timeline_impl) {
136 return timeline_impl->is_impl_only() ||
137 GetTimelineById(timeline_impl->id());
138 });
139
140 host_impl->EraseTimelines(to_erase, timelines_impl.end());
141 }
142
143 void AnimationHost::PushPropertiesToImplThread(AnimationHost* host_impl) {
144 for (auto& timeline : timelines_) {
145 AnimationTimeline* timeline_impl =
146 host_impl->GetTimelineById(timeline->id());
147 if (timeline_impl)
148 timeline->PushPropertiesTo(timeline_impl);
149 }
150 }
151
152 AnimationPlayer* AnimationHost::GetPlayerForLayerId(int layer_id) const {
153 DCHECK(layer_id);
154 auto iter = layer_to_player_map_.find(layer_id);
155 return iter == layer_to_player_map_.end() ? nullptr : iter->second;
156 }
157
158 } // namespace cc
OLDNEW
« no previous file with comments | « cc/animation/animation_host.h ('k') | cc/animation/animation_host_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698