| 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 #pragma once
6
7 #include <functional>
8 #include <memory>
9 #include <vector>
10
11 #include "flutter/fml/macros.h"
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(std::unique_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 StencilCoverage GetStencilCoverage(
33 const Entity& entity,
34 const std::optional<Rect>& current_stencil_coverage) const override;
35
36 // |Contents|
37 bool ShouldRender(const Entity& entity,
38 const std::optional<Rect>& stencil_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::unique_ptr<Geometry> geometry_;
52 Entity::ClipOperation clip_op_ = Entity::ClipOperation::kIntersect;
53
54 FML_DISALLOW_COPY_AND_ASSIGN(ClipContents);
55 };
56
57 class ClipRestoreContents final : public Contents {
58 public:
59 ClipRestoreContents();
60
61 ~ClipRestoreContents();
62
63 /// @brief The area on the pass texture where this clip restore will be
64 /// applied. If unset, the entire pass texture will be restored.
65 ///
66 /// @note This rectangle is not transformed by the entity's transformation.
67 void SetRestoreCoverage(std::optional<Rect> coverage);
68
69 // |Contents|
70 std::optional<Rect> GetCoverage(const Entity& entity) const override;
71
72 // |Contents|
73 StencilCoverage GetStencilCoverage(
74 const Entity& entity,
75 const std::optional<Rect>& current_stencil_coverage) const override;
76
77 // |Contents|
78 bool ShouldRender(const Entity& entity,
79 const std::optional<Rect>& stencil_coverage) const override;
80
81 // |Contents|
82 bool Render(const ContentContext& renderer,
83 const Entity& entity,
84 RenderPass& pass) const override;
85
86 // |Contents|
87 bool CanInheritOpacity(const Entity& entity) const override;
88
89 // |Contents|
90 void SetInheritedOpacity(Scalar opacity) override;
91
92 private:
93 std::optional<Rect> restore_coverage_;
94
95 FML_DISALLOW_COPY_AND_ASSIGN(ClipRestoreContents);
96 };
97
98 } // namespace impeller
impeller::ClipRestoreContents::ShouldRender
bool ShouldRender(const Entity &entity, const std::optional< Rect > &stencil_coverage) const override
Definition: clip_contents.cc:164
impeller::Entity::ClipOperation::kIntersect
@ kIntersect
impeller::ClipRestoreContents::GetStencilCoverage
StencilCoverage GetStencilCoverage(const Entity &entity, const std::optional< Rect > &current_stencil_coverage) const override
Given the current screen space bounding rectangle of the stencil, return the expected stencil coverag...
Definition: clip_contents.cc:158
contents.h
impeller::ClipRestoreContents::ClipRestoreContents
ClipRestoreContents()
impeller::Scalar
float Scalar
Definition: scalar.h:15
impeller::ClipRestoreContents::GetCoverage
std::optional< Rect > GetCoverage(const Entity &entity) const override
Get the screen space bounding rectangle that this contents affects.
Definition: clip_contents.cc:153
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:170
impeller::ClipContents::SetGeometry
void SetGeometry(std::unique_ptr< Geometry > geometry)
Definition: clip_contents.cc:25
impeller::ClipContents::SetClipOperation
void SetClipOperation(Entity::ClipOperation clip_op)
Definition: clip_contents.cc:29
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:148
impeller::ClipRestoreContents::~ClipRestoreContents
~ClipRestoreContents()
impeller::Entity
Definition: entity.h:21
impeller::ClipContents::ClipContents
ClipContents()
impeller::Contents::StencilCoverage
Definition: contents.h:39
impeller::ClipRestoreContents::Render
bool Render(const ContentContext &renderer, const Entity &entity, RenderPass &pass) const override
Definition: clip_contents.cc:176
impeller::ClipContents::~ClipContents
~ClipContents()
impeller::ClipContents::GetCoverage
std::optional< Rect > GetCoverage(const Entity &entity) const override
Get the screen space bounding rectangle that this contents affects.
Definition: clip_contents.cc:33
geometry.h
impeller::ClipRestoreContents::SetInheritedOpacity
void SetInheritedOpacity(Scalar opacity) override
Inherit the provided opacity.
Definition: clip_contents.cc:174
impeller::ClipContents::GetStencilCoverage
StencilCoverage GetStencilCoverage(const Entity &entity, const std::optional< Rect > &current_stencil_coverage) const override
Given the current screen space bounding rectangle of the stencil, return the expected stencil coverag...
Definition: clip_contents.cc:37
impeller::ClipRestoreContents
Definition: clip_contents.h:57
impeller::ClipContents::Render
bool Render(const ContentContext &renderer, const Entity &entity, RenderPass &pass) const override
Definition: clip_contents.cc:79
impeller::RenderPass
Render passes encode render commands directed as one specific render target into an underlying comman...
Definition: render_pass.h:27
impeller::ClipContents::ShouldRender
bool ShouldRender(const Entity &entity, const std::optional< Rect > &stencil_coverage) const override
Definition: clip_contents.cc:67
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:73
impeller::ClipContents
Definition: clip_contents.h:18
impeller::Entity::ClipOperation
ClipOperation
Definition: entity.h:59
impeller::ClipContents::SetInheritedOpacity
void SetInheritedOpacity(Scalar opacity) override
Inherit the provided opacity.
Definition: clip_contents.cc:77
impeller::Contents
Definition: contents.h:33
impeller
Definition: aiks_context.cc:10
impeller::ContentContext
Definition: content_context.h:344