Flutter Engine
 
Loading...
Searching...
No Matches
flutter::RuntimeController Class Reference

#include <runtime_controller.h>

Inheritance diagram for flutter::RuntimeController:
flutter::PlatformConfigurationClient flutter::PointerDataPacketConverter::Delegate

Public Types

using AddViewCallback = std::function< void(bool added)>
 

Public Member Functions

 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 associated with the shell.
 
std::unique_ptr< RuntimeControllerSpawn (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 RuntimeController such that together they occupy less memory.
 
 ~RuntimeController () override
 
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. Before this call, the Dart isolate has not been initialized. On successful return, the caller can assume that the isolate is in the DartIsolate::Phase::Running phase.
 
std::unique_ptr< RuntimeControllerClone () const
 Clone the runtime controller. Launching an isolate with a cloned runtime controller will use the same snapshots and copies all window data to the new instance. This is usually only used in the debug runtime mode to support the cold-restart scenario.
 
void AddView (int64_t view_id, const ViewportMetrics &view_metrics, AddViewCallback callback)
 Notify the isolate that a new view is available.
 
bool RemoveView (int64_t view_id)
 Notify the isolate that a view is no longer available.
 
bool SendViewFocusEvent (const ViewFocusEvent &event)
 Notify the isolate that the focus state of a native view has changed.
 
bool SetViewportMetrics (int64_t view_id, const ViewportMetrics &metrics)
 Forward the specified viewport metrics to the running isolate. If the isolate is not running, these metrics will be saved and flushed to the isolate when it starts.
 
bool SetDisplays (const std::vector< DisplayData > &displays)
 Forward the specified display metrics to the running isolate. If the isolate is not running, these metrics will be saved and flushed to the isolate when it starts.
 
bool SetLocales (const std::vector< std::string > &locale_data)
 Forward the specified locale data to the running isolate. If the isolate is not running, this data will be saved and flushed to the isolate when it starts running.
 
bool SetUserSettingsData (const std::string &data)
 Forward the user settings data to the running isolate. If the isolate is not running, this data will be saved and flushed to the isolate when it starts running.
 
bool SetInitialLifecycleState (const std::string &data)
 Forward the initial lifecycle state data to the running isolate. If the isolate is not running, this data will be saved and flushed to the isolate when it starts running. After the isolate starts running, the current lifecycle state is pushed to it via the "flutter/lifecycle" channel.
 
bool SetSemanticsEnabled (bool enabled)
 Notifies the running isolate about whether the semantics tree should be generated or not. If the isolate is not running, this preference will be saved and flushed to the isolate when it starts running.
 
bool SetAccessibilityFeatures (int32_t flags)
 Forward the preference of accessibility features that must be enabled in the semantics tree to the running isolate. If the isolate is not running, this data will be saved and flushed to the isolate when it starts running.
 
bool BeginFrame (fml::TimePoint frame_time, uint64_t frame_number)
 Notifies the running isolate that it should start generating a new frame.
 
bool ReportTimings (std::vector< int64_t > timings)
 Dart code cannot fully measure the time it takes for a specific frame to be rendered. This is because Dart code only runs on the UI task runner. That is only a small part of the overall frame workload. The raster task runner frame workload is executed on a thread where Dart code cannot run (and hence instrument). Besides, due to the pipelined nature of rendering in Flutter, there may be multiple frame workloads being processed at any given time. However, for non-Timeline based profiling, it is useful for trace collection and processing to happen in Dart. To do this, the raster task runner frame workloads need to be instrumented separately. After a set number of these profiles have been gathered, they need to be reported back to Dart code. The engine reports this extra instrumentation information back to Dart code running on the engine by invoking this method at predefined intervals.
 
virtual bool NotifyIdle (fml::TimeDelta deadline)
 Notify the Dart VM that no frame workloads are expected on the UI task runner till the specified deadline. The VM uses this opportunity to perform garbage collection operations is a manner that interferes as little as possible with frame rendering.
 
virtual bool IsRootIsolateRunning () const
 Returns if the root isolate is running. The isolate must be transitioned to the running phase manually. The isolate can stop running if it terminates execution on its own.
 
virtual bool DispatchPlatformMessage (std::unique_ptr< PlatformMessage > message)
 Dispatch the specified platform message to running root isolate.
 
bool DispatchPointerDataPacket (const PointerDataPacket &packet)
 Dispatch the specified pointer data message to the running root isolate.
 
bool DispatchSemanticsAction (int64_t view_id, int32_t node_id, SemanticsAction action, fml::MallocMapping args)
 Dispatch the semantics action to the specified accessibility node.
 
Dart_Port GetMainPort ()
 Gets the main port identifier of the root isolate.
 
std::string GetIsolateName ()
 Gets the debug name of the root isolate. But default, the debug name of the isolate is derived from its advisory script URI, advisory main entrypoint and its main port name. For example, "main.dart$main-1234" where the script URI is "main.dart", the entrypoint is "main" and the port name "1234". Once launched, the isolate may re-christen itself using a name it selects via setIsolateDebugName in window.dart. This name is purely advisory and only used by instrumentation and reporting purposes.
 
bool HasLivePorts ()
 Returns if the root isolate has any live receive ports.
 
bool HasPendingMicrotasks ()
 Returns if the root isolate has any pending microtasks.
 
tonic::DartErrorHandleType GetLastError ()
 Get the last error encountered by the microtask queue.
 
std::optional< std::string > GetRootIsolateServiceID () const
 Get the service ID of the root isolate if the root isolate is running.
 
std::optional< uint32_t > GetRootIsolateReturnCode ()
 Get the return code specified by the root isolate (if one is present).
 
uint64_t GetRootIsolateGroup () const
 Get an identifier that represents the Dart isolate group the root isolate is in.
 
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, the Dart future returned by the originating loadLibrary() call completes.
 
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 id has failed.
 
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 deferred library identified by the specified loading unit id should be downloaded and loaded into the Dart VM via LoadDartDeferredLibrary
 
std::shared_ptr< const fml::MappingGetPersistentIsolateData () override
 The embedder can specify data that the isolate can request synchronously on launch. This accessor fetches that data.
 
void UpdateSemantics (int64_t view_id, SemanticsUpdate *update) override
 Receives an updated semantics tree from the Framework.
 
void SetApplicationLocale (std::string locale) override
 Framework sets the application locale.
 
void SetSemanticsTreeEnabled (bool enabled) override
 Notifies whether Framework starts generating semantics tree.
 
const fml::WeakPtr< IOManager > & GetIOManager () const
 
virtual DartVMGetDartVM () const
 
const fml::RefPtr< const DartSnapshot > & GetIsolateSnapshot () const
 
const PlatformDataGetPlatformData () const
 
const fml::RefPtr< SkiaUnrefQueue > & GetSkiaUnrefQueue () const
 
const fml::TaskRunnerAffineWeakPtr< SnapshotDelegate > & GetSnapshotDelegate () const
 
std::weak_ptr< const DartIsolateGetRootIsolate () const
 
void FlushMicrotaskQueue ()
 
std::shared_ptr< PlatformIsolateManagerGetPlatformIsolateManager () override
 
void SetRootIsolateOwnerToCurrentThread ()
 
void ShutdownPlatformIsolates ()
 Shuts down all registered platform isolates. Must be called from the platform thread.
 

Protected Member Functions

 RuntimeController (RuntimeDelegate &p_client, const TaskRunners &task_runners)
 Constructor for Mocks.
 
- Protected Member Functions inherited from flutter::PlatformConfigurationClient
virtual ~PlatformConfigurationClient ()
 

Detailed Description

Represents an instance of a running root isolate with window bindings. In normal operation, a single instance of this object is owned by the engine per shell. This object may only be created, used, and collected on the UI task runner. Window state queried by the root isolate is stored by this object. In cold-restart scenarios, the engine may collect this before installing a new runtime controller in its place. The Clone method may be used by the engine to copy the currently accumulated window state so it can be referenced by the new runtime controller.

When RuntimeController is created, it takes some time before the root isolate becomes ready. Operation during this gap is stored by RuntimeController and flushed to the Dart VM when the isolate becomes ready before the entrypoint function. See PlatformData.

Definition at line 50 of file runtime_controller.h.

Member Typedef Documentation

◆ AddViewCallback

using flutter::RuntimeController::AddViewCallback = std::function<void(bool added)>

A callback that's invoked after this RuntimeController attempts to add a view to the Dart isolate.

If the Dart isolate is not launched yet, this callback will be stored and invoked after the isolate is launched.

The added parameter is false if the add operation fails or was cancelled while pending using RemoveView.

Definition at line 61 of file runtime_controller.h.

Constructor & Destructor Documentation

◆ RuntimeController() [1/2]

flutter::RuntimeController::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 associated with the shell.

Parameters
clientThe runtime delegate. This is usually the Engine instance.
vmA reference to a running Dart VM. The runtime controller must be collected before the VM is destroyed (this order is guaranteed by the shell).
[in]idle_notification_callbackThe idle notification callback. This allows callers to run native code in isolate scope when the VM is about to be notified that the engine is going to be idle.
[in]platform_dataThe window data (if exists).
[in]isolate_create_callbackThe isolate create callback. This allows callers to run native code in isolate scope on the UI task runner as soon as the root isolate has been created.
[in]isolate_shutdown_callbackThe isolate shutdown callback. This allows callers to run native code in isolate scoped on the UI task runner just as the root isolate is about to be torn down.
[in]persistent_isolate_dataUnstructured persistent read-only data that the root isolate can access in a synchronous manner.
[in]contextEngine-owned state which is accessed by the root dart isolate.

Definition at line 29 of file runtime_controller.cc.

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) {}

