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

#include <shell_test_platform_view_metal.h>

Inheritance diagram for flutter::testing::ShellTestPlatformViewMetal:
flutter::testing::ShellTestPlatformView flutter::GPUSurfaceMetalDelegate flutter::PlatformView

Public Member Functions

 ShellTestPlatformViewMetal (PlatformView::Delegate &delegate, const TaskRunners &task_runners, std::shared_ptr< ShellTestVsyncClock > vsync_clock, CreateVsyncWaiter create_vsync_waiter, std::shared_ptr< ShellTestExternalViewEmbedder > shell_test_external_view_embedder, const std::shared_ptr< const fml::SyncSwitch > &is_gpu_disabled_sync_switch)
 
virtual ~ShellTestPlatformViewMetal () override
 
- 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.
 
virtual void HandlePlatformMessage (std::unique_ptr< PlatformMessage > message)
 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.
 
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.
 
virtual void UpdateSemantics (SemanticsNodeUpdates updates, CustomAccessibilityActionUpdates actions)
 Used by the framework to tell the embedder to apply the specified semantics node updates. The default implementation of this method does nothing.
 
virtual void SendChannelUpdate (const std::string &name, bool listening)
 Used by the framework to tell the embedder that it has registered a listener on a given channel.
 
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 sk_sp< GrDirectContextCreateResourceContext () const
 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).
 
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.
 
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.
 
virtual void OnPreEngineRestart () const
 Gives embedders a chance to react to a "cold restart" of the running isolate. The default implementation of this method does nothing.
 
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 std::unique_ptr< std::vector< std::string > > ComputePlatformResolvedLocales (const std::vector< std::string > &supported_locale_data)
 Directly invokes platform-specific APIs to compute the locale the platform would have natively resolved to.
 
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.
 
virtual std::shared_ptr< PlatformMessageHandlerGetPlatformMessageHandler () const
 Specifies a delegate that will receive PlatformMessages from Flutter to the host platform.
 
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.
 
- Public Member Functions inherited from flutter::GPUSurfaceMetalDelegate
 GPUSurfaceMetalDelegate (MTLRenderTargetType render_target)
 Construct a new GPUSurfaceMetalDelegate object with the specified render_target type.
 
virtual ~GPUSurfaceMetalDelegate ()
 
virtual bool AllowsDrawingWhenGpuDisabled () const
 Whether to allow drawing to the surface when the GPU is disabled.
 
MTLRenderTargetType GetRenderTargetType ()
 

Private Member Functions

virtual void SimulateVSync () override
 
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.
 
std::shared_ptr< ExternalViewEmbedderCreateExternalViewEmbedder () override
 
PointerDataDispatcherMaker GetDispatcherMaker () override
 Returns a platform-specific PointerDataDispatcherMaker so the Engine can construct the PointerDataPacketDispatcher based on platforms.
 
std::unique_ptr< SurfaceCreateRenderingSurface () override
 
std::shared_ptr< impeller::ContextGetImpellerContext () const override
 
GPUCAMetalLayerHandle GetCAMetalLayer (const SkISize &frame_info) const override
 Returns the handle to the CAMetalLayer to render to. This is only called when the specified render target type is kCAMetalLayer.
 
bool PresentDrawable (GrMTLHandle drawable) const override
 Presents the drawable to the "screen". The drawable is obtained from the CAMetalLayer that given by GetCAMetalLayer call. This is only called when the specified render target type in kCAMetalLayer.
 
GPUMTLTextureInfo GetMTLTexture (const SkISize &frame_info) const override
 Returns the handle to the MTLTexture to render to. This is only called when the specified render target type is kMTLTexture.
 
bool PresentTexture (GPUMTLTextureInfo texture) const override
 Presents the texture with texture_id to the "screen". texture_id corresponds to a texture that has been obtained by an earlier call to GetMTLTexture. This is only called when the specified render target type is kMTLTexture.
 

Additional Inherited Members

- Public Types inherited from flutter::testing::ShellTestPlatformView
enum class  BackendType { kDefaultBackend = 0 , kGLBackend , kVulkanBackend , kMetalBackend }
 
