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

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

Issue 947033002: CC Animations: Establish AnimationHost, AnimationTimeline and AnimationPlayer (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Set up impl-only timelines for ScrollOffset animations Created 5 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_id_provider.h » ('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 DCHECK(!layer_tree_mutators_client());
28
29 for (auto& timeline : timelines_)
30 timeline->SetAnimationHost(nullptr);
31 }
32
33 AnimationTimeline* AnimationHost::GetTimelineById(int timeline_id) const {
34 for (auto& timeline : timelines_)
35 if (timeline->id() == timeline_id)
36 return timeline.get();
37 return nullptr;
38 }
39
40 void AnimationHost::ClearTimelines() {
41 for (auto& timeline : timelines_)
42 timeline->ClearPlayers();
43
44 EraseTimelines(timelines_.begin(), timelines_.end());
45 }
46
47 void AnimationHost::EraseTimelines(AnimationTimelineList::iterator begin,
48 AnimationTimelineList::iterator end) {
49 for (auto i = begin; i != end; ++i) {
50 auto& timeline = *i;
51 timeline->ClearPlayers();
52 timeline->SetAnimationHost(nullptr);
53 }
54
55 timelines_.erase(begin, end);
56 }
57
58 void AnimationHost::AddAnimationTimeline(AnimationTimeline* timeline) {
59 timeline->SetAnimationHost(this);
60 timelines_.push_back(timeline);
61 }
62
63 void AnimationHost::RemoveAnimationTimeline(AnimationTimeline* timeline) {
64 for (auto iter = timelines_.begin(); iter != timelines_.end(); ++iter) {
65 if (iter->get() != timeline)
66 continue;
67
68 EraseTimelines(iter, iter + 1);
69 break;
70 }
71 }
72
73 void AnimationHost::RegisterLayerImpl(int layer_id, bool is_active_tree) {
74 AnimationPlayer* player = GetPlayerForLayerId(layer_id);
75 if (player)
76 player->LayerImplRegistered(layer_id, is_active_tree);
77 }
78
79 void AnimationHost::UnregisterLayerImpl(int layer_id, bool is_active_tree) {
80 AnimationPlayer* player = GetPlayerForLayerId(layer_id);
81 if (player)
82 player->LayerImplUnregistered(layer_id, is_active_tree);
83 }
84
85 void AnimationHost::RegisterPlayerForLayer(int layer_id,
86 AnimationPlayer* player) {
87 DCHECK(layer_id);
88 DCHECK(player);
89 layer_to_player_map_[layer_id] = player;
90 }
91
92 void AnimationHost::UnregisterPlayerForLayer(int layer_id,
93 AnimationPlayer* player) {
94 DCHECK(layer_id);
95 DCHECK(player);
96 auto iter = layer_to_player_map_.find(layer_id);
97 if (iter != layer_to_player_map_.end() && iter->second == player)
98 layer_to_player_map_.erase(iter);
99 }
100
101 void AnimationHost::SetLayerTreeMutatorsClient(
102 LayerTreeMutatorsClient* client) {
103 if (layer_tree_mutators_client_ == client)
104 return;
105
106 layer_tree_mutators_client_ = client;
107 }
108
109 void AnimationHost::SetNeedsCommit() {
110 DCHECK(layer_tree_mutators_client_);
111 layer_tree_mutators_client_->SetMutatorsNeedCommit();
112 }
113
114 void AnimationHost::PushPropertiesTo(AnimationHost* host_impl) {
115 PushTimelinesToImplThread(host_impl);
116 RemoveTimelinesFromImplThread(host_impl);
117 PushPropertiesToImplThread(host_impl);
118 }
119
120 void AnimationHost::PushTimelinesToImplThread(AnimationHost* host_impl) const {
121 for (auto& timeline : timelines_) {
122 AnimationTimeline* timeline_impl =
123 host_impl->GetTimelineById(timeline->id());
124 if (timeline_impl)
125 continue;
126
127 scoped_refptr<AnimationTimeline> to_add = timeline->CreateImplInstance();
128 host_impl->AddAnimationTimeline(to_add.get());
129 }
130 }
131
132 void AnimationHost::RemoveTimelinesFromImplThread(
133 AnimationHost* host_impl) const {
134 AnimationTimelineList& timelines_impl = host_impl->timelines_;
135
136 auto to_erase =
137 std::partition(timelines_impl.begin(), timelines_impl.end(),
138 [this](AnimationTimelineList::value_type timeline_impl) {
139 return timeline_impl->is_impl_only() ||
140 GetTimelineById(timeline_impl->id());
141 });
142
143 host_impl->EraseTimelines(to_erase, timelines_impl.end());
144 }
145
146 void AnimationHost::PushPropertiesToImplThread(AnimationHost* host_impl) {
147 for (auto& timeline : timelines_) {
148 AnimationTimeline* timeline_impl =
149 host_impl->GetTimelineById(timeline->id());
150 if (timeline_impl)
151 timeline->PushPropertiesTo(timeline_impl);
152 }
153 }
154
155 AnimationPlayer* AnimationHost::GetPlayerForLayerId(int layer_id) const {
156 DCHECK(layer_id);
157 auto iter = layer_to_player_map_.find(layer_id);
158 return iter == layer_to_player_map_.end() ? nullptr : iter->second;
159 }
160
161 } // namespace cc
OLDNEW
« no previous file with comments | « cc/animation/animation_host.h ('k') | cc/animation/animation_id_provider.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698