effect_tree_layer_list_iterator.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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
  3. // found in the LICENSE file.
  4. #ifndef CC_LAYERS_EFFECT_TREE_LAYER_LIST_ITERATOR_H_
  5. #define CC_LAYERS_EFFECT_TREE_LAYER_LIST_ITERATOR_H_
  6. #include "base/memory/raw_ptr.h"
  7. #include "base/notreached.h"
  8. #include "cc/cc_export.h"
  9. #include "cc/trees/effect_node.h"
  10. #include "cc/trees/layer_tree_impl.h"
  11. #include "cc/trees/property_tree.h"
  12. namespace cc {
  13. class LayerImpl;
  14. class LayerTreeImpl;
  15. // This iterates over layers and render surfaces in front-to-back order (that
  16. // is, in reverse-draw-order). Only layers that draw content to some render
  17. // surface are visited. A render surface is visited immediately after all
  18. // layers and surfaces that contribute content to that surface are visited.
  19. // Surfaces are first visited in state TARGET_SURFACE. Immediately after that,
  20. // every surface other than the root surface is visited in state
  21. // CONTRIBUTING_SURFACE, as it contributes to the next target surface.
  22. //
  23. // The iterator takes on the following states:
  24. // 1. LAYER: The iterator is visiting layer |current_layer()| that contributes
  25. // to surface |target_render_surface()|.
  26. // 2. TARGET_SURFACE: The iterator is visiting render surface
  27. // |target_render_surface()|.
  28. // 3. CONTRIBUTING_SURFACE: The iterator is visiting render surface
  29. // |current_render_surface()| that contributes to surface
  30. // |target_render_surface()|.
  31. // 4. END: All layers and render surfaces have already been visited.
  32. class CC_EXPORT EffectTreeLayerListIterator {
  33. public:
  34. enum class State { LAYER, TARGET_SURFACE, CONTRIBUTING_SURFACE, END };
  35. explicit EffectTreeLayerListIterator(LayerTreeImpl* layer_tree_impl);
  36. EffectTreeLayerListIterator(const EffectTreeLayerListIterator& iterator);
  37. ~EffectTreeLayerListIterator();
  38. void operator++();
  39. State state() { return state_; }
  40. LayerImpl* current_layer() const {
  41. DCHECK(state_ == State::LAYER);
  42. return *layer_list_iterator_;
  43. }
  44. RenderSurfaceImpl* current_render_surface() const {
  45. DCHECK(state_ == State::CONTRIBUTING_SURFACE);
  46. return effect_tree_->GetRenderSurface(current_effect_tree_index_);
  47. }
  48. RenderSurfaceImpl* target_render_surface() const {
  49. switch (state_) {
  50. case State::LAYER:
  51. case State::TARGET_SURFACE:
  52. return effect_tree_->GetRenderSurface(current_effect_tree_index_);
  53. case State::CONTRIBUTING_SURFACE: {
  54. int target_node_id =
  55. effect_tree_->Node(current_effect_tree_index_)->target_id;
  56. return effect_tree_->GetRenderSurface(target_node_id);
  57. }
  58. case State::END:
  59. NOTREACHED();
  60. }
  61. NOTREACHED();
  62. return nullptr;
  63. }
  64. struct Position {
  65. State state = State::END;
  66. LayerImpl* current_layer = nullptr;
  67. RenderSurfaceImpl* current_render_surface = nullptr;
  68. RenderSurfaceImpl* target_render_surface = nullptr;
  69. };
  70. operator const Position() const {
  71. Position position;
  72. if (state_ == State::END)
  73. return position;
  74. position.state = state_;
  75. position.target_render_surface = target_render_surface();
  76. if (state_ == State::LAYER)
  77. position.current_layer = current_layer();
  78. else if (state_ == State::CONTRIBUTING_SURFACE)
  79. position.current_render_surface = current_render_surface();
  80. return position;
  81. }
  82. private:
  83. State state_;
  84. // When in state LAYER, this is the layer that's currently being visited.
  85. // Otherwise, this is the layer that will be visited the next time we're in
  86. // state LAYER.
  87. LayerTreeImpl::const_reverse_iterator layer_list_iterator_;
  88. // When in state LAYER, this is the render target effect tree index for the
  89. // currently visited layer. Otherwise, this is the the effect tree index of
  90. // the currently visited render surface.
  91. int current_effect_tree_index_;
  92. // Render target effect tree index for the layer currently visited by
  93. // layer_list_iterator_.
  94. int next_effect_tree_index_;
  95. // The index in the effect tree of the lowest common ancestor
  96. // current_effect_tree_index_ and next_effect_tree_index_, that has a
  97. // render surface.
  98. int lowest_common_effect_tree_ancestor_index_;
  99. raw_ptr<LayerTreeImpl> layer_tree_impl_;
  100. raw_ptr<EffectTree> effect_tree_;
  101. };
  102. } // namespace cc
  103. #endif // CC_LAYERS_EFFECT_TREE_LAYER_LIST_ITERATOR_H_