diff options
Diffstat (limited to 'cc/layers')
-rw-r--r-- | cc/layers/layer_iterator.cc | 296 | ||||
-rw-r--r-- | cc/layers/layer_iterator.h | 430 | ||||
-rw-r--r-- | cc/layers/layer_iterator_unittest.cc | 449 |
3 files changed, 688 insertions, 487 deletions
diff --git a/cc/layers/layer_iterator.cc b/cc/layers/layer_iterator.cc index 58a9175..02634bd 100644 --- a/cc/layers/layer_iterator.cc +++ b/cc/layers/layer_iterator.cc @@ -11,137 +11,209 @@ namespace cc { -template <typename LayerType, typename LayerList, typename RenderSurfaceType, typename ActionType> -void LayerIteratorActions::BackToFront::begin(LayerIterator<LayerType, LayerList, RenderSurfaceType, ActionType>& it) -{ - it.m_targetRenderSurfaceLayerIndex = 0; - it.m_currentLayerIndex = LayerIteratorValue::LayerIndexRepresentingTargetRenderSurface; - - m_highestTargetRenderSurfaceLayer = 0; +template <typename LayerType, + typename LayerList, + typename RenderSurfaceType, + typename ActionType> +void LayerIteratorActions::BackToFront::Begin( + LayerIterator<LayerType, LayerList, RenderSurfaceType, ActionType>* it) { + it->target_render_surface_layer_index_ = 0; + it->current_layer_index_ = + LayerIteratorValue::kLayerIndexRepresentingTargetRenderSurface; + + highest_target_render_surface_layer_ = 0; } -template <typename LayerType, typename LayerList, typename RenderSurfaceType, typename ActionType> -void LayerIteratorActions::BackToFront::end(LayerIterator<LayerType, LayerList, RenderSurfaceType, ActionType>& it) -{ - it.m_targetRenderSurfaceLayerIndex = LayerIteratorValue::InvalidTargetRenderSurfaceLayerIndex; - it.m_currentLayerIndex = 0; +template <typename LayerType, + typename LayerList, + typename RenderSurfaceType, + typename ActionType> +void LayerIteratorActions::BackToFront::End( + LayerIterator<LayerType, LayerList, RenderSurfaceType, ActionType>* it) { + it->target_render_surface_layer_index_ = + LayerIteratorValue::kInvalidTargetRenderSurfaceLayerIndex; + it->current_layer_index_ = 0; } -template <typename LayerType, typename LayerList, typename RenderSurfaceType, typename ActionType> -void LayerIteratorActions::BackToFront::next(LayerIterator<LayerType, LayerList, RenderSurfaceType, ActionType>& it) -{ - // If the current layer has a RS, move to its layer list. Otherwise, visit the next layer in the current RS layer list. - if (it.currentLayerRepresentsContributingRenderSurface()) { - // Save our position in the childLayer list for the RenderSurfaceImpl, then jump to the next RenderSurfaceImpl. Save where we - // came from in the next RenderSurfaceImpl so we can get back to it. - it.targetRenderSurface()->current_layer_index_history_ = it.m_currentLayerIndex; - int previousTargetRenderSurfaceLayer = it.m_targetRenderSurfaceLayerIndex; - - it.m_targetRenderSurfaceLayerIndex = ++m_highestTargetRenderSurfaceLayer; - it.m_currentLayerIndex = LayerIteratorValue::LayerIndexRepresentingTargetRenderSurface; - - it.targetRenderSurface()->target_render_surface_layer_index_history_ = previousTargetRenderSurfaceLayer; - } else { - ++it.m_currentLayerIndex; - - int targetRenderSurfaceNumChildren = it.targetRenderSurfaceChildren().size(); - while (it.m_currentLayerIndex == targetRenderSurfaceNumChildren) { - // Jump back to the previous RenderSurfaceImpl, and get back the position where we were in that list, and move to the next position there. - if (!it.m_targetRenderSurfaceLayerIndex) { - // End of the list - it.m_targetRenderSurfaceLayerIndex = LayerIteratorValue::InvalidTargetRenderSurfaceLayerIndex; - it.m_currentLayerIndex = 0; - return; - } - it.m_targetRenderSurfaceLayerIndex = it.targetRenderSurface()->target_render_surface_layer_index_history_; - it.m_currentLayerIndex = it.targetRenderSurface()->current_layer_index_history_ + 1; - - targetRenderSurfaceNumChildren = it.targetRenderSurfaceChildren().size(); - } +template <typename LayerType, + typename LayerList, + typename RenderSurfaceType, + typename ActionType> +void LayerIteratorActions::BackToFront::Next( + LayerIterator<LayerType, LayerList, RenderSurfaceType, ActionType>* it) { + // If the current layer has a RS, move to its layer list. Otherwise, + // visit the next layer in the current RS layer list. + if (it->current_layer_represents_contributing_render_surface()) { + // Save our position in the childLayer list for the RenderSurface, + // then jump to the next RenderSurface. Save where we + // came from in the next RenderSurface so we can get back to it. + it->target_render_surface()->current_layer_index_history_ = + it->current_layer_index_; + int previous_target_render_surface_layer = + it->target_render_surface_layer_index_; + + it->target_render_surface_layer_index_ = + ++highest_target_render_surface_layer_; + it->current_layer_index_ = + LayerIteratorValue::kLayerIndexRepresentingTargetRenderSurface; + + it->target_render_surface()->target_render_surface_layer_index_history_ = + previous_target_render_surface_layer; + } else { + ++it->current_layer_index_; + + int target_render_surface_num_children = + it->target_render_surface_children().size(); + while (it->current_layer_index_ == target_render_surface_num_children) { + // Jump back to the previous RenderSurface, + // and get back the position where we were in that list, + // and move to the next position there. + if (!it->target_render_surface_layer_index_) { + // End of the list + it->target_render_surface_layer_index_ = + LayerIteratorValue::kInvalidTargetRenderSurfaceLayerIndex; + it->current_layer_index_ = 0; + return; + } + it->target_render_surface_layer_index_ = it->target_render_surface() + ->target_render_surface_layer_index_history_; + it->current_layer_index_ = + it->target_render_surface()->current_layer_index_history_ + 1; + + target_render_surface_num_children = + it->target_render_surface_children().size(); } + } } -template <typename LayerType, typename LayerList, typename RenderSurfaceType, typename ActionType> -void LayerIteratorActions::FrontToBack::begin(LayerIterator<LayerType, LayerList, RenderSurfaceType, ActionType>& it) -{ - it.m_targetRenderSurfaceLayerIndex = 0; - it.m_currentLayerIndex = it.targetRenderSurfaceChildren().size() - 1; - goToHighestInSubtree(it); +template <typename LayerType, + typename LayerList, + typename RenderSurfaceType, + typename ActionType> +void LayerIteratorActions::FrontToBack::Begin( + LayerIterator<LayerType, LayerList, RenderSurfaceType, ActionType>* it) { + it->target_render_surface_layer_index_ = 0; + it->current_layer_index_ = it->target_render_surface_children().size() - 1; + GoToHighestInSubtree(it); } -template <typename LayerType, typename LayerList, typename RenderSurfaceType, typename ActionType> -void LayerIteratorActions::FrontToBack::end(LayerIterator<LayerType, LayerList, RenderSurfaceType, ActionType>& it) -{ - it.m_targetRenderSurfaceLayerIndex = LayerIteratorValue::InvalidTargetRenderSurfaceLayerIndex; - it.m_currentLayerIndex = 0; +template <typename LayerType, + typename LayerList, + typename RenderSurfaceType, + typename ActionType> +void LayerIteratorActions::FrontToBack::End( + LayerIterator<LayerType, LayerList, RenderSurfaceType, ActionType>* it) { + it->target_render_surface_layer_index_ = + LayerIteratorValue::kInvalidTargetRenderSurfaceLayerIndex; + it->current_layer_index_ = 0; } -template <typename LayerType, typename LayerList, typename RenderSurfaceType, typename ActionType> -void LayerIteratorActions::FrontToBack::next(LayerIterator<LayerType, LayerList, RenderSurfaceType, ActionType>& it) -{ - // Moves to the previous layer in the current RS layer list. Then we check if the - // new current layer has its own RS, in which case there are things in that RS layer list that are higher, so - // we find the highest layer in that subtree. - // If we move back past the front of the list, we jump up to the previous RS layer list, picking up again where we - // had previously recursed into the current RS layer list. - - if (!it.currentLayerRepresentsTargetRenderSurface()) { - // Subtracting one here will eventually cause the current layer to become that layer - // representing the target render surface. - --it.m_currentLayerIndex; - goToHighestInSubtree(it); - } else { - while (it.currentLayerRepresentsTargetRenderSurface()) { - if (!it.m_targetRenderSurfaceLayerIndex) { - // End of the list - it.m_targetRenderSurfaceLayerIndex = LayerIteratorValue::InvalidTargetRenderSurfaceLayerIndex; - it.m_currentLayerIndex = 0; - return; - } - it.m_targetRenderSurfaceLayerIndex = it.targetRenderSurface()->target_render_surface_layer_index_history_; - it.m_currentLayerIndex = it.targetRenderSurface()->current_layer_index_history_; - } +template <typename LayerType, + typename LayerList, + typename RenderSurfaceType, + typename ActionType> +void LayerIteratorActions::FrontToBack::Next( + LayerIterator<LayerType, LayerList, RenderSurfaceType, ActionType>* it) { + // Moves to the previous layer in the current RS layer list. + // Then we check if the new current layer has its own RS, + // in which case there are things in that RS layer list that are higher, + // so we find the highest layer in that subtree. + // If we move back past the front of the list, + // we jump up to the previous RS layer list, picking up again where we + // had previously recursed into the current RS layer list. + + if (!it->current_layer_represents_target_render_surface()) { + // Subtracting one here will eventually cause the current layer + // to become that layer representing the target render surface. + --it->current_layer_index_; + GoToHighestInSubtree(it); + } else { + while (it->current_layer_represents_target_render_surface()) { + if (!it->target_render_surface_layer_index_) { + // End of the list + it->target_render_surface_layer_index_ = + LayerIteratorValue::kInvalidTargetRenderSurfaceLayerIndex; + it->current_layer_index_ = 0; + return; + } + it->target_render_surface_layer_index_ = it->target_render_surface() + ->target_render_surface_layer_index_history_; + it->current_layer_index_ = + it->target_render_surface()->current_layer_index_history_; } + } } -template <typename LayerType, typename LayerList, typename RenderSurfaceType, typename ActionType> -void LayerIteratorActions::FrontToBack::goToHighestInSubtree(LayerIterator<LayerType, LayerList, RenderSurfaceType, ActionType>& it) -{ - if (it.currentLayerRepresentsTargetRenderSurface()) - return; - while (it.currentLayerRepresentsContributingRenderSurface()) { - // Save where we were in the current target surface, move to the next one, and save the target surface that we - // came from there so we can go back to it. - it.targetRenderSurface()->current_layer_index_history_ = it.m_currentLayerIndex; - int previousTargetRenderSurfaceLayer = it.m_targetRenderSurfaceLayerIndex; - - for (LayerType* layer = it.currentLayer(); it.targetRenderSurfaceLayer() != layer; ++it.m_targetRenderSurfaceLayerIndex) { } - it.m_currentLayerIndex = it.targetRenderSurfaceChildren().size() - 1; - - it.targetRenderSurface()->target_render_surface_layer_index_history_ = previousTargetRenderSurfaceLayer; +template <typename LayerType, + typename LayerList, + typename RenderSurfaceType, + typename ActionType> +void LayerIteratorActions::FrontToBack::GoToHighestInSubtree( + LayerIterator<LayerType, LayerList, RenderSurfaceType, ActionType>* it) { + if (it->current_layer_represents_target_render_surface()) + return; + while (it->current_layer_represents_contributing_render_surface()) { + // Save where we were in the current target surface, move to the next one, + // and save the target surface that we came from there + // so we can go back to it. + it->target_render_surface()->current_layer_index_history_ = + it->current_layer_index_; + int previous_target_render_surface_layer = + it->target_render_surface_layer_index_; + + for (LayerType* layer = it->current_layer(); + it->target_render_surface_layer() != layer; + ++it->target_render_surface_layer_index_) { } + it->current_layer_index_ = it->target_render_surface_children().size() - 1; + + it->target_render_surface()->target_render_surface_layer_index_history_ = + previous_target_render_surface_layer; + } } typedef std::vector<scoped_refptr<Layer> > LayerList; typedef std::vector<LayerImpl*> LayerImplList; -// Declare each of the above functions for Layer and LayerImpl classes so that they are linked. -template CC_EXPORT void LayerIteratorActions::BackToFront::begin(LayerIterator<Layer, LayerList, RenderSurface, BackToFront> &); -template CC_EXPORT void LayerIteratorActions::BackToFront::end(LayerIterator<Layer, LayerList, RenderSurface, BackToFront>&); -template CC_EXPORT void LayerIteratorActions::BackToFront::next(LayerIterator<Layer, LayerList, RenderSurface, BackToFront>&); - -template CC_EXPORT void LayerIteratorActions::BackToFront::begin(LayerIterator<LayerImpl, LayerImplList, RenderSurfaceImpl, BackToFront>&); -template CC_EXPORT void LayerIteratorActions::BackToFront::end(LayerIterator<LayerImpl, LayerImplList, RenderSurfaceImpl, BackToFront>&); -template CC_EXPORT void LayerIteratorActions::BackToFront::next(LayerIterator<LayerImpl, LayerImplList, RenderSurfaceImpl, BackToFront>&); - -template CC_EXPORT void LayerIteratorActions::FrontToBack::next(LayerIterator<Layer, LayerList, RenderSurface, FrontToBack>&); -template CC_EXPORT void LayerIteratorActions::FrontToBack::end(LayerIterator<Layer, LayerList, RenderSurface, FrontToBack>&); -template CC_EXPORT void LayerIteratorActions::FrontToBack::begin(LayerIterator<Layer, LayerList, RenderSurface, FrontToBack>&); -template CC_EXPORT void LayerIteratorActions::FrontToBack::goToHighestInSubtree(LayerIterator<Layer, LayerList, RenderSurface, FrontToBack>&); - -template CC_EXPORT void LayerIteratorActions::FrontToBack::next(LayerIterator<LayerImpl, LayerImplList, RenderSurfaceImpl, FrontToBack>&); -template CC_EXPORT void LayerIteratorActions::FrontToBack::end(LayerIterator<LayerImpl, LayerImplList, RenderSurfaceImpl, FrontToBack>&); -template CC_EXPORT void LayerIteratorActions::FrontToBack::begin(LayerIterator<LayerImpl, LayerImplList, RenderSurfaceImpl, FrontToBack>&); -template CC_EXPORT void LayerIteratorActions::FrontToBack::goToHighestInSubtree(LayerIterator<LayerImpl, LayerImplList, RenderSurfaceImpl, FrontToBack>&); +// Declare each of the above functions for Layer and LayerImpl classes +// so that they are linked. +template CC_EXPORT void LayerIteratorActions::BackToFront::Begin( + LayerIterator<Layer, LayerList, RenderSurface, BackToFront>* it); +template CC_EXPORT void LayerIteratorActions::BackToFront::End( + LayerIterator<Layer, LayerList, RenderSurface, BackToFront>* it); +template CC_EXPORT void LayerIteratorActions::BackToFront::Next( + LayerIterator<Layer, LayerList, RenderSurface, BackToFront>* it); + +template CC_EXPORT void LayerIteratorActions::BackToFront::Begin( + LayerIterator<LayerImpl, LayerImplList, RenderSurfaceImpl, BackToFront>* + it); +template CC_EXPORT void LayerIteratorActions::BackToFront::End( + LayerIterator<LayerImpl, LayerImplList, RenderSurfaceImpl, BackToFront>* + it); +template CC_EXPORT void LayerIteratorActions::BackToFront::Next( + LayerIterator<LayerImpl, LayerImplList, RenderSurfaceImpl, BackToFront>* + it); + +template CC_EXPORT void LayerIteratorActions::FrontToBack::Next( + LayerIterator<Layer, LayerList, RenderSurface, FrontToBack>* it); +template CC_EXPORT void LayerIteratorActions::FrontToBack::End( + LayerIterator<Layer, LayerList, RenderSurface, FrontToBack>* it); +template CC_EXPORT void LayerIteratorActions::FrontToBack::Begin( + LayerIterator<Layer, LayerList, RenderSurface, FrontToBack>* it); +template CC_EXPORT void LayerIteratorActions::FrontToBack::GoToHighestInSubtree( + LayerIterator<Layer, LayerList, RenderSurface, FrontToBack>* it); + +template CC_EXPORT void LayerIteratorActions::FrontToBack::Next( + LayerIterator<LayerImpl, LayerImplList, RenderSurfaceImpl, FrontToBack>* + it); +template CC_EXPORT void LayerIteratorActions::FrontToBack::End( + LayerIterator<LayerImpl, LayerImplList, RenderSurfaceImpl, FrontToBack>* + it); +template CC_EXPORT void LayerIteratorActions::FrontToBack::Begin( + LayerIterator<LayerImpl, LayerImplList, RenderSurfaceImpl, FrontToBack>* + it); +template CC_EXPORT void LayerIteratorActions::FrontToBack::GoToHighestInSubtree( + LayerIterator<LayerImpl, LayerImplList, RenderSurfaceImpl, FrontToBack>* + it); } // namespace cc diff --git a/cc/layers/layer_iterator.h b/cc/layers/layer_iterator.h index 55b1d79..e13204b 100644 --- a/cc/layers/layer_iterator.h +++ b/cc/layers/layer_iterator.h @@ -11,198 +11,300 @@ namespace cc { -// These classes provide means to iterate over the RenderSurfaceImpl-Layer tree. +// These classes provide means to iterate over the +// RenderSurface-Layer tree. -// Example code follows, for a tree of Layer/RenderSurface objects. See below for details. +// Example code follows, for a tree of Layer/RenderSurface objects. +// See below for details. // -// void doStuffOnLayers(const std::vector<scoped_refptr<Layer> >& renderSurfaceLayerList) -// { -// typedef LayerIterator<Layer, RenderSurface, LayerIteratorActions::FrontToBack> LayerIteratorType; +// void DoStuffOnLayers( +// const std::vector<scoped_refptr<Layer> >& render_surface_layer_list) { +// typedef LayerIterator<Layer, +// RenderSurface, +// LayerIteratorActions::FrontToBack> +// LayerIteratorType; // -// LayerIteratorType end = LayerIteratorType::end(&renderSurfaceLayerList); -// for (LayerIteratorType it = LayerIteratorType::begin(&renderSurfaceLayerList); it != end; ++it) { -// // Only one of these will be true -// if (it.representsTargetRenderSurface()) -// foo(*it); // *it is a layer representing a target RenderSurfaceImpl -// if (it.representsContributingRenderSurface()) -// bar(*it); // *it is a layer representing a RenderSurfaceImpl that contributes to the layer's target RenderSurfaceImpl -// if (it.representsItself()) -// baz(*it); // *it is a layer representing itself, as it contributes to its own target RenderSurfaceImpl -// } +// LayerIteratorType end = +// LayerIteratorType::End(&render_surface_layer_list); +// for (LayerIteratorType +// it = LayerIteratorType::Begin(&render_surface_layer_list); +// it != end; +// ++it) { +// // Only one of these will be true +// if (it.represents_target_render_surface()) +// foo(*it); // *it is a layer representing a target RenderSurface +// if (it.represents_contributing_render_surface()) +// bar(*it); // *it is a layer representing a RenderSurface that +// // contributes to the layer's target RenderSurface +// if (it.represents_itself()) +// baz(*it); // *it is a layer representing itself, +// // as it contributes to its own target RenderSurface +// } // } -// A RenderSurfaceImpl R may be referred to in one of two different contexts. One RenderSurfaceImpl is "current" at any time, for -// whatever operation is being performed. This current surface is referred to as a target surface. For example, when R is -// being painted it would be the target surface. Once R has been painted, its contents may be included into another -// surface S. While S is considered the target surface when it is being painted, R is called a contributing surface -// in this context as it contributes to the content of the target surface S. +// A RenderSurface R may be referred to in one of two different contexts. +// One RenderSurface is "current" at any time, for whatever operation +// is being performed. This current surface is referred to as a target surface. +// For example, when R is being painted it would be the target surface. +// Once R has been painted, its contents may be included into another +// surface S. While S is considered the target surface when it is being +// painted, R is called a contributing surface in this context as it +// contributes to the content of the target surface S. // -// The iterator's current position in the tree always points to some layer. The state of the iterator indicates the role of the -// layer, and will be one of the following three states. A single layer L will appear in the iteration process in at least one, +// The iterator's current position in the tree always points to some layer. +// The state of the iterator indicates the role of the layer, +// and will be one of the following three states. +// A single layer L will appear in the iteration process in at least one, // and possibly all, of these states. -// 1. Representing the target surface: The iterator in this state, pointing at layer L, indicates that the target RenderSurfaceImpl -// is now the surface owned by L. This will occur exactly once for each RenderSurfaceImpl in the tree. -// 2. Representing a contributing surface: The iterator in this state, pointing at layer L, refers to the RenderSurfaceImpl owned -// by L as a contributing surface, without changing the current target RenderSurfaceImpl. -// 3. Representing itself: The iterator in this state, pointing at layer L, refers to the layer itself, as a child of the -// current target RenderSurfaceImpl. +// 1. Representing the target surface: The iterator in this state, +// pointing at layer L, indicates that the target RenderSurface +// is now the surface owned by L. This will occur exactly once for each +// RenderSurface in the tree. +// 2. Representing a contributing surface: The iterator in this state, +// pointing at layer L, refers to the RenderSurface owned +// by L as a contributing surface, without changing the current +// target RenderSurface. +// 3. Representing itself: The iterator in this state, pointing at layer L, +// refers to the layer itself, as a child of the +// current target RenderSurface. // -// The BackToFront iterator will return a layer representing the target surface before returning layers representing themselves -// as children of the current target surface. Whereas the FrontToBack ordering will iterate over children layers of a surface -// before the layer representing the surface as a target surface. +// The BackToFront iterator will return a layer representing the target surface +// before returning layers representing themselves as children of the current +// target surface. Whereas the FrontToBack ordering will iterate over children +// layers of a surface before the layer representing the surface +// as a target surface. // // To use the iterators: // -// Create a stepping iterator and end iterator by calling LayerIterator::begin() and LayerIterator::end() and passing in the -// list of layers owning target RenderSurfaces. Step through the tree by incrementing the stepping iterator while it is != to -// the end iterator. At each step the iterator knows what the layer is representing, and you can query the iterator to decide +// Create a stepping iterator and end iterator by calling +// LayerIterator::Begin() and LayerIterator::End() and passing in the +// list of layers owning target RenderSurfaces. Step through the tree +// by incrementing the stepping iterator while it is != to +// the end iterator. At each step the iterator knows what the layer +// is representing, and you can query the iterator to decide // what actions to perform with the layer given what it represents. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Non-templated constants struct LayerIteratorValue { - static const int InvalidTargetRenderSurfaceLayerIndex = -1; - // This must be -1 since the iterator action code assumes that this value can be - // reached by subtracting one from the position of the first layer in the current - // target surface's child layer list, which is 0. - static const int LayerIndexRepresentingTargetRenderSurface = -1; + static const int kInvalidTargetRenderSurfaceLayerIndex = -1; + // This must be -1 since the iterator action code assumes that this value can + // be reached by subtracting one from the position of the first layer in the + // current target surface's child layer list, which is 0. + static const int kLayerIndexRepresentingTargetRenderSurface = -1; }; -// The position of a layer iterator that is independent of its many template types. -template <typename LayerType> -struct LayerIteratorPosition { - bool representsTargetRenderSurface; - bool representsContributingRenderSurface; - bool representsItself; - LayerType* targetRenderSurfaceLayer; - LayerType* currentLayer; +// The position of a layer iterator that is independent +// of its many template types. +template <typename LayerType> struct LayerIteratorPosition { + bool represents_target_render_surface; + bool represents_contributing_render_surface; + bool represents_itself; + LayerType* target_render_surface_layer; + LayerType* current_layer; }; -// An iterator class for walking over layers in the RenderSurfaceImpl-Layer tree. -template <typename LayerType, typename LayerList, typename RenderSurfaceType, typename IteratorActionType> +// An iterator class for walking over layers in the +// RenderSurface-Layer tree. +template <typename LayerType, + typename LayerList, + typename RenderSurfaceType, + typename IteratorActionType> class LayerIterator { - typedef LayerIterator<LayerType, LayerList, RenderSurfaceType, IteratorActionType> LayerIteratorType; - -public: - LayerIterator() : m_renderSurfaceLayerList(0) { } - - static LayerIteratorType begin(const LayerList* renderSurfaceLayerList) { return LayerIteratorType(renderSurfaceLayerList, true); } - static LayerIteratorType end(const LayerList* renderSurfaceLayerList) { return LayerIteratorType(renderSurfaceLayerList, false); } - - LayerIteratorType& operator++() { m_actions.next(*this); return *this; } - bool operator==(const LayerIterator& other) const - { - return m_targetRenderSurfaceLayerIndex == other.m_targetRenderSurfaceLayerIndex - && m_currentLayerIndex == other.m_currentLayerIndex; - } - bool operator!=(const LayerIteratorType& other) const { return !(*this == other); } - - LayerType* operator->() const { return currentLayer(); } - LayerType* operator*() const { return currentLayer(); } - - bool representsTargetRenderSurface() const { return currentLayerRepresentsTargetRenderSurface(); } - bool representsContributingRenderSurface() const { return !representsTargetRenderSurface() && currentLayerRepresentsContributingRenderSurface(); } - bool representsItself() const { return !representsTargetRenderSurface() && !representsContributingRenderSurface(); } - - LayerType* targetRenderSurfaceLayer() const { return getRawPtr((*m_renderSurfaceLayerList)[m_targetRenderSurfaceLayerIndex]); } - - operator const LayerIteratorPosition<LayerType>() const - { - LayerIteratorPosition<LayerType> position; - position.representsTargetRenderSurface = representsTargetRenderSurface(); - position.representsContributingRenderSurface = representsContributingRenderSurface(); - position.representsItself = representsItself(); - position.targetRenderSurfaceLayer = targetRenderSurfaceLayer(); - position.currentLayer = currentLayer(); - return position; + typedef LayerIterator<LayerType, + LayerList, + RenderSurfaceType, + IteratorActionType> LayerIteratorType; + + public: + LayerIterator() : render_surface_layer_list_(NULL) {} + + static LayerIteratorType Begin(const LayerList* render_surface_layer_list) { + return LayerIteratorType(render_surface_layer_list, true); + } + static LayerIteratorType End(const LayerList* render_surface_layer_list) { + return LayerIteratorType(render_surface_layer_list, false); + } + + LayerIteratorType& operator++() { + actions_.Next(this); + return *this; + } + bool operator==(const LayerIterator& other) const { + return target_render_surface_layer_index_ == + other.target_render_surface_layer_index_ && + current_layer_index_ == other.current_layer_index_; + } + bool operator!=(const LayerIteratorType& other) const { + return !(*this == other); + } + + LayerType* operator->() const { return current_layer(); } + LayerType* operator*() const { return current_layer(); } + + bool represents_target_render_surface() const { + return current_layer_represents_target_render_surface(); + } + bool represents_contributing_render_surface() const { + return !represents_target_render_surface() && + current_layer_represents_contributing_render_surface(); + } + bool represents_itself() const { + return !represents_target_render_surface() && + !represents_contributing_render_surface(); + } + + LayerType* target_render_surface_layer() const { + return get_raw_ptr( + (*render_surface_layer_list_)[target_render_surface_layer_index_]); + } + + operator const LayerIteratorPosition<LayerType>() const { + LayerIteratorPosition<LayerType> position; + position.represents_target_render_surface = + represents_target_render_surface(); + position.represents_contributing_render_surface = + represents_contributing_render_surface(); + position.represents_itself = represents_itself(); + position.target_render_surface_layer = target_render_surface_layer(); + position.current_layer = current_layer(); + return position; + } + + private: + LayerIterator(const LayerList* render_surface_layer_list, bool start) + : render_surface_layer_list_(render_surface_layer_list), + target_render_surface_layer_index_(0) { + for (size_t i = 0; i < render_surface_layer_list->size(); ++i) { + if (!(*render_surface_layer_list)[i]->render_surface()) { + NOTREACHED(); + actions_.End(this); + return; + } } -private: - LayerIterator(const LayerList* renderSurfaceLayerList, bool start) - : m_renderSurfaceLayerList(renderSurfaceLayerList) - , m_targetRenderSurfaceLayerIndex(0) - { - for (size_t i = 0; i < renderSurfaceLayerList->size(); ++i) { - if (!(*renderSurfaceLayerList)[i]->render_surface()) { - NOTREACHED(); - m_actions.end(*this); - return; - } - } - - if (start && !renderSurfaceLayerList->empty()) - m_actions.begin(*this); - else - m_actions.end(*this); - } - - inline static Layer* getRawPtr(const scoped_refptr<Layer>& ptr) { return ptr.get(); } - inline static LayerImpl* getRawPtr(LayerImpl* ptr) { return ptr; } - - inline LayerType* currentLayer() const { return currentLayerRepresentsTargetRenderSurface() ? targetRenderSurfaceLayer() : getRawPtr(targetRenderSurfaceChildren()[m_currentLayerIndex]); } - - inline bool currentLayerRepresentsContributingRenderSurface() const { return LayerTreeHostCommon::renderSurfaceContributesToTarget<LayerType>(currentLayer(), targetRenderSurfaceLayer()->id()); } - inline bool currentLayerRepresentsTargetRenderSurface() const { return m_currentLayerIndex == LayerIteratorValue::LayerIndexRepresentingTargetRenderSurface; } - - inline RenderSurfaceType* targetRenderSurface() const { return targetRenderSurfaceLayer()->render_surface(); } - inline const LayerList& targetRenderSurfaceChildren() const { return targetRenderSurface()->layer_list(); } - - IteratorActionType m_actions; - const LayerList* m_renderSurfaceLayerList; - - // The iterator's current position. - - // A position in the renderSurfaceLayerList. This points to a layer which owns the current target surface. - // This is a value from 0 to n-1 (n = size of renderSurfaceLayerList = number of surfaces). A value outside of - // this range (for example, LayerIteratorValue::InvalidTargetRenderSurfaceLayerIndex) is used to - // indicate a position outside the bounds of the tree. - int m_targetRenderSurfaceLayerIndex; - // A position in the list of layers that are children of the current target surface. When pointing to one of - // these layers, this is a value from 0 to n-1 (n = number of children). Since the iterator must also stop at - // the layers representing the target surface, this is done by setting the currentLayerIndex to a value of - // LayerIteratorValue::LayerRepresentingTargetRenderSurface. - int m_currentLayerIndex; - - friend struct LayerIteratorActions; + if (start && !render_surface_layer_list->empty()) + actions_.Begin(this); + else + actions_.End(this); + } + + inline static Layer* get_raw_ptr(const scoped_refptr<Layer>& ptr) { + return ptr.get(); + } + inline static LayerImpl* get_raw_ptr(LayerImpl* ptr) { return ptr; } + + inline LayerType* current_layer() const { + return current_layer_represents_target_render_surface() + ? target_render_surface_layer() + : get_raw_ptr( + target_render_surface_children()[current_layer_index_]); + } + + inline bool current_layer_represents_contributing_render_surface() const { + return LayerTreeHostCommon::renderSurfaceContributesToTarget<LayerType>( + current_layer(), target_render_surface_layer()->id()); + } + inline bool current_layer_represents_target_render_surface() const { + return current_layer_index_ == + LayerIteratorValue::kLayerIndexRepresentingTargetRenderSurface; + } + + inline RenderSurfaceType* target_render_surface() const { + return target_render_surface_layer()->render_surface(); + } + inline const LayerList& target_render_surface_children() const { + return target_render_surface()->layer_list(); + } + + IteratorActionType actions_; + const LayerList* render_surface_layer_list_; + + // The iterator's current position. + + // A position in the render_surface_layer_list. This points to a layer which + // owns the current target surface. This is a value from 0 to n-1 + // (n = size of render_surface_layer_list = number of surfaces). + // A value outside of this range + // (for example, LayerIteratorValue::kInvalidTargetRenderSurfaceLayerIndex) + // is used to indicate a position outside the bounds of the tree. + int target_render_surface_layer_index_; + // A position in the list of layers that are children of the + // current target surface. When pointing to one of these layers, + // this is a value from 0 to n-1 (n = number of children). + // Since the iterator must also stop at the layers representing + // the target surface, this is done by setting the current_layerIndex + // to a value of LayerIteratorValue::LayerRepresentingTargetRenderSurface. + int current_layer_index_; + + friend struct LayerIteratorActions; }; -// Orderings for iterating over the RenderSurfaceImpl-Layer tree. +// Orderings for iterating over the RenderSurface-Layer tree. struct CC_EXPORT LayerIteratorActions { - // Walks layers sorted by z-order from back to front. - class CC_EXPORT BackToFront { - public: - template <typename LayerType, typename LayerList, typename RenderSurfaceType, typename ActionType> - void begin(LayerIterator<LayerType, LayerList, RenderSurfaceType, ActionType>&); - - template <typename LayerType, typename LayerList, typename RenderSurfaceType, typename ActionType> - void end(LayerIterator<LayerType, LayerList, RenderSurfaceType, ActionType>&); - - template <typename LayerType, typename LayerList, typename RenderSurfaceType, typename ActionType> - void next(LayerIterator<LayerType, LayerList, RenderSurfaceType, ActionType>&); - - private: - int m_highestTargetRenderSurfaceLayer; - }; - - // Walks layers sorted by z-order from front to back - class CC_EXPORT FrontToBack { - public: - template <typename LayerType, typename LayerList, typename RenderSurfaceType, typename ActionType> - void begin(LayerIterator<LayerType, LayerList, RenderSurfaceType, ActionType>&); - - template <typename LayerType, typename LayerList, typename RenderSurfaceType, typename ActionType> - void end(LayerIterator<LayerType, LayerList, RenderSurfaceType, ActionType>&); - - template <typename LayerType, typename LayerList, typename RenderSurfaceType, typename ActionType> - void next(LayerIterator<LayerType, LayerList, RenderSurfaceType, ActionType>&); - - private: - template <typename LayerType, typename LayerList, typename RenderSurfaceType, typename ActionType> - void goToHighestInSubtree(LayerIterator<LayerType, LayerList, RenderSurfaceType, ActionType>&); - }; + // Walks layers sorted by z-order from back to front. + class CC_EXPORT BackToFront { + public: + template <typename LayerType, + typename LayerList, + typename RenderSurfaceType, + typename ActionType> + void Begin( + LayerIterator<LayerType, LayerList, RenderSurfaceType, ActionType>* it); + + template <typename LayerType, + typename LayerList, + typename RenderSurfaceType, + typename ActionType> + void End( + LayerIterator<LayerType, LayerList, RenderSurfaceType, ActionType>* it); + + template <typename LayerType, + typename LayerList, + typename RenderSurfaceType, + typename ActionType> + void Next( + LayerIterator<LayerType, LayerList, RenderSurfaceType, ActionType>* it); + + private: + int highest_target_render_surface_layer_; + }; + + // Walks layers sorted by z-order from front to back + class CC_EXPORT FrontToBack { + public: + template <typename LayerType, + typename LayerList, + typename RenderSurfaceType, + typename ActionType> + void Begin( + LayerIterator<LayerType, LayerList, RenderSurfaceType, ActionType>* it); + + template <typename LayerType, + typename LayerList, + typename RenderSurfaceType, + typename ActionType> + void End( + LayerIterator<LayerType, LayerList, RenderSurfaceType, ActionType>* it); + + template <typename LayerType, + typename LayerList, + typename RenderSurfaceType, + typename ActionType> + void Next( + LayerIterator<LayerType, LayerList, RenderSurfaceType, ActionType>* it); + + private: + template <typename LayerType, + typename LayerList, + typename RenderSurfaceType, + typename ActionType> + void GoToHighestInSubtree( + LayerIterator<LayerType, LayerList, RenderSurfaceType, ActionType>* it); + }; }; -} // namespace cc +} // namespace cc #endif // CC_LAYERS_LAYER_ITERATOR_H_ diff --git a/cc/layers/layer_iterator_unittest.cc b/cc/layers/layer_iterator_unittest.cc index 9d4dc52..464c570 100644 --- a/cc/layers/layer_iterator_unittest.cc +++ b/cc/layers/layer_iterator_unittest.cc @@ -19,235 +19,262 @@ namespace cc { namespace { class TestLayer : public Layer { -public: - static scoped_refptr<TestLayer> Create() { return make_scoped_refptr(new TestLayer()); } - - int m_countRepresentingTargetSurface; - int m_countRepresentingContributingSurface; - int m_countRepresentingItself; - - virtual bool DrawsContent() const OVERRIDE { return m_drawsContent; } - void setDrawsContent(bool drawsContent) { m_drawsContent = drawsContent; } - -private: - TestLayer() - : Layer() - , m_drawsContent(true) - { - SetBounds(gfx::Size(100, 100)); - SetPosition(gfx::Point()); - SetAnchorPoint(gfx::Point()); - } - virtual ~TestLayer() - { - } - - bool m_drawsContent; + public: + static scoped_refptr<TestLayer> Create() { + return make_scoped_refptr(new TestLayer()); + } + + int count_representing_target_surface_; + int count_representing_contributing_surface_; + int count_representing_itself_; + + virtual bool DrawsContent() const OVERRIDE { return draws_content_; } + void set_draws_content(bool draws_content) { draws_content_ = draws_content; } + + private: + TestLayer() : Layer(), draws_content_(true) { + SetBounds(gfx::Size(100, 100)); + SetPosition(gfx::Point()); + SetAnchorPoint(gfx::Point()); + } + virtual ~TestLayer() {} + + bool draws_content_; }; -#define EXPECT_COUNT(layer, target, contrib, itself) \ - EXPECT_EQ(target, layer->m_countRepresentingTargetSurface); \ - EXPECT_EQ(contrib, layer->m_countRepresentingContributingSurface); \ - EXPECT_EQ(itself, layer->m_countRepresentingItself); - -typedef LayerIterator<Layer, std::vector<scoped_refptr<Layer> >, RenderSurface, LayerIteratorActions::FrontToBack> FrontToBack; -typedef LayerIterator<Layer, std::vector<scoped_refptr<Layer> >, RenderSurface, LayerIteratorActions::BackToFront> BackToFront; - -void resetCounts(std::vector<scoped_refptr<Layer> >& renderSurfaceLayerList) -{ - for (unsigned surfaceIndex = 0; surfaceIndex < renderSurfaceLayerList.size(); ++surfaceIndex) { - TestLayer* renderSurfaceLayer = static_cast<TestLayer*>(renderSurfaceLayerList[surfaceIndex].get()); - RenderSurface* renderSurface = renderSurfaceLayer->render_surface(); - - renderSurfaceLayer->m_countRepresentingTargetSurface = -1; - renderSurfaceLayer->m_countRepresentingContributingSurface = -1; - renderSurfaceLayer->m_countRepresentingItself = -1; - - for (unsigned layerIndex = 0; layerIndex < renderSurface->layer_list().size(); ++layerIndex) { - TestLayer* layer = static_cast<TestLayer*>(renderSurface->layer_list()[layerIndex].get()); - - layer->m_countRepresentingTargetSurface = -1; - layer->m_countRepresentingContributingSurface = -1; - layer->m_countRepresentingItself = -1; - } +#define EXPECT_COUNT(layer, target, contrib, itself) \ + EXPECT_EQ(target, layer->count_representing_target_surface_); \ + EXPECT_EQ(contrib, layer->count_representing_contributing_surface_); \ + EXPECT_EQ(itself, layer->count_representing_itself_); + +typedef LayerIterator<Layer, + std::vector<scoped_refptr<Layer> >, + RenderSurface, + LayerIteratorActions::FrontToBack> FrontToBack; +typedef LayerIterator<Layer, + std::vector<scoped_refptr<Layer> >, + RenderSurface, + LayerIteratorActions::BackToFront> BackToFront; + +void ResetCounts(std::vector<scoped_refptr<Layer> >* render_surface_layerList) { + for (unsigned surface_index = 0; + surface_index < render_surface_layerList->size(); + ++surface_index) { + TestLayer* render_surface_layer = static_cast<TestLayer*>( + (*render_surface_layerList)[surface_index].get()); + RenderSurface* render_surface = render_surface_layer->render_surface(); + + render_surface_layer->count_representing_target_surface_ = -1; + render_surface_layer->count_representing_contributing_surface_ = -1; + render_surface_layer->count_representing_itself_ = -1; + + for (unsigned layer_index = 0; + layer_index < render_surface->layer_list().size(); + ++layer_index) { + TestLayer* layer = static_cast<TestLayer*>( + render_surface->layer_list()[layer_index].get()); + + layer->count_representing_target_surface_ = -1; + layer->count_representing_contributing_surface_ = -1; + layer->count_representing_itself_ = -1; } + } } -void iterateFrontToBack(std::vector<scoped_refptr<Layer> >* renderSurfaceLayerList) -{ - resetCounts(*renderSurfaceLayerList); - int count = 0; - for (FrontToBack it = FrontToBack::begin(renderSurfaceLayerList); it != FrontToBack::end(renderSurfaceLayerList); ++it, ++count) { - TestLayer* layer = static_cast<TestLayer*>(*it); - if (it.representsTargetRenderSurface()) - layer->m_countRepresentingTargetSurface = count; - if (it.representsContributingRenderSurface()) - layer->m_countRepresentingContributingSurface = count; - if (it.representsItself()) - layer->m_countRepresentingItself = count; - } +void IterateFrontToBack( + std::vector<scoped_refptr<Layer> >* render_surface_layerList) { + ResetCounts(render_surface_layerList); + int count = 0; + for (FrontToBack it = FrontToBack::Begin(render_surface_layerList); + it != FrontToBack::End(render_surface_layerList); + ++it, ++count) { + TestLayer* layer = static_cast<TestLayer*>(*it); + if (it.represents_target_render_surface()) + layer->count_representing_target_surface_ = count; + if (it.represents_contributing_render_surface()) + layer->count_representing_contributing_surface_ = count; + if (it.represents_itself()) + layer->count_representing_itself_ = count; + } } -void iterateBackToFront(std::vector<scoped_refptr<Layer> >* renderSurfaceLayerList) -{ - resetCounts(*renderSurfaceLayerList); - int count = 0; - for (BackToFront it = BackToFront::begin(renderSurfaceLayerList); it != BackToFront::end(renderSurfaceLayerList); ++it, ++count) { - TestLayer* layer = static_cast<TestLayer*>(*it); - if (it.representsTargetRenderSurface()) - layer->m_countRepresentingTargetSurface = count; - if (it.representsContributingRenderSurface()) - layer->m_countRepresentingContributingSurface = count; - if (it.representsItself()) - layer->m_countRepresentingItself = count; - } +void IterateBackToFront( + std::vector<scoped_refptr<Layer> >* render_surface_layerList) { + ResetCounts(render_surface_layerList); + int count = 0; + for (BackToFront it = BackToFront::Begin(render_surface_layerList); + it != BackToFront::End(render_surface_layerList); + ++it, ++count) { + TestLayer* layer = static_cast<TestLayer*>(*it); + if (it.represents_target_render_surface()) + layer->count_representing_target_surface_ = count; + if (it.represents_contributing_render_surface()) + layer->count_representing_contributing_surface_ = count; + if (it.represents_itself()) + layer->count_representing_itself_ = count; + } } -TEST(LayerIteratorTest, emptyTree) -{ - std::vector<scoped_refptr<Layer> > renderSurfaceLayerList; +TEST(LayerIteratorTest, EmptyTree) { + std::vector<scoped_refptr<Layer> > render_surface_layerList; - iterateBackToFront(&renderSurfaceLayerList); - iterateFrontToBack(&renderSurfaceLayerList); + IterateBackToFront(&render_surface_layerList); + IterateFrontToBack(&render_surface_layerList); } -TEST(LayerIteratorTest, simpleTree) -{ - scoped_refptr<TestLayer> rootLayer = TestLayer::Create(); - scoped_refptr<TestLayer> first = TestLayer::Create(); - scoped_refptr<TestLayer> second = TestLayer::Create(); - scoped_refptr<TestLayer> third = TestLayer::Create(); - scoped_refptr<TestLayer> fourth = TestLayer::Create(); - - rootLayer->CreateRenderSurface(); - - rootLayer->AddChild(first); - rootLayer->AddChild(second); - rootLayer->AddChild(third); - rootLayer->AddChild(fourth); - - std::vector<scoped_refptr<Layer> > renderSurfaceLayerList; - LayerTreeHostCommon::calculateDrawProperties(rootLayer.get(), rootLayer->bounds(), 1, 1, 256, false, renderSurfaceLayerList); - - iterateBackToFront(&renderSurfaceLayerList); - EXPECT_COUNT(rootLayer, 0, -1, 1); - EXPECT_COUNT(first, -1, -1, 2); - EXPECT_COUNT(second, -1, -1, 3); - EXPECT_COUNT(third, -1, -1, 4); - EXPECT_COUNT(fourth, -1, -1, 5); - - iterateFrontToBack(&renderSurfaceLayerList); - EXPECT_COUNT(rootLayer, 5, -1, 4); - EXPECT_COUNT(first, -1, -1, 3); - EXPECT_COUNT(second, -1, -1, 2); - EXPECT_COUNT(third, -1, -1, 1); - EXPECT_COUNT(fourth, -1, -1, 0); +TEST(LayerIteratorTest, SimpleTree) { + scoped_refptr<TestLayer> root_layer = TestLayer::Create(); + scoped_refptr<TestLayer> first = TestLayer::Create(); + scoped_refptr<TestLayer> second = TestLayer::Create(); + scoped_refptr<TestLayer> third = TestLayer::Create(); + scoped_refptr<TestLayer> fourth = TestLayer::Create(); + + root_layer->CreateRenderSurface(); + + root_layer->AddChild(first); + root_layer->AddChild(second); + root_layer->AddChild(third); + root_layer->AddChild(fourth); + + std::vector<scoped_refptr<Layer> > render_surface_layerList; + LayerTreeHostCommon::calculateDrawProperties(root_layer.get(), + root_layer->bounds(), + 1, + 1, + 256, + false, + render_surface_layerList); + + IterateBackToFront(&render_surface_layerList); + EXPECT_COUNT(root_layer, 0, -1, 1); + EXPECT_COUNT(first, -1, -1, 2); + EXPECT_COUNT(second, -1, -1, 3); + EXPECT_COUNT(third, -1, -1, 4); + EXPECT_COUNT(fourth, -1, -1, 5); + + IterateFrontToBack(&render_surface_layerList); + EXPECT_COUNT(root_layer, 5, -1, 4); + EXPECT_COUNT(first, -1, -1, 3); + EXPECT_COUNT(second, -1, -1, 2); + EXPECT_COUNT(third, -1, -1, 1); + EXPECT_COUNT(fourth, -1, -1, 0); } -TEST(LayerIteratorTest, complexTree) -{ - scoped_refptr<TestLayer> rootLayer = TestLayer::Create(); - scoped_refptr<TestLayer> root1 = TestLayer::Create(); - scoped_refptr<TestLayer> root2 = TestLayer::Create(); - scoped_refptr<TestLayer> root3 = TestLayer::Create(); - scoped_refptr<TestLayer> root21 = TestLayer::Create(); - scoped_refptr<TestLayer> root22 = TestLayer::Create(); - scoped_refptr<TestLayer> root23 = TestLayer::Create(); - scoped_refptr<TestLayer> root221 = TestLayer::Create(); - scoped_refptr<TestLayer> root231 = TestLayer::Create(); - - rootLayer->CreateRenderSurface(); - - rootLayer->AddChild(root1); - rootLayer->AddChild(root2); - rootLayer->AddChild(root3); - root2->AddChild(root21); - root2->AddChild(root22); - root2->AddChild(root23); - root22->AddChild(root221); - root23->AddChild(root231); - - std::vector<scoped_refptr<Layer> > renderSurfaceLayerList; - LayerTreeHostCommon::calculateDrawProperties(rootLayer.get(), rootLayer->bounds(), 1, 1, 256, false, renderSurfaceLayerList); - - iterateBackToFront(&renderSurfaceLayerList); - EXPECT_COUNT(rootLayer, 0, -1, 1); - EXPECT_COUNT(root1, -1, -1, 2); - EXPECT_COUNT(root2, -1, -1, 3); - EXPECT_COUNT(root21, -1, -1, 4); - EXPECT_COUNT(root22, -1, -1, 5); - EXPECT_COUNT(root221, -1, -1, 6); - EXPECT_COUNT(root23, -1, -1, 7); - EXPECT_COUNT(root231, -1, -1, 8); - EXPECT_COUNT(root3, -1, -1, 9); - - iterateFrontToBack(&renderSurfaceLayerList); - EXPECT_COUNT(rootLayer, 9, -1, 8); - EXPECT_COUNT(root1, -1, -1, 7); - EXPECT_COUNT(root2, -1, -1, 6); - EXPECT_COUNT(root21, -1, -1, 5); - EXPECT_COUNT(root22, -1, -1, 4); - EXPECT_COUNT(root221, -1, -1, 3); - EXPECT_COUNT(root23, -1, -1, 2); - EXPECT_COUNT(root231, -1, -1, 1); - EXPECT_COUNT(root3, -1, -1, 0); +TEST(LayerIteratorTest, ComplexTree) { + scoped_refptr<TestLayer> root_layer = TestLayer::Create(); + scoped_refptr<TestLayer> root1 = TestLayer::Create(); + scoped_refptr<TestLayer> root2 = TestLayer::Create(); + scoped_refptr<TestLayer> root3 = TestLayer::Create(); + scoped_refptr<TestLayer> root21 = TestLayer::Create(); + scoped_refptr<TestLayer> root22 = TestLayer::Create(); + scoped_refptr<TestLayer> root23 = TestLayer::Create(); + scoped_refptr<TestLayer> root221 = TestLayer::Create(); + scoped_refptr<TestLayer> root231 = TestLayer::Create(); + + root_layer->CreateRenderSurface(); + + root_layer->AddChild(root1); + root_layer->AddChild(root2); + root_layer->AddChild(root3); + root2->AddChild(root21); + root2->AddChild(root22); + root2->AddChild(root23); + root22->AddChild(root221); + root23->AddChild(root231); + + std::vector<scoped_refptr<Layer> > render_surface_layerList; + LayerTreeHostCommon::calculateDrawProperties(root_layer.get(), + root_layer->bounds(), + 1, + 1, + 256, + false, + render_surface_layerList); + + IterateBackToFront(&render_surface_layerList); + EXPECT_COUNT(root_layer, 0, -1, 1); + EXPECT_COUNT(root1, -1, -1, 2); + EXPECT_COUNT(root2, -1, -1, 3); + EXPECT_COUNT(root21, -1, -1, 4); + EXPECT_COUNT(root22, -1, -1, 5); + EXPECT_COUNT(root221, -1, -1, 6); + EXPECT_COUNT(root23, -1, -1, 7); + EXPECT_COUNT(root231, -1, -1, 8); + EXPECT_COUNT(root3, -1, -1, 9); + + IterateFrontToBack(&render_surface_layerList); + EXPECT_COUNT(root_layer, 9, -1, 8); + EXPECT_COUNT(root1, -1, -1, 7); + EXPECT_COUNT(root2, -1, -1, 6); + EXPECT_COUNT(root21, -1, -1, 5); + EXPECT_COUNT(root22, -1, -1, 4); + EXPECT_COUNT(root221, -1, -1, 3); + EXPECT_COUNT(root23, -1, -1, 2); + EXPECT_COUNT(root231, -1, -1, 1); + EXPECT_COUNT(root3, -1, -1, 0); } -TEST(LayerIteratorTest, complexTreeMultiSurface) -{ - scoped_refptr<TestLayer> rootLayer = TestLayer::Create(); - scoped_refptr<TestLayer> root1 = TestLayer::Create(); - scoped_refptr<TestLayer> root2 = TestLayer::Create(); - scoped_refptr<TestLayer> root3 = TestLayer::Create(); - scoped_refptr<TestLayer> root21 = TestLayer::Create(); - scoped_refptr<TestLayer> root22 = TestLayer::Create(); - scoped_refptr<TestLayer> root23 = TestLayer::Create(); - scoped_refptr<TestLayer> root221 = TestLayer::Create(); - scoped_refptr<TestLayer> root231 = TestLayer::Create(); - - rootLayer->CreateRenderSurface(); - rootLayer->render_surface()->SetContentRect(gfx::Rect(gfx::Point(), rootLayer->bounds())); - - rootLayer->AddChild(root1); - rootLayer->AddChild(root2); - rootLayer->AddChild(root3); - root2->setDrawsContent(false); - root2->SetOpacity(0.5); - root2->SetForceRenderSurface(true); // Force the layer to own a new surface. - root2->AddChild(root21); - root2->AddChild(root22); - root2->AddChild(root23); - root22->SetOpacity(0.5); - root22->AddChild(root221); - root23->SetOpacity(0.5); - root23->AddChild(root231); - - std::vector<scoped_refptr<Layer> > renderSurfaceLayerList; - LayerTreeHostCommon::calculateDrawProperties(rootLayer.get(), rootLayer->bounds(), 1, 1, 256, false, renderSurfaceLayerList); - - iterateBackToFront(&renderSurfaceLayerList); - EXPECT_COUNT(rootLayer, 0, -1, 1); - EXPECT_COUNT(root1, -1, -1, 2); - EXPECT_COUNT(root2, 4, 3, -1); - EXPECT_COUNT(root21, -1, -1, 5); - EXPECT_COUNT(root22, 7, 6, 8); - EXPECT_COUNT(root221, -1, -1, 9); - EXPECT_COUNT(root23, 11, 10, 12); - EXPECT_COUNT(root231, -1, -1, 13); - EXPECT_COUNT(root3, -1, -1, 14); - - iterateFrontToBack(&renderSurfaceLayerList); - EXPECT_COUNT(rootLayer, 14, -1, 13); - EXPECT_COUNT(root1, -1, -1, 12); - EXPECT_COUNT(root2, 10, 11, -1); - EXPECT_COUNT(root21, -1, -1, 9); - EXPECT_COUNT(root22, 7, 8, 6); - EXPECT_COUNT(root221, -1, -1, 5); - EXPECT_COUNT(root23, 3, 4, 2); - EXPECT_COUNT(root231, -1, -1, 1); - EXPECT_COUNT(root3, -1, -1, 0); +TEST(LayerIteratorTest, ComplexTreeMultiSurface) { + scoped_refptr<TestLayer> root_layer = TestLayer::Create(); + scoped_refptr<TestLayer> root1 = TestLayer::Create(); + scoped_refptr<TestLayer> root2 = TestLayer::Create(); + scoped_refptr<TestLayer> root3 = TestLayer::Create(); + scoped_refptr<TestLayer> root21 = TestLayer::Create(); + scoped_refptr<TestLayer> root22 = TestLayer::Create(); + scoped_refptr<TestLayer> root23 = TestLayer::Create(); + scoped_refptr<TestLayer> root221 = TestLayer::Create(); + scoped_refptr<TestLayer> root231 = TestLayer::Create(); + + root_layer->CreateRenderSurface(); + root_layer->render_surface()-> + SetContentRect(gfx::Rect(gfx::Point(), root_layer->bounds())); + + root_layer->AddChild(root1); + root_layer->AddChild(root2); + root_layer->AddChild(root3); + root2->set_draws_content(false); + root2->SetOpacity(0.5f); + root2->SetForceRenderSurface(true); // Force the layer to own a new surface. + root2->AddChild(root21); + root2->AddChild(root22); + root2->AddChild(root23); + root22->SetOpacity(0.5f); + root22->AddChild(root221); + root23->SetOpacity(0.5f); + root23->AddChild(root231); + + std::vector<scoped_refptr<Layer> > render_surface_layerList; + LayerTreeHostCommon::calculateDrawProperties(root_layer.get(), + root_layer->bounds(), + 1, + 1, + 256, + false, + render_surface_layerList); + + IterateBackToFront(&render_surface_layerList); + EXPECT_COUNT(root_layer, 0, -1, 1); + EXPECT_COUNT(root1, -1, -1, 2); + EXPECT_COUNT(root2, 4, 3, -1); + EXPECT_COUNT(root21, -1, -1, 5); + EXPECT_COUNT(root22, 7, 6, 8); + EXPECT_COUNT(root221, -1, -1, 9); + EXPECT_COUNT(root23, 11, 10, 12); + EXPECT_COUNT(root231, -1, -1, 13); + EXPECT_COUNT(root3, -1, -1, 14); + + IterateFrontToBack(&render_surface_layerList); + EXPECT_COUNT(root_layer, 14, -1, 13); + EXPECT_COUNT(root1, -1, -1, 12); + EXPECT_COUNT(root2, 10, 11, -1); + EXPECT_COUNT(root21, -1, -1, 9); + EXPECT_COUNT(root22, 7, 8, 6); + EXPECT_COUNT(root221, -1, -1, 5); + EXPECT_COUNT(root23, 3, 4, 2); + EXPECT_COUNT(root231, -1, -1, 1); + EXPECT_COUNT(root3, -1, -1, 0); } } // namespace |