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

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

Issue 551013002: Use Custome ListContainer to Allocate SharedQuadState (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@DQAllo
Patch Set: rebase Created 6 years, 2 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 | « cc/layers/tiled_layer_impl_unittest.cc ('k') | cc/quads/list_container.cc » ('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_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 15 matching lines...) Expand all
26 public: 26 public:
27 // BaseElementType is the type of raw pointers this class hands out; however, 27 // BaseElementType is the type of raw pointers this class hands out; however,
28 // its derived classes might require different memory sizes. 28 // its derived classes might require different memory sizes.
29 // max_size_for_derived_class the largest memory size required for all the 29 // max_size_for_derived_class the largest memory size required for all the
30 // derived classes to use for allocation. 30 // derived classes to use for allocation.
31 explicit ListContainer(size_t max_size_for_derived_class); 31 explicit ListContainer(size_t max_size_for_derived_class);
32 // This constructor omits input variable for max_size_for_derived_class. This 32 // 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 33 // is used when there is no derived classes from BaseElementType we need to
34 // worry about, and allocation size is just sizeof(BaseElementType). 34 // worry about, and allocation size is just sizeof(BaseElementType).
35 ListContainer(); 35 ListContainer();
36 // This constructor reserves the requested memory up front so only a single 36 // This constructor reserves the requested memory up front so only single
37 // allocation is needed. 37 // allocation is needed. When num_of_elements_to_reserve_for is zero, use the
38 // default size.
38 ListContainer(size_t max_size_for_derived_class, 39 ListContainer(size_t max_size_for_derived_class,
39 size_t num_of_elements_to_reserve_for); 40 size_t num_of_elements_to_reserve_for);
40 41
41 ~ListContainer(); 42 ~ListContainer();
42 43
43 // This class deals only with char* and void*. It does allocation and passing 44 // This class deals only with char* and void*. It does allocation and passing
44 // out raw pointers, as well as memory deallocation when being destroyed. 45 // out raw pointers, as well as memory deallocation when being destroyed.
45 class CC_EXPORT ListContainerCharAllocator; 46 class CC_EXPORT ListContainerCharAllocator;
46 47
47 // This class points to a certain position inside memory of 48 // This class points to a certain position inside memory of
(...skipping 18 matching lines...) Expand all
66 }; 67 };
67 68
68 // Iterator classes that can be used to access data. 69 // Iterator classes that can be used to access data.
69 ///////////////////////////////////////////////////////////////// 70 /////////////////////////////////////////////////////////////////
70 class CC_EXPORT Iterator : public PositionInListContainerCharAllocator { 71 class CC_EXPORT Iterator : public PositionInListContainerCharAllocator {
71 // This class is only defined to forward iterate through 72 // This class is only defined to forward iterate through
72 // ListContainerCharAllocator. 73 // ListContainerCharAllocator.
73 public: 74 public:
74 Iterator(ListContainerCharAllocator* container, 75 Iterator(ListContainerCharAllocator* container,
75 size_t vector_ind, 76 size_t vector_ind,
76 char* item_iter); 77 char* item_iter,
78 size_t index);
77 ~Iterator(); 79 ~Iterator();
78 BaseElementType* operator->() const; 80 BaseElementType* operator->() const;
79 BaseElementType& operator*() const; 81 BaseElementType& operator*() const;
80 Iterator operator++(int unused_post_increment); 82 Iterator operator++(int unused_post_increment);
81 Iterator operator++(); 83 Iterator operator++();
84
85 size_t index() const;
86
87 private:
88 // 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
90 // needed. For iterator this means begin() corresponds to index 0 and end()
91 // corresponds to index |size|.
92 size_t index_;
82 }; 93 };
83 94
84 class CC_EXPORT ConstIterator : public PositionInListContainerCharAllocator { 95 class CC_EXPORT ConstIterator : public PositionInListContainerCharAllocator {
85 // This class is only defined to forward iterate through 96 // This class is only defined to forward iterate through
86 // ListContainerCharAllocator. 97 // ListContainerCharAllocator.
87 public: 98 public:
88 ConstIterator(ListContainerCharAllocator* container, 99 ConstIterator(ListContainerCharAllocator* container,
89 size_t vector_ind, 100 size_t vector_ind,
90 char* item_iter); 101 char* item_iter,
102 size_t index);
91 ConstIterator(const Iterator& other); // NOLINT 103 ConstIterator(const Iterator& other); // NOLINT
92 ~ConstIterator(); 104 ~ConstIterator();
93 const BaseElementType* operator->() const; 105 const BaseElementType* operator->() const;
94 const BaseElementType& operator*() const; 106 const BaseElementType& operator*() const;
95 ConstIterator operator++(int unused_post_increment); 107 ConstIterator operator++(int unused_post_increment);
96 ConstIterator operator++(); 108 ConstIterator operator++();
109
110 size_t index() const;
111
112 private:
113 // 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
115 // needed. For iterator this means begin() corresponds to index 0 and end()
116 // corresponds to index |size|.
117 size_t index_;
97 }; 118 };
98 119
99 class CC_EXPORT ReverseIterator 120 class CC_EXPORT ReverseIterator
100 : public PositionInListContainerCharAllocator { 121 : public PositionInListContainerCharAllocator {
101 // This class is only defined to reverse iterate through 122 // This class is only defined to reverse iterate through
102 // ListContainerCharAllocator. 123 // ListContainerCharAllocator.
103 public: 124 public:
104 ReverseIterator(ListContainerCharAllocator* container, 125 ReverseIterator(ListContainerCharAllocator* container,
105 size_t vector_ind, 126 size_t vector_ind,
106 char* item_iter); 127 char* item_iter,
128 size_t index);
107 ~ReverseIterator(); 129 ~ReverseIterator();
108 BaseElementType* operator->() const; 130 BaseElementType* operator->() const;
109 BaseElementType& operator*() const; 131 BaseElementType& operator*() const;
110 ReverseIterator operator++(int unused_post_increment); 132 ReverseIterator operator++(int unused_post_increment);
111 ReverseIterator operator++(); 133 ReverseIterator operator++();
134
135 size_t index() const;
136
137 private:
138 // 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
140 // needed. For reverse iterator this means rbegin() corresponds to index 0
141 // and rend() corresponds to index |size|.
142 size_t index_;
112 }; 143 };
113 144
114 class CC_EXPORT ConstReverseIterator 145 class CC_EXPORT ConstReverseIterator
115 : public PositionInListContainerCharAllocator { 146 : public PositionInListContainerCharAllocator {
116 // This class is only defined to reverse iterate through 147 // This class is only defined to reverse iterate through
117 // ListContainerCharAllocator. 148 // ListContainerCharAllocator.
118 public: 149 public:
119 ConstReverseIterator(ListContainerCharAllocator* container, 150 ConstReverseIterator(ListContainerCharAllocator* container,
120 size_t vector_ind, 151 size_t vector_ind,
121 char* item_iter); 152 char* item_iter,
153 size_t index);
122 ConstReverseIterator(const ReverseIterator& other); // NOLINT 154 ConstReverseIterator(const ReverseIterator& other); // NOLINT
123 ~ConstReverseIterator(); 155 ~ConstReverseIterator();
124 const BaseElementType* operator->() const; 156 const BaseElementType* operator->() const;
125 const BaseElementType& operator*() const; 157 const BaseElementType& operator*() const;
126 ConstReverseIterator operator++(int unused_post_increment); 158 ConstReverseIterator operator++(int unused_post_increment);
127 ConstReverseIterator operator++(); 159 ConstReverseIterator operator++();
160
161 size_t index() const;
162
163 private:
164 // This is used to track how many increment has happened since rbegin(). It
165 // is used to avoid double increment at places an index reference is
166 // needed. For reverse iterator this means rbegin() corresponds to index 0
167 // and rend() corresponds to index |size|.
168 size_t index_;
128 }; 169 };
129 170
130 // When called, all raw pointers that have been handed out are no longer 171 // When called, all raw pointers that have been handed out are no longer
131 // valid. Use with caution. 172 // valid. Use with caution.
132 // This function does not deallocate memory. 173 // This function does not deallocate memory.
133 void EraseAndInvalidateAllPointers(Iterator position); 174 void EraseAndInvalidateAllPointers(Iterator position);
134 175
135 ConstReverseIterator rbegin() const; 176 ConstReverseIterator rbegin() const;
136 ConstReverseIterator rend() const; 177 ConstReverseIterator rend() const;
137 ReverseIterator rbegin(); 178 ReverseIterator rbegin();
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 DISALLOW_COPY_AND_ASSIGN(ListContainer); 219 DISALLOW_COPY_AND_ASSIGN(ListContainer);
179 }; 220 };
180 221
181 #if !defined(COMPILER_MSVC) 222 #if !defined(COMPILER_MSVC)
182 extern template class ListContainer<SharedQuadState>; 223 extern template class ListContainer<SharedQuadState>;
183 extern template class ListContainer<DrawQuad>; 224 extern template class ListContainer<DrawQuad>;
184 #endif 225 #endif
185 } // namespace cc 226 } // namespace cc
186 227
187 #endif // CC_QUADS_LIST_CONTAINER_H_ 228 #endif // CC_QUADS_LIST_CONTAINER_H_
OLDNEW
« no previous file with comments | « cc/layers/tiled_layer_impl_unittest.cc ('k') | cc/quads/list_container.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698