-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmetal_context_helper.mm
More file actions
42 lines (37 loc) · 1.18 KB
/
Copy pathmetal_context_helper.mm
File metadata and controls
42 lines (37 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/*
* Copyright 2024 Google LLC
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#import "metal_context_helper.h"
#import "include/gpu/ganesh/mtl/GrMtlTypes.h"
#import "include/ports/SkCFObject.h"
#import <Metal/Metal.h>
GrMtlBackendContext GetMetalContext() {
GrMtlBackendContext backendContext = {};
sk_cfp<id<MTLDevice>> device;
#if defined(TARGET_OS_IPHONE) || defined(TARGET_IPHONE_SIMULATOR)
device.reset(MTLCreateSystemDefaultDevice());
#else
sk_cfp<NSArray<id <MTLDevice>>*> availableDevices(MTLCopyAllDevices());
// Choose the non-integrated CPU if available
for (id<MTLDevice> dev in availableDevices.get()) {
if (!dev.isLowPower) {
device.retain(dev);
break;
}
if (dev.isRemovable) {
device.retain(dev);
break;
}
}
if (!device) {
device.reset(MTLCreateSystemDefaultDevice());
}
#endif
backendContext.fDevice.retain((GrMTLHandle)device.get());
sk_cfp<id<MTLCommandQueue>> queue([*device newCommandQueue]);
backendContext.fQueue.retain((GrMTLHandle)queue.get());
return backendContext;
}