Flutter Engine
The Flutter Engine
Classes | Public Types | Public Member Functions | Protected Member Functions | List of all members
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. More...
 
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::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 RuntimeController such that together they occupy less memory. More...
 
 ~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)
 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. More...
 
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. More...
 
void AddView (int64_t view_id, const ViewportMetrics &view_metrics, AddViewCallback callback)
 Notify the isolate that a new view is available. More...
 
bool RemoveView (int64_t view_id)
 Notify the isolate that a view is no longer available. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
bool BeginFrame (fml::TimePoint frame_time, uint64_t frame_number)
 Notifies the running isolate that it should start generating a new frame. More...
 
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. More...
 
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. More...
 
virtual bool NotifyDestroyed ()
 Notify the Dart VM that the attached flutter view has been destroyed. This gives the Dart VM to perform some cleanup activities e.g: perform garbage collection to free up any unused memory. More...
 
virtual bool IsRootIsolateRunning ()
 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. More...
 
virtual bool DispatchPlatformMessage (std::unique_ptr< PlatformMessage > message)
 Dispatch the specified platform message to running root isolate. More...
 
bool DispatchPointerDataPacket (const PointerDataPacket &packet)
 Dispatch the specified pointer data message to the running root isolate. More...
 
bool DispatchSemanticsAction (int32_t node_id, SemanticsAction action, fml::MallocMapping args)
 Dispatch the semantics action to the specified accessibility node. More...
 
Dart_Port GetMainPort ()
 Gets the main port identifier of the root isolate. More...
 
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. More...
 
bool HasLivePorts ()
 Returns if the root isolate has any live receive ports. More...
 
tonic::DartErrorHandleType GetLastError ()
 Get the last error encountered by the microtask queue. More...
 
std::optional< std::string > GetRootIsolateServiceID () const
 Get the service ID of the root isolate if the root isolate is running. More...
 
std::optional< uint32_t > GetRootIsolateReturnCode ()
 Get the return code specified by the root isolate (if one is present). More...
 
uint64_t GetRootIsolateGroup () const
 Get an identifier that represents the Dart isolate group the root isolate is in. More...
 
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. More...
 
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. More...
 
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 More...
 
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. More...
 
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
 
std::shared_ptr< PlatformIsolateManagerGetPlatformIsolateManager () override
 
void ShutdownPlatformIsolates ()
 Shuts down all registered platform isolates. Must be called from the platform thread. More...
 
virtual std::string DefaultRouteName ()=0
 The route or path that the embedder requested when the application was launched. More...
 
virtual void ScheduleFrame ()=0
 Requests that, at the next appropriate opportunity, a new frame be scheduled for rendering. More...
 
virtual void EndWarmUpFrame ()=0
 Called when a warm up frame has ended. More...
 
virtual void Render (int64_t view_id, Scene *scene, double width, double height)=0
 Updates the client's rendering on the GPU with the newly provided Scene. More...
 
virtual void UpdateSemantics (SemanticsUpdate *update)=0
 Receives an updated semantics tree from the Framework. More...
 
virtual void HandlePlatformMessage (std::unique_ptr< PlatformMessage > message)=0
 When the Flutter application has a message to send to the underlying platform, the message needs to be forwarded to the platform on the appropriate thread (via the platform task runner). The PlatformConfiguration delegates this task to the engine via this method. More...
 
virtual FontCollectionGetFontCollection ()=0
 Returns the current collection of fonts available on the platform. More...
 
virtual std::shared_ptr< AssetManagerGetAssetManager ()=0
 Returns the current collection of assets available on the platform. More...
 
virtual void UpdateIsolateDescription (const std::string isolate_name, int64_t isolate_port)=0
 Notifies this client of the name of the root isolate and its port when that isolate is launched, restarted (in the cold-restart scenario) or the application itself updates the name of the root isolate (via Window.setIsolateDebugName in window.dart). The name of the isolate is meaningless to the engine but is used in instrumentation and tooling. Currently, this information is to update the service protocol list of available root isolates running in the VM and their names so that the appropriate isolate can be selected in the tools for debugging and instrumentation. More...
 
virtual void SetNeedsReportTimings (bool value)=0
 Notifies this client that the application has an opinion about whether its frame timings need to be reported backed to it. Due to the asynchronous nature of rendering in Flutter, it is not possible for the application to determine the total time it took to render a specific frame. While the layer-tree is constructed on the UI thread, it needs to be rendering on the raster thread. Dart code cannot execute on this thread. So any instrumentation about the frame times gathered on this thread needs to be aggregated and sent back to the UI thread for processing in Dart. More...
 
virtual std::shared_ptr< const fml::MappingGetPersistentIsolateData ()=0
 The embedder can specify data that the isolate can request synchronously on launch. This accessor fetches that data. More...
 
virtual std::unique_ptr< std::vector< std::string > > ComputePlatformResolvedLocale (const std::vector< std::string > &supported_locale_data)=0
 Directly invokes platform-specific APIs to compute the locale the platform would have natively resolved to. More...
 