◆ ~RuntimeController()

flutter::RuntimeController::~RuntimeController ( )
override

Definition at line 92 of file runtime_controller.cc.

92 {
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}
#define FML_DLOG(severity)
Definition logging.h:121
#define FML_DCHECK(condition)
Definition logging.h:122

References FML_DCHECK, and FML_DLOG.

◆ RuntimeController() [2/2]

flutter::RuntimeController::RuntimeController ( RuntimeDelegate p_client,
const TaskRunners task_runners 
)
protected

Constructor for Mocks.

Definition at line 22 of file runtime_controller.cc.

24 : client_(p_client),
25 vm_(nullptr),
26 context_(task_runners),
27 pointer_data_packet_converter_(*this) {}

Member Function Documentation

◆ AddView()

void flutter::RuntimeController::AddView ( int64_t  view_id,
const ViewportMetrics view_metrics,
AddViewCallback  callback 
)

Notify the isolate that a new view is available.

        A view must be added before other methods can refer to it,
        including the implicit view. Adding a view that already exists
        is an error.

        The `callback` is invoked when the add operation is attempted,
        failed, or is cancelled.

        If the isolate is not running, the view add will be queued and
        flushed to the isolate when it starts. Calling `RemoveView`
        before the isolate is launched cancels the add operation.

        If the isolate is running, a frame will be scheduled.
