Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
matrix_filter_contents.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
7namespace impeller {
8
10
12
14 matrix_ = matrix;
15}
16
18 Entity::RenderingMode rendering_mode) {
19 rendering_mode_ = rendering_mode;
21}
22
26
28 sampler_descriptor_ = std::move(desc);
29}
30
32 const FilterInput::Vector& inputs,
33 const ContentContext& renderer,
34 const Entity& entity,
35 const Matrix& effect_transform,
36 const Rect& coverage,
37 const std::optional<Rect>& coverage_hint) const {
38 auto snapshot = inputs[0]->GetSnapshot("Matrix", renderer, entity);
39 if (!snapshot.has_value()) {
40 return std::nullopt;
41 }
42
43 // The filter's matrix needs to be applied within the space defined by the
44 // scene's current transform matrix (CTM). For example: If the CTM is
45 // scaled up, then translations applied by the matrix should be magnified
46 // accordingly.
47 //
48 // To accomplish this, we sandwich the filter's matrix within the CTM in both
49 // cases. But notice that for the subpass backdrop filter case, we use the
50 // "effect transform" instead of the Entity's transform!
51 //
52 // That's because in the subpass backdrop filter case, the Entity's transform
53 // isn't actually the captured CTM of the scene like it usually is; instead,
54 // it's just a screen space translation that offsets the backdrop texture (as
55 // mentioned above). And so we sneak the subpass's captured CTM in through the
56 // effect transform.
57
58 auto transform = rendering_mode_ == Entity::RenderingMode::kSubpass
59 ? effect_transform
60 : entity.GetTransform();
61 snapshot->transform = transform * //
62 matrix_ * //
63 transform.Invert() * //
64 snapshot->transform;
65
66 snapshot->sampler_descriptor = sampler_descriptor_;
67 if (!snapshot.has_value()) {
68 return std::nullopt;
69 }
70 return Entity::FromSnapshot(snapshot.value(), entity.GetBlendMode());
71}
72
74 const Matrix& effect_transform,
75 const Rect& output_limit) const {
76 auto transform = effect_transform * //
77 matrix_ * //
78 effect_transform.Invert(); //
79 if (transform.GetDeterminant() == 0.0) {
80 return std::nullopt;
81 }
82 auto inverse = transform.Invert();
83 return output_limit.TransformBounds(inverse);
84}
85
87 const FilterInput::Vector& inputs,
88 const Entity& entity,
89 const Matrix& effect_transform) const {
90 if (inputs.empty()) {
91 return std::nullopt;
92 }
93
94 auto coverage = inputs[0]->GetCoverage(entity);
95 if (!coverage.has_value()) {
96 return std::nullopt;
97 }
98 auto& m = rendering_mode_ == Entity::RenderingMode::kSubpass
99 ? effect_transform
100 : inputs[0]->GetTransform(entity);
101 auto transform = m * //
102 matrix_ * //
103 m.Invert(); //
104 return coverage->TransformBounds(transform);
105}
106
107} // namespace impeller
static Entity FromSnapshot(const Snapshot &snapshot, BlendMode blend_mode=BlendMode::kSourceOver)
Create an entity that can be used to render a given snapshot.
Definition entity.cc:22
BlendMode GetBlendMode() const
Definition entity.cc:119
const Matrix & GetTransform() const
Get the global transform matrix for this Entity.
Definition entity.cc:46
virtual bool IsTranslationOnly() const
Returns true if this filter graph doesn't perform any basis transforms to the filtered content....
virtual void SetRenderingMode(Entity::RenderingMode rendering_mode)
Marks this filter chain as applying in a subpass scenario.
std::vector< FilterInput::Ref > Vector
std::optional< Rect > GetFilterCoverage(const FilterInput::Vector &inputs, const Entity &entity, const Matrix &effect_transform) const override
Internal utility method for |GetLocalCoverage| that computes the output coverage of this filter acros...
std::optional< Rect > GetFilterSourceCoverage(const Matrix &effect_transform, const Rect &output_limit) const override
Internal utility method for |GetSourceCoverage| that computes the inverse effect of this transform on...
void SetRenderingMode(Entity::RenderingMode rendering_mode) override
Marks this filter chain as applying in a subpass scenario.
std::optional< Entity > RenderFilter(const FilterInput::Vector &input_textures, const ContentContext &renderer, const Entity &entity, const Matrix &effect_transform, const Rect &coverage, const std::optional< Rect > &coverage_hint) const override
Converts zero or more filter inputs into a render instruction.
bool IsTranslationOnly() const override
Returns true if this filter graph doesn't perform any basis transforms to the filtered content....
void SetSamplerDescriptor(SamplerDescriptor desc)
static SkColor4f transform(SkColor4f c, SkColorSpace *src, SkColorSpace *dst)
Definition p3.cpp:47
A 4x4 matrix using column-major storage.
Definition matrix.h:37
constexpr bool IsIdentity() const
Definition matrix.h:377
constexpr Matrix Basis() const
The Matrix without its w components (without translation).
Definition matrix.h:229
Matrix Invert() const
Definition matrix.cc:97
constexpr TRect TransformBounds(const Matrix &transform) const
Creates a new bounding box that contains this transformed rectangle.
Definition rect.h:440