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" |
11 #include "base/json/json_writer.h" | 11 #include "base/json/json_writer.h" |
12 #include "base/lazy_instance.h" | 12 #include "base/lazy_instance.h" |
13 #include "base/logging.h" | 13 #include "base/logging.h" |
14 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
15 #include "base/trace_event/trace_event.h" | 15 #include "base/trace_event/trace_event.h" |
16 #include "cc/base/scoped_ptr_algorithm.h" | 16 #include "cc/base/scoped_ptr_algorithm.h" |
17 #include "cc/layers/content_layer.h" | 17 #include "cc/layers/content_layer.h" |
18 #include "cc/layers/delegated_renderer_layer.h" | 18 #include "cc/layers/delegated_renderer_layer.h" |
19 #include "cc/layers/nine_patch_layer.h" | 19 #include "cc/layers/nine_patch_layer.h" |
20 #include "cc/layers/picture_layer.h" | 20 #include "cc/layers/picture_layer.h" |
21 #include "cc/layers/solid_color_layer.h" | 21 #include "cc/layers/solid_color_layer.h" |
22 #include "cc/layers/surface_layer.h" | 22 #include "cc/layers/surface_layer.h" |
23 #include "cc/layers/texture_layer.h" | 23 #include "cc/layers/texture_layer.h" |
24 #include "cc/output/copy_output_request.h" | 24 #include "cc/output/copy_output_request.h" |
25 #include "cc/output/delegated_frame_data.h" | 25 #include "cc/output/delegated_frame_data.h" |
26 #include "cc/output/filter_operation.h" | 26 #include "cc/output/filter_operation.h" |
27 #include "cc/output/filter_operations.h" | 27 #include "cc/output/filter_operations.h" |
28 #include "cc/resources/transferable_resource.h" | 28 #include "cc/resources/transferable_resource.h" |
29 #include "cc/trees/layer_tree_host.h" | |
29 #include "ui/compositor/compositor_switches.h" | 30 #include "ui/compositor/compositor_switches.h" |
30 #include "ui/compositor/dip_util.h" | 31 #include "ui/compositor/dip_util.h" |
31 #include "ui/compositor/layer_animator.h" | 32 #include "ui/compositor/layer_animator.h" |
32 #include "ui/compositor/paint_context.h" | 33 #include "ui/compositor/paint_context.h" |
33 #include "ui/gfx/animation/animation.h" | 34 #include "ui/gfx/animation/animation.h" |
34 #include "ui/gfx/canvas.h" | 35 #include "ui/gfx/canvas.h" |
35 #include "ui/gfx/display.h" | 36 #include "ui/gfx/display.h" |
36 #include "ui/gfx/geometry/point3_f.h" | 37 #include "ui/gfx/geometry/point3_f.h" |
37 #include "ui/gfx/geometry/point_conversions.h" | 38 #include "ui/gfx/geometry/point_conversions.h" |
38 #include "ui/gfx/geometry/size_conversions.h" | 39 #include "ui/gfx/geometry/size_conversions.h" |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
117 if (compositor_) | 118 if (compositor_) |
118 compositor_->SetRootLayer(NULL); | 119 compositor_->SetRootLayer(NULL); |
119 if (parent_) | 120 if (parent_) |
120 parent_->Remove(this); | 121 parent_->Remove(this); |
121 if (layer_mask_) | 122 if (layer_mask_) |
122 SetMaskLayer(NULL); | 123 SetMaskLayer(NULL); |
123 if (layer_mask_back_link_) | 124 if (layer_mask_back_link_) |
124 layer_mask_back_link_->SetMaskLayer(NULL); | 125 layer_mask_back_link_->SetMaskLayer(NULL); |
125 for (size_t i = 0; i < children_.size(); ++i) | 126 for (size_t i = 0; i < children_.size(); ++i) |
126 children_[i]->parent_ = NULL; | 127 children_[i]->parent_ = NULL; |
127 cc_layer_->RemoveLayerAnimationEventObserver(this); | 128 |
129 DetachObservers(); | |
130 | |
128 cc_layer_->RemoveFromParent(); | 131 cc_layer_->RemoveFromParent(); |
129 } | 132 } |
130 | 133 |
131 // static | 134 // static |
132 bool Layer::UsingPictureLayer() { | 135 bool Layer::UsingPictureLayer() { |
133 return g_ui_impl_side_painting_status.Get().enabled; | 136 return g_ui_impl_side_painting_status.Get().enabled; |
134 } | 137 } |
135 | 138 |
136 const Compositor* Layer::GetCompositor() const { | 139 const Compositor* Layer::GetCompositor() const { |
137 return GetRoot(this)->compositor_; | 140 return GetRoot(this)->compositor_; |
138 } | 141 } |
139 | 142 |
140 float Layer::opacity() const { | 143 float Layer::opacity() const { |
141 return cc_layer_->opacity(); | 144 return cc_layer_->opacity(); |
142 } | 145 } |
143 | 146 |
144 void Layer::SetCompositor(Compositor* compositor) { | 147 void Layer::SetCompositor(Compositor* compositor) { |
ajuma
2015/04/23 15:09:15
This only gets called on the root layer, and only
loyso (OOO)
2015/04/24 03:44:52
Done.
| |
148 if (compositor) | |
149 RegisterForAnimations(compositor); | |
150 | |
145 // This function must only be called to set the compositor on the root layer, | 151 // This function must only be called to set the compositor on the root layer, |
146 // or to reset it. | 152 // or to reset it. |
147 DCHECK(!compositor || !compositor_); | 153 DCHECK(!compositor || !compositor_); |
148 DCHECK(!compositor || compositor->root_layer() == this); | 154 DCHECK(!compositor || compositor->root_layer() == this); |
149 DCHECK(!parent_); | 155 DCHECK(!parent_); |
150 if (compositor_) { | 156 if (compositor_) { |
157 DetachObservers(); | |
151 RemoveAnimatorsInTreeFromCollection( | 158 RemoveAnimatorsInTreeFromCollection( |
152 compositor_->layer_animator_collection()); | 159 compositor_->layer_animator_collection()); |
153 } | 160 } |
154 compositor_ = compositor; | 161 compositor_ = compositor; |
155 if (compositor) { | 162 if (compositor) { |
163 AttachObservers(); | |
156 OnDeviceScaleFactorChanged(compositor->device_scale_factor()); | 164 OnDeviceScaleFactorChanged(compositor->device_scale_factor()); |
157 SendPendingThreadedAnimations(); | 165 SendPendingThreadedAnimations(); |
158 AddAnimatorsInTreeToCollection(compositor_->layer_animator_collection()); | 166 AddAnimatorsInTreeToCollection(compositor_->layer_animator_collection()); |
159 } | 167 } |
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_); |
170 if (GetCompositor()) | 178 Compositor* compositor = GetCompositor(); |
179 if (compositor) { | |
180 child->RegisterForAnimations(compositor); | |
ajuma
2015/04/23 15:09:15
The call to cc_layer_->AddChild(child->cc_layer_)
loyso (OOO)
2015/04/24 03:44:52
Done.
| |
181 child->AttachObservers(); | |
171 child->SendPendingThreadedAnimations(); | 182 child->SendPendingThreadedAnimations(); |
183 } | |
172 LayerAnimatorCollection* collection = GetLayerAnimatorCollection(); | 184 LayerAnimatorCollection* collection = GetLayerAnimatorCollection(); |
173 if (collection) | 185 if (collection) |
174 child->AddAnimatorsInTreeToCollection(collection); | 186 child->AddAnimatorsInTreeToCollection(collection); |
175 } | 187 } |
176 | 188 |
177 void Layer::Remove(Layer* child) { | 189 void Layer::Remove(Layer* child) { |
178 // Current bounds are used to calculate offsets when layers are reparented. | 190 // Current bounds are used to calculate offsets when layers are reparented. |
179 // Stop (and complete) an ongoing animation to update the bounds immediately. | 191 // Stop (and complete) an ongoing animation to update the bounds immediately. |
180 LayerAnimator* child_animator = child->animator_.get(); | 192 LayerAnimator* child_animator = child->animator_.get(); |
181 if (child_animator) | 193 if (child_animator) |
182 child_animator->StopAnimatingProperty(ui::LayerAnimationElement::BOUNDS); | 194 child_animator->StopAnimatingProperty(ui::LayerAnimationElement::BOUNDS); |
183 LayerAnimatorCollection* collection = GetLayerAnimatorCollection(); | 195 LayerAnimatorCollection* collection = GetLayerAnimatorCollection(); |
184 if (collection) | 196 if (collection) |
185 child->RemoveAnimatorsInTreeFromCollection(collection); | 197 child->RemoveAnimatorsInTreeFromCollection(collection); |
186 | 198 |
199 child->DetachObservers(); | |
200 | |
187 std::vector<Layer*>::iterator i = | 201 std::vector<Layer*>::iterator i = |
188 std::find(children_.begin(), children_.end(), child); | 202 std::find(children_.begin(), children_.end(), child); |
189 DCHECK(i != children_.end()); | 203 DCHECK(i != children_.end()); |
190 children_.erase(i); | 204 children_.erase(i); |
191 child->parent_ = NULL; | 205 child->parent_ = NULL; |
192 child->cc_layer_->RemoveFromParent(); | 206 child->cc_layer_->RemoveFromParent(); |
193 } | 207 } |
194 | 208 |
195 void Layer::StackAtTop(Layer* child) { | 209 void Layer::StackAtTop(Layer* child) { |
196 if (children_.size() <= 1 || child == children_.back()) | 210 if (children_.size() <= 1 || child == children_.back()) |
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
483 | 497 |
484 if (texture_layer_.get()) | 498 if (texture_layer_.get()) |
485 texture_layer_->ClearClient(); | 499 texture_layer_->ClearClient(); |
486 // TODO(piman): delegated_renderer_layer_ cleanup. | 500 // TODO(piman): delegated_renderer_layer_ cleanup. |
487 | 501 |
488 cc_layer_->RemoveAllChildren(); | 502 cc_layer_->RemoveAllChildren(); |
489 if (cc_layer_->parent()) { | 503 if (cc_layer_->parent()) { |
490 cc_layer_->parent()->ReplaceChild(cc_layer_, new_layer); | 504 cc_layer_->parent()->ReplaceChild(cc_layer_, new_layer); |
491 } | 505 } |
492 cc_layer_->SetLayerClient(NULL); | 506 cc_layer_->SetLayerClient(NULL); |
493 cc_layer_->RemoveLayerAnimationEventObserver(this); | 507 |
508 DetachObservers(); | |
509 | |
494 new_layer->SetOpacity(cc_layer_->opacity()); | 510 new_layer->SetOpacity(cc_layer_->opacity()); |
495 new_layer->SetTransform(cc_layer_->transform()); | 511 new_layer->SetTransform(cc_layer_->transform()); |
496 new_layer->SetPosition(cc_layer_->position()); | 512 new_layer->SetPosition(cc_layer_->position()); |
497 new_layer->SetBackgroundColor(cc_layer_->background_color()); | 513 new_layer->SetBackgroundColor(cc_layer_->background_color()); |
498 | 514 |
499 cc_layer_ = new_layer.get(); | 515 cc_layer_ = new_layer.get(); |
500 content_layer_ = NULL; | 516 content_layer_ = NULL; |
501 solid_color_layer_ = NULL; | 517 solid_color_layer_ = NULL; |
502 texture_layer_ = NULL; | 518 texture_layer_ = NULL; |
503 delegated_renderer_layer_ = NULL; | 519 delegated_renderer_layer_ = NULL; |
504 surface_layer_ = NULL; | 520 surface_layer_ = NULL; |
505 | 521 |
506 cc_layer_->AddLayerAnimationEventObserver(this); | 522 AttachObservers(); |
523 | |
507 for (size_t i = 0; i < children_.size(); ++i) { | 524 for (size_t i = 0; i < children_.size(); ++i) { |
508 DCHECK(children_[i]->cc_layer_); | 525 DCHECK(children_[i]->cc_layer_); |
509 cc_layer_->AddChild(children_[i]->cc_layer_); | 526 cc_layer_->AddChild(children_[i]->cc_layer_); |
510 } | 527 } |
511 cc_layer_->SetLayerClient(this); | 528 cc_layer_->SetLayerClient(this); |
512 cc_layer_->SetTransformOrigin(gfx::Point3F()); | 529 cc_layer_->SetTransformOrigin(gfx::Point3F()); |
513 cc_layer_->SetContentsOpaque(fills_bounds_opaquely_); | 530 cc_layer_->SetContentsOpaque(fills_bounds_opaquely_); |
514 cc_layer_->SetForceRenderSurface(force_render_surface_); | 531 cc_layer_->SetForceRenderSurface(force_render_surface_); |
515 cc_layer_->SetIsDrawable(type_ != LAYER_NOT_DRAWN); | 532 cc_layer_->SetIsDrawable(type_ != LAYER_NOT_DRAWN); |
516 cc_layer_->SetHideLayerAndSubtree(!visible_); | 533 cc_layer_->SetHideLayerAndSubtree(!visible_); |
(...skipping 517 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1034 } else { | 1051 } else { |
1035 if (Layer::UsingPictureLayer()) | 1052 if (Layer::UsingPictureLayer()) |
1036 content_layer_ = cc::PictureLayer::Create(this); | 1053 content_layer_ = cc::PictureLayer::Create(this); |
1037 else | 1054 else |
1038 content_layer_ = cc::ContentLayer::Create(this); | 1055 content_layer_ = cc::ContentLayer::Create(this); |
1039 cc_layer_ = content_layer_.get(); | 1056 cc_layer_ = content_layer_.get(); |
1040 } | 1057 } |
1041 cc_layer_->SetTransformOrigin(gfx::Point3F()); | 1058 cc_layer_->SetTransformOrigin(gfx::Point3F()); |
1042 cc_layer_->SetContentsOpaque(true); | 1059 cc_layer_->SetContentsOpaque(true); |
1043 cc_layer_->SetIsDrawable(type_ != LAYER_NOT_DRAWN); | 1060 cc_layer_->SetIsDrawable(type_ != LAYER_NOT_DRAWN); |
1044 cc_layer_->AddLayerAnimationEventObserver(this); | |
1045 cc_layer_->SetLayerClient(this); | 1061 cc_layer_->SetLayerClient(this); |
1046 RecomputePosition(); | 1062 RecomputePosition(); |
1047 } | 1063 } |
1048 | 1064 |
1065 void Layer::RegisterForAnimations(Compositor* compositor) { | |
1066 DCHECK(compositor); | |
1067 const cc::LayerTreeHost& host = compositor->GetLayerTreeHost(); | |
1068 | |
1069 cc_layer_->RegisterForAnimations(host.animation_registrar(), host.settings()); | |
1070 | |
1071 for (size_t i = 0; i < children_.size(); ++i) | |
1072 children_[i]->RegisterForAnimations(compositor); | |
1073 } | |
1074 | |
1075 void Layer::AttachObservers() { | |
1076 if (cc_layer_->layer_animation_controller()) | |
1077 cc_layer_->AddLayerAnimationEventObserver(this); | |
1078 | |
1079 for (size_t i = 0; i < children_.size(); ++i) | |
1080 children_[i]->AttachObservers(); | |
1081 } | |
1082 | |
1083 void Layer::DetachObservers() { | |
1084 if (cc_layer_->layer_animation_controller()) | |
1085 cc_layer_->RemoveLayerAnimationEventObserver(this); | |
1086 | |
1087 for (size_t i = 0; i < children_.size(); ++i) | |
1088 children_[i]->DetachObservers(); | |
1089 } | |
1090 | |
1049 gfx::Transform Layer::transform() const { | 1091 gfx::Transform Layer::transform() const { |
1050 return cc_layer_->transform(); | 1092 return cc_layer_->transform(); |
1051 } | 1093 } |
1052 | 1094 |
1053 void Layer::RecomputeDrawsContentAndUVRect() { | 1095 void Layer::RecomputeDrawsContentAndUVRect() { |
1054 DCHECK(cc_layer_); | 1096 DCHECK(cc_layer_); |
1055 gfx::Size size(bounds_.size()); | 1097 gfx::Size size(bounds_.size()); |
1056 if (texture_layer_.get()) { | 1098 if (texture_layer_.get()) { |
1057 size.SetToMin(frame_size_in_dip_); | 1099 size.SetToMin(frame_size_in_dip_); |
1058 gfx::PointF uv_top_left(0.f, 0.f); | 1100 gfx::PointF uv_top_left(0.f, 0.f); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1092 children_.end(), | 1134 children_.end(), |
1093 std::bind2nd(std::mem_fun(&Layer::RemoveAnimatorsInTreeFromCollection), | 1135 std::bind2nd(std::mem_fun(&Layer::RemoveAnimatorsInTreeFromCollection), |
1094 collection)); | 1136 collection)); |
1095 } | 1137 } |
1096 | 1138 |
1097 bool Layer::IsAnimating() const { | 1139 bool Layer::IsAnimating() const { |
1098 return animator_.get() && animator_->is_animating(); | 1140 return animator_.get() && animator_->is_animating(); |
1099 } | 1141 } |
1100 | 1142 |
1101 } // namespace ui | 1143 } // namespace ui |
OLD | NEW |