Flutter Engine
 
Loading...
Searching...
No Matches
runtime_controller.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 <utility>
8
19
20namespace flutter {
21
23 const TaskRunners& task_runners)
24 : client_(p_client),
25 vm_(nullptr),
26 context_(task_runners),
27 pointer_data_packet_converter_(*this) {}
28
30 RuntimeDelegate& p_client,
31 DartVM* p_vm,
32 fml::RefPtr<const DartSnapshot> p_isolate_snapshot,
33 const std::function<void(int64_t)>& p_idle_notification_callback,
34 const PlatformData& p_platform_data,
35 const fml::closure& p_isolate_create_callback,
36 const fml::closure& p_isolate_shutdown_callback,
37 std::shared_ptr<const fml::Mapping> p_persistent_isolate_data,
38 const UIDartState::Context& p_context)
39 : client_(p_client),
40 vm_(p_vm),
41 isolate_snapshot_(std::move(p_isolate_snapshot)),
42 idle_notification_callback_(p_idle_notification_callback),
43 platform_data_(p_platform_data),
44 isolate_create_callback_(p_isolate_create_callback),
45 isolate_shutdown_callback_(p_isolate_shutdown_callback),
46 persistent_isolate_data_(std::move(p_persistent_isolate_data)),
47 context_(p_context),
48 pointer_data_packet_converter_(*this) {}
49
50std::unique_ptr<RuntimeController> RuntimeController::Spawn(
51 RuntimeDelegate& p_client,
52 const std::string& advisory_script_uri,
53 const std::string& advisory_script_entrypoint,
54 const std::function<void(int64_t)>& p_idle_notification_callback,
55 const fml::closure& p_isolate_create_callback,
56 const fml::closure& p_isolate_shutdown_callback,
57 const std::shared_ptr<const fml::Mapping>& p_persistent_isolate_data,
58 fml::WeakPtr<IOManager> io_manager,
61 image_generator_registry,
62 fml::TaskRunnerAffineWeakPtr<SnapshotDelegate> snapshot_delegate) const {
63 UIDartState::Context spawned_context{
64 context_.task_runners,
65 std::move(snapshot_delegate),
66 std::move(io_manager),
67 context_.unref_queue,
68 std::move(image_decoder),
69 std::move(image_generator_registry),
70 advisory_script_uri,
71 advisory_script_entrypoint,
74 context_.runtime_stage_backend,
75 context_.enable_impeller,
76 context_.enable_flutter_gpu,
77 };
78 auto result =
79 std::make_unique<RuntimeController>(p_client, //
80 vm_, //
81 isolate_snapshot_, //
82 p_idle_notification_callback, //
83 platform_data_, //
84 p_isolate_create_callback, //
85 p_isolate_shutdown_callback, //
86 p_persistent_isolate_data, //
87 spawned_context); //
88 result->spawning_isolate_ = root_isolate_;
89 return result;
90}
91
93 FML_DCHECK(Dart_CurrentIsolate() == nullptr);
94 std::shared_ptr<DartIsolate> root_isolate = root_isolate_.lock();
95 if (root_isolate) {
96 root_isolate->SetReturnCodeCallback(nullptr);
97 auto result = root_isolate->Shutdown();
98 if (!result) {
99 FML_DLOG(ERROR) << "Could not shutdown the root isolate.";
100 }
101 root_isolate_ = {};
102 }
103}
104
106 std::shared_ptr<DartIsolate> root_isolate = root_isolate_.lock();
107 if (root_isolate) {
108 return root_isolate->GetPhase() == DartIsolate::Phase::Running;
109 }
110 return false;
111}
112
113std::unique_ptr<RuntimeController> RuntimeController::Clone() const {
114 return std::make_unique<RuntimeController>(client_, //
115 vm_, //
116 isolate_snapshot_, //
117 idle_notification_callback_, //
118 platform_data_, //
119 isolate_create_callback_, //
120 isolate_shutdown_callback_, //
121 persistent_isolate_data_, //
122 context_ //
123 );
124}
125
126bool RuntimeController::FlushRuntimeStateToIsolate() {
127 FML_DCHECK(!has_flushed_runtime_state_)
128 << "FlushRuntimeStateToIsolate is called more than once somehow.";
129 has_flushed_runtime_state_ = true;
130
131 auto platform_configuration = GetPlatformConfigurationIfAvailable();
132 if (!platform_configuration) {
133 return false;
134 }
135
136 for (auto const& [view_id, viewport_metrics] :
137 platform_data_.viewport_metrics_for_views) {
138 bool added = platform_configuration->AddView(view_id, viewport_metrics);
139
140 // Callbacks will have been already invoked if the engine was restarted.
141 if (pending_add_view_callbacks_.find(view_id) !=
142 pending_add_view_callbacks_.end()) {
143 pending_add_view_callbacks_[view_id](added);
144 pending_add_view_callbacks_.erase(view_id);
145 }
146
147 if (!added) {
148 FML_LOG(ERROR) << "Failed to flush view #" << view_id
149 << ". The Dart isolate may be in an inconsistent state.";
150 }
151 }
152
153 FML_DCHECK(pending_add_view_callbacks_.empty());
154 return SetLocales(platform_data_.locale_data) &&
155 SetSemanticsEnabled(platform_data_.semantics_enabled) &&
157 platform_data_.accessibility_feature_flags_) &&
158 SetUserSettingsData(platform_data_.user_settings_data) &&
160 SetDisplays(platform_data_.displays);
161}
162
164 const ViewportMetrics& view_metrics,
166 // If the Dart isolate is not running, |FlushRuntimeStateToIsolate| will
167 // add the view and invoke the callback when the isolate is started.
168 auto* platform_configuration = GetPlatformConfigurationIfAvailable();
169 if (!platform_configuration) {
170 FML_DCHECK(has_flushed_runtime_state_ == false);
171
172 if (pending_add_view_callbacks_.find(view_id) !=
173 pending_add_view_callbacks_.end()) {
174 FML_LOG(ERROR) << "View #" << view_id << " is already pending creation.";
175 callback(false);
176 return;
177 }
178
179 platform_data_.viewport_metrics_for_views[view_id] = view_metrics;
180 pending_add_view_callbacks_[view_id] = std::move(callback);
181 return;
182 }
183
184 FML_DCHECK(has_flushed_runtime_state_ || pending_add_view_callbacks_.empty());
185
186 platform_data_.viewport_metrics_for_views[view_id] = view_metrics;
187 bool added = platform_configuration->AddView(view_id, view_metrics);
188 if (added) {
189 ScheduleFrame();
190 }
191
192 callback(added);
193}
194
196 platform_data_.viewport_metrics_for_views.erase(view_id);
197
198 // If the Dart isolate has not been launched yet, the pending
199 // add view operation's callback is stored by the runtime controller.
200 // Notify this callback of the cancellation.
201 auto* platform_configuration = GetPlatformConfigurationIfAvailable();
202 if (!platform_configuration) {
203 FML_DCHECK(has_flushed_runtime_state_ == false);
204 if (pending_add_view_callbacks_.find(view_id) !=
205 pending_add_view_callbacks_.end()) {
206 pending_add_view_callbacks_[view_id](false);
207 pending_add_view_callbacks_.erase(view_id);
208 }
209
210 return false;
211 }
212
213 return platform_configuration->RemoveView(view_id);
214}
215
217 auto* platform_configuration = GetPlatformConfigurationIfAvailable();
218 if (!platform_configuration) {
219 return false;
220 }
221 return platform_configuration->SendFocusEvent(event);
222}
223
224bool RuntimeController::ViewExists(int64_t view_id) const {
225 return platform_data_.viewport_metrics_for_views.count(view_id) != 0;
226}
227
229 const ViewportMetrics& metrics) {
230 TRACE_EVENT0("flutter", "SetViewportMetrics");
231
232 platform_data_.viewport_metrics_for_views[view_id] = metrics;
233 if (auto* platform_configuration = GetPlatformConfigurationIfAvailable()) {
234 return platform_configuration->UpdateViewMetrics(view_id, metrics);
235 }
236
237 return false;
238}
239
241 const std::vector<std::string>& locale_data) {
242 platform_data_.locale_data = locale_data;
243
244 if (auto* platform_configuration = GetPlatformConfigurationIfAvailable()) {
245 platform_configuration->UpdateLocales(locale_data);
246 return true;
247 }
248
249 return false;
250}
251
253 platform_data_.user_settings_data = data;
254
255 if (auto* platform_configuration = GetPlatformConfigurationIfAvailable()) {
256 platform_configuration->UpdateUserSettingsData(
257 platform_data_.user_settings_data);
258 return true;
259 }
260
261 return false;
262}
263
265 platform_data_.lifecycle_state = data;
266
267 if (auto* platform_configuration = GetPlatformConfigurationIfAvailable()) {
268 platform_configuration->UpdateInitialLifecycleState(
269 platform_data_.lifecycle_state);
270 return true;
271 }
272
273 return false;
274}
275
277 platform_data_.semantics_enabled = enabled;
278
279 if (auto* platform_configuration = GetPlatformConfigurationIfAvailable()) {
280 platform_configuration->UpdateSemanticsEnabled(
281 platform_data_.semantics_enabled);
282 return true;
283 }
284
285 return false;
286}
287
289 platform_data_.accessibility_feature_flags_ = flags;
290 if (auto* platform_configuration = GetPlatformConfigurationIfAvailable()) {
291 platform_configuration->UpdateAccessibilityFeatures(
292 platform_data_.accessibility_feature_flags_);
293 return true;
294 }
295
296 return false;
297}
298
300 uint64_t frame_number) {
301 MarkAsFrameBorder();
302 if (auto* platform_configuration = GetPlatformConfigurationIfAvailable()) {
303 platform_configuration->BeginFrame(frame_time, frame_number);
304 return true;
305 }
306
307 return false;
308}
309
310bool RuntimeController::ReportTimings(std::vector<int64_t> timings) {
311 if (auto* platform_configuration = GetPlatformConfigurationIfAvailable()) {
312 platform_configuration->ReportTimings(std::move(timings));
313 return true;
314 }
315
316 return false;
317}
318
320 if (deadline - fml::TimeDelta::FromMicroseconds(Dart_TimelineGetMicros()) <
322 // There's less than 1ms left before the deadline. Upstream callers do not
323 // check to see if the deadline is in the past, and work after this point
324 // will be in vain.
325 return false;
326 }
327
328 std::shared_ptr<DartIsolate> root_isolate = root_isolate_.lock();
329 if (!root_isolate) {
330 return false;
331 }
332
333 tonic::DartState::Scope scope(root_isolate);
334
335 Dart_PerformanceMode performance_mode =
337 if (performance_mode == Dart_PerformanceMode::Dart_PerformanceMode_Latency) {
338 return false;
339 }
340
341 Dart_NotifyIdle(deadline.ToMicroseconds());
342
343 // Idle notifications being in isolate scope are part of the contract.
344 if (idle_notification_callback_) {
345 TRACE_EVENT0("flutter", "EmbedderIdleNotification");
346 idle_notification_callback_(deadline.ToMicroseconds());
347 }
348 return true;
349}
350
352 std::unique_ptr<PlatformMessage> message) {
353 if (auto* platform_configuration = GetPlatformConfigurationIfAvailable()) {
354 TRACE_EVENT0("flutter", "RuntimeController::DispatchPlatformMessage");
355 platform_configuration->DispatchPlatformMessage(std::move(message));
356 return true;
357 }
358
359 return false;
360}
361
363 const PointerDataPacket& packet) {
364 if (auto* platform_configuration = GetPlatformConfigurationIfAvailable()) {
365 TRACE_EVENT0("flutter", "RuntimeController::DispatchPointerDataPacket");
366 std::unique_ptr<PointerDataPacket> converted_packet =
367 pointer_data_packet_converter_.Convert(packet);
368 if (converted_packet->GetLength() != 0) {
369 platform_configuration->DispatchPointerDataPacket(*converted_packet);
370 }
371 return true;
372 }
373
374 return false;
375}
376
378 int32_t node_id,
381 TRACE_EVENT1("flutter", "RuntimeController::DispatchSemanticsAction", "mode",
382 "basic");
383 if (auto* platform_configuration = GetPlatformConfigurationIfAvailable()) {
384 platform_configuration->DispatchSemanticsAction(view_id, node_id, action,
385 std::move(args));
386 return true;
387 }
388
389 return false;
390}
391
393RuntimeController::GetPlatformConfigurationIfAvailable() {
394 std::shared_ptr<DartIsolate> root_isolate = root_isolate_.lock();
395 return root_isolate ? root_isolate->platform_configuration() : nullptr;
396}
397
398// |PlatformConfigurationClient|
399std::string RuntimeController::DefaultRouteName() {
400 return client_.DefaultRouteName();
401}
402
403// |PlatformConfigurationClient|
404void RuntimeController::ScheduleFrame() {
405 client_.ScheduleFrame();
406}
407
408void RuntimeController::EndWarmUpFrame() {
409 client_.OnAllViewsRendered();
410}
411
412// |PlatformConfigurationClient|
413void RuntimeController::Render(int64_t view_id,
414 Scene* scene,
415 double width,
416 double height) {
417 const ViewportMetrics* view_metrics =
419 if (view_metrics == nullptr) {
420 return;
421 }
422 client_.Render(view_id, scene->takeLayerTree(width, height),
423 view_metrics->device_pixel_ratio);
424 rendered_views_during_frame_.insert(view_id);
425 CheckIfAllViewsRendered();
426}
427
428void RuntimeController::MarkAsFrameBorder() {
429 rendered_views_during_frame_.clear();
430}
431
432void RuntimeController::CheckIfAllViewsRendered() {
433 if (rendered_views_during_frame_.size() != 0 &&
434 rendered_views_during_frame_.size() ==
435 platform_data_.viewport_metrics_for_views.size()) {
436 client_.OnAllViewsRendered();
437 MarkAsFrameBorder();
438 }
439}
440
441// |PlatformConfigurationClient|
443 SemanticsUpdate* update) {
444 client_.UpdateSemantics(view_id, update->takeNodes(), update->takeActions());
445}
446
447// |PlatformConfigurationClient|
449 client_.SetApplicationLocale(std::move(locale));
450}
451
452// |PlatformConfigurationClient|
454 client_.SetSemanticsTreeEnabled(enabled);
455}
456
457// |PlatformConfigurationClient|
458void RuntimeController::HandlePlatformMessage(
459 std::unique_ptr<PlatformMessage> message) {
460 client_.HandlePlatformMessage(std::move(message));
461}
462
463// |PlatformConfigurationClient|
464FontCollection& RuntimeController::GetFontCollection() {
465 return client_.GetFontCollection();
466}
467
468// |PlatfromConfigurationClient|
469std::shared_ptr<AssetManager> RuntimeController::GetAssetManager() {
470 return client_.GetAssetManager();
471}
472
473// |PlatformConfigurationClient|
474void RuntimeController::UpdateIsolateDescription(const std::string isolate_name,
475 int64_t isolate_port) {
476 client_.UpdateIsolateDescription(isolate_name, isolate_port);
477}
478
479// |PlatformConfigurationClient|
480void RuntimeController::SetNeedsReportTimings(bool value) {
481 client_.SetNeedsReportTimings(value);
482}
483
484// |PlatformConfigurationClient|
485std::shared_ptr<const fml::Mapping>
487 return persistent_isolate_data_;
488}
489
490// |PlatformConfigurationClient|
491std::unique_ptr<std::vector<std::string>>
492RuntimeController::ComputePlatformResolvedLocale(
493 const std::vector<std::string>& supported_locale_data) {
494 return client_.ComputePlatformResolvedLocale(supported_locale_data);
495}
496
497// |PlatformConfigurationClient|
498void RuntimeController::SendChannelUpdate(std::string name, bool listening) {
499 client_.SendChannelUpdate(std::move(name), listening);
500}
501
503 std::shared_ptr<DartIsolate> root_isolate = root_isolate_.lock();
504 return root_isolate ? root_isolate->main_port() : ILLEGAL_PORT;
505}
506
508 std::shared_ptr<DartIsolate> root_isolate = root_isolate_.lock();
509 return root_isolate ? root_isolate->debug_name() : "";
510}
511
513 std::shared_ptr<DartIsolate> root_isolate = root_isolate_.lock();
514 if (!root_isolate) {
515 return false;
516 }
517 tonic::DartState::Scope scope(root_isolate);
518 return Dart_HasLivePorts();
519}
520
522 std::shared_ptr<DartIsolate> root_isolate = root_isolate_.lock();
523 if (!root_isolate) {
524 return false;
525 }
526 return root_isolate->HasPendingMicrotasks();
527}
528
530 std::shared_ptr<DartIsolate> root_isolate = root_isolate_.lock();
531 return root_isolate ? root_isolate->GetLastError() : tonic::kNoError;
532}
533
535 const Settings& settings,
536 const fml::closure& root_isolate_create_callback,
537 std::optional<std::string> dart_entrypoint,
538 std::optional<std::string> dart_entrypoint_library,
539 const std::vector<std::string>& dart_entrypoint_args,
540 std::unique_ptr<IsolateConfiguration> isolate_configuration,
541 std::shared_ptr<NativeAssetsManager> native_assets_manager,
542 std::optional<int64_t> engine_id) {
543 if (root_isolate_.lock()) {
544 FML_LOG(ERROR) << "Root isolate was already running.";
545 return false;
546 }
547
548 auto strong_root_isolate =
550 settings, //
551 isolate_snapshot_, //
552 std::make_unique<PlatformConfiguration>(this), //
554 root_isolate_create_callback, //
555 isolate_create_callback_, //
556 isolate_shutdown_callback_, //
557 std::move(dart_entrypoint), //
558 std::move(dart_entrypoint_library), //
559 dart_entrypoint_args, //
560 std::move(isolate_configuration), //
561 context_, //
562 spawning_isolate_.lock().get(),
563 std::move(native_assets_manager)) //
564 .lock();
565
566 if (!strong_root_isolate) {
567 FML_LOG(ERROR) << "Could not create root isolate.";
568 return false;
569 }
570
571 // Enable platform channels for background isolates.
572 strong_root_isolate->GetIsolateGroupData().SetPlatformMessageHandler(
573 strong_root_isolate->GetRootIsolateToken(),
574 client_.GetPlatformMessageHandler());
575
576 // The root isolate ivar is weak.
577 root_isolate_ = strong_root_isolate;
578
579 // Capture by `this` here is safe because the callback is made by the dart
580 // state itself. The isolate (and its Dart state) is owned by this object and
581 // it will be collected before this object.
582 strong_root_isolate->SetReturnCodeCallback(
583 [this](uint32_t code) { root_isolate_return_code_ = code; });
584
585 if (auto* platform_configuration = GetPlatformConfigurationIfAvailable()) {
586 tonic::DartState::Scope scope(strong_root_isolate);
587 platform_configuration->DidCreateIsolate();
588 if (!FlushRuntimeStateToIsolate()) {
589 FML_DLOG(ERROR) << "Could not set up initial isolate state.";
590 }
591 if (engine_id) {
592 if (!platform_configuration->SetEngineId(*engine_id)) {
593 FML_DLOG(ERROR) << "Could not set engine identifier.";
594 }
595 }
596 } else {
597 FML_DCHECK(false) << "RuntimeController created without window binding.";
598 }
599
600 FML_DCHECK(Dart_CurrentIsolate() == nullptr);
601
602 client_.OnRootIsolateCreated();
603
604 return true;
605}
606
607std::optional<std::string> RuntimeController::GetRootIsolateServiceID() const {
608 if (auto isolate = root_isolate_.lock()) {
609 return isolate->GetServiceId();
610 }
611 return std::nullopt;
612}
613
615 return root_isolate_return_code_;
616}
617
619 auto isolate = root_isolate_.lock();
620 if (isolate) {
621 auto isolate_scope = tonic::DartIsolateScope(isolate->isolate());
622 Dart_IsolateGroup isolate_group = Dart_CurrentIsolateGroup();
623 return reinterpret_cast<uint64_t>(isolate_group);
624 } else {
625 return 0;
626 }
627}
628
630 intptr_t loading_unit_id,
631 std::unique_ptr<const fml::Mapping> snapshot_data,
632 std::unique_ptr<const fml::Mapping> snapshot_instructions) {
633 root_isolate_.lock()->LoadLoadingUnit(loading_unit_id,
634 std::move(snapshot_data),
635 std::move(snapshot_instructions));
636}
637
639 intptr_t loading_unit_id,
640 const std::string
641 error_message, // NOLINT(performance-unnecessary-value-param)
642 bool transient) {
643 root_isolate_.lock()->LoadLoadingUnitError(loading_unit_id, error_message,
644 transient);
645}
646
647void RuntimeController::RequestDartDeferredLibrary(intptr_t loading_unit_id) {
648 return client_.RequestDartDeferredLibrary(loading_unit_id);
649}
650
651bool RuntimeController::SetDisplays(const std::vector<DisplayData>& displays) {
652 TRACE_EVENT0("flutter", "SetDisplays");
653 platform_data_.displays = displays;
654
655 if (auto* platform_configuration = GetPlatformConfigurationIfAvailable()) {
656 platform_configuration->UpdateDisplays(displays);
657 return true;
658 }
659 return false;
660}
661
662double RuntimeController::GetScaledFontSize(double unscaled_font_size,
663 int configuration_id) const {
664 return client_.GetScaledFontSize(unscaled_font_size, configuration_id);
665}
666
667void RuntimeController::RequestViewFocusChange(
668 const ViewFocusChangeRequest& request) {
669 client_.RequestViewFocusChange(request);
670}
671
673 platform_isolate_manager_->ShutdownPlatformIsolates();
674}
675
677 std::shared_ptr<DartIsolate> root_isolate = root_isolate_.lock();
678 if (root_isolate) {
679 root_isolate->SetOwnerToCurrentThread();
680 }
681}
682
683RuntimeController::Locale::Locale(std::string language_code_,
684 std::string country_code_,
685 std::string script_code_,
686 std::string variant_code_)
687 : language_code(std::move(language_code_)),
688 country_code(std::move(country_code_)),
689 script_code(std::move(script_code_)),
690 variant_code(std::move(variant_code_)) {}
691
692RuntimeController::Locale::~Locale() = default;
693
694} // namespace flutter
static std::weak_ptr< DartIsolate > CreateRunningRootIsolate(const Settings &settings, const fml::RefPtr< const DartSnapshot > &isolate_snapshot, std::unique_ptr< PlatformConfiguration > platform_configuration, Flags flags, const fml::closure &root_isolate_create_callback, const fml::closure &isolate_create_callback, const fml::closure &isolate_shutdown_callback, std::optional< std::string > dart_entrypoint, std::optional< std::string > dart_entrypoint_library, const std::vector< std::string > &dart_entrypoint_args, std::unique_ptr< IsolateConfiguration > isolate_configuration, const UIDartState::Context &context, const DartIsolate *spawning_isolate=nullptr, std::shared_ptr< NativeAssetsManager > native_assets_manager=nullptr)
Creates an instance of a root isolate and returns a weak pointer to the same. The isolate instance ma...
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
A class for holding and distributing platform-level information to and from the Dart code in Flutter'...
const ViewportMetrics * GetMetrics(int view_id)
Retrieves the viewport metrics with the given ID managed by the PlatformConfiguration.
static Dart_PerformanceMode GetDartPerformanceMode()
Returns the current performance mode of the Dart VM. Defaults to Dart_PerformanceMode_Default if no p...
std::unique_ptr< PointerDataPacket > Convert(const PointerDataPacket &packet)
Converts pointer data packet into a form that framework understands. The raw pointer data packet from...
void AddView(int64_t view_id, const ViewportMetrics &view_metrics, AddViewCallback callback)
Notify the isolate that a new view is available.
bool SetAccessibilityFeatures(int32_t flags)
Forward the preference of accessibility features that must be enabled in the semantics tree to the ru...
void SetSemanticsTreeEnabled(bool enabled) override
Notifies whether Framework starts generating semantics tree.
Dart_Port GetMainPort()
Gets the main port identifier of the root isolate.
bool SetSemanticsEnabled(bool enabled)
Notifies the running isolate about whether the semantics tree should be generated or not....
bool SetViewportMetrics(int64_t view_id, const ViewportMetrics &metrics)
Forward the specified viewport metrics to the running isolate. If the isolate is not running,...
uint64_t GetRootIsolateGroup() const
Get an identifier that represents the Dart isolate group the root isolate is in.
RuntimeController(RuntimeDelegate &p_client, DartVM *vm, fml::RefPtr< const DartSnapshot > p_isolate_snapshot, const std::function< void(int64_t)> &idle_notification_callback, const PlatformData &platform_data, const fml::closure &isolate_create_callback, const fml::closure &isolate_shutdown_callback, std::shared_ptr< const fml::Mapping > p_persistent_isolate_data, const UIDartState::Context &context)
Creates a new instance of a runtime controller. This is usually only done by the engine instance asso...
virtual bool NotifyIdle(fml::TimeDelta deadline)
Notify the Dart VM that no frame workloads are expected on the UI task runner till the specified dead...
bool HasPendingMicrotasks()
Returns if the root isolate has any pending microtasks.
bool DispatchPointerDataPacket(const PointerDataPacket &packet)
Dispatch the specified pointer data message to the running root isolate.
bool SetInitialLifecycleState(const std::string &data)
Forward the initial lifecycle state data to the running isolate. If the isolate is not running,...
std::function< void(bool added)> AddViewCallback
bool SetLocales(const std::vector< std::string > &locale_data)
Forward the specified locale data to the running isolate. If the isolate is not running,...
void RequestDartDeferredLibrary(intptr_t loading_unit_id) override
Invoked when the Dart VM requests that a deferred library be loaded. Notifies the engine that the def...
bool SetDisplays(const std::vector< DisplayData > &displays)
Forward the specified display metrics to the running isolate. If the isolate is not running,...
bool HasLivePorts()
Returns if the root isolate has any live receive ports.
bool RemoveView(int64_t view_id)
Notify the isolate that a view is no longer available.
std::optional< std::string > GetRootIsolateServiceID() const
Get the service ID of the root isolate if the root isolate is running.
virtual bool IsRootIsolateRunning() const
Returns if the root isolate is running. The isolate must be transitioned to the running phase manuall...
bool LaunchRootIsolate(const Settings &settings, const fml::closure &root_isolate_create_callback, std::optional< std::string > dart_entrypoint, std::optional< std::string > dart_entrypoint_library, const std::vector< std::string > &dart_entrypoint_args, std::unique_ptr< IsolateConfiguration > isolate_configuration, std::shared_ptr< NativeAssetsManager > native_assets_manager, std::optional< int64_t > engine_id)
Launches the isolate using the window data associated with this runtime controller....
bool ReportTimings(std::vector< int64_t > timings)
Dart code cannot fully measure the time it takes for a specific frame to be rendered....
bool DispatchSemanticsAction(int64_t view_id, int32_t node_id, SemanticsAction action, fml::MallocMapping args)
Dispatch the semantics action to the specified accessibility node.
virtual bool DispatchPlatformMessage(std::unique_ptr< PlatformMessage > message)
Dispatch the specified platform message to running root isolate.
tonic::DartErrorHandleType GetLastError()
Get the last error encountered by the microtask queue.
bool SetUserSettingsData(const std::string &data)
Forward the user settings data to the running isolate. If the isolate is not running,...
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,...
std::unique_ptr< RuntimeController > Clone() const
Clone the runtime controller. Launching an isolate with a cloned runtime controller will use the same...
bool SendViewFocusEvent(const ViewFocusEvent &event)
Notify the isolate that the focus state of a native view has changed.
void ShutdownPlatformIsolates()
Shuts down all registered platform isolates. Must be called from the platform thread.
std::unique_ptr< RuntimeController > Spawn(RuntimeDelegate &p_client, const std::string &advisory_script_uri, const std::string &advisory_script_entrypoint, const std::function< void(int64_t)> &idle_notification_callback, const fml::closure &isolate_create_callback, const fml::closure &isolate_shutdown_callback, const std::shared_ptr< const fml::Mapping > &persistent_isolate_data, fml::WeakPtr< IOManager > io_manager, fml::TaskRunnerAffineWeakPtr< ImageDecoder > image_decoder, fml::TaskRunnerAffineWeakPtr< ImageGeneratorRegistry > image_generator_registry, fml::TaskRunnerAffineWeakPtr< SnapshotDelegate > snapshot_delegate) const
Create a RuntimeController that shares as many resources as possible with the calling RuntimeControll...
void UpdateSemantics(int64_t view_id, SemanticsUpdate *update) override
Receives an updated semantics tree from the Framework.
bool BeginFrame(fml::TimePoint frame_time, uint64_t frame_number)
Notifies the running isolate that it should start generating a new frame.
std::optional< uint32_t > GetRootIsolateReturnCode()
Get the return code specified by the root isolate (if one is present).
std::shared_ptr< const fml::Mapping > GetPersistentIsolateData() override
The embedder can specify data that the isolate can request synchronously on launch....
virtual 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 ...
void SetApplicationLocale(std::string locale) override
Framework sets the application locale.
std::string GetIsolateName()
Gets the debug name of the root isolate. But default, the debug name of the isolate is derived from i...
virtual std::unique_ptr< std::vector< std::string > > ComputePlatformResolvedLocale(const std::vector< std::string > &supported_locale_data)=0
virtual void RequestDartDeferredLibrary(intptr_t loading_unit_id)=0
virtual double GetScaledFontSize(double unscaled_font_size, int configuration_id) const =0
virtual std::string DefaultRouteName()=0
virtual std::weak_ptr< PlatformMessageHandler > GetPlatformMessageHandler() const =0
virtual void HandlePlatformMessage(std::unique_ptr< PlatformMessage > message)=0
virtual void SetNeedsReportTimings(bool value)=0
virtual void SetApplicationLocale(std::string locale)=0
virtual std::shared_ptr< AssetManager > GetAssetManager()=0
virtual void OnRootIsolateCreated()=0
virtual FontCollection & GetFontCollection()=0
virtual void Render(int64_t view_id, std::unique_ptr< flutter::LayerTree > layer_tree, float device_pixel_ratio)=0
virtual void UpdateSemantics(int64_t view_id, SemanticsNodeUpdates update, CustomAccessibilityActionUpdates actions)=0
virtual void UpdateIsolateDescription(const std::string isolate_name, int64_t isolate_port)=0
virtual void OnAllViewsRendered()=0
virtual void SendChannelUpdate(std::string name, bool listening)=0
virtual void RequestViewFocusChange(const ViewFocusChangeRequest &request)=0
virtual void SetSemanticsTreeEnabled(bool enabled)=0
virtual void ScheduleFrame(bool regenerate_layer_trees=true)=0
SemanticsNodeUpdates takeNodes()
CustomAccessibilityActionUpdates takeActions()
PlatformConfiguration * platform_configuration() const
static UIDartState * Current()
A Mapping like NonOwnedMapping, but uses Free as its release proc.
Definition mapping.h:144
constexpr int64_t ToMicroseconds() const
Definition time_delta.h:62
static constexpr TimeDelta FromMilliseconds(int64_t millis)
Definition time_delta.h:46
static constexpr TimeDelta FromMicroseconds(int64_t micros)
Definition time_delta.h:43
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
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
#define FML_DCHECK(condition)
Definition logging.h:122
DEF_SWITCHES_START aot vmservice shared library name
Definition switch_defs.h: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 switch_defs.h:36
std::function< void()> closure
Definition closure.h:14
Definition ref_ptr.h:261
DartErrorHandleType
Definition dart_error.h:67
@ kNoError
Definition dart_error.h:68
std::vector< FlutterEngineDisplay > * displays
int32_t height
int32_t width
std::unordered_map< int64_t, ViewportMetrics > viewport_metrics_for_views
int32_t accessibility_feature_flags_
std::string lifecycle_state
std::vector< DisplayData > displays
std::vector< std::string > locale_data
std::string user_settings_data
The subset of state which is owned by the shell or engine and passed through the RuntimeController in...
fml::RefPtr< SkiaUnrefQueue > unref_queue
bool enable_flutter_gpu
Whether flutter_gpu is enabled or not.
std::shared_future< impeller::RuntimeStageBackend > runtime_stage_backend
The runtime stage backend for fragment shaders.
const TaskRunners task_runners
bool enable_impeller
Whether Impeller is enabled or not.
std::shared_ptr< fml::ConcurrentTaskRunner > concurrent_task_runner
bool deterministic_rendering_enabled
Whether deterministic rendering practices should be used.
#define TRACE_EVENT0(category_group, name)
#define TRACE_EVENT1(category_group, name, arg1_name, arg1_val)