2 * Copyright 2019 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 "src/gpu/ganesh/mtl/GrMtlSemaphore.h"
10 #include "src/gpu/ganesh/mtl/GrMtlGpu.h"
12 #if !__has_feature(objc_arc)
13 #error This file must be compiled with Arc. Use -fobjc-arc flag
18 sk_sp<GrMtlEvent> GrMtlEvent::Make(GrMtlGpu* gpu) {
19 if (@available(macOS 10.14, iOS 12.0, *)) {
20 id<MTLEvent> event = [gpu->device() newEvent];
21 return sk_sp<GrMtlEvent>(new GrMtlEvent(event));
27 sk_sp<GrMtlEvent> GrMtlEvent::MakeWrapped(GrMTLHandle event) {
28 // The GrMtlEvent will have strong ownership at this point.
29 // The GrMTLHandle will subsequently only have weak ownership.
30 if (@available(macOS 10.14, iOS 12.0, *)) {
31 id<MTLEvent> mtlEvent = (__bridge_transfer id<MTLEvent>)event;
32 return sk_sp<GrMtlEvent>(new GrMtlEvent(mtlEvent));
38 GrBackendSemaphore GrMtlSemaphore::backendSemaphore() const {
39 GrBackendSemaphore backendSemaphore;
40 // The GrMtlSemaphore and the GrBackendSemaphore will have strong ownership at this point.
41 // Whoever uses the GrBackendSemaphore will subsquently steal this ref (see MakeWrapped, above).
42 if (@available(macOS 10.14, iOS 12.0, *)) {
43 GrMTLHandle handle = (__bridge_retained GrMTLHandle)(fEvent->mtlEvent());
44 backendSemaphore.initMetal(handle, fValue);
46 return backendSemaphore;