Flutter Engine
The Flutter Engine
third_party
skia
example
external_client
src
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
8
#import "
metal_context_helper.h
"
9
10
#import "
include/gpu/ganesh/mtl/GrMtlTypes.h
"
11
#import "
include/ports/SkCFObject.h
"
12
13
#import <Metal/Metal.h>
14
15
GrMtlBackendContext
GetMetalContext
() {
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
}
GrMtlTypes.h
GrMTLHandle
const void * GrMTLHandle
Definition:
GrMtlTypes.h:20
SkCFObject.h
device
VkDevice device
Definition:
main.cc:53
queue
VkQueue queue
Definition:
main.cc:55
metal_context_helper.h
GetMetalContext
GrMtlBackendContext GetMetalContext()
Definition:
metal_context_helper.mm:15
GrMtlBackendContext
Definition:
GrMtlBackendContext.h:16
GrMtlBackendContext::fDevice
sk_cfp< GrMTLHandle > fDevice
Definition:
GrMtlBackendContext.h:17
GrMtlBackendContext::fQueue
sk_cfp< GrMTLHandle > fQueue
Definition:
GrMtlBackendContext.h:18
Generated on Sun Jun 23 2024 21:55:56 for Flutter Engine by
1.9.4