| 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 #ifndef CC_LAYERS_LAYER_LIST_ITERATOR_H_ | 5 #ifndef CC_LAYERS_LAYER_LIST_ITERATOR_H_ |
| 6 #define CC_LAYERS_LAYER_LIST_ITERATOR_H_ | 6 #define CC_LAYERS_LAYER_LIST_ITERATOR_H_ |
| 7 | 7 |
| 8 #include <stdlib.h> | 8 #include <stdlib.h> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "cc/base/cc_export.h" | 11 #include "cc/base/cc_export.h" |
| 12 | 12 |
| 13 namespace cc { | 13 namespace cc { |
| 14 | 14 |
| 15 class Layer; | |
| 16 class LayerImpl; | 15 class LayerImpl; |
| 17 | 16 |
| 18 // Unlike LayerIterator and friends, these iterators are not intended to permit | 17 // Unlike LayerIterator and friends, these iterators are not intended to permit |
| 19 // traversing the RSLL. Rather, they visit a collection of LayerImpls in | 18 // traversing the RSLL. Rather, they visit a collection of LayerImpls in |
| 20 // stacking order. All recursive walks over the LayerImpl tree should be | 19 // stacking order. All recursive walks over the LayerImpl tree should be |
| 21 // switched to use these classes instead as the concept of a LayerImpl tree is | 20 // switched to use these classes instead as the concept of a LayerImpl tree is |
| 22 // deprecated. | 21 // deprecated. |
| 23 template <typename LayerType> | |
| 24 class CC_EXPORT LayerListIterator { | 22 class CC_EXPORT LayerListIterator { |
| 25 public: | 23 public: |
| 26 explicit LayerListIterator(LayerType* root_layer); | 24 explicit LayerListIterator(LayerImpl* root_layer); |
| 27 LayerListIterator(const LayerListIterator<LayerType>& other); | 25 LayerListIterator(const LayerListIterator& other); |
| 28 virtual ~LayerListIterator(); | 26 virtual ~LayerListIterator(); |
| 29 | 27 |
| 30 bool operator==(const LayerListIterator<LayerType>& other) const { | 28 bool operator==(const LayerListIterator& other) const { |
| 31 return current_layer_ == other.current_layer_; | 29 return current_layer_ == other.current_layer_; |
| 32 } | 30 } |
| 33 | 31 |
| 34 bool operator!=(const LayerListIterator<LayerType>& other) const { | 32 bool operator!=(const LayerListIterator& other) const { |
| 35 return !(*this == other); | 33 return !(*this == other); |
| 36 } | 34 } |
| 37 | 35 |
| 38 // We will only support prefix increment. | 36 // We will only support prefix increment. |
| 39 virtual LayerListIterator& operator++(); | 37 virtual LayerListIterator& operator++(); |
| 40 LayerType* operator->() const { return current_layer_; } | 38 LayerImpl* operator->() const { return current_layer_; } |
| 41 LayerType* operator*() const { return current_layer_; } | 39 LayerImpl* operator*() const { return current_layer_; } |
| 42 | 40 |
| 43 protected: | 41 protected: |
| 44 // The implementation of this iterator is currently tied tightly to the layer | 42 // The implementation of this iterator is currently tied tightly to the layer |
| 45 // tree, but it should be straightforward to reimplement in terms of a list | 43 // tree, but it should be straightforward to reimplement in terms of a list |
| 46 // when it's ready. | 44 // when it's ready. |
| 47 LayerType* current_layer_; | 45 LayerImpl* current_layer_; |
| 48 std::vector<size_t> list_indices_; | 46 std::vector<size_t> list_indices_; |
| 49 }; | 47 }; |
| 50 | 48 |
| 51 template <typename LayerType> | 49 class CC_EXPORT LayerListReverseIterator : public LayerListIterator { |
| 52 class CC_EXPORT LayerListReverseIterator : public LayerListIterator<LayerType> { | |
| 53 public: | 50 public: |
| 54 explicit LayerListReverseIterator(LayerType* root_layer); | 51 explicit LayerListReverseIterator(LayerImpl* root_layer); |
| 55 ~LayerListReverseIterator() override; | 52 ~LayerListReverseIterator() override; |
| 56 | 53 |
| 57 // We will only support prefix increment. | 54 // We will only support prefix increment. |
| 58 LayerListIterator<LayerType>& operator++() override; | 55 LayerListIterator& operator++() override; |
| 59 | 56 |
| 60 private: | 57 private: |
| 61 void DescendToRightmostInSubtree(); | 58 void DescendToRightmostInSubtree(); |
| 62 LayerType* current_layer() { return this->current_layer_; } | |
| 63 std::vector<size_t>& list_indices() { return this->list_indices_; } | |
| 64 }; | 59 }; |
| 65 | 60 |
| 66 } // namespace cc | 61 } // namespace cc |
| 67 | 62 |
| 68 #endif // CC_LAYERS_LAYER_LIST_ITERATOR_H_ | 63 #endif // CC_LAYERS_LAYER_LIST_ITERATOR_H_ |
| OLD | NEW |