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 
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,
55  int32_t mip_count = 1) const = 0;
56 
57  std::optional<Rect> GetLocalCoverage(const Entity& entity) const;
58 
59  virtual std::optional<Rect> GetCoverage(const Entity& entity) const = 0;
60 
61  virtual std::optional<Rect> GetSourceCoverage(const Matrix& effect_transform,
62  const Rect& output_limit) const;
63 
64  /// @brief Get the local transform of this filter input. This transform is
65  /// relative to the `Entity` transform space.
66  virtual Matrix GetLocalTransform(const Entity& entity) const;
67 
68  /// @brief Get the transform of this `FilterInput`. This is equivalent to
69  /// calling `entity.GetTransform() * GetLocalTransform()`.
70  virtual Matrix GetTransform(const Entity& entity) const;
71 
72  /// @see `Contents::PopulateGlyphAtlas`
73  virtual void PopulateGlyphAtlas(
74  const std::shared_ptr<LazyGlyphAtlas>& lazy_glyph_atlas,
75  Scalar scale);
76 
77  /// @see `FilterContents::HasBasisTransforms`
78  virtual bool IsTranslationOnly() const;
79 
80  /// @brief Returns `true` unless this input is a `FilterInput`, which may
81  /// take other inputs.
82  virtual bool IsLeaf() const;
83 
84  /// @brief Replaces the inputs of all leaf `FilterContents` with a new set
85  /// of `inputs`.
86  /// @see `FilterInput::IsLeaf`
87  virtual void SetLeafInputs(const FilterInput::Vector& inputs);
88 
89  /// @brief Sets the effect transform of filter inputs.
90  virtual void SetEffectTransform(const Matrix& matrix);
91 
92  /// @brief Turns on subpass mode for filter inputs.
93  virtual void SetRenderingMode(Entity::RenderingMode rendering_mode);
94 };
95 
96 } // namespace impeller
97 
98 #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
scale
const Scalar scale
Definition: stroke_path_geometry.cc:297
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, int32_t mip_count=1) const =0
impeller::Entity::RenderingMode
RenderingMode
Definition: entity.h:28
impeller::FilterInput::Vector
std::vector< FilterInput::Ref > Vector
Definition: filter_input.h:33
impeller
Definition: aiks_blur_unittests.cc:20
impeller::ContentContext
Definition: content_context.h:392
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::~FilterInput
virtual ~FilterInput()