Flutter Engine
The Flutter Engine
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
15namespace impeller {
16
17template <typename T>
18Pipeline<T>::Pipeline(std::weak_ptr<PipelineLibrary> library, T desc)
19 : library_(std::move(library)), desc_(std::move(desc)) {}
20
21template <typename T>
22Pipeline<T>::~Pipeline() = default;
23
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
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
48template <typename T>
50 return desc_;
51}
52
53template <typename T>
55 bool async,
56 std::function<void(T& desc)> descriptor_callback) const {
57 if (!descriptor_callback) {
58 return {std::nullopt,
59 RealizedFuture<std::shared_ptr<Pipeline<T>>>(nullptr)};
60 }
61
62 auto copied_desc = desc_;
63
64 descriptor_callback(copied_desc);
65
66 auto library = library_.lock();
67 if (!library) {
68 VALIDATION_LOG << "The library from which this pipeline was created was "
69 "already collected.";
70 return {desc_, RealizedFuture<std::shared_ptr<Pipeline<T>>>(nullptr)};
71 }
72
73 return library->GetPipeline(std::move(copied_desc), async);
74}
75
76template class Pipeline<PipelineDescriptor>;
78
79} // namespace impeller
To do anything rendering related with Impeller, you need a context.
Definition: context.h:45
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:54
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:49
Dart_NativeFunction function
Definition: fuchsia.cc:51
PipelineFuture< PipelineDescriptor > CreatePipelineFuture(const Context &context, std::optional< PipelineDescriptor > desc)
Definition: pipeline.cc:24
Definition: ref_ptr.h:256
#define T
Definition: precompiler.cc:65
#define VALIDATION_LOG
Definition: validation.h:73