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 #include "impeller/geometry/rect.h"
11 
12 namespace impeller {
13 
15  std::optional<Rect> coverage;
16  size_t clip_height = 0;
17 };
18 
19 /// @brief A class that tracks all clips that have been recorded in the current
20 /// entity pass stencil.
21 ///
22 /// These clips are replayed when restoring the backdrop so that the
23 /// stencil buffer is left in an identical state.
25  public:
26  struct ReplayResult {
28  std::optional<Rect> clip_coverage;
29  };
30 
31  struct ClipStateResult {
32  /// Whether or not the Entity should be rendered. If false, the Entity may
33  /// be safely skipped.
34  bool should_render = false;
35  /// Whether or not the current clip coverage changed during the call to
36  /// `ApplyClipState`.
37  bool clip_did_change = false;
38  };
39 
40  /// Create a new [EntityPassClipStack] with an initialized coverage rect.
41  explicit EntityPassClipStack(const Rect& initial_coverage_rect);
42 
43  ~EntityPassClipStack() = default;
44 
45  std::optional<Rect> CurrentClipCoverage() const;
46 
47  void PushSubpass(std::optional<Rect> subpass_coverage, size_t clip_height);
48 
49  void PopSubpass();
50 
51  bool HasCoverage() const;
52 
53  /// @brief Applies the current clip state to an Entity. If the given Entity
54  /// is a clip operation, then the clip state is updated accordingly.
56  Entity& entity,
57  size_t clip_height_floor,
58  Point global_pass_position);
59 
60  // Visible for testing.
61  void RecordEntity(const Entity& entity,
63  std::optional<Rect> clip_coverage);
64 
65  const std::vector<ReplayResult>& GetReplayEntities() const;
66 
67  void ActivateClipReplay();
68 
69  /// @brief Returns the next Entity that should be replayed. If there are no
70  /// enities to replay, then nullptr is returned.
71  const ReplayResult* GetNextReplayResult(size_t current_clip_depth);
72 
73  // Visible for testing.
74  const std::vector<ClipCoverageLayer> GetClipCoverageLayers() const;
75 
76  private:
77  struct SubpassState {
78  std::vector<ReplayResult> rendered_clip_entities;
79  std::vector<ClipCoverageLayer> clip_coverage;
80  };
81 
82  SubpassState& GetCurrentSubpassState();
83 
84  std::vector<SubpassState> subpass_state_;
85  size_t next_replay_index_ = 0;
86 };
87 
88 } // namespace impeller
89 
90 #endif // FLUTTER_IMPELLER_ENTITY_ENTITY_PASS_CLIP_STACK_H_
impeller::EntityPassClipStack::ClipStateResult::should_render
bool should_render
Definition: entity_pass_clip_stack.h:34
contents.h
impeller::EntityPassClipStack::PushSubpass
void PushSubpass(std::optional< Rect > subpass_coverage, size_t clip_height)
Definition: entity_pass_clip_stack.cc:33
impeller::Contents::ClipCoverage::Type
Type
Definition: contents.h:38
entity.h
impeller::EntityPassClipStack::GetClipCoverageLayers
const std::vector< ClipCoverageLayer > GetClipCoverageLayers() const
Definition: entity_pass_clip_stack.cc:51
impeller::EntityPassClipStack::~EntityPassClipStack
~EntityPassClipStack()=default
impeller::EntityPassClipStack::HasCoverage
bool HasCoverage() const
Definition: entity_pass_clip_stack.cc:29
impeller::EntityPassClipStack::EntityPassClipStack
EntityPassClipStack(const Rect &initial_coverage_rect)
Create a new [EntityPassClipStack] with an initialized coverage rect.
Definition: entity_pass_clip_stack.cc:13
impeller::EntityPassClipStack::GetNextReplayResult
const ReplayResult * GetNextReplayResult(size_t current_clip_depth)
Returns the next Entity that should be replayed. If there are no enities to replay,...
Definition: entity_pass_clip_stack.cc:194
impeller::ClipCoverageLayer::coverage
std::optional< Rect > coverage
Definition: entity_pass_clip_stack.h:15
impeller::ClipCoverageLayer
Definition: entity_pass_clip_stack.h:14
impeller::Entity
Definition: entity.h:20
impeller::EntityPassClipStack::ApplyClipState
ClipStateResult ApplyClipState(Contents::ClipCoverage global_clip_coverage, Entity &entity, size_t clip_height_floor, Point global_pass_position)
Applies the current clip state to an Entity. If the given Entity is a clip operation,...
Definition: entity_pass_clip_stack.cc:55
impeller::EntityPassClipStack::GetReplayEntities
const std::vector< ReplayResult > & GetReplayEntities() const
Definition: entity_pass_clip_stack.cc:185
impeller::EntityPassClipStack::ActivateClipReplay
void ActivateClipReplay()
Definition: entity_pass_clip_stack.cc:189
impeller::EntityPassClipStack::CurrentClipCoverage
std::optional< Rect > CurrentClipCoverage() const
Definition: entity_pass_clip_stack.cc:25
type
GLenum type
Definition: blit_command_gles.cc:127
impeller::EntityPassClipStack::PopSubpass
void PopSubpass()
Definition: entity_pass_clip_stack.cc:45
impeller::EntityPassClipStack::ReplayResult::clip_coverage
std::optional< Rect > clip_coverage
Definition: entity_pass_clip_stack.h:28
impeller::EntityPassClipStack::ReplayResult::entity
Entity entity
Definition: entity_pass_clip_stack.h:27
impeller::EntityPassClipStack::RecordEntity
void RecordEntity(const Entity &entity, Contents::ClipCoverage::Type type, std::optional< Rect > clip_coverage)
Definition: entity_pass_clip_stack.cc:150
impeller::EntityPassClipStack::ClipStateResult::clip_did_change
bool clip_did_change
Definition: entity_pass_clip_stack.h:37
rect.h
impeller::TPoint< Scalar >
impeller::Contents::ClipCoverage
Definition: contents.h:37
impeller::EntityPassClipStack
A class that tracks all clips that have been recorded in the current entity pass stencil.
Definition: entity_pass_clip_stack.h:24
impeller::EntityPassClipStack::ReplayResult
Definition: entity_pass_clip_stack.h:26
impeller::EntityPassClipStack::ClipStateResult
Definition: entity_pass_clip_stack.h:31
impeller
Definition: allocation.cc:12
impeller::TRect< Scalar >
impeller::ClipCoverageLayer::clip_height
size_t clip_height
Definition: entity_pass_clip_stack.h:16