| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "cc/layers/layer_list_iterator.h" | 5 #include "cc/layers/layer_list_iterator.h" |
| 6 | 6 |
| 7 #include "cc/layers/layer_impl.h" | 7 #include "cc/layers/layer_impl.h" |
| 8 | 8 |
| 9 namespace cc { | 9 namespace cc { |
| 10 | 10 |
| 11 LayerListIterator::LayerListIterator(LayerImpl* root_layer) | 11 LayerListIterator::LayerListIterator(LayerImpl* root_layer) |
| 12 : current_layer_(root_layer) { | 12 : current_layer_(root_layer) { |
| 13 DCHECK(!root_layer || !root_layer->parent()); | 13 DCHECK(!root_layer || !root_layer->parent()); |
| 14 list_indices_.push_back(0); | 14 list_indices_.push_back(0); |
| 15 } | 15 } |
| 16 | 16 |
| 17 LayerListIterator::~LayerListIterator() {} | 17 LayerListIterator::~LayerListIterator() {} |
| 18 | 18 |
| 19 LayerListIterator& LayerListIterator::operator++() { | 19 LayerListIterator& LayerListIterator::operator++() { |
| 20 // case 0: done | 20 // case 0: done |
| 21 if (!current_layer_) | 21 if (!current_layer_) |
| 22 return *this; | 22 return *this; |
| 23 | 23 |
| 24 // case 1: descend. | 24 // case 1: descend. |
| 25 const OwnedLayerImplList& current_list = current_layer_->children(); | 25 const LayerImplList& current_list = current_layer_->children(); |
| 26 if (!current_list.empty()) { | 26 if (!current_list.empty()) { |
| 27 current_layer_ = current_list[0].get(); | 27 current_layer_ = current_list[0]; |
| 28 list_indices_.push_back(0); | 28 list_indices_.push_back(0); |
| 29 return *this; | 29 return *this; |
| 30 } | 30 } |
| 31 | 31 |
| 32 for (LayerImpl* parent = current_layer_->parent(); parent; | 32 for (LayerImpl* parent = current_layer_->parent(); parent; |
| 33 parent = parent->parent()) { | 33 parent = parent->parent()) { |
| 34 // We now try and advance in some list of siblings. | 34 // We now try and advance in some list of siblings. |
| 35 const OwnedLayerImplList& sibling_list = parent->children(); | 35 const LayerImplList& sibling_list = parent->children(); |
| 36 | 36 |
| 37 // case 2: Advance to a sibling. | 37 // case 2: Advance to a sibling. |
| 38 if (list_indices_.back() + 1 < sibling_list.size()) { | 38 if (list_indices_.back() + 1 < sibling_list.size()) { |
| 39 ++list_indices_.back(); | 39 ++list_indices_.back(); |
| 40 current_layer_ = sibling_list[list_indices_.back()].get(); | 40 current_layer_ = sibling_list[list_indices_.back()]; |
| 41 return *this; | 41 return *this; |
| 42 } | 42 } |
| 43 | 43 |
| 44 // We need to ascend. We will pop an index off the stack. | 44 // We need to ascend. We will pop an index off the stack. |
| 45 list_indices_.pop_back(); | 45 list_indices_.pop_back(); |
| 46 } | 46 } |
| 47 | 47 |
| 48 current_layer_ = nullptr; | 48 current_layer_ = nullptr; |
| 49 return *this; | 49 return *this; |
| 50 } | 50 } |
| (...skipping 15 matching lines...) Expand all Loading... |
| 66 if (!list_indices_.back()) { | 66 if (!list_indices_.back()) { |
| 67 list_indices_.pop_back(); | 67 list_indices_.pop_back(); |
| 68 current_layer_ = current_layer_->parent(); | 68 current_layer_ = current_layer_->parent(); |
| 69 return *this; | 69 return *this; |
| 70 } | 70 } |
| 71 | 71 |
| 72 // case 2: we're not the leftmost sibling. In this case, we want to move one | 72 // case 2: we're not the leftmost sibling. In this case, we want to move one |
| 73 // sibling over, and then descend to the rightmost descendant in that subtree. | 73 // sibling over, and then descend to the rightmost descendant in that subtree. |
| 74 CHECK(current_layer_->parent()); | 74 CHECK(current_layer_->parent()); |
| 75 --list_indices_.back(); | 75 --list_indices_.back(); |
| 76 const OwnedLayerImplList& parent_list = current_layer_->parent()->children(); | 76 const LayerImplList& parent_list = current_layer_->parent()->children(); |
| 77 current_layer_ = parent_list[list_indices_.back()].get(); | 77 current_layer_ = parent_list[list_indices_.back()]; |
| 78 DescendToRightmostInSubtree(); | 78 DescendToRightmostInSubtree(); |
| 79 return *this; | 79 return *this; |
| 80 } | 80 } |
| 81 | 81 |
| 82 void LayerListReverseIterator::DescendToRightmostInSubtree() { | 82 void LayerListReverseIterator::DescendToRightmostInSubtree() { |
| 83 if (!current_layer_) | 83 if (!current_layer_) |
| 84 return; | 84 return; |
| 85 | 85 |
| 86 const OwnedLayerImplList& current_list = current_layer_->children(); | 86 const LayerImplList& current_list = current_layer_->children(); |
| 87 if (current_list.empty()) | 87 if (current_list.empty()) |
| 88 return; | 88 return; |
| 89 | 89 |
| 90 size_t last_index = current_list.size() - 1; | 90 size_t last_index = current_list.size() - 1; |
| 91 current_layer_ = current_list[last_index].get(); | 91 current_layer_ = current_list[last_index]; |
| 92 list_indices_.push_back(last_index); | 92 list_indices_.push_back(last_index); |
| 93 DescendToRightmostInSubtree(); | 93 DescendToRightmostInSubtree(); |
| 94 } | 94 } |
| 95 | 95 |
| 96 } // namespace cc | 96 } // namespace cc |
| OLD | NEW |