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::FrontToBack::Begin(
21 LayerIterator
<LayerType
, LayerList
, RenderSurfaceType
, ActionType
>* it
) {
22 it
->target_render_surface_layer_index_
= 0;
23 it
->current_layer_index_
= it
->target_render_surface_children().size() - 1;
24 GoToHighestInSubtree(it
);
27 template <typename LayerType
,
29 typename RenderSurfaceType
,
31 void LayerIteratorActions::FrontToBack::End(
32 LayerIterator
<LayerType
, LayerList
, RenderSurfaceType
, ActionType
>* it
) {
33 it
->target_render_surface_layer_index_
=
34 LayerIteratorValue::kInvalidTargetRenderSurfaceLayerIndex
;
35 it
->current_layer_index_
= 0;
38 template <typename LayerType
,
40 typename RenderSurfaceType
,
42 void LayerIteratorActions::FrontToBack::Next(
43 LayerIterator
<LayerType
, LayerList
, RenderSurfaceType
, ActionType
>* it
) {
44 // Moves to the previous layer in the current RS layer list.
45 // Then we check if the new current layer has its own RS,
46 // in which case there are things in that RS layer list that are higher,
47 // so we find the highest layer in that subtree.
48 // If we move back past the front of the list,
49 // we jump up to the previous RS layer list, picking up again where we
50 // had previously recursed into the current RS layer list.
52 if (!it
->current_layer_represents_target_render_surface()) {
53 // Subtracting one here will eventually cause the current layer
54 // to become that layer representing the target render surface.
55 --it
->current_layer_index_
;
56 GoToHighestInSubtree(it
);
58 while (it
->current_layer_represents_target_render_surface()) {
59 if (!it
->target_render_surface_layer_index_
) {
61 it
->target_render_surface_layer_index_
=
62 LayerIteratorValue::kInvalidTargetRenderSurfaceLayerIndex
;
63 it
->current_layer_index_
= 0;
66 it
->target_render_surface_layer_index_
= it
->target_render_surface()
67 ->target_render_surface_layer_index_history_
;
68 it
->current_layer_index_
=
69 it
->target_render_surface()->current_layer_index_history_
;
74 template <typename LayerType
,
76 typename RenderSurfaceType
,
78 void LayerIteratorActions::FrontToBack::GoToHighestInSubtree(
79 LayerIterator
<LayerType
, LayerList
, RenderSurfaceType
, ActionType
>* it
) {
80 if (it
->current_layer_represents_target_render_surface())
82 while (it
->current_layer_represents_contributing_render_surface()) {
83 // Save where we were in the current target surface, move to the next one,
84 // and save the target surface that we came from there
85 // so we can go back to it.
86 it
->target_render_surface()->current_layer_index_history_
=
87 it
->current_layer_index_
;
88 int previous_target_render_surface_layer
=
89 it
->target_render_surface_layer_index_
;
91 for (LayerType
* layer
= it
->current_layer();
92 it
->target_render_surface_layer() != layer
;
93 ++it
->target_render_surface_layer_index_
) {
95 it
->current_layer_index_
= it
->target_render_surface_children().size() - 1;
97 it
->target_render_surface()->target_render_surface_layer_index_history_
=
98 previous_target_render_surface_layer
;
102 // Declare each of the above functions for Layer and LayerImpl classes
103 // so that they are linked.
104 template CC_EXPORT
void LayerIteratorActions::FrontToBack::Next(
105 LayerIterator
<Layer
, RenderSurfaceLayerList
, RenderSurface
, FrontToBack
>*
107 template CC_EXPORT
void LayerIteratorActions::FrontToBack::End(
108 LayerIterator
<Layer
, RenderSurfaceLayerList
, RenderSurface
, FrontToBack
>*
110 template CC_EXPORT
void LayerIteratorActions::FrontToBack::Begin(
111 LayerIterator
<Layer
, RenderSurfaceLayerList
, RenderSurface
, FrontToBack
>*
113 template CC_EXPORT
void LayerIteratorActions::FrontToBack::GoToHighestInSubtree(
114 LayerIterator
<Layer
, RenderSurfaceLayerList
, RenderSurface
, FrontToBack
>*
117 template CC_EXPORT
void LayerIteratorActions::FrontToBack::Next(
118 LayerIterator
<LayerImpl
, LayerImplList
, RenderSurfaceImpl
, FrontToBack
>*
120 template CC_EXPORT
void LayerIteratorActions::FrontToBack::End(
121 LayerIterator
<LayerImpl
, LayerImplList
, RenderSurfaceImpl
, FrontToBack
>*
123 template CC_EXPORT
void LayerIteratorActions::FrontToBack::Begin(
124 LayerIterator
<LayerImpl
, LayerImplList
, RenderSurfaceImpl
, FrontToBack
>*
126 template CC_EXPORT
void LayerIteratorActions::FrontToBack::GoToHighestInSubtree(
127 LayerIterator
<LayerImpl
, LayerImplList
, RenderSurfaceImpl
, FrontToBack
>*