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

#include <ios_surface_metal_skia.h>

Inheritance diagram for flutter::IOSSurfaceMetalSkia:
flutter::IOSSurface flutter::GPUSurfaceMetalDelegate

Public Member Functions

 IOSSurfaceMetalSkia (const fml::scoped_nsobject< CAMetalLayer > &layer, std::shared_ptr< IOSContext > context)
 
 ~IOSSurfaceMetalSkia ()
 
- Public Member Functions inherited from flutter::IOSSurface
std::shared_ptr< IOSContextGetContext () const
 
virtual ~IOSSurface ()
 
- Public Member Functions inherited from flutter::GPUSurfaceMetalDelegate
 GPUSurfaceMetalDelegate (MTLRenderTargetType render_target)
 Construct a new GPUSurfaceMetalDelegate object with the specified render_target type.
 
virtual ~GPUSurfaceMetalDelegate ()
 
MTLRenderTargetType GetRenderTargetType ()
 

Private Member Functions

bool IsValid () const override
 
void UpdateStorageSizeIfNecessary () override
 
std::unique_ptr< SurfaceCreateGPUSurface (GrDirectContext *gr_context) override
 
GPUCAMetalLayerHandle GetCAMetalLayer (const SkISize &frame_info) const override __attribute__((cf_audited_transfer))
 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 __attribute__((cf_audited_transfer))
 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 __attribute__((cf_audited_transfer))
 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 __attribute__((cf_audited_transfer))
 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.
 
bool AllowsDrawingWhenGpuDisabled () const override
 Whether to allow drawing to the surface when the GPU is disabled.
 

Additional Inherited Members

- Static Public Member Functions inherited from flutter::IOSSurface
static std::unique_ptr< IOSSurfaceCreate (std::shared_ptr< IOSContext > context, const fml::scoped_nsobject< CALayer > &layer)
 
- Protected Member Functions inherited from flutter::IOSSurface
 IOSSurface (std::shared_ptr< IOSContext > ios_context)
 

Detailed Description

Definition at line 17 of file ios_surface_metal_skia.h.

Constructor & Destructor Documentation

◆ IOSSurfaceMetalSkia()

flutter::IOSSurfaceMetalSkia::IOSSurfaceMetalSkia ( const fml::scoped_nsobject< CAMetalLayer > &  layer,
std::shared_ptr< IOSContext context 
)

Definition at line 24 of file ios_surface_metal_skia.mm.

26 : IOSSurface(std::move(context)),
28 layer_(layer) {
29 is_valid_ = layer_;
30 auto metal_context = CastToMetalContext(GetContext());
31 auto darwin_context = metal_context->GetDarwinContext().get();
32 command_queue_ = darwin_context.commandQueue;
33 device_ = darwin_context.device;
34}
GPUSurfaceMetalDelegate(MTLRenderTargetType render_target)
Construct a new GPUSurfaceMetalDelegate object with the specified render_target type.
IOSSurface(std::shared_ptr< IOSContext > ios_context)
std::shared_ptr< IOSContext > GetContext() const
static IOSContextMetalSkia * CastToMetalContext(const std::shared_ptr< IOSContext > &context) __attribute__((cf_audited_transfer))

◆ ~IOSSurfaceMetalSkia()

flutter::IOSSurfaceMetalSkia::~IOSSurfaceMetalSkia ( )
default

Member Function Documentation

◆ AllowsDrawingWhenGpuDisabled()

bool flutter::IOSSurfaceMetalSkia::AllowsDrawingWhenGpuDisabled ( ) const
overrideprivatevirtual

Whether to allow drawing to the surface when the GPU is disabled.

Reimplemented from flutter::GPUSurfaceMetalDelegate.

Definition at line 115 of file ios_surface_metal_skia.mm.

115 {
116 return false;
117}

◆ CreateGPUSurface()

std::unique_ptr< Surface > flutter::IOSSurfaceMetalSkia::CreateGPUSurface ( GrDirectContext gr_context)
overrideprivatevirtual

