Add missing OWNERS for chrome_android.gypi
[chromium-blink-merge.git] / cc / layers / layer_iterator.cc
blobc33e7536ec0ab729cbefa948a78638bd955486fb
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
3 // found in the LICENSE file.
5 #include "cc/layers/layer_iterator.h"
7 #include <vector>
9 #include "cc/layers/layer.h"
10 #include "cc/layers/layer_impl.h"
11 #include "cc/layers/render_surface.h"
12 #include "cc/layers/render_surface_impl.h"
14 namespace cc {
16 template <typename LayerType,
17 typename LayerList,
18 typename RenderSurfaceType,
19 typename ActionType>
20 void LayerIteratorActions::BackToFront::Begin(
21 LayerIterator<LayerType, LayerList, RenderSurfaceType, ActionType>* it) {
22 it->target_render_surface_layer_index_ = 0;
23 it->current_layer_index_ =
24 LayerIteratorValue::kLayerIndexRepresentingTargetRenderSurface;
26 highest_target_render_surface_layer_ = 0;
29 template <typename LayerType,
30 typename LayerList,
31 typename RenderSurfaceType,
32 typename ActionType>
33 void LayerIteratorActions::BackToFront::End(
34 LayerIterator<LayerType, LayerList, RenderSurfaceType, ActionType>* it) {
35 it->target_render_surface_layer_index_ =
36 LayerIteratorValue::kInvalidTargetRenderSurfaceLayerIndex;
37 it->current_layer_index_ = 0;
40 template <typename LayerType,
41 typename LayerList,
42 typename RenderSurfaceType,
43 typename ActionType>
44 void LayerIteratorActions::BackToFront::Next(
45 LayerIterator<LayerType, LayerList, RenderSurfaceType, ActionType>* it) {
46 // If the current layer has a RS, move to its layer list. Otherwise,
47 // visit the next layer in the current RS layer list.
48 if (it->current_layer_represents_contributing_render_surface()) {
49 // Save our position in the child_layers list for the RenderSurface,
50 // then jump to the next RenderSurface. Save where we
51 // came from in the next RenderSurface so we can get back to it.
52 it->target_render_surface()->current_layer_index_history_ =
53 it->current_layer_index_;
54 int previous_target_render_surface_layer =
55 it->target_render_surface_layer_index_;
57 it->target_render_surface_layer_index_ =
58 ++highest_target_render_surface_layer_;
59 it->current_layer_index_ =
60 LayerIteratorValue::kLayerIndexRepresentingTargetRenderSurface;
62 it->target_render_surface()->target_render_surface_layer_index_history_ =
63 previous_target_render_surface_layer;
64 } else {
65 ++it->current_layer_index_;
67 int target_render_surface_num_children =
68 it->target_render_surface_children().size();
69 while (it->current_layer_index_ == target_render_surface_num_children) {
70 // Jump back to the previous RenderSurface,
71 // and get back the position where we were in that list,
72 // and move to the next position there.
73 if (!it->target_render_surface_layer_index_) {
74 // End of the list
75 it->target_render_surface_layer_index_ =
76 LayerIteratorValue::kInvalidTargetRenderSurfaceLayerIndex;
77 it->current_layer_index_ = 0;
78 return;
80 it->target_render_surface_layer_index_ = it->target_render_surface()
81 ->target_render_surface_layer_index_history_;
82 it->current_layer_index_ =
83 it->target_render_surface()->current_layer_index_history_ + 1;
85 target_render_surface_num_children =
86 it->target_render_surface_children().size();
91 template <typename LayerType,
92 typename LayerList,
93 typename RenderSurfaceType,
94 typename ActionType>
95 void LayerIteratorActions::FrontToBack::Begin(
96 LayerIterator<LayerType, LayerList, RenderSurfaceType, ActionType>* it) {
97 it->target_render_surface_layer_index_ = 0;
98 it->current_layer_index_ = it->target_render_surface_children().size() - 1;
99 GoToHighestInSubtree(it);
102 template <typename LayerType,
103 typename LayerList,
104 typename RenderSurfaceType,
105 typename ActionType>
106 void LayerIteratorActions::FrontToBack::End(
107 LayerIterator<LayerType, LayerList, RenderSurfaceType, ActionType>* it) {
108 it->target_render_surface_layer_index_ =
109 LayerIteratorValue::kInvalidTargetRenderSurfaceLayerIndex;
110 it->current_layer_index_ = 0;
113 template <typename LayerType,
114 typename LayerList,
115 typename RenderSurfaceType,
116 typename ActionType>
117 void LayerIteratorActions::FrontToBack::Next(
118 LayerIterator<LayerType, LayerList, RenderSurfaceType, ActionType>* it) {
119 // Moves to the previous layer in the current RS layer list.
120 // Then we check if the new current layer has its own RS,
121 // in which case there are things in that RS layer list that are higher,
122 // so we find the highest layer in that subtree.
123 // If we move back past the front of the list,
124 // we jump up to the previous RS layer list, picking up again where we
125 // had previously recursed into the current RS layer list.
127 if (!it->current_layer_represents_target_render_surface()) {
128 // Subtracting one here will eventually cause the current layer
129 // to become that layer representing the target render surface.
130 --it->current_layer_index_;
131 GoToHighestInSubtree(it);
132 } else {
133 while (it->current_layer_represents_target_render_surface()) {
134 if (!it->target_render_surface_layer_index_) {
135 // End of the list
136 it->target_render_surface_layer_index_ =
137 LayerIteratorValue::kInvalidTargetRenderSurfaceLayerIndex;
138 it->current_layer_index_ = 0;
139 return;
141 it->target_render_surface_layer_index_ = it->target_render_surface()
142 ->target_render_surface_layer_index_history_;
143 it->current_layer_index_ =
144 it->target_render_surface()->current_layer_index_history_;
149 template <typename LayerType,
150 typename LayerList,
151 typename RenderSurfaceType,
152 typename ActionType>
153 void LayerIteratorActions::FrontToBack::GoToHighestInSubtree(
154 LayerIterator<LayerType, LayerList, RenderSurfaceType, ActionType>* it) {
155 if (it->current_layer_represents_target_render_surface())
156 return;
157 while (it->current_layer_represents_contributing_render_surface()) {
158 // Save where we were in the current target surface, move to the next one,
159 // and save the target surface that we came from there
160 // so we can go back to it.
161 it->target_render_surface()->current_layer_index_history_ =
162 it->current_layer_index_;
163 int previous_target_render_surface_layer =
164 it->target_render_surface_layer_index_;
166 for (LayerType* layer = it->current_layer();
167 it->target_render_surface_layer() != layer;
168 ++it->target_render_surface_layer_index_) {
170 it->current_layer_index_ = it->target_render_surface_children().size() - 1;
172 it->target_render_surface()->target_render_surface_layer_index_history_ =
173 previous_target_render_surface_layer;
177 // Declare each of the above functions for Layer and LayerImpl classes
178 // so that they are linked.
179 template CC_EXPORT void LayerIteratorActions::BackToFront::Begin(
180 LayerIterator<Layer, RenderSurfaceLayerList, RenderSurface, BackToFront>*
181 it);
182 template CC_EXPORT void LayerIteratorActions::BackToFront::End(
183 LayerIterator<Layer, RenderSurfaceLayerList, RenderSurface, BackToFront>*
184 it);
185 template CC_EXPORT void LayerIteratorActions::BackToFront::Next(
186 LayerIterator<Layer, RenderSurfaceLayerList, RenderSurface, BackToFront>*
187 it);
189 template CC_EXPORT void LayerIteratorActions::BackToFront::Begin(
190 LayerIterator<LayerImpl, LayerImplList, RenderSurfaceImpl, BackToFront>*
191 it);
192 template CC_EXPORT void LayerIteratorActions::BackToFront::End(
193 LayerIterator<LayerImpl, LayerImplList, RenderSurfaceImpl, BackToFront>*
194 it);
195 template CC_EXPORT void LayerIteratorActions::BackToFront::Next(
196 LayerIterator<LayerImpl, LayerImplList, RenderSurfaceImpl, BackToFront>*
197 it);
199 template CC_EXPORT void LayerIteratorActions::FrontToBack::Next(
200 LayerIterator<Layer, RenderSurfaceLayerList, RenderSurface, FrontToBack>*
201 it);
202 template CC_EXPORT void LayerIteratorActions::FrontToBack::End(
203 LayerIterator<Layer, RenderSurfaceLayerList, RenderSurface, FrontToBack>*
204 it);
205 template CC_EXPORT void LayerIteratorActions::FrontToBack::Begin(
206 LayerIterator<Layer, RenderSurfaceLayerList, RenderSurface, FrontToBack>*
207 it);
208 template CC_EXPORT void LayerIteratorActions::FrontToBack::GoToHighestInSubtree(
209 LayerIterator<Layer, RenderSurfaceLayerList, RenderSurface, FrontToBack>*
210 it);
212 template CC_EXPORT void LayerIteratorActions::FrontToBack::Next(
213 LayerIterator<LayerImpl, LayerImplList, RenderSurfaceImpl, FrontToBack>*
214 it);
215 template CC_EXPORT void LayerIteratorActions::FrontToBack::End(
216 LayerIterator<LayerImpl, LayerImplList, RenderSurfaceImpl, FrontToBack>*
217 it);
218 template CC_EXPORT void LayerIteratorActions::FrontToBack::Begin(
219 LayerIterator<LayerImpl, LayerImplList, RenderSurfaceImpl, FrontToBack>*
220 it);
221 template CC_EXPORT void LayerIteratorActions::FrontToBack::GoToHighestInSubtree(
222 LayerIterator<LayerImpl, LayerImplList, RenderSurfaceImpl, FrontToBack>*
223 it);
225 } // namespace cc