Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
metal_context_helper.mm
Go to the documentation of this file.
1/*
2 * Copyright 2024 Google LLC
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
9
12
13#import <Metal/Metal.h>
14
16 GrMtlBackendContext backendContext = {};
17 sk_cfp<id<MTLDevice>> device;
18#if defined(TARGET_OS_IPHONE) || defined(TARGET_IPHONE_SIMULATOR)
19 device.reset(MTLCreateSystemDefaultDevice());
20#else
21 sk_cfp<NSArray<id <MTLDevice>>*> availableDevices(MTLCopyAllDevices());
22 // Choose the non-integrated CPU if available
23 for (id<MTLDevice> dev in availableDevices.get()) {
24 if (!dev.isLowPower) {
25 device.retain(dev);
26 break;
27 }
28 if (dev.isRemovable) {
29 device.retain(dev);
30 break;
31 }
32 }
33 if (!device) {
34 device.reset(MTLCreateSystemDefaultDevice());
35 }
36#endif
37
38 backendContext.fDevice.retain((GrMTLHandle)device.get());
39 sk_cfp<id<MTLCommandQueue>> queue([*device newCommandQueue]);
40 backendContext.fQueue.retain((GrMTLHandle)queue.get());
41 return backendContext;
42}
const void * GrMTLHandle
Definition GrMtlTypes.h:20
VkDevice device
Definition main.cc:53
VkQueue queue
Definition main.cc:55
GrMtlBackendContext GetMetalContext()
sk_cfp< GrMTLHandle > fDevice
sk_cfp< GrMTLHandle > fQueue