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:
46
47 virtual ~PipelineCompileQueue();
48
50
52
53 //----------------------------------------------------------------------------
54 /// @brief Post a compile job for the specified descriptor.
55 ///
56 /// @param[in] desc The description
57 /// @param[in] job The job
58 ///
59 /// @return If the job was successfully posted to the parallel task
60 /// runners.
61 ///
63 const fml::closure& job);
64
65 //----------------------------------------------------------------------------
66 /// @brief If the task has not yet been done, perform it eagerly on the
67 /// calling thread. This can be used in lieu of an idle wait for
68 /// the task completion on the calling thread.
69 ///
70 /// @param[in] desc The description
71 ///
72 void PerformJobEagerly(const PipelineDescriptor& desc);
73
74 protected:
75 //----------------------------------------------------------------------------
76 /// @brief Post a compilation job to the worker task runner.
77 ///
78 /// This is a pure virtual function that must be implemented by
79 /// subclasses. It is responsible for actually dispatching the
80 /// job closure to the appropriate task runner for execution.
81 ///
82 /// @param[in] job The compilation job closure to post
83 ///
84 virtual void PostJob(const fml::closure& job) = 0;
85
86 //----------------------------------------------------------------------------
87 /// @brief Called by PostJobForDescriptor after a job has been
88 /// successfully added to the queue. Subclasses must implement
89 /// this to define their scheduling strategy.
90 ///
91 /// The default implementation for duplicate descriptors is to
92 /// run the job eagerly. Subclasses can override this behavior
93 /// by checking for duplicates before calling the base class.
94 ///
95 virtual void OnJobAdded() = 0;
96
97 //----------------------------------------------------------------------------
98 /// @brief Execute one pending compilation job from the queue.
99 ///
100 /// This method retrieves and executes a single job from the
101 /// pending jobs queue. It is typically called by subclasses
102 /// when they are ready to process the next job in the queue.
103 ///
104 void DoOneJob();
105
106 //----------------------------------------------------------------------------
107 /// @brief Add a compilation job to the pending queue for the specified
108 /// descriptor.
109 ///
110 /// @param[in] desc The pipeline descriptor that identifies the job
111 /// @param[in] job The compilation job closure to add
112 ///
113 /// @return True if the job was successfully added to the queue, false
114 /// if a job for this descriptor already exists.
115 ///
116 bool AddJob(const PipelineDescriptor& desc, const fml::closure& job);
117
118 //----------------------------------------------------------------------------
119 /// @brief Check if there are any pending compilation jobs in the queue.
120 ///
121 /// @return True if there are pending jobs waiting to be processed,
122 /// false otherwise.
123 ///
124 bool HasPendingJobs();
125
126 private:
127 Mutex pending_jobs_mutex_;
128 std::unordered_map<PipelineDescriptor,
132 pending_jobs_ IPLR_GUARDED_BY(pending_jobs_mutex_);
133 size_t priorities_elevated_ = {};
134 fml::closure TakeJob(const PipelineDescriptor& desc);
135 fml::closure TakeNextJob();
136 void FinishAllJobs();
137};
138
139} // namespace impeller
140
141#endif // FLUTTER_IMPELLER_RENDERER_PIPELINE_COMPILE_QUEUE_H_
A task queue designed for managing compilation of pipeline state objects.
virtual void PostJob(const fml::closure &job)=0
Post a compilation job to the worker task runner.
PipelineCompileQueue & operator=(const PipelineCompileQueue &)=delete
bool PostJobForDescriptor(const PipelineDescriptor &desc, const fml::closure &job)
Post a compile job for the specified descriptor.
PipelineCompileQueue(const PipelineCompileQueue &)=delete
bool AddJob(const PipelineDescriptor &desc, const fml::closure &job)
Add a compilation job to the pending queue for the specified descriptor.
void DoOneJob()
Execute one pending compilation job from the queue.
bool HasPendingJobs()
Check if there are any pending compilation jobs in the queue.
virtual void OnJobAdded()=0
Called by PostJobForDescriptor after a job has been successfully added to the queue....
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)