virtual void RequestDartDeferredLibrary (intptr_t loading_unit_id)=0
 Invoked when the Dart VM requests that a deferred library be loaded. Notifies the engine that the deferred library identified by the specified loading unit id should be downloaded and loaded into the Dart VM via LoadDartDeferredLibrary More...
 
virtual void SendChannelUpdate (std::string name, bool listening)=0
 Invoked when a listener is registered on a platform channel. More...
 
virtual double GetScaledFontSize (double unscaled_font_size, int configuration_id) const =0
 Synchronously invokes platform-specific APIs to apply the system text scaling on the given unscaled font size. More...
 
virtual std::shared_ptr< PlatformIsolateManagerGetPlatformIsolateManager ()=0
 

Protected Member Functions

 RuntimeController (RuntimeDelegate &p_client, const TaskRunners &task_runners)
 Constructor for Mocks. More...
 
- 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 52 of file runtime_controller.h.

Member Typedef Documentation

◆ AddViewCallback

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 63 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 31 of file runtime_controller.cc.

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

◆ ~RuntimeController()

flutter::RuntimeController::~RuntimeController ( )
override

Definition at line 90 of file runtime_controller.cc.

90 {
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}
DART_EXPORT Dart_Isolate Dart_CurrentIsolate(void)
GAsyncResult * result
#define FML_DLOG(severity)
Definition: logging.h:102
#define FML_DCHECK(condition)
Definition: logging.h:103
#define ERROR(message)
Definition: elf_loader.cc:260

◆ RuntimeController() [2/2]

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

Constructor for Mocks.

Definition at line 24 of file runtime_controller.cc.

26 : client_(p_client),
27 vm_(nullptr),
28 context_(task_runners),
29 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 161 of file runtime_controller.cc.

163 {
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}
FlKeyEvent uint64_t FlKeyResponderAsyncCallback callback
#define FML_LOG(severity)
Definition: logging.h:82
std::unordered_map< int64_t, ViewportMetrics > viewport_metrics_for_views
Definition: platform_data.h:36

◆ 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 289 of file runtime_controller.cc.

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

◆ 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 111 of file runtime_controller.cc.

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

◆ 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 354 of file runtime_controller.cc.

355 {
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}
Win32Message message
#define TRACE_EVENT0(category_group, name)
Definition: trace_event.h:131

◆ 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 365 of file runtime_controller.cc.

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

◆ DispatchSemanticsAction()

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

Dispatch the semantics action to the specified accessibility node.

Parameters
[in]node_idThe identified 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 380 of file runtime_controller.cc.

382 {
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}
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
#define TRACE_EVENT1(category_group, name, arg1_name, arg1_val)
Definition: trace_event.h:141

◆ GetDartVM()

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

Definition at line 630 of file runtime_controller.h.

630{ return vm_; }

◆ GetIOManager()

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

Definition at line 626 of file runtime_controller.h.

626 {
627 return context_.io_manager;
628 }
fml::WeakPtr< IOManager > io_manager
The IO manager used by the isolate for asynchronous texture uploads.
Definition: ui_dart_state.h:72

◆ 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 500 of file runtime_controller.cc.

500 {
501 std::shared_ptr<DartIsolate> root_isolate = root_isolate_.lock();
502 return root_isolate ? root_isolate->debug_name() : "";
503}

◆ GetIsolateSnapshot()

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

Definition at line 632 of file runtime_controller.h.

632 {
633 return isolate_snapshot_;
634 }

◆ 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 514 of file runtime_controller.cc.

514 {
515 std::shared_ptr<DartIsolate> root_isolate = root_isolate_.lock();
516 return root_isolate ? root_isolate->GetLastError() : tonic::kNoError;
517}
@ kNoError
Definition: dart_error.h:68

◆ 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 495 of file runtime_controller.cc.

495 {
496 std::shared_ptr<DartIsolate> root_isolate = root_isolate_.lock();
497 return root_isolate ? root_isolate->main_port() : ILLEGAL_PORT;
498}
#define ILLEGAL_PORT
Definition: dart_api.h:1535

◆ 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 479 of file runtime_controller.cc.

479 {
480 return persistent_isolate_data_;
481}

◆ GetPlatformData()

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

Definition at line 636 of file runtime_controller.h.

636{ return platform_data_; }

◆ GetPlatformIsolateManager()

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

Implements flutter::PlatformConfigurationClient.

Definition at line 651 of file runtime_controller.h.

651 {
652 return platform_isolate_manager_;
653 }

◆ GetRootIsolate()

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

Definition at line 647 of file runtime_controller.h.

647 {
648 return root_isolate_;
649 }

◆ 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 595 of file runtime_controller.cc.

595 {
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}
struct _Dart_IsolateGroup * Dart_IsolateGroup
Definition: dart_api.h:89
DART_EXPORT Dart_IsolateGroup Dart_CurrentIsolateGroup(void)

◆ 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 591 of file runtime_controller.cc.

