Adding a logging class to cast.
[chromium-blink-merge.git] / cc / layers / layer_iterator.cc
bloba52c3f1f39a1b89b71f838ca5d8deab7e20a92c4
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::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,
28 typename LayerList,
29 typename RenderSurfaceType,
30 typename ActionType>
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,
39 typename LayerList,
40 typename RenderSurfaceType,
41 typename ActionType>
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);
57 } else {
58 while (it->current_layer_represents_target_render_surface()) {
59 if (!it->target_render_surface_layer_index_) {
60 // End of the list
61 it->target_render_surface_layer_index_ =
62 LayerIteratorValue::kInvalidTargetRenderSurfaceLayerIndex;
63 it->current_layer_index_ = 0;
64 return;
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,
75 typename LayerList,
76 typename RenderSurfaceType,
77 typename ActionType>
78 void LayerIteratorActions::FrontToBack::GoToHighestInSubtree(
79 LayerIterator<LayerType, LayerList, RenderSurfaceType, ActionType>* it) {
80 if (it->current_layer_represents_target_render_surface())
81 return;
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>*
106 it);
107 template CC_EXPORT void LayerIteratorActions::FrontToBack::End(
108 LayerIterator<Layer, RenderSurfaceLayerList, RenderSurface, FrontToBack>*
109 it);
110 template CC_EXPORT void LayerIteratorActions::FrontToBack::Begin(
111 LayerIterator<Layer, RenderSurfaceLayerList, RenderSurface, FrontToBack>*
112 it);
113 template CC_EXPORT void LayerIteratorActions::FrontToBack::GoToHighestInSubtree(
114 LayerIterator<Layer, RenderSurfaceLayerList, RenderSurface, FrontToBack>*
115 it);
117 template CC_EXPORT void LayerIteratorActions::FrontToBack::Next(
118 LayerIterator<LayerImpl, LayerImplList, RenderSurfaceImpl, FrontToBack>*
119 it);
120 template CC_EXPORT void LayerIteratorActions::FrontToBack::End(
121 LayerIterator<LayerImpl, LayerImplList, RenderSurfaceImpl, FrontToBack>*
122 it);
123 template CC_EXPORT void LayerIteratorActions::FrontToBack::Begin(
124 LayerIterator<LayerImpl, LayerImplList, RenderSurfaceImpl, FrontToBack>*
125 it);
126 template CC_EXPORT void LayerIteratorActions::FrontToBack::GoToHighestInSubtree(
127 LayerIterator<LayerImpl, LayerImplList, RenderSurfaceImpl, FrontToBack>*
128 it);
130 } // namespace cc