| 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
5 #include "impeller/renderer/pipeline.h"
6 #include <optional>
7
8 #include "compute_pipeline_descriptor.h"
9 #include "impeller/base/promise.h"
10 #include "impeller/renderer/compute_pipeline_descriptor.h"
11 #include "impeller/renderer/context.h"
12 #include "impeller/renderer/pipeline_library.h"
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
24 PipelineFuture<PipelineDescriptor> CreatePipelineFuture(
25 const Context& context,
26 std::optional<PipelineDescriptor> desc) {
27 if (!context.IsValid()) {
28 return {desc, RealizedFuture<std::shared_ptr<Pipeline<PipelineDescriptor>>>(
29 nullptr)};
30 }
31
32 return context.GetPipelineLibrary()->GetPipeline(std::move(desc));
33 }
34
35 PipelineFuture<ComputePipelineDescriptor> CreatePipelineFuture(
36 const Context& context,
37 std::optional<ComputePipelineDescriptor> desc) {
38 if (!context.IsValid()) {
39 return {
40 desc,
41 RealizedFuture<std::shared_ptr<Pipeline<ComputePipelineDescriptor>>>(
42 nullptr)};
43 }
44
45 return context.GetPipelineLibrary()->GetPipeline(std::move(desc));
46 }
47
48 template <typename T>
49 const T& Pipeline<T>::GetDescriptor() const {
50 return desc_;
51 }
52
53 template <typename T>
54 PipelineFuture<T> Pipeline<T>::CreateVariant(
55 std::function<void(T& desc)> descriptor_callback) const {
56 if (!descriptor_callback) {
57 return {std::nullopt,
58 RealizedFuture<std::shared_ptr<Pipeline<T>>>(nullptr)};
59 }
60
61 auto copied_desc = desc_;
62
63 descriptor_callback(copied_desc);
64
65 auto library = library_.lock();
66 if (!library) {
67 VALIDATION_LOG << "The library from which this pipeline was created was "
68 "already collected.";
69 return {desc_, RealizedFuture<std::shared_ptr<Pipeline<T>>>(nullptr)};
70 }
71
72 return library->GetPipeline(std::move(copied_desc));
73 }
74
75 template class Pipeline<PipelineDescriptor>;
76 template class Pipeline<ComputePipelineDescriptor>;
77
78 } // namespace impeller
impeller::Context::GetPipelineLibrary
virtual std::shared_ptr< PipelineLibrary > GetPipelineLibrary() const =0
Returns the library of pipelines used by render or compute commands.
impeller::Pipeline
Describes the fixed function and programmable aspects of rendering and compute operations performed b...
Definition: compute_pipeline_descriptor.h:27
pipeline.h
impeller::PipelineFuture
Definition: pipeline.h:24
impeller::Pipeline::Pipeline
Pipeline(std::weak_ptr< PipelineLibrary > library, T desc)
Definition: pipeline.cc:18
compute_pipeline_descriptor.h
impeller::CreatePipelineFuture
PipelineFuture< ComputePipelineDescriptor > CreatePipelineFuture(const Context &context, std::optional< ComputePipelineDescriptor > desc)
Definition: pipeline.cc:35
impeller::Context::IsValid
virtual bool IsValid() const =0
Determines if a context is valid. If the caller ever receives an invalid context, they must discard i...
pipeline_library.h
VALIDATION_LOG
#define VALIDATION_LOG
Definition: validation.h:60
impeller::Context
To do anything rendering related with Impeller, you need a context.
Definition: context.h:47
promise.h
std
Definition: comparable.h:98
context.h
pipeline_descriptor.h
impeller
Definition: aiks_context.cc:10