2 * Copyright 2017 Google Inc.
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
8 #include "tools/gpu/mtl/MtlTestContext.h"
10 #include "include/gpu/GrContextOptions.h"
11 #include "include/gpu/GrDirectContext.h"
13 #include "src/gpu/ganesh/mtl/GrMtlUtil.h"
17 #import <Metal/Metal.h>
20 class MtlTestContextImpl : public sk_gpu_test::MtlTestContext {
22 static MtlTestContext* Create(MtlTestContext* sharedContext) {
23 GrMtlBackendContext backendContext = {};
25 MtlTestContextImpl* sharedContextImpl = (MtlTestContextImpl*) sharedContext;
26 backendContext = sharedContextImpl->getMtlBackendContext();
28 sk_cfp<id<MTLDevice>> device;
29 #ifdef SK_BUILD_FOR_MAC
30 sk_cfp<NSArray<id <MTLDevice>>*> availableDevices(MTLCopyAllDevices());
31 // Choose the non-integrated CPU if available
32 for (id<MTLDevice> dev in availableDevices.get()) {
33 if (!dev.isLowPower) {
37 if (dev.isRemovable) {
43 device.reset(MTLCreateSystemDefaultDevice());
46 device.reset(MTLCreateSystemDefaultDevice());
48 backendContext.fDevice.retain((GrMTLHandle)device.get());
49 sk_cfp<id<MTLCommandQueue>> queue([*device newCommandQueue]);
50 backendContext.fQueue.retain((GrMTLHandle)queue.get());
53 return new MtlTestContextImpl(backendContext);
56 ~MtlTestContextImpl() override { this->teardown(); }
58 void testAbandon() override {}
60 void finish() override {}
62 sk_sp<GrDirectContext> makeContext(const GrContextOptions& options) override {
63 return GrDirectContext::MakeMetal(fMtl, options);
67 MtlTestContextImpl(const GrMtlBackendContext& mtl)
72 void onPlatformMakeNotCurrent() const override {}
73 void onPlatformMakeCurrent() const override {}
74 std::function<void()> onPlatformGetAutoContextRestore() const override { return nullptr; }
76 using INHERITED = sk_gpu_test::MtlTestContext;
79 } // anonymous namespace
81 namespace sk_gpu_test {
83 MtlTestContext* CreatePlatformMtlTestContext(MtlTestContext* sharedContext) {
84 return MtlTestContextImpl::Create(sharedContext);
87 } // namespace sk_gpu_test