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

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

Issue 2458833003: Revert of [M55] Generalize layer mirroring for phantom windows (Closed)
Patch Set: 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(std::unique_ptr<Layer> layer) { 20 void LayerOwner::SetLayer(Layer* layer) {
21 DCHECK(!OwnsLayer()); 21 DCHECK(!OwnsLayer());
22 layer_owner_ = std::move(layer); 22 layer_owner_.reset(layer);
23 layer_ = layer_owner_.get(); 23 layer_ = layer;
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 SetLayer(old_layer->Clone()); 41 const gfx::Rect layer_bounds(old_layer->bounds());
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));
42 59
43 if (old_layer->parent()) { 60 if (old_layer->parent()) {
44 // Install new layer as a sibling of the old layer, stacked below it. 61 // Install new layer as a sibling of the old layer, stacked below it.
45 old_layer->parent()->Add(layer_); 62 old_layer->parent()->Add(new_layer);
46 old_layer->parent()->StackBelow(layer_, old_layer.get()); 63 old_layer->parent()->StackBelow(new_layer, old_layer.get());
47 } else if (old_layer->GetCompositor()) { 64 } else if (old_layer->GetCompositor()) {
48 // If old_layer was the layer tree root then we need to move the Compositor 65 // If old_layer was the layer tree root then we need to move the Compositor
49 // over to the new root. 66 // over to the new root.
50 old_layer->GetCompositor()->SetRootLayer(layer_); 67 old_layer->GetCompositor()->SetRootLayer(new_layer);
51 } 68 }
52 69
53 // Migrate all the child layers over to the new layer. Copy the list because 70 // Migrate all the child layers over to the new layer. Copy the list because
54 // the items are removed during iteration. 71 // the items are removed during iteration.
55 std::vector<ui::Layer*> children_copy = old_layer->children(); 72 std::vector<ui::Layer*> children_copy = old_layer->children();
56 for (std::vector<ui::Layer*>::const_iterator it = children_copy.begin(); 73 for (std::vector<ui::Layer*>::const_iterator it = children_copy.begin();
57 it != children_copy.end(); 74 it != children_copy.end();
58 ++it) { 75 ++it) {
59 ui::Layer* child = *it; 76 ui::Layer* child = *it;
60 layer_->Add(child); 77 new_layer->Add(child);
61 } 78 }
62 79
63 // Install the delegate last so that the delegate isn't notified as we copy 80 // Install the delegate last so that the delegate isn't notified as we copy
64 // state to the new layer. 81 // state to the new layer.
65 layer_->set_delegate(old_delegate); 82 new_layer->set_delegate(old_delegate);
66 83
67 if (layer_owner_delegate_) 84 if (layer_owner_delegate_)
68 layer_owner_delegate_->OnLayerRecreated(old_layer.get(), layer_); 85 layer_owner_delegate_->OnLayerRecreated(old_layer.get(), new_layer);
69 86
70 return old_layer; 87 return old_layer;
71 } 88 }
72 89
73 void LayerOwner::DestroyLayer() { 90 void LayerOwner::DestroyLayer() {
74 layer_ = NULL; 91 layer_ = NULL;
75 layer_owner_.reset(); 92 layer_owner_.reset();
76 } 93 }
77 94
78 bool LayerOwner::OwnsLayer() const { 95 bool LayerOwner::OwnsLayer() const {
79 return !!layer_owner_; 96 return !!layer_owner_;
80 } 97 }
81 98
82 } // namespace ui 99 } // 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