Flutter Impeller
pipeline.cc
Go to the documentation of this file.
1 // Copyright 2013 The Flutter Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
6 #include <optional>
7 
13 #include "pipeline_descriptor.h"
14 
15 namespace impeller {
16 
17 template <typename T>
18 Pipeline<T>::Pipeline(std::weak_ptr<PipelineLibrary> library, T desc)
19  : library_(std::move(library)), desc_(std::move(desc)) {}
20 
21 template <typename T>
22 Pipeline<T>::~Pipeline() = default;
23 
25  const Context& context,
26  std::optional<PipelineDescriptor> desc,
27  bool async) {
28  if (!context.IsValid()) {
29  return {desc, RealizedFuture<std::shared_ptr<Pipeline<PipelineDescriptor>>>(
30  nullptr)};
31  }
32 
33  return context.GetPipelineLibrary()->GetPipeline(std::move(desc),
34  /*async=*/async);
35 }
36 
38  const Context& context,
39  std::optional<ComputePipelineDescriptor> desc) {
40  if (!context.IsValid()) {
41  return {
42  desc,
43  RealizedFuture<std::shared_ptr<Pipeline<ComputePipelineDescriptor>>>(
44  nullptr)};
45  }
46 
47  return context.GetPipelineLibrary()->GetPipeline(std::move(desc));
48 }
49 
50 template <typename T>
51 const T& Pipeline<T>::GetDescriptor() const {
52  return desc_;
53 }
54 
55 template <typename T>
57  bool async,
58  std::function<void(T& desc)> descriptor_callback) const {
59  if (!descriptor_callback) {
60  return {std::nullopt,
61  RealizedFuture<std::shared_ptr<Pipeline<T>>>(nullptr)};
62  }
63 
64  auto copied_desc = desc_;
65 
66  descriptor_callback(copied_desc);
67 
68  auto library = library_.lock();
69  if (!library) {
70  VALIDATION_LOG << "The library from which this pipeline was created was "
71  "already collected.";
72  return {desc_, RealizedFuture<std::shared_ptr<Pipeline<T>>>(nullptr)};
73  }
74 
75  return library->GetPipeline(std::move(copied_desc), async);
76 }
77 
78 template class Pipeline<PipelineDescriptor>;
80 
81 } // namespace impeller
To do anything rendering related with Impeller, you need a context.
Definition: context.h:65
virtual std::shared_ptr< PipelineLibrary > GetPipelineLibrary() const =0
Returns the library of pipelines used by render or compute commands.
virtual bool IsValid() const =0
Determines if a context is valid. If the caller ever receives an invalid context, they must discard i...
PipelineFuture< T > CreateVariant(bool async, std::function< void(T &desc)> descriptor_callback) const
Definition: pipeline.cc:56
Pipeline(std::weak_ptr< PipelineLibrary > library, T desc)
Definition: pipeline.cc:18
const T & GetDescriptor() const
Get the descriptor that was responsible for creating this pipeline. It may be copied and modified to ...
Definition: pipeline.cc:51
std::optional< PipelineDescriptor > desc_
PipelineFuture< PipelineDescriptor > CreatePipelineFuture(const Context &context, std::optional< PipelineDescriptor > desc, bool async)
Create a pipeline for the given descriptor.
Definition: pipeline.cc:24
Definition: comparable.h:95
#define VALIDATION_LOG
Definition: validation.h:91