Implements flutter::IOSSurface.

Definition at line 50 of file ios_surface_metal_skia.mm.

50 {
51 FML_DCHECK(context);
52 return std::make_unique<GPUSurfaceMetalSkia>(this, // delegate
53 sk_ref_sp(context), // context
54 GetContext()->GetMsaaSampleCount() // sample count
55 );
56}
sk_sp< T > sk_ref_sp(T *obj)
Definition SkRefCnt.h:381
#define FML_DCHECK(condition)
Definition logging.h:103

◆ GetCAMetalLayer()

GPUCAMetalLayerHandle flutter::IOSSurfaceMetalSkia::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 59 of file ios_surface_metal_skia.mm.

59 {
60 CAMetalLayer* layer = layer_.get();
61 layer.device = device_;
62
63 layer.pixelFormat = MTLPixelFormatBGRA8Unorm;
64 // Flutter needs to read from the color attachment in cases where there are effects such as
65 // backdrop filters. Flutter plugins that create platform views may also read from the layer.
66 layer.framebufferOnly = NO;
67
68 const auto drawable_size = CGSizeMake(frame_info.width(), frame_info.height());
69 if (!CGSizeEqualToSize(drawable_size, layer.drawableSize)) {
70 layer.drawableSize = drawable_size;
71 }
72
73 // When there are platform views in the scene, the drawable needs to be presented in the same
74 // transaction as the one created for platform views. When the drawable are being presented from
75 // the raster thread, there is no such transaction.
76 layer.presentsWithTransaction = [[NSThread currentThread] isMainThread];
77
78 return (__bridge GPUCAMetalLayerHandle)layer;
79}
T get() const __attribute((ns_returns_not_retained))
constexpr int32_t width() const
Definition SkSize.h:36
constexpr int32_t height() const
Definition SkSize.h:37

◆ GetMTLTexture()

GPUMTLTextureInfo flutter::IOSSurfaceMetalSkia::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 103 of file ios_surface_metal_skia.mm.

103 {
104 FML_CHECK(false) << "render to texture not supported on ios";
105 return {.texture_id = -1, .texture = nullptr};
106}
#define FML_CHECK(condition)
Definition logging.h:85

◆ IsValid()

bool flutter::IOSSurfaceMetalSkia::IsValid ( ) const
overrideprivatevirtual

Implements flutter::IOSSurface.

Definition at line 40 of file ios_surface_metal_skia.mm.

40 {
41 return is_valid_;
42}

◆ PresentDrawable()

bool flutter::IOSSurfaceMetalSkia::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 82 of file ios_surface_metal_skia.mm.

82 {
83 if (drawable == nullptr) {
84 FML_DLOG(ERROR) << "Could not acquire next Metal drawable from the SkSurface.";
85 return false;
86 }
87
88 id<MTLCommandBuffer> command_buffer = [command_queue_ commandBuffer];
89
90 id<CAMetalDrawable> metal_drawable = (__bridge id<CAMetalDrawable>)drawable;
91 if ([metal_drawable conformsToProtocol:@protocol(FlutterMetalDrawable)]) {
92 [(id<FlutterMetalDrawable>)metal_drawable flutterPrepareForPresent:command_buffer];
93 }
94
95 [command_buffer commit];
96 [command_buffer waitUntilScheduled];
97
98 [metal_drawable present];
99 return true;
100}
#define FML_DLOG(severity)
Definition logging.h:102
#define ERROR(message)

◆ PresentTexture()

bool flutter::IOSSurfaceMetalSkia::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 109 of file ios_surface_metal_skia.mm.

109 {
110 FML_CHECK(false) << "render to texture not supported on ios";
111 return false;
112}

◆ UpdateStorageSizeIfNecessary()

void flutter::IOSSurfaceMetalSkia::UpdateStorageSizeIfNecessary ( )
overrideprivatevirtual

Implements flutter::IOSSurface.

Definition at line 45 of file ios_surface_metal_skia.mm.

45 {
46 // Nothing to do.
47}

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