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

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

Issue 1814103002: CC Animation: Use unordered_map instead of vector. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Use move semantics on insertions. Created 4 years, 9 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_timeline.cc » ('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 "cc/animation/animation_delegate.h" 10 #include "cc/animation/animation_delegate.h"
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 160
161 AnimationHost::~AnimationHost() { 161 AnimationHost::~AnimationHost() {
162 scroll_offset_animations_ = nullptr; 162 scroll_offset_animations_ = nullptr;
163 163
164 ClearTimelines(); 164 ClearTimelines();
165 DCHECK(!mutator_host_client()); 165 DCHECK(!mutator_host_client());
166 DCHECK(layer_to_element_animations_map_.empty()); 166 DCHECK(layer_to_element_animations_map_.empty());
167 } 167 }
168 168
169 AnimationTimeline* AnimationHost::GetTimelineById(int timeline_id) const { 169 AnimationTimeline* AnimationHost::GetTimelineById(int timeline_id) const {
170 for (auto& timeline : timelines_) 170 auto f = id_to_timeline_map_.find(timeline_id);
171 if (timeline->id() == timeline_id) 171 return f == id_to_timeline_map_.end() ? nullptr : f->second.get();
172 return timeline.get();
173 return nullptr;
174 } 172 }
175 173
176 void AnimationHost::ClearTimelines() { 174 void AnimationHost::ClearTimelines() {
177 EraseTimelines(timelines_.begin(), timelines_.end()); 175 for (auto& kv : id_to_timeline_map_)
176 EraseTimeline(kv.second);
177 id_to_timeline_map_.clear();
178 } 178 }
179 179
180 void AnimationHost::EraseTimelines(AnimationTimelineList::iterator begin, 180 void AnimationHost::EraseTimeline(scoped_refptr<AnimationTimeline> timeline) {
181 AnimationTimelineList::iterator end) { 181 timeline->ClearPlayers();
182 for (auto i = begin; i != end; ++i) { 182 timeline->SetAnimationHost(nullptr);
183 auto& timeline = *i;
184 timeline->ClearPlayers();
185 timeline->SetAnimationHost(nullptr);
186 }
187
188 timelines_.erase(begin, end);
189 } 183 }
190 184
191 void AnimationHost::AddAnimationTimeline( 185 void AnimationHost::AddAnimationTimeline(
192 scoped_refptr<AnimationTimeline> timeline) { 186 scoped_refptr<AnimationTimeline> timeline) {
187 DCHECK(timeline->id());
193 timeline->SetAnimationHost(this); 188 timeline->SetAnimationHost(this);
194 timelines_.push_back(timeline); 189 id_to_timeline_map_.insert(
190 std::make_pair(timeline->id(), std::move(timeline)));
195 } 191 }
196 192
197 void AnimationHost::RemoveAnimationTimeline( 193 void AnimationHost::RemoveAnimationTimeline(
198 scoped_refptr<AnimationTimeline> timeline) { 194 scoped_refptr<AnimationTimeline> timeline) {
199 for (auto iter = timelines_.begin(); iter != timelines_.end(); ++iter) { 195 DCHECK(timeline->id());
200 if (iter->get() != timeline) 196 EraseTimeline(timeline);
201 continue; 197 id_to_timeline_map_.erase(timeline->id());
202
203 EraseTimelines(iter, iter + 1);
204 break;
205 }
206 } 198 }
207 199
208 void AnimationHost::RegisterLayer(int layer_id, LayerTreeType tree_type) { 200 void AnimationHost::RegisterLayer(int layer_id, LayerTreeType tree_type) {
209 ElementAnimations* element_animations = 201 ElementAnimations* element_animations =
210 GetElementAnimationsForLayerId(layer_id); 202 GetElementAnimationsForLayerId(layer_id);
211 if (element_animations) 203 if (element_animations)
212 element_animations->LayerRegistered(layer_id, tree_type); 204 element_animations->LayerRegistered(layer_id, tree_type);
213 } 205 }
214 206
215 void AnimationHost::UnregisterLayer(int layer_id, LayerTreeType tree_type) { 207 void AnimationHost::UnregisterLayer(int layer_id, LayerTreeType tree_type) {
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
273 mutator_host_client_->SetMutatorsNeedRebuildPropertyTrees(); 265 mutator_host_client_->SetMutatorsNeedRebuildPropertyTrees();
274 } 266 }
275 267
276 void AnimationHost::PushPropertiesTo(AnimationHost* host_impl) { 268 void AnimationHost::PushPropertiesTo(AnimationHost* host_impl) {
277 PushTimelinesToImplThread(host_impl); 269 PushTimelinesToImplThread(host_impl);
278 RemoveTimelinesFromImplThread(host_impl); 270 RemoveTimelinesFromImplThread(host_impl);
279 PushPropertiesToImplThread(host_impl); 271 PushPropertiesToImplThread(host_impl);
280 } 272 }
281 273
282 void AnimationHost::PushTimelinesToImplThread(AnimationHost* host_impl) const { 274 void AnimationHost::PushTimelinesToImplThread(AnimationHost* host_impl) const {
283 for (auto& timeline : timelines_) { 275 for (auto& kv : id_to_timeline_map_) {
276 auto& timeline = kv.second;
284 AnimationTimeline* timeline_impl = 277 AnimationTimeline* timeline_impl =
285 host_impl->GetTimelineById(timeline->id()); 278 host_impl->GetTimelineById(timeline->id());
286 if (timeline_impl) 279 if (timeline_impl)
287 continue; 280 continue;
288 281
289 scoped_refptr<AnimationTimeline> to_add = timeline->CreateImplInstance(); 282 scoped_refptr<AnimationTimeline> to_add = timeline->CreateImplInstance();
290 host_impl->AddAnimationTimeline(to_add.get()); 283 host_impl->AddAnimationTimeline(to_add.get());
291 } 284 }
292 } 285 }
293 286
294 void AnimationHost::RemoveTimelinesFromImplThread( 287 void AnimationHost::RemoveTimelinesFromImplThread(
295 AnimationHost* host_impl) const { 288 AnimationHost* host_impl) const {
296 AnimationTimelineList& timelines_impl = host_impl->timelines_; 289 IdToTimelineMap& timelines_impl = host_impl->id_to_timeline_map_;
297 290
298 auto to_erase = 291 // Erase all the impl timelines which |this| doesn't have.
299 std::partition(timelines_impl.begin(), timelines_impl.end(), 292 for (auto it = timelines_impl.begin(); it != timelines_impl.end();) {
300 [this](AnimationTimelineList::value_type timeline_impl) { 293 auto& timeline_impl = it->second;
301 return timeline_impl->is_impl_only() || 294 if (timeline_impl->is_impl_only() || GetTimelineById(timeline_impl->id())) {
302 GetTimelineById(timeline_impl->id()); 295 ++it;
303 }); 296 } else {
304 297 host_impl->EraseTimeline(it->second);
305 host_impl->EraseTimelines(to_erase, timelines_impl.end()); 298 it = timelines_impl.erase(it);
299 }
300 }
306 } 301 }
307 302
308 void AnimationHost::PushPropertiesToImplThread(AnimationHost* host_impl) { 303 void AnimationHost::PushPropertiesToImplThread(AnimationHost* host_impl) {
309 // Firstly, sync all players with impl thread to create ElementAnimations and 304 // Firstly, sync all players with impl thread to create ElementAnimations and
310 // layer animation controllers. 305 // layer animation controllers.
311 for (auto& timeline : timelines_) { 306 for (auto& kv : id_to_timeline_map_) {
307 AnimationTimeline* timeline = kv.second.get();
312 AnimationTimeline* timeline_impl = 308 AnimationTimeline* timeline_impl =
313 host_impl->GetTimelineById(timeline->id()); 309 host_impl->GetTimelineById(timeline->id());
314 if (timeline_impl) 310 if (timeline_impl)
315 timeline->PushPropertiesTo(timeline_impl); 311 timeline->PushPropertiesTo(timeline_impl);
316 } 312 }
317 313
318 // Secondly, sync properties for created layer animation controllers. 314 // Secondly, sync properties for created layer animation controllers.
319 for (auto& kv : layer_to_element_animations_map_) { 315 for (auto& kv : layer_to_element_animations_map_) {
320 ElementAnimations* element_animations = kv.second.get(); 316 ElementAnimations* element_animations = kv.second.get();
321 ElementAnimations* element_animations_impl = 317 ElementAnimations* element_animations_impl =
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after
599 return scroll_offset_animations_->ScrollAnimationUpdateTarget( 595 return scroll_offset_animations_->ScrollAnimationUpdateTarget(
600 layer_id, scroll_delta, max_scroll_offset, frame_monotonic_time); 596 layer_id, scroll_delta, max_scroll_offset, frame_monotonic_time);
601 } 597 }
602 598
603 void AnimationHost::ScrollAnimationAbort(bool needs_completion) { 599 void AnimationHost::ScrollAnimationAbort(bool needs_completion) {
604 DCHECK(scroll_offset_animations_); 600 DCHECK(scroll_offset_animations_);
605 return scroll_offset_animations_->ScrollAnimationAbort(needs_completion); 601 return scroll_offset_animations_->ScrollAnimationAbort(needs_completion);
606 } 602 }
607 603
608 } // namespace cc 604 } // namespace cc
OLDNEW
« no previous file with comments | « cc/animation/animation_host.h ('k') | cc/animation/animation_timeline.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698