Flutter Impeller
entity_pass_clip_stack.h
Go to the documentation of this file.
1 // Copyright 2013 The Flutter 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 
5 #ifndef FLUTTER_IMPELLER_ENTITY_ENTITY_PASS_CLIP_STACK_H_
6 #define FLUTTER_IMPELLER_ENTITY_ENTITY_PASS_CLIP_STACK_H_
7 
10 
11 namespace impeller {
12 
14  std::optional<Rect> coverage;
15  size_t clip_height = 0;
16 };
17 
18 /// @brief A class that tracks all clips that have been recorded in the current
19 /// entity pass stencil.
20 ///
21 /// These clips are replayed when restoring the backdrop so that the
22 /// stencil buffer is left in an identical state.
24  public:
25  struct ReplayResult {
28  std::optional<Rect> clip_coverage;
29  uint32_t clip_depth = 0;
30  };
31 
32  struct ClipStateResult {
33  /// Whether or not the Entity should be rendered. If false, the Entity may
34  /// be safely skipped.
35  bool should_render = false;
36  /// Whether or not the current clip coverage changed during the call to
37  /// `ApplyClipState`.
38  bool clip_did_change = false;
39  };
40 
41  /// Create a new [EntityPassClipStack] with an initialized coverage rect.
42  explicit EntityPassClipStack(const Rect& initial_coverage_rect);
43 
44  ~EntityPassClipStack() = default;
45 
46  std::optional<Rect> CurrentClipCoverage() const;
47 
48  void PushSubpass(std::optional<Rect> subpass_coverage, size_t clip_height);
49 
50  void PopSubpass();
51 
52  bool HasCoverage() const;
53 
54  ClipStateResult RecordClip(const ClipContents& clip_contents,
56  Point global_pass_position,
57  uint32_t clip_depth,
58  size_t clip_height_floor,
59  bool is_aa);
60 
62  return GetCurrentSubpassState().rendered_clip_entities.back();
63  }
64 
65  ClipStateResult RecordRestore(Point global_pass_position,
66  size_t restore_height);
67 
68  const std::vector<ReplayResult>& GetReplayEntities() const;
69 
70  // Visible for testing.
71  const std::vector<ClipCoverageLayer> GetClipCoverageLayers() const;
72 
73  private:
74  struct SubpassState {
75  std::vector<ReplayResult> rendered_clip_entities;
76  std::vector<ClipCoverageLayer> clip_coverage;
77  };
78 
79  SubpassState& GetCurrentSubpassState();
80 
81  std::vector<SubpassState> subpass_state_;
82  size_t next_replay_index_ = 0;
83 };
84 
85 } // namespace impeller
86 
87 #endif // FLUTTER_IMPELLER_ENTITY_ENTITY_PASS_CLIP_STACK_H_
A class that tracks all clips that have been recorded in the current entity pass stencil.
std::optional< Rect > CurrentClipCoverage() const
void PushSubpass(std::optional< Rect > subpass_coverage, size_t clip_height)
const std::vector< ReplayResult > & GetReplayEntities() const
ClipStateResult RecordClip(const ClipContents &clip_contents, Matrix transform, Point global_pass_position, uint32_t clip_depth, size_t clip_height_floor, bool is_aa)
ClipStateResult RecordRestore(Point global_pass_position, size_t restore_height)
EntityPassClipStack(const Rect &initial_coverage_rect)
Create a new [EntityPassClipStack] with an initialized coverage rect.
const std::vector< ClipCoverageLayer > GetClipCoverageLayers() const
A 4x4 matrix using column-major storage.
Definition: matrix.h:37