Flutter Engine
The Flutter Engine
Instance Methods | Class Methods | Properties | List of all members
FlutterDarwinContextMetalSkia Class Reference

#import <FlutterDarwinContextMetalSkia.h>

Inheritance diagram for FlutterDarwinContextMetalSkia:

Instance Methods

(instancetype) - initWithDefaultMTLDevice
 
(instancetype) - initWithMTLDevice:commandQueue:
 
(FlutterDarwinExternalTextureMetal *) - createExternalTextureWithIdentifier:texture:
 
(sk_sp< GrDirectContext >) - createGrContext [implementation]
 
(void) - dealloc [implementation]
 

Class Methods

(sk_sp< GrDirectContext >) + createGrContext:commandQueue:
 

Properties

id< MTLDevice > device
 
id< MTLCommandQueue > commandQueue
 
sk_sp< GrDirectContextmainContext
 
sk_sp< GrDirectContextresourceContext
 
CVMetalTextureCacheRef textureCache
 

Detailed Description

Provides skia GrContexts that are shared between iOS and macOS embeddings.

Definition at line 23 of file FlutterDarwinContextMetalSkia.h.

Method Documentation

◆ createExternalTextureWithIdentifier:texture:

- (FlutterDarwinExternalTextureMetal *) createExternalTextureWithIdentifier: (int64_t)  textureID
texture: (NSObject<FlutterTexture>*)  texture 

Creates an external texture with the specified ID and contents.

Definition at line 17 of file FlutterDarwinContextMetalSkia.mm.

106 :(int64_t)textureID
107 texture:(NSObject<FlutterTexture>*)texture {
108 return [[FlutterDarwinExternalTextureMetal alloc] initWithTextureCache:_textureCache
109 textureID:textureID
110 texture:texture
111 enableImpeller:NO];
112}
FlTexture * texture

◆ createGrContext

- (sk_sp< GrDirectContext >) createGrContext
implementation

Definition at line 17 of file FlutterDarwinContextMetalSkia.mm.

79 {
80 const auto contextOptions =
82 id<MTLDevice> device = _device;
83 id<MTLCommandQueue> commandQueue = _commandQueue;
85}
sk_sp< GrDirectContext > createGrContext:commandQueue:(id< MTLDevice > device,[commandQueue] id< MTLCommandQueue > commandQueue)
GrContextOptions MakeDefaultContextOptions(ContextType type, std::optional< GrBackendApi > api)
Initializes GrContextOptions with values suitable for Flutter. The options can be further tweaked bef...
@ kRender
The context is used to render to a texture or renderbuffer.

◆ createGrContext:commandQueue:

+ (sk_sp< GrDirectContext >) createGrContext: (id<MTLDevice>)  device
commandQueue: (id<MTLCommandQueue>)  commandQueue 

Creates a GrDirectContext with the provided MTLDevice and MTLCommandQueue.

Definition at line 17 of file FlutterDarwinContextMetalSkia.mm.

87 :(id<MTLDevice>)device
88 commandQueue:(id<MTLCommandQueue>)commandQueue {
89 const auto contextOptions =
91 GrMtlBackendContext backendContext = {};
92 // Skia expect arguments to `MakeMetal` transfer ownership of the reference in for release later
93 // when the GrDirectContext is collected.
94 backendContext.fDevice.reset((__bridge_retained void*)device);
95 backendContext.fQueue.reset((__bridge_retained void*)commandQueue);
96 return GrDirectContexts::MakeMetal(backendContext, contextOptions);
97}
SK_API sk_sp< GrDirectContext > MakeMetal(const GrMtlBackendContext &, const GrContextOptions &)
sk_cfp< GrMTLHandle > fDevice
sk_cfp< GrMTLHandle > fQueue

◆ dealloc

- (void) dealloc
implementation

Definition at line 17 of file FlutterDarwinContextMetalSkia.mm.

99 {
100 if (_textureCache) {
101 CFRelease(_textureCache);
102 }
103}

◆ initWithDefaultMTLDevice

