Flutter Engine
flutter::EmbedderEngine Class Reference

#include <embedder_engine.h>

Public Member Functions

 EmbedderEngine (std::unique_ptr< EmbedderThreadHost > thread_host, TaskRunners task_runners, Settings settings, RunConfiguration run_configuration, Shell::CreateCallback< PlatformView > on_create_platform_view, Shell::CreateCallback< Rasterizer > on_create_rasterizer)
 
 ~EmbedderEngine ()
 
bool LaunchShell ()
 
bool CollectShell ()
 
const TaskRunnersGetTaskRunners () const
 
bool NotifyCreated ()
 
bool NotifyDestroyed ()
 
bool RunRootIsolate ()
 
bool IsValid () const
 
bool SetViewportMetrics (flutter::ViewportMetrics metrics)
 
bool DispatchPointerDataPacket (std::unique_ptr< flutter::PointerDataPacket > packet)
 
bool SendPlatformMessage (fml::RefPtr< flutter::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 id, flutter::SemanticsAction action, std::vector< uint8_t > 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 (std::function< void(FlutterNativeThreadType)> closure) const
 
ShellGetShell ()
 

Detailed Description

Definition at line 27 of file embedder_engine.h.

Constructor & Destructor Documentation

◆ EmbedderEngine()

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

Definition at line 24 of file embedder_engine.cc.

References ~EmbedderEngine().

36  : thread_host_(std::move(thread_host)),
37  task_runners_(task_runners),
38  run_configuration_(std::move(run_configuration)),
39  shell_args_(std::make_unique<ShellArgs>(std::move(settings),
40  on_create_platform_view,
41  on_create_rasterizer))
42 #ifdef SHELL_ENABLE_GL
43  ,
44  external_texture_callback_(external_texture_callback)
45 #endif
46 {
47 }

◆ ~EmbedderEngine()

flutter::EmbedderEngine::~EmbedderEngine ( )
default

Referenced by EmbedderEngine().

Member Function Documentation

◆ CollectShell()

bool flutter::EmbedderEngine::CollectShell ( )

Definition at line 72 of file embedder_engine.cc.

References IsValid().

72  {
73  shell_.reset();
74  return IsValid();
75 }

◆ DispatchPointerDataPacket()

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

Definition at line 124 of file embedder_engine.cc.

References IsValid().

125  {
126  if (!IsValid() || !packet) {
127  return false;
128  }
129 
130  auto platform_view = shell_->GetPlatformView();
131  if (!platform_view) {
132  return false;
133  }
134 
135  platform_view->DispatchPointerDataPacket(std::move(packet));
136  return true;
137 }

◆ DispatchSemanticsAction()

bool flutter::EmbedderEngine::DispatchSemanticsAction ( int  id,
flutter::SemanticsAction  action,
std::vector< uint8_t >  args 
)

Definition at line 214 of file embedder_engine.cc.

References IsValid().

216  {
217  if (!IsValid()) {
218  return false;
219  }
220  auto platform_view = shell_->GetPlatformView();
221  if (!platform_view) {
222  return false;
223  }
224  platform_view->DispatchSemanticsAction(id, action, std::move(args));
225  return true;
226 }
SemanticsAction action

◆ GetShell()

Shell & flutter::EmbedderEngine::GetShell ( )

Definition at line 295 of file embedder_engine.cc.

References FML_DCHECK.

295  {
296  FML_DCHECK(shell_);
297  return *shell_.get();
298 }
#define FML_DCHECK(condition)
Definition: logging.h:86

◆ GetTaskRunners()

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

Definition at line 89 of file embedder_engine.cc.

89  {
90  return task_runners_;
91 }

◆ IsValid()

◆ LaunchShell()

bool flutter::EmbedderEngine::LaunchShell ( )

Definition at line 51 of file embedder_engine.cc.

References flutter::Shell::Create(), FML_DLOG, and IsValid().

51  {
52  if (!shell_args_) {
53  FML_DLOG(ERROR) << "Invalid shell arguments.";
54  return false;
55  }
56 
57  if (shell_) {
58  FML_DLOG(ERROR) << "Shell already initialized";
59  }
60 
61  shell_ = Shell::Create(task_runners_, shell_args_->settings,
62  shell_args_->on_create_platform_view,
63  shell_args_->on_create_rasterizer);
64 
65  // Reset the args no matter what. They will never be used to initialize a
66  // shell again.
67  shell_args_.reset();
68 
69  return IsValid();
70 }
#define FML_DLOG(severity)
Definition: logging.h:85
static std::unique_ptr< Shell > Create(TaskRunners task_runners, Settings settings, const CreateCallback< PlatformView > &on_create_platform_view, const CreateCallback< Rasterizer > &on_create_rasterizer)
Creates a shell instance using the provided settings. The callbacks to create the various shell subco...
Definition: shell.cc:239

◆ MarkTextureFrameAvailable()

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

Definition at line 178 of file embedder_engine.cc.

References IsValid().

178  {
179 #ifdef SHELL_ENABLE_GL
180  if (!IsValid() || !external_texture_callback_) {
181  return false;
182  }
183  shell_->GetPlatformView()->MarkTextureFrameAvailable(texture);
184 #endif
185 
186  return true;
187 }

◆ NotifyCreated()

bool flutter::EmbedderEngine::NotifyCreated ( )

Definition at line 93 of file embedder_engine.cc.

References IsValid().

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

◆ NotifyDestroyed()

bool flutter::EmbedderEngine::NotifyDestroyed ( )

Definition at line 102 of file embedder_engine.cc.

References IsValid().

Referenced by FlutterEngineDeinitialize().

102  {
103  if (!IsValid()) {
104  return false;
105  }
106 
107  shell_->GetPlatformView()->NotifyDestroyed();
108  return true;
109 }

◆ OnVsyncEvent()

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

Definition at line 228 of file embedder_engine.cc.

References IsValid(), and flutter::VsyncWaiterEmbedder::OnEmbedderVsync().

230  {
231  if (!IsValid()) {
232  return false;
233  }
234 
235  return VsyncWaiterEmbedder::OnEmbedderVsync(baton, frame_start_time,
236  frame_target_time);
237 }
static bool OnEmbedderVsync(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 247 of file embedder_engine.cc.

References IsValid().

247  {
248  if (!IsValid()) {
249  return false;
250  }
251 
252  shell_->GetTaskRunners().GetRasterTaskRunner()->PostTask(task);
253  return true;
254 }

◆ PostTaskOnEngineManagedNativeThreads()

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

Definition at line 267 of file embedder_engine.cc.

References IsValid(), kFlutterNativeThreadTypePlatform, kFlutterNativeThreadTypeRender, kFlutterNativeThreadTypeUI, and kFlutterNativeThreadTypeWorker.

268  {
269  if (!IsValid() || closure == nullptr) {
270  return false;
271  }
272 
273  const auto trampoline = [closure](FlutterNativeThreadType type,
275  runner->PostTask([closure, type] { closure(type); });
276  };
277 
278  // Post the task to all thread host threads.
279  const auto& task_runners = shell_->GetTaskRunners();
281  task_runners.GetRasterTaskRunner());
282  trampoline(kFlutterNativeThreadTypeWorker, task_runners.GetIOTaskRunner());
283  trampoline(kFlutterNativeThreadTypeUI, task_runners.GetUITaskRunner());
285  task_runners.GetPlatformTaskRunner());
286 
287  // Post the task to all worker threads.
288  auto vm = shell_->GetDartVM();
289  vm->GetConcurrentMessageLoop()->PostTaskToAllWorkers(
291 
292  return true;
293 }
std::function< void()> closure
Definition: closure.h:14
FlutterNativeThreadType
Definition: embedder.h:1092

◆ RegisterTexture()

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

Definition at line 154 of file embedder_engine.cc.

References IsValid().

154  {
155 #ifdef SHELL_ENABLE_GL
156  if (!IsValid() || !external_texture_callback_) {
157  return false;
158  }
159  shell_->GetPlatformView()->RegisterTexture(
160  std::make_unique<EmbedderExternalTextureGL>(texture,
161  external_texture_callback_));
162 #endif
163 
164  return true;
165 }

◆ ReloadSystemFonts()

bool flutter::EmbedderEngine::ReloadSystemFonts ( )

Definition at line 239 of file embedder_engine.cc.

References IsValid().

239  {
240  if (!IsValid()) {
241  return false;
242  }
243 
244  return shell_->ReloadSystemFonts();
245 }

◆ RunRootIsolate()

bool flutter::EmbedderEngine::RunRootIsolate ( )

Definition at line 77 of file embedder_engine.cc.

References IsValid(), and flutter::RunConfiguration::IsValid().

77  {
78  if (!IsValid() || !run_configuration_.IsValid()) {
79  return false;
80  }
81  shell_->RunEngine(std::move(run_configuration_));
82  return true;
83 }
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 256 of file embedder_engine.cc.

References FlutterTask::runner, and FlutterTask::task.

256  {
257  // The shell doesn't need to be running or valid for access to the thread
258  // host. This is why there is no `IsValid` check here. This allows embedders
259  // to perform custom task runner interop before the shell is running.
260  if (task == nullptr) {
261  return false;
262  }
263  return thread_host_->PostTask(reinterpret_cast<int64_t>(task->runner),
264  task->task);
265 }
FlutterTaskRunner runner
Definition: embedder.h:703
uint64_t task
Definition: embedder.h:704

◆ SendPlatformMessage()

bool flutter::EmbedderEngine::SendPlatformMessage ( fml::RefPtr< flutter::PlatformMessage message)

Definition at line 139 of file embedder_engine.cc.

References IsValid().

140  {
141  if (!IsValid() || !message) {
142  return false;
143  }
144 
145  auto platform_view = shell_->GetPlatformView();
146  if (!platform_view) {
147  return false;
148  }
149 
150  platform_view->DispatchPlatformMessage(message);
151  return true;
152 }

◆ SetAccessibilityFeatures()

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

Definition at line 202 of file embedder_engine.cc.

References IsValid().

202  {
203  if (!IsValid()) {
204  return false;
205  }
206  auto platform_view = shell_->GetPlatformView();
207  if (!platform_view) {
208  return false;
209  }
210  platform_view->SetAccessibilityFeatures(flags);
211  return true;
212 }
DEF_SWITCHES_START snapshot asset Path to the directory containing the four files specified by VmSnapshotInstructions and IsolateSnapshotInstructions vm snapshot The VM instructions snapshot that will be memory mapped as read and executable SnapshotAssetPath must be present isolate snapshot The isolate instructions snapshot that will be memory mapped as read and executable SnapshotAssetPath must be present icu symbol Prefix for the symbols representing ICU data linked into the Flutter library dart flags
Definition: switches.h:66

◆ SetSemanticsEnabled()

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

Definition at line 189 of file embedder_engine.cc.

References IsValid().

189  {
190  if (!IsValid()) {
191  return false;
192  }
193 
194  auto platform_view = shell_->GetPlatformView();
195  if (!platform_view) {
196  return false;
197  }
198  platform_view->SetSemanticsEnabled(enabled);
199  return true;
200 }

◆ SetViewportMetrics()

bool flutter::EmbedderEngine::SetViewportMetrics ( flutter::ViewportMetrics  metrics)

Definition at line 111 of file embedder_engine.cc.

References IsValid().

111  {
112  if (!IsValid()) {
113  return false;
114  }
115 
116  auto platform_view = shell_->GetPlatformView();
117  if (!platform_view) {
118  return false;
119  }
120  platform_view->SetViewportMetrics(std::move(metrics));
121  return true;
122 }

◆ UnregisterTexture()

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

Definition at line 167 of file embedder_engine.cc.

References IsValid().

167  {
168 #ifdef SHELL_ENABLE_GL
169  if (!IsValid() || !external_texture_callback_) {
170  return false;
171  }
172  shell_->GetPlatformView()->UnregisterTexture(texture);
173 #endif
174 
175  return true;
176 }

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