Parameters
[in]view_idThe ID of the new view.
[in]viewport_metricsThe initial viewport metrics for the view.
[in]callbackCallback that will be invoked after the add operation is attempted or cancelled.

Definition at line 163 of file runtime_controller.cc.

165 {
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}
G_BEGIN_DECLS FlutterViewId view_id
FlutterDesktopBinaryReply callback
#define FML_LOG(severity)
Definition logging.h:101
std::unordered_map< int64_t, ViewportMetrics > viewport_metrics_for_views

References callback, FML_DCHECK, FML_LOG, view_id, and flutter::PlatformData::viewport_metrics_for_views.

◆ BeginFrame()

bool flutter::RuntimeController::BeginFrame ( fml::TimePoint  frame_time,
uint64_t  frame_number 
)

Notifies the running isolate that it should start generating a new frame.

See also
Engine::BeginFrame for more context.
Parameters
[in]frame_timeThe point at which the current frame interval began. May be used by animation interpolators, physics simulations, etc.
Returns
If notification to begin frame rendering was delivered to the running isolate.

Definition at line 299 of file runtime_controller.cc.

300 {
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}

◆ Clone()

std::unique_ptr< RuntimeController > flutter::RuntimeController::Clone ( ) const

Clone the runtime controller. Launching an isolate with a cloned runtime controller will use the same snapshots and copies all window data to the new instance. This is usually only used in the debug runtime mode to support the cold-restart scenario.

Returns
A clone of the existing runtime controller.

Definition at line 113 of file runtime_controller.cc.

113 {
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}

◆ DispatchPlatformMessage()

bool flutter::RuntimeController::DispatchPlatformMessage ( std::unique_ptr< PlatformMessage message)
virtual

Dispatch the specified platform message to running root isolate.

Parameters
[in]messageThe message to dispatch to the isolate.
Returns
If the message was dispatched to the running root isolate. This may fail is an isolate is not running.

Definition at line 351 of file runtime_controller.cc.

352 {
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}
G_BEGIN_DECLS GBytes * message
#define TRACE_EVENT0(category_group, name)

References message, and TRACE_EVENT0.

◆ DispatchPointerDataPacket()

bool flutter::RuntimeController::DispatchPointerDataPacket ( const PointerDataPacket packet)

Dispatch the specified pointer data message to the running root isolate.

Parameters
[in]packetThe pointer data message to dispatch to the isolate.
Returns
If the pointer data message was dispatched. This may fail is an isolate is not running.

Definition at line 362 of file runtime_controller.cc.

363 {
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}
std::unique_ptr< PointerDataPacket > Convert(const PointerDataPacket &packet)
Converts pointer data packet into a form that framework understands. The raw pointer data packet from...

References flutter::PointerDataPacketConverter::Convert(), and TRACE_EVENT0.

◆ DispatchSemanticsAction()

bool flutter::RuntimeController::DispatchSemanticsAction ( int64_t  view_id,
int32_t  node_id,
SemanticsAction  action,
fml::MallocMapping  args 
)

Dispatch the semantics action to the specified accessibility node.

Parameters
[in]view_idThe identifier of the view.
[in]node_idThe identifier of the accessibility node.
[in]actionThe semantics action to perform on the specified accessibility node.
[in]argsOptional data that applies to the specified action.
Returns
If the semantics action was dispatched. This may fail if an isolate is not running.

Definition at line 377 of file runtime_controller.cc.

380 {
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}
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
#define TRACE_EVENT1(category_group, name, arg1_name, arg1_val)

References action, args, TRACE_EVENT1, and view_id.

◆ FlushMicrotaskQueue()

void flutter::RuntimeController::FlushMicrotaskQueue ( )
inline

Definition at line 670 of file runtime_controller.h.

670 {
671 if (auto isolate = root_isolate_.lock()) {
672 isolate->FlushMicrotasksNow();
673 }
674 }

◆ GetDartVM()

virtual DartVM * flutter::RuntimeController::GetDartVM ( ) const
inlinevirtual

Definition at line 649 of file runtime_controller.h.

649{ return vm_; }

◆ GetIOManager()

const fml::WeakPtr< IOManager > & flutter::RuntimeController::GetIOManager ( ) const
inline

Definition at line 645 of file runtime_controller.h.

