| Flutter Impeller |

filter_input.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_FILTERS_INPUTS_FILTER_INPUT_H_
6 #define FLUTTER_IMPELLER_ENTITY_CONTENTS_FILTERS_INPUTS_FILTER_INPUT_H_
7
8 #include <memory>
9 #include <optional>
10 #include <variant>
11 #include <vector>
12
13 #include "impeller/entity/contents/contents.h"
14 #include "impeller/entity/entity.h"
15 #include "impeller/geometry/rect.h"
16
17 namespace impeller {
18
19 class ContentContext;
20 class FilterContents;
21
22 /// `FilterInput` is a lazy/single eval `Snapshot` which may be shared across
23 /// filter parameters and used to evaluate input coverage.
24 ///
25 /// A `FilterInput` can be re-used for any filter inputs across an entity's
26 /// filter graph without repeating subpasses unnecessarily.
27 ///
28 /// Filters may decide to not evaluate inputs in situations where they won't
29 /// contribute to the filter's output texture.
30 class FilterInput {
31 public:
32 using Ref = std::shared_ptr<FilterInput>;
33 using Vector = std::vector<FilterInput::Ref>;
34 using Variant = std::variant<std::shared_ptr<FilterContents>,
35 std::shared_ptr<Contents>,
36 std::shared_ptr<Texture>,
37 Rect>;
38
39 virtual ~FilterInput();
40
41 static FilterInput::Ref Make(Variant input, bool msaa_enabled = true);
42
43 static FilterInput::Ref Make(std::shared_ptr<Texture> input,
44 Matrix local_transform);
45
46 static FilterInput::Vector Make(std::initializer_list<Variant> inputs);
47
48 virtual Variant GetInput() const = 0;
49
50 virtual std::optional<Snapshot> GetSnapshot(
51 const std::string& label,
52 const ContentContext& renderer,
53 const Entity& entity,
54 std::optional<Rect> coverage_limit = std::nullopt) const = 0;
55
56 std::optional<Rect> GetLocalCoverage(const Entity& entity) const;
57
58 virtual std::optional<Rect> GetCoverage(const Entity& entity) const = 0;
59
60 virtual std::optional<Rect> GetSourceCoverage(const Matrix& effect_transform,
61 const Rect& output_limit) const;
62
63 /// @brief Get the local transform of this filter input. This transform is
64 /// relative to the `Entity` transform space.
65 virtual Matrix GetLocalTransform(const Entity& entity) const;
66
67 /// @brief Get the transform of this `FilterInput`. This is equivalent to
68 /// calling `entity.GetTransform() * GetLocalTransform()`.
69 virtual Matrix GetTransform(const Entity& entity) const;
70
71 /// @see `Contents::PopulateGlyphAtlas`
72 virtual void PopulateGlyphAtlas(
73 const std::shared_ptr<LazyGlyphAtlas>& lazy_glyph_atlas,
74 Scalar scale);
75
76 /// @see `FilterContents::HasBasisTransforms`
77 virtual bool IsTranslationOnly() const;
78
79 /// @brief Returns `true` unless this input is a `FilterInput`, which may
80 /// take other inputs.
81 virtual bool IsLeaf() const;
82
83 /// @brief Replaces the inputs of all leaf `FilterContents` with a new set
84 /// of `inputs`.
85 /// @see `FilterInput::IsLeaf`
86 virtual void SetLeafInputs(const FilterInput::Vector& inputs);
87
88 /// @brief Sets the effect transform of filter inputs.
89 virtual void SetEffectTransform(const Matrix& matrix);
90
91 /// @brief Turns on subpass mode for filter inputs.
92 virtual void SetRenderingMode(Entity::RenderingMode rendering_mode);
93 };
94
95 } // namespace impeller
96
97 #endif // FLUTTER_IMPELLER_ENTITY_CONTENTS_FILTERS_INPUTS_FILTER_INPUT_H_
contents.h
impeller::Scalar
float Scalar
Definition: scalar.h:18
impeller::FilterInput::SetEffectTransform
virtual void SetEffectTransform(const Matrix &matrix)
Sets the effect transform of filter inputs.
Definition: filter_input.cc:95
entity.h
impeller::FilterInput::IsLeaf
virtual bool IsLeaf() const
Returns true unless this input is a FilterInput, which may take other inputs.
Definition: filter_input.cc:89
impeller::FilterInput::Make
static FilterInput::Ref Make(Variant input, bool msaa_enabled=true)
Definition: filter_input.cc:19
impeller::FilterInput::IsTranslationOnly
virtual bool IsTranslationOnly() const
Definition: filter_input.cc:85
impeller::FilterInput::Ref
std::shared_ptr< FilterInput > Ref
Definition: filter_input.h:32
impeller::FilterInput::GetTransform
virtual Matrix GetTransform(const Entity &entity) const
Get the transform of this FilterInput. This is equivalent to calling entity.GetTransform() * GetLocal...
Definition: filter_input.cc:75
impeller::FilterInput::GetCoverage
virtual std::optional< Rect > GetCoverage(const Entity &entity) const =0
impeller::Entity
Definition: entity.h:21
impeller::FilterInput
Definition: filter_input.h:30
impeller::FilterInput::GetInput
virtual Variant GetInput() const =0
impeller::FilterInput::Variant
std::variant< std::shared_ptr< FilterContents >, std::shared_ptr< Contents >, std::shared_ptr< Texture >, Rect > Variant
Definition: filter_input.h:37
impeller::FilterInput::SetLeafInputs
virtual void SetLeafInputs(const FilterInput::Vector &inputs)
Replaces the inputs of all leaf FilterContents with a new set of inputs.
Definition: filter_input.cc:93
impeller::FilterInput::SetRenderingMode
virtual void SetRenderingMode(Entity::RenderingMode rendering_mode)
Turns on subpass mode for filter inputs.
Definition: filter_input.cc:97
rect.h
impeller::FilterInput::GetLocalCoverage
std::optional< Rect > GetLocalCoverage(const Entity &entity) const
Definition: filter_input.cc:63
impeller::Entity::RenderingMode
RenderingMode
Definition: entity.h:26
impeller::FilterInput::Vector
std::vector< FilterInput::Ref > Vector
Definition: filter_input.h:33
impeller
Definition: aiks_context.cc:10
impeller::ContentContext
Definition: content_context.h:332
impeller::FilterInput::GetSourceCoverage
virtual std::optional< Rect > GetSourceCoverage(const Matrix &effect_transform, const Rect &output_limit) const
Definition: filter_input.cc:69
impeller::TRect< Scalar >
impeller::FilterInput::PopulateGlyphAtlas
virtual void PopulateGlyphAtlas(const std::shared_ptr< LazyGlyphAtlas > &lazy_glyph_atlas, Scalar scale)
Definition: filter_input.cc:79
impeller::Matrix
A 4x4 matrix using column-major storage.
Definition: matrix.h:37
impeller::FilterInput::GetLocalTransform
virtual Matrix GetLocalTransform(const Entity &entity) const
Get the local transform of this filter input. This transform is relative to the Entity transform spac...
Definition: filter_input.cc:59
impeller::FilterInput::GetSnapshot
virtual std::optional< Snapshot > GetSnapshot(const std::string &label, const ContentContext &renderer, const Entity &entity, std::optional< Rect > coverage_limit=std::nullopt) const =0
impeller::FilterInput::~FilterInput
virtual ~FilterInput()