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"
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"
16 template <typename LayerType
,
18 typename RenderSurfaceType
,
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
,
31 typename RenderSurfaceType
,
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
,
42 typename RenderSurfaceType
,
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
;
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_
) {
75 it
->target_render_surface_layer_index_
=
76 LayerIteratorValue::kInvalidTargetRenderSurfaceLayerIndex
;
77 it
->current_layer_index_
= 0;
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
,
93 typename RenderSurfaceType
,
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
,
104 typename RenderSurfaceType
,
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
,
115 typename RenderSurfaceType
,
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
);
133 while (it
->current_layer_represents_target_render_surface()) {
134 if (!it
->target_render_surface_layer_index_
) {
136 it
->target_render_surface_layer_index_
=
137 LayerIteratorValue::kInvalidTargetRenderSurfaceLayerIndex
;
138 it
->current_layer_index_
= 0;
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
,
151 typename RenderSurfaceType
,
153 void LayerIteratorActions::FrontToBack::GoToHighestInSubtree(
154 LayerIterator
<LayerType
, LayerList
, RenderSurfaceType
, ActionType
>* it
) {
155 if (it
->current_layer_represents_target_render_surface())
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
>*
182 template CC_EXPORT
void LayerIteratorActions::BackToFront::End(
183 LayerIterator
<Layer
, RenderSurfaceLayerList
, RenderSurface
, BackToFront
>*
185 template CC_EXPORT
void LayerIteratorActions::BackToFront::Next(
186 LayerIterator
<Layer
, RenderSurfaceLayerList
, RenderSurface
, BackToFront
>*
189 template CC_EXPORT
void LayerIteratorActions::BackToFront::Begin(
190 LayerIterator
<LayerImpl
, LayerImplList
, RenderSurfaceImpl
, BackToFront
>*
192 template CC_EXPORT
void LayerIteratorActions::BackToFront::End(
193 LayerIterator
<LayerImpl
, LayerImplList
, RenderSurfaceImpl
, BackToFront
>*
195 template CC_EXPORT
void LayerIteratorActions::BackToFront::Next(
196 LayerIterator
<LayerImpl
, LayerImplList
, RenderSurfaceImpl
, BackToFront
>*
199 template CC_EXPORT
void LayerIteratorActions::FrontToBack::Next(
200 LayerIterator
<Layer
, RenderSurfaceLayerList
, RenderSurface
, FrontToBack
>*
202 template CC_EXPORT
void LayerIteratorActions::FrontToBack::End(
203 LayerIterator
<Layer
, RenderSurfaceLayerList
, RenderSurface
, FrontToBack
>*
205 template CC_EXPORT
void LayerIteratorActions::FrontToBack::Begin(
206 LayerIterator
<Layer
, RenderSurfaceLayerList
, RenderSurface
, FrontToBack
>*
208 template CC_EXPORT
void LayerIteratorActions::FrontToBack::GoToHighestInSubtree(
209 LayerIterator
<Layer
, RenderSurfaceLayerList
, RenderSurface
, FrontToBack
>*
212 template CC_EXPORT
void LayerIteratorActions::FrontToBack::Next(
213 LayerIterator
<LayerImpl
, LayerImplList
, RenderSurfaceImpl
, FrontToBack
>*
215 template CC_EXPORT
void LayerIteratorActions::FrontToBack::End(
216 LayerIterator
<LayerImpl
, LayerImplList
, RenderSurfaceImpl
, FrontToBack
>*
218 template CC_EXPORT
void LayerIteratorActions::FrontToBack::Begin(
219 LayerIterator
<LayerImpl
, LayerImplList
, RenderSurfaceImpl
, FrontToBack
>*
221 template CC_EXPORT
void LayerIteratorActions::FrontToBack::GoToHighestInSubtree(
222 LayerIterator
<LayerImpl
, LayerImplList
, RenderSurfaceImpl
, FrontToBack
>*