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 #include <memory> | 8 #include <memory> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
(...skipping 10 matching lines...) Expand all Loading... | |
21 #include "cc/layers/texture_layer.h" | 21 #include "cc/layers/texture_layer.h" |
22 #include "cc/output/copy_output_request.h" | 22 #include "cc/output/copy_output_request.h" |
23 #include "cc/output/filter_operation.h" | 23 #include "cc/output/filter_operation.h" |
24 #include "cc/output/filter_operations.h" | 24 #include "cc/output/filter_operations.h" |
25 #include "cc/playback/display_item_list_settings.h" | 25 #include "cc/playback/display_item_list_settings.h" |
26 #include "cc/resources/transferable_resource.h" | 26 #include "cc/resources/transferable_resource.h" |
27 #include "cc/trees/layer_tree_settings.h" | 27 #include "cc/trees/layer_tree_settings.h" |
28 #include "ui/compositor/compositor_switches.h" | 28 #include "ui/compositor/compositor_switches.h" |
29 #include "ui/compositor/dip_util.h" | 29 #include "ui/compositor/dip_util.h" |
30 #include "ui/compositor/layer_animator.h" | 30 #include "ui/compositor/layer_animator.h" |
31 #include "ui/compositor/layer_observer.h" | |
31 #include "ui/compositor/paint_context.h" | 32 #include "ui/compositor/paint_context.h" |
32 #include "ui/gfx/animation/animation.h" | 33 #include "ui/gfx/animation/animation.h" |
33 #include "ui/gfx/canvas.h" | 34 #include "ui/gfx/canvas.h" |
34 #include "ui/gfx/geometry/point3_f.h" | 35 #include "ui/gfx/geometry/point3_f.h" |
35 #include "ui/gfx/geometry/point_conversions.h" | 36 #include "ui/gfx/geometry/point_conversions.h" |
36 #include "ui/gfx/geometry/size_conversions.h" | 37 #include "ui/gfx/geometry/size_conversions.h" |
37 #include "ui/gfx/interpolated_transform.h" | 38 #include "ui/gfx/interpolated_transform.h" |
38 | 39 |
39 namespace { | 40 namespace { |
40 | 41 |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
92 delegate_(NULL), | 93 delegate_(NULL), |
93 owner_(NULL), | 94 owner_(NULL), |
94 cc_layer_(NULL), | 95 cc_layer_(NULL), |
95 device_scale_factor_(1.0f), | 96 device_scale_factor_(1.0f), |
96 texture_x_scale_(1.0f), | 97 texture_x_scale_(1.0f), |
97 texture_y_scale_(1.0f) { | 98 texture_y_scale_(1.0f) { |
98 CreateCcLayer(); | 99 CreateCcLayer(); |
99 } | 100 } |
100 | 101 |
101 Layer::~Layer() { | 102 Layer::~Layer() { |
103 FOR_EACH_OBSERVER(LayerObserver, observer_list_, OnLayerDestroyed(this)); | |
104 | |
102 // Destroying the animator may cause observers to use the layer (and | 105 // Destroying the animator may cause observers to use the layer (and |
103 // indirectly the WebLayer). Destroy the animator first so that the WebLayer | 106 // indirectly the WebLayer). Destroy the animator first so that the WebLayer |
104 // is still around. | 107 // is still around. |
105 SetAnimator(nullptr); | 108 SetAnimator(nullptr); |
106 if (compositor_) | 109 if (compositor_) |
107 compositor_->SetRootLayer(NULL); | 110 compositor_->SetRootLayer(NULL); |
108 if (parent_) | 111 if (parent_) |
109 parent_->Remove(this); | 112 parent_->Remove(this); |
110 if (layer_mask_) | 113 if (layer_mask_) |
111 SetMaskLayer(NULL); | 114 SetMaskLayer(NULL); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
144 } | 147 } |
145 | 148 |
146 void Layer::ResetCompositor() { | 149 void Layer::ResetCompositor() { |
147 DCHECK(!parent_); | 150 DCHECK(!parent_); |
148 if (compositor_) { | 151 if (compositor_) { |
149 ResetCompositorForAnimatorsInTree(compositor_); | 152 ResetCompositorForAnimatorsInTree(compositor_); |
150 compositor_ = nullptr; | 153 compositor_ = nullptr; |
151 } | 154 } |
152 } | 155 } |
153 | 156 |
157 void Layer::AddObserver(LayerObserver* observer) { | |
158 observer_list_.AddObserver(observer); | |
159 } | |
160 | |
161 void Layer::RemoveObserver(LayerObserver* observer) { | |
162 observer_list_.RemoveObserver(observer); | |
163 } | |
164 | |
154 void Layer::Add(Layer* child) { | 165 void Layer::Add(Layer* child) { |
155 DCHECK(!child->compositor_); | 166 DCHECK(!child->compositor_); |
156 if (child->parent_) | 167 if (child->parent_) |
157 child->parent_->Remove(child); | 168 child->parent_->Remove(child); |
158 child->parent_ = this; | 169 child->parent_ = this; |
159 children_.push_back(child); | 170 children_.push_back(child); |
160 cc_layer_->AddChild(child->cc_layer_); | 171 cc_layer_->AddChild(child->cc_layer_); |
161 child->OnDeviceScaleFactorChanged(device_scale_factor_); | 172 child->OnDeviceScaleFactorChanged(device_scale_factor_); |
162 Compositor* compositor = GetCompositor(); | 173 Compositor* compositor = GetCompositor(); |
163 if (compositor) | 174 if (compositor) |
(...skipping 583 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
747 children_[i]->OnDeviceScaleFactorChanged(device_scale_factor); | 758 children_[i]->OnDeviceScaleFactorChanged(device_scale_factor); |
748 if (layer_mask_) | 759 if (layer_mask_) |
749 layer_mask_->OnDeviceScaleFactorChanged(device_scale_factor); | 760 layer_mask_->OnDeviceScaleFactorChanged(device_scale_factor); |
750 } | 761 } |
751 | 762 |
752 void Layer::OnDelegatedFrameDamage(const gfx::Rect& damage_rect_in_dip) { | 763 void Layer::OnDelegatedFrameDamage(const gfx::Rect& damage_rect_in_dip) { |
753 DCHECK(surface_layer_.get()); | 764 DCHECK(surface_layer_.get()); |
754 if (!delegate_) | 765 if (!delegate_) |
755 return; | 766 return; |
756 delegate_->OnDelegatedFrameDamage(damage_rect_in_dip); | 767 delegate_->OnDelegatedFrameDamage(damage_rect_in_dip); |
768 | |
769 for (Layer* ancestor = this; ancestor; ancestor = ancestor->parent()) { | |
sky
2016/08/18 13:36:21
I would like to avoid having to walk the tree on e
Evan Stade
2016/08/18 15:57:31
This only walks up (as opposed to a full tree trav
| |
770 FOR_EACH_OBSERVER(LayerObserver, ancestor->observer_list_, | |
771 OnDelegatedFrameDamageInTree()); | |
772 } | |
757 } | 773 } |
758 | 774 |
759 void Layer::SetScrollable(Layer* parent_clip_layer, | 775 void Layer::SetScrollable(Layer* parent_clip_layer, |
760 const base::Closure& on_scroll) { | 776 const base::Closure& on_scroll) { |
761 cc_layer_->SetScrollClipLayerId(parent_clip_layer->cc_layer_->id()); | 777 cc_layer_->SetScrollClipLayerId(parent_clip_layer->cc_layer_->id()); |
762 cc_layer_->set_did_scroll_callback(on_scroll); | 778 cc_layer_->set_did_scroll_callback(on_scroll); |
763 cc_layer_->SetUserScrollable(true, true); | 779 cc_layer_->SetUserScrollable(true, true); |
764 } | 780 } |
765 | 781 |
766 gfx::ScrollOffset Layer::CurrentScrollOffset() const { | 782 gfx::ScrollOffset Layer::CurrentScrollOffset() const { |
(...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1095 if (animator_) { | 1111 if (animator_) { |
1096 animator_->ResetCompositor(compositor); | 1112 animator_->ResetCompositor(compositor); |
1097 animator_->RemoveFromCollection(collection); | 1113 animator_->RemoveFromCollection(collection); |
1098 } | 1114 } |
1099 | 1115 |
1100 for (auto* child : children_) | 1116 for (auto* child : children_) |
1101 child->ResetCompositorForAnimatorsInTree(compositor); | 1117 child->ResetCompositorForAnimatorsInTree(compositor); |
1102 } | 1118 } |
1103 | 1119 |
1104 } // namespace ui | 1120 } // namespace ui |
OLD | NEW |