| 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
8 #include "impeller/entity/contents/clip_contents.h"
9 #include "impeller/geometry/rect.h"
10
11 namespace impeller {
12
13 struct ClipCoverageLayer {
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.
23 class EntityPassClipStack {
24 public:
25 struct ReplayResult {
26 ClipContents clip_contents;
27 Matrix transform;
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,
55 Matrix transform,
56 Point global_pass_position,
57 uint32_t clip_depth,
58 size_t clip_height_floor,
59 bool is_aa);
60
61 ReplayResult& GetLastReplayResult() {
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_
impeller::ClipContents
Definition: clip_contents.h:29
impeller::EntityPassClipStack
A class that tracks all clips that have been recorded in the current entity pass stencil.
Definition: entity_pass_clip_stack.h:23
impeller::EntityPassClipStack::CurrentClipCoverage
std::optional< Rect > CurrentClipCoverage() const
Definition: entity_pass_clip_stack.cc:24
impeller::EntityPassClipStack::PushSubpass
void PushSubpass(std::optional< Rect > subpass_coverage, size_t clip_height)
Definition: entity_pass_clip_stack.cc:32
impeller::EntityPassClipStack::~EntityPassClipStack
~EntityPassClipStack()=default
impeller::EntityPassClipStack::GetLastReplayResult
ReplayResult & GetLastReplayResult()
Definition: entity_pass_clip_stack.h:61
impeller::EntityPassClipStack::GetReplayEntities
const std::vector< ReplayResult > & GetReplayEntities() const
Definition: entity_pass_clip_stack.cc:209
impeller::EntityPassClipStack::RecordClip
ClipStateResult RecordClip(const ClipContents &clip_contents, Matrix transform, Point global_pass_position, uint32_t clip_depth, size_t clip_height_floor, bool is_aa)
Definition: entity_pass_clip_stack.cc:100
impeller::EntityPassClipStack::RecordRestore
ClipStateResult RecordRestore(Point global_pass_position, size_t restore_height)
Definition: entity_pass_clip_stack.cc:54
impeller::EntityPassClipStack::PopSubpass
void PopSubpass()
Definition: entity_pass_clip_stack.cc:44
impeller::EntityPassClipStack::HasCoverage
bool HasCoverage() const
Definition: entity_pass_clip_stack.cc:28
impeller::EntityPassClipStack::EntityPassClipStack
EntityPassClipStack(const Rect &initial_coverage_rect)
Create a new [EntityPassClipStack] with an initialized coverage rect.
Definition: entity_pass_clip_stack.cc:12
impeller::EntityPassClipStack::GetClipCoverageLayers
const std::vector< ClipCoverageLayer > GetClipCoverageLayers() const
Definition: entity_pass_clip_stack.cc:50
clip_contents.h
transform
Matrix transform
Definition: gaussian_blur_filter_contents.cc:312
impeller
Definition: allocation.cc:12
rect.h
impeller::ClipCoverageLayer
Definition: entity_pass_clip_stack.h:13
impeller::ClipCoverageLayer::coverage
std::optional< Rect > coverage
Definition: entity_pass_clip_stack.h:14
impeller::ClipCoverageLayer::clip_height
size_t clip_height
Definition: entity_pass_clip_stack.h:15
impeller::EntityPassClipStack::ClipStateResult
Definition: entity_pass_clip_stack.h:32
impeller::EntityPassClipStack::ClipStateResult::clip_did_change
bool clip_did_change
Definition: entity_pass_clip_stack.h:38
impeller::EntityPassClipStack::ClipStateResult::should_render
bool should_render
Definition: entity_pass_clip_stack.h:35
impeller::EntityPassClipStack::ReplayResult
Definition: entity_pass_clip_stack.h:25
impeller::EntityPassClipStack::ReplayResult::clip_coverage
std::optional< Rect > clip_coverage
Definition: entity_pass_clip_stack.h:28
impeller::EntityPassClipStack::ReplayResult::transform
Matrix transform
Definition: entity_pass_clip_stack.h:27
impeller::EntityPassClipStack::ReplayResult::clip_contents
ClipContents clip_contents
Definition: entity_pass_clip_stack.h:26
impeller::EntityPassClipStack::ReplayResult::clip_depth
uint32_t clip_depth
Definition: entity_pass_clip_stack.h:29
impeller::Matrix
A 4x4 matrix using column-major storage.
Definition: matrix.h:37
impeller::TPoint< Scalar >
impeller::TRect< Scalar >