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

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

Issue 2383263002: Generalize layer mirroring for phantom windows (Closed)
Patch Set: Fix another test and update comment 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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 layer_mask_back_link_(NULL), 87 layer_mask_back_link_(NULL),
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
97 Layer::Layer(const Layer& layer)
98 : Layer(layer.type_) {
99 SetVisible(layer.GetTargetVisibility());
100 SetOpacity(layer.GetTargetOpacity());
101 SetBounds(layer.bounds_);
102 SetMasksToBounds(layer.GetMasksToBounds());
103 set_name(layer.name_);
104 SetFillsBoundsOpaquely(layer.fills_bounds_opaquely_);
105 SetFillsBoundsCompletely(layer.fills_bounds_completely_);
106 SetSubpixelPositionOffset(layer.subpixel_position_offset_);
107 SetLayerInverted(layer.layer_inverted_);
108 SetTransform(layer.GetTargetTransform());
109 if (layer.type_ == LAYER_SOLID_COLOR)
110 SetColor(layer.GetTargetColor());
111 if (SkRegion* alpha_shape = layer.alpha_shape())
112 SetAlphaShape(base::MakeUnique<SkRegion>(*alpha_shape));
113
114 const cc::SurfaceLayer* const surface = layer.surface_layer_.get();
115 if (surface && !surface->surface_id().is_null()) {
116 SetShowSurface(
117 surface->surface_id(),
118 surface->satisfy_callback(), surface->require_callback(),
119 surface->surface_size(), surface->surface_scale(),
120 layer.frame_size_in_dip_);
121 }
122 }
123
98 Layer::~Layer() { 124 Layer::~Layer() {
125 for (auto* mirror : mirrors_)
126 mirror->RemoveObserver(this);
127
99 FOR_EACH_OBSERVER(LayerObserver, observer_list_, LayerDestroyed(this)); 128 FOR_EACH_OBSERVER(LayerObserver, observer_list_, LayerDestroyed(this));
100 129
101 // Destroying the animator may cause observers to use the layer (and 130 // Destroying the animator may cause observers to use the layer (and
102 // indirectly the WebLayer). Destroy the animator first so that the WebLayer 131 // indirectly the WebLayer). Destroy the animator first so that the WebLayer
103 // is still around. 132 // is still around.
104 SetAnimator(nullptr); 133 SetAnimator(nullptr);
105 if (compositor_) 134 if (compositor_)
106 compositor_->SetRootLayer(NULL); 135 compositor_->SetRootLayer(NULL);
107 if (parent_) 136 if (parent_)
108 parent_->Remove(this); 137 parent_->Remove(this);
(...skipping 476 matching lines...) Expand 10 before | Expand all | Expand 10 after
585 614
586 scoped_refptr<cc::SurfaceLayer> new_layer = 615 scoped_refptr<cc::SurfaceLayer> new_layer =
587 cc::SurfaceLayer::Create(satisfy_callback, require_callback); 616 cc::SurfaceLayer::Create(satisfy_callback, require_callback);
588 new_layer->SetSurfaceId(surface_id, scale, surface_size); 617 new_layer->SetSurfaceId(surface_id, scale, surface_size);
589 SwitchToLayer(new_layer); 618 SwitchToLayer(new_layer);
590 surface_layer_ = new_layer; 619 surface_layer_ = new_layer;
591 620
592 frame_size_in_dip_ = frame_size_in_dip; 621 frame_size_in_dip_ = frame_size_in_dip;
593 RecomputeDrawsContentAndUVRect(); 622 RecomputeDrawsContentAndUVRect();
594 623
595 FOR_EACH_OBSERVER(LayerObserver, observer_list_, SurfaceChanged(this)); 624 for (auto* mirror : mirrors_)
oshima 2016/10/12 19:31:41 you need {} for this case
Dominik Laskowski 2016/10/13 17:58:56 Done.
625 mirror->SetShowSurface(surface_id, satisfy_callback, require_callback,
626 surface_size, scale, frame_size_in_dip);
627 }
628
629 std::unique_ptr<Layer> Layer::Mirror() {
630 std::unique_ptr<Layer> mirror(new Layer(*this));
631 mirror->AddObserver(this);
632 mirrors_.push_back(mirror.get());
633 return mirror;
596 } 634 }
597 635
598 void Layer::SetShowSolidColorContent() { 636 void Layer::SetShowSolidColorContent() {
599 DCHECK_EQ(type_, LAYER_SOLID_COLOR); 637 DCHECK_EQ(type_, LAYER_SOLID_COLOR);
600 638
601 if (solid_color_layer_.get()) 639 if (solid_color_layer_.get())
602 return; 640 return;
603 641
604 scoped_refptr<cc::SolidColorLayer> new_layer = cc::SolidColorLayer::Create(); 642 scoped_refptr<cc::SolidColorLayer> new_layer = cc::SolidColorLayer::Create();
605 SwitchToLayer(new_layer); 643 SwitchToLayer(new_layer);
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
642 nine_patch_layer_->SetBorder(border); 680 nine_patch_layer_->SetBorder(border);
643 } 681 }
644 682
645 void Layer::UpdateNinePatchOcclusion(const gfx::Rect& occlusion) { 683 void Layer::UpdateNinePatchOcclusion(const gfx::Rect& occlusion) {
646 DCHECK(type_ == LAYER_NINE_PATCH && nine_patch_layer_.get()); 684 DCHECK(type_ == LAYER_NINE_PATCH && nine_patch_layer_.get());
647 nine_patch_layer_->SetLayerOcclusion(occlusion); 685 nine_patch_layer_->SetLayerOcclusion(occlusion);
648 } 686 }
649 687
650 void Layer::SetColor(SkColor color) { GetAnimator()->SetColor(color); } 688 void Layer::SetColor(SkColor color) { GetAnimator()->SetColor(color); }
651 689
652 SkColor Layer::GetTargetColor() { 690 SkColor Layer::GetTargetColor() const {
653 if (GetAnimator()->IsAnimatingProperty(LayerAnimationElement::COLOR)) 691 if (animator_.get() && animator_->IsAnimatingProperty(
654 return GetAnimator()->GetTargetColor(); 692 LayerAnimationElement::COLOR))
693 return animator_->GetTargetColor();
655 return cc_layer_->background_color(); 694 return cc_layer_->background_color();
656 } 695 }
657 696
658 SkColor Layer::background_color() const { 697 SkColor Layer::background_color() const {
659 return cc_layer_->background_color(); 698 return cc_layer_->background_color();
660 } 699 }
661 700
662 bool Layer::SchedulePaint(const gfx::Rect& invalid_rect) { 701 bool Layer::SchedulePaint(const gfx::Rect& invalid_rect) {
663 if ((type_ == LAYER_SOLID_COLOR && !texture_layer_.get()) || 702 if ((type_ == LAYER_SOLID_COLOR && !texture_layer_.get()) ||
664 type_ == LAYER_NINE_PATCH || (!delegate_ && !mailbox_.IsValid())) 703 type_ == LAYER_NINE_PATCH || (!delegate_ && !mailbox_.IsValid()))
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after
909 948
910 if (was_move) { 949 if (was_move) {
911 // Don't schedule a draw if we're invisible. We'll schedule one 950 // Don't schedule a draw if we're invisible. We'll schedule one
912 // automatically when we get visible. 951 // automatically when we get visible.
913 if (IsDrawn()) 952 if (IsDrawn())
914 ScheduleDraw(); 953 ScheduleDraw();
915 } else { 954 } else {
916 // Always schedule a paint, even if we're invisible. 955 // Always schedule a paint, even if we're invisible.
917 SchedulePaint(gfx::Rect(bounds.size())); 956 SchedulePaint(gfx::Rect(bounds.size()));
918 } 957 }
958
959 if (sync_bounds_)
oshima 2016/10/12 19:31:41 nit {} or early exit
Dominik Laskowski 2016/10/13 17:58:56 Done.
960 for (auto* mirror : mirrors_)
961 mirror->SetBounds(bounds);
919 } 962 }
920 963
921 void Layer::SetTransformFromAnimation(const gfx::Transform& transform) { 964 void Layer::SetTransformFromAnimation(const gfx::Transform& transform) {
922 cc_layer_->SetTransform(transform); 965 cc_layer_->SetTransform(transform);
923 } 966 }
924 967
925 void Layer::SetOpacityFromAnimation(float opacity) { 968 void Layer::SetOpacityFromAnimation(float opacity) {
926 cc_layer_->SetOpacity(opacity); 969 cc_layer_->SetOpacity(opacity);
927 ScheduleDraw(); 970 ScheduleDraw();
928 } 971 }
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
998 1041
999 cc::Layer* Layer::GetCcLayer() const { 1042 cc::Layer* Layer::GetCcLayer() const {
1000 return cc_layer_; 1043 return cc_layer_;
1001 } 1044 }
1002 1045
1003 LayerThreadedAnimationDelegate* Layer::GetThreadedAnimationDelegate() { 1046 LayerThreadedAnimationDelegate* Layer::GetThreadedAnimationDelegate() {
1004 DCHECK(animator_); 1047 DCHECK(animator_);
1005 return animator_.get(); 1048 return animator_.get();
1006 } 1049 }
1007 1050
1051 void Layer::LayerDestroyed(Layer* mirror) {
1052 const auto it = std::find(mirrors_.begin(), mirrors_.end(), mirror);
1053 DCHECK(it != mirrors_.end());
1054 mirrors_.erase(it);
1055 }
1056
1008 void Layer::CreateCcLayer() { 1057 void Layer::CreateCcLayer() {
1009 if (type_ == LAYER_SOLID_COLOR) { 1058 if (type_ == LAYER_SOLID_COLOR) {
1010 solid_color_layer_ = cc::SolidColorLayer::Create(); 1059 solid_color_layer_ = cc::SolidColorLayer::Create();
1011 cc_layer_ = solid_color_layer_.get(); 1060 cc_layer_ = solid_color_layer_.get();
1012 } else if (type_ == LAYER_NINE_PATCH) { 1061 } else if (type_ == LAYER_NINE_PATCH) {
1013 nine_patch_layer_ = cc::NinePatchLayer::Create(); 1062 nine_patch_layer_ = cc::NinePatchLayer::Create();
1014 cc_layer_ = nine_patch_layer_.get(); 1063 cc_layer_ = nine_patch_layer_.get();
1015 } else { 1064 } else {
1016 content_layer_ = cc::PictureLayer::Create(this); 1065 content_layer_ = cc::PictureLayer::Create(this);
1017 cc_layer_ = content_layer_.get(); 1066 cc_layer_ = content_layer_.get();
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
1070 if (animator_) { 1119 if (animator_) {
1071 animator_->DetachLayerAndTimeline(compositor); 1120 animator_->DetachLayerAndTimeline(compositor);
1072 animator_->RemoveFromCollection(collection); 1121 animator_->RemoveFromCollection(collection);
1073 } 1122 }
1074 1123
1075 for (auto* child : children_) 1124 for (auto* child : children_)
1076 child->ResetCompositorForAnimatorsInTree(compositor); 1125 child->ResetCompositorForAnimatorsInTree(compositor);
1077 } 1126 }
1078 1127
1079 } // namespace ui 1128 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698