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