#include <engine.h>
Classes | |
| class | Delegate |
| While the engine operates entirely on the UI task runner, it needs the capabilities of the other components to fulfill the requirements of the root isolate. The shell is the only class that implements this interface as no other component has access to all components in a thread safe manner. The engine delegates these tasks to the shell via this interface. More... | |
Public Types | |
| enum class | RunStatus { Success , FailureAlreadyRunning , Failure } |
Indicates the result of the call to Engine::Run. More... | |
Public Member Functions | |
| 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 for tests. | |
| Engine (Delegate &delegate, const PointerDataDispatcherMaker &dispatcher_maker, DartVM &vm, fml::RefPtr< const DartSnapshot > isolate_snapshot, const TaskRunners &task_runners, const PlatformData &platform_data, const Settings &settings, std::unique_ptr< Animator > animator, fml::WeakPtr< IOManager > io_manager, const fml::RefPtr< SkiaUnrefQueue > &unref_queue, fml::TaskRunnerAffineWeakPtr< SnapshotDelegate > snapshot_delegate, const std::shared_ptr< fml::SyncSwitch > &gpu_disabled_switch, const std::shared_future< impeller::RuntimeStageBackend > &runtime_stage_backend) | |
| Creates an instance of the engine. This is done by the Shell on the UI task runner. | |
| 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 they occupy less memory and be created faster. | |
| ~Engine () override | |
| Destroys the engine engine. Called by the shell on the UI task runner. The running root isolate is terminated and will no longer access the task runner after this call returns. This allows the embedder to tear down the thread immediately if needed. | |
| fml::TaskRunnerAffineWeakPtr< Engine > | GetWeakPtr () const |
| RunStatus | Run (RunConfiguration configuration) |
Moves the root isolate to the DartIsolate::Phase::Running phase on a successful call to this method. | |
| bool | Restart (RunConfiguration configuration) |
| Tears down an existing root isolate, reuses the components of that isolate and attempts to launch a new isolate using the given the run configuration. This is only used in the "debug" Flutter runtime mode in the cold-restart scenario. | |
| void | SetupDefaultFontManager () |
| Setup default font manager according to specific platform. | |
| bool | UpdateAssetManager (const std::shared_ptr< AssetManager > &asset_manager) |
Updates the asset manager referenced by the root isolate of a Flutter application. This happens implicitly in the call to Engine::Run and Engine::Restart as the asset manager is referenced from the run configuration provided to those calls. In addition to the Engine::Run and Engine::Restart calls, the tooling may need to update the assets available to the application as the user adds them to their project. For example, these assets may be referenced by code that is newly patched in after a hot-reload. Neither the shell or the isolate in relaunched in such cases. The tooling usually patches in the new assets in a temporary location and updates the asset manager to point to that location. | |
| 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 to Engine::ScheduleFrame. This call originates in the animator. | |
| void | NotifyIdle (fml::TimeDelta deadline) |
Notifies the engine that the UI task runner is not expected to undertake a new frame workload till a specified timepoint. The timepoint is measured in microseconds against the system's monotonic clock. It is recommended that the clock be accessed via Dart_TimelineGetMicros from dart_api.h for consistency. In reality, the clocks used by Dart, FML and std::steady_clock are all the same and the timepoints can be converted from on clock type to another. | |
| void | 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 shell reports this extra instrumentation information back to Dart code running on the engine by invoking this method at predefined intervals. | |
| Dart_Port | GetUIIsolateMainPort () |
Gets the main port of the root isolate. Since the isolate is created immediately in the constructor of the engine, it is possible to get its main port immediately (even before a call to Run can be made). This is useful in registering the port in a race free manner with a port nameserver. | |
| std::string | GetUIIsolateName () |
Gets the debug name of the root isolate. By 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 platform_dispatcher.dart. This name is purely advisory and only used by instrumentation and reporting purposes. | |
| bool | UIIsolateHasLivePorts () |
It is an unexpected challenge to determine when a Dart application is "done". The application cannot simply terminate the native process (and perhaps return an exit code) because it does not have that power. After all, Flutter applications reside within a host process that may have other responsibilities besides just running Flutter applications. Also, the main entry-points are run on an event loop and returning from "main" (unlike in C/C++ applications) does not mean termination of the process. Besides, the return value of the main entrypoint is discarded. | |
| bool | UIIsolateHasPendingMicrotasks () |
| Another signal of liveness is the presence of microtasks that have been queued by the application but have not yet been executed. Embedders may want to check for pending microtasks and ensure that the microtask queue has been drained before the embedder terminates. | |
| tonic::DartErrorHandleType | GetUIIsolateLastError () |
| Errors that are unhandled on the Dart message loop are kept for further inspection till the next unhandled error comes along. This accessor returns the last unhandled error encountered by the root isolate. | |
| std::optional< uint32_t > | GetUIIsolateReturnCode () |
As described in the discussion for UIIsolateHasLivePorts, the "done-ness" of a Dart application is tricky to ascertain and the return value from the main entrypoint is discarded (because the Dart isolate is still running after the main entrypoint returns). But, the concept of an exit code akin to those returned by native applications is still useful. Short lived Dart applications (usually tests), emulate this by setting a per isolate "return value" and then indicating their "done-ness" (usually via closing all live ports). This accessor returns that "return value" is present. | |
| 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. | |
| bool | RemoveView (int64_t view_id) |
| Notify the Flutter application that a view is no longer available. | |
| bool | SendViewFocusEvent (const ViewFocusEvent &event) |
| Notify the Flutter application that the focus state of a native view has changed. | |
| 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 viewport in texels as well as edge insets if present. | |
| void | SetDisplays (const std::vector< DisplayData > &displays) |
| Updates the display metrics for the currently running Flutter application. | |
| void | DispatchPlatformMessage (std::unique_ptr< PlatformMessage > message) |
| Notifies the engine that the embedder has sent it a message. This call originates in the platform view and has been forwarded to the engine on the UI task runner here. | |
| 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 contain multiple input events. This call originates in the platform view and the shell has forwarded the same to the engine on the UI task runner here. | |
| void | DispatchSemanticsAction (int64_t view_id, int node_id, SemanticsAction action, fml::MallocMapping args) |
| Notifies the engine that the embedder encountered an accessibility related action on the specified node. This call originates on the platform view and has been forwarded to the engine here on the UI task runner by the shell. | |
| void | SetSemanticsEnabled (bool enabled) |
| Notifies the engine that the embedder has expressed an opinion about whether the accessibility tree should be generated or not. This call originates in the platform view and is forwarded to the engine here on the UI task runner by the shell. | |
| void | SetAccessibilityFeatures (int32_t flags) |
| Notifies the engine that the embedder has expressed an opinion about where the flags to set on the accessibility tree. This flag originates in the platform view and is forwarded to the engine here on the UI task runner by the shell. | |
| void | ScheduleFrame (bool regenerate_layer_trees) override |
| void | ScheduleFrame () |
| void | OnAllViewsRendered () override |
| FontCollection & | GetFontCollection () override |
| std::shared_ptr< AssetManager > | GetAssetManager () override |
| fml::TaskRunnerAffineWeakPtr< ImageDecoder > | GetImageDecoderWeakPtr () |
| fml::TaskRunnerAffineWeakPtr< ImageGeneratorRegistry > | GetImageGeneratorRegistry () |
Get the ImageGeneratorRegistry associated with the current engine. | |
| void | DoDispatchPacket (std::unique_ptr< PointerDataPacket > packet, uint64_t trace_flow_id) override |
| void | ScheduleSecondaryVsyncCallback (uintptr_t id, const fml::closure &callback) override |
Schedule a secondary callback to be executed right after the main VsyncWaiter::AsyncWaitForVsync callback (which is added by Animator::RequestFrame). | |
| const std::string & | GetLastEntrypoint () const |
| Get the last Entrypoint that was used in the RunConfiguration when |EngineRun| was called. | |
| std::optional< int64_t > | GetLastEngineId () const |
| Get the last Engine Id that was used in the RunConfiguration when |EngineRun| was called. | |
| const std::string & | GetLastEntrypointLibrary () const |
| Get the last Entrypoint Library that was used in the RunConfiguration when |EngineRun| was called. | |
| const std::vector< std::string > & | GetLastEntrypointArgs () const |
| Get the last Entrypoint Arguments that was used in the RunConfiguration when |EngineRun| was called.This is only valid in debug mode. | |
| const std::string & | InitialRoute () const |
| Getter for the initial route. This can be set with a platform message. | |
| 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. | |
| 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. | |
| const RuntimeController * | GetRuntimeController () const |
| Accessor for the RuntimeController. | |
| const std::weak_ptr< VsyncWaiter > | GetVsyncWaiter () const |
| void | ShutdownPlatformIsolates () |
| Shuts down all registered platform isolates. Must be called from the platform thread. | |
| void | FlushMicrotaskQueue () |
| Flushes the microtask queue of the root isolate. | |
Friends | |
| class | testing::ShellTest |
Additional Inherited Members | |
Protected Member Functions inherited from flutter::RuntimeDelegate | |
| virtual | ~RuntimeDelegate () |
The engine is a component owned by the shell that resides on the UI task runner and is responsible for managing the needs of the root isolate and its runtime. The engine can only be created, accessed and collected on the UI task runner. Each shell owns exactly one instance of the engine.
The root isolate of Flutter application gets "window" bindings. Using these bindings, the application can schedule frames, post layer-trees for rendering, ask to decompress images and upload them to the GPU, etc.. Non-root isolates of the VM do not get any of these capabilities and are run in a VM managed thread pool (so if they did have "window", the threading guarantees needed for engine operation would be violated).
The engine is responsible for the entire life-cycle of the root isolate. When the engine is collected, its owner assumes that the root isolate has been shutdown and appropriate resources collected. While each engine instance can only manage a single instance of a root isolate, it may restart that isolate on request. This is how the cold-restart development scenario is supported.
When the engine instance is initially created, the root isolate is created but it is not in the |DartIsolate::Phase::Running| phase yet. It only moves into that phase when a successful call to Engine::Run is made.
Shell
|
strong |
Indicates the result of the call to Engine::Run.
| Enumerator | |
|---|---|
| Success | The call to |EngineRun| was successful and the root isolate is in the |
| FailureAlreadyRunning | The engine can only manage a single instance of a root isolate. If a previous call to run the root isolate was successful, subsequent calls to run the isolate (even if the new run configuration is different) will be rejected. It is up to the caller to decide to re-purpose the running isolate, terminate it, or use another shell to host the new isolate. This is mostly used by embedders which have a fire-and-forget strategy to root isolate launch. For example, the application may try to "launch" an isolate when the embedders launches or resumes from a paused state. That the isolate is running is not necessarily a failure condition for them. But from the engine's perspective, the run configuration was rejected. |
| Failure | Used to indicate to the embedder that a root isolate was not already running but the run configuration was not valid and root isolate could not be moved into the The caller must attempt the run call again with a valid configuration. The set of all failure modes is massive and can originate from a variety of sub-components. The engine will attempt to log the same when possible. With the aid of logs, the common causes of failure are:
|
Definition at line 74 of file engine.h.
| flutter::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 for tests.
Definition at line 36 of file engine.cc.
| flutter::Engine::Engine | ( | Delegate & | delegate, |
| const PointerDataDispatcherMaker & | dispatcher_maker, | ||
| DartVM & | vm, | ||
| fml::RefPtr< const DartSnapshot > | isolate_snapshot, | ||
| const TaskRunners & | task_runners, | ||
| const PlatformData & | platform_data, | ||
| const Settings & | settings, | ||
| std::unique_ptr< Animator > | animator, | ||
| fml::WeakPtr< IOManager > | io_manager, | ||
| const fml::RefPtr< SkiaUnrefQueue > & | unref_queue, | ||
| fml::TaskRunnerAffineWeakPtr< SnapshotDelegate > | snapshot_delegate, | ||
| const std::shared_ptr< fml::SyncSwitch > & | gpu_disabled_switch, | ||
| const std::shared_future< impeller::RuntimeStageBackend > & | runtime_stage_backend | ||
| ) |
Creates an instance of the engine. This is done by the Shell on the UI task runner.
| delegate | The object used by the engine to perform tasks that require access to components that cannot be safely accessed by the engine. This is the shell. | |
| dispatcher_maker | The callback provided by PlatformView for engine to create the pointer data dispatcher. Similar to other engine resources, this dispatcher_maker and its returned dispatcher is only safe to be called from the UI thread. | |
| vm | An instance of the running Dart VM. | |
| [in] | isolate_snapshot | The snapshot used to create the root isolate. Even though the isolate is not DartIsolate::Phase::Running phase, it is created when the engine is created. This requires access to the isolate snapshot upfront. |
| [in] | task_runners | The task runners used by the shell that hosts this engine. |
| [in] | settings | The settings used to initialize the shell and the engine. |
| [in] | animator | The animator used to schedule frames. |
| [in] | snapshot_delegate | The delegate used to fulfill requests to snapshot a specified scene. The engine cannot snapshot a scene on the UI thread directly because the scene (described via a DisplayList) may reference resources on the GPU and there is no GPU context current on the UI thread. The delegate is a component that has access to all the requisite GPU resources. |
| [in] | io_manager | The IO manager used by this root isolate to schedule tasks that manage resources on the GPU. |
Definition at line 62 of file engine.cc.
References flutter::Settings::idle_notification_callback, flutter::Settings::isolate_create_callback, flutter::Settings::isolate_shutdown_callback, and flutter::Settings::persistent_isolate_data.
|
overridedefault |
Destroys the engine engine. Called by the shell on the UI task runner. The running root isolate is terminated and will no longer access the task runner after this call returns. This allows the embedder to tear down the thread immediately if needed.
| void flutter::Engine::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.
A view must be added before other methods can refer to it,
including the implicit view. Adding a view that already exists
triggers an assertion.
| [in] | view_id | The ID of the new view. |
| [in] | viewport_metrics | The initial viewport metrics for the view. |
| [in] | callback | Callback that will be invoked once the engine attempts to add the view. |
Definition at line 332 of file engine.cc.
| void flutter::Engine::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 to Engine::ScheduleFrame. This call originates in the animator.
The frame time given as the argument indicates the point at which the current frame interval began. It is very slightly (because of scheduling overhead) in the past. If a new layer tree is not produced and given to the raster task runner within one frame interval from this point, the Flutter application will jank.
If a root isolate is running, this method calls the ::_beginFrame method in hooks.dart. If a root isolate is not running, this call does nothing.
This method encapsulates the entire UI thread frame workload. The following (mis)behavior in the functioning of the method will cause the jank in the Flutter application:
| [in] | frame_time | The point at which the current frame interval began. May be used by animation interpolators, physics simulations, etc.. |
| [in] | frame_number | The frame number recorded by the animator. Used by the framework to associate frame specific debug information with frame timings and timeline events. |
Definition at line 296 of file engine.cc.
| void flutter::Engine::DispatchPlatformMessage | ( | std::unique_ptr< PlatformMessage > | message | ) |
Notifies the engine that the embedder has sent it a message. This call originates in the platform view and has been forwarded to the engine on the UI task runner here.
| [in] | message | The message sent from the embedder to the Dart application. |
Definition at line 352 of file engine.cc.
References channel, FML_DLOG, flutter::kLifecycleChannel, flutter::kLocalizationChannel, flutter::kNavigationChannel, flutter::kSettingsChannel, and message.
| void flutter::Engine::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 contain multiple input events. This call originates in the platform view and the shell has forwarded the same to the engine on the UI task runner here.
| [in] | packet | The pointer data packet containing multiple input events. |
| [in] | trace_flow_id | The trace flow identifier associated with the pointer data packet. The engine uses this trace identifier to connect trace flows in the timeline from the input event to the frames generated due to those input events. These flows are tagged as "PointerEvent" in the timeline and allow grouping frames and input events into logical chunks. |
Definition at line 469 of file engine.cc.
References TRACE_EVENT0_WITH_FLOW_IDS, and TRACE_FLOW_STEP.
| void flutter::Engine::DispatchSemanticsAction | ( | int64_t | view_id, |
| int | node_id, | ||
| SemanticsAction | action, | ||
| fml::MallocMapping | args | ||
| ) |
Notifies the engine that the embedder encountered an accessibility related action on the specified node. This call originates on the platform view and has been forwarded to the engine here on the UI task runner by the shell.
| [in] | view_id | The identifier of the view. |
| [in] | node_id | The identifier of the accessibility node. |
| [in] | action | The accessibility related action performed on the node of the specified ID. |
| [in] | args | Optional data that applies to the specified action. |
|
overridevirtual |
Actually dispatch the packet using Engine's animator_ and runtime_controller_.
Implements flutter::PointerDataDispatcher::Delegate.
Definition at line 579 of file engine.cc.
| void flutter::Engine::FlushMicrotaskQueue | ( | ) |
|
overridevirtual |
Implements flutter::RuntimeDelegate.
Definition at line 162 of file engine.cc.
|
overridevirtual |
Implements flutter::RuntimeDelegate.
Definition at line 575 of file engine.cc.
| fml::TaskRunnerAffineWeakPtr< ImageDecoder > flutter::Engine::GetImageDecoderWeakPtr | ( | ) |
| fml::TaskRunnerAffineWeakPtr< ImageGeneratorRegistry > flutter::Engine::GetImageGeneratorRegistry | ( | ) |
Get the ImageGeneratorRegistry associated with the current engine.
ImageGeneratorRegistry. Definition at line 171 of file engine.cc.
References flutter::ImageGeneratorRegistry::GetWeakPtr().
| std::optional< int64_t > flutter::Engine::GetLastEngineId | ( | ) | const |
Get the last Engine Id that was used in the RunConfiguration when |EngineRun| was called.
Definition at line 626 of file engine.cc.
| const std::string & flutter::Engine::GetLastEntrypoint | ( | ) | const |
Get the last Entrypoint that was used in the RunConfiguration when |EngineRun| was called.
Definition at line 614 of file engine.cc.
| const std::vector< std::string > & flutter::Engine::GetLastEntrypointArgs | ( | ) | const |
Get the last Entrypoint Arguments that was used in the RunConfiguration when |EngineRun| was called.This is only valid in debug mode.
Definition at line 622 of file engine.cc.
| const std::string & flutter::Engine::GetLastEntrypointLibrary | ( | ) | const |
Get the last Entrypoint Library that was used in the RunConfiguration when |EngineRun| was called.
Definition at line 618 of file engine.cc.
|
inline |
Accessor for the RuntimeController.
Definition at line 1008 of file engine.h.
| tonic::DartErrorHandleType flutter::Engine::GetUIIsolateLastError | ( | ) |
Errors that are unhandled on the Dart message loop are kept for further inspection till the next unhandled error comes along. This accessor returns the last unhandled error encountered by the root isolate.
Definition at line 328 of file engine.cc.
| Dart_Port flutter::Engine::GetUIIsolateMainPort | ( | ) |
Gets the main port of the root isolate. Since the isolate is created immediately in the constructor of the engine, it is possible to get its main port immediately (even before a call to Run can be made). This is useful in registering the port in a race free manner with a port nameserver.
Definition at line 312 of file engine.cc.
| std::string flutter::Engine::GetUIIsolateName | ( | ) |
Gets the debug name of the root isolate. By 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 platform_dispatcher.dart. This name is purely advisory and only used by instrumentation and reporting purposes.
Definition at line 316 of file engine.cc.
| std::optional< uint32_t > flutter::Engine::GetUIIsolateReturnCode | ( | ) |
As described in the discussion for UIIsolateHasLivePorts, the "done-ness" of a Dart application is tricky to ascertain and the return value from the main entrypoint is discarded (because the Dart isolate is still running after the main entrypoint returns). But, the concept of an exit code akin to those returned by native applications is still useful. Short lived Dart applications (usually tests), emulate this by setting a per isolate "return value" and then indicating their "done-ness" (usually via closing all live ports). This accessor returns that "return value" is present.
UIIsolateHasLivePortsDefinition at line 308 of file engine.cc.
| const std::weak_ptr< VsyncWaiter > flutter::Engine::GetVsyncWaiter | ( | ) | const |
| fml::TaskRunnerAffineWeakPtr< Engine > flutter::Engine::GetWeakPtr | ( | ) | const |
|
inline |
| void flutter::Engine::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.
| [in] | loading_unit_id | The unique id of the deferred library's loading unit, as passed in by RequestDartDeferredLibrary. |
| [in] | snapshot_data | Dart snapshot data of the loading unit's shared library. |
| [in] | snapshot_data | Dart snapshot instructions of the loading unit's shared library. |
Definition at line 644 of file engine.cc.
References LoadDartDeferredLibraryError().
| void flutter::Engine::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.
The dart future returned by the initiating loadLibrary() call will complete with an error.
| [in] | loading_unit_id | The unique id of the deferred library's loading unit, as passed in by RequestDartDeferredLibrary. |
| [in] | error_message | The error message that will appear in the dart Future. |
| [in] | transient | A 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 658 of file engine.cc.
Referenced by LoadDartDeferredLibrary().
| void flutter::Engine::NotifyIdle | ( | fml::TimeDelta | deadline | ) |
Notifies the engine that the UI task runner is not expected to undertake a new frame workload till a specified timepoint. The timepoint is measured in microseconds against the system's monotonic clock. It is recommended that the clock be accessed via Dart_TimelineGetMicros from dart_api.h for consistency. In reality, the clocks used by Dart, FML and std::steady_clock are all the same and the timepoints can be converted from on clock type to another.
The Dart VM uses this notification to schedule book-keeping tasks that may include a garbage collection. In this way, it is less likely for the VM to perform such (potentially long running) tasks in the middle of a frame workload.
This notification is advisory. That is, not providing this notification does not mean garbage collection is postponed till this call is made. If this notification is not provided, garbage collection will happen based on the usual heuristics used by the Dart VM.
Currently, this idle notification is delivered to the engine at two points. Once, the deadline is calculated based on how much time in the current frame interval is left on the UI task runner. Since the next frame workload cannot begin till at least the next callback from the vsync waiter, this period may be used to used as a "small" idle notification. On the other hand, if no more frames are scheduled, a large (but arbitrary) idle notification deadline is chosen for a "big" idle notification. Again, this notification does not guarantee collection, just gives the Dart VM more hints about opportune moments to perform collections.
| [in] | deadline | The deadline is used by the VM to determine if the corresponding sweep can be performed within the deadline. |
Definition at line 304 of file engine.cc.
|
overridevirtual |
Implements flutter::RuntimeDelegate.
Definition at line 506 of file engine.cc.
| bool flutter::Engine::RemoveView | ( | int64_t | view_id | ) |
Notify the Flutter application that a view is no longer available.
Removing a view that does not exist triggers an assertion.
The implicit view (kFlutterImplicitViewId) should never be removed. Doing so triggers an assertion.
| [in] | view_id | The ID of the view. |
Definition at line 338 of file engine.cc.
References view_id.
| void flutter::Engine::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 shell reports this extra instrumentation information back to Dart code running on the engine by invoking this method at predefined intervals.
FrameTiming | [in] | timings | Collection 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 engine.cc.
| bool flutter::Engine::Restart | ( | RunConfiguration | configuration | ) |
Tears down an existing root isolate, reuses the components of that isolate and attempts to launch a new isolate using the given the run configuration. This is only used in the "debug" Flutter runtime mode in the cold-restart scenario.
| [in] | configuration | The configuration used to launch the new isolate. |
Definition at line 205 of file engine.cc.
References FML_LOG, flutter::RunConfiguration::IsValid(), flutter::Engine::Delegate::OnPreEngineRestart(), Run(), Success, TRACE_EVENT0, and UpdateAssetManager().
| Engine::RunStatus flutter::Engine::Run | ( | RunConfiguration | configuration | ) |
Moves the root isolate to the DartIsolate::Phase::Running phase on a successful call to this method.
The isolate itself is created when the engine is created, but it is not yet in the running phase. This is done to amortize initial time taken to launch the root isolate. The isolate snapshots used to run the isolate can be fetched on another thread while the engine itself is launched on the UI task runner.
Repeated calls to this method after a successful run will be rejected even if the run configuration is valid (with the appropriate error returned).
| [in] | configuration | The configuration used to run the root isolate. The configuration must be valid. |
Definition at line 217 of file engine.cc.
References engine, Failure, FailureAlreadyRunning, FML_LOG, flutter::RunConfiguration::GetAssetManager(), flutter::RunConfiguration::GetEngineId(), flutter::RunConfiguration::GetEntrypoint(), flutter::RunConfiguration::GetEntrypointArgs(), flutter::RunConfiguration::GetEntrypointLibrary(), fml::MessageLoopTaskQueues::GetInstance(), flutter::TaskRunners::GetPlatformTaskRunner(), fml::TaskRunner::GetTaskQueueId(), flutter::TaskRunners::GetUITaskRunner(), GetWeakPtr(), flutter::RunConfiguration::IsValid(), flutter::kIsolateChannel, flutter::Settings::kMergeAfterLaunch, fml::MessageLoopTaskQueues::Merge(), flutter::Settings::merged_platform_ui_thread, fml::TaskRunner::PostTask(), flutter::Settings::prefetched_default_font_manager, SetupDefaultFontManager(), Success, flutter::RunConfiguration::TakeIsolateConfiguration(), and UpdateAssetManager().
Referenced by Restart().
|
inline |
Schedule a frame with the default parameter of regenerating the layer tree.
Definition at line 882 of file engine.h.
References ScheduleFrame().
Referenced by ScheduleFrame(), SetDisplays(), and SetViewportMetrics().
|
overridevirtual |
Implements flutter::RuntimeDelegate.
Definition at line 502 of file engine.cc.
|
overridevirtual |
Schedule a secondary callback to be executed right after the main VsyncWaiter::AsyncWaitForVsync callback (which is added by Animator::RequestFrame).
Like the callback in AsyncWaitForVsync, this callback is only scheduled to be called once per |id|, and it will be called in the UI thread. If there is no AsyncWaitForVsync callback (Animator::RequestFrame is not called), this secondary callback will still be executed at vsync.
This callback is used to provide the vsync signal needed by SmoothPointerDataDispatcher, and for Animator input flow events.
Implements flutter::PointerDataDispatcher::Delegate.
Definition at line 587 of file engine.cc.
References callback.
| bool flutter::Engine::SendViewFocusEvent | ( | const ViewFocusEvent & | event | ) |
| void flutter::Engine::SetAccessibilityFeatures | ( | int32_t | flags | ) |
Notifies the engine that the embedder has expressed an opinion about where the flags to set on the accessibility tree. This flag originates in the platform view and is forwarded to the engine here on the UI task runner by the shell.
The engine does not care about the accessibility feature flags as all it does is forward this information from the embedder to the framework. However, curious readers may refer to AccessibilityFeatures in window.dart for currently supported accessibility feature flags.
| [in] | flags | The features to enable in the accessibility tree. |
Definition at line 491 of file engine.cc.
| void flutter::Engine::SetDisplays | ( | const std::vector< DisplayData > & | displays | ) |
Updates the display metrics for the currently running Flutter application.
| [in] | displays | A complete list of displays |
Definition at line 671 of file engine.cc.
References displays, and ScheduleFrame().
| void flutter::Engine::SetSemanticsEnabled | ( | bool | enabled | ) |
Notifies the engine that the embedder has expressed an opinion about whether the accessibility tree should be generated or not. This call originates in the platform view and is forwarded to the engine here on the UI task runner by the shell.
| [in] | enabled | Whether the accessibility tree is enabled or disabled. |
Definition at line 487 of file engine.cc.
| void flutter::Engine::SetupDefaultFontManager | ( | ) |
Setup default font manager according to specific platform.
Definition at line 157 of file engine.cc.
References flutter::Settings::font_initialization_data, and TRACE_EVENT0.
Referenced by Run().
| void flutter::Engine::SetViewportMetrics | ( | int64_t | view_id, |
| const ViewportMetrics & | metrics | ||
| ) |
Updates the viewport metrics for a view. The viewport metrics detail the size of the rendering viewport in texels as well as edge insets if present.
ViewportMetrics| [in] | view_id | The ID for the view that metrics describes. |
| [in] | metrics | The metrics. |
Definition at line 346 of file engine.cc.
References ScheduleFrame(), and view_id.
| void flutter::Engine::ShutdownPlatformIsolates | ( | ) |
| std::unique_ptr< Engine > flutter::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 they occupy less memory and be created faster.
This should only be called on running Engines.
Definition at line 113 of file engine.cc.
References flutter::Settings::advisory_script_entrypoint, flutter::Settings::advisory_script_uri, flutter::Settings::idle_notification_callback, flutter::Settings::isolate_create_callback, flutter::Settings::isolate_shutdown_callback, and flutter::Settings::persistent_isolate_data.
| bool flutter::Engine::UIIsolateHasLivePorts | ( | ) |
It is an unexpected challenge to determine when a Dart application is "done". The application cannot simply terminate the native process (and perhaps return an exit code) because it does not have that power. After all, Flutter applications reside within a host process that may have other responsibilities besides just running Flutter applications. Also, the main entry-points are run on an event loop and returning from "main" (unlike in C/C++ applications) does not mean termination of the process. Besides, the return value of the main entrypoint is discarded.
One technique used by embedders to determine "liveness" is to count the outstanding live ports dedicated to the application. These ports may be live as a result of pending timers, scheduled tasks, pending IO on sockets, channels open with other isolates, etc.. At regular intervals (sometimes as often as after the UI task runner processes any task), embedders may check for the "liveness" of the application and perform teardown of the embedder when no more ports are live.
Definition at line 320 of file engine.cc.
| bool flutter::Engine::UIIsolateHasPendingMicrotasks | ( | ) |
Another signal of liveness is the presence of microtasks that have been queued by the application but have not yet been executed. Embedders may want to check for pending microtasks and ensure that the microtask queue has been drained before the embedder terminates.
Definition at line 324 of file engine.cc.
| bool flutter::Engine::UpdateAssetManager | ( | const std::shared_ptr< AssetManager > & | asset_manager | ) |
Updates the asset manager referenced by the root isolate of a Flutter application. This happens implicitly in the call to Engine::Run and Engine::Restart as the asset manager is referenced from the run configuration provided to those calls. In addition to the Engine::Run and Engine::Restart calls, the tooling may need to update the assets available to the application as the user adds them to their project. For example, these assets may be referenced by code that is newly patched in after a hot-reload. Neither the shell or the isolate in relaunched in such cases. The tooling usually patches in the new assets in a temporary location and updates the asset manager to point to that location.
| [in] | asset_manager | The new asset manager to use for the running root isolate. |
Definition at line 175 of file engine.cc.
References flutter::Settings::use_asset_fonts, and flutter::Settings::use_test_fonts.
|
friend |