skia2/tools/gpu/mtl/MtlTestContext.mm
Jim Van Verth e8a1c0150b Revert "Remove ARC from tools lib."
This reverts commit 4c4c80fa12.

Reason for revert: Need to update Flutter with sk_cf_obj renaming.

Original change's description:
> Remove ARC from tools lib.
>
> Trying this in baby steps to manage leaks better.
>
> Change-Id: Id8597ba236c752bcbf1c7ec94f6c1021e636d547
> Reviewed-on: https://skia-review.googlesource.com/c/skia/+/372556
> Commit-Queue: Jim Van Verth <jvanverth@google.com>
> Reviewed-by: Brian Salomon <bsalomon@google.com>
> Reviewed-by: Adlai Holler <adlai@google.com>

TBR=jvanverth@google.com,bsalomon@google.com,adlai@google.com

Change-Id: I7dc226d002184b80a1d8d2aee09d122d2e13d732
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/372680
Reviewed-by: Jim Van Verth <jvanverth@google.com>
Commit-Queue: Jim Van Verth <jvanverth@google.com>
2021-02-20 00:08:41 +00:00

91 lines
2.5 KiB
Plaintext

/*
* Copyright 2017 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "tools/gpu/mtl/MtlTestContext.h"
#include "include/gpu/GrContextOptions.h"
#include "include/gpu/GrDirectContext.h"
#include "src/gpu/mtl/GrMtlUtil.h"
#ifdef SK_METAL
#import <Metal/Metal.h>
namespace {
class MtlTestContextImpl : public sk_gpu_test::MtlTestContext {
public:
static MtlTestContext* Create(MtlTestContext* sharedContext) {
GrMtlBackendContext backendContext = {};
if (sharedContext) {
MtlTestContextImpl* sharedContextImpl = (MtlTestContextImpl*) sharedContext;
backendContext = sharedContextImpl->getMtlBackendContext();
} else {
id<MTLDevice> device;
#ifdef SK_BUILD_FOR_MAC
NSArray<id <MTLDevice>>* availableDevices = MTLCopyAllDevices();
// Choose the non-integrated CPU if available
for (id<MTLDevice> dev in availableDevices) {
if (!dev.isLowPower) {
device = dev;
break;
}
if (dev.isRemovable) {
device = dev;
break;
}
}
if (!device) {
device = MTLCreateSystemDefaultDevice();
}
#else
device = MTLCreateSystemDefaultDevice();
#endif
backendContext.fDevice.retain((__bridge GrMTLHandle)device);
id<MTLCommandQueue> queue = [device newCommandQueue];
backendContext.fQueue.retain((__bridge GrMTLHandle)queue);
}
return new MtlTestContextImpl(backendContext);
}
~MtlTestContextImpl() override { this->teardown(); }
void testAbandon() override {}
void finish() override {}
sk_sp<GrDirectContext> makeContext(const GrContextOptions& options) override {
return GrDirectContext::MakeMetal(fMtl, options);
}
private:
MtlTestContextImpl(const GrMtlBackendContext& mtl)
: INHERITED(mtl) {
fFenceSupport = true;
}
void onPlatformMakeNotCurrent() const override {}
void onPlatformMakeCurrent() const override {}
std::function<void()> onPlatformGetAutoContextRestore() const override { return nullptr; }
using INHERITED = sk_gpu_test::MtlTestContext;
};
} // anonymous namespace
namespace sk_gpu_test {
MtlTestContext* CreatePlatformMtlTestContext(MtlTestContext* sharedContext) {
return MtlTestContextImpl::Create(sharedContext);
}
} // namespace sk_gpu_test
#endif