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) | |
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() const { return mirror_; } | |
oshima
2016/10/21 13:35:09
remote const since you're returning (exposing) int
Dominik Laskowski
2016/10/21 18:22:54
Done. No need to update the loops, because the "co
| |
66 | |
67 // LayerDelegate: | |
68 void OnPaintLayer(const PaintContext& context) override { | |
69 if (const auto delegate = mirrored_->delegate()) | |
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*) override { | |
77 mirrored_->OnMirrorDestroyed(this); | |
78 } | |
79 | |
80 private: | |
81 Layer* const mirrored_; | |
82 Layer* const mirror_; | |
83 | |
84 DISALLOW_COPY_AND_ASSIGN(LayerMirror); | |
85 }; | |
86 | |
52 Layer::Layer() | 87 Layer::Layer() |
53 : type_(LAYER_TEXTURED), | 88 : type_(LAYER_TEXTURED), |
54 compositor_(NULL), | 89 compositor_(NULL), |
55 parent_(NULL), | 90 parent_(NULL), |
56 visible_(true), | 91 visible_(true), |
57 fills_bounds_opaquely_(true), | 92 fills_bounds_opaquely_(true), |
58 fills_bounds_completely_(false), | 93 fills_bounds_completely_(false), |
59 background_blur_radius_(0), | 94 background_blur_radius_(0), |
60 layer_saturation_(0.0f), | 95 layer_saturation_(0.0f), |
61 layer_brightness_(0.0f), | 96 layer_brightness_(0.0f), |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
112 if (layer_mask_back_link_) | 147 if (layer_mask_back_link_) |
113 layer_mask_back_link_->SetMaskLayer(NULL); | 148 layer_mask_back_link_->SetMaskLayer(NULL); |
114 for (size_t i = 0; i < children_.size(); ++i) | 149 for (size_t i = 0; i < children_.size(); ++i) |
115 children_[i]->parent_ = NULL; | 150 children_[i]->parent_ = NULL; |
116 | 151 |
117 cc_layer_->RemoveFromParent(); | 152 cc_layer_->RemoveFromParent(); |
118 if (mailbox_release_callback_) | 153 if (mailbox_release_callback_) |
119 mailbox_release_callback_->Run(gpu::SyncToken(), false); | 154 mailbox_release_callback_->Run(gpu::SyncToken(), false); |
120 } | 155 } |
121 | 156 |
157 std::unique_ptr<Layer> Layer::Clone() const { | |
158 auto clone = base::MakeUnique<Layer>(type_); | |
159 | |
160 clone->SetTransform(GetTargetTransform()); | |
161 clone->SetBounds(bounds_); | |
162 clone->SetSubpixelPositionOffset(subpixel_position_offset_); | |
163 clone->SetMasksToBounds(GetMasksToBounds()); | |
164 clone->SetOpacity(GetTargetOpacity()); | |
165 clone->SetVisible(GetTargetVisibility()); | |
166 clone->SetFillsBoundsOpaquely(fills_bounds_opaquely_); | |
167 clone->SetFillsBoundsCompletely(fills_bounds_completely_); | |
168 clone->set_name(name_); | |
169 | |
170 // Background filters. | |
171 clone->SetBackgroundBlur(background_blur_radius_); | |
172 clone->SetBackgroundZoom(zoom_, zoom_inset_); | |
173 | |
174 // Filters. | |
175 clone->SetLayerSaturation(layer_saturation_); | |
176 clone->SetLayerBrightness(GetTargetBrightness()); | |
177 clone->SetLayerGrayscale(GetTargetGrayscale()); | |
178 clone->SetLayerInverted(layer_inverted_); | |
179 if (alpha_shape_) | |
180 clone->SetAlphaShape(base::MakeUnique<SkRegion>(*alpha_shape_)); | |
181 | |
182 // cc::Layer state. | |
183 if (surface_layer_ && !surface_layer_->surface_id().is_null()) { | |
184 clone->SetShowSurface( | |
185 surface_layer_->surface_id(), | |
186 surface_layer_->satisfy_callback(), | |
187 surface_layer_->require_callback(), | |
188 surface_layer_->surface_size(), | |
189 surface_layer_->surface_scale(), | |
190 frame_size_in_dip_); | |
191 } else if (type_ == LAYER_SOLID_COLOR) { | |
192 clone->SetColor(GetTargetColor()); | |
193 } | |
194 return clone; | |
195 } | |
196 | |
122 const Compositor* Layer::GetCompositor() const { | 197 const Compositor* Layer::GetCompositor() const { |
123 return GetRoot(this)->compositor_; | 198 return GetRoot(this)->compositor_; |
124 } | 199 } |
125 | 200 |
126 float Layer::opacity() const { | 201 float Layer::opacity() const { |
127 return cc_layer_->opacity(); | 202 return cc_layer_->opacity(); |
128 } | 203 } |
129 | 204 |
130 void Layer::SetCompositor(Compositor* compositor, | 205 void Layer::SetCompositor(Compositor* compositor, |
131 scoped_refptr<cc::Layer> root_layer) { | 206 scoped_refptr<cc::Layer> root_layer) { |
(...skipping 454 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
586 | 661 |
587 scoped_refptr<cc::SurfaceLayer> new_layer = | 662 scoped_refptr<cc::SurfaceLayer> new_layer = |
588 cc::SurfaceLayer::Create(satisfy_callback, require_callback); | 663 cc::SurfaceLayer::Create(satisfy_callback, require_callback); |
589 new_layer->SetSurfaceId(surface_id, scale, surface_size); | 664 new_layer->SetSurfaceId(surface_id, scale, surface_size); |
590 SwitchToLayer(new_layer); | 665 SwitchToLayer(new_layer); |
591 surface_layer_ = new_layer; | 666 surface_layer_ = new_layer; |
592 | 667 |
593 frame_size_in_dip_ = frame_size_in_dip; | 668 frame_size_in_dip_ = frame_size_in_dip; |
594 RecomputeDrawsContentAndUVRect(); | 669 RecomputeDrawsContentAndUVRect(); |
595 | 670 |
596 for (auto& observer : observer_list_) | 671 for (const auto& mirror : mirrors_) { |
597 observer.SurfaceChanged(this); | 672 mirror->layer()->SetShowSurface( |
673 surface_id, satisfy_callback, require_callback, | |
674 surface_size, scale, frame_size_in_dip); | |
675 } | |
676 } | |
677 | |
678 std::unique_ptr<Layer> Layer::Mirror() { | |
679 auto mirror = Clone(); | |
680 mirrors_.emplace_back(base::MakeUnique<LayerMirror>(this, mirror.get())); | |
681 return mirror; | |
598 } | 682 } |
599 | 683 |
600 void Layer::SetShowSolidColorContent() { | 684 void Layer::SetShowSolidColorContent() { |
601 DCHECK_EQ(type_, LAYER_SOLID_COLOR); | 685 DCHECK_EQ(type_, LAYER_SOLID_COLOR); |
602 | 686 |
603 if (solid_color_layer_.get()) | 687 if (solid_color_layer_.get()) |
604 return; | 688 return; |
605 | 689 |
606 scoped_refptr<cc::SolidColorLayer> new_layer = cc::SolidColorLayer::Create(); | 690 scoped_refptr<cc::SolidColorLayer> new_layer = cc::SolidColorLayer::Create(); |
607 SwitchToLayer(new_layer); | 691 SwitchToLayer(new_layer); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
644 nine_patch_layer_->SetBorder(border); | 728 nine_patch_layer_->SetBorder(border); |
645 } | 729 } |
646 | 730 |
647 void Layer::UpdateNinePatchOcclusion(const gfx::Rect& occlusion) { | 731 void Layer::UpdateNinePatchOcclusion(const gfx::Rect& occlusion) { |
648 DCHECK(type_ == LAYER_NINE_PATCH && nine_patch_layer_.get()); | 732 DCHECK(type_ == LAYER_NINE_PATCH && nine_patch_layer_.get()); |
649 nine_patch_layer_->SetLayerOcclusion(occlusion); | 733 nine_patch_layer_->SetLayerOcclusion(occlusion); |
650 } | 734 } |
651 | 735 |
652 void Layer::SetColor(SkColor color) { GetAnimator()->SetColor(color); } | 736 void Layer::SetColor(SkColor color) { GetAnimator()->SetColor(color); } |
653 | 737 |
654 SkColor Layer::GetTargetColor() { | 738 SkColor Layer::GetTargetColor() const { |
655 if (GetAnimator()->IsAnimatingProperty(LayerAnimationElement::COLOR)) | 739 if (animator_.get() && animator_->IsAnimatingProperty( |
656 return GetAnimator()->GetTargetColor(); | 740 LayerAnimationElement::COLOR)) |
741 return animator_->GetTargetColor(); | |
657 return cc_layer_->background_color(); | 742 return cc_layer_->background_color(); |
658 } | 743 } |
659 | 744 |
660 SkColor Layer::background_color() const { | 745 SkColor Layer::background_color() const { |
661 return cc_layer_->background_color(); | 746 return cc_layer_->background_color(); |
662 } | 747 } |
663 | 748 |
664 bool Layer::SchedulePaint(const gfx::Rect& invalid_rect) { | 749 bool Layer::SchedulePaint(const gfx::Rect& invalid_rect) { |
665 if ((type_ == LAYER_SOLID_COLOR && !texture_layer_.get()) || | 750 if ((type_ == LAYER_SOLID_COLOR && !texture_layer_.get()) || |
666 type_ == LAYER_NINE_PATCH || (!delegate_ && !mailbox_.IsValid())) | 751 type_ == LAYER_NINE_PATCH || (!delegate_ && !mailbox_.IsValid())) |
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
909 | 994 |
910 if (bounds.size() == old_bounds.size()) { | 995 if (bounds.size() == old_bounds.size()) { |
911 // Don't schedule a draw if we're invisible. We'll schedule one | 996 // Don't schedule a draw if we're invisible. We'll schedule one |
912 // automatically when we get visible. | 997 // automatically when we get visible. |
913 if (IsDrawn()) | 998 if (IsDrawn()) |
914 ScheduleDraw(); | 999 ScheduleDraw(); |
915 } else { | 1000 } else { |
916 // Always schedule a paint, even if we're invisible. | 1001 // Always schedule a paint, even if we're invisible. |
917 SchedulePaint(gfx::Rect(bounds.size())); | 1002 SchedulePaint(gfx::Rect(bounds.size())); |
918 } | 1003 } |
1004 | |
1005 if (sync_bounds_) { | |
1006 for (const auto& mirror : mirrors_) | |
1007 mirror->layer()->SetBounds(bounds); | |
1008 } | |
919 } | 1009 } |
920 | 1010 |
921 void Layer::SetTransformFromAnimation(const gfx::Transform& transform) { | 1011 void Layer::SetTransformFromAnimation(const gfx::Transform& transform) { |
922 cc_layer_->SetTransform(transform); | 1012 cc_layer_->SetTransform(transform); |
923 } | 1013 } |
924 | 1014 |
925 void Layer::SetOpacityFromAnimation(float opacity) { | 1015 void Layer::SetOpacityFromAnimation(float opacity) { |
926 cc_layer_->SetOpacity(opacity); | 1016 cc_layer_->SetOpacity(opacity); |
927 ScheduleDraw(); | 1017 ScheduleDraw(); |
928 } | 1018 } |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1069 | 1159 |
1070 if (animator_) { | 1160 if (animator_) { |
1071 animator_->DetachLayerAndTimeline(compositor); | 1161 animator_->DetachLayerAndTimeline(compositor); |
1072 animator_->RemoveFromCollection(collection); | 1162 animator_->RemoveFromCollection(collection); |
1073 } | 1163 } |
1074 | 1164 |
1075 for (auto* child : children_) | 1165 for (auto* child : children_) |
1076 child->ResetCompositorForAnimatorsInTree(compositor); | 1166 child->ResetCompositorForAnimatorsInTree(compositor); |
1077 } | 1167 } |
1078 | 1168 |
1169 void Layer::OnMirrorDestroyed(LayerMirror* mirror) { | |
1170 const auto it = std::find_if(mirrors_.begin(), mirrors_.end(), | |
1171 [mirror](const std::unique_ptr<LayerMirror>& mirror_ptr) { | |
1172 return mirror_ptr.get() == mirror; | |
1173 }); | |
1174 | |
1175 DCHECK(it != mirrors_.end()); | |
1176 mirrors_.erase(it); | |
1177 } | |
1178 | |
1079 } // namespace ui | 1179 } // namespace ui |
OLD | NEW |