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