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, 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 (flutter::ViewportMetrics metrics)
 
bool DispatchPointerDataPacket (std::unique_ptr< flutter::PointerDataPacket > packet)
 
bool DispatchKeyDataPacket (std::unique_ptr< flutter::KeyDataPacket > packet, KeyDataResponse callback)
 Notifies the platform view that the embedder has sent it a key data packet. A key data packet contains one key event. This call originates in the platform view and the shell has forwarded the same to the engine on the UI task runner here. The platform view will decide whether to handle this event, and send the result using callback, which will be called exactly once. More...
 
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 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 (std::function< void(FlutterNativeThreadType)> closure) const
 
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,
flutter::TaskRunners  task_runners,
flutter::Settings  settings,
RunConfiguration  run_configuration,
Shell::CreateCallback< PlatformView on_create_platform_view,
Shell::CreateCallback< Rasterizer on_create_rasterizer,
std::unique_ptr< EmbedderExternalTextureResolver external_texture_resolver 
)

Definition at line 24 of file embedder_engine.cc.

References ~EmbedderEngine().

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>(std::move(settings),
36  on_create_platform_view,
37  on_create_rasterizer)),
38  external_texture_resolver_(std::move(external_texture_resolver)) {}

◆ ~EmbedderEngine()

flutter::EmbedderEngine::~EmbedderEngine ( )
default

Referenced by EmbedderEngine().

Member Function Documentation

◆ CollectShell()

bool flutter::EmbedderEngine::CollectShell ( )

Definition at line 63 of file embedder_engine.cc.

References IsValid().

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

◆ DispatchKeyDataPacket()

bool flutter::EmbedderEngine::DispatchKeyDataPacket ( std::unique_ptr< flutter::KeyDataPacket packet,
KeyDataResponse  callback 
)

Notifies the platform view that the embedder has sent it a key data packet. A key data packet contains one key event. This call originates in the platform view and the shell has forwarded the same to the engine on the UI task runner here. The platform view will decide whether to handle this event, and send the result using callback, which will be called exactly once.

Parameters
[in]packetThe key data packet.
[in]callbackCalled when the framework has decided whether to handle this key data.

Definition at line 130 of file embedder_engine.cc.

References IsValid(), and platform_view.

132  {
133  if (!IsValid() || !packet) {
134  return false;
135  }
136 
137  auto platform_view = shell_->GetPlatformView();
138  if (!platform_view) {
139  return false;
140  }
141 
142  platform_view->DispatchKeyDataPacket(std::move(packet), std::move(callback));
143  return true;
144 }
std::unique_ptr< flutter::PlatformViewIOS > platform_view
FlKeyEvent FlKeyResponderAsyncCallback callback

◆ DispatchPointerDataPacket()

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

Definition at line 115 of file embedder_engine.cc.

References IsValid(), and platform_view.

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

◆ DispatchSemanticsAction()

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

Definition at line 211 of file embedder_engine.cc.

References IsValid(), and platform_view.

213  {
214  if (!IsValid()) {
215  return false;
216  }
217  auto platform_view = shell_->GetPlatformView();
218  if (!platform_view) {
219  return false;
220  }
221  platform_view->DispatchSemanticsAction(id, action, std::move(args));
222  return true;
223 }
std::unique_ptr< flutter::PlatformViewIOS > platform_view
SemanticsAction action

◆ GetShell()

Shell & flutter::EmbedderEngine::GetShell ( )

Definition at line 292 of file embedder_engine.cc.

References FML_DCHECK.

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

◆ GetTaskRunners()

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

Definition at line 80 of file embedder_engine.cc.

80  {
81  return task_runners_;
82 }

◆ IsValid()

◆ LaunchShell()

bool flutter::EmbedderEngine::LaunchShell ( )

Definition at line 42 of file embedder_engine.cc.

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

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, 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:126
#define FML_DLOG(severity)
Definition: logging.h:85

