Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Classes | Public Types | Public Member Functions | Private Member Functions | List of all members
flutter::PlatformViewEmbedder Class Referencefinal

#include <platform_view_embedder.h>

Inheritance diagram for flutter::PlatformViewEmbedder:
flutter::PlatformView

Classes

class  EmbedderPlatformMessageHandler
 
struct  PlatformDispatchTable
 

Public Types

using UpdateSemanticsCallback = std::function< void(flutter::SemanticsNodeUpdates update, flutter::CustomAccessibilityActionUpdates actions)>
 
using PlatformMessageResponseCallback = std::function< void(std::unique_ptr< PlatformMessage >)>
 
using ComputePlatformResolvedLocaleCallback = std::function< std::unique_ptr< std::vector< std::string > >(const std::vector< std::string > &supported_locale_data)>
 
using OnPreEngineRestartCallback = std::function< void()>
 
using ChanneUpdateCallback = std::function< void(const std::string &, bool)>
 
- Public Types inherited from flutter::PlatformView
using AddViewCallback = std::function< void(bool added)>
 
using RemoveViewCallback = std::function< void(bool removed)>
 

Public Member Functions

 PlatformViewEmbedder (PlatformView::Delegate &delegate, const flutter::TaskRunners &task_runners, const EmbedderSurfaceSoftware::SoftwareDispatchTable &software_dispatch_table, PlatformDispatchTable platform_dispatch_table, std::shared_ptr< EmbedderExternalViewEmbedder > external_view_embedder)
 
 ~PlatformViewEmbedder () override
 
void UpdateSemantics (flutter::SemanticsNodeUpdates update, flutter::CustomAccessibilityActionUpdates actions) override
 Used by the framework to tell the embedder to apply the specified semantics node updates. The default implementation of this method does nothing.
 
void HandlePlatformMessage (std::unique_ptr< PlatformMessage > message) override
 Overridden by embedders to perform actions in response to platform messages sent from the framework to the embedder. Default implementation of this method simply returns an empty response.
 
std::shared_ptr< PlatformMessageHandlerGetPlatformMessageHandler () const override
 Specifies a delegate that will receive PlatformMessages from Flutter to the host platform.
 
- Public Member Functions inherited from flutter::PlatformView
 PlatformView (Delegate &delegate, const TaskRunners &task_runners)
 Creates a platform view with the specified delegate and task runner. The base class by itself does not do much but is suitable for use in test environments where full platform integration may not be necessary. The platform view may only be created, accessed and destroyed on the platform task runner.
 
virtual ~PlatformView ()
 Destroys the platform view. The platform view is owned by the shell and will be destroyed by the same on the platform tasks runner.
 
void DispatchPlatformMessage (std::unique_ptr< PlatformMessage > message)
 Used by embedders to dispatch a platform message to a running root isolate hosted by the engine. If an isolate is not running, the message is dropped. If there is no one on the other side listening on the channel, the message is dropped. When a platform message is dropped, any response handles associated with that message will be dropped as well. All users of platform messages must assume that message may not be delivered and/or their response handles may not be invoked. Platform messages are not buffered.
 
void DispatchSemanticsAction (int32_t node_id, SemanticsAction action, fml::MallocMapping args)
 Used by embedders to dispatch an accessibility action to a running isolate hosted by the engine.
 
virtual void SetSemanticsEnabled (bool enabled)
 Used by embedder to notify the running isolate hosted by the engine on the UI thread that the accessibility tree needs to be generated.
 
virtual void SetAccessibilityFeatures (int32_t flags)
 Used by the embedder to specify the features to enable in the accessibility tree generated by the isolate. This information is forwarded to the root isolate hosted by the engine on the UI thread.
 
void SetViewportMetrics (int64_t view_id, const ViewportMetrics &metrics)
 Used by embedders to specify the updated viewport metrics for a view. In response to this call, on the raster thread, the rasterizer may need to be reconfigured to the updated viewport dimensions. On the UI thread, the framework may need to start generating a new frame for the updated viewport metrics as well.
 
void NotifyCreated ()
 Used by embedders to notify the shell that a platform view has been created. This notification is used to create a rendering surface and pick the client rendering API to use to render into this surface. No frames will be scheduled or rendered before this call. The surface must remain valid till the corresponding call to NotifyDestroyed.
 
