/* * Copyright 2019 Google Inc. * * Use of this source code is governed by a BSD-style license that can be * found in the LICENSE file. */ #include "src/gpu/mtl/GrMtlSemaphore.h" #include "src/gpu/mtl/GrMtlGpu.h" #if !__has_feature(objc_arc) #error This file must be compiled with Arc. Use -fobjc-arc flag #endif GR_NORETAIN_BEGIN sk_sp GrMtlEvent::Make(GrMtlGpu* gpu) { if (@available(macOS 10.14, iOS 12.0, *)) { id event = [gpu->device() newEvent]; return sk_sp(new GrMtlEvent(event)); } else { return nullptr; } } sk_sp GrMtlEvent::MakeWrapped(GrMTLHandle event) { // The GrMtlEvent will have strong ownership at this point. // The GrMTLHandle will subsequently only have weak ownership. if (@available(macOS 10.14, iOS 12.0, *)) { id mtlEvent = (__bridge_transfer id)event; return sk_sp(new GrMtlEvent(mtlEvent)); } else { return nullptr; } } GrBackendSemaphore GrMtlSemaphore::backendSemaphore() const { GrBackendSemaphore backendSemaphore; // The GrMtlSemaphore and the GrBackendSemaphore will have strong ownership at this point. // Whoever uses the GrBackendSemaphore will subsquently steal this ref (see MakeWrapped, above). if (@available(macOS 10.14, iOS 12.0, *)) { GrMTLHandle handle = (__bridge_retained GrMTLHandle)(fEvent->mtlEvent()); backendSemaphore.initMetal(handle, fValue); } return backendSemaphore; } GR_NORETAIN_END