diff --git a/impeller/entity/contents/contents.cc b/impeller/entity/contents/contents.cc index 0105704a1a450..27ea0cba38c63 100644 --- a/impeller/entity/contents/contents.cc +++ b/impeller/entity/contents/contents.cc @@ -7,6 +7,7 @@ #include "fml/logging.h" #include "impeller/entity/contents/content_context.h" +#include "impeller/entity/contents/texture_contents.h" #include "impeller/renderer/command_buffer.h" #include "impeller/renderer/formats.h" #include "impeller/renderer/render_pass.h" @@ -31,6 +32,30 @@ ContentContextOptions OptionsFromPassAndEntity(const RenderPass& pass, return opts; } +std::optional Contents::EntityFromSnapshot( + const std::optional& snapshot, + BlendMode blend_mode, + uint32_t stencil_depth) { + if (!snapshot.has_value()) { + return std::nullopt; + } + + auto texture_rect = Rect::MakeSize(snapshot->texture->GetSize()); + + auto contents = TextureContents::MakeRect(texture_rect); + contents->SetTexture(snapshot->texture); + contents->SetSamplerDescriptor(snapshot->sampler_descriptor); + contents->SetSourceRect(texture_rect); + contents->SetOpacity(snapshot->opacity); + + Entity entity; + entity.SetBlendMode(blend_mode); + entity.SetStencilDepth(stencil_depth); + entity.SetTransformation(snapshot->transform); + entity.SetContents(contents); + return entity; +} + Contents::Contents() = default; Contents::~Contents() = default; diff --git a/impeller/entity/contents/contents.h b/impeller/entity/contents/contents.h index ec9919097c17b..2c5f3abf0cbd5 100644 --- a/impeller/entity/contents/contents.h +++ b/impeller/entity/contents/contents.h @@ -9,6 +9,7 @@ #include #include "flutter/fml/macros.h" +#include "impeller/geometry/color.h" #include "impeller/geometry/rect.h" #include "impeller/renderer/sampler_descriptor.h" #include "impeller/renderer/snapshot.h" @@ -40,6 +41,12 @@ class Contents { std::optional coverage = std::nullopt; }; + /// @brief Create an entity that renders a given snapshot. + static std::optional EntityFromSnapshot( + const std::optional& snapshot, + BlendMode blend_mode = BlendMode::kSourceOver, + uint32_t stencil_depth = 0); + virtual bool Render(const ContentContext& renderer, const Entity& entity, RenderPass& pass) const = 0; diff --git a/impeller/entity/contents/filters/blend_filter_contents.cc b/impeller/entity/contents/filters/blend_filter_contents.cc index ddfc723379c99..42b5553313f31 100644 --- a/impeller/entity/contents/filters/blend_filter_contents.cc +++ b/impeller/entity/contents/filters/blend_filter_contents.cc @@ -17,6 +17,7 @@ #include "impeller/renderer/formats.h" #include "impeller/renderer/render_pass.h" #include "impeller/renderer/sampler_library.h" +#include "impeller/renderer/snapshot.h" namespace impeller { @@ -30,7 +31,7 @@ using PipelineProc = std::shared_ptr> ( ContentContext::*)(ContentContextOptions) const; template -static std::optional AdvancedBlend( +static std::optional AdvancedBlend( const FilterInput::Vector& inputs, const ContentContext& renderer, const Entity& entity, @@ -67,11 +68,19 @@ static std::optional AdvancedBlend( if (!foreground_color.has_value()) { src_snapshot = inputs[1]->GetSnapshot(renderer, entity); if (!src_snapshot.has_value()) { - return dst_snapshot; + if (!dst_snapshot.has_value()) { + return std::nullopt; + } + return Contents::EntityFromSnapshot(dst_snapshot, entity.GetBlendMode(), + entity.GetStencilDepth()); } auto maybe_src_uvs = src_snapshot->GetCoverageUVs(coverage); if (!maybe_src_uvs.has_value()) { - return dst_snapshot; + if (!dst_snapshot.has_value()) { + return std::nullopt; + } + return Contents::EntityFromSnapshot(dst_snapshot, entity.GetBlendMode(), + entity.GetStencilDepth()); } src_uvs = maybe_src_uvs.value(); } @@ -147,17 +156,19 @@ static std::optional AdvancedBlend( } out_texture->SetLabel("Advanced Blend Filter Texture"); - return Snapshot{.texture = out_texture, - .transform = Matrix::MakeTranslation(coverage.origin), - // Since we absorbed the transform of the inputs and used the - // respective snapshot sampling modes when blending, pass on - // the default NN clamp sampler. - .sampler_descriptor = {}, - .opacity = (absorb_opacity ? 1.0f : dst_snapshot->opacity) * - alpha.value_or(1.0)}; + return Contents::EntityFromSnapshot( + Snapshot{.texture = out_texture, + .transform = Matrix::MakeTranslation(coverage.origin), + // Since we absorbed the transform of the inputs and used the + // respective snapshot sampling modes when blending, pass on + // the default NN clamp sampler. + .sampler_descriptor = {}, + .opacity = (absorb_opacity ? 1.0f : dst_snapshot->opacity) * + alpha.value_or(1.0)}, + entity.GetBlendMode(), entity.GetStencilDepth()); } -static std::optional PipelineBlend( +static std::optional PipelineBlend( const FilterInput::Vector& inputs, const ContentContext& renderer, const Entity& entity, @@ -269,28 +280,31 @@ static std::optional PipelineBlend( } out_texture->SetLabel("Pipeline Blend Filter Texture"); - return Snapshot{.texture = out_texture, - .transform = Matrix::MakeTranslation(coverage.origin), - // Since we absorbed the transform of the inputs and used the - // respective snapshot sampling modes when blending, pass on - // the default NN clamp sampler. - .sampler_descriptor = {}, - .opacity = (absorb_opacity ? 1.0f : dst_snapshot->opacity) * - alpha.value_or(1.0)}; + return Contents::EntityFromSnapshot( + Snapshot{.texture = out_texture, + .transform = Matrix::MakeTranslation(coverage.origin), + // Since we absorbed the transform of the inputs and used the + // respective snapshot sampling modes when blending, pass on + // the default NN clamp sampler. + .sampler_descriptor = {}, + .opacity = (absorb_opacity ? 1.0f : dst_snapshot->opacity) * + alpha.value_or(1.0)}, + entity.GetBlendMode(), entity.GetStencilDepth()); } -#define BLEND_CASE(mode) \ - case BlendMode::k##mode: \ - advanced_blend_proc_ = \ - [](const FilterInput::Vector& inputs, const ContentContext& renderer, \ - const Entity& entity, const Rect& coverage, \ - std::optional fg_color, bool absorb_opacity, \ - std::optional alpha) { \ - PipelineProc p = &ContentContext::GetBlend##mode##Pipeline; \ - return AdvancedBlend(inputs, renderer, entity, \ - coverage, fg_color, \ - absorb_opacity, p, alpha); \ - }; \ +#define BLEND_CASE(mode) \ + case BlendMode::k##mode: \ + advanced_blend_proc_ = [](const FilterInput::Vector& inputs, \ + const ContentContext& renderer, \ + const Entity& entity, const Rect& coverage, \ + std::optional fg_color, \ + bool absorb_opacity, \ + std::optional alpha) { \ + PipelineProc p = &ContentContext::GetBlend##mode##Pipeline; \ + return AdvancedBlend(inputs, renderer, entity, \ + coverage, fg_color, \ + absorb_opacity, p, alpha); \ + }; \ break; void BlendFilterContents::SetBlendMode(BlendMode blend_mode) { @@ -328,7 +342,7 @@ void BlendFilterContents::SetForegroundColor(std::optional color) { foreground_color_ = color; } -std::optional BlendFilterContents::RenderFilter( +std::optional BlendFilterContents::RenderFilter( const FilterInput::Vector& inputs, const ContentContext& renderer, const Entity& entity, diff --git a/impeller/entity/contents/filters/blend_filter_contents.h b/impeller/entity/contents/filters/blend_filter_contents.h index 47734ffa7b554..1b7f51a839719 100644 --- a/impeller/entity/contents/filters/blend_filter_contents.h +++ b/impeller/entity/contents/filters/blend_filter_contents.h @@ -11,14 +11,14 @@ namespace impeller { class BlendFilterContents : public ColorFilterContents { public: - using AdvancedBlendProc = std::function( - const FilterInput::Vector& inputs, - const ContentContext& renderer, - const Entity& entity, - const Rect& coverage, - std::optional foreground_color, - bool absorb_opacity, - std::optional alpha)>; + using AdvancedBlendProc = + std::function(const FilterInput::Vector& inputs, + const ContentContext& renderer, + const Entity& entity, + const Rect& coverage, + std::optional foreground_color, + bool absorb_opacity, + std::optional alpha)>; BlendFilterContents(); @@ -32,11 +32,11 @@ class BlendFilterContents : public ColorFilterContents { private: // |FilterContents| - std::optional RenderFilter(const FilterInput::Vector& inputs, - const ContentContext& renderer, - const Entity& entity, - const Matrix& effect_transform, - const Rect& coverage) const override; + std::optional RenderFilter(const FilterInput::Vector& inputs, + const ContentContext& renderer, + const Entity& entity, + const Matrix& effect_transform, + const Rect& coverage) const override; BlendMode blend_mode_ = BlendMode::kSourceOver; AdvancedBlendProc advanced_blend_proc_; diff --git a/impeller/entity/contents/filters/border_mask_blur_filter_contents.cc b/impeller/entity/contents/filters/border_mask_blur_filter_contents.cc index 847cfafa8815f..d9376c87145c7 100644 --- a/impeller/entity/contents/filters/border_mask_blur_filter_contents.cc +++ b/impeller/entity/contents/filters/border_mask_blur_filter_contents.cc @@ -47,7 +47,7 @@ void BorderMaskBlurFilterContents::SetBlurStyle(BlurStyle blur_style) { } } -std::optional BorderMaskBlurFilterContents::RenderFilter( +std::optional BorderMaskBlurFilterContents::RenderFilter( const FilterInput::Vector& inputs, const ContentContext& renderer, const Entity& entity, @@ -126,9 +126,11 @@ std::optional BorderMaskBlurFilterContents::RenderFilter( } out_texture->SetLabel("BorderMaskBlurFilter Texture"); - return Snapshot{.texture = out_texture, - .transform = Matrix::MakeTranslation(coverage.origin), - .opacity = input_snapshot->opacity}; + return Contents::EntityFromSnapshot( + Snapshot{.texture = out_texture, + .transform = Matrix::MakeTranslation(coverage.origin), + .opacity = input_snapshot->opacity}, + entity.GetBlendMode(), entity.GetStencilDepth()); } std::optional BorderMaskBlurFilterContents::GetFilterCoverage( diff --git a/impeller/entity/contents/filters/border_mask_blur_filter_contents.h b/impeller/entity/contents/filters/border_mask_blur_filter_contents.h index 9d971f5a11fdf..06dc386704fb9 100644 --- a/impeller/entity/contents/filters/border_mask_blur_filter_contents.h +++ b/impeller/entity/contents/filters/border_mask_blur_filter_contents.h @@ -29,12 +29,11 @@ class BorderMaskBlurFilterContents final : public FilterContents { private: // |FilterContents| - std::optional RenderFilter( - const FilterInput::Vector& input_textures, - const ContentContext& renderer, - const Entity& entity, - const Matrix& effect_transform, - const Rect& coverage) const override; + std::optional RenderFilter(const FilterInput::Vector& input_textures, + const ContentContext& renderer, + const Entity& entity, + const Matrix& effect_transform, + const Rect& coverage) const override; Sigma sigma_x_; Sigma sigma_y_; diff --git a/impeller/entity/contents/filters/color_matrix_filter_contents.cc b/impeller/entity/contents/filters/color_matrix_filter_contents.cc index 66e8464f81d49..16cef668e5495 100644 --- a/impeller/entity/contents/filters/color_matrix_filter_contents.cc +++ b/impeller/entity/contents/filters/color_matrix_filter_contents.cc @@ -23,7 +23,7 @@ void ColorMatrixFilterContents::SetMatrix(const ColorMatrix& matrix) { matrix_ = matrix; } -std::optional ColorMatrixFilterContents::RenderFilter( +std::optional ColorMatrixFilterContents::RenderFilter( const FilterInput::Vector& inputs, const ContentContext& renderer, const Entity& entity, @@ -104,11 +104,12 @@ std::optional ColorMatrixFilterContents::RenderFilter( } out_texture->SetLabel("ColorMatrixFilter Texture"); - return Snapshot{ - .texture = out_texture, - .transform = input_snapshot->transform, - .sampler_descriptor = input_snapshot->sampler_descriptor, - .opacity = GetAbsorbOpacity() ? 1.0f : input_snapshot->opacity}; + return Contents::EntityFromSnapshot( + Snapshot{.texture = out_texture, + .transform = input_snapshot->transform, + .sampler_descriptor = input_snapshot->sampler_descriptor, + .opacity = GetAbsorbOpacity() ? 1.0f : input_snapshot->opacity}, + entity.GetBlendMode(), entity.GetStencilDepth()); } } // namespace impeller diff --git a/impeller/entity/contents/filters/color_matrix_filter_contents.h b/impeller/entity/contents/filters/color_matrix_filter_contents.h index 3486365a5a642..fb3a32058f2b9 100644 --- a/impeller/entity/contents/filters/color_matrix_filter_contents.h +++ b/impeller/entity/contents/filters/color_matrix_filter_contents.h @@ -24,12 +24,11 @@ class ColorMatrixFilterContents final : public ColorFilterContents { private: // |FilterContents| - std::optional RenderFilter( - const FilterInput::Vector& input_textures, - const ContentContext& renderer, - const Entity& entity, - const Matrix& effect_transform, - const Rect& coverage) const override; + std::optional RenderFilter(const FilterInput::Vector& input_textures, + const ContentContext& renderer, + const Entity& entity, + const Matrix& effect_transform, + const Rect& coverage) const override; ColorMatrix matrix_; diff --git a/impeller/entity/contents/filters/filter_contents.cc b/impeller/entity/contents/filters/filter_contents.cc index cf10504d244c7..48c0b08ebd6a3 100644 --- a/impeller/entity/contents/filters/filter_contents.cc +++ b/impeller/entity/contents/filters/filter_contents.cc @@ -167,26 +167,11 @@ bool FilterContents::Render(const ContentContext& renderer, // Run the filter. - auto maybe_snapshot = RenderToSnapshot(renderer, entity); - if (!maybe_snapshot.has_value()) { - return false; + auto maybe_entity = GetEntity(renderer, entity); + if (!maybe_entity.has_value()) { + return true; } - auto& snapshot = maybe_snapshot.value(); - - // Draw the result texture, respecting the transform and clip stack. - - auto texture_rect = Rect::MakeSize(snapshot.texture->GetSize()); - auto contents = TextureContents::MakeRect(texture_rect); - contents->SetTexture(snapshot.texture); - contents->SetSamplerDescriptor(snapshot.sampler_descriptor); - contents->SetSourceRect(texture_rect); - contents->SetOpacity(snapshot.opacity); - - Entity e; - e.SetBlendMode(entity.GetBlendMode()); - e.SetStencilDepth(entity.GetStencilDepth()); - e.SetTransformation(snapshot.transform); - return contents->Render(renderer, e, pass); + return maybe_entity->Render(renderer, pass); } std::optional FilterContents::GetLocalCoverage( @@ -234,11 +219,8 @@ std::optional FilterContents::GetFilterCoverage( return result; } -std::optional FilterContents::RenderToSnapshot( - const ContentContext& renderer, - const Entity& entity, - const std::optional& sampler_descriptor, - bool msaa_enabled) const { +std::optional FilterContents::GetEntity(const ContentContext& renderer, + const Entity& entity) const { Entity entity_with_local_transform = entity; entity_with_local_transform.SetTransformation( GetTransform(entity.GetTransformation())); @@ -252,6 +234,21 @@ std::optional FilterContents::RenderToSnapshot( effect_transform_, coverage.value()); } +std::optional FilterContents::RenderToSnapshot( + const ContentContext& renderer, + const Entity& entity, + const std::optional& sampler_descriptor, + bool msaa_enabled) const { + // Resolve the render instruction (entity) from the filter and render it to a + // snapshot. + if (std::optional result = GetEntity(renderer, entity); + result.has_value()) { + return result->GetContents()->RenderToSnapshot(renderer, result.value()); + } + + return std::nullopt; +} + Matrix FilterContents::GetLocalTransform(const Matrix& parent_transform) const { return Matrix(); } diff --git a/impeller/entity/contents/filters/filter_contents.h b/impeller/entity/contents/filters/filter_contents.h index 74c10397eccb0..00959b69d4e96 100644 --- a/impeller/entity/contents/filters/filter_contents.h +++ b/impeller/entity/contents/filters/filter_contents.h @@ -107,6 +107,10 @@ class FilterContents : public Contents { /// filter. Note that this is in addition to the entity's transform. void SetEffectTransform(Matrix effect_transform); + /// @brief Create an Entity that renders this filter's output. + std::optional GetEntity(const ContentContext& renderer, + const Entity& entity) const; + // |Contents| bool Render(const ContentContext& renderer, const Entity& entity, @@ -132,13 +136,12 @@ class FilterContents : public Contents { const Entity& entity, const Matrix& effect_transform) const; - /// @brief Converts zero or more filter inputs into a new texture. - virtual std::optional RenderFilter( - const FilterInput::Vector& inputs, - const ContentContext& renderer, - const Entity& entity, - const Matrix& effect_transform, - const Rect& coverage) const = 0; + /// @brief Converts zero or more filter inputs into a render instruction. + virtual std::optional RenderFilter(const FilterInput::Vector& inputs, + const ContentContext& renderer, + const Entity& entity, + const Matrix& effect_transform, + const Rect& coverage) const = 0; std::optional GetLocalCoverage(const Entity& local_entity) const; diff --git a/impeller/entity/contents/filters/gaussian_blur_filter_contents.cc b/impeller/entity/contents/filters/gaussian_blur_filter_contents.cc index d3d056727acc9..87cecd9996816 100644 --- a/impeller/entity/contents/filters/gaussian_blur_filter_contents.cc +++ b/impeller/entity/contents/filters/gaussian_blur_filter_contents.cc @@ -81,7 +81,7 @@ void DirectionalGaussianBlurFilterContents::SetSourceOverride( source_override_ = std::move(source_override); } -std::optional DirectionalGaussianBlurFilterContents::RenderFilter( +std::optional DirectionalGaussianBlurFilterContents::RenderFilter( const FilterInput::Vector& inputs, const ContentContext& renderer, const Entity& entity, @@ -106,7 +106,9 @@ std::optional DirectionalGaussianBlurFilterContents::RenderFilter( } if (blur_sigma_.sigma < kEhCloseEnough) { - return input_snapshot.value(); // No blur to render. + return Contents::EntityFromSnapshot( + input_snapshot.value(), entity.GetBlendMode(), + entity.GetStencilDepth()); // No blur to render. } auto radius = Radius{blur_sigma_}.radius; @@ -120,7 +122,9 @@ std::optional DirectionalGaussianBlurFilterContents::RenderFilter( // If the radius length is < .5, the shader will take at most 1 sample, // resulting in no blur. if (transformed_blur_radius_length < .5) { - return input_snapshot.value(); // No blur to render. + return Contents::EntityFromSnapshot( + input_snapshot.value(), entity.GetBlendMode(), + entity.GetStencilDepth()); // No blur to render. } // A matrix that rotates the snapshot space such that the blur direction is @@ -283,14 +287,15 @@ std::optional DirectionalGaussianBlurFilterContents::RenderFilter( sampler_desc.min_filter = MinMagFilter::kLinear; sampler_desc.mag_filter = MinMagFilter::kLinear; - return Snapshot{ - .texture = out_texture, - .transform = - texture_rotate.Invert() * - Matrix::MakeTranslation(pass_texture_rect.origin) * - Matrix::MakeScale((1 / scale) * (scaled_size / floored_size)), - .sampler_descriptor = sampler_desc, - .opacity = input_snapshot->opacity}; + return Contents::EntityFromSnapshot( + Snapshot{.texture = out_texture, + .transform = texture_rotate.Invert() * + Matrix::MakeTranslation(pass_texture_rect.origin) * + Matrix::MakeScale((1 / scale) * + (scaled_size / floored_size)), + .sampler_descriptor = sampler_desc, + .opacity = input_snapshot->opacity}, + entity.GetBlendMode(), entity.GetStencilDepth()); } std::optional DirectionalGaussianBlurFilterContents::GetFilterCoverage( diff --git a/impeller/entity/contents/filters/gaussian_blur_filter_contents.h b/impeller/entity/contents/filters/gaussian_blur_filter_contents.h index 7c4e44d68ece5..b69f6627e1485 100644 --- a/impeller/entity/contents/filters/gaussian_blur_filter_contents.h +++ b/impeller/entity/contents/filters/gaussian_blur_filter_contents.h @@ -37,12 +37,11 @@ class DirectionalGaussianBlurFilterContents final : public FilterContents { private: // |FilterContents| - std::optional RenderFilter( - const FilterInput::Vector& input_textures, - const ContentContext& renderer, - const Entity& entity, - const Matrix& effect_transform, - const Rect& coverage) const override; + std::optional RenderFilter(const FilterInput::Vector& input_textures, + const ContentContext& renderer, + const Entity& entity, + const Matrix& effect_transform, + const Rect& coverage) const override; Sigma blur_sigma_; Sigma secondary_blur_sigma_; Vector2 blur_direction_; diff --git a/impeller/entity/contents/filters/linear_to_srgb_filter_contents.cc b/impeller/entity/contents/filters/linear_to_srgb_filter_contents.cc index 98d397a727008..48a2b0ca8ea90 100644 --- a/impeller/entity/contents/filters/linear_to_srgb_filter_contents.cc +++ b/impeller/entity/contents/filters/linear_to_srgb_filter_contents.cc @@ -17,7 +17,7 @@ LinearToSrgbFilterContents::LinearToSrgbFilterContents() = default; LinearToSrgbFilterContents::~LinearToSrgbFilterContents() = default; -std::optional LinearToSrgbFilterContents::RenderFilter( +std::optional LinearToSrgbFilterContents::RenderFilter( const FilterInput::Vector& inputs, const ContentContext& renderer, const Entity& entity, @@ -81,11 +81,12 @@ std::optional LinearToSrgbFilterContents::RenderFilter( } out_texture->SetLabel("LinearToSrgb Texture"); - return Snapshot{ - .texture = out_texture, - .transform = input_snapshot->transform, - .sampler_descriptor = input_snapshot->sampler_descriptor, - .opacity = GetAbsorbOpacity() ? 1.0f : input_snapshot->opacity}; + return Contents::EntityFromSnapshot( + Snapshot{.texture = out_texture, + .transform = input_snapshot->transform, + .sampler_descriptor = input_snapshot->sampler_descriptor, + .opacity = GetAbsorbOpacity() ? 1.0f : input_snapshot->opacity}, + entity.GetBlendMode(), entity.GetStencilDepth()); } } // namespace impeller diff --git a/impeller/entity/contents/filters/linear_to_srgb_filter_contents.h b/impeller/entity/contents/filters/linear_to_srgb_filter_contents.h index 00b7116420a55..ee2390c5980c3 100644 --- a/impeller/entity/contents/filters/linear_to_srgb_filter_contents.h +++ b/impeller/entity/contents/filters/linear_to_srgb_filter_contents.h @@ -17,12 +17,11 @@ class LinearToSrgbFilterContents final : public ColorFilterContents { private: // |FilterContents| - std::optional RenderFilter( - const FilterInput::Vector& input_textures, - const ContentContext& renderer, - const Entity& entity, - const Matrix& effect_transform, - const Rect& coverage) const override; + std::optional RenderFilter(const FilterInput::Vector& input_textures, + const ContentContext& renderer, + const Entity& entity, + const Matrix& effect_transform, + const Rect& coverage) const override; FML_DISALLOW_COPY_AND_ASSIGN(LinearToSrgbFilterContents); }; diff --git a/impeller/entity/contents/filters/local_matrix_filter_contents.cc b/impeller/entity/contents/filters/local_matrix_filter_contents.cc index 5cafbb58e10b8..a5214b489c37f 100644 --- a/impeller/entity/contents/filters/local_matrix_filter_contents.cc +++ b/impeller/entity/contents/filters/local_matrix_filter_contents.cc @@ -19,13 +19,15 @@ Matrix LocalMatrixFilterContents::GetLocalTransform( return matrix_; } -std::optional LocalMatrixFilterContents::RenderFilter( +std::optional LocalMatrixFilterContents::RenderFilter( const FilterInput::Vector& inputs, const ContentContext& renderer, const Entity& entity, const Matrix& effect_transform, const Rect& coverage) const { - return inputs[0]->GetSnapshot(renderer, entity); + return Contents::EntityFromSnapshot(inputs[0]->GetSnapshot(renderer, entity), + entity.GetBlendMode(), + entity.GetStencilDepth()); } } // namespace impeller diff --git a/impeller/entity/contents/filters/local_matrix_filter_contents.h b/impeller/entity/contents/filters/local_matrix_filter_contents.h index 9d310c986a584..824f1c36e3bd5 100644 --- a/impeller/entity/contents/filters/local_matrix_filter_contents.h +++ b/impeller/entity/contents/filters/local_matrix_filter_contents.h @@ -22,12 +22,11 @@ class LocalMatrixFilterContents final : public FilterContents { private: // |FilterContents| - std::optional RenderFilter( - const FilterInput::Vector& input_textures, - const ContentContext& renderer, - const Entity& entity, - const Matrix& effect_transform, - const Rect& coverage) const override; + std::optional RenderFilter(const FilterInput::Vector& input_textures, + const ContentContext& renderer, + const Entity& entity, + const Matrix& effect_transform, + const Rect& coverage) const override; Matrix matrix_; diff --git a/impeller/entity/contents/filters/matrix_filter_contents.cc b/impeller/entity/contents/filters/matrix_filter_contents.cc index e8d5281a36dca..45b6aad04d87c 100644 --- a/impeller/entity/contents/filters/matrix_filter_contents.cc +++ b/impeller/entity/contents/filters/matrix_filter_contents.cc @@ -18,7 +18,7 @@ void MatrixFilterContents::SetSamplerDescriptor(SamplerDescriptor desc) { sampler_descriptor_ = std::move(desc); } -std::optional MatrixFilterContents::RenderFilter( +std::optional MatrixFilterContents::RenderFilter( const FilterInput::Vector& inputs, const ContentContext& renderer, const Entity& entity, @@ -34,7 +34,8 @@ std::optional MatrixFilterContents::RenderFilter( entity.GetTransformation().Invert() * // snapshot->transform; snapshot->sampler_descriptor = sampler_descriptor_; - return snapshot; + return Contents::EntityFromSnapshot(snapshot, entity.GetBlendMode(), + entity.GetStencilDepth()); } std::optional MatrixFilterContents::GetFilterCoverage( diff --git a/impeller/entity/contents/filters/matrix_filter_contents.h b/impeller/entity/contents/filters/matrix_filter_contents.h index f5f3880e1bd21..2ccdd2b4ff694 100644 --- a/impeller/entity/contents/filters/matrix_filter_contents.h +++ b/impeller/entity/contents/filters/matrix_filter_contents.h @@ -27,12 +27,11 @@ class MatrixFilterContents final : public FilterContents { private: // |FilterContents| - std::optional RenderFilter( - const FilterInput::Vector& input_textures, - const ContentContext& renderer, - const Entity& entity, - const Matrix& effect_transform, - const Rect& coverage) const override; + std::optional RenderFilter(const FilterInput::Vector& input_textures, + const ContentContext& renderer, + const Entity& entity, + const Matrix& effect_transform, + const Rect& coverage) const override; Matrix matrix_; SamplerDescriptor sampler_descriptor_ = {}; diff --git a/impeller/entity/contents/filters/morphology_filter_contents.cc b/impeller/entity/contents/filters/morphology_filter_contents.cc index 42c1d79afc3b9..da20f07b148b5 100644 --- a/impeller/entity/contents/filters/morphology_filter_contents.cc +++ b/impeller/entity/contents/filters/morphology_filter_contents.cc @@ -34,7 +34,7 @@ void DirectionalMorphologyFilterContents::SetMorphType(MorphType morph_type) { morph_type_ = morph_type; } -std::optional DirectionalMorphologyFilterContents::RenderFilter( +std::optional DirectionalMorphologyFilterContents::RenderFilter( const FilterInput::Vector& inputs, const ContentContext& renderer, const Entity& entity, @@ -57,7 +57,9 @@ std::optional DirectionalMorphologyFilterContents::RenderFilter( } if (radius_.radius < kEhCloseEnough) { - return input_snapshot.value(); + return Contents::EntityFromSnapshot(input_snapshot.value(), + entity.GetBlendMode(), + entity.GetStencilDepth()); } auto maybe_input_uvs = input_snapshot->GetCoverageUVs(coverage); @@ -139,10 +141,12 @@ std::optional DirectionalMorphologyFilterContents::RenderFilter( sampler_desc.min_filter = MinMagFilter::kLinear; sampler_desc.mag_filter = MinMagFilter::kLinear; - return Snapshot{.texture = out_texture, - .transform = Matrix::MakeTranslation(coverage.origin), - .sampler_descriptor = sampler_desc, - .opacity = input_snapshot->opacity}; + return Contents::EntityFromSnapshot( + Snapshot{.texture = out_texture, + .transform = Matrix::MakeTranslation(coverage.origin), + .sampler_descriptor = sampler_desc, + .opacity = input_snapshot->opacity}, + entity.GetBlendMode(), entity.GetStencilDepth()); } std::optional DirectionalMorphologyFilterContents::GetFilterCoverage( diff --git a/impeller/entity/contents/filters/morphology_filter_contents.h b/impeller/entity/contents/filters/morphology_filter_contents.h index 0028039e11177..6c4ac20a561d8 100644 --- a/impeller/entity/contents/filters/morphology_filter_contents.h +++ b/impeller/entity/contents/filters/morphology_filter_contents.h @@ -31,12 +31,11 @@ class DirectionalMorphologyFilterContents final : public FilterContents { private: // |FilterContents| - std::optional RenderFilter( - const FilterInput::Vector& input_textures, - const ContentContext& renderer, - const Entity& entity, - const Matrix& effect_transform, - const Rect& coverage) const override; + std::optional RenderFilter(const FilterInput::Vector& input_textures, + const ContentContext& renderer, + const Entity& entity, + const Matrix& effect_transform, + const Rect& coverage) const override; Radius radius_; Vector2 direction_; diff --git a/impeller/entity/contents/filters/srgb_to_linear_filter_contents.cc b/impeller/entity/contents/filters/srgb_to_linear_filter_contents.cc index ee483b6ed5e93..7b38cdbc567cc 100644 --- a/impeller/entity/contents/filters/srgb_to_linear_filter_contents.cc +++ b/impeller/entity/contents/filters/srgb_to_linear_filter_contents.cc @@ -17,7 +17,7 @@ SrgbToLinearFilterContents::SrgbToLinearFilterContents() = default; SrgbToLinearFilterContents::~SrgbToLinearFilterContents() = default; -std::optional SrgbToLinearFilterContents::RenderFilter( +std::optional SrgbToLinearFilterContents::RenderFilter( const FilterInput::Vector& inputs, const ContentContext& renderer, const Entity& entity, @@ -81,11 +81,12 @@ std::optional SrgbToLinearFilterContents::RenderFilter( } out_texture->SetLabel("SrgbToLinear Texture"); - return Snapshot{ - .texture = out_texture, - .transform = input_snapshot->transform, - .sampler_descriptor = input_snapshot->sampler_descriptor, - .opacity = GetAbsorbOpacity() ? 1.0f : input_snapshot->opacity}; + return Contents::EntityFromSnapshot( + Snapshot{.texture = out_texture, + .transform = input_snapshot->transform, + .sampler_descriptor = input_snapshot->sampler_descriptor, + .opacity = GetAbsorbOpacity() ? 1.0f : input_snapshot->opacity}, + entity.GetBlendMode(), entity.GetStencilDepth()); } } // namespace impeller diff --git a/impeller/entity/contents/filters/srgb_to_linear_filter_contents.h b/impeller/entity/contents/filters/srgb_to_linear_filter_contents.h index 07b3307159c74..6568e9db43308 100644 --- a/impeller/entity/contents/filters/srgb_to_linear_filter_contents.h +++ b/impeller/entity/contents/filters/srgb_to_linear_filter_contents.h @@ -17,12 +17,11 @@ class SrgbToLinearFilterContents final : public ColorFilterContents { private: // |FilterContents| - std::optional RenderFilter( - const FilterInput::Vector& input_textures, - const ContentContext& renderer, - const Entity& entity, - const Matrix& effect_transform, - const Rect& coverage) const override; + std::optional RenderFilter(const FilterInput::Vector& input_textures, + const ContentContext& renderer, + const Entity& entity, + const Matrix& effect_transform, + const Rect& coverage) const override; FML_DISALLOW_COPY_AND_ASSIGN(SrgbToLinearFilterContents); }; diff --git a/impeller/entity/contents/filters/yuv_to_rgb_filter_contents.cc b/impeller/entity/contents/filters/yuv_to_rgb_filter_contents.cc index b00a4b92c8228..26b9fd9faa260 100644 --- a/impeller/entity/contents/filters/yuv_to_rgb_filter_contents.cc +++ b/impeller/entity/contents/filters/yuv_to_rgb_filter_contents.cc @@ -36,7 +36,7 @@ void YUVToRGBFilterContents::SetYUVColorSpace(YUVColorSpace yuv_color_space) { yuv_color_space_ = yuv_color_space; } -std::optional YUVToRGBFilterContents::RenderFilter( +std::optional YUVToRGBFilterContents::RenderFilter( const FilterInput::Vector& inputs, const ContentContext& renderer, const Entity& entity, @@ -118,7 +118,9 @@ std::optional YUVToRGBFilterContents::RenderFilter( } out_texture->SetLabel("YUVToRGB Texture"); - return Snapshot{.texture = out_texture}; + return Contents::EntityFromSnapshot(Snapshot{.texture = out_texture}, + entity.GetBlendMode(), + entity.GetStencilDepth()); } } // namespace impeller diff --git a/impeller/entity/contents/filters/yuv_to_rgb_filter_contents.h b/impeller/entity/contents/filters/yuv_to_rgb_filter_contents.h index 7e15cb5efce97..45ac58cfbe3d3 100644 --- a/impeller/entity/contents/filters/yuv_to_rgb_filter_contents.h +++ b/impeller/entity/contents/filters/yuv_to_rgb_filter_contents.h @@ -18,12 +18,11 @@ class YUVToRGBFilterContents final : public FilterContents { private: // |FilterContents| - std::optional RenderFilter( - const FilterInput::Vector& input_textures, - const ContentContext& renderer, - const Entity& entity, - const Matrix& effect_transform, - const Rect& coverage) const override; + std::optional RenderFilter(const FilterInput::Vector& input_textures, + const ContentContext& renderer, + const Entity& entity, + const Matrix& effect_transform, + const Rect& coverage) const override; YUVColorSpace yuv_color_space_ = YUVColorSpace::kBT601LimitedRange;