645 {
646 return context_.io_manager;
647 }
fml::WeakPtr< IOManager > io_manager
The IO manager used by the isolate for asynchronous texture uploads.

References flutter::UIDartState::Context::io_manager.

◆ GetIsolateName()

std::string flutter::RuntimeController::GetIsolateName ( )

Gets the debug name of the root isolate. But default, the debug name of the isolate is derived from its advisory script URI, advisory main entrypoint and its main port name. For example, "main.dart$main-1234" where the script URI is "main.dart", the entrypoint is "main" and the port name "1234". Once launched, the isolate may re-christen itself using a name it selects via setIsolateDebugName in window.dart. This name is purely advisory and only used by instrumentation and reporting purposes.

Returns
The debug name of the root isolate.

Definition at line 507 of file runtime_controller.cc.

507 {
508 std::shared_ptr<DartIsolate> root_isolate = root_isolate_.lock();
509 return root_isolate ? root_isolate->debug_name() : "";
510}

◆ GetIsolateSnapshot()

const fml::RefPtr< const DartSnapshot > & flutter::RuntimeController::GetIsolateSnapshot ( ) const
inline

Definition at line 651 of file runtime_controller.h.

651 {
652 return isolate_snapshot_;
653 }

◆ GetLastError()

tonic::DartErrorHandleType flutter::RuntimeController::GetLastError ( )

Get the last error encountered by the microtask queue.

Returns
The last error encountered by the microtask queue.

Definition at line 529 of file runtime_controller.cc.

529 {
530 std::shared_ptr<DartIsolate> root_isolate = root_isolate_.lock();
531 return root_isolate ? root_isolate->GetLastError() : tonic::kNoError;
532}
@ kNoError
Definition dart_error.h:68

References tonic::kNoError.

◆ GetMainPort()

Dart_Port flutter::RuntimeController::GetMainPort ( )

Gets the main port identifier of the root isolate.

Returns
The main port identifier. If no root isolate is running, returns ILLEGAL_PORT.

Definition at line 502 of file runtime_controller.cc.

502 {
503 std::shared_ptr<DartIsolate> root_isolate = root_isolate_.lock();
504 return root_isolate ? root_isolate->main_port() : ILLEGAL_PORT;
505}

◆ GetPersistentIsolateData()

std::shared_ptr< const fml::Mapping > flutter::RuntimeController::GetPersistentIsolateData ( )
overridevirtual

The embedder can specify data that the isolate can request synchronously on launch. This accessor fetches that data.

This data is persistent for the duration of the Flutter application and is available even after isolate restarts. Because of this lifecycle, the size of this data must be kept to a minimum.

For asynchronous communication between the embedder and isolate, a platform channel may be used.

Returns
A map of the isolate data that the framework can request upon launch.

Implements flutter::PlatformConfigurationClient.

Definition at line 486 of file runtime_controller.cc.

486 {
487 return persistent_isolate_data_;
488}

◆ GetPlatformData()

const PlatformData & flutter::RuntimeController::GetPlatformData ( ) const
inline

Definition at line 655 of file runtime_controller.h.

655{ return platform_data_; }

◆ GetPlatformIsolateManager()

std::shared_ptr< PlatformIsolateManager > flutter::RuntimeController::GetPlatformIsolateManager ( )
inlineoverridevirtual

Implements flutter::PlatformConfigurationClient.

Definition at line 676 of file runtime_controller.h.

676 {
677 return platform_isolate_manager_;
678 }

◆ GetRootIsolate()

std::weak_ptr< const DartIsolate > flutter::RuntimeController::GetRootIsolate ( ) const
inline

Definition at line 666 of file runtime_controller.h.

666 {
667 return root_isolate_;
668 }

◆ GetRootIsolateGroup()

uint64_t flutter::RuntimeController::GetRootIsolateGroup ( ) const

Get an identifier that represents the Dart isolate group the root isolate is in.

Returns
The root isolate group identifier, zero if one can't be established.

Definition at line 618 of file runtime_controller.cc.

618 {
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}

◆ GetRootIsolateReturnCode()

std::optional< uint32_t > flutter::RuntimeController::GetRootIsolateReturnCode ( )

Get the return code specified by the root isolate (if one is present).

Returns
The root isolate return code if the isolate has specified one.

Definition at line 614 of file runtime_controller.cc.

614 {
615 return root_isolate_return_code_;
616}

◆ GetRootIsolateServiceID()

std::optional< std::string > flutter::RuntimeController::GetRootIsolateServiceID ( ) const

Get the service ID of the root isolate if the root isolate is running.

Returns
The root isolate service id.

Definition at line 607 of file runtime_controller.cc.

607 {
608 if (auto isolate = root_isolate_.lock()) {
609 return isolate->GetServiceId();
610 }
611 return std::nullopt;
612}

◆ GetSkiaUnrefQueue()

const fml::RefPtr< SkiaUnrefQueue > & flutter::RuntimeController::GetSkiaUnrefQueue ( ) const
inline

Definition at line 657 of file runtime_controller.h.

657 {
658 return context_.unref_queue;
659 }
fml::RefPtr< SkiaUnrefQueue > unref_queue

References flutter::UIDartState::Context::unref_queue.

