Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Public Member Functions | Private 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 ClearRenderContext ()
 

Private Member Functions

std::unique_ptr< SurfaceFrameAcquireFrame (const SkISize &frame_size) override
 
SkMatrix GetRootTransformation () const override
 
GrDirectContextGetContext () override
 
std::unique_ptr< GLContextResultMakeRenderContextCurrent () override
 
bool AllowsDrawingWhenGpuDisabled () const override
 
bool EnableRasterCache () const override
 
std::shared_ptr< impeller::AiksContextGetAiksContext () const override
 

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,
42 impeller::TypographerContextSkia::Make())),
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::unique_ptr< SkEncoder > Make(SkWStream *dst, const SkPixmap *src, const SkYUVAPixmaps *srcYUVA, const SkColorSpace *srcYUVAColorSpace, const SkJpegEncoder::Options &options)
static std::shared_ptr< impeller::Renderer > CreateImpellerRenderer(std::shared_ptr< impeller::Context > context)

◆ ~GPUSurfaceMetalImpeller()

flutter::GPUSurfaceMetalImpeller::~GPUSurfaceMetalImpeller ( )
default

Member Function Documentation

◆ AcquireFrame()

std::unique_ptr< SurfaceFrame > flutter::GPUSurfaceMetalImpeller::AcquireFrame ( const SkISize frame_size)
overrideprivatevirtual

Implements flutter::Surface.

Definition at line 60 of file gpu_surface_metal_impeller.mm.

60 {
61 TRACE_EVENT0("impeller", "GPUSurfaceMetalImpeller::AcquireFrame");
62
63 if (!IsValid()) {
64 FML_LOG(ERROR) << "Metal surface was invalid.";
65 return nullptr;
66 }
67
68 if (frame_size.isEmpty()) {
69 FML_LOG(ERROR) << "Metal surface was asked for an empty frame.";
70 return nullptr;
71 }
72
73 if (!render_to_surface_) {
74 return std::make_unique<SurfaceFrame>(
75 nullptr, SurfaceFrame::FramebufferInfo(),
76 [](const SurfaceFrame& surface_frame, DlCanvas* canvas) { return true; }, frame_size);
77 }
78
79 switch (render_target_type_) {
81 return AcquireFrameFromCAMetalLayer(frame_size);
83 return AcquireFrameFromMTLTexture(frame_size);
84 default:
85 FML_CHECK(false) << "Unknown MTLRenderTargetType type.";
86 }
87
88 return nullptr;
89}
#define FML_LOG(severity)
Definition logging.h:82
#define FML_CHECK(condition)
Definition logging.h:85
bool isEmpty() const
Definition SkSize.h:31
#define ERROR(message)
#define TRACE_EVENT0(category_group, name)

◆ AllowsDrawingWhenGpuDisabled()

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

Reimplemented from flutter::Surface.

Definition at line 361 of file gpu_surface_metal_impeller.mm.

361 {
362 return delegate_->AllowsDrawingWhenGpuDisabled();
363}
virtual bool AllowsDrawingWhenGpuDisabled() const
Whether to allow drawing to the surface when the GPU is disabled.

◆ EnableRasterCache()

bool flutter::GPUSurfaceMetalImpeller::EnableRasterCache ( ) const
overrideprivatevirtual

Reimplemented from flutter::Surface.

Definition at line 366 of file gpu_surface_metal_impeller.mm.

366 {
367 return false;
368}

◆ GetAiksContext()

std::shared_ptr< impeller::AiksContext > flutter::GPUSurfaceMetalImpeller::GetAiksContext ( ) const
overrideprivatevirtual

Reimplemented from flutter::Surface.

Definition at line 371 of file gpu_surface_metal_impeller.mm.

371 {
372 return aiks_context_;
373}

◆ GetContext()

GrDirectContext * flutter::GPUSurfaceMetalImpeller::GetContext ( )
overrideprivatevirtual

Implements flutter::Surface.

Definition at line 351 of file gpu_surface_metal_impeller.mm.

351 {
352 return nullptr;
353}

◆ GetRootTransformation()

SkMatrix flutter::GPUSurfaceMetalImpeller::GetRootTransformation ( ) const
overrideprivatevirtual

Implements flutter::Surface.

Definition at line 344 of file gpu_surface_metal_impeller.mm.

344 {
345 // This backend does not currently support root surface transformations. Just
346 // return identity.
347 return {};
348}

◆ 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 375 of file gpu_surface_metal_impeller.mm.

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

◆ MakeRenderContextCurrent()

std::unique_ptr< GLContextResult > flutter::GPUSurfaceMetalImpeller::MakeRenderContextCurrent ( )
overrideprivatevirtual

Reimplemented from flutter::Surface.

Definition at line 356 of file gpu_surface_metal_impeller.mm.

356 {
357 // This backend has no such concept.
358 return std::make_unique<GLContextDefaultResult>(true);
359}

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