5#ifndef FLUTTER_RUNTIME_RUNTIME_CONTROLLER_H_
6#define FLUTTER_RUNTIME_RUNTIME_CONTROLLER_H_
11#include "flutter/assets/asset_manager.h"
12#include "flutter/common/task_runners.h"
13#include "flutter/flow/layers/layer_tree.h"
14#include "flutter/fml/macros.h"
15#include "flutter/fml/mapping.h"
16#include "flutter/lib/ui/io_manager.h"
17#include "flutter/lib/ui/painting/image_generator_registry.h"
18#include "flutter/lib/ui/text/font_collection.h"
19#include "flutter/lib/ui/ui_dart_state.h"
20#include "flutter/lib/ui/volatile_path_tracker.h"
21#include "flutter/lib/ui/window/platform_configuration.h"
22#include "flutter/lib/ui/window/pointer_data_packet.h"
23#include "flutter/lib/ui/window/pointer_data_packet_converter.h"
24#include "flutter/runtime/dart_vm.h"
25#include "flutter/runtime/platform_data.h"
26#include "flutter/runtime/platform_isolate_manager.h"
27#include "rapidjson/document.h"
28#include "rapidjson/stringbuffer.h"
103 const std::function<
void(int64_t)>& idle_notification_callback,
107 std::shared_ptr<const fml::Mapping> p_persistent_isolate_data,
117 std::unique_ptr<RuntimeController>
Spawn(
119 const std::string& advisory_script_uri,
120 const std::string& advisory_script_entrypoint,
121 const std::function<
void(int64_t)>& idle_notification_callback,
124 const std::shared_ptr<const fml::Mapping>& persistent_isolate_data,
168 std::optional<std::string> dart_entrypoint,
169 std::optional<std::string> dart_entrypoint_library,
170 const std::vector<std::string>& dart_entrypoint_args,
171 std::unique_ptr<IsolateConfiguration> isolate_configuration);
182 std::unique_ptr<RuntimeController>
Clone()
const;
247 bool SetDisplays(
const std::vector<DisplayData>& displays);
262 bool SetLocales(
const std::vector<std::string>& locale_data);
467 std::unique_ptr<PlatformMessage>
message);
590 intptr_t loading_unit_id,
591 std::unique_ptr<const fml::Mapping> snapshot_data,
592 std::unique_ptr<const fml::Mapping> snapshot_instructions);
617 const std::string error_message,
633 return isolate_snapshot_;
648 return root_isolate_;
652 return platform_isolate_manager_;
667 Locale(std::string language_code_,
668 std::string country_code_,
669 std::string script_code_,
670 std::string variant_code_);
674 std::string language_code;
675 std::string country_code;
676 std::string script_code;
677 std::string variant_code;
680 RuntimeDelegate& client_;
684 PlatformData platform_data_;
685 std::weak_ptr<DartIsolate> root_isolate_;
686 std::weak_ptr<DartIsolate> spawning_isolate_;
687 std::optional<uint32_t> root_isolate_return_code_;
690 std::shared_ptr<const fml::Mapping> persistent_isolate_data_;
691 UIDartState::Context context_;
692 PointerDataPacketConverter pointer_data_packet_converter_;
693 std::shared_ptr<PlatformIsolateManager> platform_isolate_manager_ =
694 std::shared_ptr<PlatformIsolateManager>(
new PlatformIsolateManager());
695 bool has_flushed_runtime_state_ =
false;
701 std::unordered_map<int64_t, AddViewCallback> pending_add_view_callbacks_;
717 std::unordered_set<uint64_t> rendered_views_during_frame_;
719 void MarkAsFrameBorder();
721 void CheckIfAllViewsRendered();
723 PlatformConfiguration* GetPlatformConfigurationIfAvailable();
725 bool FlushRuntimeStateToIsolate();
728 bool ViewExists(int64_t view_id)
const override;
731 std::string DefaultRouteName()
override;
734 void ScheduleFrame()
override;
737 void EndWarmUpFrame()
override;
740 void Render(int64_t view_id,
746 void UpdateSemantics(SemanticsUpdate*
update)
override;
749 void HandlePlatformMessage(std::unique_ptr<PlatformMessage>
message)
override;
752 FontCollection& GetFontCollection()
override;
755 std::shared_ptr<AssetManager> GetAssetManager()
override;
758 void UpdateIsolateDescription(
const std::string isolate_name,
759 int64_t isolate_port)
override;
762 void SetNeedsReportTimings(
bool value)
override;
765 std::unique_ptr<std::vector<std::string>> ComputePlatformResolvedLocale(
766 const std::vector<std::string>& supported_locale_data)
override;
769 void SendChannelUpdate(std::string
name,
bool listening)
override;
772 double GetScaledFontSize(
double unscaled_font_size,
773 int configuration_id)
const override;
Describes a running instance of the Dart VM. There may only be one running instance of the Dart VM in...
void AddView(int64_t view_id, const ViewportMetrics &view_metrics, AddViewCallback callback)
Notify the isolate that a new view is available.
~RuntimeController() override
bool SetAccessibilityFeatures(int32_t flags)
Forward the preference of accessibility features that must be enabled in the semantics tree to the ru...
virtual bool IsRootIsolateRunning()
Returns if the root isolate is running. The isolate must be transitioned to the running phase manuall...
Dart_Port GetMainPort()
Gets the main port identifier of the root isolate.
bool SetSemanticsEnabled(bool enabled)
Notifies the running isolate about whether the semantics tree should be generated or not....
bool SetViewportMetrics(int64_t view_id, const ViewportMetrics &metrics)
Forward the specified viewport metrics to the running isolate. If the isolate is not running,...
uint64_t GetRootIsolateGroup() const
Get an identifier that represents the Dart isolate group the root isolate is in.
RuntimeController(RuntimeDelegate &p_client, DartVM *vm, fml::RefPtr< const DartSnapshot > p_isolate_snapshot, const std::function< void(int64_t)> &idle_notification_callback, const PlatformData &platform_data, const fml::closure &isolate_create_callback, const fml::closure &isolate_shutdown_callback, std::shared_ptr< const fml::Mapping > p_persistent_isolate_data, const UIDartState::Context &context)
Creates a new instance of a runtime controller. This is usually only done by the engine instance asso...
bool DispatchSemanticsAction(int32_t node_id, SemanticsAction action, fml::MallocMapping args)
Dispatch the semantics action to the specified accessibility node.
virtual bool NotifyIdle(fml::TimeDelta deadline)
Notify the Dart VM that no frame workloads are expected on the UI task runner till the specified dead...
std::weak_ptr< const DartIsolate > GetRootIsolate() const
bool DispatchPointerDataPacket(const PointerDataPacket &packet)
Dispatch the specified pointer data message to the running root isolate.
bool SetInitialLifecycleState(const std::string &data)
Forward the initial lifecycle state data to the running isolate. If the isolate is not running,...
std::function< void(bool added)> AddViewCallback
std::shared_ptr< PlatformIsolateManager > GetPlatformIsolateManager() override
bool SetLocales(const std::vector< std::string > &locale_data)
Forward the specified locale data to the running isolate. If the isolate is not running,...
void RequestDartDeferredLibrary(intptr_t loading_unit_id) override
Invoked when the Dart VM requests that a deferred library be loaded. Notifies the engine that the def...
bool SetDisplays(const std::vector< DisplayData > &displays)
Forward the specified display metrics to the running isolate. If the isolate is not running,...
bool HasLivePorts()
Returns if the root isolate has any live receive ports.
bool RemoveView(int64_t view_id)
Notify the isolate that a view is no longer available.
std::optional< std::string > GetRootIsolateServiceID() const
Get the service ID of the root isolate if the root isolate is running.
const fml::RefPtr< const DartSnapshot > & GetIsolateSnapshot() const
const PlatformData & GetPlatformData() const
std::unique_ptr< RuntimeController > Spawn(RuntimeDelegate &p_client, const std::string &advisory_script_uri, const std::string &advisory_script_entrypoint, const std::function< void(int64_t)> &idle_notification_callback, const fml::closure &isolate_create_callback, const fml::closure &isolate_shutdown_callback, const std::shared_ptr< const fml::Mapping > &persistent_isolate_data, fml::WeakPtr< IOManager > io_manager, fml::WeakPtr< ImageDecoder > image_decoder, fml::WeakPtr< ImageGeneratorRegistry > image_generator_registry, fml::TaskRunnerAffineWeakPtr< SnapshotDelegate > snapshot_delegate) const
Create a RuntimeController that shares as many resources as possible with the calling RuntimeControll...
bool ReportTimings(std::vector< int64_t > timings)
Dart code cannot fully measure the time it takes for a specific frame to be rendered....
virtual bool NotifyDestroyed()
Notify the Dart VM that the attached flutter view has been destroyed. This gives the Dart VM to perfo...
const fml::RefPtr< SkiaUnrefQueue > & GetSkiaUnrefQueue() const
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....
const fml::TaskRunnerAffineWeakPtr< SnapshotDelegate > & GetSnapshotDelegate() const
virtual bool DispatchPlatformMessage(std::unique_ptr< PlatformMessage > message)
Dispatch the specified platform message to running root isolate.
tonic::DartErrorHandleType GetLastError()
Get the last error encountered by the microtask queue.
bool SetUserSettingsData(const std::string &data)
Forward the user settings data to the running isolate. If the isolate is not running,...
void LoadDartDeferredLibrary(intptr_t loading_unit_id, std::unique_ptr< const fml::Mapping > snapshot_data, std::unique_ptr< const fml::Mapping > snapshot_instructions)
Loads the Dart shared library into the Dart VM. When the Dart library is loaded successfully,...
std::unique_ptr< RuntimeController > Clone() const
Clone the runtime controller. Launching an isolate with a cloned runtime controller will use the same...
void ShutdownPlatformIsolates()
Shuts down all registered platform isolates. Must be called from the platform thread.
virtual DartVM * GetDartVM() const
bool BeginFrame(fml::TimePoint frame_time, uint64_t frame_number)
Notifies the running isolate that it should start generating a new frame.
std::optional< uint32_t > GetRootIsolateReturnCode()
Get the return code specified by the root isolate (if one is present).
std::shared_ptr< const fml::Mapping > GetPersistentIsolateData() override
The embedder can specify data that the isolate can request synchronously on launch....
const fml::WeakPtr< IOManager > & GetIOManager() const
virtual void LoadDartDeferredLibraryError(intptr_t loading_unit_id, const std::string error_message, bool transient)
Indicates to the dart VM that the request to load a deferred library with the specified loading unit ...
std::string GetIsolateName()
Gets the debug name of the root isolate. But default, the debug name of the isolate is derived from i...
A Mapping like NonOwnedMapping, but uses Free as its release proc.
FlutterSemanticsFlag flags
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
FlKeyEvent uint64_t FlKeyResponderAsyncCallback callback
Dart_NativeFunction function
DEF_SWITCHES_START aot vmservice shared library name
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot data
std::function< void()> closure
The subset of state which is owned by the shell or engine and passed through the RuntimeController in...
fml::RefPtr< SkiaUnrefQueue > unref_queue
fml::WeakPtr< IOManager > io_manager
The IO manager used by the isolate for asynchronous texture uploads.
fml::TaskRunnerAffineWeakPtr< SnapshotDelegate > snapshot_delegate