Flutter Engine
The Flutter Engine
|
#include <shell.h>
Public Types | |
template<class T > | |
using | CreateCallback = std::function< std::unique_ptr< T >(Shell &)> |
typedef std::function< std::unique_ptr< Engine >(Engine::Delegate &delegate, const PointerDataDispatcherMaker &dispatcher_maker, DartVM &vm, fml::RefPtr< const DartSnapshot > isolate_snapshot, TaskRunners task_runners, const PlatformData &platform_data, Settings settings, std::unique_ptr< Animator > animator, fml::WeakPtr< IOManager > io_manager, fml::RefPtr< SkiaUnrefQueue > unref_queue, fml::TaskRunnerAffineWeakPtr< SnapshotDelegate > snapshot_delegate, std::shared_ptr< VolatilePathTracker > volatile_path_tracker, const std::shared_ptr< fml::SyncSwitch > &gpu_disabled_switch, impeller::RuntimeStageBackend runtime_stage_type)> | EngineCreateCallback |
Public Types inherited from flutter::PlatformView::Delegate | |
using | AddViewCallback = PlatformView::AddViewCallback |
using | RemoveViewCallback = PlatformView::RemoveViewCallback |
using | KeyDataResponse = std::function< void(bool)> |
Public Types inherited from flutter::ServiceProtocol::Handler | |
using | ServiceProtocolMap = std::map< std::string_view, std::string_view > |
Public Member Functions | |
~Shell () | |
Destroys the shell. This is a synchronous operation and synchronous barrier blocks are introduced on the various threads to ensure shutdown of all shell sub-components before this method returns. | |
std::unique_ptr< Shell > | Spawn (RunConfiguration run_configuration, const std::string &initial_route, const CreateCallback< PlatformView > &on_create_platform_view, const CreateCallback< Rasterizer > &on_create_rasterizer) const |
Creates one Shell from another Shell where the created Shell takes the opportunity to share any internal components it can. This results is a Shell that has a smaller startup time cost and a smaller memory footprint than an Shell created with the Create function. | |
void | RunEngine (RunConfiguration run_configuration) |
Starts an isolate for the given RunConfiguration. | |
void | RunEngine (RunConfiguration run_configuration, const std::function< void(Engine::RunStatus)> &result_callback) |
Starts an isolate for the given RunConfiguration. The result_callback will be called with the status of the operation. | |
const Settings & | GetSettings () const override |
const TaskRunners & | GetTaskRunners () const override |
If callers wish to interact directly with any shell subcomponents, they must (on the platform thread) obtain a task runner that the component is designed to run on and a weak pointer to that component. They may then post a task to that task runner, do the validity check on that task runner before performing any operation on that component. This accessor allows callers to access the task runners for this shell. | |
const fml::RefPtr< fml::RasterThreadMerger > | GetParentRasterThreadMerger () const override |
Getting the raster thread merger from parent shell, it can be a null RefPtr when it's a root Shell or the embedder_->SupportsDynamicThreadMerging() returns false. | |
fml::TaskRunnerAffineWeakPtr< Rasterizer > | GetRasterizer () const |
Rasterizers may only be accessed on the raster task runner. | |
fml::WeakPtr< Engine > | GetEngine () |
Engines may only be accessed on the UI thread. This method is deprecated, and implementers should instead use other API available on the Shell or the PlatformView. | |
fml::WeakPtr< PlatformView > | GetPlatformView () |
Platform views may only be accessed on the platform task runner. | |
fml::WeakPtr< ShellIOManager > | GetIOManager () |
The IO Manager may only be accessed on the IO task runner. | |
void | NotifyLowMemoryWarning () const |
Used by embedders to notify that there is a low memory warning. The shell will attempt to purge caches. Current, only the rasterizer cache is purged. | |
bool | IsSetup () const |
Used by embedders to check if all shell subcomponents are initialized. It is the embedder's responsibility to make this call before accessing any other shell method. A shell that is not set up must be discarded and another one created with updated settings. | |
Rasterizer::Screenshot | Screenshot (Rasterizer::ScreenshotType type, bool base64_encode) |
Captures a screenshot and optionally Base64 encodes the data of the last layer tree rendered by the rasterizer in this shell. | |
fml::Status | WaitForFirstFrame (fml::TimeDelta timeout) |
Pauses the calling thread until the first frame is presented. | |
bool | ReloadSystemFonts () |
Used by embedders to reload the system fonts in FontCollection. It also clears the cached font families and send system channel message to framework to rebuild affected widgets. | |
std::optional< DartErrorCode > | GetUIIsolateLastError () const |
Used by embedders to get the last error from the Dart UI Isolate, if one exists. | |
bool | EngineHasLivePorts () const |
Used by embedders to check if the Engine is running and has any live ports remaining. For example, the Flutter tester uses this method to check whether it should continue to wait for a running test or not. | |
std::shared_ptr< const fml::SyncSwitch > | GetIsGpuDisabledSyncSwitch () const override |
Accessor for the disable GPU SyncSwitch. | |
void | SetGpuAvailability (GpuAvailability availability) |
Marks the GPU as available or unavailable. | |
DartVM * | GetDartVM () |
Get a pointer to the Dart VM used by this running shell instance. | |
void | OnDisplayUpdates (std::vector< std::unique_ptr< Display > > displays) |
Notifies the display manager of the updates. | |
double | GetMainDisplayRefreshRate () |
Queries the DisplayManager for the main display refresh rate. | |
void | RegisterImageDecoder (ImageGeneratorFactory factory, int32_t priority) |
Install a new factory that can match against and decode image data. | |
const std::shared_ptr< PlatformMessageHandler > & | GetPlatformMessageHandler () const override |
Returns the delegate object that handles PlatformMessage's from Flutter to the host platform (and its responses). | |
const std::weak_ptr< VsyncWaiter > | GetVsyncWaiter () const |
const std::shared_ptr< fml::ConcurrentTaskRunner > | GetConcurrentWorkerTaskRunner () const |
Public Member Functions inherited from flutter::PlatformView::Delegate | |
virtual void | OnPlatformViewRegisterTexture (std::shared_ptr< Texture > texture)=0 |
Notifies the delegate that the embedder has specified a texture that it want the rasterizer to composite within the Flutter layer tree. All textures must have a unique identifier. When the rasterizer encounters an external texture within its hierarchy, it gives the embedder a chance to update that texture on the raster thread before it composites the same on-screen. | |
Static Public Member Functions | |
static std::unique_ptr< Shell > | Create (const PlatformData &platform_data, const TaskRunners &task_runners, Settings settings, const CreateCallback< PlatformView > &on_create_platform_view, const CreateCallback< Rasterizer > &on_create_rasterizer, bool is_gpu_disabled=false) |
Creates a shell instance using the provided settings. The callbacks to create the various shell subcomponents will be called on the appropriate threads before this method returns. If this is the first instance of a shell in the process, this call also bootstraps the Dart VM. | |
static std::pair< DartVMRef, fml::RefPtr< const DartSnapshot > > | InferVmInitDataFromSettings (Settings &settings) |
Private Member Functions | |
void | OnPlatformViewCreated (std::unique_ptr< Surface > surface) override |
Notifies the delegate that the platform view was created with the given render surface. This surface is platform (iOS, Android) and client-rendering API (OpenGL, Software, Metal, Vulkan) specific. This is usually a sign to the rasterizer to set up and begin rendering to that surface. | |
void | OnPlatformViewDestroyed () override |
Notifies the delegate that the platform view was destroyed. This is usually a sign to the rasterizer to suspend rendering a previously configured surface and collect any intermediate resources. | |
void | OnPlatformViewScheduleFrame () override |
Notifies the delegate that the platform needs to schedule a frame to regenerate the layer tree and redraw the surface. | |
void | OnPlatformViewAddView (int64_t view_id, const ViewportMetrics &viewport_metrics, AddViewCallback callback) override |
Allocate resources for a new non-implicit view and inform Dart about the view, and on success, schedules a new frame. | |
void | OnPlatformViewRemoveView (int64_t view_id, RemoveViewCallback callback) override |
Deallocate resources for a removed view and inform Dart about the removal. | |
void | OnPlatformViewSetViewportMetrics (int64_t view_id, const ViewportMetrics &metrics) override |
Notifies the delegate the viewport metrics of a view have been updated. The rasterizer will need to be reconfigured to render the frame in the updated viewport metrics. | |
void | OnPlatformViewDispatchPlatformMessage (std::unique_ptr< PlatformMessage > message) override |
Notifies the delegate that the platform has dispatched a platform message from the embedder to the Flutter application. This message must be forwarded to the running isolate hosted by the engine on the UI thread. | |
void | OnPlatformViewDispatchPointerDataPacket (std::unique_ptr< PointerDataPacket > packet) override |
Notifies the delegate that the platform view has encountered a pointer event. This pointer event needs to be forwarded to the running root isolate hosted by the engine on the UI thread. | |
void | OnPlatformViewDispatchSemanticsAction (int32_t node_id, SemanticsAction action, fml::MallocMapping args) override |
Notifies the delegate that the platform view has encountered an accessibility related action on the specified node. This event must be forwarded to the running root isolate hosted by the engine on the UI thread. | |
void | OnPlatformViewSetSemanticsEnabled (bool enabled) override |
Notifies the delegate that the embedder has expressed an opinion about whether the accessibility tree needs to be enabled or disabled. This information needs to be forwarded to the root isolate running on the UI thread. | |
void | OnPlatformViewSetAccessibilityFeatures (int32_t flags) override |
Notifies the delegate that the embedder has expressed an opinion about the features to enable in the accessibility tree. | |
void | OnPlatformViewRegisterTexture (std::shared_ptr< flutter::Texture > texture) override |
void | OnPlatformViewUnregisterTexture (int64_t texture_id) override |
Notifies the delegate that the embedder will no longer attempt to composite the specified texture within the layer tree. This allows the rasterizer to collect associated resources. | |
void | OnPlatformViewMarkTextureFrameAvailable (int64_t texture_id) override |
Notifies the delegate that the embedder has updated the contents of the texture with the specified identifier. Typically, Flutter will only render a frame if there is an updated layer tree. However, in cases where the layer tree is static but one of the externally composited textures has been updated by the embedder, the embedder needs to notify the rasterizer to render a new frame. In such cases, the existing layer tree may be reused with the frame composited with all updated external textures. | |
void | OnPlatformViewSetNextFrameCallback (const fml::closure &closure) override |
Notifies the delegate that the specified callback needs to be invoked after the rasterizer is done rendering the next frame. This callback will be called on the render thread and it is caller responsibility to perform any re-threading as necessary. Due to the asynchronous nature of rendering in Flutter, embedders usually add a placeholder over the contents in which Flutter is going to render when Flutter is first initialized. This callback may be used as a signal to remove that placeholder. | |
const Settings & | OnPlatformViewGetSettings () const override |
Called by the platform view on the platform thread to get the settings object associated with the platform view instance. | |
void | LoadDartDeferredLibrary (intptr_t loading_unit_id, std::unique_ptr< const fml::Mapping > snapshot_data, std::unique_ptr< const fml::Mapping > snapshot_instructions) override |
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) override |
Indicates to the dart VM that the request to load a deferred library with the specified loading unit id has failed. | |
void | UpdateAssetResolverByType (std::unique_ptr< AssetResolver > updated_asset_resolver, AssetResolver::AssetResolverType type) override |
Replaces the asset resolver handled by the engine's AssetManager of the specified type with updated_asset_resolver . The matching AssetResolver is removed and replaced with updated_asset_resolvers . | |
void | OnAnimatorBeginFrame (fml::TimePoint frame_target_time, uint64_t frame_number) override |
void | OnAnimatorNotifyIdle (fml::TimeDelta deadline) override |
void | OnAnimatorUpdateLatestFrameTargetTime (fml::TimePoint frame_target_time) override |
void | OnAnimatorDraw (std::shared_ptr< FramePipeline > pipeline) override |
void | OnAnimatorDrawLastLayerTrees (std::unique_ptr< FrameTimingsRecorder > frame_timings_recorder) override |
void | OnEngineUpdateSemantics (SemanticsNodeUpdates update, CustomAccessibilityActionUpdates actions) override |
When the accessibility tree has been updated by the Flutter application, this new information needs to be conveyed to the underlying platform. The engine delegates this task to the shell via this call. The engine cannot access the underlying platform directly because of threading considerations. Most platform specific APIs to convey accessibility information are only safe to access on the platform task runner while the engine is running on the UI task runner. | |
void | OnEngineHandlePlatformMessage (std::unique_ptr< PlatformMessage > message) override |
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 engine delegates this task to the shell via this method. | |
void | OnPreEngineRestart () override |
Notifies the delegate that the root isolate of the application is about to be discarded and a new isolate with the same runtime started in its place. This should only happen in the Flutter "debug" runtime mode in the cold-restart scenario. The embedder may need to reset native resource in response to the restart. | |
void | OnRootIsolateCreated () override |
Notifies the shell that the root isolate is created. Currently, this information is to add to 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. | |
void | UpdateIsolateDescription (const std::string isolate_name, int64_t isolate_port) override |
Notifies the shell 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 PlatformDispatcher.setIsolateDebugName in platform_dispatcher.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. | |
void | SetNeedsReportTimings (bool value) override |
Notifies the shell 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. | |
std::unique_ptr< std::vector< std::string > > | ComputePlatformResolvedLocale (const std::vector< std::string > &supported_locale_data) override |
Directly invokes platform-specific APIs to compute the locale the platform would have natively resolved to. | |
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 | |
fml::TimePoint | GetCurrentTimePoint () override |
Returns the current fml::TimePoint. This method is primarily provided to allow tests to control Any methods that rely on advancing the clock. | |
void | OnEngineChannelUpdate (std::string name, bool listening) override |
Invoked when a listener is registered on a platform channel. | |
double | GetScaledFontSize (double unscaled_font_size, int configuration_id) const override |
Synchronously invokes platform-specific APIs to apply the system text scaling on the given unscaled font size. | |
void | OnFrameRasterized (const FrameTiming &) override |
Notifies the delegate that a frame has been rendered. The rasterizer collects profiling information for each part of the frame workload. This profiling information is made available to the delegate for forwarding to subsystems interested in collecting such profiles. Currently, the shell (the delegate) forwards this to the engine where Dart code can react to this information. | |
fml::Milliseconds | GetFrameBudget () override |
fml::TimePoint | GetLatestFrameTargetTime () const override |
bool | ShouldDiscardLayerTree (int64_t view_id, const flutter::LayerTree &tree) override |
fml::RefPtr< fml::TaskRunner > | GetServiceProtocolHandlerTaskRunner (std::string_view method) const override |
bool | HandleServiceProtocolMessage (std::string_view method, const ServiceProtocolMap ¶ms, rapidjson::Document *response) override |
ServiceProtocol::Handler::Description | GetServiceProtocolDescription () const override |
size_t | GetResourceCacheLimit () override |
Friends | |
class | testing::ShellTest |
Additional Inherited Members | |
Protected Member Functions inherited from flutter::ResourceCacheLimitItem | |
virtual | ~ResourceCacheLimitItem ()=default |
Perhaps the single most important class in the Flutter engine repository. When embedders create a Flutter application, they are referring to the creation of an instance of a shell. Creation and destruction of the shell is synchronous and the embedder only holds a unique pointer to the shell. The shell does not create the threads its primary components run on. Instead, it is the embedder's responsibility to create threads and give the shell task runners for those threads. Due to deterministic destruction of the shell, the embedder can terminate all threads immediately after collecting the shell. The shell must be created and destroyed on the same thread, but, different shells (i.e. a separate instances of a Flutter application) may be run on different threads simultaneously. The task runners themselves do not have to be unique. If all task runner references given to the shell during shell creation point to the same task runner, the Flutter application is effectively single threaded.
The shell is the central nervous system of the Flutter application. None of the shell components are thread safe and must be created, accessed and destroyed on the same thread. To interact with one another, the various components delegate to the shell for communication. Instead of using back pointers to the shell, a delegation pattern is used by all components that want to communicate with one another. Because of this, the shell implements the delegate interface for all these components.
All shell methods accessed by the embedder may only be called on the platform task runner. In case the embedder wants to directly access a shell subcomponent, it is the embedder's responsibility to acquire a weak pointer to that component and post a task to the task runner used by the component to access its methods. The shell must also be destroyed on the platform task runner.
There is no explicit API to bootstrap and shutdown the Dart VM. The first instance of the shell in the process bootstraps the Dart VM and the destruction of the last shell instance destroys the same. Since different shells may be created and destroyed on different threads. VM bootstrap may happen on one thread but its collection on another. This behavior is thread safe.
using flutter::Shell::CreateCallback = std::function<std::unique_ptr<T>(Shell&)> |
typedef std::function<std::unique_ptr<Engine>( Engine::Delegate& delegate, const PointerDataDispatcherMaker& dispatcher_maker, DartVM& vm, fml::RefPtr<const DartSnapshot> isolate_snapshot, TaskRunners task_runners, const PlatformData& platform_data, Settings settings, std::unique_ptr<Animator> animator, fml::WeakPtr<IOManager> io_manager, fml::RefPtr<SkiaUnrefQueue> unref_queue, fml::TaskRunnerAffineWeakPtr<SnapshotDelegate> snapshot_delegate, std::shared_ptr<VolatilePathTracker> volatile_path_tracker, const std::shared_ptr<fml::SyncSwitch>& gpu_disabled_switch, impeller::RuntimeStageBackend runtime_stage_type)> flutter::Shell::EngineCreateCallback |
flutter::Shell::~Shell | ( | ) |
Destroys the shell. This is a synchronous operation and synchronous barrier blocks are introduced on the various threads to ensure shutdown of all shell sub-components before this method returns.
Definition at line 527 of file shell.cc.
|
overrideprivatevirtual |
Directly invokes platform-specific APIs to compute the locale the platform would have natively resolved to.
[in] | supported_locale_data | The vector of strings that represents the locales supported by the app. Each locale consists of three strings: languageCode, countryCode, and scriptCode in that order. |
Implements flutter::Engine::Delegate.
Definition at line 1475 of file shell.cc.
|
static |
Creates a shell instance using the provided settings. The callbacks to create the various shell subcomponents will be called on the appropriate threads before this method returns. If this is the first instance of a shell in the process, this call also bootstraps the Dart VM.
[in] | task_runners | The task runners |
[in] | settings | The settings |
[in] | on_create_platform_view | The callback that must return a platform view. This will be called on the platform task runner before this method returns. |
[in] | on_create_rasterizer | That callback that must provide a valid rasterizer. This will be called on the render task runner before this method returns. |
[in] | is_gpu_disabled | The default value for the switch that turns off the GPU. |
Definition at line 167 of file shell.cc.
bool flutter::Shell::EngineHasLivePorts | ( | ) | const |
Used by embedders to check if the Engine is running and has any live ports remaining. For example, the Flutter tester uses this method to check whether it should continue to wait for a running test or not.
Definition at line 713 of file shell.cc.
const std::shared_ptr< fml::ConcurrentTaskRunner > flutter::Shell::GetConcurrentWorkerTaskRunner | ( | ) | const |
Definition at line 2316 of file shell.cc.
|
overrideprivatevirtual |
Returns the current fml::TimePoint. This method is primarily provided to allow tests to control Any methods that rely on advancing the clock.
Implements flutter::Engine::Delegate.
Definition at line 2299 of file shell.cc.
DartVM * flutter::Shell::GetDartVM | ( | ) |
fml::WeakPtr< Engine > flutter::Shell::GetEngine | ( | ) |
Engines may only be accessed on the UI thread. This method is deprecated, and implementers should instead use other API available on the Shell or the PlatformView.
|
overrideprivatevirtual |
Time limit for a smooth frame.
See: DisplayManager::GetMainDisplayRefreshRate
.
Implements flutter::Rasterizer::Delegate.
Definition at line 1628 of file shell.cc.
fml::WeakPtr< ShellIOManager > flutter::Shell::GetIOManager | ( | ) |
The IO Manager may only be accessed on the IO task runner.
|
overridevirtual |
Accessor for the disable GPU SyncSwitch.
Implements flutter::Rasterizer::Delegate.
Definition at line 2249 of file shell.cc.
|
overrideprivatevirtual |
Target time for the latest frame. See also Shell::OnAnimatorBeginFrame
for when this time gets updated.
Implements flutter::Rasterizer::Delegate.
Definition at line 1637 of file shell.cc.
double flutter::Shell::GetMainDisplayRefreshRate | ( | ) |
Queries the DisplayManager
for the main display refresh rate.
Definition at line 1862 of file shell.cc.
|
overridevirtual |
Getting the raster thread merger from parent shell, it can be a null RefPtr when it's a root Shell or the embedder_->SupportsDynamicThreadMerging() returns false.
Implements flutter::Rasterizer::Delegate.
Definition at line 803 of file shell.cc.
|
overridevirtual |
Returns the delegate object that handles PlatformMessage's from Flutter to the host platform (and its responses).
Implements flutter::Engine::Delegate.
Definition at line 2304 of file shell.cc.
fml::WeakPtr< PlatformView > flutter::Shell::GetPlatformView | ( | ) |
Platform views may only be accessed on the platform task runner.
fml::TaskRunnerAffineWeakPtr< Rasterizer > flutter::Shell::GetRasterizer | ( | ) | const |
Rasterizers may only be accessed on the raster task runner.
|
inlineoverrideprivatevirtual |
Implements flutter::ResourceCacheLimitItem.
Definition at line 778 of file shell.h.
|
overrideprivatevirtual |
Synchronously invokes platform-specific APIs to apply the system text scaling on the given unscaled font size.
Platforms that support this feature (currently it's only implemented for Android SDK level 34+) will send a valid configuration_id to potential callers, before this method can be called.
[in] | unscaled_font_size | The unscaled font size specified by the app developer. The value is in logical pixels, and is guaranteed to be finite and non-negative. |
[in] | configuration_id | The unique id of the configuration to use for computing the scaled font size. |
Implements flutter::Engine::Delegate.
Definition at line 1534 of file shell.cc.
|
overrideprivatevirtual |
Implements flutter::ServiceProtocol::Handler.
Definition at line 1679 of file shell.cc.
|
overrideprivatevirtual |
Implements flutter::ServiceProtocol::Handler.
Definition at line 1656 of file shell.cc.
|
overridevirtual |
Implements flutter::Rasterizer::Delegate.
Definition at line 795 of file shell.cc.
|
overridevirtual |
If callers wish to interact directly with any shell subcomponents, they must (on the platform thread) obtain a task runner that the component is designed to run on and a weak pointer to that component. They may then post a task to that task runner, do the validity check on that task runner before performing any operation on that component. This accessor allows callers to access the task runners for this shell.
Implements flutter::Rasterizer::Delegate.
Definition at line 799 of file shell.cc.
std::optional< DartErrorCode > flutter::Shell::GetUIIsolateLastError | ( | ) | const |
Used by embedders to get the last error from the Dart UI Isolate, if one exists.
Definition at line 693 of file shell.cc.
const std::weak_ptr< VsyncWaiter > flutter::Shell::GetVsyncWaiter | ( | ) | const |
|
overrideprivatevirtual |
Implements flutter::ServiceProtocol::Handler.
Definition at line 1667 of file shell.cc.
|
static |
Definition at line 151 of file shell.cc.
bool flutter::Shell::IsSetup | ( | ) | const |
Used by embedders to check if all shell subcomponents are initialized. It is the embedder's responsibility to make this call before accessing any other shell method. A shell that is not set up must be discarded and another one created with updated settings.
Definition at line 724 of file shell.cc.
|
overrideprivatevirtual |
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. |
[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. |
Implements flutter::PlatformView::Delegate.
Definition at line 1480 of file shell.cc.
|
overrideprivatevirtual |
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. |
Implements flutter::PlatformView::Delegate.
Definition at line 1495 of file shell.cc.
void flutter::Shell::NotifyLowMemoryWarning | ( | ) | const |
Used by embedders to notify that there is a low memory warning. The shell will attempt to purge caches. Current, only the rasterizer cache is purged.
Definition at line 633 of file shell.cc.
|
overrideprivatevirtual |
Implements flutter::Animator::Delegate.
Definition at line 1225 of file shell.cc.
|
overrideprivatevirtual |
Implements flutter::Animator::Delegate.
Definition at line 1267 of file shell.cc.
|
overrideprivatevirtual |
Implements flutter::Animator::Delegate.
Definition at line 1290 of file shell.cc.
|
overrideprivatevirtual |
Implements flutter::Animator::Delegate.
Definition at line 1241 of file shell.cc.
|
overrideprivatevirtual |
Implements flutter::Animator::Delegate.
Definition at line 1251 of file shell.cc.
void flutter::Shell::OnDisplayUpdates | ( | std::vector< std::unique_ptr< Display > > | displays | ) |
Notifies the display manager of the updates.
Definition at line 2279 of file shell.cc.
|
overrideprivatevirtual |
Invoked when a listener is registered on a platform channel.
[in] | name | The name of the platform channel to which a listener has been registered or cleared. |
[in] | listening | Whether the listener has been set (true) or cleared (false). |
Implements flutter::Engine::Delegate.
Definition at line 1380 of file shell.cc.
|
overrideprivatevirtual |
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 engine delegates this task to the shell via this method.
[in] | message | The message from the Flutter application to send to the underlying platform. |
Implements flutter::Engine::Delegate.
Definition at line 1321 of file shell.cc.
|
overrideprivatevirtual |
When the accessibility tree has been updated by the Flutter application, this new information needs to be conveyed to the underlying platform. The engine delegates this task to the shell via this call. The engine cannot access the underlying platform directly because of threading considerations. Most platform specific APIs to convey accessibility information are only safe to access on the platform task runner while the engine is running on the UI task runner.
SemanticsNode
, SemanticsNodeUpdates
, CustomAccessibilityActionUpdates
, PlatformView::UpdateSemantics
[in] | updates | A map with the stable semantics node identifier as key and the node properties as the value. |
[in] | actions | A map with the stable semantics node identifier as key and the custom node action as the value. |
Implements flutter::Engine::Delegate.
Definition at line 1306 of file shell.cc.
|
overrideprivatevirtual |
Notifies the delegate that a frame has been rendered. The rasterizer collects profiling information for each part of the frame workload. This profiling information is made available to the delegate for forwarding to subsystems interested in collecting such profiles. Currently, the shell (the delegate) forwards this to the engine where Dart code can react to this information.
FrameTiming
[in] | frame_timing | Instrumentation information for each phase of the frame workload. |
Implements flutter::Rasterizer::Delegate.
Definition at line 1560 of file shell.cc.
|
overrideprivatevirtual |
Allocate resources for a new non-implicit view and inform Dart about the view, and on success, schedules a new frame.
After the operation, |callback| should be invoked with whether the operation is successful.
Adding |kFlutterImplicitViewId| or an existing view ID should result in failure.
[in] | view_id | The view ID of the new view. |
[in] | viewport_metrics | The initial viewport metrics for the view. |
[in] | callback | The callback that's invoked once the shell has attempted to add the view. |
Implements flutter::PlatformView::Delegate.
Definition at line 2117 of file shell.cc.
|
overrideprivatevirtual |
Notifies the delegate that the platform view was created with the given render surface. This surface is platform (iOS, Android) and client-rendering API (OpenGL, Software, Metal, Vulkan) specific. This is usually a sign to the rasterizer to set up and begin rendering to that surface.
[in] | surface | The surface |
Implements flutter::PlatformView::Delegate.
Definition at line 833 of file shell.cc.
|
overrideprivatevirtual |
Notifies the delegate that the platform view was destroyed. This is usually a sign to the rasterizer to suspend rendering a previously configured surface and collect any intermediate resources.
Implements flutter::PlatformView::Delegate.
Definition at line 924 of file shell.cc.
|
overrideprivatevirtual |
Notifies the delegate that the platform has dispatched a platform message from the embedder to the Flutter application. This message must be forwarded to the running isolate hosted by the engine on the UI thread.
[in] | message | The platform message to dispatch to the running root isolate. |
Implements flutter::PlatformView::Delegate.
Definition at line 1051 of file shell.cc.
|
overrideprivatevirtual |
Notifies the delegate that the platform view has encountered a pointer event. This pointer event needs to be forwarded to the running root isolate hosted by the engine on the UI thread.
[in] | packet | The pointer data packet containing multiple pointer events. |
Implements flutter::PlatformView::Delegate.
Definition at line 1084 of file shell.cc.
|
overrideprivatevirtual |
Notifies the delegate that the platform view has encountered an accessibility related action on the specified node. This event must be forwarded to the running root isolate hosted by the engine on the UI thread.
[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 | An optional list of argument that apply to the specified action. |
Implements flutter::PlatformView::Delegate.
Definition at line 1103 of file shell.cc.
|
overrideprivatevirtual |
Called by the platform view on the platform thread to get the settings object associated with the platform view instance.
Implements flutter::PlatformView::Delegate.
Definition at line 1220 of file shell.cc.
|
overrideprivatevirtual |
Notifies the delegate that the embedder has updated the contents of the texture with the specified identifier. Typically, Flutter will only render a frame if there is an updated layer tree. However, in cases where the layer tree is static but one of the externally composited textures has been updated by the embedder, the embedder needs to notify the rasterizer to render a new frame. In such cases, the existing layer tree may be reused with the frame composited with all updated external textures.
[in] | texture_id | The identifier of the texture that has been updated. |
Implements flutter::PlatformView::Delegate.
Definition at line 1176 of file shell.cc.
|
overrideprivate |
Definition at line 1145 of file shell.cc.
|
overrideprivatevirtual |
Deallocate resources for a removed view and inform Dart about the removal.
After the operation, |callback| should be invoked with whether the operation is successful.
Removing |kFlutterImplicitViewId| or an non-existent view ID should result in failure.
[in] | view_id | The view ID of the view to be removed. |
[in] | callback | The callback that's invoked once the shell has attempted to remove the view. |
Implements flutter::PlatformView::Delegate.
Definition at line 2138 of file shell.cc.
|
overrideprivatevirtual |
Notifies the delegate that the platform needs to schedule a frame to regenerate the layer tree and redraw the surface.
Implements flutter::PlatformView::Delegate.
Definition at line 998 of file shell.cc.
|
overrideprivatevirtual |
Notifies the delegate that the embedder has expressed an opinion about the features to enable in the accessibility tree.
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. |
Implements flutter::PlatformView::Delegate.
Definition at line 1132 of file shell.cc.
|
overrideprivatevirtual |
Notifies the delegate that the specified callback needs to be invoked after the rasterizer is done rendering the next frame. This callback will be called on the render thread and it is caller responsibility to perform any re-threading as necessary. Due to the asynchronous nature of rendering in Flutter, embedders usually add a placeholder over the contents in which Flutter is going to render when Flutter is first initialized. This callback may be used as a signal to remove that placeholder.
[in] | closure | The callback to execute on the next frame. |
Implements flutter::PlatformView::Delegate.
Definition at line 1207 of file shell.cc.
|
overrideprivatevirtual |
Notifies the delegate that the embedder has expressed an opinion about whether the accessibility tree needs to be enabled or disabled. This information needs to be forwarded to the root isolate running on the UI thread.
[in] | enabled | Whether the accessibility tree is enabled or disabled. |
Implements flutter::PlatformView::Delegate.
Definition at line 1119 of file shell.cc.
|
overrideprivatevirtual |
Notifies the delegate the viewport metrics of a view have been updated. The rasterizer will need to be reconfigured to render the frame in the updated viewport metrics.
[in] | view_id | The ID for the view that metrics describes. |
[in] | metrics | The updated viewport metrics. |
Implements flutter::PlatformView::Delegate.
Definition at line 1011 of file shell.cc.
|
overrideprivatevirtual |
Notifies the delegate that the embedder will no longer attempt to composite the specified texture within the layer tree. This allows the rasterizer to collect associated resources.
[in] | texture_id | The identifier of the texture to unregister. If the texture has not been previously registered, this call does nothing. |
Implements flutter::PlatformView::Delegate.
Definition at line 1161 of file shell.cc.
|
overrideprivatevirtual |
Notifies the delegate that the root isolate of the application is about to be discarded and a new isolate with the same runtime started in its place. This should only happen in the Flutter "debug" runtime mode in the cold-restart scenario. The embedder may need to reset native resource in response to the restart.
PlatformView::OnPreEngineRestart
Implements flutter::Engine::Delegate.
Definition at line 1428 of file shell.cc.
|
overrideprivatevirtual |
Notifies the shell that the root isolate is created. Currently, this information is to add to 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.
Implements flutter::Engine::Delegate.
Definition at line 1447 of file shell.cc.
void flutter::Shell::RegisterImageDecoder | ( | ImageGeneratorFactory | factory, |
int32_t | priority | ||
) |
Install a new factory that can match against and decode image data.
[in] | factory | Callback that produces ImageGenerator s for compatible input data. |
[in] | priority | The priority used to determine the order in which factories are tried. Higher values mean higher priority. The built-in Skia decoders are installed at priority 0, and so a priority > 0 takes precedent over the builtin decoders. When multiple decoders are added with the same priority, those which are added earlier take precedent. |
CreateCompatibleGenerator
Definition at line 1866 of file shell.cc.
bool flutter::Shell::ReloadSystemFonts | ( | ) |
Used by embedders to reload the system fonts in FontCollection. It also clears the cached font families and send system channel message to framework to rebuild affected widgets.
Definition at line 2234 of file shell.cc.
|
overrideprivatevirtual |
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.
[in] | loading_unit_id | The 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::Engine::Delegate.
Definition at line 1524 of file shell.cc.
void flutter::Shell::RunEngine | ( | RunConfiguration | run_configuration | ) |
Starts an isolate for the given RunConfiguration.
Definition at line 655 of file shell.cc.
void flutter::Shell::RunEngine | ( | RunConfiguration | run_configuration, |
const std::function< void(Engine::RunStatus)> & | result_callback | ||
) |
Starts an isolate for the given RunConfiguration. The result_callback will be called with the status of the operation.
Definition at line 659 of file shell.cc.
Rasterizer::Screenshot flutter::Shell::Screenshot | ( | Rasterizer::ScreenshotType | type, |
bool | base64_encode | ||
) |
Captures a screenshot and optionally Base64 encodes the data of the last layer tree rendered by the rasterizer in this shell.
[in] | type | The type of screenshot to capture. |
[in] | base64_encode | If the screenshot data should be base64 encoded. |
Definition at line 2171 of file shell.cc.
void flutter::Shell::SetGpuAvailability | ( | GpuAvailability | availability | ) |
Marks the GPU as available or unavailable.
Definition at line 2254 of file shell.cc.
|
overrideprivatevirtual |
Notifies the shell 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.
When the application indicates that frame times need to be reported, it collects this information till a specified number of data points are gathered. Then this information is sent back to Dart code via Engine::ReportTimings
.
This option is engine counterpart of the Window._setNeedsReportTimings
in window.dart
.
[in] | needs_reporting | If reporting information should be collected and send back to Dart. |
Implements flutter::Engine::Delegate.
|
overrideprivatevirtual |
Implements flutter::Rasterizer::Delegate.
Definition at line 1647 of file shell.cc.
std::unique_ptr< Shell > flutter::Shell::Spawn | ( | RunConfiguration | run_configuration, |
const std::string & | initial_route, | ||
const CreateCallback< PlatformView > & | on_create_platform_view, | ||
const CreateCallback< Rasterizer > & | on_create_rasterizer | ||
) | const |
Creates one Shell from another Shell where the created Shell takes the opportunity to share any internal components it can. This results is a Shell that has a smaller startup time cost and a smaller memory footprint than an Shell created with the Create function.
The new Shell is returned in a running state so RunEngine shouldn't be called again on the Shell. Once running, the second Shell is mostly independent from the original Shell and the original Shell doesn't need to keep running for the spawned Shell to keep functioning.
[in] | run_configuration | A RunConfiguration used to run the Isolate associated with this new Shell. It doesn't have to be the same configuration as the current Shell but it needs to be in the same snapshot or AOT. |
Definition at line 589 of file shell.cc.
|
overrideprivatevirtual |
Replaces the asset resolver handled by the engine's AssetManager of the specified type
with updated_asset_resolver
. The matching AssetResolver is removed and replaced with updated_asset_resolvers
.
AssetResolvers should be updated when the existing resolver becomes obsolete and a newer one becomes available that provides updated access to the same type of assets as the existing one. This update process is meant to be performed at runtime.
If a null resolver is provided, nothing will be done. If no matching resolver is found, the provided resolver will be added to the end of the AssetManager resolvers queue. The replacement only occurs with the first matching resolver. Any additional matching resolvers are untouched.
[in] | updated_asset_resolver | The asset resolver to replace the resolver of matching type with. |
[in] | type | The type of AssetResolver to update. Only resolvers of the specified type will be replaced by the updated resolver. |
Implements flutter::PlatformView::Delegate.
Definition at line 1508 of file shell.cc.
|
overrideprivatevirtual |
Notifies the shell 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 PlatformDispatcher.setIsolateDebugName
in platform_dispatcher.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.
[in] | isolate_name | The isolate name |
[in] | isolate_port | The isolate port |
Implements flutter::Engine::Delegate.
Definition at line 1464 of file shell.cc.
fml::Status flutter::Shell::WaitForFirstFrame | ( | fml::TimeDelta | timeout | ) |
Pauses the calling thread until the first frame is presented.
[in] | timeout | The duration to wait before timing out. If this duration would cause an overflow when added to std::chrono::steady_clock::now(), this method will wait indefinitely for the first frame. |
Definition at line 2206 of file shell.cc.
|
friend |