Flutter Engine
The Flutter Engine
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
16
17namespace impeller {
18
19class ContentContext;
20class 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.
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,
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,
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_
virtual std::optional< Rect > GetSourceCoverage(const Matrix &effect_transform, const Rect &output_limit) const
Definition: filter_input.cc:69
virtual void SetEffectTransform(const Matrix &matrix)
Sets the effect transform of filter inputs.
Definition: filter_input.cc:95
virtual Variant GetInput() const =0
std::shared_ptr< FilterInput > Ref
Definition: filter_input.h:32
virtual bool IsLeaf() const
Returns true unless this input is a FilterInput, which may take other inputs.
Definition: filter_input.cc:89
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
virtual void PopulateGlyphAtlas(const std::shared_ptr< LazyGlyphAtlas > &lazy_glyph_atlas, Scalar scale)
Definition: filter_input.cc:79
std::optional< Rect > GetLocalCoverage(const Entity &entity) const
Definition: filter_input.cc:63
virtual std::optional< Rect > GetCoverage(const Entity &entity) const =0
std::variant< std::shared_ptr< FilterContents >, std::shared_ptr< Contents >, std::shared_ptr< Texture >, Rect > Variant
Definition: filter_input.h:37
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
static FilterInput::Ref Make(Variant input, bool msaa_enabled=true)
Definition: filter_input.cc:19
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
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
std::vector< FilterInput::Ref > Vector
Definition: filter_input.h:33
virtual bool IsTranslationOnly() const
Definition: filter_input.cc:85
virtual void SetRenderingMode(Entity::RenderingMode rendering_mode)
Turns on subpass mode for filter inputs.
Definition: filter_input.cc:97
unsigned useCenter Optional< SkMatrix > matrix
Definition: SkRecords.h:258
float Scalar
Definition: scalar.h:18
const Scalar scale
A 4x4 matrix using column-major storage.
Definition: matrix.h:37