Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
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
9
14
15#import <Metal/Metal.h>
16
17namespace {
18class MtlTestContextImpl : public sk_gpu_test::MtlTestContext {
19public:
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 {
60 }
61
62private:
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
77namespace sk_gpu_test {
78
79MtlTestContext* CreatePlatformMtlTestContext(MtlTestContext* sharedContext) {
80 return MtlTestContextImpl::Create(sharedContext);
81}
82
83} // namespace sk_gpu_test
const char * options
const void * GrMTLHandle
Definition GrMtlTypes.h:20
static sk_sp< Effect > Create()
#define INHERITED(method,...)
VkDevice device
Definition main.cc:53
VkQueue queue
Definition main.cc:55
SK_API sk_sp< GrDirectContext > MakeMetal(const GrMtlBackendContext &, const GrContextOptions &)
sk_cfp< GrMTLHandle > fDevice
sk_cfp< GrMTLHandle > fQueue