Flutter Engine
The Flutter Engine
Public Member Functions | List of all members
flutter::EmbedderEngine Class Reference

#include <embedder_engine.h>

Public Member Functions

 EmbedderEngine (std::unique_ptr< EmbedderThreadHost > thread_host, const TaskRunners &task_runners, const Settings &settings, RunConfiguration run_configuration, const Shell::CreateCallback< PlatformView > &on_create_platform_view, const Shell::CreateCallback< Rasterizer > &on_create_rasterizer, std::unique_ptr< EmbedderExternalTextureResolver > external_texture_resolver)
 
 ~EmbedderEngine ()
 
bool LaunchShell ()
 
bool CollectShell ()
 
const TaskRunnersGetTaskRunners () const
 
bool NotifyCreated ()
 
bool NotifyDestroyed ()
 
bool RunRootIsolate ()
 
bool IsValid () const
 
bool SetViewportMetrics (int64_t view_id, const flutter::ViewportMetrics &metrics)
 
bool DispatchPointerDataPacket (std::unique_ptr< flutter::PointerDataPacket > packet)
 
bool SendPlatformMessage (std::unique_ptr< PlatformMessage > message)
 
bool RegisterTexture (int64_t texture)
 
bool UnregisterTexture (int64_t texture)
 
bool MarkTextureFrameAvailable (int64_t texture)
 
bool SetSemanticsEnabled (bool enabled)
 
bool SetAccessibilityFeatures (int32_t flags)
 
bool DispatchSemanticsAction (int node_id, flutter::SemanticsAction action, fml::MallocMapping args)
 
bool OnVsyncEvent (intptr_t baton, fml::TimePoint frame_start_time, fml::TimePoint frame_target_time)
 
bool ReloadSystemFonts ()
 
bool PostRenderThreadTask (const fml::closure &task)
 
bool RunTask (const FlutterTask *task)
 
bool PostTaskOnEngineManagedNativeThreads (const std::function< void(FlutterNativeThreadType)> &closure) const
 
bool ScheduleFrame ()
 
ShellGetShell ()
 

Detailed Description

Definition at line 23 of file embedder_engine.h.

Constructor & Destructor Documentation

◆ EmbedderEngine()

flutter::EmbedderEngine::EmbedderEngine ( std::unique_ptr< EmbedderThreadHost thread_host,
const TaskRunners task_runners,
const Settings settings,
RunConfiguration  run_configuration,
const Shell::CreateCallback< PlatformView > &  on_create_platform_view,
const Shell::CreateCallback< Rasterizer > &  on_create_rasterizer,
std::unique_ptr< EmbedderExternalTextureResolver external_texture_resolver 
)

Definition at line 24 of file embedder_engine.cc.

32 : thread_host_(std::move(thread_host)),
33 task_runners_(task_runners),
34 run_configuration_(std::move(run_configuration)),
35 shell_args_(std::make_unique<ShellArgs>(settings,
36 on_create_platform_view,
37 on_create_rasterizer)),
38 external_texture_resolver_(std::move(external_texture_resolver)) {}

◆ ~EmbedderEngine()

flutter::EmbedderEngine::~EmbedderEngine ( )
default

Member Function Documentation

◆ CollectShell()

bool flutter::EmbedderEngine::CollectShell ( )

Definition at line 63 of file embedder_engine.cc.

63 {
64 shell_.reset();
65 return IsValid();
66}

◆ DispatchPointerDataPacket()

bool flutter::EmbedderEngine::DispatchPointerDataPacket ( std::unique_ptr< flutter::PointerDataPacket packet)

Definition at line 117 of file embedder_engine.cc.

118 {
119 if (!IsValid() || !packet) {
120 return false;
121 }
122
123 auto platform_view = shell_->GetPlatformView();
124 if (!platform_view) {
125 return false;
126 }
127
128 platform_view->DispatchPointerDataPacket(std::move(packet));
129 return true;
130}
std::unique_ptr< flutter::PlatformViewIOS > platform_view

◆ DispatchSemanticsAction()

bool flutter::EmbedderEngine::DispatchSemanticsAction ( int  node_id,
flutter::SemanticsAction  action,
fml::MallocMapping  args 
)

Definition at line 197 of file embedder_engine.cc.

199 {
200 if (!IsValid()) {
201 return false;
202 }
203 auto platform_view = shell_->GetPlatformView();
204 if (!platform_view) {
205 return false;
206 }
207 platform_view->DispatchSemanticsAction(node_id, action, std::move(args));
208 return true;
209}
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args

◆ GetShell()

Shell & flutter::EmbedderEngine::GetShell ( )

Definition at line 292 of file embedder_engine.cc.

292 {
293 FML_DCHECK(shell_);
294 return *shell_.get();
295}
#define FML_DCHECK(condition)
Definition: logging.h:103

◆ GetTaskRunners()