- Public Types inherited from flutter::PlatformView
using AddViewCallback = std::function< void(bool added)>
 
using RemoveViewCallback = std::function< void(bool removed)>
 
- Static Public Member Functions inherited from flutter::testing::ShellTestPlatformView
static std::unique_ptr< ShellTestPlatformViewCreate (PlatformView::Delegate &delegate, const TaskRunners &task_runners, const std::shared_ptr< ShellTestVsyncClock > &vsync_clock, const CreateVsyncWaiter &create_vsync_waiter, BackendType backend, const std::shared_ptr< ShellTestExternalViewEmbedder > &shell_test_external_view_embedder, const std::shared_ptr< const fml::SyncSwitch > &is_gpu_disabled_sync_switch)
 
- Protected Member Functions inherited from flutter::testing::ShellTestPlatformView
 ShellTestPlatformView (PlatformView::Delegate &delegate, const TaskRunners &task_runners)
 
 FML_DISALLOW_COPY_AND_ASSIGN (ShellTestPlatformView)
 
- 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 17 of file shell_test_platform_view_metal.h.

Constructor & Destructor Documentation

◆ ShellTestPlatformViewMetal()

flutter::testing::ShellTestPlatformViewMetal::ShellTestPlatformViewMetal ( PlatformView::Delegate delegate,
const TaskRunners task_runners,
std::shared_ptr< ShellTestVsyncClock vsync_clock,
CreateVsyncWaiter  create_vsync_waiter,
std::shared_ptr< ShellTestExternalViewEmbedder shell_test_external_view_embedder,
const std::shared_ptr< const fml::SyncSwitch > &  is_gpu_disabled_sync_switch 
)

Definition at line 69 of file shell_test_platform_view_metal.mm.

76 : ShellTestPlatformView(delegate, task_runners),
78 metal_context_(std::make_unique<DarwinContextMetal>(GetSettings().enable_impeller,
79 is_gpu_disabled_sync_switch)),
80 create_vsync_waiter_(std::move(create_vsync_waiter)),
81 vsync_clock_(std::move(vsync_clock)),
82 shell_test_external_view_embedder_(std::move(shell_test_external_view_embedder)) {
83 if (GetSettings().enable_impeller) {
84 FML_CHECK([metal_context_->impeller_context() context] != nil);
85 } else {
86 FML_CHECK([metal_context_->context() mainContext] != nil);
87 }
88}
GPUSurfaceMetalDelegate(MTLRenderTargetType render_target)
Construct a new GPUSurfaceMetalDelegate object with the specified render_target type.
const Settings & GetSettings() const
Get the settings for this platform view instance.
ShellTestPlatformView(PlatformView::Delegate &delegate, const TaskRunners &task_runners)
#define FML_CHECK(condition)
Definition logging.h:85

◆ ~ShellTestPlatformViewMetal()

flutter::testing::ShellTestPlatformViewMetal::~ShellTestPlatformViewMetal ( )
overridevirtualdefault

Member Function Documentation

◆ CreateExternalViewEmbedder()

std::shared_ptr< ExternalViewEmbedder > flutter::testing::ShellTestPlatformViewMetal::CreateExternalViewEmbedder ( )
overrideprivatevirtual

Reimplemented from flutter::PlatformView.

Definition at line 102 of file shell_test_platform_view_metal.mm.

102 {
103 return shell_test_external_view_embedder_;
104}

◆ CreateRenderingSurface()

std::unique_ptr< Surface > flutter::testing::ShellTestPlatformViewMetal::CreateRenderingSurface ( )
overrideprivatevirtual

Reimplemented from flutter::PlatformView.

Definition at line 114 of file shell_test_platform_view_metal.mm.

