OLD | NEW |
(Empty) | |
| 1 // Copyright 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "cc/layer_tree_impl.h" |
| 6 |
| 7 #include "cc/layer_tree_host_common.h" |
| 8 #include "cc/layer_tree_host_impl.h" |
| 9 |
| 10 namespace cc { |
| 11 |
| 12 LayerTreeImpl::LayerTreeImpl(LayerTreeImplClient* client) |
| 13 : client_(client) |
| 14 , source_frame_number_(-1) |
| 15 , hud_layer_(0) |
| 16 , root_scroll_layer_(0) |
| 17 , currently_scrolling_layer_(0) |
| 18 , scrolling_layer_id_from_previous_tree_(0) { |
| 19 } |
| 20 |
| 21 LayerTreeImpl::~LayerTreeImpl() { |
| 22 } |
| 23 |
| 24 static LayerImpl* findRootScrollLayer(LayerImpl* layer) |
| 25 { |
| 26 if (!layer) |
| 27 return 0; |
| 28 |
| 29 if (layer->scrollable()) |
| 30 return layer; |
| 31 |
| 32 for (size_t i = 0; i < layer->children().size(); ++i) { |
| 33 LayerImpl* found = findRootScrollLayer(layer->children()[i]); |
| 34 if (found) |
| 35 return found; |
| 36 } |
| 37 |
| 38 return 0; |
| 39 } |
| 40 |
| 41 void LayerTreeImpl::SetRootLayer(scoped_ptr<LayerImpl> layer) { |
| 42 root_layer_ = layer.Pass(); |
| 43 root_scroll_layer_ = findRootScrollLayer(root_layer_.get()); |
| 44 currently_scrolling_layer_ = 0; |
| 45 |
| 46 if (root_layer_ && scrolling_layer_id_from_previous_tree_) { |
| 47 currently_scrolling_layer_ = LayerTreeHostCommon::findLayerInSubtree( |
| 48 root_layer_.get(), |
| 49 scrolling_layer_id_from_previous_tree_); |
| 50 } |
| 51 |
| 52 scrolling_layer_id_from_previous_tree_ = 0; |
| 53 |
| 54 client_->OnCanDrawStateChangedForTree(this); |
| 55 } |
| 56 |
| 57 scoped_ptr<LayerImpl> LayerTreeImpl::DetachLayerTree() { |
| 58 // Clear all data structures that have direct references to the layer tree. |
| 59 scrolling_layer_id_from_previous_tree_ = |
| 60 currently_scrolling_layer_ ? currently_scrolling_layer_->id() : 0; |
| 61 currently_scrolling_layer_ = NULL; |
| 62 |
| 63 return root_layer_.Pass(); |
| 64 } |
| 65 |
| 66 void LayerTreeImpl::ClearCurrentlyScrollingLayer() { |
| 67 currently_scrolling_layer_ = NULL; |
| 68 scrolling_layer_id_from_previous_tree_ = 0; |
| 69 } |
| 70 |
| 71 } // namespace cc |
OLD | NEW |