WebKit merge 128969:128981
[chromium-blink-merge.git] / cc / CCLayerIterator.cpp
blob65499101c12fa9004e35fcfe7e5a3f414b35f2e5
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 "config.h"
7 #if USE(ACCELERATED_COMPOSITING)
9 #include "CCLayerIterator.h"
11 #include "CCLayerImpl.h"
12 #include "CCRenderSurface.h"
13 #include "LayerChromium.h"
14 #include "RenderSurfaceChromium.h"
16 namespace cc {
18 template <typename LayerType, typename LayerList, typename RenderSurfaceType, typename ActionType>
19 void CCLayerIteratorActions::BackToFront::begin(CCLayerIterator<LayerType, LayerList, RenderSurfaceType, ActionType>& it)
21 it.m_targetRenderSurfaceLayerIndex = 0;
22 it.m_currentLayerIndex = CCLayerIteratorValue::LayerIndexRepresentingTargetRenderSurface;
24 m_highestTargetRenderSurfaceLayer = 0;
27 template <typename LayerType, typename LayerList, typename RenderSurfaceType, typename ActionType>
28 void CCLayerIteratorActions::BackToFront::end(CCLayerIterator<LayerType, LayerList, RenderSurfaceType, ActionType>& it)
30 it.m_targetRenderSurfaceLayerIndex = CCLayerIteratorValue::InvalidTargetRenderSurfaceLayerIndex;
31 it.m_currentLayerIndex = 0;
34 template <typename LayerType, typename LayerList, typename RenderSurfaceType, typename ActionType>
35 void CCLayerIteratorActions::BackToFront::next(CCLayerIterator<LayerType, LayerList, RenderSurfaceType, ActionType>& it)
37 // If the current layer has a RS, move to its layer list. Otherwise, visit the next layer in the current RS layer list.
38 if (it.currentLayerRepresentsContributingRenderSurface()) {
39 // Save our position in the childLayer list for the RenderSurface, then jump to the next RenderSurface. Save where we
40 // came from in the next RenderSurface so we can get back to it.
41 it.targetRenderSurface()->m_currentLayerIndexHistory = it.m_currentLayerIndex;
42 int previousTargetRenderSurfaceLayer = it.m_targetRenderSurfaceLayerIndex;
44 it.m_targetRenderSurfaceLayerIndex = ++m_highestTargetRenderSurfaceLayer;
45 it.m_currentLayerIndex = CCLayerIteratorValue::LayerIndexRepresentingTargetRenderSurface;
47 it.targetRenderSurface()->m_targetRenderSurfaceLayerIndexHistory = previousTargetRenderSurfaceLayer;
48 } else {
49 ++it.m_currentLayerIndex;
51 int targetRenderSurfaceNumChildren = it.targetRenderSurfaceChildren().size();
52 while (it.m_currentLayerIndex == targetRenderSurfaceNumChildren) {
53 // Jump back to the previous RenderSurface, and get back the position where we were in that list, and move to the next position there.
54 if (!it.m_targetRenderSurfaceLayerIndex) {
55 // End of the list
56 it.m_targetRenderSurfaceLayerIndex = CCLayerIteratorValue::InvalidTargetRenderSurfaceLayerIndex;
57 it.m_currentLayerIndex = 0;
58 return;
60 it.m_targetRenderSurfaceLayerIndex = it.targetRenderSurface()->m_targetRenderSurfaceLayerIndexHistory;
61 it.m_currentLayerIndex = it.targetRenderSurface()->m_currentLayerIndexHistory + 1;
63 targetRenderSurfaceNumChildren = it.targetRenderSurfaceChildren().size();
68 template <typename LayerType, typename LayerList, typename RenderSurfaceType, typename ActionType>
69 void CCLayerIteratorActions::FrontToBack::begin(CCLayerIterator<LayerType, LayerList, RenderSurfaceType, ActionType>& it)
71 it.m_targetRenderSurfaceLayerIndex = 0;
72 it.m_currentLayerIndex = it.targetRenderSurfaceChildren().size() - 1;
73 goToHighestInSubtree(it);
76 template <typename LayerType, typename LayerList, typename RenderSurfaceType, typename ActionType>
77 void CCLayerIteratorActions::FrontToBack::end(CCLayerIterator<LayerType, LayerList, RenderSurfaceType, ActionType>& it)
79 it.m_targetRenderSurfaceLayerIndex = CCLayerIteratorValue::InvalidTargetRenderSurfaceLayerIndex;
80 it.m_currentLayerIndex = 0;
83 template <typename LayerType, typename LayerList, typename RenderSurfaceType, typename ActionType>
84 void CCLayerIteratorActions::FrontToBack::next(CCLayerIterator<LayerType, LayerList, RenderSurfaceType, ActionType>& it)
86 // Moves to the previous layer in the current RS layer list. Then we check if the
87 // new current layer has its own RS, in which case there are things in that RS layer list that are higher, so
88 // we find the highest layer in that subtree.
89 // If we move back past the front of the list, we jump up to the previous RS layer list, picking up again where we
90 // had previously recursed into the current RS layer list.
92 if (!it.currentLayerRepresentsTargetRenderSurface()) {
93 // Subtracting one here will eventually cause the current layer to become that layer
94 // representing the target render surface.
95 --it.m_currentLayerIndex;
96 goToHighestInSubtree(it);
97 } else {
98 while (it.currentLayerRepresentsTargetRenderSurface()) {
99 if (!it.m_targetRenderSurfaceLayerIndex) {
100 // End of the list
101 it.m_targetRenderSurfaceLayerIndex = CCLayerIteratorValue::InvalidTargetRenderSurfaceLayerIndex;
102 it.m_currentLayerIndex = 0;
103 return;
105 it.m_targetRenderSurfaceLayerIndex = it.targetRenderSurface()->m_targetRenderSurfaceLayerIndexHistory;
106 it.m_currentLayerIndex = it.targetRenderSurface()->m_currentLayerIndexHistory;
111 template <typename LayerType, typename LayerList, typename RenderSurfaceType, typename ActionType>
112 void CCLayerIteratorActions::FrontToBack::goToHighestInSubtree(CCLayerIterator<LayerType, LayerList, RenderSurfaceType, ActionType>& it)
114 if (it.currentLayerRepresentsTargetRenderSurface())
115 return;
116 while (it.currentLayerRepresentsContributingRenderSurface()) {
117 // Save where we were in the current target surface, move to the next one, and save the target surface that we
118 // came from there so we can go back to it.
119 it.targetRenderSurface()->m_currentLayerIndexHistory = it.m_currentLayerIndex;
120 int previousTargetRenderSurfaceLayer = it.m_targetRenderSurfaceLayerIndex;
122 for (LayerType* layer = it.currentLayer(); it.targetRenderSurfaceLayer() != layer; ++it.m_targetRenderSurfaceLayerIndex) { }
123 it.m_currentLayerIndex = it.targetRenderSurfaceChildren().size() - 1;
125 it.targetRenderSurface()->m_targetRenderSurfaceLayerIndexHistory = previousTargetRenderSurfaceLayer;
129 // Declare each of the above functions for LayerChromium and CCLayerImpl classes so that they are linked.
130 template void CCLayerIteratorActions::BackToFront::begin(CCLayerIterator<LayerChromium, Vector<RefPtr<LayerChromium> >, RenderSurfaceChromium, BackToFront> &);
131 template void CCLayerIteratorActions::BackToFront::end(CCLayerIterator<LayerChromium, Vector<RefPtr<LayerChromium> >, RenderSurfaceChromium, BackToFront>&);
132 template void CCLayerIteratorActions::BackToFront::next(CCLayerIterator<LayerChromium, Vector<RefPtr<LayerChromium> >, RenderSurfaceChromium, BackToFront>&);
134 template void CCLayerIteratorActions::BackToFront::begin(CCLayerIterator<CCLayerImpl, Vector<CCLayerImpl*>, CCRenderSurface, BackToFront>&);
135 template void CCLayerIteratorActions::BackToFront::end(CCLayerIterator<CCLayerImpl, Vector<CCLayerImpl*>, CCRenderSurface, BackToFront>&);
136 template void CCLayerIteratorActions::BackToFront::next(CCLayerIterator<CCLayerImpl, Vector<CCLayerImpl*>, CCRenderSurface, BackToFront>&);
138 template void CCLayerIteratorActions::FrontToBack::next(CCLayerIterator<LayerChromium, Vector<RefPtr<LayerChromium> >, RenderSurfaceChromium, FrontToBack>&);
139 template void CCLayerIteratorActions::FrontToBack::end(CCLayerIterator<LayerChromium, Vector<RefPtr<LayerChromium> >, RenderSurfaceChromium, FrontToBack>&);
140 template void CCLayerIteratorActions::FrontToBack::begin(CCLayerIterator<LayerChromium, Vector<RefPtr<LayerChromium> >, RenderSurfaceChromium, FrontToBack>&);
141 template void CCLayerIteratorActions::FrontToBack::goToHighestInSubtree(CCLayerIterator<LayerChromium, Vector<RefPtr<LayerChromium> >, RenderSurfaceChromium, FrontToBack>&);
143 template void CCLayerIteratorActions::FrontToBack::next(CCLayerIterator<CCLayerImpl, Vector<CCLayerImpl*>, CCRenderSurface, FrontToBack>&);
144 template void CCLayerIteratorActions::FrontToBack::end(CCLayerIterator<CCLayerImpl, Vector<CCLayerImpl*>, CCRenderSurface, FrontToBack>&);
145 template void CCLayerIteratorActions::FrontToBack::begin(CCLayerIterator<CCLayerImpl, Vector<CCLayerImpl*>, CCRenderSurface, FrontToBack>&);
146 template void CCLayerIteratorActions::FrontToBack::goToHighestInSubtree(CCLayerIterator<CCLayerImpl, Vector<CCLayerImpl*>, CCRenderSurface, FrontToBack>&);
148 } // namespace cc
150 #endif // USE(ACCELERATED_COMPOSITING)