5#ifndef FLUTTER_IMPELLER_SCENE_SCENE_CONTEXT_H_
6#define FLUTTER_IMPELLER_SCENE_SCENE_CONTEXT_H_
49 std::shared_ptr<Pipeline<PipelineDescriptor>>
GetPipeline(
60 class PipelineVariants {
62 virtual ~PipelineVariants() =
default;
64 virtual std::shared_ptr<Pipeline<PipelineDescriptor>>
GetPipeline(
69 template <
class PipelineT>
70 class PipelineVariantsT final :
public PipelineVariants {
72 explicit PipelineVariantsT(
Context& context) {
73 auto desc = PipelineT::Builder::MakeDefaultPipelineDescriptor(context);
74 if (!
desc.has_value()) {
79 SceneContextOptions{}.ApplyToPipelineDescriptor(
82 variants_[{}] = std::make_unique<PipelineT>(context,
desc);
86 std::shared_ptr<Pipeline<PipelineDescriptor>>
GetPipeline(
88 SceneContextOptions opts) {
89 if (
auto found = variants_.find(opts); found != variants_.end()) {
90 return found->second->WaitAndGet();
93 auto prototype = variants_.find({});
98 auto variant_future = prototype->second->WaitAndGet()->CreateVariant(
99 false, [&context, &opts, variants_count = variants_.size()](
100 PipelineDescriptor&
desc) {
101 opts.ApplyToPipelineDescriptor(*context.GetCapabilities(), desc);
103 SPrintF(
"%s V#%zu", desc.GetLabel().c_str(), variants_count));
105 auto variant = std::make_unique<PipelineT>(std::move(variant_future));
106 auto variant_pipeline = variant->WaitAndGet();
107 variants_[opts] = std::move(variant);
108 return variant_pipeline;
111 bool IsValid()
const {
return is_valid_; }
114 bool is_valid_ =
true;
115 std::unordered_map<SceneContextOptions,
116 std::unique_ptr<PipelineT>,
118 SceneContextOptions::Equal>
122 template <
typename VertexShader,
typename FragmentShader>
126 std::unique_ptr<PipelineVariants> MakePipelineVariants(
Context& context) {
128 PipelineVariantsT<RenderPipelineHandle<VertexShader, FragmentShader>>(
130 if (!pipeline.IsValid()) {
133 return std::make_unique<
134 PipelineVariantsT<RenderPipelineHandle<VertexShader, FragmentShader>>>(
135 std::move(pipeline));
138 std::unordered_map<PipelineKey,
139 std::unique_ptr<PipelineVariants>,
144 std::shared_ptr<Context> context_;
146 bool is_valid_ =
false;
149 std::shared_ptr<Texture> placeholder_texture_;
150 std::shared_ptr<HostBuffer> host_buffer_;
To do anything rendering related with Impeller, you need a context.
virtual const std::shared_ptr< const Capabilities > & GetCapabilities() const =0
Get the capabilities of Impeller context. All optionally supported feature of the platform,...
std::shared_ptr< Context > GetContext() const
SceneContext(std::shared_ptr< Context > context)
std::shared_ptr< Pipeline< PipelineDescriptor > > GetPipeline(PipelineKey key, SceneContextOptions opts) const
std::shared_ptr< Texture > GetPlaceholderTexture() const
HostBuffer & GetTransientsBuffer() const
#define FML_CHECK(condition)
static uint32_t Hash(uint32_t key)
constexpr std::size_t HashCombine()
PrimitiveType
Decides how backend draws pixels based on input vertices.
constexpr bool operator()(const SceneContextOptions &lhs, const SceneContextOptions &rhs) const
constexpr std::size_t operator()(const SceneContextOptions &o) const
PrimitiveType primitive_type
void ApplyToPipelineDescriptor(const Capabilities &capabilities, PipelineDescriptor &desc) const