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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
42 const ui::Layer* GetRoot(const ui::Layer* layer) { | 42 const ui::Layer* GetRoot(const ui::Layer* layer) { |
43 while (layer->parent()) | 43 while (layer->parent()) |
44 layer = layer->parent(); | 44 layer = layer->parent(); |
45 return layer; | 45 return layer; |
46 } | 46 } |
47 | 47 |
48 } // namespace | 48 } // namespace |
49 | 49 |
50 namespace ui { | 50 namespace ui { |
51 | 51 |
52 class Layer::LayerMirror : public LayerDelegate, LayerObserver { | |
53 public: | |
54 LayerMirror(Layer* mirrored, Layer* mirror) | |
danakj
2016/10/24 20:28:02
nit: mirror_source and mirror_dest? or just source
Dominik Laskowski
2016/10/24 22:58:04
Done.
| |
55 : mirrored_(mirrored), mirror_(mirror) { | |
56 mirror->AddObserver(this); | |
57 mirror->set_delegate(this); | |
58 } | |
59 | |
60 ~LayerMirror() override { | |
61 mirror_->RemoveObserver(this); | |
62 mirror_->set_delegate(nullptr); | |
63 } | |
64 | |
65 Layer* layer() { return mirror_; } | |
danakj
2016/10/24 20:28:02
This method's name is ambiguous can it specify its
Dominik Laskowski
2016/10/24 22:58:05
Done.
| |
66 | |
67 // LayerDelegate: | |
68 void OnPaintLayer(const PaintContext& context) override { | |
69 if (const auto delegate = mirrored_->delegate()) | |
danakj
2016/10/24 20:28:02
auto*
Dominik Laskowski
2016/10/24 22:58:05
OnPaintLayer isn't const.
Dominik Laskowski
2016/10/24 23:15:07
...or did you mean:
if (auto* delegate = ...
danakj
2016/10/24 23:57:57
That'd be fine yes. It's a raw pointer so denote i
Dominik Laskowski
2016/10/25 22:44:56
Done.
| |
70 delegate->OnPaintLayer(context); | |
71 } | |
72 void OnDelegatedFrameDamage(const gfx::Rect& damage_rect_in_dip) override {} | |
73 void OnDeviceScaleFactorChanged(float device_scale_factor) override {} | |
74 | |
75 // LayerObserver: | |
76 void LayerDestroyed(Layer* mirror) override { | |
77 DCHECK_EQ(mirror_, mirror); | |
78 mirrored_->OnMirrorDestroyed(this); | |
79 } | |
80 | |
81 private: | |
82 Layer* const mirrored_; | |
83 Layer* const mirror_; | |
84 | |
85 DISALLOW_COPY_AND_ASSIGN(LayerMirror); | |
86 }; | |
87 | |
52 Layer::Layer() | 88 Layer::Layer() |
53 : type_(LAYER_TEXTURED), | 89 : type_(LAYER_TEXTURED), |
54 compositor_(NULL), | 90 compositor_(NULL), |
55 parent_(NULL), | 91 parent_(NULL), |
56 visible_(true), | 92 visible_(true), |
57 fills_bounds_opaquely_(true), | 93 fills_bounds_opaquely_(true), |
58 fills_bounds_completely_(false), | 94 fills_bounds_completely_(false), |
59 background_blur_radius_(0), | 95 background_blur_radius_(0), |
60 layer_saturation_(0.0f), | 96 layer_saturation_(0.0f), |
61 layer_brightness_(0.0f), | 97 layer_brightness_(0.0f), |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
112 if (layer_mask_back_link_) | 148 if (layer_mask_back_link_) |
113 layer_mask_back_link_->SetMaskLayer(NULL); | 149 layer_mask_back_link_->SetMaskLayer(NULL); |
114 for (size_t i = 0; i < children_.size(); ++i) | 150 for (size_t i = 0; i < children_.size(); ++i) |
115 children_[i]->parent_ = NULL; | 151 children_[i]->parent_ = NULL; |
116 | 152 |
117 cc_layer_->RemoveFromParent(); | 153 cc_layer_->RemoveFromParent(); |
118 if (mailbox_release_callback_) | 154 if (mailbox_release_callback_) |
119 mailbox_release_callback_->Run(gpu::SyncToken(), false); | 155 mailbox_release_callback_->Run(gpu::SyncToken(), false); |
120 } | 156 } |
121 | 157 |
158 std::unique_ptr<Layer> Layer::Clone() const { | |
159 auto clone = base::MakeUnique<Layer>(type_); | |
160 | |
161 clone->SetTransform(GetTargetTransform()); | |
162 clone->SetBounds(bounds_); | |
163 clone->SetSubpixelPositionOffset(subpixel_position_offset_); | |
164 clone->SetMasksToBounds(GetMasksToBounds()); | |
165 clone->SetOpacity(GetTargetOpacity()); | |
166 clone->SetVisible(GetTargetVisibility()); | |
167 clone->SetFillsBoundsOpaquely(fills_bounds_opaquely_); | |
168 clone->SetFillsBoundsCompletely(fills_bounds_completely_); | |
169 clone->set_name(name_); | |
170 | |
171 // Background filters. | |
172 clone->SetBackgroundBlur(background_blur_radius_); | |
173 clone->SetBackgroundZoom(zoom_, zoom_inset_); | |
174 | |
175 // Filters. | |
176 clone->SetLayerSaturation(layer_saturation_); | |
177 clone->SetLayerBrightness(GetTargetBrightness()); | |
178 clone->SetLayerGrayscale(GetTargetGrayscale()); | |
179 clone->SetLayerInverted(layer_inverted_); | |
180 if (alpha_shape_) | |
181 clone->SetAlphaShape(base::MakeUnique<SkRegion>(*alpha_shape_)); | |
182 | |
183 // cc::Layer state. | |
184 if (surface_layer_ && !surface_layer_->surface_id().is_null()) { | |
185 clone->SetShowSurface( | |
186 surface_layer_->surface_id(), | |
187 surface_layer_->satisfy_callback(), | |
188 surface_layer_->require_callback(), | |
189 surface_layer_->surface_size(), | |
190 surface_layer_->surface_scale(), | |
191 frame_size_in_dip_); | |
192 } else if (type_ == LAYER_SOLID_COLOR) { | |
193 clone->SetColor(GetTargetColor()); | |
194 } | |
195 return clone; | |
196 } | |
197 | |
122 const Compositor* Layer::GetCompositor() const { | 198 const Compositor* Layer::GetCompositor() const { |
123 return GetRoot(this)->compositor_; | 199 return GetRoot(this)->compositor_; |
124 } | 200 } |
125 | 201 |
126 float Layer::opacity() const { | 202 float Layer::opacity() const { |
127 return cc_layer_->opacity(); | 203 return cc_layer_->opacity(); |
128 } | 204 } |
129 | 205 |
130 void Layer::SetCompositor(Compositor* compositor, | 206 void Layer::SetCompositor(Compositor* compositor, |
131 scoped_refptr<cc::Layer> root_layer) { | 207 scoped_refptr<cc::Layer> root_layer) { |
(...skipping 454 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
586 | 662 |
587 scoped_refptr<cc::SurfaceLayer> new_layer = | 663 scoped_refptr<cc::SurfaceLayer> new_layer = |
588 cc::SurfaceLayer::Create(satisfy_callback, require_callback); | 664 cc::SurfaceLayer::Create(satisfy_callback, require_callback); |
589 new_layer->SetSurfaceId(surface_id, scale, surface_size); | 665 new_layer->SetSurfaceId(surface_id, scale, surface_size); |
590 SwitchToLayer(new_layer); | 666 SwitchToLayer(new_layer); |
591 surface_layer_ = new_layer; | 667 surface_layer_ = new_layer; |
592 | 668 |
593 frame_size_in_dip_ = frame_size_in_dip; | 669 frame_size_in_dip_ = frame_size_in_dip; |
594 RecomputeDrawsContentAndUVRect(); | 670 RecomputeDrawsContentAndUVRect(); |
595 | 671 |
596 for (auto& observer : observer_list_) | 672 for (const auto& mirror : mirrors_) { |
597 observer.SurfaceChanged(this); | 673 mirror->layer()->SetShowSurface( |
674 surface_id, satisfy_callback, require_callback, | |
675 surface_size, scale, frame_size_in_dip); | |
676 } | |
677 } | |
678 | |
679 std::unique_ptr<Layer> Layer::Mirror() { | |
680 auto mirror = Clone(); | |
681 mirrors_.emplace_back(base::MakeUnique<LayerMirror>(this, mirror.get())); | |
682 return mirror; | |
598 } | 683 } |
599 | 684 |
600 void Layer::SetShowSolidColorContent() { | 685 void Layer::SetShowSolidColorContent() { |
601 DCHECK_EQ(type_, LAYER_SOLID_COLOR); | 686 DCHECK_EQ(type_, LAYER_SOLID_COLOR); |
602 | 687 |
603 if (solid_color_layer_.get()) | 688 if (solid_color_layer_.get()) |
604 return; | 689 return; |
605 | 690 |
606 scoped_refptr<cc::SolidColorLayer> new_layer = cc::SolidColorLayer::Create(); | 691 scoped_refptr<cc::SolidColorLayer> new_layer = cc::SolidColorLayer::Create(); |
607 SwitchToLayer(new_layer); | 692 SwitchToLayer(new_layer); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
644 nine_patch_layer_->SetBorder(border); | 729 nine_patch_layer_->SetBorder(border); |
645 } | 730 } |
646 | 731 |
647 void Layer::UpdateNinePatchOcclusion(const gfx::Rect& occlusion) { | 732 void Layer::UpdateNinePatchOcclusion(const gfx::Rect& occlusion) { |
648 DCHECK(type_ == LAYER_NINE_PATCH && nine_patch_layer_.get()); | 733 DCHECK(type_ == LAYER_NINE_PATCH && nine_patch_layer_.get()); |
649 nine_patch_layer_->SetLayerOcclusion(occlusion); | 734 nine_patch_layer_->SetLayerOcclusion(occlusion); |
650 } | 735 } |
651 | 736 |
652 void Layer::SetColor(SkColor color) { GetAnimator()->SetColor(color); } | 737 void Layer::SetColor(SkColor color) { GetAnimator()->SetColor(color); } |
653 | 738 |
654 SkColor Layer::GetTargetColor() { | 739 SkColor Layer::GetTargetColor() const { |
655 if (GetAnimator()->IsAnimatingProperty(LayerAnimationElement::COLOR)) | 740 if (animator_.get() && animator_->IsAnimatingProperty( |
danakj
2016/10/24 20:28:02
no .get() needed
Dominik Laskowski
2016/10/24 22:58:04
Done, and elsewhere too.
| |
656 return GetAnimator()->GetTargetColor(); | 741 LayerAnimationElement::COLOR)) |
742 return animator_->GetTargetColor(); | |
657 return cc_layer_->background_color(); | 743 return cc_layer_->background_color(); |
658 } | 744 } |
659 | 745 |
660 SkColor Layer::background_color() const { | 746 SkColor Layer::background_color() const { |
661 return cc_layer_->background_color(); | 747 return cc_layer_->background_color(); |
662 } | 748 } |
663 | 749 |
664 bool Layer::SchedulePaint(const gfx::Rect& invalid_rect) { | 750 bool Layer::SchedulePaint(const gfx::Rect& invalid_rect) { |
665 if ((type_ == LAYER_SOLID_COLOR && !texture_layer_.get()) || | 751 if ((type_ == LAYER_SOLID_COLOR && !texture_layer_.get()) || |
666 type_ == LAYER_NINE_PATCH || (!delegate_ && !mailbox_.IsValid())) | 752 type_ == LAYER_NINE_PATCH || (!delegate_ && !mailbox_.IsValid())) |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
790 paint_region_.Clear(); | 876 paint_region_.Clear(); |
791 cc::DisplayItemListSettings settings; | 877 cc::DisplayItemListSettings settings; |
792 settings.use_cached_picture = false; | 878 settings.use_cached_picture = false; |
793 scoped_refptr<cc::DisplayItemList> display_list = | 879 scoped_refptr<cc::DisplayItemList> display_list = |
794 cc::DisplayItemList::Create(settings); | 880 cc::DisplayItemList::Create(settings); |
795 if (delegate_) { | 881 if (delegate_) { |
796 delegate_->OnPaintLayer( | 882 delegate_->OnPaintLayer( |
797 PaintContext(display_list.get(), device_scale_factor_, invalidation)); | 883 PaintContext(display_list.get(), device_scale_factor_, invalidation)); |
798 } | 884 } |
799 display_list->Finalize(); | 885 display_list->Finalize(); |
800 for (auto& observer : observer_list_) | 886 for (const auto& mirror : mirrors_) |
801 observer.DidPaintLayer(this, invalidation); | 887 mirror->layer()->SchedulePaint(invalidation); |
danakj
2016/10/24 20:28:02
I would expect SchedulePaint for the whole layers
Dominik Laskowski
2016/10/24 22:58:04
I was also wondering why DidPaintLayer was called
danakj
2016/10/24 23:57:57
Would you mind leaving a TODO describing this all
Dominik Laskowski
2016/10/25 22:44:56
Done, but a bug seems overkill.
| |
802 return display_list; | 888 return display_list; |
803 } | 889 } |
804 | 890 |
805 bool Layer::FillsBoundsCompletely() const { return fills_bounds_completely_; } | 891 bool Layer::FillsBoundsCompletely() const { return fills_bounds_completely_; } |
806 | 892 |
807 size_t Layer::GetApproximateUnsharedMemoryUsage() const { | 893 size_t Layer::GetApproximateUnsharedMemoryUsage() const { |
808 // Most of the "picture memory" is shared with the cc::DisplayItemList, so | 894 // Most of the "picture memory" is shared with the cc::DisplayItemList, so |
809 // there's nothing significant to report here. | 895 // there's nothing significant to report here. |
810 return 0; | 896 return 0; |
811 } | 897 } |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
909 | 995 |
910 if (bounds.size() == old_bounds.size()) { | 996 if (bounds.size() == old_bounds.size()) { |
911 // Don't schedule a draw if we're invisible. We'll schedule one | 997 // Don't schedule a draw if we're invisible. We'll schedule one |
912 // automatically when we get visible. | 998 // automatically when we get visible. |
913 if (IsDrawn()) | 999 if (IsDrawn()) |
914 ScheduleDraw(); | 1000 ScheduleDraw(); |
915 } else { | 1001 } else { |
916 // Always schedule a paint, even if we're invisible. | 1002 // Always schedule a paint, even if we're invisible. |
917 SchedulePaint(gfx::Rect(bounds.size())); | 1003 SchedulePaint(gfx::Rect(bounds.size())); |
918 } | 1004 } |
1005 | |
1006 if (sync_bounds_) { | |
1007 for (const auto& mirror : mirrors_) | |
1008 mirror->layer()->SetBounds(bounds); | |
1009 } | |
919 } | 1010 } |
920 | 1011 |
921 void Layer::SetTransformFromAnimation(const gfx::Transform& transform) { | 1012 void Layer::SetTransformFromAnimation(const gfx::Transform& transform) { |
922 cc_layer_->SetTransform(transform); | 1013 cc_layer_->SetTransform(transform); |
923 } | 1014 } |
924 | 1015 |
925 void Layer::SetOpacityFromAnimation(float opacity) { | 1016 void Layer::SetOpacityFromAnimation(float opacity) { |
926 cc_layer_->SetOpacity(opacity); | 1017 cc_layer_->SetOpacity(opacity); |
927 ScheduleDraw(); | 1018 ScheduleDraw(); |
928 } | 1019 } |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1069 | 1160 |
1070 if (animator_) { | 1161 if (animator_) { |
1071 animator_->DetachLayerAndTimeline(compositor); | 1162 animator_->DetachLayerAndTimeline(compositor); |
1072 animator_->RemoveFromCollection(collection); | 1163 animator_->RemoveFromCollection(collection); |
1073 } | 1164 } |
1074 | 1165 |
1075 for (auto* child : children_) | 1166 for (auto* child : children_) |
1076 child->ResetCompositorForAnimatorsInTree(compositor); | 1167 child->ResetCompositorForAnimatorsInTree(compositor); |
1077 } | 1168 } |
1078 | 1169 |
1170 void Layer::OnMirrorDestroyed(LayerMirror* mirror) { | |
1171 const auto it = std::find_if(mirrors_.begin(), mirrors_.end(), | |
1172 [mirror](const std::unique_ptr<LayerMirror>& mirror_ptr) { | |
1173 return mirror_ptr.get() == mirror; | |
1174 }); | |
1175 | |
1176 DCHECK(it != mirrors_.end()); | |
1177 mirrors_.erase(it); | |
1178 } | |
1179 | |
1079 } // namespace ui | 1180 } // namespace ui |
OLD | NEW |