114 {
115 if (GetSettings().enable_impeller) {
116 return std::make_unique<GPUSurfaceMetalImpeller>(this,
117 [metal_context_->impeller_context() context]);
118 }
119 return std::make_unique<GPUSurfaceMetalSkia>(this, [metal_context_->context() mainContext],
121}

◆ CreateVSyncWaiter()

std::unique_ptr< VsyncWaiter > flutter::testing::ShellTestPlatformViewMetal::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 92 of file shell_test_platform_view_metal.mm.

92 {
93 return create_vsync_waiter_();
94}

◆ GetCAMetalLayer()

GPUCAMetalLayerHandle flutter::testing::ShellTestPlatformViewMetal::GetCAMetalLayer ( const SkISize frame_info) const
overrideprivatevirtual

Returns the handle to the CAMetalLayer to render to. This is only called when the specified render target type is kCAMetalLayer.

Implements flutter::GPUSurfaceMetalDelegate.

Definition at line 129 of file shell_test_platform_view_metal.mm.

129 {
130 FML_CHECK(false) << "A Metal Delegate configured with MTLRenderTargetType::kMTLTexture was asked "
131 "to acquire a layer.";
132 return nullptr;
133}

◆ GetDispatcherMaker()

PointerDataDispatcherMaker flutter::testing::ShellTestPlatformViewMetal::GetDispatcherMaker ( )
overrideprivatevirtual

Returns a platform-specific PointerDataDispatcherMaker so the Engine can construct the PointerDataPacketDispatcher based on platforms.

Reimplemented from flutter::PlatformView.

Definition at line 107 of file shell_test_platform_view_metal.mm.

107 {
108 return [](DefaultPointerDataDispatcher::Delegate& delegate) {
109 return std::make_unique<SmoothPointerDataDispatcher>(delegate);
110 };
111}

◆ GetImpellerContext()

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

Reimplemented from flutter::PlatformView.

Definition at line 124 of file shell_test_platform_view_metal.mm.

124 {
125 return [metal_context_->impeller_context() context];
126}

◆ GetMTLTexture()

GPUMTLTextureInfo flutter::testing::ShellTestPlatformViewMetal::GetMTLTexture ( const SkISize frame_info) const
overrideprivatevirtual

Returns the handle to the MTLTexture to render to. This is only called when the specified render target type is kMTLTexture.

Implements flutter::GPUSurfaceMetalDelegate.

Definition at line 143 of file shell_test_platform_view_metal.mm.

143 {
144 return metal_context_->offscreen_texture_info();
145}

◆ PresentDrawable()

bool flutter::testing::ShellTestPlatformViewMetal::PresentDrawable ( GrMTLHandle  drawable) const
overrideprivatevirtual

Presents the drawable to the "screen". The drawable is obtained from the CAMetalLayer that given by GetCAMetalLayer call. This is only called when the specified render target type in kCAMetalLayer.

See also
|GPUSurfaceMetalDelegateGetCAMetalLayer|

Implements flutter::GPUSurfaceMetalDelegate.

Definition at line 136 of file shell_test_platform_view_metal.mm.

136 {
137 FML_CHECK(false) << "A Metal Delegate configured with MTLRenderTargetType::kMTLTexture was asked "
138 "to present a layer drawable.";
139 return true;
140}

◆ PresentTexture()

bool flutter::testing::ShellTestPlatformViewMetal::PresentTexture ( GPUMTLTextureInfo  texture) const
overrideprivatevirtual

Presents the texture with texture_id to the "screen". texture_id corresponds to a texture that has been obtained by an earlier call to GetMTLTexture. This is only called when the specified render target type is kMTLTexture.

See also
|GPUSurfaceMetalDelegateGetMTLTexture|

Implements flutter::GPUSurfaceMetalDelegate.

Definition at line 148 of file shell_test_platform_view_metal.mm.

148 {
149 // The texture resides offscreen. There is nothing to render to.
150 return true;
151}

◆ SimulateVSync()

void flutter::testing::ShellTestPlatformViewMetal::SimulateVSync ( )
overrideprivatevirtual

Implements flutter::testing::ShellTestPlatformView.

Definition at line 97 of file shell_test_platform_view_metal.mm.

97 {
98 vsync_clock_->SimulateVSync();
99}

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