5#ifndef FLUTTER_SHELL_COMMON_PIPELINE_H_
6#define FLUTTER_SHELL_COMMON_PIPELINE_H_
12#include "flutter/flow/frame_timings.h"
13#include "flutter/flow/layers/layer_tree.h"
14#include "flutter/fml/macros.h"
15#include "flutter/fml/memory/ref_counted.h"
16#include "flutter/fml/synchronization/semaphore.h"
17#include "flutter/fml/trace_event.h"
76 : continuation_(other.continuation_), trace_id_(other.trace_id_) {
77 other.continuation_ =
nullptr;
82 std::swap(continuation_, other.continuation_);
89 continuation_(
nullptr, trace_id_);
102 continuation_ =
nullptr;
109 explicit operator bool()
const {
return continuation_ !=
nullptr; }
116 Continuation continuation_;
120 : continuation_(continuation), trace_id_(trace_id) {
132 : empty_(depth), available_(0), inflight_(0) {}
149 reinterpret_cast<int64_t
>(
this),
150 "frames in flight", inflight_.load()
154 std::bind(&Pipeline::ProducerCommit,
this, std::placeholders::_1,
155 std::placeholders::_2),
170 reinterpret_cast<int64_t
>(
this),
171 "frames in flight", inflight_.load()
175 std::bind(&Pipeline::ProducerCommitIfEmpty,
this, std::placeholders::_1,
176 std::placeholders::_2),
184 if (consumer ==
nullptr) {
194 size_t items_count = 0;
197 std::scoped_lock lock(queue_mutex_);
198 std::tie(
resource, trace_id) = std::move(queue_.front());
200 items_count = queue_.size();
218 std::atomic<int> inflight_;
219 std::mutex queue_mutex_;
220 std::deque<std::pair<ResourcePtr, size_t>> queue_;
225 bool is_first_item =
false;
227 std::scoped_lock lock(queue_mutex_);
228 is_first_item = queue_.empty();
229 queue_.emplace_back(std::move(
resource), trace_id);
234 return {.success =
true, .is_first_item = is_first_item};
240 std::scoped_lock lock(queue_mutex_);
241 if (!queue_.empty()) {
245 return {.success =
false, .is_first_item =
false};
247 queue_.emplace_back(std::move(
resource), trace_id);
252 return {.success =
true, .is_first_item =
true};
static SkString resource(SkPDFResourceType type, int index)
void swap(sk_sp< T > &a, sk_sp< T > &b)
ProducerContinuation(ProducerContinuation &&other)
PipelineProduceResult Complete(ResourcePtr resource)
Completes the continuation with the specified resource.
ProducerContinuation & operator=(ProducerContinuation &&other)
std::function< void(ResourcePtr)> Consumer
ProducerContinuation ProduceIfEmpty()
ProducerContinuation Produce()
PipelineConsumeResult Consume(const Consumer &consumer)
std::unique_ptr< Resource > ResourcePtr
A traditional counting semaphore. Waits decrement the counter and Signal increments it.
bool IsValid() const
Check if the underlying semaphore handle could be created. Failure modes are platform specific and ma...
void Signal()
Increment the count by one. Any pending Waits will be resolved at this point.
bool TryWait()
Decrement the counts if it is greater than zero. Returns false if the counter is already at zero.
#define FML_DISALLOW_COPY_AND_ASSIGN(TypeName)
Dart_NativeFunction function
size_t GetNextPipelineTraceID()
#define TRACE_FLOW_BEGIN(category, name, id)
#define TRACE_FLOW_STEP(category, name, id)
#define FML_TRACE_COUNTER(category_group, name, counter_id, arg1,...)
#define TRACE_EVENT_ASYNC_BEGIN0_WITH_FLOW_IDS(category_group, name, id, flow_id_count, flow_ids)
#define TRACE_EVENT_ASYNC_END0(category_group, name, id)
#define TRACE_FLOW_END(category, name, id)
#define TRACE_EVENT_ASYNC_BEGIN0(category_group, name, id)