Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
embedder_task_runner.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_SHELL_PLATFORM_EMBEDDER_EMBEDDER_TASK_RUNNER_H_
6#define FLUTTER_SHELL_PLATFORM_EMBEDDER_EMBEDDER_TASK_RUNNER_H_
7
8#include <mutex>
9#include <unordered_map>
10
11#include "flutter/fml/macros.h"
12#include "flutter/fml/task_runner.h"
13
14namespace flutter {
15
16//------------------------------------------------------------------------------
17/// A task runner which delegates responsibility of task execution to an
18/// embedder. This is done by managing a dispatch table to the embedder.
19///
20class EmbedderTaskRunner final : public fml::TaskRunner {
21 public:
22 //----------------------------------------------------------------------------
23 /// @brief A
24 ///
26 //--------------------------------------------------------------------------
27 /// Delegates responsibility of deferred task execution to the embedder.
28 /// Once the embedder gets the task, it must call
29 /// `EmbedderTaskRunner::PostTask` with the supplied `task_baton` on the
30 /// correct thread after the tasks `target_time` point expires.
31 ///
32 std::function<void(EmbedderTaskRunner* task_runner,
33 uint64_t task_baton,
34 fml::TimePoint target_time)>
36 //--------------------------------------------------------------------------
37 /// Asks the embedder if tasks posted to it on this task runner via the
38 /// `post_task_callback` will be executed (after task expiry) on the calling
39 /// thread.
40 ///
41 std::function<bool(void)> runs_task_on_current_thread_callback;
42 };
43
44 //----------------------------------------------------------------------------
45 /// @brief Create a task runner with a dispatch table for delegation of
46 /// task runner responsibility to the embedder. When embedders
47 /// specify task runner dispatch tables that service tasks on the
48 /// same thread, they also must ensure that their
49 /// `embedder_idetifier`s match. This allows the engine to
50 /// determine task runner equality without actually posting tasks
51 /// to the task runner.
52 ///
53 /// @param[in] table The task runner dispatch table.
54 /// @param[in] embedder_identifier The embedder identifier
55 ///
56 EmbedderTaskRunner(DispatchTable table, size_t embedder_identifier);
57
58 // |fml::TaskRunner|
60
61 //----------------------------------------------------------------------------
62 /// @brief The unique identifier provided by the embedder for the task
63 /// runner. Embedders whose dispatch tables service tasks on the
64 /// same underlying OS thread must ensure that their identifiers
65 /// match. This allows the engine to determine task runner
66 /// equality without posting tasks on the thread.
67 ///
68 /// @return The embedder identifier.
69 ///
70 size_t GetEmbedderIdentifier() const;
71
72 bool PostTask(uint64_t baton);
73
74 private:
75 const size_t embedder_identifier_;
76 DispatchTable dispatch_table_;
77 std::mutex tasks_mutex_;
78 uint64_t last_baton_ = 0;
79 std::unordered_map<uint64_t, fml::closure> pending_tasks_;
80 fml::TaskQueueId placeholder_id_;
81
82 // |fml::TaskRunner|
83 void PostTask(const fml::closure& task) override;
84
85 // |fml::TaskRunner|
86 void PostTaskForTime(const fml::closure& task,
87 fml::TimePoint target_time) override;
88
89 // |fml::TaskRunner|
90 void PostDelayedTask(const fml::closure& task, fml::TimeDelta delay) override;
91
92 // |fml::TaskRunner|
93 bool RunsTasksOnCurrentThread() override;
94
95 // |fml::TaskRunner|
97
99};
100
101} // namespace flutter
102
103#endif // FLUTTER_SHELL_PLATFORM_EMBEDDER_EMBEDDER_TASK_RUNNER_H_
SI F table(const skcms_Curve *curve, F v)
fml::TaskQueueId GetTaskQueueId() override
void PostDelayedTask(const fml::closure &task, fml::TimeDelta delay) override
size_t GetEmbedderIdentifier() const
The unique identifier provided by the embedder for the task runner. Embedders whose dispatch tables s...
void PostTaskForTime(const fml::closure &task, fml::TimePoint target_time) override
#define FML_DISALLOW_COPY_AND_ASSIGN(TypeName)
Definition macros.h:27
std::function< void()> closure
Definition closure.h:14
std::function< void(EmbedderTaskRunner *task_runner, uint64_t task_baton, fml::TimePoint target_time)> post_task_callback
std::function< bool(void)> runs_task_on_current_thread_callback