Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(119)

Side by Side Diff: ui/compositor/layer.cc

Issue 2383263002: Generalize layer mirroring for phantom windows (Closed)
Patch Set: Revert layer renaming Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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/layer_owner.h"
32 #include "ui/compositor/paint_context.h" 32 #include "ui/compositor/paint_context.h"
33 #include "ui/gfx/animation/animation.h" 33 #include "ui/gfx/animation/animation.h"
34 #include "ui/gfx/canvas.h" 34 #include "ui/gfx/canvas.h"
35 #include "ui/gfx/geometry/point3_f.h" 35 #include "ui/gfx/geometry/point3_f.h"
36 #include "ui/gfx/geometry/point_conversions.h" 36 #include "ui/gfx/geometry/point_conversions.h"
37 #include "ui/gfx/geometry/size_conversions.h" 37 #include "ui/gfx/geometry/size_conversions.h"
38 #include "ui/gfx/interpolated_transform.h" 38 #include "ui/gfx/interpolated_transform.h"
39 39
40 namespace { 40 namespace {
41 41
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 ui::LayerOwner,
sky 2016/10/19 19:27:14 I find this code confusing. In particular it's a L
Dominik Laskowski 2016/10/19 22:46:38 The LayerOwner inheritance was just to reduce boil
sky 2016/10/19 23:44:26 I was suggesting you make this class the LayerObse
Dominik Laskowski 2016/10/20 02:12:30 Done.
53 public ui::LayerDelegate {
54 public:
55 explicit LayerMirror(ui::Layer* mirrored) : mirrored_(mirrored) {
56 SetLayer(mirrored->Clone());
57 layer()->AddObserver(mirrored);
58 layer()->set_delegate(this);
59 }
60
61 ~LayerMirror() override {
62 layer()->RemoveObserver(mirrored_);
63 layer()->set_delegate(nullptr);
64 }
65
66 // ui::LayerDelegate:
67 void OnPaintLayer(const ui::PaintContext& context) override {
68 if (const auto delegate = mirrored_->delegate())
69 delegate->OnPaintLayer(context);
70 }
71 void OnDelegatedFrameDamage(const gfx::Rect& damage_rect_in_dip) override {}
72 void OnDeviceScaleFactorChanged(float device_scale_factor) override {}
73
74 private:
75 ui::Layer* const mirrored_;
76
77 DISALLOW_COPY_AND_ASSIGN(LayerMirror);
78 };
79
52 Layer::Layer() 80 Layer::Layer()
53 : type_(LAYER_TEXTURED), 81 : type_(LAYER_TEXTURED),
54 compositor_(NULL), 82 compositor_(NULL),
55 parent_(NULL), 83 parent_(NULL),
56 visible_(true), 84 visible_(true),
57 fills_bounds_opaquely_(true), 85 fills_bounds_opaquely_(true),
58 fills_bounds_completely_(false), 86 fills_bounds_completely_(false),
59 background_blur_radius_(0), 87 background_blur_radius_(0),
60 layer_saturation_(0.0f), 88 layer_saturation_(0.0f),
61 layer_brightness_(0.0f), 89 layer_brightness_(0.0f),
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 if (layer_mask_back_link_) 140 if (layer_mask_back_link_)
113 layer_mask_back_link_->SetMaskLayer(NULL); 141 layer_mask_back_link_->SetMaskLayer(NULL);
114 for (size_t i = 0; i < children_.size(); ++i) 142 for (size_t i = 0; i < children_.size(); ++i)
115 children_[i]->parent_ = NULL; 143 children_[i]->parent_ = NULL;
116 144
117 cc_layer_->RemoveFromParent(); 145 cc_layer_->RemoveFromParent();
118 if (mailbox_release_callback_) 146 if (mailbox_release_callback_)
119 mailbox_release_callback_->Run(gpu::SyncToken(), false); 147 mailbox_release_callback_->Run(gpu::SyncToken(), false);
120 } 148 }
121 149
150 std::unique_ptr<Layer> Layer::Clone() const {
151 auto clone = base::MakeUnique<Layer>(type_);
152
153 clone->SetTransform(GetTargetTransform());
154 clone->SetBounds(bounds_);
155 clone->SetSubpixelPositionOffset(subpixel_position_offset_);
156 clone->SetMasksToBounds(GetMasksToBounds());
157 clone->SetOpacity(GetTargetOpacity());
158 clone->SetVisible(GetTargetVisibility());
159 clone->SetFillsBoundsOpaquely(fills_bounds_opaquely_);
160 clone->SetFillsBoundsCompletely(fills_bounds_completely_);
161 clone->set_name(name_);
162
163 // Background filters.
164 clone->SetBackgroundBlur(background_blur_radius_);
165 clone->SetBackgroundZoom(zoom_, zoom_inset_);
166
167 // Filters.
168 clone->SetLayerSaturation(layer_saturation_);
169 clone->SetLayerBrightness(GetTargetBrightness());
170 clone->SetLayerGrayscale(GetTargetGrayscale());
171 clone->SetLayerInverted(layer_inverted_);
172 if (alpha_shape_)
173 clone->SetAlphaShape(base::MakeUnique<SkRegion>(*alpha_shape_));
174
175 // cc::Layer state.
176 if (surface_layer_ && !surface_layer_->surface_id().is_null()) {
177 clone->SetShowSurface(
178 surface_layer_->surface_id(),
179 surface_layer_->satisfy_callback(),
180 surface_layer_->require_callback(),
181 surface_layer_->surface_size(),
182 surface_layer_->surface_scale(),
183 frame_size_in_dip_);
184 } else if (type_ == LAYER_SOLID_COLOR) {
185 clone->SetColor(GetTargetColor());
186 }
187 return clone;
188 }
189
122 const Compositor* Layer::GetCompositor() const { 190 const Compositor* Layer::GetCompositor() const {
123 return GetRoot(this)->compositor_; 191 return GetRoot(this)->compositor_;
124 } 192 }
125 193
126 float Layer::opacity() const { 194 float Layer::opacity() const {
127 return cc_layer_->opacity(); 195 return cc_layer_->opacity();
128 } 196 }
129 197
130 void Layer::SetCompositor(Compositor* compositor, 198 void Layer::SetCompositor(Compositor* compositor,
131 scoped_refptr<cc::Layer> root_layer) { 199 scoped_refptr<cc::Layer> root_layer) {
(...skipping 454 matching lines...) Expand 10 before | Expand all | Expand 10 after
586 654
587 scoped_refptr<cc::SurfaceLayer> new_layer = 655 scoped_refptr<cc::SurfaceLayer> new_layer =
588 cc::SurfaceLayer::Create(satisfy_callback, require_callback); 656 cc::SurfaceLayer::Create(satisfy_callback, require_callback);
589 new_layer->SetSurfaceId(surface_id, scale, surface_size); 657 new_layer->SetSurfaceId(surface_id, scale, surface_size);
590 SwitchToLayer(new_layer); 658 SwitchToLayer(new_layer);
591 surface_layer_ = new_layer; 659 surface_layer_ = new_layer;
592 660
593 frame_size_in_dip_ = frame_size_in_dip; 661 frame_size_in_dip_ = frame_size_in_dip;
594 RecomputeDrawsContentAndUVRect(); 662 RecomputeDrawsContentAndUVRect();
595 663
596 for (auto& observer : observer_list_) 664 for (const auto& mirror : mirrors_) {
597 observer.SurfaceChanged(this); 665 mirror->layer()->SetShowSurface(
666 surface_id, satisfy_callback, require_callback,
667 surface_size, scale, frame_size_in_dip);
668 }
669 }
670
671 std::unique_ptr<Layer> Layer::Mirror() {
672 mirrors_.emplace_back(base::MakeUnique<LayerMirror>(this));
673 return mirrors_.back()->AcquireLayer();
598 } 674 }
599 675
600 void Layer::SetShowSolidColorContent() { 676 void Layer::SetShowSolidColorContent() {
601 DCHECK_EQ(type_, LAYER_SOLID_COLOR); 677 DCHECK_EQ(type_, LAYER_SOLID_COLOR);
602 678
603 if (solid_color_layer_.get()) 679 if (solid_color_layer_.get())
604 return; 680 return;
605 681
606 scoped_refptr<cc::SolidColorLayer> new_layer = cc::SolidColorLayer::Create(); 682 scoped_refptr<cc::SolidColorLayer> new_layer = cc::SolidColorLayer::Create();
607 SwitchToLayer(new_layer); 683 SwitchToLayer(new_layer);
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
644 nine_patch_layer_->SetBorder(border); 720 nine_patch_layer_->SetBorder(border);
645 } 721 }
646 722
647 void Layer::UpdateNinePatchOcclusion(const gfx::Rect& occlusion) { 723 void Layer::UpdateNinePatchOcclusion(const gfx::Rect& occlusion) {
648 DCHECK(type_ == LAYER_NINE_PATCH && nine_patch_layer_.get()); 724 DCHECK(type_ == LAYER_NINE_PATCH && nine_patch_layer_.get());
649 nine_patch_layer_->SetLayerOcclusion(occlusion); 725 nine_patch_layer_->SetLayerOcclusion(occlusion);
650 } 726 }
651 727
652 void Layer::SetColor(SkColor color) { GetAnimator()->SetColor(color); } 728 void Layer::SetColor(SkColor color) { GetAnimator()->SetColor(color); }
653 729
654 SkColor Layer::GetTargetColor() { 730 SkColor Layer::GetTargetColor() const {
655 if (GetAnimator()->IsAnimatingProperty(LayerAnimationElement::COLOR)) 731 if (animator_.get() && animator_->IsAnimatingProperty(
656 return GetAnimator()->GetTargetColor(); 732 LayerAnimationElement::COLOR))
733 return animator_->GetTargetColor();
657 return cc_layer_->background_color(); 734 return cc_layer_->background_color();
658 } 735 }
659 736
660 SkColor Layer::background_color() const { 737 SkColor Layer::background_color() const {
661 return cc_layer_->background_color(); 738 return cc_layer_->background_color();
662 } 739 }
663 740
664 bool Layer::SchedulePaint(const gfx::Rect& invalid_rect) { 741 bool Layer::SchedulePaint(const gfx::Rect& invalid_rect) {
665 if ((type_ == LAYER_SOLID_COLOR && !texture_layer_.get()) || 742 if ((type_ == LAYER_SOLID_COLOR && !texture_layer_.get()) ||
666 type_ == LAYER_NINE_PATCH || (!delegate_ && !mailbox_.IsValid())) 743 type_ == LAYER_NINE_PATCH || (!delegate_ && !mailbox_.IsValid()))
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after
909 986
910 if (bounds.size() == old_bounds.size()) { 987 if (bounds.size() == old_bounds.size()) {
911 // Don't schedule a draw if we're invisible. We'll schedule one 988 // Don't schedule a draw if we're invisible. We'll schedule one
912 // automatically when we get visible. 989 // automatically when we get visible.
913 if (IsDrawn()) 990 if (IsDrawn())
914 ScheduleDraw(); 991 ScheduleDraw();
915 } else { 992 } else {
916 // Always schedule a paint, even if we're invisible. 993 // Always schedule a paint, even if we're invisible.
917 SchedulePaint(gfx::Rect(bounds.size())); 994 SchedulePaint(gfx::Rect(bounds.size()));
918 } 995 }
996
997 if (sync_bounds_) {
998 for (const auto& mirror : mirrors_)
999 mirror->layer()->SetBounds(bounds);
1000 }
919 } 1001 }
920 1002
921 void Layer::SetTransformFromAnimation(const gfx::Transform& transform) { 1003 void Layer::SetTransformFromAnimation(const gfx::Transform& transform) {
922 cc_layer_->SetTransform(transform); 1004 cc_layer_->SetTransform(transform);
923 } 1005 }
924 1006
925 void Layer::SetOpacityFromAnimation(float opacity) { 1007 void Layer::SetOpacityFromAnimation(float opacity) {
926 cc_layer_->SetOpacity(opacity); 1008 cc_layer_->SetOpacity(opacity);
927 ScheduleDraw(); 1009 ScheduleDraw();
928 } 1010 }
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
998 1080
999 cc::Layer* Layer::GetCcLayer() const { 1081 cc::Layer* Layer::GetCcLayer() const {
1000 return cc_layer_; 1082 return cc_layer_;
1001 } 1083 }
1002 1084
1003 LayerThreadedAnimationDelegate* Layer::GetThreadedAnimationDelegate() { 1085 LayerThreadedAnimationDelegate* Layer::GetThreadedAnimationDelegate() {
1004 DCHECK(animator_); 1086 DCHECK(animator_);
1005 return animator_.get(); 1087 return animator_.get();
1006 } 1088 }
1007 1089
1090 void Layer::LayerDestroyed(Layer* layer) {
1091 const auto it = std::find_if(mirrors_.begin(), mirrors_.end(),
1092 [layer](const std::unique_ptr<LayerMirror>& mirror) {
1093 return mirror->layer() == layer;
1094 });
1095
1096 DCHECK(it != mirrors_.end());
1097 mirrors_.erase(it);
1098 }
1099
1008 void Layer::CreateCcLayer() { 1100 void Layer::CreateCcLayer() {
1009 if (type_ == LAYER_SOLID_COLOR) { 1101 if (type_ == LAYER_SOLID_COLOR) {
1010 solid_color_layer_ = cc::SolidColorLayer::Create(); 1102 solid_color_layer_ = cc::SolidColorLayer::Create();
1011 cc_layer_ = solid_color_layer_.get(); 1103 cc_layer_ = solid_color_layer_.get();
1012 } else if (type_ == LAYER_NINE_PATCH) { 1104 } else if (type_ == LAYER_NINE_PATCH) {
1013 nine_patch_layer_ = cc::NinePatchLayer::Create(); 1105 nine_patch_layer_ = cc::NinePatchLayer::Create();
1014 cc_layer_ = nine_patch_layer_.get(); 1106 cc_layer_ = nine_patch_layer_.get();
1015 } else { 1107 } else {
1016 content_layer_ = cc::PictureLayer::Create(this); 1108 content_layer_ = cc::PictureLayer::Create(this);
1017 cc_layer_ = content_layer_.get(); 1109 cc_layer_ = content_layer_.get();
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
1070 if (animator_) { 1162 if (animator_) {
1071 animator_->DetachLayerAndTimeline(compositor); 1163 animator_->DetachLayerAndTimeline(compositor);
1072 animator_->RemoveFromCollection(collection); 1164 animator_->RemoveFromCollection(collection);
1073 } 1165 }
1074 1166
1075 for (auto* child : children_) 1167 for (auto* child : children_)
1076 child->ResetCompositorForAnimatorsInTree(compositor); 1168 child->ResetCompositorForAnimatorsInTree(compositor);
1077 } 1169 }
1078 1170
1079 } // namespace ui 1171 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698