Flutter Engine
 
Loading...
Searching...
No Matches
FlutterDarwinContextMetalSkia Class Reference

#include <FlutterDarwinContextMetalSkia.h>

Inheritance diagram for FlutterDarwinContextMetalSkia:

Instance Methods

(instancetype) - initWithDefaultMTLDevice
 
(instancetype) - initWithMTLDevice:commandQueue:
 
(FlutterDarwinExternalTextureMetal *) - createExternalTextureWithIdentifier:texture:
 

Class Methods

(sk_sp< GrDirectContext >) + createGrContext:commandQueue:
 

Properties

id< MTLDevice > device
 
id< MTLCommandQueue > commandQueue
 
sk_sp< GrDirectContext > mainContext
 
sk_sp< GrDirectContext > resourceContext
 
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 18 of file FlutterDarwinContextMetalSkia.mm.

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

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

92 :(id<MTLDevice>)device
93 commandQueue:(id<MTLCommandQueue>)commandQueue {
94 const auto contextOptions =
96 GrMtlBackendContext backendContext = {};
97 // Skia expect arguments to `MakeMetal` transfer ownership of the reference in for release later
98 // when the GrDirectContext is collected.
99 backendContext.fDevice.retain((__bridge void*)device);
100 backendContext.fQueue.retain((__bridge void*)commandQueue);
101 return GrDirectContexts::MakeMetal(backendContext, contextOptions);
102}
@ kMetal
Definition embedder.h:85
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.
const uintptr_t id

◆ initWithDefaultMTLDevice

- (instancetype) initWithDefaultMTLDevice
Initial value:

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

Definition at line 18 of file FlutterDarwinContextMetalSkia.mm.

24 {
25 id<MTLDevice> device = MTLCreateSystemDefaultDevice();
26 return [self initWithMTLDevice:device commandQueue:[device newCommandQueue]];
27}

◆ initWithMTLDevice:commandQueue:

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

Initializes a FlutterDarwinContextMetalSkia with provided MTLDevice and MTLCommandQueue.

Definition at line 18 of file FlutterDarwinContextMetalSkia.mm.

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

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.

Referenced by flutter::testing::ShellTestPlatformViewMetal::ShellTestPlatformViewMetal().

◆ mainContext

- (sk_sp<GrDirectContext>) mainContext
readnonatomicassign

◆ 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: