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

Side by Side Diff: cc/base/list_container.h

Issue 2064833002: Implement DrawQuad StructTraits (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix move constructor Created 4 years, 6 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 | « no previous file | cc/ipc/DEPS » ('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 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_BASE_LIST_CONTAINER_H_ 5 #ifndef CC_BASE_LIST_CONTAINER_H_
6 #define CC_BASE_LIST_CONTAINER_H_ 6 #define CC_BASE_LIST_CONTAINER_H_
7 7
8 #include <stddef.h> 8 #include <stddef.h>
9 9
10 #include <memory> 10 #include <memory>
11 11
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "base/macros.h" 13 #include "base/macros.h"
14 #include "cc/base/cc_export.h" 14 #include "cc/base/cc_export.h"
15 #include "cc/base/list_container_helper.h" 15 #include "cc/base/list_container_helper.h"
16 16
17 namespace cc { 17 namespace cc {
18 18
19 // ListContainer is a container type that handles allocating contiguous memory 19 // ListContainer is a container type that handles allocating contiguous memory
20 // for new elements and traversing through elements with either iterator or 20 // for new elements and traversing through elements with either iterator or
21 // reverse iterator. Since this container hands out raw pointers of its 21 // reverse iterator. Since this container hands out raw pointers of its
22 // elements, it is very important that this container never reallocate its 22 // elements, it is very important that this container never reallocate its
23 // memory so those raw pointer will continue to be valid. This class is used to 23 // memory so those raw pointer will continue to be valid. This class is used to
24 // contain SharedQuadState or DrawQuad. Since the size of each DrawQuad varies, 24 // contain SharedQuadState or DrawQuad. Since the size of each DrawQuad varies,
25 // to hold DrawQuads, the allocations size of each element in this class is 25 // to hold DrawQuads, the allocations size of each element in this class is
26 // LargestDrawQuadSize while BaseElementType is DrawQuad. 26 // LargestDrawQuadSize while BaseElementType is DrawQuad.
27 template <class BaseElementType> 27 template <class BaseElementType>
28 class ListContainer { 28 class ListContainer {
29 public: 29 public:
30 ListContainer(ListContainer&& other) : helper_(sizeof(BaseElementType)) {
31 helper_.data_.swap(other.helper_.data_);
32 }
33
30 // BaseElementType is the type of raw pointers this class hands out; however, 34 // BaseElementType is the type of raw pointers this class hands out; however,
31 // its derived classes might require different memory sizes. 35 // its derived classes might require different memory sizes.
32 // max_size_for_derived_class the largest memory size required for all the 36 // max_size_for_derived_class the largest memory size required for all the
33 // derived classes to use for allocation. 37 // derived classes to use for allocation.
34 explicit ListContainer(size_t max_size_for_derived_class) 38 explicit ListContainer(size_t max_size_for_derived_class)
35 : helper_(max_size_for_derived_class) {} 39 : helper_(max_size_for_derived_class) {}
36 40
37 // This constructor omits input variable for max_size_for_derived_class. This 41 // This constructor omits input variable for max_size_for_derived_class. This
38 // is used when there is no derived classes from BaseElementType we need to 42 // is used when there is no derived classes from BaseElementType we need to
39 // worry about, and allocation size is just sizeof(BaseElementType). 43 // worry about, and allocation size is just sizeof(BaseElementType).
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 Iterator InsertBeforeAndInvalidateAllPointers(Iterator at, size_t count) { 141 Iterator InsertBeforeAndInvalidateAllPointers(Iterator at, size_t count) {
138 helper_.InsertBeforeAndInvalidateAllPointers(&at, count); 142 helper_.InsertBeforeAndInvalidateAllPointers(&at, count);
139 Iterator result = at; 143 Iterator result = at;
140 for (size_t i = 0; i < count; ++i) { 144 for (size_t i = 0; i < count; ++i) {
141 new (at.item_iterator) DerivedElementType(); 145 new (at.item_iterator) DerivedElementType();
142 ++at; 146 ++at;
143 } 147 }
144 return result; 148 return result;
145 } 149 }
146 150
151 ListContainer& operator=(ListContainer&& other) {
152 helper_.data_.swap(other.helper_.data_);
153 return *this;
154 }
155
147 template <typename DerivedElementType> 156 template <typename DerivedElementType>
148 void swap(ListContainer<DerivedElementType>& other) { 157 void swap(ListContainer<DerivedElementType>& other) {
149 helper_.data_.swap(other.helper_.data_); 158 helper_.data_.swap(other.helper_.data_);
150 } 159 }
151 160
152 // Appends a new item without copying. The original item will not be 161 // Appends a new item without copying. The original item will not be
153 // destructed and will be replaced with a new DerivedElementType. The 162 // destructed and will be replaced with a new DerivedElementType. The
154 // DerivedElementType does not have to match the moved type as a full block 163 // DerivedElementType does not have to match the moved type as a full block
155 // of memory will be moved (up to MaxSizeForDerivedClass()). A pointer to 164 // of memory will be moved (up to MaxSizeForDerivedClass()). A pointer to
156 // the moved element is returned. 165 // the moved element is returned.
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
338 347
339 private: 348 private:
340 ListContainerHelper helper_; 349 ListContainerHelper helper_;
341 350
342 DISALLOW_COPY_AND_ASSIGN(ListContainer); 351 DISALLOW_COPY_AND_ASSIGN(ListContainer);
343 }; 352 };
344 353
345 } // namespace cc 354 } // namespace cc
346 355
347 #endif // CC_BASE_LIST_CONTAINER_H_ 356 #endif // CC_BASE_LIST_CONTAINER_H_
OLDNEW
« no previous file with comments | « no previous file | cc/ipc/DEPS » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698