| Flutter Impeller |

filter_input.cc
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 #include "impeller/entity/contents/filters/inputs/filter_input.h"
6
7 #include <memory>
8 #include <utility>
9
10 #include "flutter/fml/logging.h"
11 #include "impeller/entity/contents/filters/filter_contents.h"
12 #include "impeller/entity/contents/filters/inputs/contents_filter_input.h"
13 #include "impeller/entity/contents/filters/inputs/filter_contents_filter_input.h"
14 #include "impeller/entity/contents/filters/inputs/placeholder_filter_input.h"
15 #include "impeller/entity/contents/filters/inputs/texture_filter_input.h"
16
17 namespace impeller {
18
19 FilterInput::Ref FilterInput::Make(Variant input, bool msaa_enabled) {
20 if (auto filter = std::get_if<std::shared_ptr<FilterContents>>(&input)) {
21 return std::static_pointer_cast<FilterInput>(
22 std::shared_ptr<FilterContentsFilterInput>(
23 new FilterContentsFilterInput(*filter)));
24 }
25
26 if (auto contents = std::get_if<std::shared_ptr<Contents>>(&input)) {
27 return std::static_pointer_cast<FilterInput>(
28 std::shared_ptr<ContentsFilterInput>(
29 new ContentsFilterInput(*contents, msaa_enabled)));
30 }
31
32 if (auto texture = std::get_if<std::shared_ptr<Texture>>(&input)) {
33 return Make(*texture, Matrix());
34 }
35
36 if (auto rect = std::get_if<Rect>(&input)) {
37 return std::shared_ptr<PlaceholderFilterInput>(
38 new PlaceholderFilterInput(*rect));
39 }
40
41 FML_UNREACHABLE();
42 }
43
44 FilterInput::Ref FilterInput::Make(std::shared_ptr<Texture> texture,
45 Matrix local_transform) {
46 return std::shared_ptr<TextureFilterInput>(
47 new TextureFilterInput(std::move(texture), local_transform));
48 }
49
50 FilterInput::Vector FilterInput::Make(std::initializer_list<Variant> inputs) {
51 FilterInput::Vector result;
52 result.reserve(inputs.size());
53 for (const auto& input : inputs) {
54 result.push_back(Make(input));
55 }
56 return result;
57 }
58
59 Matrix FilterInput::GetLocalTransform(const Entity& entity) const {
60 return Matrix();
61 }
62
63 std::optional<Rect> FilterInput::GetLocalCoverage(const Entity& entity) const {
64 Entity local_entity = entity.Clone();
65 local_entity.SetTransform(GetLocalTransform(entity));
66 return GetCoverage(local_entity);
67 }
68
69 std::optional<Rect> FilterInput::GetSourceCoverage(
70 const Matrix& effect_transform,
71 const Rect& output_limit) const {
72 return output_limit;
73 }
74
75 Matrix FilterInput::GetTransform(const Entity& entity) const {
76 return entity.GetTransform() * GetLocalTransform(entity);
77 }
78
79 FilterInput::~FilterInput() = default;
80
81 void FilterInput::SetEffectTransform(const Matrix& matrix) {}
82
83 void FilterInput::SetRenderingMode(Entity::RenderingMode rendering_mode) {}
84
85 } // namespace impeller
impeller::ContentsFilterInput
Definition: contents_filter_input.h:12
impeller::Entity
Definition: entity.h:26
impeller::Entity::SetTransform
void SetTransform(const Matrix &transform)
Set the global transform matrix for this Entity.
Definition: entity.cc:62
impeller::Entity::RenderingMode
RenderingMode
Definition: entity.h:33
impeller::Entity::Clone
Entity Clone() const
Definition: entity.cc:159
impeller::Entity::GetTransform
const Matrix & GetTransform() const
Get the global transform matrix for this Entity.
Definition: entity.cc:46
impeller::FilterContentsFilterInput
Definition: filter_contents_filter_input.h:12
impeller::FilterInput::GetSourceCoverage
virtual std::optional< Rect > GetSourceCoverage(const Matrix &effect_transform, const Rect &output_limit) const
Definition: filter_input.cc:69
impeller::FilterInput::SetEffectTransform
virtual void SetEffectTransform(const Matrix &matrix)
Sets the effect transform of filter inputs.
Definition: filter_input.cc:81
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::GetLocalCoverage
std::optional< Rect > GetLocalCoverage(const Entity &entity) const
Definition: filter_input.cc:63
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::GetCoverage
virtual std::optional< Rect > GetCoverage(const Entity &entity) const =0
impeller::FilterInput::Make
static FilterInput::Ref Make(Variant input, bool msaa_enabled=true)
Definition: filter_input.cc:19
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()
impeller::FilterInput::Vector
std::vector< FilterInput::Ref > Vector
Definition: filter_input.h:33
impeller::FilterInput::SetRenderingMode
virtual void SetRenderingMode(Entity::RenderingMode rendering_mode)
Turns on subpass mode for filter inputs.
Definition: filter_input.cc:83
impeller::PlaceholderFilterInput
Definition: placeholder_filter_input.h:12
impeller::TextureFilterInput
Definition: texture_filter_input.h:14
contents_filter_input.h
filter_contents.h
filter_contents_filter_input.h
filter_input.h
impeller
Definition: allocation.cc:12
placeholder_filter_input.h
impeller::Matrix
A 4x4 matrix using column-major storage.
Definition: matrix.h:37
impeller::TRect< Scalar >
texture_filter_input.h