virtual void NotifyDestroyed ()
 Used by embedders to notify the shell that the platform view has been destroyed. This notification used to collect the rendering surface and all associated resources. Frame scheduling is also suspended.
 
void ScheduleFrame ()
 Used by embedders to schedule a frame. In response to this call, the framework may need to start generating a new frame.
 
void AddView (int64_t view_id, const ViewportMetrics &viewport_metrics, AddViewCallback callback)
 Used by embedders to notify the shell of a new non-implicit view.
 
void RemoveView (int64_t view_id, RemoveViewCallback callback)
 Used by embedders to notify the shell of a removed non-implicit view.
 
virtual void ReleaseResourceContext () const
 Used by the shell to notify the embedder that the resource context previously obtained via a call to CreateResourceContext() is being collected. The embedder is free to collect an platform specific resources associated with this context.
 
virtual PointerDataDispatcherMaker GetDispatcherMaker ()
 Returns a platform-specific PointerDataDispatcherMaker so the Engine can construct the PointerDataPacketDispatcher based on platforms.
 
fml::WeakPtr< PlatformViewGetWeakPtr () const
 Returns a weak pointer to the platform view. Since the platform view may only be created, accessed and destroyed on the platform thread, any access to the platform view from a non-platform task runner needs a weak pointer to the platform view along with a reference to the platform task runner. A task must be posted to the platform task runner with the weak pointer captured in the same. The platform view method may only be called in the posted task once the weak pointer validity has been checked. This method is used by callers to obtain that weak pointer.
 
void SetNextFrameCallback (const fml::closure &closure)
 Sets a callback that gets executed when the rasterizer renders the next frame. 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. The callback is executed on the render task runner and not the platform task runner. It is the embedder's responsibility to re-thread as necessary.
 
void DispatchPointerDataPacket (std::unique_ptr< PointerDataPacket > packet)
 Dispatches pointer events from the embedder to the framework. Each pointer data packet may contain multiple pointer input events. Each call to this method wakes up the UI thread.
 
void RegisterTexture (std::shared_ptr< flutter::Texture > texture)
 Used by the embedder to specify a texture that it wants 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.
 
void UnregisterTexture (int64_t texture_id)
 Used by the embedder to notify the rasterizer that it will no longer attempt to composite the specified texture within the layer tree. This allows the rasterizer to collect associated resources.
 
void MarkTextureFrameAvailable (int64_t texture_id)
 Used by the embedder to notify the rasterizer that the context of the previously registered texture have been updated. 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 re-composited with all updated external textures. Unlike the calls to register and unregister the texture, this call must be made each time a new texture frame is available.
 
virtual void RequestDartDeferredLibrary (intptr_t loading_unit_id)
 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
 
virtual 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.
 
virtual void LoadDartDeferredLibraryError (intptr_t loading_unit_id, const std::string error_message, bool transient)
 Indicates to the dart VM that the request to load a deferred library with the specified loading unit id has failed.
 
virtual void UpdateAssetResolverByType (std::unique_ptr< AssetResolver > updated_asset_resolver, AssetResolver::AssetResolverType type)
 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.
 
virtual std::unique_ptr< SnapshotSurfaceProducerCreateSnapshotSurfaceProducer ()
 Creates an object that produces surfaces suitable for raster snapshotting. The rasterizer will request this surface if no on screen surface is currently available when an application requests a snapshot, e.g. if Scene.toImage or Picture.toImage are called while the application is in the background.
 
const SettingsGetSettings () const
 Get the settings for this platform view instance.
 
virtual double GetScaledFontSize (double unscaled_font_size, int configuration_id) const
 Synchronously invokes platform-specific APIs to apply the system text scaling on the given unscaled font size.
 

Private Member Functions

std::unique_ptr< SurfaceCreateRenderingSurface () override
 
std::shared_ptr< ExternalViewEmbedderCreateExternalViewEmbedder () override
 
std::shared_ptr< impeller::ContextGetImpellerContext () const override
 
sk_sp< GrDirectContextCreateResourceContext () const override
 Used by the shell to obtain a Skia GPU context that is capable of operating on the IO thread. The context must be in the same share-group as the Skia GPU context used on the render thread. This context will always be used on the IO thread. Because it is in the same share-group as the separate render thread context, any GPU resources uploaded in this context will be visible to the render thread context (synchronization of GPU resources is managed by Skia).
 
