diff --git a/impeller/entity/contents/filters/blend_filter_contents.cc b/impeller/entity/contents/filters/blend_filter_contents.cc index 60d8a233360a1..dc4e78260cbd2 100644 --- a/impeller/entity/contents/filters/blend_filter_contents.cc +++ b/impeller/entity/contents/filters/blend_filter_contents.cc @@ -394,134 +394,6 @@ std::optional BlendFilterContents::CreateForegroundAdvancedBlend( return sub_entity; } -std::optional BlendFilterContents::CreateForegroundPorterDuffBlend( - const std::shared_ptr& input, - const ContentContext& renderer, - const Entity& entity, - const Rect& coverage, - Color foreground_color, - BlendMode blend_mode, - std::optional alpha, - ColorFilterContents::AbsorbOpacity absorb_opacity) const { - if (blend_mode == BlendMode::kClear) { - return std::nullopt; - } - - if (blend_mode == BlendMode::kSource) { - auto contents = std::make_shared(); - contents->SetGeometry(Geometry::MakeRect(coverage)); - contents->SetColor(foreground_color); - - Entity foreground_entity; - foreground_entity.SetBlendMode(entity.GetBlendMode()); - foreground_entity.SetClipDepth(entity.GetClipDepth()); - foreground_entity.SetContents(std::move(contents)); - return foreground_entity; - } - - auto dst_snapshot = - input->GetSnapshot("ForegroundPorterDuffBlend", renderer, entity); - if (!dst_snapshot.has_value()) { - return std::nullopt; - } - - if (blend_mode == BlendMode::kDestination) { - return Entity::FromSnapshot(dst_snapshot.value(), entity.GetBlendMode(), - entity.GetClipDepth()); - } - - RenderProc render_proc = [foreground_color, coverage, dst_snapshot, - blend_mode, absorb_opacity, alpha]( - const ContentContext& renderer, - const Entity& entity, RenderPass& pass) -> bool { - using VS = PorterDuffBlendPipeline::VertexShader; - using FS = PorterDuffBlendPipeline::FragmentShader; - - auto& host_buffer = renderer.GetTransientsBuffer(); - - auto maybe_dst_uvs = dst_snapshot->GetCoverageUVs(coverage); - if (!maybe_dst_uvs.has_value()) { - return false; - } - auto dst_uvs = maybe_dst_uvs.value(); - - auto size = coverage.GetSize(); - auto origin = coverage.GetOrigin(); - auto color = foreground_color.Premultiply(); - VertexBufferBuilder vtx_builder; - vtx_builder.AddVertices({ - {origin, dst_uvs[0], color}, - {Point(origin.x + size.width, origin.y), dst_uvs[1], color}, - {Point(origin.x, origin.y + size.height), dst_uvs[2], color}, - {Point(origin.x + size.width, origin.y + size.height), dst_uvs[3], - color}, - }); - auto vtx_buffer = vtx_builder.CreateVertexBuffer(host_buffer); - -#ifdef IMPELLER_DEBUG - pass.SetCommandLabel(SPrintF("Foreground PorterDuff Blend Filter (%s)", - BlendModeToString(blend_mode))); -#endif // IMPELLER_DEBUG - pass.SetVertexBuffer(std::move(vtx_buffer)); - pass.SetStencilReference(entity.GetClipDepth()); - auto options = OptionsFromPass(pass); - options.primitive_type = PrimitiveType::kTriangleStrip; - pass.SetPipeline(renderer.GetPorterDuffBlendPipeline(options)); - - FS::FragInfo frag_info; - VS::FrameInfo frame_info; - frame_info.depth = entity.GetShaderClipDepth(); - - auto dst_sampler_descriptor = dst_snapshot->sampler_descriptor; - if (renderer.GetDeviceCapabilities().SupportsDecalSamplerAddressMode()) { - dst_sampler_descriptor.width_address_mode = SamplerAddressMode::kDecal; - dst_sampler_descriptor.height_address_mode = SamplerAddressMode::kDecal; - } - const std::unique_ptr& dst_sampler = - renderer.GetContext()->GetSamplerLibrary()->GetSampler( - dst_sampler_descriptor); - FS::BindTextureSamplerDst(pass, dst_snapshot->texture, dst_sampler); - frame_info.texture_sampler_y_coord_scale = - dst_snapshot->texture->GetYCoordScale(); - - frag_info.input_alpha = - absorb_opacity == ColorFilterContents::AbsorbOpacity::kYes - ? dst_snapshot->opacity * alpha.value_or(1.0) - : 1.0; - frag_info.output_alpha = 1.0; - - auto blend_coefficients = - kPorterDuffCoefficients[static_cast(blend_mode)]; - frag_info.src_coeff = blend_coefficients[0]; - frag_info.src_coeff_dst_alpha = blend_coefficients[1]; - frag_info.dst_coeff = blend_coefficients[2]; - frag_info.dst_coeff_src_alpha = blend_coefficients[3]; - frag_info.dst_coeff_src_color = blend_coefficients[4]; - - FS::BindFragInfo(pass, host_buffer.EmplaceUniform(frag_info)); - - frame_info.mvp = pass.GetOrthographicTransform() * entity.GetTransform(); - - auto uniform_view = host_buffer.EmplaceUniform(frame_info); - VS::BindFrameInfo(pass, uniform_view); - - return pass.Draw().ok(); - }; - - CoverageProc coverage_proc = - [coverage](const Entity& entity) -> std::optional { - return coverage.TransformBounds(entity.GetTransform()); - }; - - auto contents = AnonymousContents::Make(render_proc, coverage_proc); - - Entity sub_entity; - sub_entity.SetContents(std::move(contents)); - sub_entity.SetClipDepth(entity.GetClipDepth()); - - return sub_entity; -} - static std::optional PipelineBlend( const FilterInput::Vector& inputs, const ContentContext& renderer, @@ -740,12 +612,6 @@ std::optional BlendFilterContents::RenderFilter( } if (blend_mode_ <= Entity::kLastPipelineBlendMode) { - if (inputs.size() == 1 && foreground_color_.has_value() && - GetAbsorbOpacity() == ColorFilterContents::AbsorbOpacity::kYes) { - return CreateForegroundPorterDuffBlend( - inputs[0], renderer, entity, coverage, foreground_color_.value(), - blend_mode_, GetAlpha(), GetAbsorbOpacity()); - } return PipelineBlend(inputs, renderer, entity, coverage, blend_mode_, foreground_color_, GetAbsorbOpacity(), GetAlpha()); } diff --git a/impeller/entity/contents/filters/blend_filter_contents.h b/impeller/entity/contents/filters/blend_filter_contents.h index 562f306034ebd..75f575f5b2aaf 100644 --- a/impeller/entity/contents/filters/blend_filter_contents.h +++ b/impeller/entity/contents/filters/blend_filter_contents.h @@ -78,20 +78,6 @@ class BlendFilterContents : public ColorFilterContents { std::optional alpha, ColorFilterContents::AbsorbOpacity absorb_opacity) const; - /// @brief Optimized porter-duff blend that avoids a second subpass when there - /// is only a single input and a foreground color. - /// - /// These contents cannot absorb opacity. - std::optional CreateForegroundPorterDuffBlend( - const std::shared_ptr& input, - const ContentContext& renderer, - const Entity& entity, - const Rect& coverage, - Color foreground_color, - BlendMode blend_mode, - std::optional alpha, - ColorFilterContents::AbsorbOpacity absorb_opacity) const; - BlendMode blend_mode_ = BlendMode::kSourceOver; AdvancedBlendProc advanced_blend_proc_; std::optional foreground_color_;