- (instancetype) initWithDefaultMTLDevice

Initializes a FlutterDarwinContextMetalSkia with the system default MTLDevice and a new MTLCommandQueue.

Definition at line 17 of file FlutterDarwinContextMetalSkia.mm.

21 {
22 id<MTLDevice> device = MTLCreateSystemDefaultDevice();
23 return [self initWithMTLDevice:device commandQueue:[device newCommandQueue]];
24}

◆ initWithMTLDevice:commandQueue:

- (instancetype) initWithMTLDevice: (id<MTLDevice>)  device
commandQueue: (id<MTLCommandQueue>)  commandQueue 

Initializes a FlutterDarwinContextMetalSkia with provided MTLDevice and MTLCommandQueue.

Definition at line 17 of file FlutterDarwinContextMetalSkia.mm.

26 :(id<MTLDevice>)device
27 commandQueue:(id<MTLCommandQueue>)commandQueue {
28 self = [super init];
29 if (self != nil) {
30 _device = device;
31
32 if (!_device) {
33 FML_DLOG(ERROR) << "Could not acquire Metal device.";
34 return nil;
35 }
36
37 _commandQueue = commandQueue;
38
39 if (!_commandQueue) {
40 FML_DLOG(ERROR) << "Could not create Metal command queue.";
41 return nil;
42 }
43
44 [_commandQueue setLabel:@"Flutter Main Queue"];
45
46 CVReturn cvReturn = CVMetalTextureCacheCreate(kCFAllocatorDefault, // allocator
47 nil, // cache attributes (nil default)
48 _device, // metal device
49 nil, // texture attributes (nil default)
50 &_textureCache // [out] cache
51 );
52 if (cvReturn != kCVReturnSuccess) {
53 FML_DLOG(ERROR) << "Could not create Metal texture cache.";
54 return nil;
55 }
56
57 // The devices are in the same "sharegroup" because they share the same device and command
58 // queues for now. When the resource context gets its own transfer queue, this will have to be
59 // refactored.
60 _mainContext = [self createGrContext];
61 _resourceContext = [self createGrContext];
62
63 if (!_mainContext || !_resourceContext) {
64 FML_DLOG(ERROR) << "Could not create Skia Metal contexts.";
65 return nil;
66 }
67
68 // Only log this message on iOS where the default is Impeller. On macOS
69 // desktop, Skia is still the default and this log is unecessary.
70#if defined(FML_OS_IOS) || defined(FML_OS_IOS_SIM)
71 FML_LOG(IMPORTANT) << "Using the Skia rendering backend (Metal).";
72#endif // defined(FML_OS_IOS) || defined(FML_OS_IOS_SIM)
73
74 _resourceContext->setResourceCacheLimit(0u);
75 }
76 return self;
77}
#define FML_DLOG(severity)
Definition: logging.h:102
#define FML_LOG(severity)
Definition: logging.h:82
#define ERROR(message)
Definition: elf_loader.cc:260

Property Documentation

◆ commandQueue

- (id<MTLCommandQueue>) commandQueue
readnonatomicassign

MTLCommandQueue that is acquired from the device. This queue is used both for rendering and resource related commands.

Definition at line 59 of file FlutterDarwinContextMetalSkia.h.

◆ device

- (id<MTLDevice>) device
readnonatomicassign

MTLDevice that is backing this context.s

Definition at line 53 of file FlutterDarwinContextMetalSkia.h.

◆ mainContext

- (sk_sp<GrDirectContext>) mainContext
readnonatomicassign

Skia GrContext that is used for rendering.

Definition at line 64 of file FlutterDarwinContextMetalSkia.h.

◆ resourceContext

- (sk_sp<GrDirectContext>) resourceContext
readnonatomicassign

Skia GrContext that is used for resources (uploading textures etc).

Definition at line 69 of file FlutterDarwinContextMetalSkia.h.

◆ textureCache

- (CVMetalTextureCacheRef) textureCache
readnonatomicassign

Definition at line 74 of file FlutterDarwinContextMetalSkia.h.


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