diff --git a/engine/src/flutter/impeller/display_list/display_list_dispatcher.cc b/engine/src/flutter/impeller/display_list/display_list_dispatcher.cc index 28ef0d73453..627d8f0da1d 100644 --- a/engine/src/flutter/impeller/display_list/display_list_dispatcher.cc +++ b/engine/src/flutter/impeller/display_list/display_list_dispatcher.cc @@ -578,8 +578,10 @@ static std::optional ToImageFilterProc( auto matrix_filter = filter->asMatrix(); FML_DCHECK(matrix_filter); auto matrix = ToMatrix(matrix_filter->matrix()); - return [matrix](FilterInput::Ref input, const Matrix& effect_transform) { - return FilterContents::MakeMatrixFilter(input, matrix); + auto desc = ToSamplerDescriptor(matrix_filter->sampling()); + return [matrix, desc](FilterInput::Ref input, + const Matrix& effect_transform) { + return FilterContents::MakeMatrixFilter(input, matrix, desc); }; break; } diff --git a/engine/src/flutter/impeller/display_list/display_list_unittests.cc b/engine/src/flutter/impeller/display_list/display_list_unittests.cc index d42c2c3fd0c..6c20f1b185f 100644 --- a/engine/src/flutter/impeller/display_list/display_list_unittests.cc +++ b/engine/src/flutter/impeller/display_list/display_list_unittests.cc @@ -670,7 +670,9 @@ TEST_P(DisplayListTest, CanDrawWithMatrixFilter) { flutter::DisplayListBuilder builder; SkPaint paint; - builder.saveLayer(nullptr, nullptr); + if (enable_savelayer) { + builder.saveLayer(nullptr, nullptr); + } { auto content_scale = GetContentScale(); builder.scale(content_scale.x, content_scale.y); @@ -695,7 +697,8 @@ TEST_P(DisplayListTest, CanDrawWithMatrixFilter) { builder.drawImage(DlImageImpeller::Make(boston), {}, flutter::DlImageSampling::kLinear, true); - + } + if (enable_savelayer) { builder.restore(); } return builder.Build(); diff --git a/engine/src/flutter/impeller/entity/contents/filters/filter_contents.cc b/engine/src/flutter/impeller/entity/contents/filters/filter_contents.cc index 6c1865b5185..0c629c8657d 100644 --- a/engine/src/flutter/impeller/entity/contents/filters/filter_contents.cc +++ b/engine/src/flutter/impeller/entity/contents/filters/filter_contents.cc @@ -178,10 +178,12 @@ std::shared_ptr FilterContents::MakeSrgbToLinearFilter( std::shared_ptr FilterContents::MakeMatrixFilter( FilterInput::Ref input, - const Matrix& matrix) { + const Matrix& matrix, + const SamplerDescriptor& desc) { auto filter = std::make_shared(); filter->SetInputs({input}); filter->SetMatrix(matrix); + filter->SetSamplerDescriptor(desc); return filter; } diff --git a/engine/src/flutter/impeller/entity/contents/filters/filter_contents.h b/engine/src/flutter/impeller/entity/contents/filters/filter_contents.h index 11981abf4f1..7ac0351374a 100644 --- a/engine/src/flutter/impeller/entity/contents/filters/filter_contents.h +++ b/engine/src/flutter/impeller/entity/contents/filters/filter_contents.h @@ -92,7 +92,8 @@ class FilterContents : public Contents { static std::shared_ptr MakeMatrixFilter( FilterInput::Ref input, - const Matrix& matrix); + const Matrix& matrix, + const SamplerDescriptor& desc); FilterContents(); diff --git a/engine/src/flutter/impeller/entity/contents/filters/matrix_filter_contents.cc b/engine/src/flutter/impeller/entity/contents/filters/matrix_filter_contents.cc index bde911bc884..e8d5281a36d 100644 --- a/engine/src/flutter/impeller/entity/contents/filters/matrix_filter_contents.cc +++ b/engine/src/flutter/impeller/entity/contents/filters/matrix_filter_contents.cc @@ -14,9 +14,8 @@ void MatrixFilterContents::SetMatrix(Matrix matrix) { matrix_ = matrix; } -Matrix MatrixFilterContents::GetLocalTransform( - const Matrix& parent_transform) const { - return parent_transform.Invert() * matrix_ * parent_transform; +void MatrixFilterContents::SetSamplerDescriptor(SamplerDescriptor desc) { + sampler_descriptor_ = std::move(desc); } std::optional MatrixFilterContents::RenderFilter( @@ -25,7 +24,36 @@ std::optional MatrixFilterContents::RenderFilter( const Entity& entity, const Matrix& effect_transform, const Rect& coverage) const { - return inputs[0]->GetSnapshot(renderer, entity); + auto snapshot = inputs[0]->GetSnapshot(renderer, entity); + if (!snapshot.has_value()) { + return std::nullopt; + } + + snapshot->transform = entity.GetTransformation() * // + matrix_ * // + entity.GetTransformation().Invert() * // + snapshot->transform; + snapshot->sampler_descriptor = sampler_descriptor_; + return snapshot; +} + +std::optional MatrixFilterContents::GetFilterCoverage( + const FilterInput::Vector& inputs, + const Entity& entity, + const Matrix& effect_transform) const { + if (inputs.empty()) { + return std::nullopt; + } + + auto coverage = inputs[0]->GetCoverage(entity); + if (!coverage.has_value()) { + return std::nullopt; + } + + auto transform = inputs[0]->GetTransform(entity) * // + matrix_ * // + inputs[0]->GetTransform(entity).Invert(); + return coverage->TransformBounds(transform); } } // namespace impeller diff --git a/engine/src/flutter/impeller/entity/contents/filters/matrix_filter_contents.h b/engine/src/flutter/impeller/entity/contents/filters/matrix_filter_contents.h index 425372c82a7..f5f3880e1bd 100644 --- a/engine/src/flutter/impeller/entity/contents/filters/matrix_filter_contents.h +++ b/engine/src/flutter/impeller/entity/contents/filters/matrix_filter_contents.h @@ -17,8 +17,13 @@ class MatrixFilterContents final : public FilterContents { void SetMatrix(Matrix matrix); + void SetSamplerDescriptor(SamplerDescriptor desc); + // |FilterContents| - Matrix GetLocalTransform(const Matrix& parent_transform) const override; + std::optional GetFilterCoverage( + const FilterInput::Vector& inputs, + const Entity& entity, + const Matrix& effect_transform) const override; private: // |FilterContents| @@ -30,6 +35,7 @@ class MatrixFilterContents final : public FilterContents { const Rect& coverage) const override; Matrix matrix_; + SamplerDescriptor sampler_descriptor_ = {}; FML_DISALLOW_COPY_AND_ASSIGN(MatrixFilterContents); };