| Flutter Impeller |

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"
11 #include "flutter/fml/concurrent_message_loop.h"
12 #include "impeller/base/thread.h"
13 #include "impeller/renderer/pipeline_descriptor.h"
14
15 namespace 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 ///
42 class PipelineCompileQueue final
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
50 PipelineCompileQueue(const PipelineCompileQueue&) = delete;
51
52 PipelineCompileQueue& operator=(const PipelineCompileQueue&) = delete;
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 ///
63 bool PostJobForDescriptor(const PipelineDescriptor& desc,
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,
81 fml::closure,
82 ComparableHash<PipelineDescriptor>,
83 ComparableEqual<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_
impeller::PipelineCompileQueue
A task queue designed for managing compilation of pipeline state objects.
Definition: pipeline_compile_queue.h:43
impeller::PipelineCompileQueue::PostJobForDescriptor
bool PostJobForDescriptor(const PipelineDescriptor &desc, const fml::closure &job)
Post a compile job for the specified descriptor.
Definition: pipeline_compile_queue.cc:26
impeller::PipelineCompileQueue::Create
static std::shared_ptr< PipelineCompileQueue > Create(std::shared_ptr< fml::ConcurrentTaskRunner > worker_task_runner)
Definition: pipeline_compile_queue.cc:12
impeller::PipelineCompileQueue::operator=
PipelineCompileQueue & operator=(const PipelineCompileQueue &)=delete
impeller::PipelineCompileQueue::PipelineCompileQueue
PipelineCompileQueue(const PipelineCompileQueue &)=delete
impeller::PipelineCompileQueue::~PipelineCompileQueue
virtual ~PipelineCompileQueue()
Definition: pipeline_compile_queue.cc:22
impeller::PipelineCompileQueue::PerformJobEagerly
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...
Definition: pipeline_compile_queue.cc:112
impeller::PipelineDescriptor
Definition: pipeline_descriptor.h:24
impeller
Definition: allocation.cc:12
pipeline_descriptor.h
impeller::ComparableEqual
Definition: comparable.h:48
impeller::ComparableHash
Definition: comparable.h:39
thread.h