1/* 2 * Copyright 2019 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 "src/gpu/ganesh/mtl/GrMtlSemaphore.h" 9 10#include "include/gpu/ganesh/mtl/GrMtlBackendSemaphore.h" 11#include "src/gpu/ganesh/mtl/GrMtlGpu.h" 12 13#if !__has_feature(objc_arc) 14#error This file must be compiled with Arc. Use -fobjc-arc flag 15#endif 16 17GR_NORETAIN_BEGIN 18 19sk_sp<GrMtlEvent> GrMtlEvent::Make(GrMtlGpu* gpu) { 20 if (@available(macOS 10.14, iOS 12.0, tvOS 12.0, *)) { 21 id<MTLEvent> event = [gpu->device() newEvent]; 22 return sk_sp<GrMtlEvent>(new GrMtlEvent(event)); 23 } else { 24 return nullptr; 25 } 26} 27 28sk_sp<GrMtlEvent> GrMtlEvent::MakeWrapped(GrMTLHandle event) { 29 // The GrMtlEvent will have strong ownership at this point. 30 // The GrMTLHandle will subsequently only have weak ownership. 31 if (@available(macOS 10.14, iOS 12.0, tvOS 12.0, *)) { 32 id<MTLEvent> mtlEvent = (__bridge_transfer id<MTLEvent>)event; 33 return sk_sp<GrMtlEvent>(new GrMtlEvent(mtlEvent)); 34 } else { 35 return nullptr; 36 } 37} 38 39GrBackendSemaphore GrMtlSemaphore::backendSemaphore() const { 40 GrBackendSemaphore backendSemaphore; 41 // The GrMtlSemaphore and the GrBackendSemaphore will have strong ownership at this point. 42 // Whoever uses the GrBackendSemaphore will subsquently steal this ref (see MakeWrapped, above). 43 if (@available(macOS 10.14, iOS 12.0, tvOS 12.0, *)) { 44 GrMTLHandle handle = (__bridge_retained GrMTLHandle)(fEvent->mtlEvent()); 45 backendSemaphore = GrBackendSemaphores::MakeMtl(handle, fValue); 46 } 47 return backendSemaphore; 48} 49 50GR_NORETAIN_END 51