Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Instance Methods | Class Methods | Properties | List of all members
FlutterDarwinContextMetalSkia Class Reference

#include <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 21 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 15 of file FlutterDarwinContextMetalSkia.mm.

100 :(int64_t)textureID
101 texture:(NSObject<FlutterTexture>*)texture {
102 return [[FlutterDarwinExternalTextureMetal alloc] initWithTextureCache:_textureCache
103 textureID:textureID
105 enableImpeller:NO];
106}
FlTexture * texture

◆ createGrContext

- (sk_sp< GrDirectContext >) createGrContext
implementation

Definition at line 15 of file FlutterDarwinContextMetalSkia.mm.

73 {
74 const auto contextOptions =
75 flutter::MakeDefaultContextOptions(flutter::ContextType::kRender, GrBackendApi::kMetal);
76 id<MTLDevice> device = _device;
77 id<MTLCommandQueue> commandQueue = _commandQueue;
79}
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...

◆ 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 15 of file FlutterDarwinContextMetalSkia.mm.

81 :(id<MTLDevice>)device
82 commandQueue:(id<MTLCommandQueue>)commandQueue {
83 const auto contextOptions =
85 GrMtlBackendContext backendContext = {};
86 // Skia expect arguments to `MakeMetal` transfer ownership of the reference in for release later
87 // when the GrDirectContext is collected.
88 backendContext.fDevice.reset((__bridge_retained void*)device);
89 backendContext.fQueue.reset((__bridge_retained void*)commandQueue);
90 return GrDirectContexts::MakeMetal(backendContext, contextOptions);
91}
GrBackendApi
Definition GrTypes.h:95
@ kMetal
Definition embedder.h:85
SK_API sk_sp< GrDirectContext > MakeMetal(const GrMtlBackendContext &, const GrContextOptions &)
@ kRender
The context is used to render to a texture or renderbuffer.
sk_cfp< GrMTLHandle > fDevice
sk_cfp< GrMTLHandle > fQueue
const uintptr_t id

◆ dealloc

- (void) dealloc
implementation

Definition at line 15 of file FlutterDarwinContextMetalSkia.mm.

93 {
94 if (_textureCache) {
95 CFRelease(_textureCache);
96 }
97}

◆ initWithDefaultMTLDevice

- (instancetype) initWithDefaultMTLDevice

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

Definition at line 15 of file FlutterDarwinContextMetalSkia.mm.

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

◆ initWithMTLDevice:commandQueue:

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

Initializes a FlutterDarwinContextMetalSkia with provided MTLDevice and MTLCommandQueue.

Definition at line 15 of file FlutterDarwinContextMetalSkia.mm.

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

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 57 of file FlutterDarwinContextMetalSkia.h.

◆ device

- (id<MTLDevice>) device
readnonatomicassign

MTLDevice that is backing this context.s

Definition at line 51 of file FlutterDarwinContextMetalSkia.h.

◆ mainContext

- (sk_sp<GrDirectContext>) mainContext
readnonatomicassign

Skia GrContext that is used for rendering.

Definition at line 62 of file FlutterDarwinContextMetalSkia.h.

◆ resourceContext

- (sk_sp<GrDirectContext>) resourceContext
readnonatomicassign

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

Definition at line 67 of file FlutterDarwinContextMetalSkia.h.

◆ textureCache

- (CVMetalTextureCacheRef) textureCache
readnonatomicassign

Definition at line 72 of file FlutterDarwinContextMetalSkia.h.


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