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

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

Issue 2383263002: Generalize layer mirroring for phantom windows (Closed)
Patch Set: Rebase 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"
32 #include "ui/compositor/paint_context.h" 31 #include "ui/compositor/paint_context.h"
33 #include "ui/gfx/animation/animation.h" 32 #include "ui/gfx/animation/animation.h"
34 #include "ui/gfx/canvas.h" 33 #include "ui/gfx/canvas.h"
35 #include "ui/gfx/geometry/point3_f.h" 34 #include "ui/gfx/geometry/point3_f.h"
36 #include "ui/gfx/geometry/point_conversions.h" 35 #include "ui/gfx/geometry/point_conversions.h"
37 #include "ui/gfx/geometry/size_conversions.h" 36 #include "ui/gfx/geometry/size_conversions.h"
38 #include "ui/gfx/interpolated_transform.h" 37 #include "ui/gfx/interpolated_transform.h"
39 38
40 namespace { 39 namespace {
41 40
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 zoom_(1), 88 zoom_(1),
90 zoom_inset_(0), 89 zoom_inset_(0),
91 delegate_(NULL), 90 delegate_(NULL),
92 owner_(NULL), 91 owner_(NULL),
93 cc_layer_(NULL), 92 cc_layer_(NULL),
94 device_scale_factor_(1.0f) { 93 device_scale_factor_(1.0f) {
95 CreateCcLayer(); 94 CreateCcLayer();
96 } 95 }
97 96
98 Layer::~Layer() { 97 Layer::~Layer() {
98 for (auto* mirror : mirrors_)
99 mirror->RemoveObserver(this);
100
99 for (auto& observer : observer_list_) 101 for (auto& observer : observer_list_)
100 observer.LayerDestroyed(this); 102 observer.LayerDestroyed(this);
101 103
102 // Destroying the animator may cause observers to use the layer (and 104 // Destroying the animator may cause observers to use the layer (and
103 // indirectly the WebLayer). Destroy the animator first so that the WebLayer 105 // indirectly the WebLayer). Destroy the animator first so that the WebLayer
104 // is still around. 106 // is still around.
105 SetAnimator(nullptr); 107 SetAnimator(nullptr);
106 if (compositor_) 108 if (compositor_)
107 compositor_->SetRootLayer(NULL); 109 compositor_->SetRootLayer(NULL);
108 if (parent_) 110 if (parent_)
109 parent_->Remove(this); 111 parent_->Remove(this);
110 if (layer_mask_) 112 if (layer_mask_)
111 SetMaskLayer(NULL); 113 SetMaskLayer(NULL);
112 if (layer_mask_back_link_) 114 if (layer_mask_back_link_)
113 layer_mask_back_link_->SetMaskLayer(NULL); 115 layer_mask_back_link_->SetMaskLayer(NULL);
114 for (size_t i = 0; i < children_.size(); ++i) 116 for (size_t i = 0; i < children_.size(); ++i)
115 children_[i]->parent_ = NULL; 117 children_[i]->parent_ = NULL;
116 118
117 cc_layer_->RemoveFromParent(); 119 cc_layer_->RemoveFromParent();
118 if (mailbox_release_callback_) 120 if (mailbox_release_callback_)
119 mailbox_release_callback_->Run(gpu::SyncToken(), false); 121 mailbox_release_callback_->Run(gpu::SyncToken(), false);
120 } 122 }
121 123
124 std::unique_ptr<Layer> Layer::Clone() const {
125 auto clone = base::MakeUnique<Layer>(type_);
126
127 clone->SetVisible(GetTargetVisibility());
128 clone->SetOpacity(GetTargetOpacity());
sky 2016/10/14 22:36:37 What about int background_blur_radius_, satuations
Dominik Laskowski 2016/10/17 19:53:21 This code was pulled from LayerOwner::RecreateLaye
129 clone->SetBounds(bounds_);
130 clone->SetMasksToBounds(GetMasksToBounds());
131 clone->set_name(name_);
132 clone->SetFillsBoundsOpaquely(fills_bounds_opaquely_);
133 clone->SetFillsBoundsCompletely(fills_bounds_completely_);
134 clone->SetSubpixelPositionOffset(subpixel_position_offset_);
135 clone->SetLayerInverted(layer_inverted_);
136 clone->SetTransform(GetTargetTransform());
137
138 if (type_ == LAYER_SOLID_COLOR)
139 clone->SetColor(GetTargetColor());
140 if (alpha_shape_)
141 clone->SetAlphaShape(base::MakeUnique<SkRegion>(*alpha_shape_));
142
143 if (surface_layer_ && !surface_layer_->surface_id().is_null()) {
144 clone->SetShowSurface(
145 surface_layer_->surface_id(),
146 surface_layer_->satisfy_callback(),
147 surface_layer_->require_callback(),
148 surface_layer_->surface_size(),
149 surface_layer_->surface_scale(),
150 frame_size_in_dip_);
151 }
152 return clone;
153 }
154
122 const Compositor* Layer::GetCompositor() const { 155 const Compositor* Layer::GetCompositor() const {
123 return GetRoot(this)->compositor_; 156 return GetRoot(this)->compositor_;
124 } 157 }
125 158
126 float Layer::opacity() const { 159 float Layer::opacity() const {
127 return cc_layer_->opacity(); 160 return cc_layer_->opacity();
128 } 161 }
129 162
130 void Layer::SetCompositor(Compositor* compositor, 163 void Layer::SetCompositor(Compositor* compositor,
131 scoped_refptr<cc::Layer> root_layer) { 164 scoped_refptr<cc::Layer> root_layer) {
(...skipping 454 matching lines...) Expand 10 before | Expand all | Expand 10 after
586 619
587 scoped_refptr<cc::SurfaceLayer> new_layer = 620 scoped_refptr<cc::SurfaceLayer> new_layer =
588 cc::SurfaceLayer::Create(satisfy_callback, require_callback); 621 cc::SurfaceLayer::Create(satisfy_callback, require_callback);
589 new_layer->SetSurfaceId(surface_id, scale, surface_size); 622 new_layer->SetSurfaceId(surface_id, scale, surface_size);
590 SwitchToLayer(new_layer); 623 SwitchToLayer(new_layer);
591 surface_layer_ = new_layer; 624 surface_layer_ = new_layer;
592 625
593 frame_size_in_dip_ = frame_size_in_dip; 626 frame_size_in_dip_ = frame_size_in_dip;
594 RecomputeDrawsContentAndUVRect(); 627 RecomputeDrawsContentAndUVRect();
595 628
596 for (auto& observer : observer_list_) 629 for (auto* mirror : mirrors_) {
597 observer.SurfaceChanged(this); 630 mirror->SetShowSurface(surface_id, satisfy_callback, require_callback,
631 surface_size, scale, frame_size_in_dip);
632 }
633 }
634
635 std::unique_ptr<Layer> Layer::Mirror() {
636 std::unique_ptr<Layer> mirror = Clone();
637 mirror->AddObserver(this);
638 mirrors_.push_back(mirror.get());
639 return mirror;
598 } 640 }
599 641
600 void Layer::SetShowSolidColorContent() { 642 void Layer::SetShowSolidColorContent() {
601 DCHECK_EQ(type_, LAYER_SOLID_COLOR); 643 DCHECK_EQ(type_, LAYER_SOLID_COLOR);
602 644
603 if (solid_color_layer_.get()) 645 if (solid_color_layer_.get())
604 return; 646 return;
605 647
606 scoped_refptr<cc::SolidColorLayer> new_layer = cc::SolidColorLayer::Create(); 648 scoped_refptr<cc::SolidColorLayer> new_layer = cc::SolidColorLayer::Create();
607 SwitchToLayer(new_layer); 649 SwitchToLayer(new_layer);
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
644 nine_patch_layer_->SetBorder(border); 686 nine_patch_layer_->SetBorder(border);
645 } 687 }
646 688
647 void Layer::UpdateNinePatchOcclusion(const gfx::Rect& occlusion) { 689 void Layer::UpdateNinePatchOcclusion(const gfx::Rect& occlusion) {
648 DCHECK(type_ == LAYER_NINE_PATCH && nine_patch_layer_.get()); 690 DCHECK(type_ == LAYER_NINE_PATCH && nine_patch_layer_.get());
649 nine_patch_layer_->SetLayerOcclusion(occlusion); 691 nine_patch_layer_->SetLayerOcclusion(occlusion);
650 } 692 }
651 693
652 void Layer::SetColor(SkColor color) { GetAnimator()->SetColor(color); } 694 void Layer::SetColor(SkColor color) { GetAnimator()->SetColor(color); }
653 695
654 SkColor Layer::GetTargetColor() { 696 SkColor Layer::GetTargetColor() const {
655 if (GetAnimator()->IsAnimatingProperty(LayerAnimationElement::COLOR)) 697 if (animator_.get() && animator_->IsAnimatingProperty(
656 return GetAnimator()->GetTargetColor(); 698 LayerAnimationElement::COLOR))
699 return animator_->GetTargetColor();
657 return cc_layer_->background_color(); 700 return cc_layer_->background_color();
658 } 701 }
659 702
660 SkColor Layer::background_color() const { 703 SkColor Layer::background_color() const {
661 return cc_layer_->background_color(); 704 return cc_layer_->background_color();
662 } 705 }
663 706
664 bool Layer::SchedulePaint(const gfx::Rect& invalid_rect) { 707 bool Layer::SchedulePaint(const gfx::Rect& invalid_rect) {
665 if ((type_ == LAYER_SOLID_COLOR && !texture_layer_.get()) || 708 if ((type_ == LAYER_SOLID_COLOR && !texture_layer_.get()) ||
666 type_ == LAYER_NINE_PATCH || (!delegate_ && !mailbox_.IsValid())) 709 type_ == LAYER_NINE_PATCH || (!delegate_ && !mailbox_.IsValid()))
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after
909 952
910 if (bounds.size() == old_bounds.size()) { 953 if (bounds.size() == old_bounds.size()) {
911 // Don't schedule a draw if we're invisible. We'll schedule one 954 // Don't schedule a draw if we're invisible. We'll schedule one
912 // automatically when we get visible. 955 // automatically when we get visible.
913 if (IsDrawn()) 956 if (IsDrawn())
914 ScheduleDraw(); 957 ScheduleDraw();
915 } else { 958 } else {
916 // Always schedule a paint, even if we're invisible. 959 // Always schedule a paint, even if we're invisible.
917 SchedulePaint(gfx::Rect(bounds.size())); 960 SchedulePaint(gfx::Rect(bounds.size()));
918 } 961 }
962
963 if (sync_bounds_) {
964 for (auto* mirror : mirrors_)
965 mirror->SetBounds(bounds);
966 }
919 } 967 }
920 968
921 void Layer::SetTransformFromAnimation(const gfx::Transform& transform) { 969 void Layer::SetTransformFromAnimation(const gfx::Transform& transform) {
922 cc_layer_->SetTransform(transform); 970 cc_layer_->SetTransform(transform);
923 } 971 }
924 972
925 void Layer::SetOpacityFromAnimation(float opacity) { 973 void Layer::SetOpacityFromAnimation(float opacity) {
926 cc_layer_->SetOpacity(opacity); 974 cc_layer_->SetOpacity(opacity);
927 ScheduleDraw(); 975 ScheduleDraw();
928 } 976 }
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
998 1046
999 cc::Layer* Layer::GetCcLayer() const { 1047 cc::Layer* Layer::GetCcLayer() const {
1000 return cc_layer_; 1048 return cc_layer_;
1001 } 1049 }
1002 1050
1003 LayerThreadedAnimationDelegate* Layer::GetThreadedAnimationDelegate() { 1051 LayerThreadedAnimationDelegate* Layer::GetThreadedAnimationDelegate() {
1004 DCHECK(animator_); 1052 DCHECK(animator_);
1005 return animator_.get(); 1053 return animator_.get();
1006 } 1054 }
1007 1055
1056 void Layer::LayerDestroyed(Layer* mirror) {
1057 const auto it = std::find(mirrors_.begin(), mirrors_.end(), mirror);
1058 DCHECK(it != mirrors_.end());
1059 mirrors_.erase(it);
1060 }
1061
1008 void Layer::CreateCcLayer() { 1062 void Layer::CreateCcLayer() {
1009 if (type_ == LAYER_SOLID_COLOR) { 1063 if (type_ == LAYER_SOLID_COLOR) {
1010 solid_color_layer_ = cc::SolidColorLayer::Create(); 1064 solid_color_layer_ = cc::SolidColorLayer::Create();
1011 cc_layer_ = solid_color_layer_.get(); 1065 cc_layer_ = solid_color_layer_.get();
1012 } else if (type_ == LAYER_NINE_PATCH) { 1066 } else if (type_ == LAYER_NINE_PATCH) {
1013 nine_patch_layer_ = cc::NinePatchLayer::Create(); 1067 nine_patch_layer_ = cc::NinePatchLayer::Create();
1014 cc_layer_ = nine_patch_layer_.get(); 1068 cc_layer_ = nine_patch_layer_.get();
1015 } else { 1069 } else {
1016 content_layer_ = cc::PictureLayer::Create(this); 1070 content_layer_ = cc::PictureLayer::Create(this);
1017 cc_layer_ = content_layer_.get(); 1071 cc_layer_ = content_layer_.get();
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
1070 if (animator_) { 1124 if (animator_) {
1071 animator_->DetachLayerAndTimeline(compositor); 1125 animator_->DetachLayerAndTimeline(compositor);
1072 animator_->RemoveFromCollection(collection); 1126 animator_->RemoveFromCollection(collection);
1073 } 1127 }
1074 1128
1075 for (auto* child : children_) 1129 for (auto* child : children_)
1076 child->ResetCompositorForAnimatorsInTree(compositor); 1130 child->ResetCompositorForAnimatorsInTree(compositor);
1077 } 1131 }
1078 1132
1079 } // namespace ui 1133 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698