Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(20)

Side by Side Diff: cc/layers/layer_list_iterator.cc

Issue 1900723002: Revert of cc: Add a main thread LayerListIterator (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « cc/layers/layer_list_iterator.h ('k') | cc/layers/layer_list_iterator_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
8 #include "cc/layers/layer_impl.h" 7 #include "cc/layers/layer_impl.h"
9 8
10 namespace cc { 9 namespace cc {
11 10
12 template <typename LayerType> 11 LayerListIterator::LayerListIterator(LayerImpl* root_layer)
13 LayerListIterator<LayerType>::LayerListIterator(LayerType* root_layer)
14 : current_layer_(root_layer) { 12 : current_layer_(root_layer) {
15 DCHECK(!root_layer || !root_layer->parent()); 13 DCHECK(!root_layer || !root_layer->parent());
16 list_indices_.push_back(0); 14 list_indices_.push_back(0);
17 } 15 }
18 16
19 template <typename LayerType> 17 LayerListIterator::LayerListIterator(const LayerListIterator& other) = default;
20 LayerListIterator<LayerType>::LayerListIterator(
21 const LayerListIterator<LayerType>& other) = default;
22 18
23 template <typename LayerType> 19 LayerListIterator::~LayerListIterator() {}
24 LayerListIterator<LayerType>::~LayerListIterator() {}
25 20
26 template <typename LayerType> 21 LayerListIterator& LayerListIterator::operator++() {
27 LayerListIterator<LayerType>& LayerListIterator<LayerType>::operator++() {
28 // case 0: done 22 // case 0: done
29 if (!current_layer_) 23 if (!current_layer_)
30 return *this; 24 return *this;
31 25
32 // case 1: descend. 26 // case 1: descend.
33 if (!current_layer_->children().empty()) { 27 const LayerImplList& current_list = current_layer_->children();
34 current_layer_ = current_layer_->child_at(0); 28 if (!current_list.empty()) {
29 current_layer_ = current_list[0];
35 list_indices_.push_back(0); 30 list_indices_.push_back(0);
36 return *this; 31 return *this;
37 } 32 }
38 33
39 for (LayerType* parent = current_layer_->parent(); parent; 34 for (LayerImpl* parent = current_layer_->parent(); parent;
40 parent = parent->parent()) { 35 parent = parent->parent()) {
41 // We now try and advance in some list of siblings. 36 // We now try and advance in some list of siblings.
37 const LayerImplList& sibling_list = parent->children();
38
42 // case 2: Advance to a sibling. 39 // case 2: Advance to a sibling.
43 if (list_indices_.back() + 1 < parent->children().size()) { 40 if (list_indices_.back() + 1 < sibling_list.size()) {
44 ++list_indices_.back(); 41 ++list_indices_.back();
45 current_layer_ = parent->child_at(list_indices_.back()); 42 current_layer_ = sibling_list[list_indices_.back()];
46 return *this; 43 return *this;
47 } 44 }
48 45
49 // We need to ascend. We will pop an index off the stack. 46 // We need to ascend. We will pop an index off the stack.
50 list_indices_.pop_back(); 47 list_indices_.pop_back();
51 } 48 }
52 49
53 current_layer_ = nullptr; 50 current_layer_ = nullptr;
54 return *this; 51 return *this;
55 } 52 }
56 53
57 template <typename LayerType> 54 LayerListReverseIterator::LayerListReverseIterator(LayerImpl* root_layer)
58 LayerListReverseIterator<LayerType>::LayerListReverseIterator( 55 : LayerListIterator(root_layer) {
59 LayerType* root_layer)
60 : LayerListIterator<LayerType>(root_layer) {
61 DescendToRightmostInSubtree(); 56 DescendToRightmostInSubtree();
62 } 57 }
63 58
64 template <typename LayerType> 59 LayerListReverseIterator::~LayerListReverseIterator() {}
65 LayerListReverseIterator<LayerType>::~LayerListReverseIterator() {}
66 60
67 // We will only support prefix increment. 61 // We will only support prefix increment.
68 template <typename LayerType> 62 LayerListIterator& LayerListReverseIterator::operator++() {
69 LayerListIterator<LayerType>& LayerListReverseIterator<LayerType>::
70 operator++() {
71 // case 0: done 63 // case 0: done
72 if (!current_layer()) 64 if (!current_layer_)
73 return *this; 65 return *this;
74 66
75 // case 1: we're the leftmost sibling. 67 // case 1: we're the leftmost sibling.
76 if (!list_indices().back()) { 68 if (!list_indices_.back()) {
77 list_indices().pop_back(); 69 list_indices_.pop_back();
78 this->current_layer_ = current_layer()->parent(); 70 current_layer_ = current_layer_->parent();
79 return *this; 71 return *this;
80 } 72 }
81 73
82 // case 2: we're not the leftmost sibling. In this case, we want to move one 74 // case 2: we're not the leftmost sibling. In this case, we want to move one
83 // sibling over, and then descend to the rightmost descendant in that subtree. 75 // sibling over, and then descend to the rightmost descendant in that subtree.
84 CHECK(current_layer()->parent()); 76 CHECK(current_layer_->parent());
85 --list_indices().back(); 77 --list_indices_.back();
86 this->current_layer_ = 78 const LayerImplList& parent_list = current_layer_->parent()->children();
87 current_layer()->parent()->child_at(list_indices().back()); 79 current_layer_ = parent_list[list_indices_.back()];
88 DescendToRightmostInSubtree(); 80 DescendToRightmostInSubtree();
89 return *this; 81 return *this;
90 } 82 }
91 83
92 template <typename LayerType> 84 void LayerListReverseIterator::DescendToRightmostInSubtree() {
93 void LayerListReverseIterator<LayerType>::DescendToRightmostInSubtree() { 85 if (!current_layer_)
94 if (!current_layer())
95 return; 86 return;
96 87
97 if (current_layer()->children().empty()) 88 const LayerImplList& current_list = current_layer_->children();
89 if (current_list.empty())
98 return; 90 return;
99 91
100 size_t last_index = current_layer()->children().size() - 1; 92 size_t last_index = current_list.size() - 1;
101 this->current_layer_ = current_layer()->child_at(last_index); 93 current_layer_ = current_list[last_index];
102 list_indices().push_back(last_index); 94 list_indices_.push_back(last_index);
103 DescendToRightmostInSubtree(); 95 DescendToRightmostInSubtree();
104 } 96 }
105 97
106 template class LayerListIterator<Layer>;
107 template class LayerListIterator<LayerImpl>;
108 template class LayerListReverseIterator<Layer>;
109 template class LayerListReverseIterator<LayerImpl>;
110
111 } // namespace cc 98 } // namespace cc
OLDNEW
« no previous file with comments | « cc/layers/layer_list_iterator.h ('k') | cc/layers/layer_list_iterator_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698