◆ MarkTextureFrameAvailable()

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

Definition at line 178 of file embedder_engine.cc.

References IsValid().

178  {
179  if (!IsValid()) {
180  return false;
181  }
182  shell_->GetPlatformView()->MarkTextureFrameAvailable(texture);
183  return true;
184 }
G_BEGIN_DECLS FlTexture * texture

◆ NotifyCreated()

bool flutter::EmbedderEngine::NotifyCreated ( )

Definition at line 84 of file embedder_engine.cc.

References IsValid().

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.

References IsValid().

Referenced by FlutterEngineDeinitialize().

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 225 of file embedder_engine.cc.

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

227  {
228  if (!IsValid()) {
229  return false;
230  }
231 
232  return VsyncWaiterEmbedder::OnEmbedderVsync(baton, frame_start_time,
233  frame_target_time);
234 }
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 244 of file embedder_engine.cc.

References IsValid().

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

◆ PostTaskOnEngineManagedNativeThreads()

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

Definition at line 264 of file embedder_engine.cc.

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

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

◆ RegisterTexture()

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

Definition at line 161 of file embedder_engine.cc.

References IsValid().

161  {
162  if (!IsValid()) {
163  return false;
164  }
165  shell_->GetPlatformView()->RegisterTexture(
166  external_texture_resolver_->ResolveExternalTexture(texture));
167  return true;
168 }
G_BEGIN_DECLS FlTexture * texture

◆ ReloadSystemFonts()

bool flutter::EmbedderEngine::ReloadSystemFonts ( )

Definition at line 236 of file embedder_engine.cc.

References IsValid().

236  {
237  if (!IsValid()) {
238  return false;
239  }
240 
241  return shell_->ReloadSystemFonts();
242 }

◆ RunRootIsolate()

bool flutter::EmbedderEngine::RunRootIsolate ( )

Definition at line 68 of file embedder_engine.cc.

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

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 253 of file embedder_engine.cc.

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

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

◆ SendPlatformMessage()

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

Definition at line 146 of file embedder_engine.cc.

References IsValid(), and platform_view.

147  {
148  if (!IsValid() || !message) {
149  return false;
150  }
151 
152  auto platform_view = shell_->GetPlatformView();
153  if (!platform_view) {
154  return false;
155  }
156 
157  platform_view->DispatchPlatformMessage(std::move(message));
158  return true;
159 }
std::unique_ptr< flutter::PlatformViewIOS > platform_view

◆ SetAccessibilityFeatures()

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

Definition at line 199 of file embedder_engine.cc.

References IsValid(), and platform_view.

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->SetAccessibilityFeatures(flags);
208  return true;
209 }
std::unique_ptr< flutter::PlatformViewIOS > platform_view
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 186 of file embedder_engine.cc.

References IsValid(), and platform_view.

186  {
187  if (!IsValid()) {
188  return false;
189  }
190 
191  auto platform_view = shell_->GetPlatformView();
192  if (!platform_view) {
193  return false;
194  }
195  platform_view->SetSemanticsEnabled(enabled);
196  return true;
197 }
std::unique_ptr< flutter::PlatformViewIOS > platform_view

◆ SetViewportMetrics()

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

Definition at line 102 of file embedder_engine.cc.

References IsValid(), and platform_view.

102  {
103  if (!IsValid()) {
104  return false;
105  }
106 
107  auto platform_view = shell_->GetPlatformView();
108  if (!platform_view) {
109  return false;
110  }
111  platform_view->SetViewportMetrics(std::move(metrics));
112  return true;
113 }
std::unique_ptr< flutter::PlatformViewIOS > platform_view

◆ UnregisterTexture()

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

Definition at line 170 of file embedder_engine.cc.

References IsValid().

170  {
171  if (!IsValid()) {
172  return false;
173  }
174  shell_->GetPlatformView()->UnregisterTexture(texture);
175  return true;
176 }
G_BEGIN_DECLS FlTexture * texture

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