std::unique_ptr< VsyncWaiterCreateVSyncWaiter () override
 Invoked by the shell to obtain a platform specific vsync waiter. It is optional for platforms to override this method and provide a custom vsync waiter because a timer based fall-back waiter is used by default. However, it is highly recommended that platform provide their own Vsync waiter as the timer based fall-back will not render frames aligned with vsync boundaries.
 
void OnPreEngineRestart () const override
 Gives embedders a chance to react to a "cold restart" of the running isolate. The default implementation of this method does nothing.
 
std::unique_ptr< std::vector< std::string > > ComputePlatformResolvedLocales (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 SendChannelUpdate (const std::string &name, bool listening) override
 Used by the framework to tell the embedder that it has registered a listener on a given channel.
 

Additional Inherited Members

- Protected Attributes inherited from flutter::PlatformView
PlatformView::Delegatedelegate_
 
const TaskRunners task_runners_
 
PointerDataPacketConverter pointer_data_packet_converter_
 
fml::WeakPtrFactory< PlatformViewweak_factory_
 

Detailed Description

Definition at line 33 of file platform_view_embedder.h.

Member Typedef Documentation

◆ ChanneUpdateCallback

using flutter::PlatformViewEmbedder::ChanneUpdateCallback = std::function<void(const std::string&, bool)>

Definition at line 44 of file platform_view_embedder.h.

◆ ComputePlatformResolvedLocaleCallback

using flutter::PlatformViewEmbedder::ComputePlatformResolvedLocaleCallback = std::function<std::unique_ptr<std::vector<std::string> >( const std::vector<std::string>& supported_locale_data)>

Definition at line 40 of file platform_view_embedder.h.

◆ OnPreEngineRestartCallback

Definition at line 43 of file platform_view_embedder.h.

◆ PlatformMessageResponseCallback

Definition at line 38 of file platform_view_embedder.h.

◆ UpdateSemanticsCallback

Definition at line 35 of file platform_view_embedder.h.

Constructor & Destructor Documentation

◆ PlatformViewEmbedder()

flutter::PlatformViewEmbedder::PlatformViewEmbedder ( PlatformView::Delegate delegate,
const flutter::TaskRunners task_runners,
const EmbedderSurfaceSoftware::SoftwareDispatchTable software_dispatch_table,
PlatformDispatchTable  platform_dispatch_table,
std::shared_ptr< EmbedderExternalViewEmbedder external_view_embedder 
)

Definition at line 48 of file platform_view_embedder.cc.

55 : PlatformView(delegate, task_runners),
56 external_view_embedder_(std::move(external_view_embedder)),
57 embedder_surface_(
58 std::make_unique<EmbedderSurfaceSoftware>(software_dispatch_table,
59 external_view_embedder_)),
60 platform_message_handler_(new EmbedderPlatformMessageHandler(
61 GetWeakPtr(),
62 task_runners.GetPlatformTaskRunner())),
63 platform_dispatch_table_(std::move(platform_dispatch_table)) {}
PlatformView(Delegate &delegate, const TaskRunners &task_runners)
Creates a platform view with the specified delegate and task runner. The base class by itself does no...
fml::WeakPtr< PlatformView > GetWeakPtr() const
Returns a weak pointer to the platform view. Since the platform view may only be created,...
fml::RefPtr< fml::TaskRunner > GetPlatformTaskRunner() const

◆ ~PlatformViewEmbedder()

flutter::PlatformViewEmbedder::~PlatformViewEmbedder ( )
overridedefault

Member Function Documentation

◆ ComputePlatformResolvedLocales()

std::unique_ptr< std::vector< std::string > > flutter::PlatformViewEmbedder::ComputePlatformResolvedLocales ( const std::vector< std::string > &  supported_locale_data)
overrideprivatevirtual

Directly invokes platform-specific APIs to compute the locale the platform would have natively resolved to.

Parameters
[in]supported_locale_dataThe vector of strings that represents the locales supported by the app. Each locale consists of three strings: languageCode, countryCode, and scriptCode in that order.
Returns
A vector of 3 strings languageCode, countryCode, and scriptCode that represents the locale selected by the platform. Empty strings mean the value was unassigned. Empty vector represents a null locale.

Reimplemented from flutter::PlatformView.

Definition at line 183 of file platform_view_embedder.cc.

184 {
185 if (platform_dispatch_table_.compute_platform_resolved_locale_callback !=
186 nullptr) {
187 return platform_dispatch_table_.compute_platform_resolved_locale_callback(
188 supported_locale_data);
189 }
190 std::unique_ptr<std::vector<std::string>> out =
191 std::make_unique<std::vector<std::string>>();
192 return out;
193}
ComputePlatformResolvedLocaleCallback compute_platform_resolved_locale_callback

◆ CreateExternalViewEmbedder()

std::shared_ptr< ExternalViewEmbedder > flutter::PlatformViewEmbedder::CreateExternalViewEmbedder ( )
overrideprivatevirtual

Reimplemented from flutter::PlatformView.

Definition at line 152 of file platform_view_embedder.cc.

152 {
153 return external_view_embedder_;
154}

◆ CreateRenderingSurface()

std::unique_ptr< Surface > flutter::PlatformViewEmbedder::CreateRenderingSurface ( )
overrideprivatevirtual

Reimplemented from flutter::PlatformView.

Definition at line 142 of file platform_view_embedder.cc.

142 {
143 if (embedder_surface_ == nullptr) {
144 FML_LOG(ERROR) << "Embedder surface was null.";
145 return nullptr;
146 }
147 return embedder_surface_->CreateGPUSurface();
148}
#define FML_LOG(severity)
Definition logging.h:82
#define ERROR(message)

◆ CreateResourceContext()

sk_sp< GrDirectContext > flutter::PlatformViewEmbedder::CreateResourceContext ( ) const
overrideprivatevirtual

Used by the shell to obtain a Skia GPU context that is capable of operating on the IO thread. The context must be in the same share-group as the Skia GPU context used on the render thread. This context will always be used on the IO thread. Because it is in the same share-group as the separate render thread context, any GPU resources uploaded in this context will be visible to the render thread context (synchronization of GPU resources is managed by Skia).

If such context cannot be created on the IO thread, callers may return nullptr. This will mean that all texture uploads will be queued onto the render thread which will cause performance issues. When this context is nullptr, an error is logged to the console. It is highly recommended that all platforms provide a resource context.

Attention
Unlike all other methods on the platform view, this will be called on IO task runner.
Returns
The Skia GPU context that is in the same share-group as the main render thread GPU context. May be nullptr in case such a context cannot be created.

Reimplemented from flutter::PlatformView.

Definition at line 162 of file platform_view_embedder.cc.

162 {
163 if (embedder_surface_ == nullptr) {
164 FML_LOG(ERROR) << "Embedder surface was null.";
165 return nullptr;
166 }
167 return embedder_surface_->CreateResourceContext();
168}

◆ CreateVSyncWaiter()

std::unique_ptr< VsyncWaiter > flutter::PlatformViewEmbedder::CreateVSyncWaiter ( )
overrideprivatevirtual

Invoked by the shell to obtain a platform specific vsync waiter. It is optional for platforms to override this method and provide a custom vsync waiter because a timer based fall-back waiter is used by default. However, it is highly recommended that platform provide their own Vsync waiter as the timer based fall-back will not render frames aligned with vsync boundaries.

Attention
If a timer based fall-back is used, a warning is logged to the console. In case this method is overridden in a subclass, it must return a valid vsync waiter. Returning null will lead to internal errors. If a valid vsync waiter cannot be returned, subclasses should just call the based class method instead.
Returns
A vsync waiter. If is an internal error to return a null waiter.

Reimplemented from flutter::PlatformView.

Definition at line 171 of file platform_view_embedder.cc.

171 {
172 if (!platform_dispatch_table_.vsync_callback) {
173 // Superclass implementation creates a timer based fallback.
175 }
176
177 return std::make_unique<VsyncWaiterEmbedder>(
178 platform_dispatch_table_.vsync_callback, task_runners_);
179}
virtual std::unique_ptr< VsyncWaiter > CreateVSyncWaiter()
Invoked by the shell to obtain a platform specific vsync waiter. It is optional for platforms to over...
const TaskRunners task_runners_

◆ GetImpellerContext()

std::shared_ptr< impeller::Context > flutter::PlatformViewEmbedder::GetImpellerContext ( ) const
overrideprivatevirtual

Reimplemented from flutter::PlatformView.

Definition at line 156 of file platform_view_embedder.cc.

157 {
158 return embedder_surface_->CreateImpellerContext();
159}

◆ GetPlatformMessageHandler()

std::shared_ptr< PlatformMessageHandler > flutter::PlatformViewEmbedder::GetPlatformMessageHandler ( ) const
overridevirtual

Specifies a delegate that will receive PlatformMessages from Flutter to the host platform.

If this returns null that means PlatformMessages should be sent to the PlatformView. That is to protect legacy behavior, any embedder that wants to support executing Platform Channel handlers on background threads should be returning a thread-safe PlatformMessageHandler instead.

Reimplemented from flutter::PlatformView.

Definition at line 211 of file platform_view_embedder.cc.

211 {
212 return platform_message_handler_;
213}

◆ HandlePlatformMessage()

void flutter::PlatformViewEmbedder::HandlePlatformMessage ( std::unique_ptr< PlatformMessage message)
overridevirtual

Overridden by embedders to perform actions in response to platform messages sent from the framework to the embedder. Default implementation of this method simply returns an empty response.

Embedders that wish to send platform messages to the framework may use the DispatchPlatformMessage method. This method is for messages that go the other way.

See also
DispatchPlatformMessage()
Parameters
[in]messageThe message

Reimplemented from flutter::PlatformView.

Definition at line 124 of file platform_view_embedder.cc.

125 {
126 if (!message) {
127 return;
128 }
129
130 if (platform_dispatch_table_.platform_message_response_callback == nullptr) {
131 if (message->response()) {
132 message->response()->CompleteEmpty();
133 }
134 return;
135 }
136
137 platform_dispatch_table_.platform_message_response_callback(
138 std::move(message));
139}
Win32Message message
PlatformMessageResponseCallback platform_message_response_callback

◆ OnPreEngineRestart()

void flutter::PlatformViewEmbedder::OnPreEngineRestart ( ) const
overrideprivatevirtual

Gives embedders a chance to react to a "cold restart" of the running isolate. The default implementation of this method does nothing.

While a "hot restart" patches a running isolate, a "cold restart" restarts the root isolate in a running shell.

Reimplemented from flutter::PlatformView.

Definition at line 196 of file platform_view_embedder.cc.

196 {
197 if (platform_dispatch_table_.on_pre_engine_restart_callback != nullptr) {
198 platform_dispatch_table_.on_pre_engine_restart_callback();
199 }
200}

◆ SendChannelUpdate()

void flutter::PlatformViewEmbedder::SendChannelUpdate ( const std::string &  name,
bool  listening 
)
overrideprivatevirtual

Used by the framework to tell the embedder that it has registered a listener on a given channel.

Parameters
[in]nameThe name of the channel on which the listener has set or cleared a listener.
[in]listeningTrue if a listener has been set, false if it has been cleared.

Reimplemented from flutter::PlatformView.

Definition at line 203 of file platform_view_embedder.cc.

204 {
205 if (platform_dispatch_table_.on_channel_update != nullptr) {
206 platform_dispatch_table_.on_channel_update(name, listening);
207 }
208}
DEF_SWITCHES_START aot vmservice shared library name
Definition switches.h:32

◆ UpdateSemantics()

void flutter::PlatformViewEmbedder::UpdateSemantics ( flutter::SemanticsNodeUpdates  updates,
flutter::CustomAccessibilityActionUpdates  actions 
)
overridevirtual

Used by the framework to tell the embedder to apply the specified semantics node updates. The default implementation of this method does nothing.

See also
SemanticsNode, SemticsNodeUpdates, CustomAccessibilityActionUpdates
Parameters
[in]updatesA map with the stable semantics node identifier as key and the node properties as the value.
[in]actionsA map with the stable semantics node identifier as key and the custom node action as the value.

Reimplemented from flutter::PlatformView.

Definition at line 115 of file platform_view_embedder.cc.

117 {
118 if (platform_dispatch_table_.update_semantics_callback != nullptr) {
119 platform_dispatch_table_.update_semantics_callback(std::move(update),
120 std::move(actions));
121 }
122}

The documentation for this class was generated from the following files: