5#ifndef FLUTTER_SHELL_COMMON_ENGINE_H_
6#define FLUTTER_SHELL_COMMON_ENGINE_H_
11#include "flutter/assets/asset_manager.h"
12#include "flutter/common/task_runners.h"
13#include "flutter/fml/macros.h"
14#include "flutter/fml/mapping.h"
15#include "flutter/fml/memory/weak_ptr.h"
16#include "flutter/lib/ui/painting/image_decoder.h"
17#include "flutter/lib/ui/painting/image_generator_registry.h"
18#include "flutter/lib/ui/semantics/custom_accessibility_action.h"
19#include "flutter/lib/ui/semantics/semantics_node.h"
20#include "flutter/lib/ui/snapshot_delegate.h"
21#include "flutter/lib/ui/text/font_collection.h"
22#include "flutter/lib/ui/volatile_path_tracker.h"
23#include "flutter/lib/ui/window/platform_message.h"
24#include "flutter/lib/ui/window/viewport_metrics.h"
25#include "flutter/runtime/dart_vm.h"
26#include "flutter/runtime/runtime_controller.h"
27#include "flutter/runtime/runtime_delegate.h"
28#include "flutter/shell/common/animator.h"
29#include "flutter/shell/common/display_manager.h"
30#include "flutter/shell/common/platform_view.h"
31#include "flutter/shell/common/pointer_data_dispatcher.h"
32#include "flutter/shell/common/run_configuration.h"
33#include "flutter/shell/common/shell_io_manager.h"
101 FailureAlreadyRunning,
179 std::unique_ptr<PlatformMessage>
message) = 0;
219 int64_t isolate_port) = 0;
261 virtual std::unique_ptr<std::vector<std::string>>
263 const std::vector<std::string>& supported_locale_data) = 0;
295 virtual const std::shared_ptr<PlatformMessageHandler>&
329 int configuration_id)
const = 0;
339 const std::shared_ptr<fml::ConcurrentTaskRunner>&
340 image_decoder_task_runner,
343 std::unique_ptr<Animator> animator,
345 const std::shared_ptr<FontCollection>& font_collection,
346 std::unique_ptr<RuntimeController> runtime_controller,
347 const std::shared_ptr<fml::SyncSwitch>& gpu_disabled_switch);
398 std::unique_ptr<Animator> animator,
402 std::shared_ptr<VolatilePathTracker> volatile_path_tracker,
403 const std::shared_ptr<fml::SyncSwitch>& gpu_disabled_switch,
416 std::unique_ptr<Engine>
Spawn(
420 std::unique_ptr<Animator> animator,
421 const std::string& initial_route,
424 const std::shared_ptr<fml::SyncSwitch>& gpu_disabled_switch)
const;
764 void SetDisplays(
const std::vector<DisplayData>& displays);
795 uint64_t trace_flow_id);
869 uint64_t trace_flow_id)
override;
932 intptr_t loading_unit_id,
933 std::unique_ptr<const fml::Mapping> snapshot_data,
934 std::unique_ptr<const fml::Mapping> snapshot_instructions);
959 const std::string& error_message,
966 return runtime_controller_.get();
979 std::string DefaultRouteName()
override;
982 void Render(int64_t view_id,
983 std::unique_ptr<flutter::LayerTree> layer_tree,
984 float device_pixel_ratio)
override;
991 void HandlePlatformMessage(std::unique_ptr<PlatformMessage>
message)
override;
994 void OnRootIsolateCreated()
override;
997 void UpdateIsolateDescription(
const std::string isolate_name,
998 int64_t isolate_port)
override;
1001 std::unique_ptr<std::vector<std::string>> ComputePlatformResolvedLocale(
1002 const std::vector<std::string>& supported_locale_data)
override;
1005 void RequestDartDeferredLibrary(intptr_t loading_unit_id)
override;
1008 std::weak_ptr<PlatformMessageHandler> GetPlatformMessageHandler()
1012 void SendChannelUpdate(std::string
name,
bool listening)
override;
1015 double GetScaledFontSize(
double unscaled_font_size,
1016 int configuration_id)
const override;
1018 void SetNeedsReportTimings(
bool value)
override;
1022 bool HandleNavigationPlatformMessage(
1023 std::unique_ptr<PlatformMessage>
message);
1029 void HandleAssetPlatformMessage(std::unique_ptr<PlatformMessage>
message);
1031 bool GetAssetAsBuffer(
const std::string&
name, std::vector<uint8_t>*
data);
1043 std::unique_ptr<PointerDataDispatcher> pointer_data_dispatcher_;
1045 std::string last_entry_point_;
1046 std::string last_entry_point_library_;
1047 std::vector<std::string> last_entry_point_args_;
1048 std::string initial_route_;
1049 std::shared_ptr<AssetManager> asset_manager_;
1050 std::shared_ptr<FontCollection> font_collection_;
1051 const std::unique_ptr<ImageDecoder> image_decoder_;
Describes a running instance of the Dart VM. There may only be one running instance of the Dart VM in...
While the engine operates entirely on the UI task runner, it needs the capabilities of the other comp...
virtual fml::TimePoint GetCurrentTimePoint()=0
Returns the current fml::TimePoint. This method is primarily provided to allow tests to control Any m...
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 f...
virtual void UpdateIsolateDescription(const std::string isolate_name, int64_t isolate_port)=0
Notifies the shell of the name of the root isolate and its port when that isolate is launched,...
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 resolv...
virtual void OnPreEngineRestart()=0
Notifies the delegate that the root isolate of the application is about to be discarded and a new iso...
virtual void OnEngineChannelUpdate(std::string name, bool listening)=0
Invoked when a listener is registered on a platform channel.
virtual void OnEngineHandlePlatformMessage(std::unique_ptr< PlatformMessage > message)=0
When the Flutter application has a message to send to the underlying platform, the message needs to b...
virtual const std::shared_ptr< PlatformMessageHandler > & GetPlatformMessageHandler() const =0
Returns the delegate object that handles PlatformMessage's from Flutter to the host platform (and its...
virtual void SetNeedsReportTimings(bool needs_reporting)=0
Notifies the shell that the application has an opinion about whether its frame timings need to be rep...
virtual void OnEngineUpdateSemantics(SemanticsNodeUpdates updates, CustomAccessibilityActionUpdates actions)=0
When the accessibility tree has been updated by the Flutter application, this new information needs t...
virtual void OnRootIsolateCreated()=0
Notifies the shell that the root isolate is created. Currently, this information is to add to the ser...
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 def...
void SetAccessibilityFeatures(int32_t flags)
Notifies the engine that the embedder has expressed an opinion about where the flags to set on the ac...
void SetupDefaultFontManager()
Setup default font manager according to specific platform.
fml::WeakPtr< Engine > GetWeakPtr() const
bool RemoveView(int64_t view_id)
Notify the Flutter application that a view is no longer available.
void NotifyIdle(fml::TimeDelta deadline)
Notifies the engine that the UI task runner is not expected to undertake a new frame workload till a ...
void SetViewportMetrics(int64_t view_id, const ViewportMetrics &metrics)
Updates the viewport metrics for a view. The viewport metrics detail the size of the rendering viewpo...
void ReportTimings(std::vector< int64_t > timings)
Dart code cannot fully measure the time it takes for a specific frame to be rendered....
void OnAllViewsRendered() override
void DispatchSemanticsAction(int node_id, SemanticsAction action, fml::MallocMapping args)
Notifies the engine that the embedder encountered an accessibility related action on the specified no...
void ShutdownPlatformIsolates()
Shuts down all registered platform isolates. Must be called from the platform thread.
void SetDisplays(const std::vector< DisplayData > &displays)
Updates the display metrics for the currently running Flutter application.
const std::weak_ptr< VsyncWaiter > GetVsyncWaiter() const
void BeginFrame(fml::TimePoint frame_time, uint64_t frame_number)
Notifies the engine that it is time to begin working on a new frame previously scheduled via a call t...
tonic::DartErrorHandleType GetUIIsolateLastError()
Errors that are unhandled on the Dart message loop are kept for further inspection till the next unha...
FontCollection & GetFontCollection() override
std::shared_ptr< AssetManager > GetAssetManager() override
RunStatus Run(RunConfiguration configuration)
Moves the root isolate to the DartIsolate::Phase::Running phase on a successful call to this method.
std::string GetUIIsolateName()
Gets the debug name of the root isolate. By default, the debug name of the isolate is derived from it...
~Engine() override
Destroys the engine engine. Called by the shell on the UI task runner. The running root isolate is te...
const std::string & GetLastEntrypointLibrary() const
Get the last Entrypoint Library that was used in the RunConfiguration when |Engine::Run| was called.
bool UpdateAssetManager(const std::shared_ptr< AssetManager > &asset_manager)
Updates the asset manager referenced by the root isolate of a Flutter application....
Dart_Port GetUIIsolateMainPort()
Gets the main port of the root isolate. Since the isolate is created immediately in the constructor o...
void DispatchPointerDataPacket(std::unique_ptr< PointerDataPacket > packet, uint64_t trace_flow_id)
Notifies the engine that the embedder has sent it a pointer data packet. A pointer data packet may co...
void LoadDartDeferredLibraryError(intptr_t loading_unit_id, const std::string &error_message, bool transient)
Indicates to the dart VM that the request to load a deferred library with the specified loading unit ...
void 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,...
void AddView(int64_t view_id, const ViewportMetrics &view_metrics, std::function< void(bool added)> callback)
Notify the Flutter application that a new view is available.
void DoDispatchPacket(std::unique_ptr< PointerDataPacket > packet, uint64_t trace_flow_id) override
bool UIIsolateHasLivePorts()
It is an unexpected challenge to determine when a Dart application is "done". The application cannot ...
const std::string & GetLastEntrypoint() const
Get the last Entrypoint that was used in the RunConfiguration when |Engine::Run| was called.
RunStatus
Indicates the result of the call to Engine::Run.
bool Restart(RunConfiguration configuration)
Tears down an existing root isolate, reuses the components of that isolate and attempts to launch a n...
const std::vector< std::string > & GetLastEntrypointArgs() const
Get the last Entrypoint Arguments that was used in the RunConfiguration when |Engine::Run| was called...
std::unique_ptr< Engine > Spawn(Delegate &delegate, const PointerDataDispatcherMaker &dispatcher_maker, const Settings &settings, std::unique_ptr< Animator > animator, const std::string &initial_route, const fml::WeakPtr< IOManager > &io_manager, fml::TaskRunnerAffineWeakPtr< SnapshotDelegate > snapshot_delegate, const std::shared_ptr< fml::SyncSwitch > &gpu_disabled_switch) const
Create a Engine that shares as many resources as possible with the calling Engine such that together ...
const std::string & InitialRoute() const
Getter for the initial route. This can be set with a platform message.
void SetSemanticsEnabled(bool enabled)
Notifies the engine that the embedder has expressed an opinion about whether the accessibility tree s...
void DispatchPlatformMessage(std::unique_ptr< PlatformMessage > message)
Notifies the engine that the embedder has sent it a message. This call originates in the platform vie...
const RuntimeController * GetRuntimeController() const
Accessor for the RuntimeController.
fml::WeakPtr< ImageGeneratorRegistry > GetImageGeneratorRegistry()
Get the ImageGeneratorRegistry associated with the current engine.
Engine(Delegate &delegate, const PointerDataDispatcherMaker &dispatcher_maker, const std::shared_ptr< fml::ConcurrentTaskRunner > &image_decoder_task_runner, const TaskRunners &task_runners, const Settings &settings, std::unique_ptr< Animator > animator, const fml::WeakPtr< IOManager > &io_manager, const std::shared_ptr< FontCollection > &font_collection, std::unique_ptr< RuntimeController > runtime_controller, const std::shared_ptr< fml::SyncSwitch > &gpu_disabled_switch)
Creates an instance of the engine with a supplied RuntimeController. Use the other constructor except...
std::optional< uint32_t > GetUIIsolateReturnCode()
As described in the discussion for UIIsolateHasLivePorts, the "done-ness" of a Dart application is tr...
fml::WeakPtr< ImageDecoder > GetImageDecoderWeakPtr()
void ScheduleSecondaryVsyncCallback(uintptr_t id, const fml::closure &callback) override
Schedule a secondary callback to be executed right after the main VsyncWaiter::AsyncWaitForVsync call...
void NotifyDestroyed()
Notifies the engine that the attached flutter view has been destroyed. This enables the engine to not...
Keeps a priority-ordered registry of image generator builders to be used when decoding images....
The interface for Engine to implement.
Specifies all the configuration required by the runtime library to launch the root isolate....
A Mapping like NonOwnedMapping, but uses Free as its release proc.
std::unique_ptr< RuntimeController > runtime_controller_
TaskRunners task_runners_
std::unique_ptr< Animator > animator_
FlutterSemanticsFlag flags
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
FlKeyEvent uint64_t FlKeyResponderAsyncCallback callback
#define FML_DISALLOW_COPY_AND_ASSIGN(TypeName)
Dart_NativeFunction function
std::unordered_map< int32_t, SemanticsNode > SemanticsNodeUpdates
std::unordered_map< int32_t, CustomAccessibilityAction > CustomAccessibilityActionUpdates
std::function< std::unique_ptr< PointerDataDispatcher >(PointerDataDispatcher::Delegate &)> PointerDataDispatcherMaker
Signature for constructing PointerDataDispatcher.
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