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" | 10 #include "cc/base/cc_export.h" |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
143 | 143 |
144 BaseElementType* front(); | 144 BaseElementType* front(); |
145 BaseElementType* back(); | 145 BaseElementType* back(); |
146 const BaseElementType* front() const; | 146 const BaseElementType* front() const; |
147 const BaseElementType* back() const; | 147 const BaseElementType* back() const; |
148 | 148 |
149 // Take in derived element type and construct it at location generated by | 149 // Take in derived element type and construct it at location generated by |
150 // Allocate(). | 150 // Allocate(). |
151 template <typename DerivedElementType> | 151 template <typename DerivedElementType> |
152 DerivedElementType* AllocateAndConstruct() { | 152 DerivedElementType* AllocateAndConstruct() { |
153 DerivedElementType* result = | 153 return new (Allocate(sizeof(DerivedElementType))) DerivedElementType; |
154 new (Allocate(sizeof(DerivedElementType))) DerivedElementType; | 154 } |
155 return result; | 155 // Take in derived element type and copy construct it at location generated by |
156 // Allocate(). | |
157 template <typename DerivedElementType> | |
158 DerivedElementType* AllocateAndCopyConstruct( | |
danakj
2014/09/23 17:59:38
nit: AllocateAndCopyFrom?
weiliangc
2014/09/24 20:14:35
Done.
| |
159 const DerivedElementType* source) { | |
160 return new (Allocate(sizeof(DerivedElementType))) | |
161 DerivedElementType(*source); | |
156 } | 162 } |
157 | 163 |
158 size_t size() const; | 164 size_t size() const; |
159 bool empty() const; | 165 bool empty() const; |
160 void clear(); | 166 void clear(); |
161 | 167 |
162 size_t AvailableSizeWithoutAnotherAllocationForTesting() const; | 168 size_t AvailableSizeWithoutAnotherAllocationForTesting() const; |
163 | 169 |
164 private: | 170 private: |
165 // Hands out memory location for an element at the end of data structure. | 171 // Hands out memory location for an element at the end of data structure. |
166 BaseElementType* Allocate(size_t size_of_actual_element_in_bytes); | 172 BaseElementType* Allocate(size_t size_of_actual_element_in_bytes); |
167 | 173 |
168 scoped_ptr<ListContainerCharAllocator> data_; | 174 scoped_ptr<ListContainerCharAllocator> data_; |
169 | 175 |
170 DISALLOW_COPY_AND_ASSIGN(ListContainer); | 176 DISALLOW_COPY_AND_ASSIGN(ListContainer); |
171 }; | 177 }; |
172 | 178 |
173 #if !defined(COMPILER_MSVC) | 179 #if !defined(COMPILER_MSVC) |
174 extern template class ListContainer<SharedQuadState>; | 180 extern template class ListContainer<SharedQuadState>; |
175 extern template class ListContainer<DrawQuad>; | 181 extern template class ListContainer<DrawQuad>; |
176 #endif | 182 #endif |
177 } // namespace cc | 183 } // namespace cc |
178 | 184 |
179 #endif // CC_QUADS_LIST_CONTAINER_H_ | 185 #endif // CC_QUADS_LIST_CONTAINER_H_ |
OLD | NEW |