| Flutter Impeller |

clip_contents.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_CONTENTS_CLIP_CONTENTS_H_
6 #define FLUTTER_IMPELLER_ENTITY_CONTENTS_CLIP_CONTENTS_H_
7
8 #include <functional>
9 #include <memory>
10 #include <vector>
11
12 #include "impeller/entity/contents/contents.h"
13 #include "impeller/entity/entity.h"
14 #include "impeller/entity/geometry/geometry.h"
15
16 namespace impeller {
17
18 class ClipContents final : public Contents {
19 public:
20 ClipContents();
21
22 ~ClipContents();
23
24 void SetGeometry(const std::shared_ptr<Geometry>& geometry);
25
26 void SetClipOperation(Entity::ClipOperation clip_op);
27
28 // |Contents|
29 std::optional<Rect> GetCoverage(const Entity& entity) const override;
30
31 // |Contents|
32 ClipCoverage GetClipCoverage(
33 const Entity& entity,
34 const std::optional<Rect>& current_clip_coverage) const override;
35
36 // |Contents|
37 bool ShouldRender(const Entity& entity,
38 const std::optional<Rect> clip_coverage) const override;
39
40 // |Contents|
41 bool Render(const ContentContext& renderer,
42 const Entity& entity,
43 RenderPass& pass) const override;
44 // |Contents|
45 bool CanInheritOpacity(const Entity& entity) const override;
46
47 // |Contents|
48 void SetInheritedOpacity(Scalar opacity) override;
49
50 private:
51 std::shared_ptr<Geometry> geometry_;
52 Entity::ClipOperation clip_op_ = Entity::ClipOperation::kIntersect;
53
54 ClipContents(const ClipContents&) = delete;
55
56 ClipContents& operator=(const ClipContents&) = delete;
57 };
58
59 class ClipRestoreContents final : public Contents {
60 public:
61 ClipRestoreContents();
62
63 ~ClipRestoreContents();
64
65 void SetRestoreHeight(size_t clip_height);
66
67 size_t GetRestoreHeight() const;
68
69 /// @brief The area on the pass texture where this clip restore will be
70 /// applied. If unset, the entire pass texture will be restored.
71 ///
72 /// @note This rectangle is not transformed by the entity's transform.
73 void SetRestoreCoverage(std::optional<Rect> coverage);
74
75 // |Contents|
76 std::optional<Rect> GetCoverage(const Entity& entity) const override;
77
78 // |Contents|
79 ClipCoverage GetClipCoverage(
80 const Entity& entity,
81 const std::optional<Rect>& current_clip_coverage) const override;
82
83 // |Contents|
84 bool ShouldRender(const Entity& entity,
85 const std::optional<Rect> clip_coverage) const override;
86
87 // |Contents|
88 bool Render(const ContentContext& renderer,
89 const Entity& entity,
90 RenderPass& pass) const override;
91
92 // |Contents|
93 bool CanInheritOpacity(const Entity& entity) const override;
94
95 // |Contents|
96 void SetInheritedOpacity(Scalar opacity) override;
97
98 private:
99 std::optional<Rect> restore_coverage_;
100 size_t restore_height_ = 0;
101
102 ClipRestoreContents(const ClipRestoreContents&) = delete;
103
104 ClipRestoreContents& operator=(const ClipRestoreContents&) = delete;
105 };
106
107 } // namespace impeller
108
109 #endif // FLUTTER_IMPELLER_ENTITY_CONTENTS_CLIP_CONTENTS_H_
impeller::Entity::ClipOperation::kIntersect
@ kIntersect
contents.h
impeller::ClipRestoreContents::ClipRestoreContents
ClipRestoreContents()
impeller::Scalar
float Scalar
Definition: scalar.h:18
impeller::ClipRestoreContents::GetCoverage
std::optional< Rect > GetCoverage(const Entity &entity) const override
Get the area of the render pass that will be affected when this contents is rendered.
Definition: clip_contents.cc:207
entity.h
impeller::ClipRestoreContents::CanInheritOpacity
bool CanInheritOpacity(const Entity &entity) const override
Whether or not this contents can accept the opacity peephole optimization.
Definition: clip_contents.cc:224
impeller::ClipContents::SetClipOperation
void SetClipOperation(Entity::ClipOperation clip_op)
Definition: clip_contents.cc:38
impeller::ClipRestoreContents::SetRestoreCoverage
void SetRestoreCoverage(std::optional< Rect > coverage)
The area on the pass texture where this clip restore will be applied. If unset, the entire pass textu...
Definition: clip_contents.cc:202
impeller::ClipRestoreContents::GetRestoreHeight
size_t GetRestoreHeight() const
Definition: clip_contents.cc:198
impeller::ClipRestoreContents::~ClipRestoreContents
~ClipRestoreContents()
impeller::ClipContents::ShouldRender
bool ShouldRender(const Entity &entity, const std::optional< Rect > clip_coverage) const override
Definition: clip_contents.cc:74
impeller::ClipContents::GetClipCoverage
ClipCoverage GetClipCoverage(const Entity &entity, const std::optional< Rect > &current_clip_coverage) const override
Given the current pass space bounding rectangle of the clip buffer, return the expected clip coverage...
Definition: clip_contents.cc:46
impeller::Entity
Definition: entity.h:20
impeller::ClipContents::SetGeometry
void SetGeometry(const std::shared_ptr< Geometry > &geometry)
Definition: clip_contents.cc:34
impeller::ClipContents::ClipContents
ClipContents()
impeller::ClipRestoreContents::Render
bool Render(const ContentContext &renderer, const Entity &entity, RenderPass &pass) const override
Definition: clip_contents.cc:230
impeller::ClipContents::~ClipContents
~ClipContents()
impeller::ClipContents::GetCoverage
std::optional< Rect > GetCoverage(const Entity &entity) const override
Get the area of the render pass that will be affected when this contents is rendered.
Definition: clip_contents.cc:42
geometry.h
impeller::ClipRestoreContents::SetInheritedOpacity
void SetInheritedOpacity(Scalar opacity) override
Inherit the provided opacity.
Definition: clip_contents.cc:228
impeller::ClipRestoreContents
Definition: clip_contents.h:59
impeller::ClipContents::Render
bool Render(const ContentContext &renderer, const Entity &entity, RenderPass &pass) const override
Definition: clip_contents.cc:85
impeller::RenderPass
Render passes encode render commands directed as one specific render target into an underlying comman...
Definition: render_pass.h:33
impeller::ClipRestoreContents::ShouldRender
bool ShouldRender(const Entity &entity, const std::optional< Rect > clip_coverage) const override
Definition: clip_contents.cc:218
impeller::ClipRestoreContents::GetClipCoverage
ClipCoverage GetClipCoverage(const Entity &entity, const std::optional< Rect > &current_clip_coverage) const override
Given the current pass space bounding rectangle of the clip buffer, return the expected clip coverage...
Definition: clip_contents.cc:212
impeller::Contents::ClipCoverage
Definition: contents.h:37
impeller::ClipContents::CanInheritOpacity
bool CanInheritOpacity(const Entity &entity) const override
Whether or not this contents can accept the opacity peephole optimization.
Definition: clip_contents.cc:79
impeller::ClipContents
Definition: clip_contents.h:18
impeller::Entity::ClipOperation
ClipOperation
Definition: entity.h:61
impeller::ClipContents::SetInheritedOpacity
void SetInheritedOpacity(Scalar opacity) override
Inherit the provided opacity.
Definition: clip_contents.cc:83
impeller::ClipRestoreContents::SetRestoreHeight
void SetRestoreHeight(size_t clip_height)
Definition: clip_contents.cc:194
impeller::Contents
Definition: contents.h:31
impeller
Definition: aiks_blend_unittests.cc:18
impeller::ContentContext
Definition: content_context.h:366