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 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 zoom_(1), | 89 zoom_(1), |
89 zoom_inset_(0), | 90 zoom_inset_(0), |
90 delegate_(NULL), | 91 delegate_(NULL), |
91 owner_(NULL), | 92 owner_(NULL), |
92 cc_layer_(NULL), | 93 cc_layer_(NULL), |
93 device_scale_factor_(1.0f) { | 94 device_scale_factor_(1.0f) { |
94 CreateCcLayer(); | 95 CreateCcLayer(); |
95 } | 96 } |
96 | 97 |
97 Layer::~Layer() { | 98 Layer::~Layer() { |
| 99 FOR_EACH_OBSERVER(LayerObserver, observer_list_, LayerDestroyed(this)); |
| 100 |
98 // Destroying the animator may cause observers to use the layer (and | 101 // Destroying the animator may cause observers to use the layer (and |
99 // indirectly the WebLayer). Destroy the animator first so that the WebLayer | 102 // indirectly the WebLayer). Destroy the animator first so that the WebLayer |
100 // is still around. | 103 // is still around. |
101 SetAnimator(nullptr); | 104 SetAnimator(nullptr); |
102 if (compositor_) | 105 if (compositor_) |
103 compositor_->SetRootLayer(NULL); | 106 compositor_->SetRootLayer(NULL); |
104 if (parent_) | 107 if (parent_) |
105 parent_->Remove(this); | 108 parent_->Remove(this); |
106 if (layer_mask_) | 109 if (layer_mask_) |
107 SetMaskLayer(NULL); | 110 SetMaskLayer(NULL); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
140 } | 143 } |
141 | 144 |
142 void Layer::ResetCompositor() { | 145 void Layer::ResetCompositor() { |
143 DCHECK(!parent_); | 146 DCHECK(!parent_); |
144 if (compositor_) { | 147 if (compositor_) { |
145 ResetCompositorForAnimatorsInTree(compositor_); | 148 ResetCompositorForAnimatorsInTree(compositor_); |
146 compositor_ = nullptr; | 149 compositor_ = nullptr; |
147 } | 150 } |
148 } | 151 } |
149 | 152 |
| 153 void Layer::AddObserver(LayerObserver* observer) { |
| 154 observer_list_.AddObserver(observer); |
| 155 } |
| 156 |
| 157 void Layer::RemoveObserver(LayerObserver* observer) { |
| 158 observer_list_.RemoveObserver(observer); |
| 159 } |
| 160 |
150 void Layer::Add(Layer* child) { | 161 void Layer::Add(Layer* child) { |
151 DCHECK(!child->compositor_); | 162 DCHECK(!child->compositor_); |
152 if (child->parent_) | 163 if (child->parent_) |
153 child->parent_->Remove(child); | 164 child->parent_->Remove(child); |
154 child->parent_ = this; | 165 child->parent_ = this; |
155 children_.push_back(child); | 166 children_.push_back(child); |
156 cc_layer_->AddChild(child->cc_layer_); | 167 cc_layer_->AddChild(child->cc_layer_); |
157 child->OnDeviceScaleFactorChanged(device_scale_factor_); | 168 child->OnDeviceScaleFactorChanged(device_scale_factor_); |
158 Compositor* compositor = GetCompositor(); | 169 Compositor* compositor = GetCompositor(); |
159 if (compositor) | 170 if (compositor) |
(...skipping 417 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
577 DCHECK(type_ == LAYER_TEXTURED || type_ == LAYER_SOLID_COLOR); | 588 DCHECK(type_ == LAYER_TEXTURED || type_ == LAYER_SOLID_COLOR); |
578 | 589 |
579 scoped_refptr<cc::SurfaceLayer> new_layer = | 590 scoped_refptr<cc::SurfaceLayer> new_layer = |
580 cc::SurfaceLayer::Create(satisfy_callback, require_callback); | 591 cc::SurfaceLayer::Create(satisfy_callback, require_callback); |
581 new_layer->SetSurfaceId(surface_id, scale, surface_size); | 592 new_layer->SetSurfaceId(surface_id, scale, surface_size); |
582 SwitchToLayer(new_layer); | 593 SwitchToLayer(new_layer); |
583 surface_layer_ = new_layer; | 594 surface_layer_ = new_layer; |
584 | 595 |
585 frame_size_in_dip_ = frame_size_in_dip; | 596 frame_size_in_dip_ = frame_size_in_dip; |
586 RecomputeDrawsContentAndUVRect(); | 597 RecomputeDrawsContentAndUVRect(); |
| 598 |
| 599 FOR_EACH_OBSERVER(LayerObserver, observer_list_, SurfaceChanged(this)); |
587 } | 600 } |
588 | 601 |
589 void Layer::SetShowSolidColorContent() { | 602 void Layer::SetShowSolidColorContent() { |
590 DCHECK_EQ(type_, LAYER_SOLID_COLOR); | 603 DCHECK_EQ(type_, LAYER_SOLID_COLOR); |
591 | 604 |
592 if (solid_color_layer_.get()) | 605 if (solid_color_layer_.get()) |
593 return; | 606 return; |
594 | 607 |
595 scoped_refptr<cc::SolidColorLayer> new_layer = cc::SolidColorLayer::Create(); | 608 scoped_refptr<cc::SolidColorLayer> new_layer = cc::SolidColorLayer::Create(); |
596 SwitchToLayer(new_layer); | 609 SwitchToLayer(new_layer); |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
722 if (delegate_) | 735 if (delegate_) |
723 delegate_->OnDeviceScaleFactorChanged(device_scale_factor); | 736 delegate_->OnDeviceScaleFactorChanged(device_scale_factor); |
724 for (size_t i = 0; i < children_.size(); ++i) | 737 for (size_t i = 0; i < children_.size(); ++i) |
725 children_[i]->OnDeviceScaleFactorChanged(device_scale_factor); | 738 children_[i]->OnDeviceScaleFactorChanged(device_scale_factor); |
726 if (layer_mask_) | 739 if (layer_mask_) |
727 layer_mask_->OnDeviceScaleFactorChanged(device_scale_factor); | 740 layer_mask_->OnDeviceScaleFactorChanged(device_scale_factor); |
728 } | 741 } |
729 | 742 |
730 void Layer::OnDelegatedFrameDamage(const gfx::Rect& damage_rect_in_dip) { | 743 void Layer::OnDelegatedFrameDamage(const gfx::Rect& damage_rect_in_dip) { |
731 DCHECK(surface_layer_.get()); | 744 DCHECK(surface_layer_.get()); |
732 if (!delegate_) | 745 if (delegate_) |
733 return; | 746 delegate_->OnDelegatedFrameDamage(damage_rect_in_dip); |
734 delegate_->OnDelegatedFrameDamage(damage_rect_in_dip); | |
735 } | 747 } |
736 | 748 |
737 void Layer::SetScrollable(Layer* parent_clip_layer, | 749 void Layer::SetScrollable(Layer* parent_clip_layer, |
738 const base::Closure& on_scroll) { | 750 const base::Closure& on_scroll) { |
739 cc_layer_->SetScrollClipLayerId(parent_clip_layer->cc_layer_->id()); | 751 cc_layer_->SetScrollClipLayerId(parent_clip_layer->cc_layer_->id()); |
740 cc_layer_->set_did_scroll_callback(on_scroll); | 752 cc_layer_->set_did_scroll_callback(on_scroll); |
741 cc_layer_->SetUserScrollable(true, true); | 753 cc_layer_->SetUserScrollable(true, true); |
742 } | 754 } |
743 | 755 |
744 gfx::ScrollOffset Layer::CurrentScrollOffset() const { | 756 gfx::ScrollOffset Layer::CurrentScrollOffset() const { |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
780 paint_region_.Clear(); | 792 paint_region_.Clear(); |
781 cc::DisplayItemListSettings settings; | 793 cc::DisplayItemListSettings settings; |
782 settings.use_cached_picture = false; | 794 settings.use_cached_picture = false; |
783 scoped_refptr<cc::DisplayItemList> display_list = | 795 scoped_refptr<cc::DisplayItemList> display_list = |
784 cc::DisplayItemList::Create(settings); | 796 cc::DisplayItemList::Create(settings); |
785 if (delegate_) { | 797 if (delegate_) { |
786 delegate_->OnPaintLayer( | 798 delegate_->OnPaintLayer( |
787 PaintContext(display_list.get(), device_scale_factor_, invalidation)); | 799 PaintContext(display_list.get(), device_scale_factor_, invalidation)); |
788 } | 800 } |
789 display_list->Finalize(); | 801 display_list->Finalize(); |
| 802 FOR_EACH_OBSERVER(LayerObserver, observer_list_, |
| 803 DidPaintLayer(this, invalidation)); |
790 return display_list; | 804 return display_list; |
791 } | 805 } |
792 | 806 |
793 bool Layer::FillsBoundsCompletely() const { return fills_bounds_completely_; } | 807 bool Layer::FillsBoundsCompletely() const { return fills_bounds_completely_; } |
794 | 808 |
795 size_t Layer::GetApproximateUnsharedMemoryUsage() const { | 809 size_t Layer::GetApproximateUnsharedMemoryUsage() const { |
796 // Most of the "picture memory" is shared with the cc::DisplayItemList, so | 810 // Most of the "picture memory" is shared with the cc::DisplayItemList, so |
797 // there's nothing significant to report here. | 811 // there's nothing significant to report here. |
798 return 0; | 812 return 0; |
799 } | 813 } |
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1060 if (animator_) { | 1074 if (animator_) { |
1061 animator_->ResetCompositor(compositor); | 1075 animator_->ResetCompositor(compositor); |
1062 animator_->RemoveFromCollection(collection); | 1076 animator_->RemoveFromCollection(collection); |
1063 } | 1077 } |
1064 | 1078 |
1065 for (auto* child : children_) | 1079 for (auto* child : children_) |
1066 child->ResetCompositorForAnimatorsInTree(compositor); | 1080 child->ResetCompositorForAnimatorsInTree(compositor); |
1067 } | 1081 } |
1068 | 1082 |
1069 } // namespace ui | 1083 } // namespace ui |
OLD | NEW |