Flutter Engine
The Flutter Engine
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
5#include "flutter/runtime/runtime_controller.h"
6
7#include <utility>
8
9#include "flutter/common/constants.h"
10#include "flutter/common/settings.h"
11#include "flutter/fml/message_loop.h"
12#include "flutter/fml/trace_event.h"
13#include "flutter/lib/ui/compositing/scene.h"
14#include "flutter/lib/ui/ui_dart_state.h"
15#include "flutter/lib/ui/window/platform_configuration.h"
16#include "flutter/lib/ui/window/viewport_metrics.h"
17#include "flutter/runtime/dart_isolate_group_data.h"
18#include "flutter/runtime/isolate_configuration.h"
19#include "flutter/runtime/runtime_delegate.h"
21
22namespace flutter {
23
25 const TaskRunners& task_runners)
26 : client_(p_client),
27 vm_(nullptr),
28 context_(task_runners),
29 pointer_data_packet_converter_(*this) {}
30
32 RuntimeDelegate& p_client,
33 DartVM* p_vm,
34 fml::RefPtr<const DartSnapshot> p_isolate_snapshot,
35 const std::function<void(int64_t)>& p_idle_notification_callback,
36 const PlatformData& p_platform_data,
37 const fml::closure& p_isolate_create_callback,
38 const fml::closure& p_isolate_shutdown_callback,
39 std::shared_ptr<const fml::Mapping> p_persistent_isolate_data,
40 const UIDartState::Context& p_context)
41 : client_(p_client),
42 vm_(p_vm),
43 isolate_snapshot_(std::move(p_isolate_snapshot)),
44 idle_notification_callback_(p_idle_notification_callback),
45 platform_data_(p_platform_data),
46 isolate_create_callback_(p_isolate_create_callback),
47 isolate_shutdown_callback_(p_isolate_shutdown_callback),
48 persistent_isolate_data_(std::move(p_persistent_isolate_data)),
49 context_(p_context),
50 pointer_data_packet_converter_(*this) {}
51
52std::unique_ptr<RuntimeController> RuntimeController::Spawn(
53 RuntimeDelegate& p_client,
54 const std::string& advisory_script_uri,
55 const std::string& advisory_script_entrypoint,
56 const std::function<void(int64_t)>& p_idle_notification_callback,
57 const fml::closure& p_isolate_create_callback,
58 const fml::closure& p_isolate_shutdown_callback,
59 const std::shared_ptr<const fml::Mapping>& p_persistent_isolate_data,
60 fml::WeakPtr<IOManager> io_manager,
61 fml::WeakPtr<ImageDecoder> image_decoder,
62 fml::WeakPtr<ImageGeneratorRegistry> image_generator_registry,
63 fml::TaskRunnerAffineWeakPtr<SnapshotDelegate> snapshot_delegate) const {
64 UIDartState::Context spawned_context{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,
72 context_.volatile_path_tracker,
74 context_.enable_impeller,
75 context_.runtime_stage_backend};
76 auto result =
77 std::make_unique<RuntimeController>(p_client, //
78 vm_, //
79 isolate_snapshot_, //
80 p_idle_notification_callback, //
81 platform_data_, //
82 p_isolate_create_callback, //
83 p_isolate_shutdown_callback, //
84 p_persistent_isolate_data, //
85 spawned_context); //
86 result->spawning_isolate_ = root_isolate_;
87 return result;
88}
89
91 FML_DCHECK(Dart_CurrentIsolate() == nullptr);
92 std::shared_ptr<DartIsolate> root_isolate = root_isolate_.lock();
93 if (root_isolate) {
94 root_isolate->SetReturnCodeCallback(nullptr);
95 auto result = root_isolate->Shutdown();
96 if (!result) {
97 FML_DLOG(ERROR) << "Could not shutdown the root isolate.";
98 }
99 root_isolate_ = {};
100 }
101}
102
104 std::shared_ptr<DartIsolate> root_isolate = root_isolate_.lock();
105 if (root_isolate) {
106 return root_isolate->GetPhase() == DartIsolate::Phase::Running;
107 }
108 return false;
109}
110
111std::unique_ptr<RuntimeController> RuntimeController::Clone() const {
112 return std::make_unique<RuntimeController>(client_, //
113 vm_, //
114 isolate_snapshot_, //
115 idle_notification_callback_, //
116 platform_data_, //
117 isolate_create_callback_, //
118 isolate_shutdown_callback_, //
119 persistent_isolate_data_, //
120 context_ //
121 );
122}
123
124bool RuntimeController::FlushRuntimeStateToIsolate() {
125 FML_DCHECK(!has_flushed_runtime_state_)
126 << "FlushRuntimeStateToIsolate is called more than once somehow.";
127 has_flushed_runtime_state_ = true;
128
129 auto platform_configuration = GetPlatformConfigurationIfAvailable();
130 if (!platform_configuration) {
131 return false;
132 }
133
134 for (auto const& [view_id, viewport_metrics] :
135 platform_data_.viewport_metrics_for_views) {
136 bool added = platform_configuration->AddView(view_id, viewport_metrics);
137
138 // Callbacks will have been already invoked if the engine was restarted.
139 if (pending_add_view_callbacks_.find(view_id) !=
140 pending_add_view_callbacks_.end()) {
141 pending_add_view_callbacks_[view_id](added);
142 pending_add_view_callbacks_.erase(view_id);
143 }
144
145 if (!added) {
146 FML_LOG(ERROR) << "Failed to flush view #" << view_id
147 << ". The Dart isolate may be in an inconsistent state.";
148 }
149 }
150
151 FML_DCHECK(pending_add_view_callbacks_.empty());
152 return SetLocales(platform_data_.locale_data) &&
153 SetSemanticsEnabled(platform_data_.semantics_enabled) &&
155 platform_data_.accessibility_feature_flags_) &&
156 SetUserSettingsData(platform_data_.user_settings_data) &&
158 SetDisplays(platform_data_.displays);
159}
160
161void RuntimeController::AddView(int64_t view_id,
162 const ViewportMetrics& view_metrics,
164 // If the Dart isolate is not running, |FlushRuntimeStateToIsolate| will
165 // add the view and invoke the callback when the isolate is started.
166 auto* platform_configuration = GetPlatformConfigurationIfAvailable();
167 if (!platform_configuration) {
168 FML_DCHECK(has_flushed_runtime_state_ == false);
169
170 if (pending_add_view_callbacks_.find(view_id) !=
171 pending_add_view_callbacks_.end()) {
172 FML_LOG(ERROR) << "View #" << view_id << " is already pending creation.";
173 callback(false);
174 return;
175 }
176
177 platform_data_.viewport_metrics_for_views[view_id] = view_metrics;
178 pending_add_view_callbacks_[view_id] = std::move(callback);
179 return;
180 }
181
182 FML_DCHECK(has_flushed_runtime_state_ || pending_add_view_callbacks_.empty());
183
184 platform_data_.viewport_metrics_for_views[view_id] = view_metrics;
185 bool added = platform_configuration->AddView(view_id, view_metrics);
186 if (added) {
187 ScheduleFrame();
188 }
189
190 callback(added);
191}
192
193bool RuntimeController::RemoveView(int64_t view_id) {
194 platform_data_.viewport_metrics_for_views.erase(view_id);
195
196 // If the Dart isolate has not been launched yet, the pending
197 // add view operation's callback is stored by the runtime controller.
198 // Notify this callback of the cancellation.
199 auto* platform_configuration = GetPlatformConfigurationIfAvailable();
200 if (!platform_configuration) {
201 FML_DCHECK(has_flushed_runtime_state_ == false);
202 if (pending_add_view_callbacks_.find(view_id) !=
203 pending_add_view_callbacks_.end()) {
204 pending_add_view_callbacks_[view_id](false);
205 pending_add_view_callbacks_.erase(view_id);
206 }
207
208 return false;
209 }
210
211 return platform_configuration->RemoveView(view_id);
212}
213
214bool RuntimeController::ViewExists(int64_t view_id) const {
215 return platform_data_.viewport_metrics_for_views.count(view_id) != 0;
216}
217
219 const ViewportMetrics& metrics) {
220 TRACE_EVENT0("flutter", "SetViewportMetrics");
221
222 platform_data_.viewport_metrics_for_views[view_id] = metrics;
223 if (auto* platform_configuration = GetPlatformConfigurationIfAvailable()) {
224 return platform_configuration->UpdateViewMetrics(view_id, metrics);
225 }
226
227 return false;
228}
229
231 const std::vector<std::string>& locale_data) {
232 platform_data_.locale_data = locale_data;
233
234 if (auto* platform_configuration = GetPlatformConfigurationIfAvailable()) {
235 platform_configuration->UpdateLocales(locale_data);
236 return true;
237 }
238
239 return false;
240}
241
243 platform_data_.user_settings_data = data;
244
245 if (auto* platform_configuration = GetPlatformConfigurationIfAvailable()) {
246 platform_configuration->UpdateUserSettingsData(
247 platform_data_.user_settings_data);
248 return true;
249 }
250
251 return false;
252}
253
255 platform_data_.lifecycle_state = data;
256
257 if (auto* platform_configuration = GetPlatformConfigurationIfAvailable()) {
258 platform_configuration->UpdateInitialLifecycleState(
259 platform_data_.lifecycle_state);
260 return true;
261 }
262
263 return false;
264}
265
267 platform_data_.semantics_enabled = enabled;
268
269 if (auto* platform_configuration = GetPlatformConfigurationIfAvailable()) {
270 platform_configuration->UpdateSemanticsEnabled(
271 platform_data_.semantics_enabled);
272 return true;
273 }
274
275 return false;
276}
277
279 platform_data_.accessibility_feature_flags_ = flags;
280 if (auto* platform_configuration = GetPlatformConfigurationIfAvailable()) {
281 platform_configuration->UpdateAccessibilityFeatures(
282 platform_data_.accessibility_feature_flags_);
283 return true;
284 }
285
286 return false;
287}
288
290 uint64_t frame_number) {
291 MarkAsFrameBorder();
292 if (auto* platform_configuration = GetPlatformConfigurationIfAvailable()) {
293 platform_configuration->BeginFrame(frame_time, frame_number);
294 return true;
295 }
296
297 return false;
298}
299
300bool RuntimeController::ReportTimings(std::vector<int64_t> timings) {
301 if (auto* platform_configuration = GetPlatformConfigurationIfAvailable()) {
302 platform_configuration->ReportTimings(std::move(timings));
303 return true;
304 }
305
306 return false;
307}
308
312 // There's less than 1ms left before the deadline. Upstream callers do not
313 // check to see if the deadline is in the past, and work after this point
314 // will be in vain.
315 return false;
316 }
317
318 std::shared_ptr<DartIsolate> root_isolate = root_isolate_.lock();
319 if (!root_isolate) {
320 return false;
321 }
322
323 tonic::DartState::Scope scope(root_isolate);
324
325 Dart_PerformanceMode performance_mode =
328 return false;
329 }
330
332
333 // Idle notifications being in isolate scope are part of the contract.
334 if (idle_notification_callback_) {
335 TRACE_EVENT0("flutter", "EmbedderIdleNotification");
336 idle_notification_callback_(deadline.ToMicroseconds());
337 }
338 return true;
339}
340
342 std::shared_ptr<DartIsolate> root_isolate = root_isolate_.lock();
343 if (!root_isolate) {
344 return false;
345 }
346
347 tonic::DartState::Scope scope(root_isolate);
348
350
351 return true;
352}
353
355 std::unique_ptr<PlatformMessage> message) {
356 if (auto* platform_configuration = GetPlatformConfigurationIfAvailable()) {
357 TRACE_EVENT0("flutter", "RuntimeController::DispatchPlatformMessage");
358 platform_configuration->DispatchPlatformMessage(std::move(message));
359 return true;
360 }
361
362 return false;
363}
364
366 const PointerDataPacket& packet) {
367 if (auto* platform_configuration = GetPlatformConfigurationIfAvailable()) {
368 TRACE_EVENT0("flutter", "RuntimeController::DispatchPointerDataPacket");
369 std::unique_ptr<PointerDataPacket> converted_packet =
370 pointer_data_packet_converter_.Convert(packet);
371 if (converted_packet->GetLength() != 0) {
372 platform_configuration->DispatchPointerDataPacket(*converted_packet);
373 }
374 return true;
375 }
376
377 return false;
378}
379
383 TRACE_EVENT1("flutter", "RuntimeController::DispatchSemanticsAction", "mode",
384 "basic");
385 if (auto* platform_configuration = GetPlatformConfigurationIfAvailable()) {
386 platform_configuration->DispatchSemanticsAction(node_id, action,
387 std::move(args));
388 return true;
389 }
390
391 return false;
392}
393
395RuntimeController::GetPlatformConfigurationIfAvailable() {
396 std::shared_ptr<DartIsolate> root_isolate = root_isolate_.lock();
397 return root_isolate ? root_isolate->platform_configuration() : nullptr;
398}
399
400// |PlatformConfigurationClient|
401std::string RuntimeController::DefaultRouteName() {
402 return client_.DefaultRouteName();
403}
404
405// |PlatformConfigurationClient|
406void RuntimeController::ScheduleFrame() {
407 client_.ScheduleFrame();
408}
409
410void RuntimeController::EndWarmUpFrame() {
411 client_.OnAllViewsRendered();
412}
413
414// |PlatformConfigurationClient|
415void RuntimeController::Render(int64_t view_id,
416 Scene* scene,
417 double width,
418 double height) {
419 const ViewportMetrics* view_metrics =
421 if (view_metrics == nullptr) {
422 return;
423 }
424 client_.Render(view_id, scene->takeLayerTree(width, height),
425 view_metrics->device_pixel_ratio);
426 rendered_views_during_frame_.insert(view_id);
427 CheckIfAllViewsRendered();
428}
429
430void RuntimeController::MarkAsFrameBorder() {
431 rendered_views_during_frame_.clear();
432}
433
434void RuntimeController::CheckIfAllViewsRendered() {
435 if (rendered_views_during_frame_.size() != 0 &&
436 rendered_views_during_frame_.size() ==
437 platform_data_.viewport_metrics_for_views.size()) {
438 client_.OnAllViewsRendered();
439 MarkAsFrameBorder();
440 }
441}
442
443// |PlatformConfigurationClient|
444void RuntimeController::UpdateSemantics(SemanticsUpdate* update) {
445 if (platform_data_.semantics_enabled) {
446 client_.UpdateSemantics(update->takeNodes(), update->takeActions());
447 }
448}
449
450// |PlatformConfigurationClient|
451void RuntimeController::HandlePlatformMessage(
452 std::unique_ptr<PlatformMessage> message) {
453 client_.HandlePlatformMessage(std::move(message));
454}
455
456// |PlatformConfigurationClient|
457FontCollection& RuntimeController::GetFontCollection() {
458 return client_.GetFontCollection();
459}
460
461// |PlatfromConfigurationClient|
462std::shared_ptr<AssetManager> RuntimeController::GetAssetManager() {
463 return client_.GetAssetManager();
464}
465
466// |PlatformConfigurationClient|
467void RuntimeController::UpdateIsolateDescription(const std::string isolate_name,
468 int64_t isolate_port) {
469 client_.UpdateIsolateDescription(isolate_name, isolate_port);
470}
471
472// |PlatformConfigurationClient|
473void RuntimeController::SetNeedsReportTimings(bool value) {
475}
476
477// |PlatformConfigurationClient|
478std::shared_ptr<const fml::Mapping>
480 return persistent_isolate_data_;
481}
482
483// |PlatformConfigurationClient|
484std::unique_ptr<std::vector<std::string>>
485RuntimeController::ComputePlatformResolvedLocale(
486 const std::vector<std::string>& supported_locale_data) {
487 return client_.ComputePlatformResolvedLocale(supported_locale_data);
488}
489
490// |PlatformConfigurationClient|
491void RuntimeController::SendChannelUpdate(std::string name, bool listening) {
492 client_.SendChannelUpdate(std::move(name), listening);
493}
494
496 std::shared_ptr<DartIsolate> root_isolate = root_isolate_.lock();
497 return root_isolate ? root_isolate->main_port() : ILLEGAL_PORT;
498}
499
501 std::shared_ptr<DartIsolate> root_isolate = root_isolate_.lock();
502 return root_isolate ? root_isolate->debug_name() : "";
503}
504
506 std::shared_ptr<DartIsolate> root_isolate = root_isolate_.lock();
507 if (!root_isolate) {
508 return false;
509 }
510 tonic::DartState::Scope scope(root_isolate);
511 return Dart_HasLivePorts();
512}
513
515 std::shared_ptr<DartIsolate> root_isolate = root_isolate_.lock();
516 return root_isolate ? root_isolate->GetLastError() : tonic::kNoError;
517}
518
520 const Settings& settings,
521 const fml::closure& root_isolate_create_callback,
522 std::optional<std::string> dart_entrypoint,
523 std::optional<std::string> dart_entrypoint_library,
524 const std::vector<std::string>& dart_entrypoint_args,
525 std::unique_ptr<IsolateConfiguration> isolate_configuration) {
526 if (root_isolate_.lock()) {
527 FML_LOG(ERROR) << "Root isolate was already running.";
528 return false;
529 }
530
531 auto strong_root_isolate =
533 settings, //
534 isolate_snapshot_, //
535 std::make_unique<PlatformConfiguration>(this), //
537 root_isolate_create_callback, //
538 isolate_create_callback_, //
539 isolate_shutdown_callback_, //
540 std::move(dart_entrypoint), //
541 std::move(dart_entrypoint_library), //
542 dart_entrypoint_args, //
543 std::move(isolate_configuration), //
544 context_, //
545 spawning_isolate_.lock().get()) //
546 .lock();
547
548 if (!strong_root_isolate) {
549 FML_LOG(ERROR) << "Could not create root isolate.";
550 return false;
551 }
552
553 // Enable platform channels for background isolates.
554 strong_root_isolate->GetIsolateGroupData().SetPlatformMessageHandler(
555 strong_root_isolate->GetRootIsolateToken(),
556 client_.GetPlatformMessageHandler());
557
558 // The root isolate ivar is weak.
559 root_isolate_ = strong_root_isolate;
560
561 // Capture by `this` here is safe because the callback is made by the dart
562 // state itself. The isolate (and its Dart state) is owned by this object and
563 // it will be collected before this object.
564 strong_root_isolate->SetReturnCodeCallback(
565 [this](uint32_t code) { root_isolate_return_code_ = code; });
566
567 if (auto* platform_configuration = GetPlatformConfigurationIfAvailable()) {
568 tonic::DartState::Scope scope(strong_root_isolate);
569 platform_configuration->DidCreateIsolate();
570 if (!FlushRuntimeStateToIsolate()) {
571 FML_DLOG(ERROR) << "Could not set up initial isolate state.";
572 }
573 } else {
574 FML_DCHECK(false) << "RuntimeController created without window binding.";
575 }
576
577 FML_DCHECK(Dart_CurrentIsolate() == nullptr);
578
579 client_.OnRootIsolateCreated();
580
581 return true;
582}
583
584std::optional<std::string> RuntimeController::GetRootIsolateServiceID() const {
585 if (auto isolate = root_isolate_.lock()) {
586 return isolate->GetServiceId();
587 }
588 return std::nullopt;
589}
590
592 return root_isolate_return_code_;
593}
594
596 auto isolate = root_isolate_.lock();
597 if (isolate) {
598 auto isolate_scope = tonic::DartIsolateScope(isolate->isolate());
600 return reinterpret_cast<uint64_t>(isolate_group);
601 } else {
602 return 0;
603 }
604}
605
607 intptr_t loading_unit_id,
608 std::unique_ptr<const fml::Mapping> snapshot_data,
609 std::unique_ptr<const fml::Mapping> snapshot_instructions) {
610 root_isolate_.lock()->LoadLoadingUnit(loading_unit_id,
611 std::move(snapshot_data),
612 std::move(snapshot_instructions));
613}
614
616 intptr_t loading_unit_id,
617 const std::string
618 error_message, // NOLINT(performance-unnecessary-value-param)
619 bool transient) {
620 root_isolate_.lock()->LoadLoadingUnitError(loading_unit_id, error_message,
621 transient);
622}
623
624void RuntimeController::RequestDartDeferredLibrary(intptr_t loading_unit_id) {
625 return client_.RequestDartDeferredLibrary(loading_unit_id);
626}
627
628bool RuntimeController::SetDisplays(const std::vector<DisplayData>& displays) {
629 TRACE_EVENT0("flutter", "SetDisplays");
630 platform_data_.displays = displays;
631
632 if (auto* platform_configuration = GetPlatformConfigurationIfAvailable()) {
633 platform_configuration->UpdateDisplays(displays);
634 return true;
635 }
636 return false;
637}
638
639double RuntimeController::GetScaledFontSize(double unscaled_font_size,
640 int configuration_id) const {
641 return client_.GetScaledFontSize(unscaled_font_size, configuration_id);
642}
643
645 platform_isolate_manager_->ShutdownPlatformIsolates();
646}
647
648RuntimeController::Locale::Locale(std::string language_code_,
649 std::string country_code_,
650 std::string script_code_,
651 std::string variant_code_)
652 : language_code(std::move(language_code_)),
653 country_code(std::move(country_code_)),
654 script_code(std::move(script_code_)),
655 variant_code(std::move(variant_code_)) {}
656
657RuntimeController::Locale::~Locale() = default;
658
659} // 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)
Creates an instance of a root isolate and returns a weak pointer to the same. The isolate instance ma...
Definition: dart_isolate.cc:90
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
static Dart_PerformanceMode GetDartPerformanceMode()
Returns the current performance mode of the Dart VM. Defaults to Dart_PerformanceMode_Default if no p...
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.
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...
virtual bool IsRootIsolateRunning()
Returns if the root isolate is running. The isolate must be transitioned to the running phase manuall...
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...
bool DispatchSemanticsAction(int32_t node_id, SemanticsAction action, fml::MallocMapping args)
Dispatch the semantics action to the specified accessibility node.
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 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.
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::WeakPtr< ImageDecoder > image_decoder, fml::WeakPtr< ImageGeneratorRegistry > image_generator_registry, fml::TaskRunnerAffineWeakPtr< SnapshotDelegate > snapshot_delegate) const
Create a RuntimeController that shares as many resources as possible with the calling RuntimeControll...
bool ReportTimings(std::vector< int64_t > timings)
Dart code cannot fully measure the time it takes for a specific frame to be rendered....
virtual bool NotifyDestroyed()
Notify the Dart VM that the attached flutter view has been destroyed. This gives the Dart VM to perfo...
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)
Launches the isolate using the window data associated with this runtime controller....
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...
void ShutdownPlatformIsolates()
Shuts down all registered platform isolates. Must be called from the platform thread.
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 ...
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 UpdateSemantics(SemanticsNodeUpdates update, CustomAccessibilityActionUpdates actions)=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 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 ScheduleFrame(bool regenerate_layer_trees=true)=0
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
#define ILLEGAL_PORT
Definition: dart_api.h:1535
Dart_PerformanceMode
Definition: dart_api.h:1369
@ Dart_PerformanceMode_Latency
Definition: dart_api.h:1380
int64_t Dart_Port
Definition: dart_api.h:1525
struct _Dart_IsolateGroup * Dart_IsolateGroup
Definition: dart_api.h:89
DART_EXPORT void Dart_NotifyIdle(int64_t deadline)
DART_EXPORT Dart_Isolate Dart_CurrentIsolate(void)
DART_EXPORT void Dart_NotifyDestroyed(void)
DART_EXPORT Dart_IsolateGroup Dart_CurrentIsolateGroup(void)
DART_EXPORT bool Dart_HasLivePorts(void)
DART_EXPORT int64_t Dart_TimelineGetMicros()
FlutterSemanticsFlag flags
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
FlKeyEvent uint64_t FlKeyResponderAsyncCallback callback
uint8_t value
GAsyncResult * result
#define FML_DLOG(severity)
Definition: logging.h:102
#define FML_LOG(severity)
Definition: logging.h:82
#define FML_DCHECK(condition)
Definition: logging.h:103
Dart_NativeFunction function
Definition: fuchsia.cc:51
Win32Message message
DEF_SWITCHES_START aot vmservice shared library name
Definition: switches.h:32
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
std::function< void()> closure
Definition: closure.h:14
Definition: ref_ptr.h:256
DartErrorHandleType
Definition: dart_error.h:67
@ kNoError
Definition: dart_error.h:68
Definition: update.py:1
int32_t height
int32_t width
std::unordered_map< int64_t, ViewportMetrics > viewport_metrics_for_views
Definition: platform_data.h:36
int32_t accessibility_feature_flags_
Definition: platform_data.h:47
std::string lifecycle_state
Definition: platform_data.h:44
std::vector< DisplayData > displays
Definition: platform_data.h:48
std::vector< std::string > locale_data
Definition: platform_data.h:42
std::string user_settings_data
Definition: platform_data.h:43
The subset of state which is owned by the shell or engine and passed through the RuntimeController in...
Definition: ui_dart_state.h:45
fml::RefPtr< SkiaUnrefQueue > unref_queue
Definition: ui_dart_state.h:76
const TaskRunners task_runners
Definition: ui_dart_state.h:64
std::shared_ptr< VolatilePathTracker > volatile_path_tracker
Cache for tracking path volatility.
Definition: ui_dart_state.h:96
bool enable_impeller
Whether Impeller is enabled or not.
impeller::RuntimeStageBackend runtime_stage_backend
The expected backend for runtime stage shaders.
std::shared_ptr< fml::ConcurrentTaskRunner > concurrent_task_runner
#define ERROR(message)
Definition: elf_loader.cc:260
#define TRACE_EVENT0(category_group, name)
Definition: trace_event.h:131
#define TRACE_EVENT1(category_group, name, arg1_name, arg1_val)
Definition: trace_event.h:141