Flutter Engine
 
Loading...
Searching...
No Matches
engine.cc
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
6
7#include <cstring>
8#include <memory>
9#include <string>
10#include <utility>
11#include <vector>
12
19#include "rapidjson/document.h"
20
21namespace flutter {
22
23static constexpr char kAssetChannel[] = "flutter/assets";
24static constexpr char kLifecycleChannel[] = "flutter/lifecycle";
25static constexpr char kNavigationChannel[] = "flutter/navigation";
26static constexpr char kLocalizationChannel[] = "flutter/localization";
27static constexpr char kSettingsChannel[] = "flutter/settings";
28static constexpr char kIsolateChannel[] = "flutter/isolate";
29
30namespace {
31fml::MallocMapping MakeMapping(const std::string& str) {
32 return fml::MallocMapping::Copy(str.c_str(), str.length());
33}
34} // namespace
35
37 Delegate& delegate,
38 const PointerDataDispatcherMaker& dispatcher_maker,
39 const std::shared_ptr<fml::ConcurrentTaskRunner>& image_decoder_task_runner,
40 const TaskRunners& task_runners,
41 const Settings& settings,
42 std::unique_ptr<Animator> animator,
43 const fml::WeakPtr<IOManager>& io_manager,
44 const std::shared_ptr<FontCollection>& font_collection,
45 std::unique_ptr<RuntimeController> runtime_controller,
46 const std::shared_ptr<fml::SyncSwitch>& gpu_disabled_switch)
47 : delegate_(delegate),
48 settings_(settings),
49 animator_(std::move(animator)),
50 runtime_controller_(std::move(runtime_controller)),
51 font_collection_(font_collection),
52 image_decoder_(ImageDecoder::Make(settings_,
53 task_runners,
54 image_decoder_task_runner,
55 io_manager,
56 gpu_disabled_switch)),
57 task_runners_(task_runners),
58 weak_factory_(this) {
59 pointer_data_dispatcher_ = dispatcher_maker(*this);
60}
61
63 const PointerDataDispatcherMaker& dispatcher_maker,
64 DartVM& vm,
65 fml::RefPtr<const DartSnapshot> isolate_snapshot,
66 const TaskRunners& task_runners,
67 const PlatformData& platform_data,
68 const Settings& settings,
69 std::unique_ptr<Animator> animator,
70 fml::WeakPtr<IOManager> io_manager,
71 const fml::RefPtr<SkiaUnrefQueue>& unref_queue,
73 const std::shared_ptr<fml::SyncSwitch>& gpu_disabled_switch,
74 const std::shared_future<impeller::RuntimeStageBackend>&
75 runtime_stage_backend)
76 : Engine(delegate,
77 dispatcher_maker,
78 vm.GetConcurrentWorkerTaskRunner(),
79 task_runners,
80 settings,
81 std::move(animator),
82 io_manager,
83 std::make_shared<FontCollection>(),
84 nullptr,
85 gpu_disabled_switch) {
86 runtime_controller_ = std::make_unique<RuntimeController>(
87 *this, // runtime delegate
88 &vm, // VM
89 std::move(isolate_snapshot), // isolate snapshot
90 settings_.idle_notification_callback, // idle notification callback
91 platform_data, // platform data
92 settings_.isolate_create_callback, // isolate create callback
93 settings_.isolate_shutdown_callback, // isolate shutdown callback
94 settings_.persistent_isolate_data, // persistent isolate data
96 task_runners_, // task runners
97 std::move(snapshot_delegate), // snapshot delegate
98 std::move(io_manager), // io manager
99 unref_queue, // Skia unref queue
100 image_decoder_->GetWeakPtr(), // image decoder
101 image_generator_registry_.GetWeakPtr(), // image generator registry
102 settings_.advisory_script_uri, // advisory script uri
103 settings_.advisory_script_entrypoint, // advisory script entrypoint
104 settings_
105 .skia_deterministic_rendering_on_cpu, // deterministic rendering
106 vm.GetConcurrentWorkerTaskRunner(), // concurrent task runner
107 runtime_stage_backend, // runtime stage
108 settings_.enable_impeller, // enable impeller
109 settings_.enable_flutter_gpu // enable impeller
110 });
111}
112
113std::unique_ptr<Engine> Engine::Spawn(
114 Delegate& delegate,
115 const PointerDataDispatcherMaker& dispatcher_maker,
116 const Settings& settings,
117 std::unique_ptr<Animator> animator,
118 const std::string& initial_route,
119 const fml::WeakPtr<IOManager>& io_manager,
121 const std::shared_ptr<fml::SyncSwitch>& gpu_disabled_switch) const {
122 auto result = std::make_unique<Engine>(
123 /*delegate=*/delegate,
124 /*dispatcher_maker=*/dispatcher_maker,
125 /*image_decoder_task_runner=*/
126 runtime_controller_->GetDartVM()->GetConcurrentWorkerTaskRunner(),
127 /*task_runners=*/task_runners_,
128 /*settings=*/settings,
129 /*animator=*/std::move(animator),
130 /*io_manager=*/io_manager,
131 /*font_collection=*/font_collection_,
132 /*runtime_controller=*/nullptr,
133 /*gpu_disabled_switch=*/gpu_disabled_switch);
134 result->runtime_controller_ = runtime_controller_->Spawn(
135 /*p_client=*/*result,
136 /*advisory_script_uri=*/settings.advisory_script_uri,
137 /*advisory_script_entrypoint=*/settings.advisory_script_entrypoint,
138 /*idle_notification_callback=*/settings.idle_notification_callback,
139 /*isolate_create_callback=*/settings.isolate_create_callback,
140 /*isolate_shutdown_callback=*/settings.isolate_shutdown_callback,
141 /*persistent_isolate_data=*/settings.persistent_isolate_data,
142 /*io_manager=*/io_manager,
143 /*image_decoder=*/result->GetImageDecoderWeakPtr(),
144 /*image_generator_registry=*/result->GetImageGeneratorRegistry(),
145 /*snapshot_delegate=*/std::move(snapshot_delegate));
146 result->initial_route_ = initial_route;
147 result->asset_manager_ = asset_manager_;
148 return result;
149}
150
151Engine::~Engine() = default;
152
154 return weak_factory_.GetWeakPtr();
155}
156
158 TRACE_EVENT0("flutter", "Engine::SetupDefaultFontManager");
159 font_collection_->SetupDefaultFontManager(settings_.font_initialization_data);
160}
161
162std::shared_ptr<AssetManager> Engine::GetAssetManager() {
163 return asset_manager_;
164}
165
167 return image_decoder_->GetWeakPtr();
168}
169
172 return image_generator_registry_.GetWeakPtr();
173}
174
176 const std::shared_ptr<AssetManager>& new_asset_manager) {
177 if (asset_manager_ && new_asset_manager &&
178 *asset_manager_ == *new_asset_manager) {
179 return false;
180 }
181
182 asset_manager_ = new_asset_manager;
183
184 if (!asset_manager_) {
185 return false;
186 }
187
188 // Using libTXT as the text engine.
189 if (settings_.use_asset_fonts) {
190 font_collection_->RegisterFonts(asset_manager_);
191 }
192
193 if (settings_.use_test_fonts) {
194 font_collection_->RegisterTestFonts();
195 }
196
197 if (native_assets_manager_ == nullptr) {
198 native_assets_manager_ = std::make_shared<NativeAssetsManager>();
199 }
200 native_assets_manager_->RegisterNativeAssets(asset_manager_);
201
202 return true;
203}
204
206 TRACE_EVENT0("flutter", "Engine::Restart");
207 if (!configuration.IsValid()) {
208 FML_LOG(ERROR) << "Engine run configuration was invalid.";
209 return false;
210 }
211 delegate_.OnPreEngineRestart();
212 runtime_controller_ = runtime_controller_->Clone();
213 UpdateAssetManager(nullptr);
214 return Run(std::move(configuration)) == Engine::RunStatus::Success;
215}
216
218 if (!configuration.IsValid()) {
219 FML_LOG(ERROR) << "Engine run configuration was invalid.";
220 return RunStatus::Failure;
221 }
222
223 last_entry_point_ = configuration.GetEntrypoint();
224 last_entry_point_library_ = configuration.GetEntrypointLibrary();
225#if (FLUTTER_RUNTIME_MODE == FLUTTER_RUNTIME_MODE_DEBUG)
226 // This is only used to support restart.
227 last_entry_point_args_ = configuration.GetEntrypointArgs();
228#endif
229
230 last_engine_id_ = configuration.GetEngineId();
231
232 UpdateAssetManager(configuration.GetAssetManager());
233
234 if (runtime_controller_->IsRootIsolateRunning()) {
236 }
237
238 // If the embedding prefetched the default font manager, then set up the
239 // font manager later in the engine launch process. This makes it less
240 // likely that the setup will need to wait for the prefetch to complete.
241 auto root_isolate_create_callback = [&]() {
242 if (settings_.prefetched_default_font_manager) {
244 }
245 };
246
247 if (settings_.merged_platform_ui_thread ==
249 // Queue a task to the UI task runner that sets the owner of the root
250 // isolate. This task runs after the thread merge and will therefore be
251 // executed on the platform thread. The task will run before any tasks
252 // queued by LaunchRootIsolate that execute the app's Dart code.
253 task_runners_.GetUITaskRunner()->PostTask([engine = GetWeakPtr()]() {
254 if (engine) {
255 engine->runtime_controller_->SetRootIsolateOwnerToCurrentThread();
256 }
257 });
258 }
259
260 if (!runtime_controller_->LaunchRootIsolate(
261 settings_, //
262 root_isolate_create_callback, //
263 configuration.GetEntrypoint(), //
264 configuration.GetEntrypointLibrary(), //
265 configuration.GetEntrypointArgs(), //
266 configuration.TakeIsolateConfiguration(), //
267 native_assets_manager_, //
268 configuration.GetEngineId())) //
269 {
270 return RunStatus::Failure;
271 }
272
273 auto service_id = runtime_controller_->GetRootIsolateServiceID();
274 if (service_id.has_value()) {
275 std::unique_ptr<PlatformMessage> service_id_message =
276 std::make_unique<flutter::PlatformMessage>(
277 kIsolateChannel, MakeMapping(service_id.value()), nullptr);
278 HandlePlatformMessage(std::move(service_id_message));
279 }
280
281 if (settings_.merged_platform_ui_thread ==
283 // Move the UI task runner to the platform thread.
285 task_runners_.GetPlatformTaskRunner()->GetTaskQueueId(),
286 task_runners_.GetUITaskRunner()->GetTaskQueueId());
287 if (!success) {
288 FML_LOG(ERROR)
289 << "Unable to move the UI task runner to the platform thread";
290 }
291 }
292
294}
295
296void Engine::BeginFrame(fml::TimePoint frame_time, uint64_t frame_number) {
297 runtime_controller_->BeginFrame(frame_time, frame_number);
298}
299
300void Engine::ReportTimings(std::vector<int64_t> timings) {
301 runtime_controller_->ReportTimings(std::move(timings));
302}
303
305 runtime_controller_->NotifyIdle(deadline);
306}
307
308std::optional<uint32_t> Engine::GetUIIsolateReturnCode() {
309 return runtime_controller_->GetRootIsolateReturnCode();
310}
311
313 return runtime_controller_->GetMainPort();
314}
315
317 return runtime_controller_->GetIsolateName();
318}
319
321 return runtime_controller_->HasLivePorts();
322}
323
325 return runtime_controller_->HasPendingMicrotasks();
326}
327
329 return runtime_controller_->GetLastError();
330}
331
333 const ViewportMetrics& view_metrics,
334 std::function<void(bool added)> callback) {
335 runtime_controller_->AddView(view_id, view_metrics, std::move(callback));
336}
337
339 return runtime_controller_->RemoveView(view_id);
340}
341
343 return runtime_controller_->SendViewFocusEvent(event);
344}
345
347 const ViewportMetrics& metrics) {
348 runtime_controller_->SetViewportMetrics(view_id, metrics);
350}
351
352void Engine::DispatchPlatformMessage(std::unique_ptr<PlatformMessage> message) {
353 std::string channel = message->channel();
354 if (channel == kLifecycleChannel) {
355 if (HandleLifecyclePlatformMessage(message.get())) {
356 return;
357 }
358 } else if (channel == kLocalizationChannel) {
359 if (HandleLocalizationPlatformMessage(message.get())) {
360 return;
361 }
362 } else if (channel == kSettingsChannel) {
363 HandleSettingsPlatformMessage(message.get());
364 return;
365 } else if (!runtime_controller_->IsRootIsolateRunning() &&
367 // If there's no runtime_, we may still need to set the initial route.
368 HandleNavigationPlatformMessage(std::move(message));
369 return;
370 }
371
372 if (runtime_controller_->IsRootIsolateRunning() &&
373 runtime_controller_->DispatchPlatformMessage(std::move(message))) {
374 return;
375 }
376
377 FML_DLOG(WARNING) << "Dropping platform message on channel: " << channel;
378}
379
380bool Engine::HandleLifecyclePlatformMessage(PlatformMessage* message) {
381 const auto& data = message->data();
382 std::string state(reinterpret_cast<const char*>(data.GetMapping()),
383 data.GetSize());
384
385 // Always schedule a frame when the app does become active as per API
386 // recommendation
387 // https://developer.apple.com/documentation/uikit/uiapplicationdelegate/1622956-applicationdidbecomeactive?language=objc
388 if (state == "AppLifecycleState.resumed" ||
389 state == "AppLifecycleState.inactive") {
391 }
392 runtime_controller_->SetInitialLifecycleState(state);
393 // Always forward these messages to the framework by returning false.
394 return false;
395}
396
397bool Engine::HandleNavigationPlatformMessage(
398 std::unique_ptr<PlatformMessage> message) {
399 const auto& data = message->data();
400
401 rapidjson::Document document;
402 document.Parse(reinterpret_cast<const char*>(data.GetMapping()),
403 data.GetSize());
404 if (document.HasParseError() || !document.IsObject()) {
405 return false;
406 }
407 auto root = document.GetObject();
408 auto method = root.FindMember("method");
409 if (method->value != "setInitialRoute") {
410 return false;
411 }
412 auto route = root.FindMember("args");
413 initial_route_ = route->value.GetString();
414 return true;
415}
416
417bool Engine::HandleLocalizationPlatformMessage(PlatformMessage* message) {
418 const auto& data = message->data();
419
420 rapidjson::Document document;
421 document.Parse(reinterpret_cast<const char*>(data.GetMapping()),
422 data.GetSize());
423 if (document.HasParseError() || !document.IsObject()) {
424 return false;
425 }
426 auto root = document.GetObject();
427 auto method = root.FindMember("method");
428 if (method == root.MemberEnd()) {
429 return false;
430 }
431 const size_t strings_per_locale = 4;
432 if (method->value == "setLocale") {
433 // Decode and pass the list of locale data onwards to dart.
434 auto args = root.FindMember("args");
435 if (args == root.MemberEnd() || !args->value.IsArray()) {
436 return false;
437 }
438
439 if (args->value.Size() % strings_per_locale != 0) {
440 return false;
441 }
442 std::vector<std::string> locale_data;
443 for (size_t locale_index = 0; locale_index < args->value.Size();
444 locale_index += strings_per_locale) {
445 if (!args->value[locale_index].IsString() ||
446 !args->value[locale_index + 1].IsString()) {
447 return false;
448 }
449 locale_data.push_back(args->value[locale_index].GetString());
450 locale_data.push_back(args->value[locale_index + 1].GetString());
451 locale_data.push_back(args->value[locale_index + 2].GetString());
452 locale_data.push_back(args->value[locale_index + 3].GetString());
453 }
454
455 return runtime_controller_->SetLocales(locale_data);
456 }
457 return false;
458}
459
460void Engine::HandleSettingsPlatformMessage(PlatformMessage* message) {
461 const auto& data = message->data();
462 std::string jsonData(reinterpret_cast<const char*>(data.GetMapping()),
463 data.GetSize());
464 if (runtime_controller_->SetUserSettingsData(jsonData)) {
466 }
467}
468
470 std::unique_ptr<PointerDataPacket> packet,
471 uint64_t trace_flow_id) {
472 TRACE_EVENT0_WITH_FLOW_IDS("flutter", "Engine::DispatchPointerDataPacket",
473 /*flow_id_count=*/1,
474 /*flow_ids=*/&trace_flow_id);
475 TRACE_FLOW_STEP("flutter", "PointerEvent", trace_flow_id);
476 pointer_data_dispatcher_->DispatchPacket(std::move(packet), trace_flow_id);
477}
478
480 int node_id,
483 runtime_controller_->DispatchSemanticsAction(view_id, node_id, action,
484 std::move(args));
485}
486
487void Engine::SetSemanticsEnabled(bool enabled) {
488 runtime_controller_->SetSemanticsEnabled(enabled);
489}
490
492 runtime_controller_->SetAccessibilityFeatures(flags);
493}
494
495std::string Engine::DefaultRouteName() {
496 if (!initial_route_.empty()) {
497 return initial_route_;
498 }
499 return "/";
500}
501
502void Engine::ScheduleFrame(bool regenerate_layer_trees) {
503 animator_->RequestFrame(regenerate_layer_trees);
504}
505
507 animator_->OnAllViewsRendered();
508}
509
510void Engine::Render(int64_t view_id,
511 std::unique_ptr<flutter::LayerTree> layer_tree,
512 float device_pixel_ratio) {
513 if (!layer_tree) {
514 return;
515 }
516
517 // Ensure frame dimensions are sane.
518 if (layer_tree->frame_size().IsEmpty() || device_pixel_ratio <= 0.0f) {
519 return;
520 }
521
522 animator_->Render(view_id, std::move(layer_tree), device_pixel_ratio);
523}
524
525void Engine::UpdateSemantics(int64_t view_id,
528 delegate_.OnEngineUpdateSemantics(view_id, std::move(update),
529 std::move(actions));
530}
531
532void Engine::SetApplicationLocale(std::string locale) {
533 delegate_.OnEngineSetApplicationLocale(std::move(locale));
534}
535
536void Engine::SetSemanticsTreeEnabled(bool enabled) {
537 delegate_.OnEngineSetSemanticsTreeEnabled(enabled);
538}
539
540void Engine::HandlePlatformMessage(std::unique_ptr<PlatformMessage> message) {
541 if (message->channel() == kAssetChannel) {
542 HandleAssetPlatformMessage(std::move(message));
543 } else {
544 delegate_.OnEngineHandlePlatformMessage(std::move(message));
545 }
546}
547
548void Engine::OnRootIsolateCreated() {
549 delegate_.OnRootIsolateCreated();
550}
551
552void Engine::UpdateIsolateDescription(const std::string isolate_name,
553 int64_t isolate_port) {
554 delegate_.UpdateIsolateDescription(isolate_name, isolate_port);
555}
556
557std::unique_ptr<std::vector<std::string>> Engine::ComputePlatformResolvedLocale(
558 const std::vector<std::string>& supported_locale_data) {
559 return delegate_.ComputePlatformResolvedLocale(supported_locale_data);
560}
561
562double Engine::GetScaledFontSize(double unscaled_font_size,
563 int configuration_id) const {
564 return delegate_.GetScaledFontSize(unscaled_font_size, configuration_id);
565}
566
567void Engine::RequestViewFocusChange(const ViewFocusChangeRequest& request) {
568 delegate_.RequestViewFocusChange(request);
569}
570
571void Engine::SetNeedsReportTimings(bool needs_reporting) {
572 delegate_.SetNeedsReportTimings(needs_reporting);
573}
574
576 return *font_collection_;
577}
578
579void Engine::DoDispatchPacket(std::unique_ptr<PointerDataPacket> packet,
580 uint64_t trace_flow_id) {
581 animator_->EnqueueTraceFlowId(trace_flow_id);
582 if (runtime_controller_) {
583 runtime_controller_->DispatchPointerDataPacket(*packet);
584 }
585}
586
588 const fml::closure& callback) {
589 animator_->ScheduleSecondaryVsyncCallback(id, callback);
590}
591
592void Engine::HandleAssetPlatformMessage(
593 std::unique_ptr<PlatformMessage> message) {
594 fml::RefPtr<PlatformMessageResponse> response = message->response();
595 if (!response) {
596 return;
597 }
598 const auto& data = message->data();
599 std::string asset_name(reinterpret_cast<const char*>(data.GetMapping()),
600 data.GetSize());
601
602 if (asset_manager_) {
603 std::unique_ptr<fml::Mapping> asset_mapping =
604 asset_manager_->GetAsMapping(asset_name);
605 if (asset_mapping) {
606 response->Complete(std::move(asset_mapping));
607 return;
608 }
609 }
610
611 response->CompleteEmpty();
612}
613
614const std::string& Engine::GetLastEntrypoint() const {
615 return last_entry_point_;
616}
617
618const std::string& Engine::GetLastEntrypointLibrary() const {
619 return last_entry_point_library_;
620}
621
622const std::vector<std::string>& Engine::GetLastEntrypointArgs() const {
623 return last_entry_point_args_;
624}
625
626std::optional<int64_t> Engine::GetLastEngineId() const {
627 return last_engine_id_;
628}
629
630// |RuntimeDelegate|
631void Engine::RequestDartDeferredLibrary(intptr_t loading_unit_id) {
632 return delegate_.RequestDartDeferredLibrary(loading_unit_id);
633}
634
635std::weak_ptr<PlatformMessageHandler> Engine::GetPlatformMessageHandler()
636 const {
637 return delegate_.GetPlatformMessageHandler();
638}
639
640void Engine::SendChannelUpdate(std::string name, bool listening) {
641 delegate_.OnEngineChannelUpdate(std::move(name), listening);
642}
643
645 intptr_t loading_unit_id,
646 std::unique_ptr<const fml::Mapping> snapshot_data,
647 std::unique_ptr<const fml::Mapping> snapshot_instructions) {
648 if (runtime_controller_->IsRootIsolateRunning()) {
649 runtime_controller_->LoadDartDeferredLibrary(
650 loading_unit_id, std::move(snapshot_data),
651 std::move(snapshot_instructions));
652 } else {
653 LoadDartDeferredLibraryError(loading_unit_id, "No running root isolate.",
654 true);
655 }
656}
657
658void Engine::LoadDartDeferredLibraryError(intptr_t loading_unit_id,
659 const std::string& error_message,
660 bool transient) {
661 if (runtime_controller_->IsRootIsolateRunning()) {
662 runtime_controller_->LoadDartDeferredLibraryError(loading_unit_id,
663 error_message, transient);
664 }
665}
666
667const std::weak_ptr<VsyncWaiter> Engine::GetVsyncWaiter() const {
668 return animator_->GetVsyncWaiter();
669}
670
671void Engine::SetDisplays(const std::vector<DisplayData>& displays) {
672 runtime_controller_->SetDisplays(displays);
674}
675
677 runtime_controller_->ShutdownPlatformIsolates();
678}
679
681 runtime_controller_->FlushMicrotaskQueue();
682}
683
684} // namespace flutter
Describes a running instance of the Dart VM. There may only be one running instance of the Dart VM in...
Definition dart_vm.h:61
While the engine operates entirely on the UI task runner, it needs the capabilities of the other comp...
Definition engine.h:136
virtual double GetScaledFontSize(double unscaled_font_size, int configuration_id) const =0
Synchronously invokes platform-specific APIs to apply the system text scaling on the given unscaled f...
virtual void UpdateIsolateDescription(const std::string isolate_name, int64_t isolate_port)=0
Notifies the shell of the name of the root isolate and its port when that isolate is launched,...
virtual std::unique_ptr< std::vector< std::string > > ComputePlatformResolvedLocale(const std::vector< std::string > &supported_locale_data)=0
Directly invokes platform-specific APIs to compute the locale the platform would have natively resolv...
virtual void OnEngineSetApplicationLocale(std::string locale)=0
Framework sets the application locale.
virtual void OnEngineSetSemanticsTreeEnabled(bool enabled)=0
When the Framework starts or stops generating semantics tree, this new information needs to be convey...
virtual void OnPreEngineRestart()=0
Notifies the delegate that the root isolate of the application is about to be discarded and a new iso...
virtual void OnEngineChannelUpdate(std::string name, bool listening)=0
Invoked when a listener is registered on a platform channel.
virtual void OnEngineHandlePlatformMessage(std::unique_ptr< PlatformMessage > message)=0
When the Flutter application has a message to send to the underlying platform, the message needs to b...
virtual const std::shared_ptr< PlatformMessageHandler > & GetPlatformMessageHandler() const =0
Returns the delegate object that handles PlatformMessage's from Flutter to the host platform (and its...
virtual void SetNeedsReportTimings(bool needs_reporting)=0
Notifies the shell that the application has an opinion about whether its frame timings need to be rep...
virtual void OnEngineUpdateSemantics(int64_t view_id, SemanticsNodeUpdates updates, CustomAccessibilityActionUpdates actions)=0
When the accessibility tree has been updated by the Flutter application, this new information needs t...
virtual void RequestViewFocusChange(const ViewFocusChangeRequest &request)=0
Notifies the client that the Flutter view focus state has changed and the platform view should be upd...
virtual void OnRootIsolateCreated()=0
Notifies the shell that the root isolate is created. Currently, this information is to add to the ser...
virtual void RequestDartDeferredLibrary(intptr_t loading_unit_id)=0
Invoked when the Dart VM requests that a deferred library be loaded. Notifies the engine that the def...
void SetAccessibilityFeatures(int32_t flags)
Notifies the engine that the embedder has expressed an opinion about where the flags to set on the ac...
Definition engine.cc:491
void FlushMicrotaskQueue()
Flushes the microtask queue of the root isolate.
Definition engine.cc:680
void SetupDefaultFontManager()
Setup default font manager according to specific platform.
Definition engine.cc:157
bool RemoveView(int64_t view_id)
Notify the Flutter application that a view is no longer available.
Definition engine.cc:338
fml::TaskRunnerAffineWeakPtr< ImageDecoder > GetImageDecoderWeakPtr()
Definition engine.cc:166
void NotifyIdle(fml::TimeDelta deadline)
Notifies the engine that the UI task runner is not expected to undertake a new frame workload till a ...
Definition engine.cc:304
void SetViewportMetrics(int64_t view_id, const ViewportMetrics &metrics)
Updates the viewport metrics for a view. The viewport metrics detail the size of the rendering viewpo...
Definition engine.cc:346
void ReportTimings(std::vector< int64_t > timings)
Dart code cannot fully measure the time it takes for a specific frame to be rendered....
Definition engine.cc:300
void DispatchSemanticsAction(int64_t view_id, int node_id, SemanticsAction action, fml::MallocMapping args)
Notifies the engine that the embedder encountered an accessibility related action on the specified no...
Definition engine.cc:479
void OnAllViewsRendered() override
Definition engine.cc:506
fml::TaskRunnerAffineWeakPtr< ImageGeneratorRegistry > GetImageGeneratorRegistry()
Get the ImageGeneratorRegistry associated with the current engine.
Definition engine.cc:171
void ShutdownPlatformIsolates()
Shuts down all registered platform isolates. Must be called from the platform thread.
Definition engine.cc:676
void ScheduleFrame()
Definition engine.h:882
void SetDisplays(const std::vector< DisplayData > &displays)
Updates the display metrics for the currently running Flutter application.
Definition engine.cc:671
const std::weak_ptr< VsyncWaiter > GetVsyncWaiter() const
Definition engine.cc:667
void BeginFrame(fml::TimePoint frame_time, uint64_t frame_number)
Notifies the engine that it is time to begin working on a new frame previously scheduled via a call t...
Definition engine.cc:296
tonic::DartErrorHandleType GetUIIsolateLastError()
Errors that are unhandled on the Dart message loop are kept for further inspection till the next unha...
Definition engine.cc:328
FontCollection & GetFontCollection() override
Definition engine.cc:575
std::shared_ptr< AssetManager > GetAssetManager() override
Definition engine.cc:162
RunStatus Run(RunConfiguration configuration)
Moves the root isolate to the DartIsolate::Phase::Running phase on a successful call to this method.
Definition engine.cc:217
std::string GetUIIsolateName()
Gets the debug name of the root isolate. By default, the debug name of the isolate is derived from it...
Definition engine.cc:316
~Engine() override
Destroys the engine engine. Called by the shell on the UI task runner. The running root isolate is te...
const std::string & GetLastEntrypointLibrary() const
Get the last Entrypoint Library that was used in the RunConfiguration when |EngineRun| was called.
Definition engine.cc:618
bool UpdateAssetManager(const std::shared_ptr< AssetManager > &asset_manager)
Updates the asset manager referenced by the root isolate of a Flutter application....
Definition engine.cc:175
Dart_Port GetUIIsolateMainPort()
Gets the main port of the root isolate. Since the isolate is created immediately in the constructor o...
Definition engine.cc:312
void DispatchPointerDataPacket(std::unique_ptr< PointerDataPacket > packet, uint64_t trace_flow_id)
Notifies the engine that the embedder has sent it a pointer data packet. A pointer data packet may co...
Definition engine.cc:469
void LoadDartDeferredLibraryError(intptr_t loading_unit_id, const std::string &error_message, bool transient)
Indicates to the dart VM that the request to load a deferred library with the specified loading unit ...
Definition engine.cc:658
void LoadDartDeferredLibrary(intptr_t loading_unit_id, std::unique_ptr< const fml::Mapping > snapshot_data, std::unique_ptr< const fml::Mapping > snapshot_instructions)
Loads the Dart shared library into the Dart VM. When the Dart library is loaded successfully,...
Definition engine.cc:644
void AddView(int64_t view_id, const ViewportMetrics &view_metrics, std::function< void(bool added)> callback)
Notify the Flutter application that a new view is available.
Definition engine.cc:332
void DoDispatchPacket(std::unique_ptr< PointerDataPacket > packet, uint64_t trace_flow_id) override
Definition engine.cc:579
bool UIIsolateHasLivePorts()
It is an unexpected challenge to determine when a Dart application is "done". The application cannot ...
Definition engine.cc:320
const std::string & GetLastEntrypoint() const
Get the last Entrypoint that was used in the RunConfiguration when |EngineRun| was called.
Definition engine.cc:614
std::optional< int64_t > GetLastEngineId() const
Get the last Engine Id that was used in the RunConfiguration when |EngineRun| was called.
Definition engine.cc:626
fml::TaskRunnerAffineWeakPtr< Engine > GetWeakPtr() const
Definition engine.cc:153
RunStatus
Indicates the result of the call to Engine::Run.
Definition engine.h:74
bool Restart(RunConfiguration configuration)
Tears down an existing root isolate, reuses the components of that isolate and attempts to launch a n...
Definition engine.cc:205
bool UIIsolateHasPendingMicrotasks()
Another signal of liveness is the presence of microtasks that have been queued by the application but...
Definition engine.cc:324
const std::vector< std::string > & GetLastEntrypointArgs() const
Get the last Entrypoint Arguments that was used in the RunConfiguration when |EngineRun| was called....
Definition engine.cc:622
std::unique_ptr< Engine > Spawn(Delegate &delegate, const PointerDataDispatcherMaker &dispatcher_maker, const Settings &settings, std::unique_ptr< Animator > animator, const std::string &initial_route, const fml::WeakPtr< IOManager > &io_manager, fml::TaskRunnerAffineWeakPtr< SnapshotDelegate > snapshot_delegate, const std::shared_ptr< fml::SyncSwitch > &gpu_disabled_switch) const
Create a Engine that shares as many resources as possible with the calling Engine such that together ...
Definition engine.cc:113
void SetSemanticsEnabled(bool enabled)
Notifies the engine that the embedder has expressed an opinion about whether the accessibility tree s...
Definition engine.cc:487
void DispatchPlatformMessage(std::unique_ptr< PlatformMessage > message)
Notifies the engine that the embedder has sent it a message. This call originates in the platform vie...
Definition engine.cc:352
Engine(Delegate &delegate, const PointerDataDispatcherMaker &dispatcher_maker, const std::shared_ptr< fml::ConcurrentTaskRunner > &image_decoder_task_runner, const TaskRunners &task_runners, const Settings &settings, std::unique_ptr< Animator > animator, const fml::WeakPtr< IOManager > &io_manager, const std::shared_ptr< FontCollection > &font_collection, std::unique_ptr< RuntimeController > runtime_controller, const std::shared_ptr< fml::SyncSwitch > &gpu_disabled_switch)
Creates an instance of the engine with a supplied RuntimeController. Use the other constructor except...
Definition engine.cc:36
std::optional< uint32_t > GetUIIsolateReturnCode()
As described in the discussion for UIIsolateHasLivePorts, the "done-ness" of a Dart application is tr...
Definition engine.cc:308
void ScheduleSecondaryVsyncCallback(uintptr_t id, const fml::closure &callback) override
Schedule a secondary callback to be executed right after the main VsyncWaiter::AsyncWaitForVsync call...
Definition engine.cc:587
bool SendViewFocusEvent(const ViewFocusEvent &event)
Notify the Flutter application that the focus state of a native view has changed.
Definition engine.cc:342
fml::TaskRunnerAffineWeakPtr< ImageGeneratorRegistry > GetWeakPtr() const
Specifies all the configuration required by the runtime library to launch the root isolate....
std::unique_ptr< IsolateConfiguration > TakeIsolateConfiguration()
The engine uses this to take the isolate configuration from the run configuration....
std::shared_ptr< AssetManager > GetAssetManager() const
const std::string & GetEntrypoint() const
const std::vector< std::string > & GetEntrypointArgs() const
std::optional< int64_t > GetEngineId() const
bool IsValid() const
A valid run configuration only guarantees that the engine should be able to find the assets and the i...
const std::string & GetEntrypointLibrary() const
fml::RefPtr< fml::TaskRunner > GetUITaskRunner() const
fml::RefPtr< fml::TaskRunner > GetPlatformTaskRunner() const
A Mapping like NonOwnedMapping, but uses Free as its release proc.
Definition mapping.h:144
static MallocMapping Copy(const T *begin, const T *end)
Definition mapping.h:162
static MessageLoopTaskQueues * GetInstance()
bool Merge(TaskQueueId owner, TaskQueueId subsumed)
virtual void PostTask(const fml::closure &task) override
virtual TaskQueueId GetTaskQueueId()
Settings settings_
std::unique_ptr< RuntimeController > runtime_controller_
TaskRunners task_runners_
std::unique_ptr< Animator > animator_
MockDelegate delegate_
FlutterEngine engine
Definition main.cc:84
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
const gchar * channel
G_BEGIN_DECLS GBytes * message
G_BEGIN_DECLS FlutterViewId view_id
FlutterDesktopBinaryReply callback
#define FML_DLOG(severity)
Definition logging.h:121
#define FML_LOG(severity)
Definition logging.h:101
static constexpr char kSettingsChannel[]
Definition engine.cc:27
std::unordered_map< int32_t, SemanticsNode > SemanticsNodeUpdates
static constexpr char kLocalizationChannel[]
Definition engine.cc:26
std::unordered_map< int32_t, CustomAccessibilityAction > CustomAccessibilityActionUpdates
std::function< std::unique_ptr< PointerDataDispatcher >(PointerDataDispatcher::Delegate &)> PointerDataDispatcherMaker
Signature for constructing PointerDataDispatcher.
DEF_SWITCHES_START aot vmservice shared library name
Definition switch_defs.h:27
static constexpr char kAssetChannel[]
Definition engine.cc:23
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot data
Definition switch_defs.h:36
static constexpr char kIsolateChannel[]
Definition engine.cc:28
static constexpr char kNavigationChannel[]
Definition engine.cc:25
static constexpr char kLifecycleChannel[]
Definition engine.cc:24
std::function< void()> closure
Definition closure.h:14
Definition ref_ptr.h:261
DartErrorHandleType
Definition dart_error.h:67
std::vector< FlutterEngineDisplay > * displays
std::string advisory_script_entrypoint
Definition settings.h:176
bool prefetched_default_font_manager
Definition settings.h:215
std::string advisory_script_uri
Definition settings.h:173
MergedPlatformUIThread merged_platform_ui_thread
Definition settings.h:379
uint32_t font_initialization_data
Definition settings.h:262
std::shared_ptr< const fml::Mapping > persistent_isolate_data
Definition settings.h:345
fml::closure isolate_shutdown_callback
Definition settings.h:292
fml::closure isolate_create_callback
Definition settings.h:288
std::function< void(int64_t)> idle_notification_callback
Definition settings.h:306
The subset of state which is owned by the shell or engine and passed through the RuntimeController in...
#define TRACE_FLOW_STEP(category, name, id)
#define TRACE_EVENT0(category_group, name)
#define TRACE_EVENT0_WITH_FLOW_IDS(category_group, name, flow_id_count, flow_ids)