591 {
592 return root_isolate_return_code_;
593}

◆ 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 584 of file runtime_controller.cc.

584 {
585 if (auto isolate = root_isolate_.lock()) {
586 return isolate->GetServiceId();
587 }
588 return std::nullopt;
589}

◆ GetSkiaUnrefQueue()

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

Definition at line 638 of file runtime_controller.h.

638 {
639 return context_.unref_queue;
640 }
fml::RefPtr< SkiaUnrefQueue > unref_queue
Definition: ui_dart_state.h:76

◆ GetSnapshotDelegate()

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

Definition at line 642 of file runtime_controller.h.

643 {
644 return context_.snapshot_delegate;
645 }
fml::TaskRunnerAffineWeakPtr< SnapshotDelegate > snapshot_delegate
Definition: ui_dart_state.h:69

◆ 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 505 of file runtime_controller.cc.

505 {
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}
DART_EXPORT bool Dart_HasLivePorts(void)

◆ IsRootIsolateRunning()

bool flutter::RuntimeController::IsRootIsolateRunning ( )
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 103 of file runtime_controller.cc.

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

◆ 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 
)

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
Returns
If the isolate could be launched and guided to the DartIsolate::Phase::Running phase.

Definition at line 519 of file runtime_controller.cc.

525 {
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}
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
virtual std::weak_ptr< PlatformMessageHandler > GetPlatformMessageHandler() const =0
virtual void OnRootIsolateCreated()=0

◆ 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 606 of file runtime_controller.cc.

609 {
610 root_isolate_.lock()->LoadLoadingUnit(loading_unit_id,
611 std::move(snapshot_data),
612 std::move(snapshot_instructions));
613}

◆ 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 615 of file runtime_controller.cc.

619 {
620 root_isolate_.lock()->LoadLoadingUnitError(loading_unit_id, error_message,
621 transient);
622}

◆ NotifyDestroyed()

bool flutter::RuntimeController::NotifyDestroyed ( )
virtual

Notify the Dart VM that the attached flutter view has been destroyed. This gives the Dart VM to perform some cleanup activities e.g: perform garbage collection to free up any unused memory.

NotifyDestroyed is advisory. The VM may or may not perform any clean up activities.

Definition at line 341 of file runtime_controller.cc.

341 {
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}
DART_EXPORT void Dart_NotifyDestroyed(void)

◆ 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
Bug:
The deadline argument must be converted to std::chrono instead of a raw integer.
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 309 of file runtime_controller.cc.

309 {
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}
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
Dart_PerformanceMode
Definition: dart_api.h:1369
@ Dart_PerformanceMode_Latency
Definition: dart_api.h:1380
DART_EXPORT void Dart_NotifyIdle(int64_t deadline)
DART_EXPORT int64_t Dart_TimelineGetMicros()

◆ 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 193 of file runtime_controller.cc.

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

◆ 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 300 of file runtime_controller.cc.

300 {
301 if (auto* platform_configuration = GetPlatformConfigurationIfAvailable()) {
302 platform_configuration->ReportTimings(std::move(timings));
303 return true;
304 }
305
306 return false;
307}

◆ 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 624 of file runtime_controller.cc.

624 {
625 return client_.RequestDartDeferredLibrary(loading_unit_id);
626}
virtual void RequestDartDeferredLibrary(intptr_t loading_unit_id)=0

◆ 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 278 of file runtime_controller.cc.

278 {
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}
FlutterSemanticsFlag flags
int32_t accessibility_feature_flags_
Definition: platform_data.h:47

◆ 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 628 of file runtime_controller.cc.

628 {
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}
std::vector< DisplayData > displays
Definition: platform_data.h:48

◆ 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.

Deprecated:
The persistent isolate data must be used for this purpose instead.
Parameters
[in]dataThe lifecycle state data.
Returns
If the lifecycle state data was forwarded to the running isolate.

Definition at line 254 of file runtime_controller.cc.

254 {
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}
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::string lifecycle_state
Definition: platform_data.h:44

◆ 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.

Deprecated:
The persistent isolate data must be used for this purpose instead.
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 230 of file runtime_controller.cc.

231 {
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}
std::vector< std::string > locale_data
Definition: platform_data.h:42

◆ 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 266 of file runtime_controller.cc.

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

◆ 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.

Deprecated:
The persistent isolate data must be used for this purpose instead.
Parameters
[in]dataThe user settings data.
Returns
If the user settings data was forwarded to the running isolate.

Definition at line 242 of file runtime_controller.cc.

242 {
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}
std::string user_settings_data
Definition: platform_data.h:43

◆ 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 218 of file runtime_controller.cc.

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

◆ ShutdownPlatformIsolates()

void flutter::RuntimeController::ShutdownPlatformIsolates ( )

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

Definition at line 644 of file runtime_controller.cc.

644 {
645 platform_isolate_manager_->ShutdownPlatformIsolates();
646}

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

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

Definition at line 52 of file runtime_controller.cc.

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

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