Chromium Code Reviews| Index: cc/trees/layer_tree_impl.cc |
| diff --git a/cc/trees/layer_tree_impl.cc b/cc/trees/layer_tree_impl.cc |
| index 074ab1daddf05c99a4a212fc903235839f770066..64e453a8b152bc2f22d35efd7d90c54d6c62ff62 100644 |
| --- a/cc/trees/layer_tree_impl.cc |
| +++ b/cc/trees/layer_tree_impl.cc |
| @@ -57,7 +57,8 @@ LayerTreeImpl::LayerTreeImpl( |
| : layer_tree_host_impl_(layer_tree_host_impl), |
| source_frame_number_(-1), |
| is_first_frame_after_commit_tracker_(-1), |
| - hud_layer_(0), |
| + root_layer_(nullptr), |
| + hud_layer_(nullptr), |
| background_color_(0), |
| has_transparent_background_(false), |
| last_scrolled_layer_id_(Layer::INVALID_ID), |
| @@ -71,6 +72,7 @@ LayerTreeImpl::LayerTreeImpl( |
| device_scale_factor_(1.f), |
| painted_device_scale_factor_(1.f), |
| elastic_overscroll_(elastic_overscroll), |
| + layers_(new OwnedLayerImplList), |
| viewport_size_invalid_(false), |
| needs_update_draw_properties_(true), |
| needs_full_tree_sync_(true), |
| @@ -96,21 +98,22 @@ LayerTreeImpl::~LayerTreeImpl() { |
| } |
| void LayerTreeImpl::Shutdown() { |
| + if (root_layer_) |
| + RemoveLayer(root_layer_->id()); |
| root_layer_ = nullptr; |
| } |
| void LayerTreeImpl::ReleaseResources() { |
| if (root_layer_) { |
| LayerTreeHostCommon::CallFunctionForSubtree( |
| - root_layer_.get(), [](LayerImpl* layer) { layer->ReleaseResources(); }); |
| + root_layer_, [](LayerImpl* layer) { layer->ReleaseResources(); }); |
| } |
| } |
| void LayerTreeImpl::RecreateResources() { |
| if (root_layer_) { |
| LayerTreeHostCommon::CallFunctionForSubtree( |
| - root_layer_.get(), |
| - [](LayerImpl* layer) { layer->RecreateResources(); }); |
| + root_layer_, [](LayerImpl* layer) { layer->RecreateResources(); }); |
| } |
| } |
| @@ -123,7 +126,7 @@ void LayerTreeImpl::GatherFrameTimingRequestIds( |
| // that, we need to inform LayerTreeImpl whenever there are requests when we |
| // get them. |
| LayerTreeHostCommon::CallFunctionForSubtree( |
| - root_layer_.get(), [request_ids](LayerImpl* layer) { |
| + root_layer_, [request_ids](LayerImpl* layer) { |
| layer->GatherFrameTimingRequestIds(request_ids); |
| }); |
| } |
| @@ -269,8 +272,11 @@ void LayerTreeImpl::UpdateScrollbars(int scroll_layer_id, int clip_layer_id) { |
| } |
| void LayerTreeImpl::SetRootLayer(scoped_ptr<LayerImpl> layer) { |
| - root_layer_ = std::move(layer); |
| - |
| + if (root_layer_ && layer.get() != root_layer_) |
| + RemoveLayer(root_layer_->id()); |
| + root_layer_ = layer.get(); |
| + if (layer) |
| + AddLayer(std::move(layer)); |
| layer_tree_host_impl_->OnCanDrawStateChangedForTree(); |
| } |
| @@ -306,10 +312,17 @@ gfx::ScrollOffset LayerTreeImpl::TotalMaxScrollOffset() const { |
| return offset; |
| } |
| -scoped_ptr<LayerImpl> LayerTreeImpl::DetachLayerTree() { |
| +scoped_ptr<OwnedLayerImplList> LayerTreeImpl::DetachLayers() { |
| render_surface_layer_list_.clear(); |
| set_needs_update_draw_properties(); |
| - return std::move(root_layer_); |
| + scoped_ptr<OwnedLayerImplList> ret = std::move(layers_); |
| + layers_.reset(new OwnedLayerImplList); |
| + return ret; |
| +} |
| + |
| +void LayerTreeImpl::ClearLayers() { |
| + SetRootLayer(nullptr); |
| + DCHECK(layers_->empty()); |
| } |
| static void UpdateClipTreeForBoundsDeltaOnLayer(LayerImpl* layer, |
| @@ -418,7 +431,7 @@ void LayerTreeImpl::PushPropertiesTo(LayerTreeImpl* target_tree) { |
| } |
| LayerListIterator LayerTreeImpl::begin() { |
| - return LayerListIterator(root_layer_.get()); |
| + return LayerListIterator(root_layer_); |
| } |
| LayerListIterator LayerTreeImpl::end() { |
| @@ -426,7 +439,7 @@ LayerListIterator LayerTreeImpl::end() { |
| } |
| LayerListReverseIterator LayerTreeImpl::rbegin() { |
| - return LayerListReverseIterator(root_layer_.get()); |
| + return LayerListReverseIterator(root_layer_); |
| } |
| LayerListReverseIterator LayerTreeImpl::rend() { |
| @@ -711,7 +724,7 @@ gfx::Rect LayerTreeImpl::RootScrollLayerDeviceViewportBounds() const { |
| : InnerViewportScrollLayer(); |
| if (!root_scroll_layer || root_scroll_layer->children().empty()) |
| return gfx::Rect(); |
| - LayerImpl* layer = root_scroll_layer->children()[0].get(); |
| + LayerImpl* layer = root_scroll_layer->children()[0]; |
| return MathUtil::MapEnclosingClippedRect(layer->ScreenSpaceTransform(), |
| gfx::Rect(layer->bounds())); |
| } |
| @@ -946,10 +959,10 @@ bool LayerTreeImpl::UpdateDrawProperties(bool update_lcd_text) { |
| } |
| void LayerTreeImpl::BuildPropertyTreesForTesting() { |
| - LayerTreeHostCommon::PreCalculateMetaInformationForTesting(root_layer_.get()); |
| + LayerTreeHostCommon::PreCalculateMetaInformationForTesting(root_layer_); |
| property_trees_.transform_tree.set_source_to_parent_updates_allowed(true); |
| PropertyTreeBuilder::BuildPropertyTrees( |
| - root_layer_.get(), PageScaleLayer(), InnerViewportScrollLayer(), |
| + root_layer_, PageScaleLayer(), InnerViewportScrollLayer(), |
| OuterViewportScrollLayer(), OverscrollElasticityLayer(), |
| elastic_overscroll()->Current(IsActiveTree()), |
| current_page_scale_factor(), device_scale_factor(), |
| @@ -992,7 +1005,7 @@ gfx::SizeF LayerTreeImpl::ScrollableSize() const { |
| } |
| LayerImpl* LayerTreeImpl::LayerById(int id) const { |
| - LayerIdMap::const_iterator iter = layer_id_map_.find(id); |
| + LayerImplMap::const_iterator iter = layer_id_map_.find(id); |
| return iter != layer_id_map_.end() ? iter->second : NULL; |
| } |
| @@ -1027,9 +1040,30 @@ void LayerTreeImpl::UnregisterLayer(LayerImpl* layer) { |
| layer_tree_host_impl_->animation_host()->UnregisterLayer( |
| layer->id(), |
| IsActiveTree() ? LayerTreeType::ACTIVE : LayerTreeType::PENDING); |
| + if (layer == root_layer_) |
| + root_layer_ = nullptr; |
|
ajuma
2016/03/18 22:09:21
When does the root layer need to get cleared this
Ian Vollick
2016/03/19 03:05:22
Turns out never. Removed.
|
| layer_id_map_.erase(layer->id()); |
| } |
| +// These manage ownership of the LayerImpl. |
| +void LayerTreeImpl::AddLayer(scoped_ptr<LayerImpl> layer) { |
| + DCHECK(std::find(layers_->begin(), layers_->end(), layer) == layers_->end()); |
| + layers_->push_back(std::move(layer)); |
| + set_needs_update_draw_properties(); |
| +} |
| + |
| +scoped_ptr<LayerImpl> LayerTreeImpl::RemoveLayer(int id) { |
| + for (auto it = layers_->begin(); it != layers_->end(); ++it) { |
| + if ((*it) && (*it)->id() != id) |
| + continue; |
| + scoped_ptr<LayerImpl> ret = std::move(*it); |
| + set_needs_update_draw_properties(); |
| + layers_->erase(it); |
| + return ret; |
| + } |
| + return nullptr; |
| +} |
| + |
| size_t LayerTreeImpl::NumLayers() { |
| return layer_id_map_.size(); |
| } |