| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "cc/layers/effect_tree_layer_list_iterator.h" | 5 #include "cc/layers/effect_tree_layer_list_iterator.h" |
| 6 | 6 |
| 7 namespace cc { | 7 namespace cc { |
| 8 | 8 |
| 9 EffectTreeLayerListIterator::EffectTreeLayerListIterator( | 9 EffectTreeLayerListIterator::EffectTreeLayerListIterator( |
| 10 LayerTreeImpl* layer_tree_impl) | 10 LayerTreeImpl* layer_tree_impl) |
| (...skipping 25 matching lines...) Expand all Loading... |
| 36 next_effect_tree_index_ = current_effect_tree_index_; | 36 next_effect_tree_index_ = current_effect_tree_index_; |
| 37 lowest_common_effect_tree_ancestor_index_ = current_effect_tree_index_; | 37 lowest_common_effect_tree_ancestor_index_ = current_effect_tree_index_; |
| 38 } | 38 } |
| 39 } | 39 } |
| 40 | 40 |
| 41 EffectTreeLayerListIterator::EffectTreeLayerListIterator( | 41 EffectTreeLayerListIterator::EffectTreeLayerListIterator( |
| 42 const EffectTreeLayerListIterator& iterator) = default; | 42 const EffectTreeLayerListIterator& iterator) = default; |
| 43 | 43 |
| 44 EffectTreeLayerListIterator::~EffectTreeLayerListIterator() {} | 44 EffectTreeLayerListIterator::~EffectTreeLayerListIterator() {} |
| 45 | 45 |
| 46 // Finds the lowest common ancestor that has a render surface. | |
| 47 static int LowestCommonAncestor(int effect_id_1, | |
| 48 int effect_id_2, | |
| 49 const EffectTree* effect_tree) { | |
| 50 while (effect_id_1 != effect_id_2) { | |
| 51 if (effect_id_1 < effect_id_2) | |
| 52 effect_id_2 = effect_tree->Node(effect_id_2)->target_id; | |
| 53 else | |
| 54 effect_id_1 = effect_tree->Node(effect_id_1)->target_id; | |
| 55 } | |
| 56 | |
| 57 return effect_id_1; | |
| 58 } | |
| 59 | |
| 60 void EffectTreeLayerListIterator::operator++() { | 46 void EffectTreeLayerListIterator::operator++() { |
| 61 switch (state_) { | 47 switch (state_) { |
| 62 case State::LAYER: | 48 case State::LAYER: |
| 63 // Find the next drawn layer. | 49 // Find the next drawn layer. |
| 64 layer_list_iterator_++; | 50 layer_list_iterator_++; |
| 65 while (layer_list_iterator_ != layer_tree_impl_->rend() && | 51 while (layer_list_iterator_ != layer_tree_impl_->rend() && |
| 66 !(*layer_list_iterator_) | 52 !(*layer_list_iterator_) |
| 67 ->is_drawn_render_surface_layer_list_member()) { | 53 ->is_drawn_render_surface_layer_list_member()) { |
| 68 layer_list_iterator_++; | 54 layer_list_iterator_++; |
| 69 } | 55 } |
| 70 if (layer_list_iterator_ == layer_tree_impl_->rend()) { | 56 if (layer_list_iterator_ == layer_tree_impl_->rend()) { |
| 71 next_effect_tree_index_ = EffectTree::kInvalidNodeId; | 57 next_effect_tree_index_ = EffectTree::kInvalidNodeId; |
| 72 lowest_common_effect_tree_ancestor_index_ = EffectTree::kInvalidNodeId; | 58 lowest_common_effect_tree_ancestor_index_ = EffectTree::kInvalidNodeId; |
| 73 state_ = State::TARGET_SURFACE; | 59 state_ = State::TARGET_SURFACE; |
| 74 break; | 60 break; |
| 75 } | 61 } |
| 76 | 62 |
| 77 next_effect_tree_index_ = | 63 next_effect_tree_index_ = |
| 78 (*layer_list_iterator_)->render_target_effect_tree_index(); | 64 (*layer_list_iterator_)->render_target_effect_tree_index(); |
| 79 | 65 |
| 80 // If the next drawn layer has a different target effect tree index, check | 66 // If the next drawn layer has a different target effect tree index, check |
| 81 // for surfaces whose contributors have all been visited. | 67 // for surfaces whose contributors have all been visited. |
| 82 if (next_effect_tree_index_ != current_effect_tree_index_) { | 68 if (next_effect_tree_index_ != current_effect_tree_index_) { |
| 83 lowest_common_effect_tree_ancestor_index_ = LowestCommonAncestor( | 69 lowest_common_effect_tree_ancestor_index_ = |
| 84 current_effect_tree_index_, next_effect_tree_index_, effect_tree_); | 70 effect_tree_->LowestCommonAncestorWithRenderSurface( |
| 71 current_effect_tree_index_, next_effect_tree_index_); |
| 85 // If the current layer's target effect node is an ancestor of the next | 72 // If the current layer's target effect node is an ancestor of the next |
| 86 // layer's target effect node, then the current effect node still has | 73 // layer's target effect node, then the current effect node still has |
| 87 // more contributors that need to be visited. Otherwise, all | 74 // more contributors that need to be visited. Otherwise, all |
| 88 // contributors have been visited, so we visit the node's surface next. | 75 // contributors have been visited, so we visit the node's surface next. |
| 89 if (current_effect_tree_index_ == | 76 if (current_effect_tree_index_ == |
| 90 lowest_common_effect_tree_ancestor_index_) { | 77 lowest_common_effect_tree_ancestor_index_) { |
| 91 current_effect_tree_index_ = next_effect_tree_index_; | 78 current_effect_tree_index_ = next_effect_tree_index_; |
| 92 lowest_common_effect_tree_ancestor_index_ = next_effect_tree_index_; | 79 lowest_common_effect_tree_ancestor_index_ = next_effect_tree_index_; |
| 93 } else { | 80 } else { |
| 94 state_ = State::TARGET_SURFACE; | 81 state_ = State::TARGET_SURFACE; |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 // surface. | 117 // surface. |
| 131 state_ = State::TARGET_SURFACE; | 118 state_ = State::TARGET_SURFACE; |
| 132 } | 119 } |
| 133 break; | 120 break; |
| 134 case State::END: | 121 case State::END: |
| 135 NOTREACHED(); | 122 NOTREACHED(); |
| 136 } | 123 } |
| 137 } | 124 } |
| 138 | 125 |
| 139 } // namespace cc | 126 } // namespace cc |
| OLD | NEW |