#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, const std::shared_ptr< fml::SyncSwitch > &gpu_disabled_switch, const std::shared_future< impeller::RuntimeStageBackend > &runtime_stage_backend)> | 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::TaskRunnerAffineWeakPtr< 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. | |
| void | FlushMicrotaskQueue () const |
| Used by embedders to flush the microtask queue. Required when running with merged platform and UI threads, in which case the embedder is responsible for flushing the microtask queue. | |
| 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. | |
| bool | EngineHasPendingMicrotasks () const |
| Used by embedders to check if the Engine is running and has any microtasks that have been queued but have not yet run. The Flutter tester uses this as a signal that a test is still running. | |
| 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) |
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, const std::shared_ptr<fml::SyncSwitch>& gpu_disabled_switch, const std::shared_future<impeller::RuntimeStageBackend>& runtime_stage_backend)> 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 591 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 221 of file shell.cc.
References InferVmInitDataFromSettings(), flutter::Settings::resource_cache_max_bytes_threshold, and TRACE_EVENT0.
Referenced by flutter::AndroidShellHolder::AndroidShellHolder(), flutter::EmbedderEngine::LaunchShell(), flutter::RunTester(), flutter::StartupAndShutdownShell(), flutter::testing::TEST_F(), and flutter::testing::TEST_F().
| 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 812 of file shell.cc.
Referenced by flutter::ScriptCompletionTaskObserver::DidProcessTask().
| bool flutter::Shell::EngineHasPendingMicrotasks | ( | ) | const |
Used by embedders to check if the Engine is running and has any microtasks that have been queued but have not yet run. The Flutter tester uses this as a signal that a test is still running.
Definition at line 823 of file shell.cc.
Referenced by flutter::ScriptCompletionTaskObserver::DidProcessTask().
| void flutter::Shell::FlushMicrotaskQueue | ( | ) | const |
| const std::shared_ptr< fml::ConcurrentTaskRunner > flutter::Shell::GetConcurrentWorkerTaskRunner | ( | ) | const |
| DartVM * flutter::Shell::GetDartVM | ( | ) |
Get a pointer to the Dart VM used by this running shell instance.
Definition at line 940 of file shell.cc.
Referenced by flutter::testing::TEST_F().
| fml::TaskRunnerAffineWeakPtr< 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.
Definition at line 925 of file shell.cc.
| fml::WeakPtr< ShellIOManager > flutter::Shell::GetIOManager | ( | ) |
|
overridevirtual |
Accessor for the disable GPU SyncSwitch.
Implements flutter::Rasterizer::Delegate.
Definition at line 2351 of file shell.cc.
Referenced by flutter::testing::ShellTestPlatformViewBuilder::operator()(), flutter::testing::TEST_F(), and flutter::testing::TEST_F().
| double flutter::Shell::GetMainDisplayRefreshRate | ( | ) |
Queries the DisplayManager for the main display refresh rate.
Definition at line 2031 of file shell.cc.
References FML_DCHECK, flutter::TaskRunners::GetUITaskRunner(), and fml::TaskRunner::RunsTasksOnCurrentThread().
Referenced by flutter::testing::TEST_F(), flutter::testing::TEST_F(), and flutter::testing::TEST_F().
|
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 915 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.
| fml::WeakPtr< PlatformView > flutter::Shell::GetPlatformView | ( | ) |
Platform views may only be accessed on the platform task runner.
Definition at line 930 of file shell.cc.
Referenced by flutter::ConfigureShell(), flutter::testing::ShellTest::DispatchPointerData(), FlutterEngineSetNextFrameCallback(), flutter::RunTester(), flutter::testing::TEST_F(), and flutter::testing::ShellTest::VSyncFlush().
| fml::TaskRunnerAffineWeakPtr< Rasterizer > flutter::Shell::GetRasterizer | ( | ) | const |
Rasterizers may only be accessed on the raster task runner.
Definition at line 920 of file shell.cc.
Referenced by flutter::testing::TEST_F(), and flutter::testing::TEST_F().
|
overridevirtual |
Implements flutter::Rasterizer::Delegate.
Definition at line 907 of file shell.cc.
References flutter::PersistentCache::GetCacheForProcess(), and flutter::PersistentCache::Purge().
Referenced by flutter::testing::TEST_F(), and flutter::testing::TEST_F().
|
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 911 of file shell.cc.
Referenced by flutter::testing::ShellTest::DispatchPointerData(), flutter::testing::GetRasterizerResourceCacheBytesSync(), InferMetalPlatformViewCreationCallback(), InferOpenGLPlatformViewCreationCallback(), InferSoftwarePlatformViewCreationCallback(), InferVulkanPlatformViewCreationCallback(), flutter::testing::ShellTest::NotifyIdle(), flutter::testing::ShellTestPlatformViewBuilder::operator()(), flutter::testing::ShellTest::PlatformViewNotifyCreated(), flutter::testing::ShellTest::PlatformViewNotifyDestroyed(), flutter::testing::ShellTest::PumpOneFrame(), flutter::testing::RasterizerIsTornDown(), flutter::testing::ShellTest::RestartEngine(), flutter::testing::ShellTest::RunEngine(), flutter::RunTester(), flutter::testing::ShellTest::SendEnginePlatformMessage(), flutter::testing::ShellTest::SetViewportMetrics(), flutter::Spawn(), flutter::StartupAndShutdownShell(), flutter::testing::TEST_F(), flutter::testing::TEST_F(), flutter::testing::TEST_F(), flutter::testing::TEST_F(), flutter::testing::TEST_F(), flutter::testing::ValidateShell(), and flutter::testing::ShellTest::VSyncFlush().
| 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 792 of file shell.cc.
Referenced by flutter::ScriptCompletionTaskObserver::DidProcessTask().
| const std::weak_ptr< VsyncWaiter > flutter::Shell::GetVsyncWaiter | ( | ) | const |
Definition at line 2410 of file shell.cc.
References fml::TimePoint::Now().
|
static |
Definition at line 205 of file shell.cc.
References flutter::DartVMRef::Create(), flutter::DartSnapshot::IsolateSnapshotFromSettings(), and flutter::DartSnapshot::VMSnapshotFromSettings().
Referenced by Create().
| 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 834 of file shell.cc.
Referenced by flutter::RunTester(), flutter::testing::ValidateDestroyPlatformView(), and flutter::testing::ValidateShell().
| 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 726 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 2381 of file shell.cc.
Referenced by flutter::ConfigureShell().
| 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 ImageGenerators 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 2035 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 2336 of file shell.cc.
| void flutter::Shell::RunEngine | ( | RunConfiguration | run_configuration | ) |
Starts an isolate for the given RunConfiguration.
Definition at line 754 of file shell.cc.
Referenced by flutter::RunTester().
| 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 758 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 2273 of file shell.cc.
| void flutter::Shell::SetGpuAvailability | ( | GpuAvailability | availability | ) |
Marks the GPU as available or unavailable.
Definition at line 2356 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 672 of file shell.cc.
Referenced by flutter::Spawn().
| 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 2308 of file shell.cc.
|
friend |