| 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.h" | 7 #include "cc/layers/layer.h" |
| 8 #include "cc/layers/layer_impl.h" | 8 #include "cc/layers/layer_impl.h" |
| 9 | 9 |
| 10 namespace cc { | 10 namespace cc { |
| 11 | 11 |
| 12 static Layer* Parent(Layer* layer) { |
| 13 return layer->parent(); |
| 14 } |
| 15 |
| 16 static LayerImpl* Parent(LayerImpl* layer) { |
| 17 return layer->test_properties()->parent; |
| 18 } |
| 12 template <typename LayerType> | 19 template <typename LayerType> |
| 13 LayerListIterator<LayerType>::LayerListIterator(LayerType* root_layer) | 20 LayerListIterator<LayerType>::LayerListIterator(LayerType* root_layer) |
| 14 : current_layer_(root_layer) { | 21 : current_layer_(root_layer) { |
| 15 DCHECK(!root_layer || !root_layer->parent()); | 22 DCHECK(!root_layer || !Parent(root_layer)); |
| 16 list_indices_.push_back(0); | 23 list_indices_.push_back(0); |
| 17 } | 24 } |
| 18 | 25 |
| 19 static LayerImplList& Children(LayerImpl* layer) { | 26 static LayerImplList& Children(LayerImpl* layer) { |
| 20 return layer->test_properties()->children; | 27 return layer->test_properties()->children; |
| 21 } | 28 } |
| 22 | 29 |
| 23 static const LayerList& Children(Layer* layer) { | 30 static const LayerList& Children(Layer* layer) { |
| 24 return layer->children(); | 31 return layer->children(); |
| 25 } | 32 } |
| (...skipping 19 matching lines...) Expand all Loading... |
| 45 if (!current_layer_) | 52 if (!current_layer_) |
| 46 return *this; | 53 return *this; |
| 47 | 54 |
| 48 // case 1: descend. | 55 // case 1: descend. |
| 49 if (!Children(current_layer_).empty()) { | 56 if (!Children(current_layer_).empty()) { |
| 50 current_layer_ = ChildAt(current_layer_, 0); | 57 current_layer_ = ChildAt(current_layer_, 0); |
| 51 list_indices_.push_back(0); | 58 list_indices_.push_back(0); |
| 52 return *this; | 59 return *this; |
| 53 } | 60 } |
| 54 | 61 |
| 55 for (LayerType* parent = current_layer_->parent(); parent; | 62 for (LayerType* parent = Parent(current_layer_); parent; |
| 56 parent = parent->parent()) { | 63 parent = Parent(parent)) { |
| 57 // We now try and advance in some list of siblings. | 64 // We now try and advance in some list of siblings. |
| 58 // case 2: Advance to a sibling. | 65 // case 2: Advance to a sibling. |
| 59 if (list_indices_.back() + 1 < Children(parent).size()) { | 66 if (list_indices_.back() + 1 < Children(parent).size()) { |
| 60 ++list_indices_.back(); | 67 ++list_indices_.back(); |
| 61 current_layer_ = ChildAt(parent, list_indices_.back()); | 68 current_layer_ = ChildAt(parent, list_indices_.back()); |
| 62 return *this; | 69 return *this; |
| 63 } | 70 } |
| 64 | 71 |
| 65 // We need to ascend. We will pop an index off the stack. | 72 // We need to ascend. We will pop an index off the stack. |
| 66 list_indices_.pop_back(); | 73 list_indices_.pop_back(); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 84 template <typename LayerType> | 91 template <typename LayerType> |
| 85 LayerListIterator<LayerType>& LayerListReverseIterator<LayerType>:: | 92 LayerListIterator<LayerType>& LayerListReverseIterator<LayerType>:: |
| 86 operator++() { | 93 operator++() { |
| 87 // case 0: done | 94 // case 0: done |
| 88 if (!current_layer()) | 95 if (!current_layer()) |
| 89 return *this; | 96 return *this; |
| 90 | 97 |
| 91 // case 1: we're the leftmost sibling. | 98 // case 1: we're the leftmost sibling. |
| 92 if (!list_indices().back()) { | 99 if (!list_indices().back()) { |
| 93 list_indices().pop_back(); | 100 list_indices().pop_back(); |
| 94 this->current_layer_ = current_layer()->parent(); | 101 this->current_layer_ = Parent(current_layer()); |
| 95 return *this; | 102 return *this; |
| 96 } | 103 } |
| 97 | 104 |
| 98 // case 2: we're not the leftmost sibling. In this case, we want to move one | 105 // case 2: we're not the leftmost sibling. In this case, we want to move one |
| 99 // sibling over, and then descend to the rightmost descendant in that subtree. | 106 // sibling over, and then descend to the rightmost descendant in that subtree. |
| 100 CHECK(current_layer()->parent()); | 107 CHECK(Parent(current_layer())); |
| 101 --list_indices().back(); | 108 --list_indices().back(); |
| 102 this->current_layer_ = | 109 this->current_layer_ = |
| 103 ChildAt(current_layer()->parent(), list_indices().back()); | 110 ChildAt(Parent(current_layer()), list_indices().back()); |
| 104 DescendToRightmostInSubtree(); | 111 DescendToRightmostInSubtree(); |
| 105 return *this; | 112 return *this; |
| 106 } | 113 } |
| 107 | 114 |
| 108 template <typename LayerType> | 115 template <typename LayerType> |
| 109 void LayerListReverseIterator<LayerType>::DescendToRightmostInSubtree() { | 116 void LayerListReverseIterator<LayerType>::DescendToRightmostInSubtree() { |
| 110 if (!current_layer()) | 117 if (!current_layer()) |
| 111 return; | 118 return; |
| 112 | 119 |
| 113 if (Children(current_layer()).empty()) | 120 if (Children(current_layer()).empty()) |
| 114 return; | 121 return; |
| 115 | 122 |
| 116 size_t last_index = Children(current_layer()).size() - 1; | 123 size_t last_index = Children(current_layer()).size() - 1; |
| 117 this->current_layer_ = ChildAt(current_layer(), last_index); | 124 this->current_layer_ = ChildAt(current_layer(), last_index); |
| 118 list_indices().push_back(last_index); | 125 list_indices().push_back(last_index); |
| 119 DescendToRightmostInSubtree(); | 126 DescendToRightmostInSubtree(); |
| 120 } | 127 } |
| 121 | 128 |
| 122 template class LayerListIterator<Layer>; | 129 template class LayerListIterator<Layer>; |
| 123 template class LayerListIterator<LayerImpl>; | 130 template class LayerListIterator<LayerImpl>; |
| 124 template class LayerListReverseIterator<Layer>; | 131 template class LayerListReverseIterator<Layer>; |
| 125 template class LayerListReverseIterator<LayerImpl>; | 132 template class LayerListReverseIterator<LayerImpl>; |
| 126 | 133 |
| 127 } // namespace cc | 134 } // namespace cc |
| OLD | NEW |