Flutter Engine Uber Docs
Docs for the entire Flutter Engine repo.
 
Loading...
Searching...
No Matches
pipeline_compile_queue.h
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#ifndef FLUTTER_IMPELLER_RENDERER_PIPELINE_COMPILE_QUEUE_H_
6#define FLUTTER_IMPELLER_RENDERER_PIPELINE_COMPILE_QUEUE_H_
7
8#include <unordered_map>
9
10#include "flutter/fml/closure.h"
14
15namespace impeller {
16
17//------------------------------------------------------------------------------
18/// @brief A task queue designed for managing compilation of pipeline state
19/// objects.
20///
21/// The task queue attempts to perform compile jobs as quickly as
22/// possible by dispatching tasks to a concurrent task runner. These
23/// tasks are dispatched during renderer creation and usually
24/// complete before the first frame is rendered. In this ideal case,
25/// this queue is entirely unnecessary and and serves as a thin
26/// wrapper around just posting the compile jobs to a concurrent
27/// task runner.
28///
29/// If however, usually on lower end device, the compile jobs cannot
30/// be completed before the first frame is rendered, the implicit
31/// act of waiting for the compile job to be done can instead be
32/// augmented to take the pending job and perform it eagerly on the
33/// waiters thread. This effectively turns an idle wait into the job
34/// skipping to the front of the line and being done on the callers
35/// thread.
36///
37/// Again, the entire point of this class is the reduce startup
38/// times on the lowest end devices. On high end device, a queue is
39/// entirely optional. The queue skipping mechanism all assume the
40/// optional availability of a compile queue.
41///
43 : public std::enable_shared_from_this<PipelineCompileQueue> {
44 public:
45 static std::shared_ptr<PipelineCompileQueue> Create(
46 std::shared_ptr<fml::ConcurrentTaskRunner> worker_task_runner);
47
48 virtual ~PipelineCompileQueue();
49
51
53
54 //----------------------------------------------------------------------------
55 /// @brief Post a compile job for the specified descriptor.
56 ///
57 /// @param[in] desc The description
58 /// @param[in] job The job
59 ///
60 /// @return If the job was successfully posted to the parallel task
61 /// runners.
62 ///
64 const fml::closure& job);
65
66 //----------------------------------------------------------------------------
67 /// @brief If the task has not yet been done, perform it eagerly on the
68 /// calling thread. This can be used in lieu of an idle wait for
69 /// the task completion on the calling thread.
70 ///
71 /// @param[in] desc The description
72 ///
73 void PerformJobEagerly(const PipelineDescriptor& desc);
74
75 private:
76 std::shared_ptr<fml::ConcurrentTaskRunner> worker_task_runner_;
77 Mutex pending_jobs_mutex_;
78 size_t priorities_elevated_ = {};
79
80 std::unordered_map<PipelineDescriptor,
84 pending_jobs_ IPLR_GUARDED_BY(pending_jobs_mutex_);
85
86 explicit PipelineCompileQueue(
87 std::shared_ptr<fml::ConcurrentTaskRunner> worker_task_runner);
88
89 fml::closure TakeJob(const PipelineDescriptor& desc);
90
91 fml::closure TakeNextJob();
92
93 void DoOneJob();
94
95 void FinishAllJobs();
96};
97
98} // namespace impeller
99
100#endif // FLUTTER_IMPELLER_RENDERER_PIPELINE_COMPILE_QUEUE_H_
A task queue designed for managing compilation of pipeline state objects.
PipelineCompileQueue & operator=(const PipelineCompileQueue &)=delete
bool PostJobForDescriptor(const PipelineDescriptor &desc, const fml::closure &job)
Post a compile job for the specified descriptor.
static std::shared_ptr< PipelineCompileQueue > Create(std::shared_ptr< fml::ConcurrentTaskRunner > worker_task_runner)
PipelineCompileQueue(const PipelineCompileQueue &)=delete
void PerformJobEagerly(const PipelineDescriptor &desc)
If the task has not yet been done, perform it eagerly on the calling thread. This can be used in lieu...
std::function< void()> closure
Definition closure.h:14
#define IPLR_GUARDED_BY(x)