| Flutter Impeller |

pipeline_library.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_library.h"
6 #include <unordered_map>
7
8 #include "impeller/base/thread.h"
9 #include "impeller/renderer/pipeline_descriptor.h"
10
11 namespace impeller {
12
13 PipelineLibrary::PipelineLibrary() = default;
14
15 PipelineLibrary::~PipelineLibrary() = default;
16
17 PipelineFuture<PipelineDescriptor> PipelineLibrary::GetPipeline(
18 std::optional<PipelineDescriptor> descriptor,
19 bool async) {
20 if (descriptor.has_value()) {
21 return GetPipeline(descriptor.value(), async);
22 }
23 auto promise = std::make_shared<
24 std::promise<std::shared_ptr<Pipeline<PipelineDescriptor>>>>();
25 promise->set_value(nullptr);
26 return {descriptor, promise->get_future()};
27 }
28
29 PipelineFuture<ComputePipelineDescriptor> PipelineLibrary::GetPipeline(
30 std::optional<ComputePipelineDescriptor> descriptor,
31 bool async) {
32 if (descriptor.has_value()) {
33 return GetPipeline(descriptor.value(), async);
34 }
35 auto promise = std::make_shared<
36 std::promise<std::shared_ptr<Pipeline<ComputePipelineDescriptor>>>>();
37 promise->set_value(nullptr);
38 return {descriptor, promise->get_future()};
39 }
40
41 void PipelineLibrary::LogPipelineCreation(const PipelineDescriptor& p) {
42 #if FLUTTER_RUNTIME_MODE == FLUTTER_RUNTIME_MODE_DEBUG || \
43 FLUTTER_RUNTIME_MODE == FLUTTER_RUNTIME_MODE_PROFILE
44 WriterLock lock(pipeline_use_counts_mutex_);
45 if (!pipeline_use_counts_.contains(p)) {
46 pipeline_use_counts_[p] = 0;
47 }
48 #endif
49 }
50
51 void PipelineLibrary::LogPipelineUsage(const PipelineDescriptor& p) {
52 #if FLUTTER_RUNTIME_MODE == FLUTTER_RUNTIME_MODE_DEBUG || \
53 FLUTTER_RUNTIME_MODE == FLUTTER_RUNTIME_MODE_PROFILE
54 WriterLock lock(pipeline_use_counts_mutex_);
55 ++pipeline_use_counts_[p];
56 #endif
57 }
58
59 std::unordered_map<PipelineDescriptor,
60 int,
61 ComparableHash<PipelineDescriptor>,
62 ComparableEqual<PipelineDescriptor>>
63 PipelineLibrary::GetPipelineUseCounts() const {
64 std::unordered_map<PipelineDescriptor, int,
65 ComparableHash<PipelineDescriptor>,
66 ComparableEqual<PipelineDescriptor>>
67 counts;
68
69 #if FLUTTER_RUNTIME_MODE == FLUTTER_RUNTIME_MODE_DEBUG || \
70 FLUTTER_RUNTIME_MODE == FLUTTER_RUNTIME_MODE_PROFILE
71 ReaderLock lock(pipeline_use_counts_mutex_);
72 counts = pipeline_use_counts_;
73 #endif
74 return counts;
75 }
76
77 } // namespace impeller
impeller::PipelineDescriptor
Definition: pipeline_descriptor.h:24
impeller::PipelineLibrary::PipelineLibrary
PipelineLibrary()
impeller::PipelineLibrary::LogPipelineUsage
void LogPipelineUsage(const PipelineDescriptor &p)
Definition: pipeline_library.cc:51
impeller::PipelineLibrary::GetPipelineUseCounts
std::unordered_map< PipelineDescriptor, int, ComparableHash< PipelineDescriptor >, ComparableEqual< PipelineDescriptor > > GetPipelineUseCounts() const
Definition: pipeline_library.cc:63
impeller::PipelineLibrary::~PipelineLibrary
virtual ~PipelineLibrary()
impeller::PipelineLibrary::LogPipelineCreation
void LogPipelineCreation(const PipelineDescriptor &p)
Definition: pipeline_library.cc:41
impeller::PipelineLibrary::GetPipeline
PipelineFuture< PipelineDescriptor > GetPipeline(std::optional< PipelineDescriptor > descriptor, bool async=true)
Definition: pipeline_library.cc:17
impeller::ReaderLock
Definition: thread.h:92
impeller::WriterLock
Definition: thread.h:113
impeller
Definition: allocation.cc:12
pipeline_descriptor.h
pipeline_library.h
impeller::ComparableEqual
Definition: comparable.h:48
impeller::ComparableHash
Definition: comparable.h:39
impeller::PipelineFuture
Definition: pipeline.h:28
thread.h