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 ba6f0e1aa4..540c08965f 100644 --- a/engine/src/flutter/impeller/display_list/display_list_dispatcher.cc +++ b/engine/src/flutter/impeller/display_list/display_list_dispatcher.cc @@ -473,4 +473,8 @@ void DisplayListDispatcher::drawShadow(const SkPath& path, UNIMPLEMENTED; } +Picture DisplayListDispatcher::EndRecordingAsPicture() { + return canvas_.EndRecordingAsPicture(); +} + } // namespace impeller diff --git a/engine/src/flutter/impeller/display_list/display_list_dispatcher.h b/engine/src/flutter/impeller/display_list/display_list_dispatcher.h index d007de6653..c32f295f6e 100644 --- a/engine/src/flutter/impeller/display_list/display_list_dispatcher.h +++ b/engine/src/flutter/impeller/display_list/display_list_dispatcher.h @@ -18,6 +18,8 @@ class DisplayListDispatcher final : public flutter::Dispatcher { ~DisplayListDispatcher(); + Picture EndRecordingAsPicture(); + // |flutter::Dispatcher| void setAntiAlias(bool aa) override; diff --git a/engine/src/flutter/impeller/entity/content_context.cc b/engine/src/flutter/impeller/entity/content_context.cc index ed0dcc5ddb..5a628518df 100644 --- a/engine/src/flutter/impeller/entity/content_context.cc +++ b/engine/src/flutter/impeller/entity/content_context.cc @@ -4,6 +4,8 @@ #include "impeller/entity/content_context.h" +#include + namespace impeller { ContentContext::ContentContext(std::shared_ptr context) @@ -23,6 +25,7 @@ ContentContext::ContentContext(std::shared_ptr context) // Pipelines that are variants of the base pipelines with custom descriptors. if (auto solid_fill_pipeline = solid_fill_pipelines_[{}]->WaitAndGet()) { auto clip_pipeline_descriptor = solid_fill_pipeline->GetDescriptor(); + clip_pipeline_descriptor.SetLabel("Clip Pipeline"); // Write to the stencil buffer. StencilAttachmentDescriptor stencil0; stencil0.stencil_compare = CompareFunction::kGreaterEqual; diff --git a/engine/src/flutter/impeller/entity/content_context.h b/engine/src/flutter/impeller/entity/content_context.h index 0143fb2913..09870f775d 100644 --- a/engine/src/flutter/impeller/entity/content_context.h +++ b/engine/src/flutter/impeller/entity/content_context.h @@ -111,14 +111,16 @@ class ContentContext { return found->second->WaitAndGet(); } - auto found = container.find({}); + auto prototype = container.find({}); // The prototype must always be initialized in the constructor. - FML_CHECK(found != container.end()); + FML_CHECK(prototype != container.end()); - auto variant_future = found->second->WaitAndGet()->CreateVariant( - [&opts](PipelineDescriptor& desc) { + auto variant_future = prototype->second->WaitAndGet()->CreateVariant( + [&opts, variants_count = container.size()](PipelineDescriptor& desc) { ApplyOptionsToDescriptor(desc, opts); + desc.SetLabel( + SPrintF("%s V#%zu", desc.GetLabel().c_str(), variants_count)); }); auto variant = std::make_unique(std::move(variant_future)); auto variant_pipeline = variant->WaitAndGet(); diff --git a/engine/src/flutter/impeller/renderer/backend/metal/pipeline_library_mtl.h b/engine/src/flutter/impeller/renderer/backend/metal/pipeline_library_mtl.h index 612a95a1de..41c62da6a7 100644 --- a/engine/src/flutter/impeller/renderer/backend/metal/pipeline_library_mtl.h +++ b/engine/src/flutter/impeller/renderer/backend/metal/pipeline_library_mtl.h @@ -26,18 +26,16 @@ class PipelineLibraryMTL final : public PipelineLibrary { private: friend ContextMTL; - using Pipelines = std::unordered_map, - ComparableHash, - ComparableEqual>; + using Pipelines = + std::unordered_map>, + ComparableHash, + ComparableEqual>; id device_ = nullptr; Pipelines pipelines_; PipelineLibraryMTL(id device); - void SavePipeline(PipelineDescriptor descriptor, - std::shared_ptr pipeline); - // |PipelineLibrary| PipelineFuture GetRenderPipeline(PipelineDescriptor descriptor) override; diff --git a/engine/src/flutter/impeller/renderer/backend/metal/pipeline_library_mtl.mm b/engine/src/flutter/impeller/renderer/backend/metal/pipeline_library_mtl.mm index 2d33f46370..e677c931f4 100644 --- a/engine/src/flutter/impeller/renderer/backend/metal/pipeline_library_mtl.mm +++ b/engine/src/flutter/impeller/renderer/backend/metal/pipeline_library_mtl.mm @@ -67,19 +67,16 @@ static id CreateDepthStencilDescriptor( return [device newDepthStencilStateWithDescriptor:descriptor]; } -std::future> PipelineLibraryMTL::GetRenderPipeline( +PipelineFuture PipelineLibraryMTL::GetRenderPipeline( PipelineDescriptor descriptor) { - auto promise = std::make_shared>>(); - auto future = promise->get_future(); if (auto found = pipelines_.find(descriptor); found != pipelines_.end()) { - promise->set_value(nullptr); - return future; + return found->second; } - // TODO(csg): There is a bug here where multiple calls to GetRenderPipeline - // will result in multiple render pipelines of the same descriptor being - // created till the first instance of the creation invokes its completion - // callback. + auto promise = std::make_shared>>(); + auto future = PipelineFuture{promise->get_future()}; + + pipelines_[descriptor] = future; auto weak_this = weak_from_this(); @@ -100,6 +97,7 @@ std::future> PipelineLibraryMTL::GetRenderPipeline( promise->set_value(nullptr); return; } + auto new_pipeline = std::shared_ptr(new PipelineMTL( weak_this, descriptor, // @@ -107,7 +105,6 @@ std::future> PipelineLibraryMTL::GetRenderPipeline( CreateDepthStencilDescriptor(descriptor, device_) // )); promise->set_value(new_pipeline); - this->SavePipeline(descriptor, new_pipeline); }; [device_ newRenderPipelineStateWithDescriptor:GetMTLRenderPipelineDescriptor( descriptor) @@ -115,10 +112,4 @@ std::future> PipelineLibraryMTL::GetRenderPipeline( return future; } -void PipelineLibraryMTL::SavePipeline( - PipelineDescriptor descriptor, - std::shared_ptr pipeline) { - pipelines_[descriptor] = std::move(pipeline); -} - } // namespace impeller diff --git a/engine/src/flutter/impeller/renderer/pipeline.h b/engine/src/flutter/impeller/renderer/pipeline.h index 9362cbd0e6..47df168d8b 100644 --- a/engine/src/flutter/impeller/renderer/pipeline.h +++ b/engine/src/flutter/impeller/renderer/pipeline.h @@ -21,7 +21,7 @@ class Pipeline; // would be a concurrency pessimization. // // Use a struct that stores the future and the descriptor separately. -using PipelineFuture = std::future>; +using PipelineFuture = std::shared_future>; //------------------------------------------------------------------------------ /// @brief Describes the fixed function and programmable aspects of @@ -48,6 +48,13 @@ class Pipeline { virtual bool IsValid() const = 0; + //---------------------------------------------------------------------------- + /// @brief Get the descriptor that was responsible for creating this + /// pipeline. It may be copied and modified to create a pipeline + /// variant. + /// + /// @return The descriptor. + /// const PipelineDescriptor& GetDescriptor() const; PipelineFuture CreateVariant(