/* * Copyright 2019 Google Inc. * * Use of this source code is governed by a BSD-style license that can be * found in the LICENSE file. */ #ifndef GrMtlSemaphore_DEFINED #define GrMtlSemaphore_DEFINED #include "include/gpu/GrBackendSemaphore.h" #include "include/private/GrTypesPriv.h" #include "src/gpu/GrManagedResource.h" #include "src/gpu/GrSemaphore.h" #include "src/gpu/mtl/GrMtlUtil.h" #include class GrMtlGpu; class GrMtlEvent : public GrManagedResource { public: static sk_sp Make(GrMtlGpu* gpu); static sk_sp MakeWrapped(GrMTLHandle event); ~GrMtlEvent() override {} id mtlEvent() const SK_API_AVAILABLE(macos(10.14), ios(12.0)) { return fMtlEvent; } #ifdef SK_TRACE_MANAGED_RESOURCES /** output a human-readable dump of this resource's information */ void dumpInfo() const override { if (@available(macOS 10.14, iOS 12.0, *)) { SkDebugf("GrMtlEvent: %p (%ld refs)\n", fMtlEvent, CFGetRetainCount((CFTypeRef)fMtlEvent)); } } #endif void freeGPUData() const override { if (@available(macOS 10.14, iOS 12.0, *)) { fMtlEvent = nil; } } private: GrMtlEvent(id mtlEvent) SK_API_AVAILABLE(macos(10.14), ios(12.0)) : fMtlEvent(mtlEvent) {} mutable id fMtlEvent SK_API_AVAILABLE(macos(10.14), ios(12.0)); }; class GrMtlSemaphore : public GrSemaphore { public: static std::unique_ptr Make(GrMtlGpu* gpu) { sk_sp event = GrMtlEvent::Make(gpu); if (!event) { return nullptr; } return std::unique_ptr(new GrMtlSemaphore(std::move(event), 1)); } static std::unique_ptr MakeWrapped(GrMTLHandle mtlEvent, uint64_t value) { sk_sp event = GrMtlEvent::MakeWrapped(mtlEvent); if (!event) { return nullptr; } return std::unique_ptr(new GrMtlSemaphore(std::move(event), value)); } ~GrMtlSemaphore() override {} sk_sp event() { return fEvent; } uint64_t value() const { return fValue; } GrBackendSemaphore backendSemaphore() const override; private: GrMtlSemaphore(sk_sp event, uint64_t value) : fEvent(std::move(event)) , fValue(value) {} void setIsOwned() override {} sk_sp fEvent; uint64_t fValue; using INHERITED = GrSemaphore; }; #endif