| 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 "flutter/fml/macros.h"
13 #include "impeller/entity/contents/contents.h"
14 #include "impeller/entity/entity.h"
15 #include "impeller/entity/geometry/geometry.h"
16
17 namespace impeller {
18
19 class ClipContents final : public Contents {
20 public:
21 ClipContents();
22
23 ~ClipContents();
24
25 void SetGeometry(const std::shared_ptr<Geometry>& geometry);
26
27 void SetClipOperation(Entity::ClipOperation clip_op);
28
29 // |Contents|
30 std::optional<Rect> GetCoverage(const Entity& entity) const override;
31
32 // |Contents|
33 ClipCoverage GetClipCoverage(
34 const Entity& entity,
35 const std::optional<Rect>& current_clip_coverage) const override;
36
37 // |Contents|
38 bool ShouldRender(const Entity& entity,
39 const std::optional<Rect> clip_coverage) const override;
40
41 // |Contents|
42 bool Render(const ContentContext& renderer,
43 const Entity& entity,
44 RenderPass& pass) const override;
45 // |Contents|
46 bool CanInheritOpacity(const Entity& entity) const override;
47
48 // |Contents|
49 void SetInheritedOpacity(Scalar opacity) override;
50
51 private:
52 bool RenderDepthClip(const ContentContext& renderer,
53 const Entity& entity,
54 RenderPass& pass,
55 Entity::ClipOperation clip_op,
56 const Geometry& geometry) const;
57 bool RenderStencilClip(const ContentContext& renderer,
58 const Entity& entity,
59 RenderPass& pass,
60 Entity::ClipOperation clip_op,
61 const Geometry& geometry) const;
62
63 std::shared_ptr<Geometry> geometry_;
64 Entity::ClipOperation clip_op_ = Entity::ClipOperation::kIntersect;
65
66 ClipContents(const ClipContents&) = delete;
67
68 ClipContents& operator=(const ClipContents&) = delete;
69 };
70
71 class ClipRestoreContents final : public Contents {
72 public:
73 ClipRestoreContents();
74
75 ~ClipRestoreContents();
76
77 /// @brief The area on the pass texture where this clip restore will be
78 /// applied. If unset, the entire pass texture will be restored.
79 ///
80 /// @note This rectangle is not transformed by the entity's transform.
81 void SetRestoreCoverage(std::optional<Rect> coverage);
82
83 // |Contents|
84 std::optional<Rect> GetCoverage(const Entity& entity) const override;
85
86 // |Contents|
87 ClipCoverage GetClipCoverage(
88 const Entity& entity,
89 const std::optional<Rect>& current_clip_coverage) const override;
90
91 // |Contents|
92 bool ShouldRender(const Entity& entity,
93 const std::optional<Rect> clip_coverage) const override;
94
95 // |Contents|
96 bool Render(const ContentContext& renderer,
97 const Entity& entity,
98 RenderPass& pass) const override;
99
100 // |Contents|
101 bool CanInheritOpacity(const Entity& entity) const override;
102
103 // |Contents|
104 void SetInheritedOpacity(Scalar opacity) override;
105
106 private:
107 std::optional<Rect> restore_coverage_;
108
109 ClipRestoreContents(const ClipRestoreContents&) = delete;
110
111 ClipRestoreContents& operator=(const ClipRestoreContents&) = delete;
112 };
113
114 } // namespace impeller
115
116 #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:261
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:278
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:256
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:21
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:284
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:282
impeller::ClipRestoreContents
Definition: clip_contents.h:71
impeller::ClipContents::Render
bool Render(const ContentContext &renderer, const Entity &entity, RenderPass &pass) const override
Definition: clip_contents.cc:235
impeller::RenderPass
Render passes encode render commands directed as one specific render target into an underlying comman...
Definition: render_pass.h:33
impeller::Geometry
Definition: geometry.h:83
impeller::ClipRestoreContents::ShouldRender
bool ShouldRender(const Entity &entity, const std::optional< Rect > clip_coverage) const override
Definition: clip_contents.cc:272
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:266
impeller::Contents::ClipCoverage
Definition: contents.h:40
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:19
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::Contents
Definition: contents.h:34
impeller
Definition: aiks_blur_unittests.cc:20
impeller::ContentContext
Definition: content_context.h:392