◆ GetSnapshotDelegate()

const fml::TaskRunnerAffineWeakPtr< SnapshotDelegate > & flutter::RuntimeController::GetSnapshotDelegate ( ) const
inline

Definition at line 661 of file runtime_controller.h.

662 {
663 return context_.snapshot_delegate;
664 }
fml::TaskRunnerAffineWeakPtr< SnapshotDelegate > snapshot_delegate

References flutter::UIDartState::Context::snapshot_delegate.

◆ HasLivePorts()

bool flutter::RuntimeController::HasLivePorts ( )

Returns if the root isolate has any live receive ports.

Returns
True if there are live receive ports, False otherwise. Return False if the root isolate is not running as well.

Definition at line 512 of file runtime_controller.cc.

512 {
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}

◆ HasPendingMicrotasks()

bool flutter::RuntimeController::HasPendingMicrotasks ( )

Returns if the root isolate has any pending microtasks.

Returns
True if there are microtasks that have been queued but not run, False otherwise. Return False if the root isolate is not running as well.

Definition at line 521 of file runtime_controller.cc.

521 {
522 std::shared_ptr<DartIsolate> root_isolate = root_isolate_.lock();
523 if (!root_isolate) {
524 return false;
525 }
526 return root_isolate->HasPendingMicrotasks();
527}

◆ IsRootIsolateRunning()

bool flutter::RuntimeController::IsRootIsolateRunning ( ) const
virtual

Returns if the root isolate is running. The isolate must be transitioned to the running phase manually. The isolate can stop running if it terminates execution on its own.

Returns
True if root isolate running, False otherwise.

Definition at line 105 of file runtime_controller.cc.

105 {
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}

References flutter::DartIsolate::Running.

◆ LaunchRootIsolate()

bool flutter::RuntimeController::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. Before this call, the Dart isolate has not been initialized. On successful return, the caller can assume that the isolate is in the DartIsolate::Phase::Running phase.

This call will fail if a root isolate is already running. To re-create an isolate with the window data associated with this runtime controller, Clone this runtime controller and Launch an isolate in that runtime controller instead.

Parameters
[in]settingsThe per engine instance settings.
[in]root_isolate_create_callbackA callback invoked before the root isolate has launched the Dart program, but after it has been created. This is called without isolate scope, and after any root isolate callback in the settings.
[in]dart_entrypointThe dart entrypoint. If std::nullopt or empty, main will be attempted.
[in]dart_entrypoint_libraryThe dart entrypoint library. If std::nullopt or empty, the core library will be attempted.
[in]dart_entrypoint_argsArguments passed as a List<String> to Dart's entrypoint function.
[in]isolate_configurationThe isolate configuration
[in]engine_id.Engine identifier to be passed to the platform dispatcher.
Returns
If the isolate could be launched and guided to the DartIsolate::Phase::Running phase.

Definition at line 534 of file runtime_controller.cc.

542 {
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), //
553 DartIsolate::Flags{}, //
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}
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...
virtual std::weak_ptr< PlatformMessageHandler > GetPlatformMessageHandler() const =0
virtual void OnRootIsolateCreated()=0

References flutter::DartIsolate::CreateRunningRootIsolate(), FML_DCHECK, FML_DLOG, FML_LOG, flutter::RuntimeDelegate::GetPlatformMessageHandler(), and flutter::RuntimeDelegate::OnRootIsolateCreated().

◆ LoadDartDeferredLibrary()

void flutter::RuntimeController::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, the Dart future returned by the originating loadLibrary() call completes.

The Dart compiler may generate separate shared libraries files called 'loading units' when libraries are imported as deferred. Each of these shared libraries are identified by a unique loading unit id. Callers should open and resolve a SymbolMapping from the shared library. The Mappings should be moved into this method, as ownership will be assumed by the dart root isolate after successful loading and released after shutdown of the root isolate. The loading unit may not be used after isolate shutdown. If loading fails, the mappings will be released.

This method is paired with a RequestDartDeferredLibrary invocation that provides the embedder with the loading unit id of the deferred library to load.

Parameters
[in]loading_unit_idThe unique id of the deferred library's loading unit, as passed in by RequestDartDeferredLibrary.
[in]snapshot_dataDart snapshot data of the loading unit's shared library.
[in]snapshot_dataDart snapshot instructions of the loading unit's shared library.

Definition at line 629 of file runtime_controller.cc.

632 {
633 root_isolate_.lock()->LoadLoadingUnit(loading_unit_id,
634 std::move(snapshot_data),
635 std::move(snapshot_instructions));
636}

◆ LoadDartDeferredLibraryError()

void flutter::RuntimeController::LoadDartDeferredLibraryError ( intptr_t  loading_unit_id,
const std::string  error_message,
bool  transient 
)
virtual

Indicates to the dart VM that the request to load a deferred library with the specified loading unit id has failed.

The dart future returned by the initiating loadLibrary() call will complete with an error.

Parameters
[in]loading_unit_idThe unique id of the deferred library's loading unit, as passed in by RequestDartDeferredLibrary.
[in]error_messageThe error message that will appear in the dart Future.
[in]transientA transient error is a failure due to temporary conditions such as no network. Transient errors allow the dart VM to re-request the same deferred library and loading_unit_id again. Non-transient errors are permanent and attempts to re-request the library will instantly complete with an error.

