20 id<MTLDevice>
device = MTLCreateSystemDefaultDevice();
22 FML_LOG(ERROR) <<
"Could not acquire Metal device.";
26 id<MTLCommandQueue> command_queue = [
device newCommandQueue];
28 FML_LOG(ERROR) <<
"Could not create the default command queue.";
32 [command_queue setLabel:
@"Flutter Test Queue"];
34 GrMtlBackendContext backendContext = {};
37 backendContext.fDevice.retain((__bridge GrMTLHandle)
device);
38 backendContext.fQueue.retain((__bridge GrMTLHandle)command_queue);
39 skia_context_ = GrDirectContexts::MakeMetal(backendContext);
41 FML_LOG(ERROR) <<
"Could not create the GrDirectContext from the Metal Device "
45 command_queue_ = command_queue;
66 std::scoped_lock lock(textures_mutex_);
67 MTLTextureDescriptor* texture_descriptor =
68 [MTLTextureDescriptor texture2DDescriptorWithPixelFormat:MTLPixelFormatBGRA8Unorm
76 texture_descriptor.usage = MTLTextureUsageUnknown;
78 if (!texture_descriptor) {
79 FML_CHECK(
false) <<
"Invalid texture descriptor.";
80 return {.texture_id = -1, .texture =
nullptr};
84 FML_CHECK(
false) <<
"Invalid Metal device.";
85 return {.texture_id = -1, .texture =
nullptr};
88 id<MTLTexture>
texture = [device_ newTextureWithDescriptor:texture_descriptor];
90 FML_CHECK(
false) <<
"Could not create texture from texture descriptor.";
91 return {.texture_id = -1, .texture =
nullptr};
95 sk_cfp<void*> texture_ptr;
96 texture_ptr.retain((__bridge
void*)
texture);
101 .texture = (__bridge
void*)
texture,