Flutter Engine
The Flutter Engine
third_party
skia
tools
gpu
mtl
MtlTestContext.mm
Go to the documentation of this file.
1
/*
2
* Copyright 2017 Google Inc.
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
#include "
tools/gpu/mtl/MtlTestContext.h
"
9
10
#include "
include/gpu/GrContextOptions.h
"
11
#include "
include/gpu/GrDirectContext.h
"
12
#include "
include/gpu/ganesh/mtl/GrMtlDirectContext.h
"
13
#include "
src/gpu/ganesh/mtl/GrMtlUtil.h
"
14
15
#import <Metal/Metal.h>
16
17
namespace
{
18
class
MtlTestContextImpl :
public
sk_gpu_test::MtlTestContext {
19
public
:
20
static
MtlTestContext*
Create
(MtlTestContext* sharedContext) {
21
GrMtlBackendContext
backendContext = {};
22
if
(sharedContext) {
23
MtlTestContextImpl* sharedContextImpl = (MtlTestContextImpl*) sharedContext;
24
backendContext = sharedContextImpl->getMtlBackendContext();
25
}
else
{
26
sk_cfp<id<MTLDevice>>
device
;
27
#ifdef SK_BUILD_FOR_MAC
28
sk_cfp<NSArray<id <MTLDevice>>*> availableDevices(MTLCopyAllDevices());
29
// Choose the non-integrated CPU if available
30
for
(id<MTLDevice> dev in availableDevices.get()) {
31
if
(!dev.isLowPower) {
32
device
.retain(dev);
33
break
;
34
}
35
if
(dev.isRemovable) {
36
device
.retain(dev);
37
break
;
38
}
39
}
40
if
(!
device
) {
41
device
.reset(MTLCreateSystemDefaultDevice());
42
}
43
#else
44
device
.reset(MTLCreateSystemDefaultDevice());
45
#endif
46
backendContext.
fDevice
.retain((
GrMTLHandle
)
device
.get());
47
sk_cfp<id<MTLCommandQueue>>
queue
([*
device
newCommandQueue]);
48
backendContext.
fQueue
.retain((
GrMTLHandle
)
queue
.get());
49
}
50
51
return
new
MtlTestContextImpl(backendContext);
52
}
53
54
~MtlTestContextImpl()
override
{ this->teardown(); }
55
56
void
testAbandon()
override
{}
57
58
sk_sp<GrDirectContext>
makeContext(
const
GrContextOptions
&
options
)
override
{
59
return
GrDirectContexts::MakeMetal
(fMtl,
options
);
60
}
61
62
private
:
63
MtlTestContextImpl(
const
GrMtlBackendContext
& mtl)
64
:
INHERITED
(mtl) {
65
fFenceSupport =
true
;
66
}
67
68
void
onPlatformMakeNotCurrent()
const override
{}
69
void
onPlatformMakeCurrent()
const override
{}
70
std::function
<void()> onPlatformGetAutoContextRestore()
const override
{
return
nullptr
; }
71
72
using
INHERITED
= sk_gpu_test::MtlTestContext;
73
};
74
75
}
// anonymous namespace
76
77
namespace
sk_gpu_test
{
78
79
MtlTestContext*
CreatePlatformMtlTestContext
(MtlTestContext* sharedContext) {
80
return
MtlTestContextImpl::Create
(sharedContext);
81
}
82
83
}
// namespace sk_gpu_test
options
const char * options
Definition:
CommonFlagsConfig.cpp:43
GrContextOptions.h
GrDirectContext.h
GrMtlDirectContext.h
GrMTLHandle
const void * GrMTLHandle
Definition:
GrMtlTypes.h:20
GrMtlUtil.h
MtlTestContext.h
Create
static sk_sp< Effect > Create()
Definition:
RefCntTest.cpp:117
INHERITED
#define INHERITED(method,...)
Definition:
SkRecorder.cpp:128
sk_sp< GrDirectContext >
device
VkDevice device
Definition:
main.cc:53
queue
VkQueue queue
Definition:
main.cc:55
function
Dart_NativeFunction function
Definition:
fuchsia.cc:51
GrDirectContexts::MakeMetal
SK_API sk_sp< GrDirectContext > MakeMetal(const GrMtlBackendContext &, const GrContextOptions &)
Definition:
GrMtlDirectContext.mm:21
sk_gpu_test
Definition:
gm_bindings.cpp:339
sk_gpu_test::CreatePlatformMtlTestContext
MtlTestContext * CreatePlatformMtlTestContext(MtlTestContext *sharedContext)
Definition:
MtlTestContext.mm:79
GrContextOptions
Definition:
GrContextOptions.h:23
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:56:50 for Flutter Engine by
1.9.4