| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_QUADS_LIST_CONTAINER_H_ | 5 #ifndef CC_QUADS_LIST_CONTAINER_H_ |
| 6 #define CC_QUADS_LIST_CONTAINER_H_ | 6 #define CC_QUADS_LIST_CONTAINER_H_ |
| 7 | 7 |
| 8 #include "base/macros.h" | 8 #include "base/macros.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "cc/base/cc_export.h" | |
| 11 | 10 |
| 12 namespace cc { | 11 namespace cc { |
| 13 class SharedQuadState; | 12 class SharedQuadState; |
| 14 class DrawQuad; | 13 class DrawQuad; |
| 15 | 14 |
| 16 // This class is a container type that handles allocating contiguous memory for | 15 // This class is a container type that handles allocating contiguous memory for |
| 17 // new elements and traversing through elements with either iterator or reverse | 16 // new elements and traversing through elements with either iterator or reverse |
| 18 // iterator. Since this container hands out raw pointers of its elements, it is | 17 // iterator. Since this container hands out raw pointers of its elements, it is |
| 19 // very important that this container never reallocate its memory so those raw | 18 // very important that this container never reallocate its memory so those raw |
| 20 // pointer will continue to be valid. This class is used to contain | 19 // pointer will continue to be valid. This class is used to contain |
| 21 // SharedQuadState or DrawQuad. Since the size of each DrawQuad varies, to hold | 20 // SharedQuadState or DrawQuad. Since the size of each DrawQuad varies, to hold |
| 22 // DrawQuads, the allocations size of each element in this class is | 21 // DrawQuads, the allocations size of each element in this class is |
| 23 // LargestDrawQuadSize while BaseElementType is DrawQuad. | 22 // LargestDrawQuadSize while BaseElementType is DrawQuad. |
| 24 template <class BaseElementType> | 23 template <class BaseElementType> |
| 25 class CC_EXPORT ListContainer { | 24 class ListContainer { |
| 26 public: | 25 public: |
| 27 // BaseElementType is the type of raw pointers this class hands out; however, | 26 // BaseElementType is the type of raw pointers this class hands out; however, |
| 28 // its derived classes might require different memory sizes. | 27 // its derived classes might require different memory sizes. |
| 29 // max_size_for_derived_class the largest memory size required for all the | 28 // max_size_for_derived_class the largest memory size required for all the |
| 30 // derived classes to use for allocation. | 29 // derived classes to use for allocation. |
| 31 explicit ListContainer(size_t max_size_for_derived_class); | 30 explicit ListContainer(size_t max_size_for_derived_class); |
| 32 // This constructor omits input variable for max_size_for_derived_class. This | 31 // This constructor omits input variable for max_size_for_derived_class. This |
| 33 // is used when there is no derived classes from BaseElementType we need to | 32 // is used when there is no derived classes from BaseElementType we need to |
| 34 // worry about, and allocation size is just sizeof(BaseElementType). | 33 // worry about, and allocation size is just sizeof(BaseElementType). |
| 35 ListContainer(); | 34 ListContainer(); |
| 36 // This constructor reserves the requested memory up front so only single | 35 // This constructor reserves the requested memory up front so only single |
| 37 // allocation is needed. When num_of_elements_to_reserve_for is zero, use the | 36 // allocation is needed. When num_of_elements_to_reserve_for is zero, use the |
| 38 // default size. | 37 // default size. |
| 39 ListContainer(size_t max_size_for_derived_class, | 38 ListContainer(size_t max_size_for_derived_class, |
| 40 size_t num_of_elements_to_reserve_for); | 39 size_t num_of_elements_to_reserve_for); |
| 41 | 40 |
| 42 ~ListContainer(); | 41 ~ListContainer(); |
| 43 | 42 |
| 44 // This class deals only with char* and void*. It does allocation and passing | 43 // This class deals only with char* and void*. It does allocation and passing |
| 45 // out raw pointers, as well as memory deallocation when being destroyed. | 44 // out raw pointers, as well as memory deallocation when being destroyed. |
| 46 class CC_EXPORT ListContainerCharAllocator; | 45 class ListContainerCharAllocator; |
| 47 | 46 |
| 48 // This class points to a certain position inside memory of | 47 // This class points to a certain position inside memory of |
| 49 // ListContainerCharAllocator. It is a base class for ListContainer iterators. | 48 // ListContainerCharAllocator. It is a base class for ListContainer iterators. |
| 50 struct CC_EXPORT PositionInListContainerCharAllocator { | 49 struct PositionInListContainerCharAllocator { |
| 51 ListContainerCharAllocator* ptr_to_container; | 50 ListContainerCharAllocator* ptr_to_container; |
| 52 size_t vector_index; | 51 size_t vector_index; |
| 53 char* item_iterator; | 52 char* item_iterator; |
| 54 | 53 |
| 55 PositionInListContainerCharAllocator( | 54 PositionInListContainerCharAllocator( |
| 56 const PositionInListContainerCharAllocator& other); | 55 const PositionInListContainerCharAllocator& other); |
| 57 | 56 |
| 58 PositionInListContainerCharAllocator(ListContainerCharAllocator* container, | 57 PositionInListContainerCharAllocator(ListContainerCharAllocator* container, |
| 59 size_t vector_ind, | 58 size_t vector_ind, |
| 60 char* item_iter); | 59 char* item_iter); |
| 61 | 60 |
| 62 bool operator==(const PositionInListContainerCharAllocator& other) const; | 61 bool operator==(const PositionInListContainerCharAllocator& other) const; |
| 63 bool operator!=(const PositionInListContainerCharAllocator& other) const; | 62 bool operator!=(const PositionInListContainerCharAllocator& other) const; |
| 64 | 63 |
| 65 PositionInListContainerCharAllocator Increment(); | 64 PositionInListContainerCharAllocator Increment(); |
| 66 PositionInListContainerCharAllocator ReverseIncrement(); | 65 PositionInListContainerCharAllocator ReverseIncrement(); |
| 67 }; | 66 }; |
| 68 | 67 |
| 69 // Iterator classes that can be used to access data. | 68 // Iterator classes that can be used to access data. |
| 70 ///////////////////////////////////////////////////////////////// | 69 ///////////////////////////////////////////////////////////////// |
| 71 class CC_EXPORT Iterator : public PositionInListContainerCharAllocator { | 70 class Iterator : public PositionInListContainerCharAllocator { |
| 72 // This class is only defined to forward iterate through | 71 // This class is only defined to forward iterate through |
| 73 // ListContainerCharAllocator. | 72 // ListContainerCharAllocator. |
| 74 public: | 73 public: |
| 75 Iterator(ListContainerCharAllocator* container, | 74 Iterator(ListContainerCharAllocator* container, |
| 76 size_t vector_ind, | 75 size_t vector_ind, |
| 77 char* item_iter, | 76 char* item_iter, |
| 78 size_t index); | 77 size_t index); |
| 79 ~Iterator(); | 78 ~Iterator(); |
| 80 BaseElementType* operator->() const; | 79 BaseElementType* operator->() const; |
| 81 BaseElementType* operator*() const; | 80 BaseElementType* operator*() const; |
| 82 Iterator operator++(int unused_post_increment); | 81 Iterator operator++(int unused_post_increment); |
| 83 Iterator& operator++(); | 82 Iterator& operator++(); |
| 84 | 83 |
| 85 size_t index() const; | 84 size_t index() const; |
| 86 | 85 |
| 87 private: | 86 private: |
| 88 // This is used to track how many increment has happened since begin(). It | 87 // This is used to track how many increment has happened since begin(). It |
| 89 // is used to avoid double increment at places an index reference is | 88 // is used to avoid double increment at places an index reference is |
| 90 // needed. For iterator this means begin() corresponds to index 0 and end() | 89 // needed. For iterator this means begin() corresponds to index 0 and end() |
| 91 // corresponds to index |size|. | 90 // corresponds to index |size|. |
| 92 size_t index_; | 91 size_t index_; |
| 93 }; | 92 }; |
| 94 | 93 |
| 95 class CC_EXPORT ConstIterator : public PositionInListContainerCharAllocator { | 94 class ConstIterator : public PositionInListContainerCharAllocator { |
| 96 // This class is only defined to forward iterate through | 95 // This class is only defined to forward iterate through |
| 97 // ListContainerCharAllocator. | 96 // ListContainerCharAllocator. |
| 98 public: | 97 public: |
| 99 ConstIterator(ListContainerCharAllocator* container, | 98 ConstIterator(ListContainerCharAllocator* container, |
| 100 size_t vector_ind, | 99 size_t vector_ind, |
| 101 char* item_iter, | 100 char* item_iter, |
| 102 size_t index); | 101 size_t index); |
| 103 ConstIterator(const Iterator& other); // NOLINT | 102 ConstIterator(const Iterator& other); // NOLINT |
| 104 ~ConstIterator(); | 103 ~ConstIterator(); |
| 105 const BaseElementType* operator->() const; | 104 const BaseElementType* operator->() const; |
| 106 const BaseElementType* operator*() const; | 105 const BaseElementType* operator*() const; |
| 107 ConstIterator operator++(int unused_post_increment); | 106 ConstIterator operator++(int unused_post_increment); |
| 108 ConstIterator& operator++(); | 107 ConstIterator& operator++(); |
| 109 | 108 |
| 110 size_t index() const; | 109 size_t index() const; |
| 111 | 110 |
| 112 private: | 111 private: |
| 113 // This is used to track how many increment has happened since begin(). It | 112 // This is used to track how many increment has happened since begin(). It |
| 114 // is used to avoid double increment at places an index reference is | 113 // is used to avoid double increment at places an index reference is |
| 115 // needed. For iterator this means begin() corresponds to index 0 and end() | 114 // needed. For iterator this means begin() corresponds to index 0 and end() |
| 116 // corresponds to index |size|. | 115 // corresponds to index |size|. |
| 117 size_t index_; | 116 size_t index_; |
| 118 }; | 117 }; |
| 119 | 118 |
| 120 class CC_EXPORT ReverseIterator | 119 class ReverseIterator : public PositionInListContainerCharAllocator { |
| 121 : public PositionInListContainerCharAllocator { | |
| 122 // This class is only defined to reverse iterate through | 120 // This class is only defined to reverse iterate through |
| 123 // ListContainerCharAllocator. | 121 // ListContainerCharAllocator. |
| 124 public: | 122 public: |
| 125 ReverseIterator(ListContainerCharAllocator* container, | 123 ReverseIterator(ListContainerCharAllocator* container, |
| 126 size_t vector_ind, | 124 size_t vector_ind, |
| 127 char* item_iter, | 125 char* item_iter, |
| 128 size_t index); | 126 size_t index); |
| 129 ~ReverseIterator(); | 127 ~ReverseIterator(); |
| 130 BaseElementType* operator->() const; | 128 BaseElementType* operator->() const; |
| 131 BaseElementType* operator*() const; | 129 BaseElementType* operator*() const; |
| 132 ReverseIterator operator++(int unused_post_increment); | 130 ReverseIterator operator++(int unused_post_increment); |
| 133 ReverseIterator& operator++(); | 131 ReverseIterator& operator++(); |
| 134 | 132 |
| 135 size_t index() const; | 133 size_t index() const; |
| 136 | 134 |
| 137 private: | 135 private: |
| 138 // This is used to track how many increment has happened since rbegin(). It | 136 // This is used to track how many increment has happened since rbegin(). It |
| 139 // is used to avoid double increment at places an index reference is | 137 // is used to avoid double increment at places an index reference is |
| 140 // needed. For reverse iterator this means rbegin() corresponds to index 0 | 138 // needed. For reverse iterator this means rbegin() corresponds to index 0 |
| 141 // and rend() corresponds to index |size|. | 139 // and rend() corresponds to index |size|. |
| 142 size_t index_; | 140 size_t index_; |
| 143 }; | 141 }; |
| 144 | 142 |
| 145 class CC_EXPORT ConstReverseIterator | 143 class ConstReverseIterator : public PositionInListContainerCharAllocator { |
| 146 : public PositionInListContainerCharAllocator { | |
| 147 // This class is only defined to reverse iterate through | 144 // This class is only defined to reverse iterate through |
| 148 // ListContainerCharAllocator. | 145 // ListContainerCharAllocator. |
| 149 public: | 146 public: |
| 150 ConstReverseIterator(ListContainerCharAllocator* container, | 147 ConstReverseIterator(ListContainerCharAllocator* container, |
| 151 size_t vector_ind, | 148 size_t vector_ind, |
| 152 char* item_iter, | 149 char* item_iter, |
| 153 size_t index); | 150 size_t index); |
| 154 ConstReverseIterator(const ReverseIterator& other); // NOLINT | 151 ConstReverseIterator(const ReverseIterator& other); // NOLINT |
| 155 ~ConstReverseIterator(); | 152 ~ConstReverseIterator(); |
| 156 const BaseElementType* operator->() const; | 153 const BaseElementType* operator->() const; |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 225 DISALLOW_COPY_AND_ASSIGN(ListContainer); | 222 DISALLOW_COPY_AND_ASSIGN(ListContainer); |
| 226 }; | 223 }; |
| 227 | 224 |
| 228 #if !defined(COMPILER_MSVC) | 225 #if !defined(COMPILER_MSVC) |
| 229 extern template class ListContainer<SharedQuadState>; | 226 extern template class ListContainer<SharedQuadState>; |
| 230 extern template class ListContainer<DrawQuad>; | 227 extern template class ListContainer<DrawQuad>; |
| 231 #endif | 228 #endif |
| 232 } // namespace cc | 229 } // namespace cc |
| 233 | 230 |
| 234 #endif // CC_QUADS_LIST_CONTAINER_H_ | 231 #endif // CC_QUADS_LIST_CONTAINER_H_ |
| OLD | NEW |