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

Side by Side Diff: cc/layers/layer.cc

Issue 13465014: LayerTreeHost::SetAnimationEvents should use AnimationRegistrar (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased Created 7 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 | Annotate | Revision Log
« no previous file with comments | « cc/layers/layer.h ('k') | cc/layers/layer_impl.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 2010 The Chromium Authors. All rights reserved. 1 // Copyright 2010 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/layers/layer.h" 5 #include "cc/layers/layer.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/metrics/histogram.h" 9 #include "base/metrics/histogram.h"
10 #include "cc/animation/animation.h" 10 #include "cc/animation/animation.h"
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 contents_opaque_(false), 48 contents_opaque_(false),
49 double_sided_(true), 49 double_sided_(true),
50 preserves_3d_(false), 50 preserves_3d_(false),
51 use_parent_backface_visibility_(false), 51 use_parent_backface_visibility_(false),
52 draw_checkerboard_for_missing_tiles_(false), 52 draw_checkerboard_for_missing_tiles_(false),
53 force_render_surface_(false), 53 force_render_surface_(false),
54 replica_layer_(NULL), 54 replica_layer_(NULL),
55 raster_scale_(1.f), 55 raster_scale_(1.f),
56 automatically_compute_raster_scale_(false), 56 automatically_compute_raster_scale_(false),
57 bounds_contain_page_scale_(false), 57 bounds_contain_page_scale_(false),
58 layer_animation_delegate_(NULL),
59 layer_scroll_client_(NULL) { 58 layer_scroll_client_(NULL) {
60 if (layer_id_ < 0) { 59 if (layer_id_ < 0) {
61 s_next_layer_id = 1; 60 s_next_layer_id = 1;
62 layer_id_ = s_next_layer_id++; 61 layer_id_ = s_next_layer_id++;
63 } 62 }
64 63
65 layer_animation_controller_ = LayerAnimationController::Create(layer_id_); 64 layer_animation_controller_ = LayerAnimationController::Create(layer_id_);
66 layer_animation_controller_->AddObserver(this); 65 layer_animation_controller_->AddValueObserver(this);
67 AddLayerAnimationEventObserver(layer_animation_controller_.get());
68 } 66 }
69 67
70 Layer::~Layer() { 68 Layer::~Layer() {
71 // Our parent should be holding a reference to us so there should be no 69 // Our parent should be holding a reference to us so there should be no
72 // way for us to be destroyed while we still have a parent. 70 // way for us to be destroyed while we still have a parent.
73 DCHECK(!parent()); 71 DCHECK(!parent());
74 72
75 layer_animation_controller_->RemoveObserver(this); 73 layer_animation_controller_->RemoveValueObserver(this);
76 74
77 // Remove the parent reference from all children and dependents. 75 // Remove the parent reference from all children and dependents.
78 RemoveAllChildren(); 76 RemoveAllChildren();
79 if (mask_layer_) { 77 if (mask_layer_) {
80 DCHECK_EQ(this, mask_layer_->parent()); 78 DCHECK_EQ(this, mask_layer_->parent());
81 mask_layer_->RemoveFromParent(); 79 mask_layer_->RemoveFromParent();
82 } 80 }
83 if (replica_layer_) { 81 if (replica_layer_) {
84 DCHECK_EQ(this, replica_layer_->parent()); 82 DCHECK_EQ(this, replica_layer_->parent());
85 replica_layer_->RemoveFromParent(); 83 replica_layer_->RemoveFromParent();
86 } 84 }
87 } 85 }
88 86
89 void Layer::SetLayerTreeHost(LayerTreeHost* host) { 87 void Layer::SetLayerTreeHost(LayerTreeHost* host) {
90 if (layer_tree_host_ == host) 88 if (layer_tree_host_ == host)
91 return; 89 return;
92 90
93 layer_tree_host_ = host; 91 layer_tree_host_ = host;
94 92
95 for (size_t i = 0; i < children_.size(); ++i) 93 for (size_t i = 0; i < children_.size(); ++i)
96 children_[i]->SetLayerTreeHost(host); 94 children_[i]->SetLayerTreeHost(host);
97 95
98 if (mask_layer_) 96 if (mask_layer_)
99 mask_layer_->SetLayerTreeHost(host); 97 mask_layer_->SetLayerTreeHost(host);
100 if (replica_layer_) 98 if (replica_layer_)
101 replica_layer_->SetLayerTreeHost(host); 99 replica_layer_->SetLayerTreeHost(host);
102 100
103 layer_animation_controller_->SetAnimationRegistrar( 101 if (host) {
104 host ? host->animation_registrar() : NULL); 102 layer_animation_controller_->SetAnimationRegistrar(
103 host->animation_registrar());
104 }
105 105
106 if (host && layer_animation_controller_->has_any_animation()) 106 if (host && layer_animation_controller_->has_any_animation())
107 host->SetNeedsCommit(); 107 host->SetNeedsCommit();
108 if (host && 108 if (host &&
109 (!filters_.isEmpty() || !background_filters_.isEmpty() || filter_)) 109 (!filters_.isEmpty() || !background_filters_.isEmpty() || filter_))
110 layer_tree_host_->set_needs_filter_context(); 110 layer_tree_host_->set_needs_filter_context();
111 } 111 }
112 112
113 void Layer::SetNeedsCommit() { 113 void Layer::SetNeedsCommit() {
114 if (ignore_set_needs_commit_) 114 if (ignore_set_needs_commit_)
(...skipping 622 matching lines...) Expand 10 before | Expand all | Expand 10 after
737 void Layer::PauseAnimation(int animation_id, double time_offset) { 737 void Layer::PauseAnimation(int animation_id, double time_offset) {
738 layer_animation_controller_->PauseAnimation(animation_id, time_offset); 738 layer_animation_controller_->PauseAnimation(animation_id, time_offset);
739 SetNeedsCommit(); 739 SetNeedsCommit();
740 } 740 }
741 741
742 void Layer::RemoveAnimation(int animation_id) { 742 void Layer::RemoveAnimation(int animation_id) {
743 layer_animation_controller_->RemoveAnimation(animation_id); 743 layer_animation_controller_->RemoveAnimation(animation_id);
744 SetNeedsCommit(); 744 SetNeedsCommit();
745 } 745 }
746 746
747 void Layer::TransferAnimationsTo(Layer* layer) {
748 layer_animation_controller_->TransferAnimationsTo(
749 layer->layer_animation_controller());
750 }
751
747 void Layer::SuspendAnimations(double monotonic_time) { 752 void Layer::SuspendAnimations(double monotonic_time) {
748 layer_animation_controller_->SuspendAnimations(monotonic_time); 753 layer_animation_controller_->SuspendAnimations(monotonic_time);
749 SetNeedsCommit(); 754 SetNeedsCommit();
750 } 755 }
751 756
752 void Layer::ResumeAnimations(double monotonic_time) { 757 void Layer::ResumeAnimations(double monotonic_time) {
753 layer_animation_controller_->ResumeAnimations(monotonic_time); 758 layer_animation_controller_->ResumeAnimations(monotonic_time);
754 SetNeedsCommit(); 759 SetNeedsCommit();
755 } 760 }
756 761
757 void Layer::SetLayerAnimationController( 762 void Layer::SetLayerAnimationControllerForTest(
758 scoped_refptr<LayerAnimationController> controller) { 763 scoped_refptr<LayerAnimationController> controller) {
759 RemoveLayerAnimationEventObserver(layer_animation_controller_.get()); 764 layer_animation_controller_->RemoveValueObserver(this);
760 layer_animation_controller_->RemoveObserver(this);
761 layer_animation_controller_ = controller; 765 layer_animation_controller_ = controller;
762 layer_animation_controller_->set_force_sync(); 766 layer_animation_controller_->set_force_sync();
763 layer_animation_controller_->AddObserver(this); 767 layer_animation_controller_->AddValueObserver(this);
764 AddLayerAnimationEventObserver(layer_animation_controller_.get());
765 SetNeedsCommit(); 768 SetNeedsCommit();
766 } 769 }
767 770
768 scoped_refptr<LayerAnimationController>
769 Layer::ReleaseLayerAnimationController() {
770 layer_animation_controller_->RemoveObserver(this);
771 scoped_refptr<LayerAnimationController> to_return =
772 layer_animation_controller_;
773 layer_animation_controller_ = LayerAnimationController::Create(id());
774 layer_animation_controller_->AddObserver(this);
775 layer_animation_controller_->SetAnimationRegistrar(
776 to_return->animation_registrar());
777 return to_return;
778 }
779
780 bool Layer::HasActiveAnimation() const { 771 bool Layer::HasActiveAnimation() const {
781 return layer_animation_controller_->HasActiveAnimation(); 772 return layer_animation_controller_->HasActiveAnimation();
782 } 773 }
783 774
784 void Layer::NotifyAnimationStarted(const AnimationEvent& event,
785 double wall_clock_time) {
786 FOR_EACH_OBSERVER(LayerAnimationEventObserver, layer_animation_observers_,
787 OnAnimationStarted(event));
788 if (layer_animation_delegate_)
789 layer_animation_delegate_->notifyAnimationStarted(wall_clock_time);
790 }
791
792 void Layer::NotifyAnimationFinished(double wall_clock_time) {
793 if (layer_animation_delegate_)
794 layer_animation_delegate_->notifyAnimationFinished(wall_clock_time);
795 }
796
797 void Layer::NotifyAnimationPropertyUpdate(const AnimationEvent& event) {
798 if (event.target_property == Animation::Opacity)
799 SetOpacity(event.opacity);
800 else
801 SetTransform(event.transform);
802 }
803
804 void Layer::AddLayerAnimationEventObserver( 775 void Layer::AddLayerAnimationEventObserver(
805 LayerAnimationEventObserver* animation_observer) { 776 LayerAnimationEventObserver* animation_observer) {
806 if (!layer_animation_observers_.HasObserver(animation_observer)) 777 layer_animation_controller_->AddEventObserver(animation_observer);
807 layer_animation_observers_.AddObserver(animation_observer);
808 } 778 }
809 779
810 void Layer::RemoveLayerAnimationEventObserver( 780 void Layer::RemoveLayerAnimationEventObserver(
811 LayerAnimationEventObserver* animation_observer) { 781 LayerAnimationEventObserver* animation_observer) {
812 layer_animation_observers_.RemoveObserver(animation_observer); 782 layer_animation_controller_->RemoveEventObserver(animation_observer);
813 } 783 }
814 784
815 Region Layer::VisibleContentOpaqueRegion() const { 785 Region Layer::VisibleContentOpaqueRegion() const {
816 if (contents_opaque()) 786 if (contents_opaque())
817 return visible_content_rect(); 787 return visible_content_rect();
818 return Region(); 788 return Region();
819 } 789 }
820 790
821 ScrollbarLayer* Layer::ToScrollbarLayer() { 791 ScrollbarLayer* Layer::ToScrollbarLayer() {
822 return NULL; 792 return NULL;
823 } 793 }
824 794
825 RenderingStatsInstrumentation* Layer::rendering_stats_instrumentation() const { 795 RenderingStatsInstrumentation* Layer::rendering_stats_instrumentation() const {
826 return layer_tree_host_->rendering_stats_instrumentation(); 796 return layer_tree_host_->rendering_stats_instrumentation();
827 } 797 }
828 798
829 } // namespace cc 799 } // namespace cc
OLDNEW
« no previous file with comments | « cc/layers/layer.h ('k') | cc/layers/layer_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698