Definition at line 638 of file runtime_controller.cc.

642 {
643 root_isolate_.lock()->LoadLoadingUnitError(loading_unit_id, error_message,
644 transient);
645}

◆ NotifyIdle()

bool flutter::RuntimeController::NotifyIdle ( fml::TimeDelta  deadline)
virtual

Notify the Dart VM that no frame workloads are expected on the UI task runner till the specified deadline. The VM uses this opportunity to perform garbage collection operations is a manner that interferes as little as possible with frame rendering.

NotifyIdle is advisory. The VM may or may not run a garbage collection when this is called, and will eventually perform garbage collections even if it is not called or it is called with insufficient deadlines.

The garbage collection mechanism and its thresholds are internal implementation details and absolutely no guarantees are made about the threshold discussed below. This discussion is also an oversimplification but hopefully serves to calibrate expectations about GC behavior:

  • When the Dart VM and its root isolate are initialized, the memory consumed upto that point are treated as a baseline.
  • A fixed percentage of the memory consumed (~20%) over the baseline is treated as the hard threshold.
  • The memory in play is divided into old space and new space. The new space is typically very small and fills up rapidly.
  • The baseline plus the threshold is considered the old space while the small new space is a separate region (typically a few pages).
  • The total old space size minus the max new space size is treated as the soft threshold.
  • In a world where there is no call to NotifyIdle, when the total allocation exceeds the soft threshold, a concurrent mark is initiated in the VM. There is a “small” pause that occurs when the concurrent mark is initiated and another pause when the mark concludes and a sweep is initiated.
  • If the total allocations exceeds the hard threshold, a “big” stop-the-world pause is initiated.
  • If after either the sweep after the concurrent mark, or, the stop-the-world pause, the consumption returns to be below the soft threshold, the dance begins anew.
  • If after both the “small” and “big” pauses, memory usage is still over the hard threshold, i.e, the objects are still reachable, that amount of memory is treated as the new baseline and a fixed percentage of the new baseline over the new baseline is now the new hard threshold.
  • Updating the baseline will continue till memory for the updated old space can be allocated from the operating system. These allocations will typically fail due to address space exhaustion on 32-bit systems and page table exhaustion on 64-bit systems.
  • NotifyIdle initiates the concurrent mark preemptively. The deadline is used by the VM to determine if the corresponding sweep can be performed within the deadline. This way, jank due to “small” pauses can be ameliorated.
  • There is no ability to stop a “big” pause on reaching the hard threshold in the old space. The best you can do is release (by making them unreachable) objects eagerly so that the are marked as unreachable in the concurrent mark initiated by either reaching the soft threshold or an explicit NotifyIdle.
  • If you are running out of memory, its because too many large objects were allocation and remained reachable such that the old space kept growing till it could grow no more.
  • At the edges of allocation thresholds, failures can occur gracefully if the instigating allocation was made in the Dart VM or rather gracelessly if the allocation is made by some native component.
See also
Dart_TimelineGetMicros
Parameters
[in]deadlineThe deadline is used by the VM to determine if the corresponding sweep can be performed within the deadline.
Returns
If the idle notification was forwarded to the running isolate.

Definition at line 319 of file runtime_controller.cc.

319 {
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}
static Dart_PerformanceMode GetDartPerformanceMode()
Returns the current performance mode of the Dart VM. Defaults to Dart_PerformanceMode_Default if no p...
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

References fml::TimeDelta::FromMicroseconds(), fml::TimeDelta::FromMilliseconds(), flutter::PlatformConfigurationNativeApi::GetDartPerformanceMode(), fml::TimeDelta::ToMicroseconds(), and TRACE_EVENT0.

Referenced by flutter::testing::TEST_F().

◆ RemoveView()

bool flutter::RuntimeController::RemoveView ( int64_t  view_id)

Notify the isolate that a view is no longer available.

        Views that are added before the isolate is started are
        queued until the isolate is launched. If one of these
        "pending" views are removed, the view add is cancelled:
        the `AddViewCallback` will be invoked with an `added` of
        false and `RemoveView` will return false.

        The implicit view (kFlutterImplicitViewId) should never be
        removed. Doing so triggers an assertion.
Parameters
[in]view_idThe ID of the view.
Returns
If the remove view operation was forwarded to the running isolate. False if the view does not exist. If the Dart isolate is not running, then the pending view creation (if any) is cancelled and the return value is always false.

Definition at line 195 of file runtime_controller.cc.

195 {
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}

References FML_DCHECK, view_id, and flutter::PlatformData::viewport_metrics_for_views.

◆ ReportTimings()

bool flutter::RuntimeController::ReportTimings ( std::vector< int64_t >  timings)