const TaskRunners & flutter::EmbedderEngine::GetTaskRunners ( ) const

Definition at line 80 of file embedder_engine.cc.

80 {
81 return task_runners_;
82}

◆ IsValid()

bool flutter::EmbedderEngine::IsValid ( ) const

Definition at line 76 of file embedder_engine.cc.

76 {
77 return static_cast<bool>(shell_);
78}

◆ LaunchShell()

bool flutter::EmbedderEngine::LaunchShell ( )

Definition at line 42 of file embedder_engine.cc.

42 {
43 if (!shell_args_) {
44 FML_DLOG(ERROR) << "Invalid shell arguments.";
45 return false;
46 }
47
48 if (shell_) {
49 FML_DLOG(ERROR) << "Shell already initialized";
50 }
51
52 shell_ = Shell::Create(
53 flutter::PlatformData(), task_runners_, shell_args_->settings,
54 shell_args_->on_create_platform_view, shell_args_->on_create_rasterizer);
55
56 // Reset the args no matter what. They will never be used to initialize a
57 // shell again.
58 shell_args_.reset();
59
60 return IsValid();
61}
static std::unique_ptr< Shell > Create(const PlatformData &platform_data, const TaskRunners &task_runners, Settings settings, const CreateCallback< PlatformView > &on_create_platform_view, const CreateCallback< Rasterizer > &on_create_rasterizer, bool is_gpu_disabled=false)
Creates a shell instance using the provided settings. The callbacks to create the various shell subco...
Definition: shell.cc:169
#define FML_DLOG(severity)
Definition: logging.h:102
#define ERROR(message)
Definition: elf_loader.cc:260

◆ MarkTextureFrameAvailable()

bool flutter::EmbedderEngine::MarkTextureFrameAvailable ( int64_t  texture)

Definition at line 164 of file embedder_engine.cc.

164 {
165 if (!IsValid()) {
166 return false;
167 }
168 shell_->GetPlatformView()->MarkTextureFrameAvailable(texture);
169 return true;
170}
FlTexture * texture

◆ NotifyCreated()

bool flutter::EmbedderEngine::NotifyCreated ( )

Definition at line 84 of file embedder_engine.cc.

84 {
85 if (!IsValid()) {
86 return false;
87 }
88
89 shell_->GetPlatformView()->NotifyCreated();
90 return true;
91}

◆ NotifyDestroyed()

bool flutter::EmbedderEngine::NotifyDestroyed ( )

Definition at line 93 of file embedder_engine.cc.

93 {
94 if (!IsValid()) {
95 return false;
96 }
97
98 shell_->GetPlatformView()->NotifyDestroyed();
99 return true;
100}

◆ OnVsyncEvent()

bool flutter::EmbedderEngine::OnVsyncEvent ( intptr_t  baton,
fml::TimePoint  frame_start_time,
fml::TimePoint  frame_target_time 
)

Definition at line 211 of file embedder_engine.cc.

213 {
214 if (!IsValid()) {
215 return false;
216 }
217
219 task_runners_, baton, frame_start_time, frame_target_time);
220}
static bool OnEmbedderVsync(const flutter::TaskRunners &task_runners, intptr_t baton, fml::TimePoint frame_start_time, fml::TimePoint frame_target_time)

◆ PostRenderThreadTask()

bool flutter::EmbedderEngine::PostRenderThreadTask ( const fml::closure task)

Definition at line 230 of file embedder_engine.cc.

230 {
231 if (!IsValid()) {
232 return false;
233 }
234
235 shell_->GetTaskRunners().GetRasterTaskRunner()->PostTask(task);
236 return true;
237}

◆ PostTaskOnEngineManagedNativeThreads()

bool flutter::EmbedderEngine::PostTaskOnEngineManagedNativeThreads ( const std::function< void(FlutterNativeThreadType)> &  closure) const

Definition at line 250 of file embedder_engine.cc.

251 {
252 if (!IsValid() || closure == nullptr) {
253 return false;
254 }
255
256 const auto trampoline = [closure](
258 const fml::RefPtr<fml::TaskRunner>& runner) {
259 runner->PostTask([closure, type] { closure(type); });
260 };
261
262 // Post the task to all thread host threads.
263 const auto& task_runners = shell_->GetTaskRunners();
265 task_runners.GetRasterTaskRunner());
266 trampoline(kFlutterNativeThreadTypeWorker, task_runners.GetIOTaskRunner());
267 trampoline(kFlutterNativeThreadTypeUI, task_runners.GetUITaskRunner());
269 task_runners.GetPlatformTaskRunner());
270
271 // Post the task to all worker threads.
272 auto vm = shell_->GetDartVM();
273 vm->GetConcurrentMessageLoop()->PostTaskToAllWorkers(
275
276 return true;
277}
GLenum type
FlutterNativeThreadType
Definition: embedder.h:2086
@ kFlutterNativeThreadTypeWorker
Definition: embedder.h:2100
@ kFlutterNativeThreadTypeUI
Definition: embedder.h:2097
@ kFlutterNativeThreadTypePlatform
Definition: embedder.h:2090
@ kFlutterNativeThreadTypeRender
Definition: embedder.h:2094
std::function< void()> closure
Definition: closure.h:14

