| 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 "ui/compositor/layer_owner_delegate.h" | 7 #include "ui/compositor/layer_owner_delegate.h" |
| 8 | 8 |
| 9 namespace ui { | 9 namespace ui { |
| 10 | 10 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 new_layer->set_name(old_layer->name()); | 45 new_layer->set_name(old_layer->name()); |
| 46 new_layer->SetFillsBoundsOpaquely(old_layer->fills_bounds_opaquely()); | 46 new_layer->SetFillsBoundsOpaquely(old_layer->fills_bounds_opaquely()); |
| 47 new_layer->SetFillsBoundsCompletely(old_layer->FillsBoundsCompletely()); | 47 new_layer->SetFillsBoundsCompletely(old_layer->FillsBoundsCompletely()); |
| 48 new_layer->SetSubpixelPositionOffset(old_layer->subpixel_position_offset()); | 48 new_layer->SetSubpixelPositionOffset(old_layer->subpixel_position_offset()); |
| 49 if (old_layer->type() == LAYER_SOLID_COLOR) | 49 if (old_layer->type() == LAYER_SOLID_COLOR) |
| 50 new_layer->SetColor(old_layer->GetTargetColor()); | 50 new_layer->SetColor(old_layer->GetTargetColor()); |
| 51 SkRegion* alpha_shape = old_layer->alpha_shape(); | 51 SkRegion* alpha_shape = old_layer->alpha_shape(); |
| 52 if (alpha_shape) | 52 if (alpha_shape) |
| 53 new_layer->SetAlphaShape(make_scoped_ptr(new SkRegion(*alpha_shape))); | 53 new_layer->SetAlphaShape(make_scoped_ptr(new SkRegion(*alpha_shape))); |
| 54 | 54 |
| 55 // Install new layer as a sibling of the old layer, stacked below it. | |
| 56 if (old_layer->parent()) { | 55 if (old_layer->parent()) { |
| 56 // Install new layer as a sibling of the old layer, stacked below it. |
| 57 old_layer->parent()->Add(new_layer); | 57 old_layer->parent()->Add(new_layer); |
| 58 old_layer->parent()->StackBelow(new_layer, old_layer.get()); | 58 old_layer->parent()->StackBelow(new_layer, old_layer.get()); |
| 59 } else if (old_layer->GetCompositor()) { |
| 60 // If old_layer was the layer tree root then we need to move the Compositor |
| 61 // over to the new root. |
| 62 old_layer->GetCompositor()->SetRootLayer(new_layer); |
| 59 } | 63 } |
| 60 | 64 |
| 61 // Migrate all the child layers over to the new layer. Copy the list because | 65 // Migrate all the child layers over to the new layer. Copy the list because |
| 62 // the items are removed during iteration. | 66 // the items are removed during iteration. |
| 63 std::vector<ui::Layer*> children_copy = old_layer->children(); | 67 std::vector<ui::Layer*> children_copy = old_layer->children(); |
| 64 for (std::vector<ui::Layer*>::const_iterator it = children_copy.begin(); | 68 for (std::vector<ui::Layer*>::const_iterator it = children_copy.begin(); |
| 65 it != children_copy.end(); | 69 it != children_copy.end(); |
| 66 ++it) { | 70 ++it) { |
| 67 ui::Layer* child = *it; | 71 ui::Layer* child = *it; |
| 68 new_layer->Add(child); | 72 new_layer->Add(child); |
| 69 } | 73 } |
| 70 | 74 |
| 71 // If old_layer was the layer tree root then we need to move the Compositor | |
| 72 // over to the new root. | |
| 73 const bool is_root = !old_layer->parent(); | |
| 74 if (is_root && old_layer->GetCompositor()) | |
| 75 old_layer->GetCompositor()->SetRootLayer(new_layer); | |
| 76 | |
| 77 // Install the delegate last so that the delegate isn't notified as we copy | 75 // Install the delegate last so that the delegate isn't notified as we copy |
| 78 // state to the new layer. | 76 // state to the new layer. |
| 79 new_layer->set_delegate(old_delegate); | 77 new_layer->set_delegate(old_delegate); |
| 80 | 78 |
| 81 if (layer_owner_delegate_) | 79 if (layer_owner_delegate_) |
| 82 layer_owner_delegate_->OnLayerRecreated(old_layer.get(), new_layer); | 80 layer_owner_delegate_->OnLayerRecreated(old_layer.get(), new_layer); |
| 83 | 81 |
| 84 return old_layer.Pass(); | 82 return old_layer.Pass(); |
| 85 } | 83 } |
| 86 | 84 |
| 87 void LayerOwner::DestroyLayer() { | 85 void LayerOwner::DestroyLayer() { |
| 88 layer_ = NULL; | 86 layer_ = NULL; |
| 89 layer_owner_.reset(); | 87 layer_owner_.reset(); |
| 90 } | 88 } |
| 91 | 89 |
| 92 bool LayerOwner::OwnsLayer() const { | 90 bool LayerOwner::OwnsLayer() const { |
| 93 return !!layer_owner_; | 91 return !!layer_owner_; |
| 94 } | 92 } |
| 95 | 93 |
| 96 } // namespace ui | 94 } // namespace ui |
| OLD | NEW |