OLD | NEW |
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 "ui/compositor/layer_owner_delegate.h" | 10 #include "ui/compositor/layer_owner_delegate.h" |
10 | 11 |
11 namespace ui { | 12 namespace ui { |
12 | 13 |
13 LayerOwner::LayerOwner() : layer_(NULL), layer_owner_delegate_(NULL) { | 14 LayerOwner::LayerOwner() : layer_(NULL), layer_owner_delegate_(NULL) { |
14 } | 15 } |
15 | 16 |
16 LayerOwner::~LayerOwner() { | 17 LayerOwner::~LayerOwner() { |
17 } | 18 } |
18 | 19 |
19 void LayerOwner::SetLayer(Layer* layer) { | 20 void LayerOwner::SetLayer(Layer* layer) { |
20 DCHECK(!OwnsLayer()); | 21 DCHECK(!OwnsLayer()); |
21 layer_owner_.reset(layer); | 22 layer_owner_.reset(layer); |
22 layer_ = layer; | 23 layer_ = layer; |
23 layer_->owner_ = this; | 24 layer_->owner_ = this; |
24 } | 25 } |
25 | 26 |
26 scoped_ptr<Layer> LayerOwner::AcquireLayer() { | 27 std::unique_ptr<Layer> LayerOwner::AcquireLayer() { |
27 if (layer_owner_) | 28 if (layer_owner_) |
28 layer_owner_->owner_ = NULL; | 29 layer_owner_->owner_ = NULL; |
29 return std::move(layer_owner_); | 30 return std::move(layer_owner_); |
30 } | 31 } |
31 | 32 |
32 scoped_ptr<Layer> LayerOwner::RecreateLayer() { | 33 std::unique_ptr<Layer> LayerOwner::RecreateLayer() { |
33 scoped_ptr<ui::Layer> old_layer(AcquireLayer()); | 34 std::unique_ptr<ui::Layer> old_layer(AcquireLayer()); |
34 if (!old_layer) | 35 if (!old_layer) |
35 return old_layer; | 36 return old_layer; |
36 | 37 |
37 LayerDelegate* old_delegate = old_layer->delegate(); | 38 LayerDelegate* old_delegate = old_layer->delegate(); |
38 old_layer->set_delegate(NULL); | 39 old_layer->set_delegate(NULL); |
39 | 40 |
40 const gfx::Rect layer_bounds(old_layer->bounds()); | 41 const gfx::Rect layer_bounds(old_layer->bounds()); |
41 Layer* new_layer = new ui::Layer(old_layer->type()); | 42 Layer* new_layer = new ui::Layer(old_layer->type()); |
42 SetLayer(new_layer); | 43 SetLayer(new_layer); |
43 new_layer->SetVisible(old_layer->GetTargetVisibility()); | 44 new_layer->SetVisible(old_layer->GetTargetVisibility()); |
44 new_layer->SetOpacity(old_layer->GetTargetOpacity()); | 45 new_layer->SetOpacity(old_layer->GetTargetOpacity()); |
45 new_layer->SetBounds(layer_bounds); | 46 new_layer->SetBounds(layer_bounds); |
46 new_layer->SetMasksToBounds(old_layer->GetMasksToBounds()); | 47 new_layer->SetMasksToBounds(old_layer->GetMasksToBounds()); |
47 new_layer->set_name(old_layer->name()); | 48 new_layer->set_name(old_layer->name()); |
48 new_layer->SetFillsBoundsOpaquely(old_layer->fills_bounds_opaquely()); | 49 new_layer->SetFillsBoundsOpaquely(old_layer->fills_bounds_opaquely()); |
49 new_layer->SetFillsBoundsCompletely(old_layer->FillsBoundsCompletely()); | 50 new_layer->SetFillsBoundsCompletely(old_layer->FillsBoundsCompletely()); |
50 new_layer->SetSubpixelPositionOffset(old_layer->subpixel_position_offset()); | 51 new_layer->SetSubpixelPositionOffset(old_layer->subpixel_position_offset()); |
51 new_layer->SetLayerInverted(old_layer->layer_inverted()); | 52 new_layer->SetLayerInverted(old_layer->layer_inverted()); |
52 new_layer->SetTransform(old_layer->GetTargetTransform()); | 53 new_layer->SetTransform(old_layer->GetTargetTransform()); |
53 if (old_layer->type() == LAYER_SOLID_COLOR) | 54 if (old_layer->type() == LAYER_SOLID_COLOR) |
54 new_layer->SetColor(old_layer->GetTargetColor()); | 55 new_layer->SetColor(old_layer->GetTargetColor()); |
55 SkRegion* alpha_shape = old_layer->alpha_shape(); | 56 SkRegion* alpha_shape = old_layer->alpha_shape(); |
56 if (alpha_shape) | 57 if (alpha_shape) |
57 new_layer->SetAlphaShape(make_scoped_ptr(new SkRegion(*alpha_shape))); | 58 new_layer->SetAlphaShape(base::WrapUnique(new SkRegion(*alpha_shape))); |
58 | 59 |
59 if (old_layer->parent()) { | 60 if (old_layer->parent()) { |
60 // 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. |
61 old_layer->parent()->Add(new_layer); | 62 old_layer->parent()->Add(new_layer); |
62 old_layer->parent()->StackBelow(new_layer, old_layer.get()); | 63 old_layer->parent()->StackBelow(new_layer, old_layer.get()); |
63 } else if (old_layer->GetCompositor()) { | 64 } else if (old_layer->GetCompositor()) { |
64 // 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 |
65 // over to the new root. | 66 // over to the new root. |
66 old_layer->GetCompositor()->SetRootLayer(new_layer); | 67 old_layer->GetCompositor()->SetRootLayer(new_layer); |
67 } | 68 } |
(...skipping 21 matching lines...) Expand all Loading... |
89 void LayerOwner::DestroyLayer() { | 90 void LayerOwner::DestroyLayer() { |
90 layer_ = NULL; | 91 layer_ = NULL; |
91 layer_owner_.reset(); | 92 layer_owner_.reset(); |
92 } | 93 } |
93 | 94 |
94 bool LayerOwner::OwnsLayer() const { | 95 bool LayerOwner::OwnsLayer() const { |
95 return !!layer_owner_; | 96 return !!layer_owner_; |
96 } | 97 } |
97 | 98 |
98 } // namespace ui | 99 } // namespace ui |
OLD | NEW |