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 
6 
7 #include <memory>
8 #include <utility>
9 
10 #include "flutter/fml/logging.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 
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 
82 
84 
85 } // namespace impeller
void SetTransform(const Matrix &transform)
Set the global transform matrix for this Entity.
Definition: entity.cc:60
Entity Clone() const
Definition: entity.cc:158
const Matrix & GetTransform() const
Get the global transform matrix for this Entity.
Definition: entity.cc:44
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:81
std::shared_ptr< FilterInput > Ref
Definition: filter_input.h:32
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
std::optional< Rect > GetLocalCoverage(const Entity &entity) const
Definition: filter_input.cc:63
std::variant< std::shared_ptr< FilterContents >, std::shared_ptr< Contents >, std::shared_ptr< Texture >, Rect > Variant
Definition: filter_input.h:37
virtual std::optional< Rect > GetCoverage(const Entity &entity) 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
std::vector< FilterInput::Ref > Vector
Definition: filter_input.h:33
virtual void SetRenderingMode(Entity::RenderingMode rendering_mode)
Turns on subpass mode for filter inputs.
Definition: filter_input.cc:83
A 4x4 matrix using column-major storage.
Definition: matrix.h:37