Dart code cannot fully measure the time it takes for a specific frame to be rendered. This is because Dart code only runs on the UI task runner. That is only a small part of the overall frame workload. The raster task runner frame workload is executed on a thread where Dart code cannot run (and hence instrument). Besides, due to the pipelined nature of rendering in Flutter, there may be multiple frame workloads being processed at any given time. However, for non-Timeline based profiling, it is useful for trace collection and processing to happen in Dart. To do this, the raster task runner frame workloads need to be instrumented separately. After a set number of these profiles have been gathered, they need to be reported back to Dart code. The engine reports this extra instrumentation information back to Dart code running on the engine by invoking this method at predefined intervals.

See also
Engine::ReportTimings, FrameTiming
Parameters
[in]timingsCollection of FrameTiming::kCount * n timestamps for n frames whose timings have not been reported yet. A collection of integers is reported here for easier conversions to Dart objects. The timestamps are measured against the system monotonic clock measured in microseconds.

Definition at line 310 of file runtime_controller.cc.

310 {
311 if (auto* platform_configuration = GetPlatformConfigurationIfAvailable()) {
312 platform_configuration->ReportTimings(std::move(timings));
313 return true;
314 }
315
316 return false;
317}

◆ RequestDartDeferredLibrary()

void flutter::RuntimeController::RequestDartDeferredLibrary ( intptr_t  loading_unit_id)
overridevirtual

Invoked when the Dart VM requests that a deferred library be loaded. Notifies the engine that the deferred library identified by the specified loading unit id should be downloaded and loaded into the Dart VM via LoadDartDeferredLibrary

Upon encountering errors or otherwise failing to load a loading unit with the specified id, the failure should be directly reported to dart by calling LoadDartDeferredLibraryFailure to ensure the waiting dart future completes with an error.

Parameters
[in]loading_unit_idThe unique id of the deferred library's loading unit. This id is to be passed back into LoadDartDeferredLibrary in order to identify which deferred library to load.

Implements flutter::PlatformConfigurationClient.

Definition at line 647 of file runtime_controller.cc.

647 {
648 return client_.RequestDartDeferredLibrary(loading_unit_id);
649}
virtual void RequestDartDeferredLibrary(intptr_t loading_unit_id)=0

References flutter::RuntimeDelegate::RequestDartDeferredLibrary().

◆ SendViewFocusEvent()

bool flutter::RuntimeController::SendViewFocusEvent ( const ViewFocusEvent event)

Notify the isolate that the focus state of a native view has changed.

Parameters
[in]eventThe focus event describing the change.

Definition at line 216 of file runtime_controller.cc.

216 {
217 auto* platform_configuration = GetPlatformConfigurationIfAvailable();
218 if (!platform_configuration) {
219 return false;
220 }
221 return platform_configuration->SendFocusEvent(event);
222}

◆ SetAccessibilityFeatures()

bool flutter::RuntimeController::SetAccessibilityFeatures ( int32_t  flags)

Forward the preference of accessibility features that must be enabled in the semantics tree to the running isolate. If the isolate is not running, this data will be saved and flushed to the isolate when it starts running.

Parameters
[in]flagsThe accessibility features that must be generated in the semantics tree.
Returns
If the preference of accessibility features was forwarded to the running isolate.

Definition at line 288 of file runtime_controller.cc.

288 {
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}
int32_t accessibility_feature_flags_

References flutter::PlatformData::accessibility_feature_flags_.

◆ SetApplicationLocale()

void flutter::RuntimeController::SetApplicationLocale ( std::string  locale)
overridevirtual

Framework sets the application locale.

Parameters
[in]localeThe application locale in BCP 47 format.

Implements flutter::PlatformConfigurationClient.

Definition at line 448 of file runtime_controller.cc.

448 {
449 client_.SetApplicationLocale(std::move(locale));
450}
virtual void SetApplicationLocale(std::string locale)=0

References flutter::RuntimeDelegate::SetApplicationLocale().

Referenced by flutter::testing::RuntimeControllerTester::CanUpdateSetApplicationLocale().

◆ SetDisplays()

bool flutter::RuntimeController::SetDisplays ( const std::vector< DisplayData > &  displays)

Forward the specified display metrics to the running isolate. If the isolate is not running, these metrics will be saved and flushed to the isolate when it starts.

Parameters
[in]displaysThe available displays.

Definition at line 651 of file runtime_controller.cc.

651 {
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}
std::vector< FlutterEngineDisplay > * displays
std::vector< DisplayData > displays

References flutter::PlatformData::displays, displays, and TRACE_EVENT0.

◆ SetInitialLifecycleState()

bool flutter::RuntimeController::SetInitialLifecycleState ( const std::string &  data)

Forward the initial lifecycle state data to the running isolate. If the isolate is not running, this data will be saved and flushed to the isolate when it starts running. After the isolate starts running, the current lifecycle state is pushed to it via the "flutter/lifecycle" channel.

Parameters
[in]dataThe lifecycle state data.
Returns
If the lifecycle state data was forwarded to the running isolate.

Definition at line 264 of file runtime_controller.cc.

264 {
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}
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::string lifecycle_state

References flutter::data, and flutter::PlatformData::lifecycle_state.

◆ SetLocales()

bool flutter::RuntimeController::SetLocales ( const std::vector< std::string > &  locale_data)

Forward the specified locale data to the running isolate. If the isolate is not running, this data will be saved and flushed to the isolate when it starts running.

