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

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

Issue 1881373002: CC Animation: Erase AnimationRegistrar (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@private
Patch Set: Created 4 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_registrar.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"
11 #include "base/trace_event/trace_event.h"
12 #include "base/trace_event/trace_event_argument.h"
11 #include "cc/animation/animation_delegate.h" 13 #include "cc/animation/animation_delegate.h"
12 #include "cc/animation/animation_events.h" 14 #include "cc/animation/animation_events.h"
13 #include "cc/animation/animation_id_provider.h" 15 #include "cc/animation/animation_id_provider.h"
14 #include "cc/animation/animation_player.h" 16 #include "cc/animation/animation_player.h"
15 #include "cc/animation/animation_registrar.h"
16 #include "cc/animation/animation_timeline.h" 17 #include "cc/animation/animation_timeline.h"
17 #include "cc/animation/element_animations.h" 18 #include "cc/animation/element_animations.h"
19 #include "cc/animation/layer_animation_controller.h"
18 #include "cc/animation/scroll_offset_animation_curve.h" 20 #include "cc/animation/scroll_offset_animation_curve.h"
19 #include "cc/animation/timing_function.h" 21 #include "cc/animation/timing_function.h"
20 #include "ui/gfx/geometry/box_f.h" 22 #include "ui/gfx/geometry/box_f.h"
21 #include "ui/gfx/geometry/scroll_offset.h" 23 #include "ui/gfx/geometry/scroll_offset.h"
22 24
23 namespace cc { 25 namespace cc {
24 26
25 class AnimationHost::ScrollOffsetAnimations : public AnimationDelegate { 27 class AnimationHost::ScrollOffsetAnimations : public AnimationDelegate {
26 public: 28 public:
27 explicit ScrollOffsetAnimations(AnimationHost* animation_host) 29 explicit ScrollOffsetAnimations(AnimationHost* animation_host)
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 147
146 DISALLOW_COPY_AND_ASSIGN(ScrollOffsetAnimations); 148 DISALLOW_COPY_AND_ASSIGN(ScrollOffsetAnimations);
147 }; 149 };
148 150
149 std::unique_ptr<AnimationHost> AnimationHost::Create( 151 std::unique_ptr<AnimationHost> AnimationHost::Create(
150 ThreadInstance thread_instance) { 152 ThreadInstance thread_instance) {
151 return base::WrapUnique(new AnimationHost(thread_instance)); 153 return base::WrapUnique(new AnimationHost(thread_instance));
152 } 154 }
153 155
154 AnimationHost::AnimationHost(ThreadInstance thread_instance) 156 AnimationHost::AnimationHost(ThreadInstance thread_instance)
155 : animation_registrar_(AnimationRegistrar::Create()), 157 : mutator_host_client_(nullptr),
156 mutator_host_client_(nullptr), 158 thread_instance_(thread_instance),
157 thread_instance_(thread_instance) { 159 supports_scroll_animations_(false) {
158 if (thread_instance_ == ThreadInstance::IMPL) 160 if (thread_instance_ == ThreadInstance::IMPL)
159 scroll_offset_animations_ = 161 scroll_offset_animations_ =
160 base::WrapUnique(new ScrollOffsetAnimations(this)); 162 base::WrapUnique(new ScrollOffsetAnimations(this));
161 } 163 }
162 164
163 AnimationHost::~AnimationHost() { 165 AnimationHost::~AnimationHost() {
164 scroll_offset_animations_ = nullptr; 166 scroll_offset_animations_ = nullptr;
165 167
166 ClearTimelines(); 168 ClearTimelines();
167 DCHECK(!mutator_host_client()); 169 DCHECK(!mutator_host_client());
168 DCHECK(layer_to_element_animations_map_.empty()); 170 DCHECK(layer_to_element_animations_map_.empty());
171
172 AnimationControllerMap copy = all_animation_controllers_;
173 for (AnimationControllerMap::iterator iter = copy.begin(); iter != copy.end();
174 ++iter)
175 (*iter).second->SetAnimationHost(nullptr);
169 } 176 }
170 177
171 AnimationTimeline* AnimationHost::GetTimelineById(int timeline_id) const { 178 AnimationTimeline* AnimationHost::GetTimelineById(int timeline_id) const {
172 auto f = id_to_timeline_map_.find(timeline_id); 179 auto f = id_to_timeline_map_.find(timeline_id);
173 return f == id_to_timeline_map_.end() ? nullptr : f->second.get(); 180 return f == id_to_timeline_map_.end() ? nullptr : f->second.get();
174 } 181 }
175 182
176 void AnimationHost::ClearTimelines() { 183 void AnimationHost::ClearTimelines() {
177 for (auto& kv : id_to_timeline_map_) 184 for (auto& kv : id_to_timeline_map_)
178 EraseTimeline(kv.second); 185 EraseTimeline(kv.second);
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
336 ElementAnimations* AnimationHost::GetElementAnimationsForLayerId( 343 ElementAnimations* AnimationHost::GetElementAnimationsForLayerId(
337 int layer_id) const { 344 int layer_id) const {
338 DCHECK(layer_id); 345 DCHECK(layer_id);
339 auto iter = layer_to_element_animations_map_.find(layer_id); 346 auto iter = layer_to_element_animations_map_.find(layer_id);
340 return iter == layer_to_element_animations_map_.end() ? nullptr 347 return iter == layer_to_element_animations_map_.end() ? nullptr
341 : iter->second.get(); 348 : iter->second.get();
342 } 349 }
343 350
344 void AnimationHost::SetSupportsScrollAnimations( 351 void AnimationHost::SetSupportsScrollAnimations(
345 bool supports_scroll_animations) { 352 bool supports_scroll_animations) {
346 animation_registrar_->set_supports_scroll_animations( 353 supports_scroll_animations_ = supports_scroll_animations;
347 supports_scroll_animations);
348 } 354 }
349 355
350 bool AnimationHost::SupportsScrollAnimations() const { 356 bool AnimationHost::SupportsScrollAnimations() const {
351 return animation_registrar_->supports_scroll_animations(); 357 return supports_scroll_animations_;
352 } 358 }
353 359
354 bool AnimationHost::NeedsAnimateLayers() const { 360 bool AnimationHost::NeedsAnimateLayers() const {
355 return animation_registrar_->needs_animate_layers(); 361 return !active_animation_controllers_.empty();
356 } 362 }
357 363
358 bool AnimationHost::ActivateAnimations() { 364 bool AnimationHost::ActivateAnimations() {
359 return animation_registrar_->ActivateAnimations(); 365 if (!NeedsAnimateLayers())
366 return false;
367
368 TRACE_EVENT0("cc", "AnimationHost::ActivateAnimations");
369 AnimationControllerMap active_controllers_copy =
370 active_animation_controllers_;
371 for (auto& it : active_controllers_copy)
372 it.second->ActivateAnimations();
373
374 return true;
360 } 375 }
361 376
362 bool AnimationHost::AnimateLayers(base::TimeTicks monotonic_time) { 377 bool AnimationHost::AnimateLayers(base::TimeTicks monotonic_time) {
363 return animation_registrar_->AnimateLayers(monotonic_time); 378 if (!NeedsAnimateLayers())
379 return false;
380
381 TRACE_EVENT0("cc", "AnimationHost::AnimateLayers");
382 AnimationControllerMap controllers_copy = active_animation_controllers_;
383 for (auto& it : controllers_copy)
384 it.second->Animate(monotonic_time);
385
386 return true;
364 } 387 }
365 388
366 bool AnimationHost::UpdateAnimationState(bool start_ready_animations, 389 bool AnimationHost::UpdateAnimationState(bool start_ready_animations,
367 AnimationEvents* events) { 390 AnimationEvents* events) {
368 return animation_registrar_->UpdateAnimationState(start_ready_animations, 391 if (!NeedsAnimateLayers())
369 events); 392 return false;
393
394 TRACE_EVENT0("cc", "AnimationHost::UpdateAnimationState");
395 AnimationControllerMap active_controllers_copy =
396 active_animation_controllers_;
397 for (auto& it : active_controllers_copy)
398 it.second->UpdateState(start_ready_animations, events);
399
400 return true;
370 } 401 }
371 402
372 std::unique_ptr<AnimationEvents> AnimationHost::CreateEvents() { 403 std::unique_ptr<AnimationEvents> AnimationHost::CreateEvents() {
373 return animation_registrar_->CreateEvents(); 404 return base::WrapUnique(new AnimationEvents());
374 } 405 }
375 406
376 void AnimationHost::SetAnimationEvents( 407 void AnimationHost::SetAnimationEvents(
377 std::unique_ptr<AnimationEvents> events) { 408 std::unique_ptr<AnimationEvents> events) {
378 return animation_registrar_->SetAnimationEvents(std::move(events)); 409 for (size_t event_index = 0; event_index < events->events_.size();
410 ++event_index) {
411 int event_layer_id = events->events_[event_index].layer_id;
412
413 // Use the map of all controllers, not just active ones, since non-active
414 // controllers may still receive events for impl-only animations.
415 const AnimationControllerMap& animation_controllers =
416 all_animation_controllers_;
417 auto iter = animation_controllers.find(event_layer_id);
418 if (iter != animation_controllers.end()) {
419 switch (events->events_[event_index].type) {
420 case AnimationEvent::STARTED:
421 (*iter).second->NotifyAnimationStarted(events->events_[event_index]);
422 break;
423
424 case AnimationEvent::FINISHED:
425 (*iter).second->NotifyAnimationFinished(events->events_[event_index]);
426 break;
427
428 case AnimationEvent::ABORTED:
429 (*iter).second->NotifyAnimationAborted(events->events_[event_index]);
430 break;
431
432 case AnimationEvent::PROPERTY_UPDATE:
433 (*iter).second->NotifyAnimationPropertyUpdate(
434 events->events_[event_index]);
435 break;
436
437 case AnimationEvent::TAKEOVER:
438 (*iter).second->NotifyAnimationTakeover(events->events_[event_index]);
439 break;
440 }
441 }
442 }
379 } 443 }
380 444
381 bool AnimationHost::ScrollOffsetAnimationWasInterrupted(int layer_id) const { 445 bool AnimationHost::ScrollOffsetAnimationWasInterrupted(int layer_id) const {
382 LayerAnimationController* controller = GetControllerForLayerId(layer_id); 446 LayerAnimationController* controller = GetControllerForLayerId(layer_id);
383 return controller ? controller->scroll_offset_animation_was_interrupted() 447 return controller ? controller->scroll_offset_animation_was_interrupted()
384 : false; 448 : false;
385 } 449 }
386 450
387 static LayerAnimationController::ObserverType ObserverTypeFromTreeType( 451 static LayerAnimationController::ObserverType ObserverTypeFromTreeType(
388 LayerTreeType tree_type) { 452 LayerTreeType tree_type) {
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
599 layer_id, scroll_delta, max_scroll_offset, frame_monotonic_time); 663 layer_id, scroll_delta, max_scroll_offset, frame_monotonic_time);
600 } 664 }
601 665
602 void AnimationHost::ScrollAnimationAbort(bool needs_completion) { 666 void AnimationHost::ScrollAnimationAbort(bool needs_completion) {
603 DCHECK(scroll_offset_animations_); 667 DCHECK(scroll_offset_animations_);
604 return scroll_offset_animations_->ScrollAnimationAbort(needs_completion); 668 return scroll_offset_animations_->ScrollAnimationAbort(needs_completion);
605 } 669 }
606 670
607 scoped_refptr<LayerAnimationController> 671 scoped_refptr<LayerAnimationController>
608 AnimationHost::GetAnimationControllerForId(int id) { 672 AnimationHost::GetAnimationControllerForId(int id) {
609 return animation_registrar_->GetAnimationControllerForId(id); 673 scoped_refptr<LayerAnimationController> to_return;
674 if (!ContainsKey(all_animation_controllers_, id)) {
675 to_return = LayerAnimationController::Create(id);
676 to_return->SetAnimationHost(this);
677 all_animation_controllers_[id] = to_return.get();
678 } else {
679 to_return = all_animation_controllers_[id];
680 }
681 return to_return;
610 } 682 }
611 683
612 void AnimationHost::SetAnimationRegistrarFor( 684 void AnimationHost::DidActivateAnimationController(
613 scoped_refptr<LayerAnimationController> controller) { 685 LayerAnimationController* controller) {
614 controller->SetAnimationRegistrar(animation_registrar_.get()); 686 active_animation_controllers_[controller->id()] = controller;
615 } 687 }
616 688
617 void AnimationHost::ResetAnimationRegistrarFor( 689 void AnimationHost::DidDeactivateAnimationController(
618 scoped_refptr<LayerAnimationController> controller) { 690 LayerAnimationController* controller) {
619 controller->SetAnimationRegistrar(nullptr); 691 if (ContainsKey(active_animation_controllers_, controller->id()))
692 active_animation_controllers_.erase(controller->id());
620 } 693 }
621 694
622 void AnimationHost::RegisterAnimationController( 695 void AnimationHost::RegisterAnimationController(
623 LayerAnimationController* controller) { 696 LayerAnimationController* controller) {
624 animation_registrar_->RegisterAnimationController(controller); 697 all_animation_controllers_[controller->id()] = controller;
625 } 698 }
626 699
627 void AnimationHost::UnregisterAnimationController( 700 void AnimationHost::UnregisterAnimationController(
628 LayerAnimationController* controller) { 701 LayerAnimationController* controller) {
629 animation_registrar_->UnregisterAnimationController(controller); 702 if (ContainsKey(all_animation_controllers_, controller->id()))
703 all_animation_controllers_.erase(controller->id());
704 DidDeactivateAnimationController(controller);
630 } 705 }
631 706
632 const AnimationHost::AnimationControllerMap& 707 const AnimationHost::AnimationControllerMap&
633 AnimationHost::active_animation_controllers_for_testing() const { 708 AnimationHost::active_animation_controllers_for_testing() const {
634 return animation_registrar_->active_animation_controllers_for_testing(); 709 return active_animation_controllers_;
635 } 710 }
636 711
637 const AnimationHost::AnimationControllerMap& 712 const AnimationHost::AnimationControllerMap&
638 AnimationHost::all_animation_controllers_for_testing() const { 713 AnimationHost::all_animation_controllers_for_testing() const {
639 return animation_registrar_->all_animation_controllers_for_testing(); 714 return all_animation_controllers_;
640 } 715 }
641 716
642 } // namespace cc 717 } // namespace cc
OLDNEW
« no previous file with comments | « cc/animation/animation_host.h ('k') | cc/animation/animation_registrar.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698