| 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/contents.h"
9 #include "impeller/entity/entity.h"
10 #include "impeller/geometry/rect.h"
11
12 namespace impeller {
13
14 struct ClipCoverageLayer {
15 std::optional<Rect> coverage;
16 size_t clip_depth;
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.
24 class EntityPassClipStack {
25 public:
26 struct ReplayResult {
27 Entity entity;
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_depth);
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.
55 ClipStateResult ApplyClipState(Contents::ClipCoverage global_clip_coverage,
56 Entity& entity,
57 size_t clip_depth_floor,
58 Point global_pass_position);
59
60 // Visible for testing.
61 void RecordEntity(const Entity& entity,
62 Contents::ClipCoverage::Type type,
63 std::optional<Rect> clip_coverage);
64
65 // Visible for testing.
66 const std::vector<ReplayResult>& GetReplayEntities() const;
67
68 // Visible for testing.
69 const std::vector<ClipCoverageLayer> GetClipCoverageLayers() const;
70
71 private:
72 struct SubpassState {
73 std::vector<ReplayResult> rendered_clip_entities;
74 std::vector<ClipCoverageLayer> clip_coverage;
75 };
76
77 SubpassState& GetCurrentSubpassState();
78
79 std::vector<SubpassState> subpass_state_;
80 };
81
82 } // namespace impeller
83
84 #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::Contents::ClipCoverage::Type
Type
Definition: contents.h:41
entity.h
impeller::EntityPassClipStack::GetClipCoverageLayers
const std::vector< ClipCoverageLayer > GetClipCoverageLayers() const
Definition: entity_pass_clip_stack.cc:48
impeller::EntityPassClipStack::~EntityPassClipStack
~EntityPassClipStack()=default
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::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:21
impeller::EntityPassClipStack::GetReplayEntities
const std::vector< ReplayResult > & GetReplayEntities() const
Definition: entity_pass_clip_stack.cc:169
impeller::EntityPassClipStack::ApplyClipState
ClipStateResult ApplyClipState(Contents::ClipCoverage global_clip_coverage, Entity &entity, size_t clip_depth_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:52
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_depth)
Definition: entity_pass_clip_stack.cc:32
impeller::EntityPassClipStack::PopSubpass
void PopSubpass()
Definition: entity_pass_clip_stack.cc:43
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:144
impeller::ClipCoverageLayer::clip_depth
size_t clip_depth
Definition: entity_pass_clip_stack.h:16
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:40
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: aiks_blur_unittests.cc:20
impeller::TRect< Scalar >