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

Side by Side Diff: cc/layers/layer_iterator.h

Issue 180243014: Revert "Revert 253606 "Revert 251238 "cc: Clean up iterator template to ..."" (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 9 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 | Annotate | Revision Log
« no previous file with comments | « cc/debug/debug_rect_history.cc ('k') | cc/layers/layer_iterator.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 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 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_ITERATOR_H_ 5 #ifndef CC_LAYERS_LAYER_ITERATOR_H_
6 #define CC_LAYERS_LAYER_ITERATOR_H_ 6 #define CC_LAYERS_LAYER_ITERATOR_H_
7 7
8 #include "base/memory/ref_counted.h"
8 #include "cc/base/cc_export.h" 9 #include "cc/base/cc_export.h"
9 #include "cc/trees/layer_tree_host_common.h" 10 #include "cc/trees/layer_tree_host_common.h"
10 11
11 namespace cc { 12 namespace cc {
12 13
13 // These classes provide means to iterate over the 14 // These classes provide means to iterate over the
14 // RenderSurface-Layer tree. 15 // RenderSurface-Layer tree.
15 16
16 // Example code follows, for a tree of Layer/RenderSurface objects. 17 // Example code follows, for a tree of Layer/RenderSurface objects.
17 // See below for details. 18 // See below for details.
18 // 19 //
19 // void DoStuffOnLayers( 20 // void DoStuffOnLayers(
20 // const RenderSurfaceLayerList& render_surface_layer_list) { 21 // const RenderSurfaceLayerList& render_surface_layer_list) {
21 // typedef LayerIterator<Layer> LayerIteratorType; 22 // typedef LayerIterator<Layer,
23 // RenderSurfaceLayerList,
24 // RenderSurface,
25 // LayerIteratorActions::FrontToBack>
26 // LayerIteratorType;
22 // 27 //
23 // LayerIteratorType end = 28 // LayerIteratorType end =
24 // LayerIteratorType::End(&render_surface_layer_list); 29 // LayerIteratorType::End(&render_surface_layer_list);
25 // for (LayerIteratorType 30 // for (LayerIteratorType
26 // it = LayerIteratorType::Begin(&render_surface_layer_list); 31 // it = LayerIteratorType::Begin(&render_surface_layer_list);
27 // it != end; 32 // it != end;
28 // ++it) { 33 // ++it) {
29 // // Only one of these will be true 34 // // Only one of these will be true
30 // if (it.represents_target_render_surface()) 35 // if (it.represents_target_render_surface())
31 // foo(*it); // *it is a layer representing a target RenderSurface 36 // foo(*it); // *it is a layer representing a target RenderSurface
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 template <typename LayerType> struct LayerIteratorPosition { 98 template <typename LayerType> struct LayerIteratorPosition {
94 bool represents_target_render_surface; 99 bool represents_target_render_surface;
95 bool represents_contributing_render_surface; 100 bool represents_contributing_render_surface;
96 bool represents_itself; 101 bool represents_itself;
97 LayerType* target_render_surface_layer; 102 LayerType* target_render_surface_layer;
98 LayerType* current_layer; 103 LayerType* current_layer;
99 }; 104 };
100 105
101 // An iterator class for walking over layers in the 106 // An iterator class for walking over layers in the
102 // RenderSurface-Layer tree. 107 // RenderSurface-Layer tree.
103 template <typename LayerType> 108 template <typename LayerType,
109 typename LayerList,
110 typename RenderSurfaceType,
111 typename IteratorActionType>
104 class LayerIterator { 112 class LayerIterator {
105 typedef LayerIterator<LayerType> LayerIteratorType; 113 typedef LayerIterator<LayerType,
106 typedef typename LayerType::RenderSurfaceListType LayerList; 114 LayerList,
107 typedef typename LayerType::RenderSurfaceType RenderSurfaceType; 115 RenderSurfaceType,
116 IteratorActionType> LayerIteratorType;
108 117
109 public: 118 public:
110 LayerIterator() : render_surface_layer_list_(NULL) {} 119 LayerIterator() : render_surface_layer_list_(NULL) {}
111 120
112 static LayerIteratorType Begin(const LayerList* render_surface_layer_list) { 121 static LayerIteratorType Begin(const LayerList* render_surface_layer_list) {
113 return LayerIteratorType(render_surface_layer_list, true); 122 return LayerIteratorType(render_surface_layer_list, true);
114 } 123 }
115 static LayerIteratorType End(const LayerList* render_surface_layer_list) { 124 static LayerIteratorType End(const LayerList* render_surface_layer_list) {
116 return LayerIteratorType(render_surface_layer_list, false); 125 return LayerIteratorType(render_surface_layer_list, false);
117 } 126 }
118 127
119 LayerIteratorType& operator++() { 128 LayerIteratorType& operator++() {
120 MoveToNext(); 129 actions_.Next(this);
121 return *this; 130 return *this;
122 } 131 }
123 bool operator==(const LayerIterator& other) const { 132 bool operator==(const LayerIterator& other) const {
124 return target_render_surface_layer_index_ == 133 return target_render_surface_layer_index_ ==
125 other.target_render_surface_layer_index_ && 134 other.target_render_surface_layer_index_ &&
126 current_layer_index_ == other.current_layer_index_; 135 current_layer_index_ == other.current_layer_index_;
127 } 136 }
128 bool operator!=(const LayerIteratorType& other) const { 137 bool operator!=(const LayerIteratorType& other) const {
129 return !(*this == other); 138 return !(*this == other);
130 } 139 }
(...skipping 29 matching lines...) Expand all
160 return position; 169 return position;
161 } 170 }
162 171
163 private: 172 private:
164 LayerIterator(const LayerList* render_surface_layer_list, bool start) 173 LayerIterator(const LayerList* render_surface_layer_list, bool start)
165 : render_surface_layer_list_(render_surface_layer_list), 174 : render_surface_layer_list_(render_surface_layer_list),
166 target_render_surface_layer_index_(0) { 175 target_render_surface_layer_index_(0) {
167 for (size_t i = 0; i < render_surface_layer_list->size(); ++i) { 176 for (size_t i = 0; i < render_surface_layer_list->size(); ++i) {
168 if (!render_surface_layer_list->at(i)->render_surface()) { 177 if (!render_surface_layer_list->at(i)->render_surface()) {
169 NOTREACHED(); 178 NOTREACHED();
170 MoveToEnd(); 179 actions_.End(this);
171 return; 180 return;
172 } 181 }
173 } 182 }
174 183
175 if (start && !render_surface_layer_list->empty()) 184 if (start && !render_surface_layer_list->empty())
176 MoveToBegin(); 185 actions_.Begin(this);
177 else 186 else
178 MoveToEnd(); 187 actions_.End(this);
179 }
180
181 void MoveToBegin() {
182 target_render_surface_layer_index_ = 0;
183 current_layer_index_ = target_render_surface_children().size() - 1;
184 MoveToHighestInSubtree();
185 }
186
187 void MoveToEnd() {
188 target_render_surface_layer_index_ =
189 LayerIteratorValue::kInvalidTargetRenderSurfaceLayerIndex;
190 current_layer_index_ = 0;
191 }
192
193 void MoveToNext() {
194 // Moves to the previous layer in the current RS layer list.
195 // Then we check if the new current layer has its own RS,
196 // in which case there are things in that RS layer list that are higher,
197 // so we find the highest layer in that subtree.
198 // If we move back past the front of the list,
199 // we jump up to the previous RS layer list, picking up again where we
200 // had previously recursed into the current RS layer list.
201
202 if (!current_layer_represents_target_render_surface()) {
203 // Subtracting one here will eventually cause the current layer
204 // to become that layer representing the target render surface.
205 --current_layer_index_;
206 MoveToHighestInSubtree();
207 } else {
208 while (current_layer_represents_target_render_surface()) {
209 if (!target_render_surface_layer_index_) {
210 // End of the list.
211 target_render_surface_layer_index_ =
212 LayerIteratorValue::kInvalidTargetRenderSurfaceLayerIndex;
213 current_layer_index_ = 0;
214 return;
215 }
216 target_render_surface_layer_index_ =
217 target_render_surface()->target_render_surface_layer_index_history_;
218 current_layer_index_ =
219 target_render_surface()->current_layer_index_history_;
220 }
221 }
222 }
223
224 void MoveToHighestInSubtree() {
225 if (current_layer_represents_target_render_surface())
226 return;
227 while (current_layer_represents_contributing_render_surface()) {
228 // Save where we were in the current target surface, move to the next one,
229 // and save the target surface that we came from there
230 // so we can go back to it.
231 target_render_surface()->current_layer_index_history_ =
232 current_layer_index_;
233 int previous_target_render_surface_layer =
234 target_render_surface_layer_index_;
235
236 for (LayerType* layer = current_layer();
237 target_render_surface_layer() != layer;
238 ++target_render_surface_layer_index_) {
239 }
240 current_layer_index_ = target_render_surface_children().size() - 1;
241
242 target_render_surface()->target_render_surface_layer_index_history_ =
243 previous_target_render_surface_layer;
244 }
245 } 188 }
246 189
247 inline LayerType* current_layer() const { 190 inline LayerType* current_layer() const {
248 return current_layer_represents_target_render_surface() 191 return current_layer_represents_target_render_surface()
249 ? target_render_surface_layer() 192 ? target_render_surface_layer()
250 : target_render_surface_children().at(current_layer_index_); 193 : target_render_surface_children().at(current_layer_index_);
251 } 194 }
252 195
253 inline bool current_layer_represents_contributing_render_surface() const { 196 inline bool current_layer_represents_contributing_render_surface() const {
254 return LayerTreeHostCommon::RenderSurfaceContributesToTarget<LayerType>( 197 return LayerTreeHostCommon::RenderSurfaceContributesToTarget<LayerType>(
255 current_layer(), target_render_surface_layer()->id()); 198 current_layer(), target_render_surface_layer()->id());
256 } 199 }
257 inline bool current_layer_represents_target_render_surface() const { 200 inline bool current_layer_represents_target_render_surface() const {
258 return current_layer_index_ == 201 return current_layer_index_ ==
259 LayerIteratorValue::kLayerIndexRepresentingTargetRenderSurface; 202 LayerIteratorValue::kLayerIndexRepresentingTargetRenderSurface;
260 } 203 }
261 204
262 inline RenderSurfaceType* target_render_surface() const { 205 inline RenderSurfaceType* target_render_surface() const {
263 return target_render_surface_layer()->render_surface(); 206 return target_render_surface_layer()->render_surface();
264 } 207 }
265 inline const LayerList& target_render_surface_children() const { 208 inline const LayerList& target_render_surface_children() const {
266 return target_render_surface()->layer_list(); 209 return target_render_surface()->layer_list();
267 } 210 }
268 211
212 IteratorActionType actions_;
269 const LayerList* render_surface_layer_list_; 213 const LayerList* render_surface_layer_list_;
270 214
271 // The iterator's current position. 215 // The iterator's current position.
272 216
273 // A position in the render_surface_layer_list. This points to a layer which 217 // A position in the render_surface_layer_list. This points to a layer which
274 // owns the current target surface. This is a value from 0 to n-1 218 // owns the current target surface. This is a value from 0 to n-1
275 // (n = size of render_surface_layer_list = number of surfaces). 219 // (n = size of render_surface_layer_list = number of surfaces).
276 // A value outside of this range 220 // A value outside of this range
277 // (for example, LayerIteratorValue::kInvalidTargetRenderSurfaceLayerIndex) 221 // (for example, LayerIteratorValue::kInvalidTargetRenderSurfaceLayerIndex)
278 // is used to indicate a position outside the bounds of the tree. 222 // is used to indicate a position outside the bounds of the tree.
279 int target_render_surface_layer_index_; 223 int target_render_surface_layer_index_;
280 // A position in the list of layers that are children of the 224 // A position in the list of layers that are children of the
281 // current target surface. When pointing to one of these layers, 225 // current target surface. When pointing to one of these layers,
282 // this is a value from 0 to n-1 (n = number of children). 226 // this is a value from 0 to n-1 (n = number of children).
283 // Since the iterator must also stop at the layers representing 227 // Since the iterator must also stop at the layers representing
284 // the target surface, this is done by setting the current_layerIndex 228 // the target surface, this is done by setting the current_layerIndex
285 // to a value of LayerIteratorValue::LayerRepresentingTargetRenderSurface. 229 // to a value of LayerIteratorValue::LayerRepresentingTargetRenderSurface.
286 int current_layer_index_; 230 int current_layer_index_;
231
232 friend struct LayerIteratorActions;
233 };
234
235 // Orderings for iterating over the RenderSurface-Layer tree.
236 struct CC_EXPORT LayerIteratorActions {
237 // Walks layers sorted by z-order from front to back
238 class CC_EXPORT FrontToBack {
239 public:
240 template <typename LayerType,
241 typename LayerList,
242 typename RenderSurfaceType,
243 typename ActionType>
244 void Begin(
245 LayerIterator<LayerType, LayerList, RenderSurfaceType, ActionType>* it);
246
247 template <typename LayerType,
248 typename LayerList,
249 typename RenderSurfaceType,
250 typename ActionType>
251 void End(
252 LayerIterator<LayerType, LayerList, RenderSurfaceType, ActionType>* it);
253
254 template <typename LayerType,
255 typename LayerList,
256 typename RenderSurfaceType,
257 typename ActionType>
258 void Next(
259 LayerIterator<LayerType, LayerList, RenderSurfaceType, ActionType>* it);
260
261 private:
262 template <typename LayerType,
263 typename LayerList,
264 typename RenderSurfaceType,
265 typename ActionType>
266 void GoToHighestInSubtree(
267 LayerIterator<LayerType, LayerList, RenderSurfaceType, ActionType>* it);
268 };
287 }; 269 };
288 270
289 } // namespace cc 271 } // namespace cc
290 272
291 #endif // CC_LAYERS_LAYER_ITERATOR_H_ 273 #endif // CC_LAYERS_LAYER_ITERATOR_H_
OLDNEW
« no previous file with comments | « cc/debug/debug_rect_history.cc ('k') | cc/layers/layer_iterator.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698