Flutter Engine Uber Docs
Docs for the entire Flutter Engine repo.
 
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 const flutter::PointData offset) {
379 if (auto* platform_configuration = GetPlatformConfigurationIfAvailable()) {
380 TRACE_EVENT0("flutter", "RuntimeController::HitTest");
381 return platform_configuration->HitTest(view_id, offset);
382 }
383 return {.has_platform_view = false};
384}
385
387 int32_t node_id,
390 TRACE_EVENT1("flutter", "RuntimeController::DispatchSemanticsAction", "mode",
391 "basic");
392 if (auto* platform_configuration = GetPlatformConfigurationIfAvailable()) {
393 platform_configuration->DispatchSemanticsAction(view_id, node_id, action,
394 std::move(args));
395 return true;
396 }
397
398 return false;
399}
400
402RuntimeController::GetPlatformConfigurationIfAvailable() {
403 std::shared_ptr<DartIsolate> root_isolate = root_isolate_.lock();
404 return root_isolate ? root_isolate->platform_configuration() : nullptr;
405}
406
407// |PlatformConfigurationClient|
408std::string RuntimeController::DefaultRouteName() {
409 return client_.DefaultRouteName();
410}
411
412// |PlatformConfigurationClient|
413void RuntimeController::ScheduleFrame() {
414 client_.ScheduleFrame();
415}
416
417void RuntimeController::EndWarmUpFrame() {
418 client_.OnAllViewsRendered();
419}
420
421// |PlatformConfigurationClient|
422void RuntimeController::Render(int64_t view_id,
423 Scene* scene,
424 double width,
425 double height) {
426 const ViewportMetrics* view_metrics =
428 if (view_metrics == nullptr) {
429 return;
430 }
431 client_.Render(view_id, scene->takeLayerTree(width, height),
432 view_metrics->device_pixel_ratio);
433 rendered_views_during_frame_.insert(view_id);
434 CheckIfAllViewsRendered();
435}
436
437void RuntimeController::MarkAsFrameBorder() {
438 rendered_views_during_frame_.clear();
439}
440
441void RuntimeController::CheckIfAllViewsRendered() {
442 if (rendered_views_during_frame_.size() != 0 &&
443 rendered_views_during_frame_.size() ==
444 platform_data_.viewport_metrics_for_views.size()) {
445 client_.OnAllViewsRendered();
446 MarkAsFrameBorder();
447 }
448}
449
450// |PlatformConfigurationClient|
452 SemanticsUpdate* update) {
453 client_.UpdateSemantics(view_id, update->takeNodes(), update->takeActions());
454}
455
456// |PlatformConfigurationClient|
458 client_.SetApplicationLocale(std::move(locale));
459}
460
461// |PlatformConfigurationClient|
463 client_.SetSemanticsTreeEnabled(enabled);
464}
465
466// |PlatformConfigurationClient|
467void RuntimeController::HandlePlatformMessage(
468 std::unique_ptr<PlatformMessage> message) {
469 client_.HandlePlatformMessage(std::move(message));
470}
471
472// |PlatformConfigurationClient|
473FontCollection& RuntimeController::GetFontCollection() {
474 return client_.GetFontCollection();
475}
476
477// |PlatfromConfigurationClient|
478std::shared_ptr<AssetManager> RuntimeController::GetAssetManager() {
479 return client_.GetAssetManager();
480}
481
482// |PlatformConfigurationClient|
483void RuntimeController::UpdateIsolateDescription(const std::string isolate_name,
484 int64_t isolate_port) {
485 client_.UpdateIsolateDescription(isolate_name, isolate_port);
486}
487
488// |PlatformConfigurationClient|
489void RuntimeController::SetNeedsReportTimings(bool value) {
490 client_.SetNeedsReportTimings(value);
491}
492
493// |PlatformConfigurationClient|
494std::shared_ptr<const fml::Mapping>
496 return persistent_isolate_data_;
497}
498
499// |PlatformConfigurationClient|
500std::unique_ptr<std::vector<std::string>>
501RuntimeController::ComputePlatformResolvedLocale(
502 const std::vector<std::string>& supported_locale_data) {
503 return client_.ComputePlatformResolvedLocale(supported_locale_data);
504}
505
506// |PlatformConfigurationClient|
507void RuntimeController::SendChannelUpdate(std::string name, bool listening) {
508 client_.SendChannelUpdate(std::move(name), listening);
509}
510
512 std::shared_ptr<DartIsolate> root_isolate = root_isolate_.lock();
513 return root_isolate ? root_isolate->main_port() : ILLEGAL_PORT;
514}
515
517 std::shared_ptr<DartIsolate> root_isolate = root_isolate_.lock();
518 return root_isolate ? root_isolate->debug_name() : "";
519}
520
522 std::shared_ptr<DartIsolate> root_isolate = root_isolate_.lock();
523 if (!root_isolate) {
524 return false;
525 }
526 tonic::DartState::Scope scope(root_isolate);
527 return Dart_HasLivePorts();
528}
529
531 std::shared_ptr<DartIsolate> root_isolate = root_isolate_.lock();
532 if (!root_isolate) {
533 return false;
534 }
535 return root_isolate->HasPendingMicrotasks();
536}
537
539 std::shared_ptr<DartIsolate> root_isolate = root_isolate_.lock();
540 return root_isolate ? root_isolate->GetLastError() : tonic::kNoError;
541}
542
544 const Settings& settings,
545 const fml::closure& root_isolate_create_callback,
546 std::optional<std::string> dart_entrypoint,
547 std::optional<std::string> dart_entrypoint_library,
548 const std::vector<std::string>& dart_entrypoint_args,
549 std::unique_ptr<IsolateConfiguration> isolate_configuration,
550 std::shared_ptr<NativeAssetsManager> native_assets_manager,
551 std::optional<int64_t> engine_id) {
552 if (root_isolate_.lock()) {
553 FML_LOG(ERROR) << "Root isolate was already running.";
554 return false;
555 }
556
557 auto strong_root_isolate =
559 settings, //
560 isolate_snapshot_, //
561 std::make_unique<PlatformConfiguration>(this), //
563 root_isolate_create_callback, //
564 isolate_create_callback_, //
565 isolate_shutdown_callback_, //
566 std::move(dart_entrypoint), //
567 std::move(dart_entrypoint_library), //
568 dart_entrypoint_args, //
569 std::move(isolate_configuration), //
570 context_, //
571 spawning_isolate_.lock().get(),
572 std::move(native_assets_manager)) //
573 .lock();
574
575 if (!strong_root_isolate) {
576 FML_LOG(ERROR) << "Could not create root isolate.";
577 return false;
578 }
579
580 // Enable platform channels for background isolates.
581 strong_root_isolate->GetIsolateGroupData().SetPlatformMessageHandler(
582 strong_root_isolate->GetRootIsolateToken(),
583 client_.GetPlatformMessageHandler());
584
585 // The root isolate ivar is weak.
586 root_isolate_ = strong_root_isolate;
587
588 // Capture by `this` here is safe because the callback is made by the dart
589 // state itself. The isolate (and its Dart state) is owned by this object and
590 // it will be collected before this object.
591 strong_root_isolate->SetReturnCodeCallback(
592 [this](uint32_t code) { root_isolate_return_code_ = code; });
593
594 if (auto* platform_configuration = GetPlatformConfigurationIfAvailable()) {
595 tonic::DartState::Scope scope(strong_root_isolate);
596 platform_configuration->DidCreateIsolate();
597 if (!FlushRuntimeStateToIsolate()) {
598 FML_DLOG(ERROR) << "Could not set up initial isolate state.";
599 }
600 if (engine_id) {
601 if (!platform_configuration->SetEngineId(*engine_id)) {
602 FML_DLOG(ERROR) << "Could not set engine identifier.";
603 }
604 }
605 } else {
606 FML_DCHECK(false) << "RuntimeController created without window binding.";
607 }
608
609 FML_DCHECK(Dart_CurrentIsolate() == nullptr);
610
611 client_.OnRootIsolateCreated();
612
613 return true;
614}
615
616std::optional<std::string> RuntimeController::GetRootIsolateServiceID() const {
617 if (auto isolate = root_isolate_.lock()) {
618 return isolate->GetServiceId();
619 }
620 return std::nullopt;
621}
622
624 return root_isolate_return_code_;
625}
626
628 auto isolate = root_isolate_.lock();
629 if (isolate) {
630 auto isolate_scope = tonic::DartIsolateScope(isolate->isolate());
631 Dart_IsolateGroup isolate_group = Dart_CurrentIsolateGroup();
632 return reinterpret_cast<uint64_t>(isolate_group);
633 } else {
634 return 0;
635 }
636}
637
639 intptr_t loading_unit_id,
640 std::unique_ptr<const fml::Mapping> snapshot_data,
641 std::unique_ptr<const fml::Mapping> snapshot_instructions) {
642 root_isolate_.lock()->LoadLoadingUnit(loading_unit_id,
643 std::move(snapshot_data),
644 std::move(snapshot_instructions));
645}
646
648 intptr_t loading_unit_id,
649 const std::string
650 error_message, // NOLINT(performance-unnecessary-value-param)
651 bool transient) {
652 root_isolate_.lock()->LoadLoadingUnitError(loading_unit_id, error_message,
653 transient);
654}
655
656void RuntimeController::RequestDartDeferredLibrary(intptr_t loading_unit_id) {
657 return client_.RequestDartDeferredLibrary(loading_unit_id);
658}
659
660bool RuntimeController::SetDisplays(const std::vector<DisplayData>& displays) {
661 TRACE_EVENT0("flutter", "SetDisplays");
662 platform_data_.displays = displays;
663
664 if (auto* platform_configuration = GetPlatformConfigurationIfAvailable()) {
665 platform_configuration->UpdateDisplays(displays);
666 return true;
667 }
668 return false;
669}
670
671double RuntimeController::GetScaledFontSize(double unscaled_font_size,
672 int configuration_id) const {
673 return client_.GetScaledFontSize(unscaled_font_size, configuration_id);
674}
675
676void RuntimeController::RequestViewFocusChange(
677 const ViewFocusChangeRequest& request) {
678 client_.RequestViewFocusChange(request);
679}
680
682 platform_isolate_manager_->ShutdownPlatformIsolates();
683}
684
686 std::shared_ptr<DartIsolate> root_isolate = root_isolate_.lock();
687 if (root_isolate) {
688 root_isolate->SetOwnerToCurrentThread();
689 }
690}
691
692RuntimeController::Locale::Locale(std::string language_code_,
693 std::string country_code_,
694 std::string script_code_,
695 std::string variant_code_)
696 : language_code(std::move(language_code_)),
697 country_code(std::move(country_code_)),
698 script_code(std::move(script_code_)),
699 variant_code(std::move(variant_code_)) {}
700
701RuntimeController::Locale::~Locale() = default;
702
703} // 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,...
HitTestResponse HitTest(int64_t view_id, const flutter::PointData offset)
Requests to perform framework hit test from the engine.
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
const char * message
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
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)