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 
6 #include <unordered_map>
7 
8 #include "impeller/base/thread.h"
10 
11 namespace impeller {
12 
14 
16 
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 
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 
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 
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,
64  std::unordered_map<PipelineDescriptor, int,
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
void LogPipelineUsage(const PipelineDescriptor &p)
std::unordered_map< PipelineDescriptor, int, ComparableHash< PipelineDescriptor >, ComparableEqual< PipelineDescriptor > > GetPipelineUseCounts() const
void LogPipelineCreation(const PipelineDescriptor &p)
PipelineFuture< PipelineDescriptor > GetPipeline(std::optional< PipelineDescriptor > descriptor, bool async=true)