◆ RegisterTexture()

bool flutter::EmbedderEngine::RegisterTexture ( int64_t  texture)

Definition at line 147 of file embedder_engine.cc.

147 {
148 if (!IsValid()) {
149 return false;
150 }
151 shell_->GetPlatformView()->RegisterTexture(
152 external_texture_resolver_->ResolveExternalTexture(texture));
153 return true;
154}

◆ ReloadSystemFonts()

bool flutter::EmbedderEngine::ReloadSystemFonts ( )

Definition at line 222 of file embedder_engine.cc.

222 {
223 if (!IsValid()) {
224 return false;
225 }
226
227 return shell_->ReloadSystemFonts();
228}

◆ RunRootIsolate()

bool flutter::EmbedderEngine::RunRootIsolate ( )

Definition at line 68 of file embedder_engine.cc.

68 {
69 if (!IsValid() || !run_configuration_.IsValid()) {
70 return false;
71 }
72 shell_->RunEngine(std::move(run_configuration_));
73 return true;
74}
bool IsValid() const
A valid run configuration only guarantees that the engine should be able to find the assets and the i...

◆ RunTask()

bool flutter::EmbedderEngine::RunTask ( const FlutterTask task)

Definition at line 239 of file embedder_engine.cc.

239 {
240 // The shell doesn't need to be running or valid for access to the thread
241 // host. This is why there is no `IsValid` check here. This allows embedders
242 // to perform custom task runner interop before the shell is running.
243 if (task == nullptr) {
244 return false;
245 }
246 return thread_host_->PostTask(reinterpret_cast<int64_t>(task->runner),
247 task->task);
248}
FlutterTaskRunner runner
Definition: embedder.h:1551
uint64_t task
Definition: embedder.h:1552

◆ ScheduleFrame()

bool flutter::EmbedderEngine::ScheduleFrame ( )

Definition at line 279 of file embedder_engine.cc.

279 {
280 if (!IsValid()) {
281 return false;
282 }
283
284 auto platform_view = shell_->GetPlatformView();
285 if (!platform_view) {
286 return false;
287 }
288 platform_view->ScheduleFrame();
289 return true;
290}

◆ SendPlatformMessage()

bool flutter::EmbedderEngine::SendPlatformMessage ( std::unique_ptr< PlatformMessage message)

Definition at line 132 of file embedder_engine.cc.

133 {
134 if (!IsValid() || !message) {
135 return false;
136 }
137
138 auto platform_view = shell_->GetPlatformView();
139 if (!platform_view) {
140 return false;
141 }
142
143 platform_view->DispatchPlatformMessage(std::move(message));
144 return true;
145}
Win32Message message

◆ SetAccessibilityFeatures()

bool flutter::EmbedderEngine::SetAccessibilityFeatures ( int32_t  flags)

Definition at line 185 of file embedder_engine.cc.

185 {
186 if (!IsValid()) {
187 return false;
188 }
189 auto platform_view = shell_->GetPlatformView();
190 if (!platform_view) {
191 return false;
192 }
193 platform_view->SetAccessibilityFeatures(flags);
194 return true;
195}
FlutterSemanticsFlag flags

◆ SetSemanticsEnabled()

bool flutter::EmbedderEngine::SetSemanticsEnabled ( bool  enabled)

Definition at line 172 of file embedder_engine.cc.

172 {
173 if (!IsValid()) {
174 return false;
175 }
176
177 auto platform_view = shell_->GetPlatformView();
178 if (!platform_view) {
179 return false;
180 }
181 platform_view->SetSemanticsEnabled(enabled);
182 return true;
183}

◆ SetViewportMetrics()

bool flutter::EmbedderEngine::SetViewportMetrics ( int64_t  view_id,
const flutter::ViewportMetrics metrics 
)

Definition at line 102 of file embedder_engine.cc.

104 {
105 if (!IsValid()) {
106 return false;
107 }
108
109 auto platform_view = shell_->GetPlatformView();
110 if (!platform_view) {
111 return false;
112 }
113 platform_view->SetViewportMetrics(view_id, metrics);
114 return true;
115}

◆ UnregisterTexture()

bool flutter::EmbedderEngine::UnregisterTexture ( int64_t  texture)

Definition at line 156 of file embedder_engine.cc.

156 {
157 if (!IsValid()) {
158 return false;
159 }
160 shell_->GetPlatformView()->UnregisterTexture(texture);
161 return true;
162}

The documentation for this class was generated from the following files: