OLD | NEW |
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/auto_reset.h" | 9 #include "base/auto_reset.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 if (compositor_) | 117 if (compositor_) |
118 compositor_->SetRootLayer(NULL); | 118 compositor_->SetRootLayer(NULL); |
119 if (parent_) | 119 if (parent_) |
120 parent_->Remove(this); | 120 parent_->Remove(this); |
121 if (layer_mask_) | 121 if (layer_mask_) |
122 SetMaskLayer(NULL); | 122 SetMaskLayer(NULL); |
123 if (layer_mask_back_link_) | 123 if (layer_mask_back_link_) |
124 layer_mask_back_link_->SetMaskLayer(NULL); | 124 layer_mask_back_link_->SetMaskLayer(NULL); |
125 for (size_t i = 0; i < children_.size(); ++i) | 125 for (size_t i = 0; i < children_.size(); ++i) |
126 children_[i]->parent_ = NULL; | 126 children_[i]->parent_ = NULL; |
| 127 |
127 cc_layer_->RemoveLayerAnimationEventObserver(this); | 128 cc_layer_->RemoveLayerAnimationEventObserver(this); |
128 cc_layer_->RemoveFromParent(); | 129 cc_layer_->RemoveFromParent(); |
129 } | 130 } |
130 | 131 |
131 // static | 132 // static |
132 bool Layer::UsingPictureLayer() { | 133 bool Layer::UsingPictureLayer() { |
133 return g_ui_impl_side_painting_status.Get().enabled; | 134 return g_ui_impl_side_painting_status.Get().enabled; |
134 } | 135 } |
135 | 136 |
136 const Compositor* Layer::GetCompositor() const { | 137 const Compositor* Layer::GetCompositor() const { |
137 return GetRoot(this)->compositor_; | 138 return GetRoot(this)->compositor_; |
138 } | 139 } |
139 | 140 |
140 float Layer::opacity() const { | 141 float Layer::opacity() const { |
141 return cc_layer_->opacity(); | 142 return cc_layer_->opacity(); |
142 } | 143 } |
143 | 144 |
144 void Layer::SetCompositor(Compositor* compositor) { | 145 void Layer::SetCompositor(Compositor* compositor, |
145 // This function must only be called to set the compositor on the root layer, | 146 scoped_refptr<cc::Layer> root_layer) { |
146 // or to reset it. | 147 // This function must only be called to set the compositor on the root ui |
147 DCHECK(!compositor || !compositor_); | 148 // layer. |
148 DCHECK(!compositor || compositor->root_layer() == this); | 149 DCHECK(compositor); |
| 150 DCHECK(!compositor_); |
| 151 DCHECK(compositor->root_layer() == this); |
149 DCHECK(!parent_); | 152 DCHECK(!parent_); |
150 if (compositor_) { | 153 |
| 154 compositor_ = compositor; |
| 155 OnDeviceScaleFactorChanged(compositor->device_scale_factor()); |
| 156 AddAnimatorsInTreeToCollection(compositor_->layer_animator_collection()); |
| 157 |
| 158 root_layer->AddChild(cc_layer_); |
| 159 SendPendingThreadedAnimations(); |
| 160 } |
| 161 |
| 162 void Layer::ResetCompositor() { |
| 163 DCHECK(!parent_); |
| 164 if (compositor_) |
151 RemoveAnimatorsInTreeFromCollection( | 165 RemoveAnimatorsInTreeFromCollection( |
152 compositor_->layer_animator_collection()); | 166 compositor_->layer_animator_collection()); |
153 } | 167 compositor_ = nullptr; |
154 compositor_ = compositor; | |
155 if (compositor) { | |
156 OnDeviceScaleFactorChanged(compositor->device_scale_factor()); | |
157 SendPendingThreadedAnimations(); | |
158 AddAnimatorsInTreeToCollection(compositor_->layer_animator_collection()); | |
159 } | |
160 } | 168 } |
161 | 169 |
162 void Layer::Add(Layer* child) { | 170 void Layer::Add(Layer* child) { |
163 DCHECK(!child->compositor_); | 171 DCHECK(!child->compositor_); |
164 if (child->parent_) | 172 if (child->parent_) |
165 child->parent_->Remove(child); | 173 child->parent_->Remove(child); |
166 child->parent_ = this; | 174 child->parent_ = this; |
167 children_.push_back(child); | 175 children_.push_back(child); |
168 cc_layer_->AddChild(child->cc_layer_); | 176 cc_layer_->AddChild(child->cc_layer_); |
169 child->OnDeviceScaleFactorChanged(device_scale_factor_); | 177 child->OnDeviceScaleFactorChanged(device_scale_factor_); |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
330 layer_mask->children().empty() && | 338 layer_mask->children().empty() && |
331 !layer_mask->layer_mask_back_link_)); | 339 !layer_mask->layer_mask_back_link_)); |
332 DCHECK(!layer_mask_back_link_); | 340 DCHECK(!layer_mask_back_link_); |
333 if (layer_mask_ == layer_mask) | 341 if (layer_mask_ == layer_mask) |
334 return; | 342 return; |
335 // We need to de-reference the currently linked object so that no problem | 343 // We need to de-reference the currently linked object so that no problem |
336 // arises if the mask layer gets deleted before this object. | 344 // arises if the mask layer gets deleted before this object. |
337 if (layer_mask_) | 345 if (layer_mask_) |
338 layer_mask_->layer_mask_back_link_ = NULL; | 346 layer_mask_->layer_mask_back_link_ = NULL; |
339 layer_mask_ = layer_mask; | 347 layer_mask_ = layer_mask; |
340 cc_layer_->SetMaskLayer( | 348 cc_layer_->SetMaskLayer(layer_mask ? layer_mask->cc_layer_ : NULL); |
341 layer_mask ? layer_mask->cc_layer() : NULL); | |
342 // We need to reference the linked object so that it can properly break the | 349 // We need to reference the linked object so that it can properly break the |
343 // link to us when it gets deleted. | 350 // link to us when it gets deleted. |
344 if (layer_mask) { | 351 if (layer_mask) { |
345 layer_mask->layer_mask_back_link_ = this; | 352 layer_mask->layer_mask_back_link_ = this; |
346 layer_mask->OnDeviceScaleFactorChanged(device_scale_factor_); | 353 layer_mask->OnDeviceScaleFactorChanged(device_scale_factor_); |
347 } | 354 } |
348 } | 355 } |
349 | 356 |
350 void Layer::SetBackgroundZoom(float zoom, int inset) { | 357 void Layer::SetBackgroundZoom(float zoom, int inset) { |
351 zoom_ = zoom; | 358 zoom_ = zoom; |
(...skipping 733 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1085 children_.end(), | 1092 children_.end(), |
1086 std::bind2nd(std::mem_fun(&Layer::RemoveAnimatorsInTreeFromCollection), | 1093 std::bind2nd(std::mem_fun(&Layer::RemoveAnimatorsInTreeFromCollection), |
1087 collection)); | 1094 collection)); |
1088 } | 1095 } |
1089 | 1096 |
1090 bool Layer::IsAnimating() const { | 1097 bool Layer::IsAnimating() const { |
1091 return animator_.get() && animator_->is_animating(); | 1098 return animator_.get() && animator_->is_animating(); |
1092 } | 1099 } |
1093 | 1100 |
1094 } // namespace ui | 1101 } // namespace ui |
OLD | NEW |