Parameters
[in]locale_dataThe locale data. This should consist of groups of 4 strings, each group representing a single locale.
Returns
If the locale data was forwarded to the running isolate.

Definition at line 240 of file runtime_controller.cc.

241 {
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}
std::vector< std::string > locale_data

References flutter::PlatformData::locale_data.

◆ SetRootIsolateOwnerToCurrentThread()

void flutter::RuntimeController::SetRootIsolateOwnerToCurrentThread ( )

Definition at line 676 of file runtime_controller.cc.

676 {
677 std::shared_ptr<DartIsolate> root_isolate = root_isolate_.lock();
678 if (root_isolate) {
679 root_isolate->SetOwnerToCurrentThread();
680 }
681}

◆ SetSemanticsEnabled()

bool flutter::RuntimeController::SetSemanticsEnabled ( bool  enabled)

Notifies the running isolate about whether the semantics tree should be generated or not. If the isolate is not running, this preference will be saved and flushed to the isolate when it starts running.

Parameters
[in]enabledIndicates whether to generate the semantics tree.
Returns
If the semantics tree generation preference was forwarded to the running isolate.

Definition at line 276 of file runtime_controller.cc.

276 {
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}

References flutter::PlatformData::semantics_enabled.

◆ SetSemanticsTreeEnabled()

void flutter::RuntimeController::SetSemanticsTreeEnabled ( bool  enabled)
overridevirtual

Notifies whether Framework starts generating semantics tree.

Parameters
[in]enabledTrue if Framework starts generating semantics tree.

Implements flutter::PlatformConfigurationClient.

Definition at line 453 of file runtime_controller.cc.

453 {
454 client_.SetSemanticsTreeEnabled(enabled);
455}
virtual void SetSemanticsTreeEnabled(bool enabled)=0

References flutter::RuntimeDelegate::SetSemanticsTreeEnabled().

Referenced by flutter::testing::RuntimeControllerTester::CanUpdateSemanticsWhenSetSemanticsTreeEnabled().

◆ SetUserSettingsData()

bool flutter::RuntimeController::SetUserSettingsData ( const std::string &  data)

Forward the user settings data to the running isolate. If the isolate is not running, this data will be saved and flushed to the isolate when it starts running.

Parameters
[in]dataThe user settings data.
Returns
If the user settings data was forwarded to the running isolate.

Definition at line 252 of file runtime_controller.cc.

252 {
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}
std::string user_settings_data

References flutter::data, and flutter::PlatformData::user_settings_data.

◆ SetViewportMetrics()

bool flutter::RuntimeController::SetViewportMetrics ( int64_t  view_id,
const ViewportMetrics metrics 
)

Forward the specified viewport metrics to the running isolate. If the isolate is not running, these metrics will be saved and flushed to the isolate when it starts.

Parameters
[in]view_idThe ID for the view that metrics describes.
[in]metricsThe window's viewport metrics.
Returns
If the window metrics were forwarded to the running isolate.

Definition at line 228 of file runtime_controller.cc.

229 {
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}

References TRACE_EVENT0, view_id, and flutter::PlatformData::viewport_metrics_for_views.

◆ ShutdownPlatformIsolates()

void flutter::RuntimeController::ShutdownPlatformIsolates ( )

Shuts down all registered platform isolates. Must be called from the platform thread.

Definition at line 672 of file runtime_controller.cc.

672 {
673 platform_isolate_manager_->ShutdownPlatformIsolates();
674}

◆ Spawn()

std::unique_ptr< RuntimeController > flutter::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 RuntimeController such that together they occupy less memory.

Returns
A RuntimeController with a running isolate.
See also
RuntimeController::RuntimeController

Definition at line 50 of file runtime_controller.cc.

62 {
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}
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.

References flutter::UIDartState::Context::concurrent_task_runner, flutter::UIDartState::Context::deterministic_rendering_enabled, flutter::UIDartState::Context::enable_flutter_gpu, flutter::UIDartState::Context::enable_impeller, flutter::UIDartState::Context::runtime_stage_backend, flutter::UIDartState::Context::task_runners, and flutter::UIDartState::Context::unref_queue.

◆ UpdateSemantics()

void flutter::RuntimeController::UpdateSemantics ( int64_t  viewId,
SemanticsUpdate update 
)
overridevirtual

Receives an updated semantics tree from the Framework.

Parameters
[in]viewIdThe identifier of the view to update.
[in]updateThe updated semantic tree to apply.

Implements flutter::PlatformConfigurationClient.

Definition at line 442 of file runtime_controller.cc.

443 {
444 client_.UpdateSemantics(view_id, update->takeNodes(), update->takeActions());
445}
virtual void UpdateSemantics(int64_t view_id, SemanticsNodeUpdates update, CustomAccessibilityActionUpdates actions)=0

References flutter::SemanticsUpdate::takeActions(), flutter::SemanticsUpdate::takeNodes(), flutter::RuntimeDelegate::UpdateSemantics(), and view_id.

Referenced by flutter::testing::RuntimeControllerTester::CanUpdateSemanticsWhenSetSemanticsTreeEnabled().


The documentation for this class was generated from the following files: