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

Side by Side Diff: ui/compositor/layer.cc

Issue 311783002: Revert r274404 and r274409: (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 6 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 | « ui/compositor/layer.h ('k') | ui/compositor/layer_animation_delegate.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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "ui/compositor/layer.h" 5 #include "ui/compositor/layer.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/debug/trace_event.h" 10 #include "base/debug/trace_event.h"
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 float Layer::opacity() const { 135 float Layer::opacity() const {
136 return cc_layer_->opacity(); 136 return cc_layer_->opacity();
137 } 137 }
138 138
139 void Layer::SetCompositor(Compositor* compositor) { 139 void Layer::SetCompositor(Compositor* compositor) {
140 // This function must only be called to set the compositor on the root layer, 140 // This function must only be called to set the compositor on the root layer,
141 // or to reset it. 141 // or to reset it.
142 DCHECK(!compositor || !compositor_); 142 DCHECK(!compositor || !compositor_);
143 DCHECK(!compositor || compositor->root_layer() == this); 143 DCHECK(!compositor || compositor->root_layer() == this);
144 DCHECK(!parent_); 144 DCHECK(!parent_);
145 if (compositor_) {
146 RemoveAnimatorsInTreeFromCollection(
147 compositor_->layer_animator_collection());
148 }
149 compositor_ = compositor; 145 compositor_ = compositor;
150 if (compositor) { 146 if (compositor) {
151 OnDeviceScaleFactorChanged(compositor->device_scale_factor()); 147 OnDeviceScaleFactorChanged(compositor->device_scale_factor());
152 SendPendingThreadedAnimations(); 148 SendPendingThreadedAnimations();
153 AddAnimatorsInTreeToCollection(compositor_->layer_animator_collection());
154 } 149 }
155 } 150 }
156 151
157 void Layer::Add(Layer* child) { 152 void Layer::Add(Layer* child) {
158 DCHECK(!child->compositor_); 153 DCHECK(!child->compositor_);
159 if (child->parent_) 154 if (child->parent_)
160 child->parent_->Remove(child); 155 child->parent_->Remove(child);
161 child->parent_ = this; 156 child->parent_ = this;
162 children_.push_back(child); 157 children_.push_back(child);
163 cc_layer_->AddChild(child->cc_layer_); 158 cc_layer_->AddChild(child->cc_layer_);
164 child->OnDeviceScaleFactorChanged(device_scale_factor_); 159 child->OnDeviceScaleFactorChanged(device_scale_factor_);
165 if (GetCompositor()) 160 if (GetCompositor())
166 child->SendPendingThreadedAnimations(); 161 child->SendPendingThreadedAnimations();
167 LayerAnimatorCollection* collection = GetLayerAnimatorCollection();
168 if (collection)
169 child->AddAnimatorsInTreeToCollection(collection);
170 } 162 }
171 163
172 void Layer::Remove(Layer* child) { 164 void Layer::Remove(Layer* child) {
173 // Current bounds are used to calculate offsets when layers are reparented. 165 // Current bounds are used to calculate offsets when layers are reparented.
174 // Stop (and complete) an ongoing animation to update the bounds immediately. 166 // Stop (and complete) an ongoing animation to update the bounds immediately.
175 LayerAnimator* child_animator = child->animator_; 167 if (child->GetAnimator()) {
176 if (child_animator) 168 child->GetAnimator()->StopAnimatingProperty(
177 child_animator->StopAnimatingProperty(ui::LayerAnimationElement::BOUNDS); 169 ui::LayerAnimationElement::BOUNDS);
178 LayerAnimatorCollection* collection = GetLayerAnimatorCollection(); 170 }
179 if (collection)
180 child->RemoveAnimatorsInTreeFromCollection(collection);
181
182 std::vector<Layer*>::iterator i = 171 std::vector<Layer*>::iterator i =
183 std::find(children_.begin(), children_.end(), child); 172 std::find(children_.begin(), children_.end(), child);
184 DCHECK(i != children_.end()); 173 DCHECK(i != children_.end());
185 children_.erase(i); 174 children_.erase(i);
186 child->parent_ = NULL; 175 child->parent_ = NULL;
187 child->cc_layer_->RemoveFromParent(); 176 child->cc_layer_->RemoveFromParent();
188 } 177 }
189 178
190 void Layer::StackAtTop(Layer* child) { 179 void Layer::StackAtTop(Layer* child) {
191 if (children_.size() <= 1 || child == children_.back()) 180 if (children_.size() <= 1 || child == children_.back())
(...skipping 685 matching lines...) Expand 10 before | Expand all | Expand 10 after
877 } 866 }
878 867
879 pending_threaded_animations_.erase( 868 pending_threaded_animations_.erase(
880 cc::remove_if(&pending_threaded_animations_, 869 cc::remove_if(&pending_threaded_animations_,
881 pending_threaded_animations_.begin(), 870 pending_threaded_animations_.begin(),
882 pending_threaded_animations_.end(), 871 pending_threaded_animations_.end(),
883 HasAnimationId(animation_id)), 872 HasAnimationId(animation_id)),
884 pending_threaded_animations_.end()); 873 pending_threaded_animations_.end());
885 } 874 }
886 875
887 LayerAnimatorCollection* Layer::GetLayerAnimatorCollection() {
888 Compositor* compositor = GetCompositor();
889 return compositor ? compositor->layer_animator_collection() : NULL;
890 }
891
892 void Layer::SendPendingThreadedAnimations() { 876 void Layer::SendPendingThreadedAnimations() {
893 for (cc::ScopedPtrVector<cc::Animation>::iterator it = 877 for (cc::ScopedPtrVector<cc::Animation>::iterator it =
894 pending_threaded_animations_.begin(); 878 pending_threaded_animations_.begin();
895 it != pending_threaded_animations_.end(); 879 it != pending_threaded_animations_.end();
896 ++it) 880 ++it)
897 cc_layer_->AddAnimation(pending_threaded_animations_.take(it)); 881 cc_layer_->AddAnimation(pending_threaded_animations_.take(it));
898 882
899 pending_threaded_animations_.clear(); 883 pending_threaded_animations_.clear();
900 884
901 for (size_t i = 0; i < children_.size(); ++i) 885 for (size_t i = 0; i < children_.size(); ++i)
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
939 size.SetToMin(frame_size_in_dip_); 923 size.SetToMin(frame_size_in_dip_);
940 delegated_renderer_layer_->SetDisplaySize(frame_size_in_dip_); 924 delegated_renderer_layer_->SetDisplaySize(frame_size_in_dip_);
941 } 925 }
942 cc_layer_->SetBounds(size); 926 cc_layer_->SetBounds(size);
943 } 927 }
944 928
945 void Layer::RecomputePosition() { 929 void Layer::RecomputePosition() {
946 cc_layer_->SetPosition(gfx::PointF(bounds_.x(), bounds_.y())); 930 cc_layer_->SetPosition(gfx::PointF(bounds_.x(), bounds_.y()));
947 } 931 }
948 932
949 void Layer::AddAnimatorsInTreeToCollection(
950 LayerAnimatorCollection* collection) {
951 DCHECK(collection);
952 if (IsAnimating())
953 animator_->AddToCollection(collection);
954 std::for_each(
955 children_.begin(),
956 children_.end(),
957 std::bind2nd(std::mem_fun(&Layer::AddAnimatorsInTreeToCollection),
958 collection));
959 }
960
961 void Layer::RemoveAnimatorsInTreeFromCollection(
962 LayerAnimatorCollection* collection) {
963 DCHECK(collection);
964 if (IsAnimating())
965 animator_->RemoveFromCollection(collection);
966 std::for_each(
967 children_.begin(),
968 children_.end(),
969 std::bind2nd(std::mem_fun(&Layer::RemoveAnimatorsInTreeFromCollection),
970 collection));
971 }
972
973 bool Layer::IsAnimating() const {
974 return animator_ && animator_->is_animating();
975 }
976
977 } // namespace ui 933 } // namespace ui
OLDNEW
« no previous file with comments | « ui/compositor/layer.h ('k') | ui/compositor/layer_animation_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698