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

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

Issue 2383263002: Generalize layer mirroring for phantom windows (Closed)
Patch Set: Rebase Created 4 years, 1 month 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
« no previous file with comments | « ui/compositor/layer_owner.h ('k') | ui/compositor/layer_owner_delegate.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_owner.h" 5 #include "ui/compositor/layer_owner.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/memory/ptr_util.h" 9 #include "base/memory/ptr_util.h"
10 #include "ui/compositor/layer_owner_delegate.h" 10 #include "ui/compositor/layer_owner_delegate.h"
11 11
12 namespace ui { 12 namespace ui {
13 13
14 LayerOwner::LayerOwner() : layer_(NULL), layer_owner_delegate_(NULL) { 14 LayerOwner::LayerOwner() : layer_(NULL), layer_owner_delegate_(NULL) {
15 } 15 }
16 16
17 LayerOwner::~LayerOwner() { 17 LayerOwner::~LayerOwner() {
18 } 18 }
19 19
20 void LayerOwner::SetLayer(Layer* layer) { 20 void LayerOwner::SetLayer(std::unique_ptr<Layer> layer) {
21 DCHECK(!OwnsLayer()); 21 DCHECK(!OwnsLayer());
22 layer_owner_.reset(layer); 22 layer_owner_ = std::move(layer);
23 layer_ = layer; 23 layer_ = layer_owner_.get();
24 layer_->owner_ = this; 24 layer_->owner_ = this;
25 } 25 }
26 26
27 std::unique_ptr<Layer> LayerOwner::AcquireLayer() { 27 std::unique_ptr<Layer> LayerOwner::AcquireLayer() {
28 if (layer_owner_) 28 if (layer_owner_)
29 layer_owner_->owner_ = NULL; 29 layer_owner_->owner_ = NULL;
30 return std::move(layer_owner_); 30 return std::move(layer_owner_);
31 } 31 }
32 32
33 std::unique_ptr<Layer> LayerOwner::RecreateLayer() { 33 std::unique_ptr<Layer> LayerOwner::RecreateLayer() {
34 std::unique_ptr<ui::Layer> old_layer(AcquireLayer()); 34 std::unique_ptr<ui::Layer> old_layer(AcquireLayer());
35 if (!old_layer) 35 if (!old_layer)
36 return old_layer; 36 return old_layer;
37 37
38 LayerDelegate* old_delegate = old_layer->delegate(); 38 LayerDelegate* old_delegate = old_layer->delegate();
39 old_layer->set_delegate(NULL); 39 old_layer->set_delegate(NULL);
40 40
41 const gfx::Rect layer_bounds(old_layer->bounds()); 41 SetLayer(old_layer->Clone());
42 Layer* new_layer = new ui::Layer(old_layer->type());
43 SetLayer(new_layer);
44 new_layer->SetVisible(old_layer->GetTargetVisibility());
45 new_layer->SetOpacity(old_layer->GetTargetOpacity());
46 new_layer->SetBounds(layer_bounds);
47 new_layer->SetMasksToBounds(old_layer->GetMasksToBounds());
48 new_layer->set_name(old_layer->name());
49 new_layer->SetFillsBoundsOpaquely(old_layer->fills_bounds_opaquely());
50 new_layer->SetFillsBoundsCompletely(old_layer->FillsBoundsCompletely());
51 new_layer->SetSubpixelPositionOffset(old_layer->subpixel_position_offset());
52 new_layer->SetLayerInverted(old_layer->layer_inverted());
53 new_layer->SetTransform(old_layer->GetTargetTransform());
54 if (old_layer->type() == LAYER_SOLID_COLOR)
55 new_layer->SetColor(old_layer->GetTargetColor());
56 SkRegion* alpha_shape = old_layer->alpha_shape();
57 if (alpha_shape)
58 new_layer->SetAlphaShape(base::MakeUnique<SkRegion>(*alpha_shape));
59 42
60 if (old_layer->parent()) { 43 if (old_layer->parent()) {
61 // Install new layer as a sibling of the old layer, stacked below it. 44 // Install new layer as a sibling of the old layer, stacked below it.
62 old_layer->parent()->Add(new_layer); 45 old_layer->parent()->Add(layer_);
63 old_layer->parent()->StackBelow(new_layer, old_layer.get()); 46 old_layer->parent()->StackBelow(layer_, old_layer.get());
64 } else if (old_layer->GetCompositor()) { 47 } else if (old_layer->GetCompositor()) {
65 // If old_layer was the layer tree root then we need to move the Compositor 48 // If old_layer was the layer tree root then we need to move the Compositor
66 // over to the new root. 49 // over to the new root.
67 old_layer->GetCompositor()->SetRootLayer(new_layer); 50 old_layer->GetCompositor()->SetRootLayer(layer_);
68 } 51 }
69 52
70 // Migrate all the child layers over to the new layer. Copy the list because 53 // Migrate all the child layers over to the new layer. Copy the list because
71 // the items are removed during iteration. 54 // the items are removed during iteration.
72 std::vector<ui::Layer*> children_copy = old_layer->children(); 55 std::vector<ui::Layer*> children_copy = old_layer->children();
73 for (std::vector<ui::Layer*>::const_iterator it = children_copy.begin(); 56 for (std::vector<ui::Layer*>::const_iterator it = children_copy.begin();
74 it != children_copy.end(); 57 it != children_copy.end();
75 ++it) { 58 ++it) {
76 ui::Layer* child = *it; 59 ui::Layer* child = *it;
77 new_layer->Add(child); 60 layer_->Add(child);
78 } 61 }
79 62
80 // Install the delegate last so that the delegate isn't notified as we copy 63 // Install the delegate last so that the delegate isn't notified as we copy
81 // state to the new layer. 64 // state to the new layer.
82 new_layer->set_delegate(old_delegate); 65 layer_->set_delegate(old_delegate);
83 66
84 if (layer_owner_delegate_) 67 if (layer_owner_delegate_)
85 layer_owner_delegate_->OnLayerRecreated(old_layer.get(), new_layer); 68 layer_owner_delegate_->OnLayerRecreated(old_layer.get(), layer_);
86 69
87 return old_layer; 70 return old_layer;
88 } 71 }
89 72
90 void LayerOwner::DestroyLayer() { 73 void LayerOwner::DestroyLayer() {
91 layer_ = NULL; 74 layer_ = NULL;
92 layer_owner_.reset(); 75 layer_owner_.reset();
93 } 76 }
94 77
95 bool LayerOwner::OwnsLayer() const { 78 bool LayerOwner::OwnsLayer() const {
96 return !!layer_owner_; 79 return !!layer_owner_;
97 } 80 }
98 81
99 } // namespace ui 82 } // namespace ui
OLDNEW
« no previous file with comments | « ui/compositor/layer_owner.h ('k') | ui/compositor/layer_owner_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698