Flutter Engine
The Flutter Engine
Public Member Functions | List of all members
flutter::GPUSurfaceMetalImpeller Class Reference

#include <gpu_surface_metal_impeller.h>

Inheritance diagram for flutter::GPUSurfaceMetalImpeller:
flutter::Surface

Public Member Functions

 GPUSurfaceMetalImpeller (GPUSurfaceMetalDelegate *delegate, const std::shared_ptr< impeller::Context > &context, bool render_to_surface=true)
 
 ~GPUSurfaceMetalImpeller ()
 
bool IsValid () override
 
virtual Surface::SurfaceData GetSurfaceData () const override
 
- Public Member Functions inherited from flutter::Surface
 Surface ()
 
virtual ~Surface ()
 
virtual bool IsValid ()=0
 
virtual std::unique_ptr< SurfaceFrameAcquireFrame (const SkISize &size)=0
 
virtual SkMatrix GetRootTransformation () const =0
 
virtual GrDirectContextGetContext ()=0
 
virtual std::unique_ptr< GLContextResultMakeRenderContextCurrent ()
 
virtual bool ClearRenderContext ()
 
virtual bool AllowsDrawingWhenGpuDisabled () const
 
virtual bool EnableRasterCache () const
 
virtual std::shared_ptr< impeller::AiksContextGetAiksContext () const
 
virtual SurfaceData GetSurfaceData () const
 

Detailed Description

Definition at line 21 of file gpu_surface_metal_impeller.h.

Constructor & Destructor Documentation

◆ GPUSurfaceMetalImpeller()

flutter::GPUSurfaceMetalImpeller::GPUSurfaceMetalImpeller ( GPUSurfaceMetalDelegate delegate,
const std::shared_ptr< impeller::Context > &  context,
bool  render_to_surface = true 
)

Definition at line 34 of file gpu_surface_metal_impeller.mm.

37 : delegate_(delegate),
38 render_target_type_(delegate->GetRenderTargetType()),
39 impeller_renderer_(CreateImpellerRenderer(context)),
40 aiks_context_(
41 std::make_shared<impeller::AiksContext>(impeller_renderer_ ? context : nullptr,
43 render_to_surface_(render_to_surface) {
44 // If this preference is explicitly set, we allow for disabling partial repaint.
45 NSNumber* disablePartialRepaint =
46 [[NSBundle mainBundle] objectForInfoDictionaryKey:@"FLTDisablePartialRepaint"];
47 if (disablePartialRepaint != nil) {
48 disable_partial_repaint_ = disablePartialRepaint.boolValue;
49 }
50}
static std::shared_ptr< TypographerContext > Make()
static std::shared_ptr< impeller::Renderer > CreateImpellerRenderer(std::shared_ptr< impeller::Context > context)

◆ ~GPUSurfaceMetalImpeller()

flutter::GPUSurfaceMetalImpeller::~GPUSurfaceMetalImpeller ( )
default

Member Function Documentation

◆ GetSurfaceData()

Surface::SurfaceData flutter::GPUSurfaceMetalImpeller::GetSurfaceData ( ) const
overridevirtual

Capture the SurfaceData currently present in the surface.

Not guaranteed to work on all setups and not intended to be used in production. The data field will be null if it was unable to work.

Reimplemented from flutter::Surface.

Definition at line 378 of file gpu_surface_metal_impeller.mm.

378 {
379 if (!(last_texture_ && [last_texture_ conformsToProtocol:@protocol(MTLTexture)])) {
380 return {};
381 }
382 id<MTLTexture> texture = last_texture_.get();
383 int bytesPerPixel = 0;
384 std::string pixel_format;
385 switch (texture.pixelFormat) {
386 case MTLPixelFormatBGR10_XR:
387 bytesPerPixel = 4;
388 pixel_format = "MTLPixelFormatBGR10_XR";
389 break;
390 case MTLPixelFormatBGRA10_XR:
391 bytesPerPixel = 8;
392 pixel_format = "MTLPixelFormatBGRA10_XR";
393 break;
394 case MTLPixelFormatBGRA8Unorm:
395 bytesPerPixel = 4;
396 pixel_format = "MTLPixelFormatBGRA8Unorm";
397 break;
398 case MTLPixelFormatRGBA16Float:
399 bytesPerPixel = 8;
400 pixel_format = "MTLPixelFormatRGBA16Float";
401 break;
402 default:
403 return {};
404 }
405
406 // Zero initialized so that errors are easier to find at the cost of
407 // performance.
409 SkData::MakeZeroInitialized(texture.width * texture.height * bytesPerPixel);
410 [texture getBytes:result->writable_data()
411 bytesPerRow:texture.width * bytesPerPixel
412 fromRegion:MTLRegionMake2D(0, 0, texture.width, texture.height)
413 mipmapLevel:0];
414 return {
415 .pixel_format = pixel_format,
416 .data = result,
417 };
418}
static sk_sp< SkData > MakeZeroInitialized(size_t length)
Definition: SkData.cpp:120
T get() const __attribute((ns_returns_not_retained))
GAsyncResult * result
FlTexture * texture

◆ IsValid()

bool flutter::GPUSurfaceMetalImpeller::IsValid ( )
overridevirtual

Implements flutter::Surface.

Definition at line 55 of file gpu_surface_metal_impeller.mm.

55 {
56 return !!aiks_context_ && aiks_context_->IsValid();
57}

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