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

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

Issue 2538973002: CC Animation: Make AnimationPlayer to be a unit of activation. (Closed)
Patch Set: Move ScrollOffsetAnimationWasInterrupted to AnimationPlayer Created 4 years 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_player.h » ('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 "base/memory/ptr_util.h" 10 #include "base/memory/ptr_util.h"
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 DCHECK(player); 147 DCHECK(player);
148 148
149 scoped_refptr<ElementAnimations> element_animations = 149 scoped_refptr<ElementAnimations> element_animations =
150 GetElementAnimationsForElementId(element_id); 150 GetElementAnimationsForElementId(element_id);
151 DCHECK(element_animations); 151 DCHECK(element_animations);
152 element_animations->RemovePlayer(player); 152 element_animations->RemovePlayer(player);
153 153
154 if (element_animations->IsEmpty()) { 154 if (element_animations->IsEmpty()) {
155 element_animations->ClearAffectedElementTypes(); 155 element_animations->ClearAffectedElementTypes();
156 element_to_animations_map_.erase(element_animations->element_id()); 156 element_to_animations_map_.erase(element_animations->element_id());
157 DidDeactivateElementAnimations(element_animations.get());
158 element_animations->SetAnimationHost(nullptr); 157 element_animations->SetAnimationHost(nullptr);
159 } 158 }
159
160 DeactivateAnimationPlayer(player);
160 } 161 }
161 162
162 void AnimationHost::SetMutatorHostClient(MutatorHostClient* client) { 163 void AnimationHost::SetMutatorHostClient(MutatorHostClient* client) {
163 if (mutator_host_client_ == client) 164 if (mutator_host_client_ == client)
164 return; 165 return;
165 166
166 mutator_host_client_ = client; 167 mutator_host_client_ = client;
167 168
168 if (needs_push_properties() && mutator_host_client()) 169 if (needs_push_properties() && mutator_host_client())
169 SetNeedsPushProperties(); 170 SetNeedsPushProperties();
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
263 void AnimationHost::SetSupportsScrollAnimations( 264 void AnimationHost::SetSupportsScrollAnimations(
264 bool supports_scroll_animations) { 265 bool supports_scroll_animations) {
265 supports_scroll_animations_ = supports_scroll_animations; 266 supports_scroll_animations_ = supports_scroll_animations;
266 } 267 }
267 268
268 bool AnimationHost::SupportsScrollAnimations() const { 269 bool AnimationHost::SupportsScrollAnimations() const {
269 return supports_scroll_animations_; 270 return supports_scroll_animations_;
270 } 271 }
271 272
272 bool AnimationHost::NeedsAnimateLayers() const { 273 bool AnimationHost::NeedsAnimateLayers() const {
273 return !active_element_to_animations_map_.empty(); 274 return !active_players_.empty();
274 } 275 }
275 276
276 bool AnimationHost::ActivateAnimations() { 277 bool AnimationHost::ActivateAnimations() {
277 if (!NeedsAnimateLayers()) 278 if (!NeedsAnimateLayers())
278 return false; 279 return false;
279 280
280 TRACE_EVENT0("cc", "AnimationHost::ActivateAnimations"); 281 TRACE_EVENT0("cc", "AnimationHost::ActivateAnimations");
281 ElementToAnimationsMap active_element_animations_map_copy = 282 PlayersList active_active_players_copy = active_players_;
282 active_element_to_animations_map_; 283 for (auto& it : active_active_players_copy)
283 for (auto& it : active_element_animations_map_copy) 284 it->ActivateAnimations();
284 it.second->ActivateAnimations();
285 285
286 return true; 286 return true;
287 } 287 }
288 288
289 bool AnimationHost::AnimateLayers(base::TimeTicks monotonic_time) { 289 bool AnimationHost::AnimateLayers(base::TimeTicks monotonic_time) {
290 if (!NeedsAnimateLayers()) 290 if (!NeedsAnimateLayers())
291 return false; 291 return false;
292 292
293 TRACE_EVENT0("cc", "AnimationHost::AnimateLayers"); 293 TRACE_EVENT0("cc", "AnimationHost::AnimateLayers");
294 ElementToAnimationsMap active_element_animations_map_copy = 294 PlayersList active_active_players_copy = active_players_;
295 active_element_to_animations_map_; 295 for (auto& it : active_active_players_copy)
296 for (auto& it : active_element_animations_map_copy) 296 it->Animate(monotonic_time);
297 it.second->Animate(monotonic_time);
298 297
299 return true; 298 return true;
300 } 299 }
301 300
302 bool AnimationHost::UpdateAnimationState(bool start_ready_animations, 301 bool AnimationHost::UpdateAnimationState(bool start_ready_animations,
303 MutatorEvents* mutator_events) { 302 MutatorEvents* mutator_events) {
304 if (!NeedsAnimateLayers()) 303 if (!NeedsAnimateLayers())
305 return false; 304 return false;
306 305
307 auto animation_events = static_cast<AnimationEvents*>(mutator_events); 306 auto animation_events = static_cast<AnimationEvents*>(mutator_events);
308 307
309 TRACE_EVENT0("cc", "AnimationHost::UpdateAnimationState"); 308 TRACE_EVENT0("cc", "AnimationHost::UpdateAnimationState");
310 ElementToAnimationsMap active_element_animations_map_copy = 309 PlayersList active_active_players_copy = active_players_;
311 active_element_to_animations_map_; 310 for (auto& it : active_active_players_copy)
312 for (auto& it : active_element_animations_map_copy) 311 it->UpdateState(start_ready_animations, animation_events);
313 it.second->UpdateState(start_ready_animations, animation_events);
314 312
315 return true; 313 return true;
316 } 314 }
317 315
318 std::unique_ptr<MutatorEvents> AnimationHost::CreateEvents() { 316 std::unique_ptr<MutatorEvents> AnimationHost::CreateEvents() {
319 return base::MakeUnique<AnimationEvents>(); 317 return base::MakeUnique<AnimationEvents>();
320 } 318 }
321 319
322 void AnimationHost::SetAnimationEvents( 320 void AnimationHost::SetAnimationEvents(
323 std::unique_ptr<MutatorEvents> mutator_events) { 321 std::unique_ptr<MutatorEvents> mutator_events) {
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
358 break; 356 break;
359 } 357 }
360 } 358 }
361 } 359 }
362 } 360 }
363 361
364 bool AnimationHost::ScrollOffsetAnimationWasInterrupted( 362 bool AnimationHost::ScrollOffsetAnimationWasInterrupted(
365 ElementId element_id) const { 363 ElementId element_id) const {
366 auto element_animations = GetElementAnimationsForElementId(element_id); 364 auto element_animations = GetElementAnimationsForElementId(element_id);
367 return element_animations 365 return element_animations
368 ? element_animations->scroll_offset_animation_was_interrupted() 366 ? element_animations->ScrollOffsetAnimationWasInterrupted()
369 : false; 367 : false;
370 } 368 }
371 369
372 bool AnimationHost::IsAnimatingFilterProperty(ElementId element_id, 370 bool AnimationHost::IsAnimatingFilterProperty(ElementId element_id,
373 ElementListType list_type) const { 371 ElementListType list_type) const {
374 auto element_animations = GetElementAnimationsForElementId(element_id); 372 auto element_animations = GetElementAnimationsForElementId(element_id);
375 return element_animations 373 return element_animations
376 ? element_animations->IsCurrentlyAnimatingProperty( 374 ? element_animations->IsCurrentlyAnimatingProperty(
377 TargetProperty::FILTER, list_type) 375 TargetProperty::FILTER, list_type)
378 : false; 376 : false;
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
552 ScrollOffsetAnimations& AnimationHost::scroll_offset_animations() const { 550 ScrollOffsetAnimations& AnimationHost::scroll_offset_animations() const {
553 DCHECK(scroll_offset_animations_); 551 DCHECK(scroll_offset_animations_);
554 return *scroll_offset_animations_.get(); 552 return *scroll_offset_animations_.get();
555 } 553 }
556 554
557 void AnimationHost::ScrollAnimationAbort(bool needs_completion) { 555 void AnimationHost::ScrollAnimationAbort(bool needs_completion) {
558 DCHECK(scroll_offset_animations_impl_); 556 DCHECK(scroll_offset_animations_impl_);
559 return scroll_offset_animations_impl_->ScrollAnimationAbort(needs_completion); 557 return scroll_offset_animations_impl_->ScrollAnimationAbort(needs_completion);
560 } 558 }
561 559
562 void AnimationHost::DidActivateElementAnimations( 560 void AnimationHost::ActivateAnimationPlayer(
ajuma 2016/11/30 15:34:53 Not related to this CL but something to consider f
563 ElementAnimations* element_animations) { 561 scoped_refptr<AnimationPlayer> player) {
564 DCHECK(element_animations->element_id()); 562 DCHECK(std::find(active_players_.begin(), active_players_.end(), player) ==
565 active_element_to_animations_map_[element_animations->element_id()] = 563 active_players_.end());
566 element_animations; 564 active_players_.push_back(player);
567 } 565 }
568 566
569 void AnimationHost::DidDeactivateElementAnimations( 567 void AnimationHost::DeactivateAnimationPlayer(
570 ElementAnimations* element_animations) { 568 scoped_refptr<AnimationPlayer> player) {
571 DCHECK(element_animations->element_id()); 569 auto to_erase =
572 active_element_to_animations_map_.erase(element_animations->element_id()); 570 std::find(active_players_.begin(), active_players_.end(), player);
571 if (to_erase != active_players_.end())
572 active_players_.erase(to_erase);
573 }
574
575 const AnimationHost::PlayersList& AnimationHost::active_players_for_testing()
576 const {
577 return active_players_;
573 } 578 }
574 579
575 const AnimationHost::ElementToAnimationsMap& 580 const AnimationHost::ElementToAnimationsMap&
576 AnimationHost::active_element_animations_for_testing() const {
577 return active_element_to_animations_map_;
578 }
579
580 const AnimationHost::ElementToAnimationsMap&
581 AnimationHost::all_element_animations_for_testing() const { 581 AnimationHost::all_element_animations_for_testing() const {
582 return element_to_animations_map_; 582 return element_to_animations_map_;
583 } 583 }
584 584
585 } // namespace cc 585 } // namespace cc
OLDNEW
« no previous file with comments | « cc/animation/animation_host.h ('k') | cc/animation/animation_player.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698