Flutter Engine
The 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
5#include "flutter/shell/common/engine.h"
6
7#include <cstring>
8#include <memory>
9#include <string>
10#include <utility>
11#include <vector>
12
13#include "flutter/common/settings.h"
14#include "flutter/fml/make_copyable.h"
15#include "flutter/fml/trace_event.h"
16#include "flutter/lib/snapshot/snapshot.h"
17#include "flutter/lib/ui/text/font_collection.h"
18#include "flutter/shell/common/animator.h"
19#include "flutter/shell/common/platform_view.h"
20#include "flutter/shell/common/shell.h"
22#include "rapidjson/document.h"
23#include "third_party/dart/runtime/include/dart_tools_api.h"
24
25namespace flutter {
26
27static constexpr char kAssetChannel[] = "flutter/assets";
28static constexpr char kLifecycleChannel[] = "flutter/lifecycle";
29static constexpr char kNavigationChannel[] = "flutter/navigation";
30static constexpr char kLocalizationChannel[] = "flutter/localization";
31static constexpr char kSettingsChannel[] = "flutter/settings";
32static constexpr char kIsolateChannel[] = "flutter/isolate";
33
34namespace {
35fml::MallocMapping MakeMapping(const std::string& str) {
36 return fml::MallocMapping::Copy(str.c_str(), str.length());
37}
38} // namespace
39
41 Delegate& delegate,
42 const PointerDataDispatcherMaker& dispatcher_maker,
43 const std::shared_ptr<fml::ConcurrentTaskRunner>& image_decoder_task_runner,
44 const TaskRunners& task_runners,
45 const Settings& settings,
46 std::unique_ptr<Animator> animator,
47 const fml::WeakPtr<IOManager>& io_manager,
48 const std::shared_ptr<FontCollection>& font_collection,
49 std::unique_ptr<RuntimeController> runtime_controller,
50 const std::shared_ptr<fml::SyncSwitch>& gpu_disabled_switch)
51 : delegate_(delegate),
52 settings_(settings),
53 animator_(std::move(animator)),
54 runtime_controller_(std::move(runtime_controller)),
55 font_collection_(font_collection),
56 image_decoder_(ImageDecoder::Make(settings_,
57 task_runners,
58 image_decoder_task_runner,
59 io_manager,
60 gpu_disabled_switch)),
61 task_runners_(task_runners),
62 weak_factory_(this) {
63 pointer_data_dispatcher_ = dispatcher_maker(*this);
64}
65
67 const PointerDataDispatcherMaker& dispatcher_maker,
68 DartVM& vm,
69 fml::RefPtr<const DartSnapshot> isolate_snapshot,
70 const TaskRunners& task_runners,
71 const PlatformData& platform_data,
72 const Settings& settings,
73 std::unique_ptr<Animator> animator,
74 fml::WeakPtr<IOManager> io_manager,
75 const fml::RefPtr<SkiaUnrefQueue>& unref_queue,
77 std::shared_ptr<VolatilePathTracker> volatile_path_tracker,
78 const std::shared_ptr<fml::SyncSwitch>& gpu_disabled_switch,
79 impeller::RuntimeStageBackend runtime_stage_type)
80 : Engine(delegate,
81 dispatcher_maker,
82 vm.GetConcurrentWorkerTaskRunner(),
83 task_runners,
84 settings,
85 std::move(animator),
86 io_manager,
87 std::make_shared<FontCollection>(),
88 nullptr,
89 gpu_disabled_switch) {
90 runtime_controller_ = std::make_unique<RuntimeController>(
91 *this, // runtime delegate
92 &vm, // VM
93 std::move(isolate_snapshot), // isolate snapshot
94 settings_.idle_notification_callback, // idle notification callback
95 platform_data, // platform data
96 settings_.isolate_create_callback, // isolate create callback
97 settings_.isolate_shutdown_callback, // isolate shutdown callback
98 settings_.persistent_isolate_data, // persistent isolate data
100 task_runners_, // task runners
101 std::move(snapshot_delegate), // snapshot delegate
102 std::move(io_manager), // io manager
103 unref_queue, // Skia unref queue
104 image_decoder_->GetWeakPtr(), // image decoder
105 image_generator_registry_.GetWeakPtr(), // image generator registry
106 settings_.advisory_script_uri, // advisory script uri
107 settings_.advisory_script_entrypoint, // advisory script entrypoint
108 std::move(volatile_path_tracker), // volatile path tracker
109 vm.GetConcurrentWorkerTaskRunner(), // concurrent task runner
110 settings_.enable_impeller, // enable impeller
111 runtime_stage_type, // runtime stage type
112 });
113}
114
115std::unique_ptr<Engine> Engine::Spawn(
116 Delegate& delegate,
117 const PointerDataDispatcherMaker& dispatcher_maker,
118 const Settings& settings,
119 std::unique_ptr<Animator> animator,
120 const std::string& initial_route,
121 const fml::WeakPtr<IOManager>& io_manager,
123 const std::shared_ptr<fml::SyncSwitch>& gpu_disabled_switch) const {
124 auto result = std::make_unique<Engine>(
125 /*delegate=*/delegate,
126 /*dispatcher_maker=*/dispatcher_maker,
127 /*image_decoder_task_runner=*/
128 runtime_controller_->GetDartVM()->GetConcurrentWorkerTaskRunner(),
129 /*task_runners=*/task_runners_,
130 /*settings=*/settings,
131 /*animator=*/std::move(animator),
132 /*io_manager=*/io_manager,
133 /*font_collection=*/font_collection_,
134 /*runtime_controller=*/nullptr,
135 /*gpu_disabled_switch=*/gpu_disabled_switch);
136 result->runtime_controller_ = runtime_controller_->Spawn(
137 /*p_client=*/*result,
138 /*advisory_script_uri=*/settings.advisory_script_uri,
139 /*advisory_script_entrypoint=*/settings.advisory_script_entrypoint,
140 /*idle_notification_callback=*/settings.idle_notification_callback,
141 /*isolate_create_callback=*/settings.isolate_create_callback,
142 /*isolate_shutdown_callback=*/settings.isolate_shutdown_callback,
143 /*persistent_isolate_data=*/settings.persistent_isolate_data,
144 /*io_manager=*/io_manager,
145 /*image_decoder=*/result->GetImageDecoderWeakPtr(),
146 /*image_generator_registry=*/result->GetImageGeneratorRegistry(),
147 /*snapshot_delegate=*/std::move(snapshot_delegate));
148 result->initial_route_ = initial_route;
149 result->asset_manager_ = asset_manager_;
150 return result;
151}
152
153Engine::~Engine() = default;
154
156 return weak_factory_.GetWeakPtr();
157}
158
160 TRACE_EVENT0("flutter", "Engine::SetupDefaultFontManager");
161 font_collection_->SetupDefaultFontManager(settings_.font_initialization_data);
162}
163
164std::shared_ptr<AssetManager> Engine::GetAssetManager() {
165 return asset_manager_;
166}
167
169 return image_decoder_->GetWeakPtr();
170}
171
175
177 const std::shared_ptr<AssetManager>& new_asset_manager) {
178 if (asset_manager_ && new_asset_manager &&
179 *asset_manager_ == *new_asset_manager) {
180 return false;
181 }
182
183 asset_manager_ = new_asset_manager;
184
185 if (!asset_manager_) {
186 return false;
187 }
188
189 // Using libTXT as the text engine.
190 if (settings_.use_asset_fonts) {
191 font_collection_->RegisterFonts(asset_manager_);
192 }
193
194 if (settings_.use_test_fonts) {
195 font_collection_->RegisterTestFonts();
196 }
197
198 return true;
199}
200
202 TRACE_EVENT0("flutter", "Engine::Restart");
203 if (!configuration.IsValid()) {
204 FML_LOG(ERROR) << "Engine run configuration was invalid.";
205 return false;
206 }
207 delegate_.OnPreEngineRestart();
208 runtime_controller_ = runtime_controller_->Clone();
209 UpdateAssetManager(nullptr);
210 return Run(std::move(configuration)) == Engine::RunStatus::Success;
211}
212
214 if (!configuration.IsValid()) {
215 FML_LOG(ERROR) << "Engine run configuration was invalid.";
216 return RunStatus::Failure;
217 }
218
219 last_entry_point_ = configuration.GetEntrypoint();
220 last_entry_point_library_ = configuration.GetEntrypointLibrary();
221#if (FLUTTER_RUNTIME_MODE == FLUTTER_RUNTIME_MODE_DEBUG)
222 // This is only used to support restart.
223 last_entry_point_args_ = configuration.GetEntrypointArgs();
224#endif
225
226 UpdateAssetManager(configuration.GetAssetManager());
227
228 if (runtime_controller_->IsRootIsolateRunning()) {
230 }
231
232 // If the embedding prefetched the default font manager, then set up the
233 // font manager later in the engine launch process. This makes it less
234 // likely that the setup will need to wait for the prefetch to complete.
235 auto root_isolate_create_callback = [&]() {
236 if (settings_.prefetched_default_font_manager) {
238 }
239 };
240
241 if (!runtime_controller_->LaunchRootIsolate(
242 settings_, //
243 root_isolate_create_callback, //
244 configuration.GetEntrypoint(), //
245 configuration.GetEntrypointLibrary(), //
246 configuration.GetEntrypointArgs(), //
247 configuration.TakeIsolateConfiguration()) //
248 ) {
249 return RunStatus::Failure;
250 }
251
252 auto service_id = runtime_controller_->GetRootIsolateServiceID();
253 if (service_id.has_value()) {
254 std::unique_ptr<PlatformMessage> service_id_message =
255 std::make_unique<flutter::PlatformMessage>(
256 kIsolateChannel, MakeMapping(service_id.value()), nullptr);
257 HandlePlatformMessage(std::move(service_id_message));
258 }
259
261}
262
263void Engine::BeginFrame(fml::TimePoint frame_time, uint64_t frame_number) {
264 runtime_controller_->BeginFrame(frame_time, frame_number);
265}
266
267void Engine::ReportTimings(std::vector<int64_t> timings) {
268 runtime_controller_->ReportTimings(std::move(timings));
269}
270
272 runtime_controller_->NotifyIdle(deadline);
273}
274
276 TRACE_EVENT0("flutter", "Engine::NotifyDestroyed");
277 runtime_controller_->NotifyDestroyed();
278}
279
280std::optional<uint32_t> Engine::GetUIIsolateReturnCode() {
281 return runtime_controller_->GetRootIsolateReturnCode();
282}
283
285 return runtime_controller_->GetMainPort();
286}
287
289 return runtime_controller_->GetIsolateName();
290}
291
293 return runtime_controller_->HasLivePorts();
294}
295
297 return runtime_controller_->GetLastError();
298}
299
300void Engine::AddView(int64_t view_id,
301 const ViewportMetrics& view_metrics,
302 std::function<void(bool added)> callback) {
303 runtime_controller_->AddView(view_id, view_metrics, std::move(callback));
304}
305
306bool Engine::RemoveView(int64_t view_id) {
307 return runtime_controller_->RemoveView(view_id);
308}
309
310void Engine::SetViewportMetrics(int64_t view_id,
311 const ViewportMetrics& metrics) {
312 runtime_controller_->SetViewportMetrics(view_id, metrics);
314}
315
316void Engine::DispatchPlatformMessage(std::unique_ptr<PlatformMessage> message) {
317 std::string channel = message->channel();
318 if (channel == kLifecycleChannel) {
319 if (HandleLifecyclePlatformMessage(message.get())) {
320 return;
321 }
322 } else if (channel == kLocalizationChannel) {
323 if (HandleLocalizationPlatformMessage(message.get())) {
324 return;
325 }
326 } else if (channel == kSettingsChannel) {
327 HandleSettingsPlatformMessage(message.get());
328 return;
329 } else if (!runtime_controller_->IsRootIsolateRunning() &&
330 channel == kNavigationChannel) {
331 // If there's no runtime_, we may still need to set the initial route.
332 HandleNavigationPlatformMessage(std::move(message));
333 return;
334 }
335
336 if (runtime_controller_->IsRootIsolateRunning() &&
337 runtime_controller_->DispatchPlatformMessage(std::move(message))) {
338 return;
339 }
340
341 FML_DLOG(WARNING) << "Dropping platform message on channel: " << channel;
342}
343
344bool Engine::HandleLifecyclePlatformMessage(PlatformMessage* message) {
345 const auto& data = message->data();
346 std::string state(reinterpret_cast<const char*>(data.GetMapping()),
347 data.GetSize());
348
349 // Always schedule a frame when the app does become active as per API
350 // recommendation
351 // https://developer.apple.com/documentation/uikit/uiapplicationdelegate/1622956-applicationdidbecomeactive?language=objc
352 if (state == "AppLifecycleState.resumed" ||
353 state == "AppLifecycleState.inactive") {
355 }
356 runtime_controller_->SetInitialLifecycleState(state);
357 // Always forward these messages to the framework by returning false.
358 return false;
359}
360
361bool Engine::HandleNavigationPlatformMessage(
362 std::unique_ptr<PlatformMessage> message) {
363 const auto& data = message->data();
364
365 rapidjson::Document document;
366 document.Parse(reinterpret_cast<const char*>(data.GetMapping()),
367 data.GetSize());
368 if (document.HasParseError() || !document.IsObject()) {
369 return false;
370 }
371 auto root = document.GetObject();
372 auto method = root.FindMember("method");
373 if (method->value != "setInitialRoute") {
374 return false;
375 }
376 auto route = root.FindMember("args");
377 initial_route_ = route->value.GetString();
378 return true;
379}
380
381bool Engine::HandleLocalizationPlatformMessage(PlatformMessage* message) {
382 const auto& data = message->data();
383
384 rapidjson::Document document;
385 document.Parse(reinterpret_cast<const char*>(data.GetMapping()),
386 data.GetSize());
387 if (document.HasParseError() || !document.IsObject()) {
388 return false;
389 }
390 auto root = document.GetObject();
391 auto method = root.FindMember("method");
392 if (method == root.MemberEnd()) {
393 return false;
394 }
395 const size_t strings_per_locale = 4;
396 if (method->value == "setLocale") {
397 // Decode and pass the list of locale data onwards to dart.
398 auto args = root.FindMember("args");
399 if (args == root.MemberEnd() || !args->value.IsArray()) {
400 return false;
401 }
402
403 if (args->value.Size() % strings_per_locale != 0) {
404 return false;
405 }
406 std::vector<std::string> locale_data;
407 for (size_t locale_index = 0; locale_index < args->value.Size();
408 locale_index += strings_per_locale) {
409 if (!args->value[locale_index].IsString() ||
410 !args->value[locale_index + 1].IsString()) {
411 return false;
412 }
413 locale_data.push_back(args->value[locale_index].GetString());
414 locale_data.push_back(args->value[locale_index + 1].GetString());
415 locale_data.push_back(args->value[locale_index + 2].GetString());
416 locale_data.push_back(args->value[locale_index + 3].GetString());
417 }
418
419 return runtime_controller_->SetLocales(locale_data);
420 }
421 return false;
422}
423
424void Engine::HandleSettingsPlatformMessage(PlatformMessage* message) {
425 const auto& data = message->data();
426 std::string jsonData(reinterpret_cast<const char*>(data.GetMapping()),
427 data.GetSize());
428 if (runtime_controller_->SetUserSettingsData(jsonData)) {
430 }
431}
432
434 std::unique_ptr<PointerDataPacket> packet,
435 uint64_t trace_flow_id) {
436 TRACE_EVENT0_WITH_FLOW_IDS("flutter", "Engine::DispatchPointerDataPacket",
437 /*flow_id_count=*/1,
438 /*flow_ids=*/&trace_flow_id);
439 TRACE_FLOW_STEP("flutter", "PointerEvent", trace_flow_id);
440 pointer_data_dispatcher_->DispatchPacket(std::move(packet), trace_flow_id);
441}
442
446 runtime_controller_->DispatchSemanticsAction(node_id, action,
447 std::move(args));
448}
449
450void Engine::SetSemanticsEnabled(bool enabled) {
451 runtime_controller_->SetSemanticsEnabled(enabled);
452}
453
455 runtime_controller_->SetAccessibilityFeatures(flags);
456}
457
459 if (!initial_route_.empty()) {
460 return initial_route_;
461 }
462 return "/";
463}
464
465void Engine::ScheduleFrame(bool regenerate_layer_trees) {
466 animator_->RequestFrame(regenerate_layer_trees);
467}
468
470 animator_->OnAllViewsRendered();
471}
472
473void Engine::Render(int64_t view_id,
474 std::unique_ptr<flutter::LayerTree> layer_tree,
475 float device_pixel_ratio) {
476 if (!layer_tree) {
477 return;
478 }
479
480 // Ensure frame dimensions are sane.
481 if (layer_tree->frame_size().isEmpty() || device_pixel_ratio <= 0.0f) {
482 return;
483 }
484
485 animator_->Render(view_id, std::move(layer_tree), device_pixel_ratio);
486}
487
490 delegate_.OnEngineUpdateSemantics(std::move(update), std::move(actions));
491}
492
493void Engine::HandlePlatformMessage(std::unique_ptr<PlatformMessage> message) {
494 if (message->channel() == kAssetChannel) {
495 HandleAssetPlatformMessage(std::move(message));
496 } else {
497 delegate_.OnEngineHandlePlatformMessage(std::move(message));
498 }
499}
500
504
505void Engine::UpdateIsolateDescription(const std::string isolate_name,
506 int64_t isolate_port) {
507 delegate_.UpdateIsolateDescription(isolate_name, isolate_port);
508}
509
510std::unique_ptr<std::vector<std::string>> Engine::ComputePlatformResolvedLocale(
511 const std::vector<std::string>& supported_locale_data) {
512 return delegate_.ComputePlatformResolvedLocale(supported_locale_data);
513}
514
515double Engine::GetScaledFontSize(double unscaled_font_size,
516 int configuration_id) const {
517 return delegate_.GetScaledFontSize(unscaled_font_size, configuration_id);
518}
519
520void Engine::SetNeedsReportTimings(bool needs_reporting) {
521 delegate_.SetNeedsReportTimings(needs_reporting);
522}
523
525 return *font_collection_;
526}
527
528void Engine::DoDispatchPacket(std::unique_ptr<PointerDataPacket> packet,
529 uint64_t trace_flow_id) {
530 animator_->EnqueueTraceFlowId(trace_flow_id);
531 if (runtime_controller_) {
532 runtime_controller_->DispatchPointerDataPacket(*packet);
533 }
534}
535
537 const fml::closure& callback) {
538 animator_->ScheduleSecondaryVsyncCallback(id, callback);
539}
540
541void Engine::HandleAssetPlatformMessage(
542 std::unique_ptr<PlatformMessage> message) {
543 fml::RefPtr<PlatformMessageResponse> response = message->response();
544 if (!response) {
545 return;
546 }
547 const auto& data = message->data();
548 std::string asset_name(reinterpret_cast<const char*>(data.GetMapping()),
549 data.GetSize());
550
551 if (asset_manager_) {
552 std::unique_ptr<fml::Mapping> asset_mapping =
553 asset_manager_->GetAsMapping(asset_name);
554 if (asset_mapping) {
555 response->Complete(std::move(asset_mapping));
556 return;
557 }
558 }
559
560 response->CompleteEmpty();
561}
562
563const std::string& Engine::GetLastEntrypoint() const {
564 return last_entry_point_;
565}
566
567const std::string& Engine::GetLastEntrypointLibrary() const {
568 return last_entry_point_library_;
569}
570
571const std::vector<std::string>& Engine::GetLastEntrypointArgs() const {
572 return last_entry_point_args_;
573}
574
575// |RuntimeDelegate|
576void Engine::RequestDartDeferredLibrary(intptr_t loading_unit_id) {
577 return delegate_.RequestDartDeferredLibrary(loading_unit_id);
578}
579
580std::weak_ptr<PlatformMessageHandler> Engine::GetPlatformMessageHandler()
581 const {
582 return delegate_.GetPlatformMessageHandler();
583}
584
585void Engine::SendChannelUpdate(std::string name, bool listening) {
586 delegate_.OnEngineChannelUpdate(std::move(name), listening);
587}
588
590 intptr_t loading_unit_id,
591 std::unique_ptr<const fml::Mapping> snapshot_data,
592 std::unique_ptr<const fml::Mapping> snapshot_instructions) {
593 if (runtime_controller_->IsRootIsolateRunning()) {
594 runtime_controller_->LoadDartDeferredLibrary(
595 loading_unit_id, std::move(snapshot_data),
596 std::move(snapshot_instructions));
597 } else {
598 LoadDartDeferredLibraryError(loading_unit_id, "No running root isolate.",
599 true);
600 }
601}
602
603void Engine::LoadDartDeferredLibraryError(intptr_t loading_unit_id,
604 const std::string& error_message,
605 bool transient) {
606 if (runtime_controller_->IsRootIsolateRunning()) {
607 runtime_controller_->LoadDartDeferredLibraryError(loading_unit_id,
608 error_message, transient);
609 }
610}
611
612const std::weak_ptr<VsyncWaiter> Engine::GetVsyncWaiter() const {
613 return animator_->GetVsyncWaiter();
614}
615
616void Engine::SetDisplays(const std::vector<DisplayData>& displays) {
617 runtime_controller_->SetDisplays(displays);
619}
620
622 runtime_controller_->ShutdownPlatformIsolates();
623}
624
625} // namespace flutter
static std::unique_ptr< SkEncoder > Make(SkWStream *dst, const SkPixmap *src, const SkYUVAPixmaps *srcYUVA, const SkColorSpace *srcYUVAColorSpace, const SkJpegEncoder::Options &options)
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:140
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 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(SemanticsNodeUpdates updates, CustomAccessibilityActionUpdates actions)=0
When the accessibility tree has been updated by the Flutter application, this new information needs t...
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:454
void SetupDefaultFontManager()
Setup default font manager according to specific platform.
Definition engine.cc:159
fml::WeakPtr< Engine > GetWeakPtr() const
Definition engine.cc:155
bool RemoveView(int64_t view_id)
Notify the Flutter application that a view is no longer available.
Definition engine.cc:306
std::string DefaultRouteName() override
Definition engine.cc:458
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:271
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:310
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:267
void OnAllViewsRendered() override
Definition engine.cc:469
void HandlePlatformMessage(std::unique_ptr< PlatformMessage > message) override
Definition engine.cc:493
void RequestDartDeferredLibrary(intptr_t loading_unit_id) override
Definition engine.cc:576
void DispatchSemanticsAction(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:443
void ShutdownPlatformIsolates()
Shuts down all registered platform isolates. Must be called from the platform thread.
Definition engine.cc:621
void ScheduleFrame()
Definition engine.h:845
void SetDisplays(const std::vector< DisplayData > &displays)
Updates the display metrics for the currently running Flutter application.
Definition engine.cc:616
const std::weak_ptr< VsyncWaiter > GetVsyncWaiter() const
Definition engine.cc:612
void SendChannelUpdate(std::string name, bool listening) override
Definition engine.cc:585
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:263
tonic::DartErrorHandleType GetUIIsolateLastError()
Errors that are unhandled on the Dart message loop are kept for further inspection till the next unha...
Definition engine.cc:296
FontCollection & GetFontCollection() override
Definition engine.cc:524
std::shared_ptr< AssetManager > GetAssetManager() override
Definition engine.cc:164
RunStatus Run(RunConfiguration configuration)
Moves the root isolate to the DartIsolate::Phase::Running phase on a successful call to this method.
Definition engine.cc:213
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:288
void OnRootIsolateCreated() override
Definition engine.cc:501
~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:567
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:176
Dart_Port GetUIIsolateMainPort()
Gets the main port of the root isolate. Since the isolate is created immediately in the constructor o...
Definition engine.cc:284
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:433
double GetScaledFontSize(double unscaled_font_size, int configuration_id) const override
Definition engine.cc:515
std::weak_ptr< PlatformMessageHandler > GetPlatformMessageHandler() const override
Definition engine.cc:580
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:603
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:589
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:300
void DoDispatchPacket(std::unique_ptr< PointerDataPacket > packet, uint64_t trace_flow_id) override
Definition engine.cc:528
bool UIIsolateHasLivePorts()
It is an unexpected challenge to determine when a Dart application is "done". The application cannot ...
Definition engine.cc:292
const std::string & GetLastEntrypoint() const
Get the last Entrypoint that was used in the RunConfiguration when |EngineRun| was called.
Definition engine.cc:563
void Render(int64_t view_id, std::unique_ptr< flutter::LayerTree > layer_tree, float device_pixel_ratio) override
Definition engine.cc:473
RunStatus
Indicates the result of the call to Engine::Run.
Definition engine.h:78
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:201
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:571
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:115
std::unique_ptr< std::vector< std::string > > ComputePlatformResolvedLocale(const std::vector< std::string > &supported_locale_data) override
Definition engine.cc:510
void SetSemanticsEnabled(bool enabled)
Notifies the engine that the embedder has expressed an opinion about whether the accessibility tree s...
Definition engine.cc:450
void UpdateIsolateDescription(const std::string isolate_name, int64_t isolate_port) override
Definition engine.cc:505
void SetNeedsReportTimings(bool value) override
Definition engine.cc:520
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:316
fml::WeakPtr< ImageGeneratorRegistry > GetImageGeneratorRegistry()
Get the ImageGeneratorRegistry associated with the current engine.
Definition engine.cc:172
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:40
std::optional< uint32_t > GetUIIsolateReturnCode()
As described in the discussion for UIIsolateHasLivePorts, the "done-ness" of a Dart application is tr...
Definition engine.cc:280
fml::WeakPtr< ImageDecoder > GetImageDecoderWeakPtr()
Definition engine.cc:168
void UpdateSemantics(SemanticsNodeUpdates update, CustomAccessibilityActionUpdates actions) override
Definition engine.cc:488
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:536
void NotifyDestroyed()
Notifies the engine that the attached flutter view has been destroyed. This enables the engine to not...
Definition engine.cc:275
fml::WeakPtr< 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
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
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
int64_t Dart_Port
Definition dart_api.h:1524
Settings settings_
std::unique_ptr< RuntimeController > runtime_controller_
TaskRunners task_runners_
std::unique_ptr< Animator > animator_
MockDelegate delegate_
AtkStateType state
FlutterSemanticsFlag flags
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
FlKeyEvent uint64_t FlKeyResponderAsyncCallback callback
GAsyncResult * result
#define FML_DLOG(severity)
Definition logging.h:102
#define FML_LOG(severity)
Definition logging.h:82
Win32Message message
static constexpr char kSettingsChannel[]
Definition engine.cc:31
std::unordered_map< int32_t, SemanticsNode > SemanticsNodeUpdates
static constexpr char kLocalizationChannel[]
Definition engine.cc:30
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 switches.h:32
static constexpr char kAssetChannel[]
Definition engine.cc:27
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 switches.h:41
static constexpr char kIsolateChannel[]
Definition engine.cc:32
static constexpr char kNavigationChannel[]
Definition engine.cc:29
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir Path to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data vm service The hostname IP address on which the Dart VM Service should be served If not defaults to or::depending on whether ipv6 is specified vm service A custom Dart VM Service port The default is to pick a randomly available open port disable vm Disable the Dart VM Service The Dart VM Service is never available in release mode disable vm service Disable mDNS Dart VM Service publication Bind to the IPv6 localhost address for the Dart VM Service Ignored if vm service host is set endless trace Enable an endless trace buffer The default is a ring buffer This is useful when very old events need to viewed For during application launch Memory usage will continue to grow indefinitely however route
Definition switches.h:137
static constexpr char kLifecycleChannel[]
Definition engine.cc:28
std::function< void()> closure
Definition closure.h:14
Definition ref_ptr.h:256
DartErrorHandleType
Definition dart_error.h:67
bool prefetched_default_font_manager
Definition settings.h:219
uint32_t font_initialization_data
Definition settings.h:254
std::shared_ptr< const fml::Mapping > persistent_isolate_data
Definition settings.h:339
fml::closure isolate_shutdown_callback
Definition settings.h:286
fml::closure isolate_create_callback
Definition settings.h:282
std::function< void(int64_t)> idle_notification_callback
Definition settings.h:300
The subset of state which is owned by the shell or engine and passed through the RuntimeController in...
#define ERROR(message)
#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)