Debian Codegraph @

src/gpu/ganesh/mtl/GrMtlSemaphore.h

raw
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 #ifndef GrMtlSemaphore_DEFINED
9 #define GrMtlSemaphore_DEFINED
10
11 #include "include/gpu/ganesh/GrBackendSemaphore.h"
12 #include "include/private/gpu/ganesh/GrTypesPriv.h"
13 #include "src/gpu/ganesh/GrManagedResource.h"
14 #include "src/gpu/ganesh/GrSemaphore.h"
15 #include "src/gpu/ganesh/mtl/GrMtlUtil.h"
16
17 #include <Metal/Metal.h>
18
19 class GrMtlGpu;
20
21 class GrMtlEvent : public GrManagedResource {
22 public:
23 static sk_sp<GrMtlEvent> Make(GrMtlGpu* gpu);
24
25 static sk_sp<GrMtlEvent> MakeWrapped(GrMTLHandle event);
26
27 ~GrMtlEvent() override {}
28
29 id<MTLEvent> mtlEvent() const SK_API_AVAILABLE(macos(10.14), ios(12.0), tvos(12.0)) {
30 return fMtlEvent;
31 }
32
33 #ifdef SK_TRACE_MANAGED_RESOURCES
34 /** output a human-readable dump of this resource's information
35 */
36 void dumpInfo() const override {
37 if (@available(macOS 10.14, iOS 12.0, tvOS 12.0, *)) {
38 SkDebugf("GrMtlEvent: %p (%ld refs)\n", fMtlEvent,
39 CFGetRetainCount((CFTypeRef)fMtlEvent));
40 }
41 }
42 #endif
43
44 void freeGPUData() const override {
45 if (@available(macOS 10.14, iOS 12.0, tvOS 12.0, *)) {
46 fMtlEvent = nil;
47 }
48 }
49
50 private:
51 GrMtlEvent(id<MTLEvent> mtlEvent) SK_API_AVAILABLE(macos(10.14), ios(12.0), tvos(12.0))
52 : fMtlEvent(mtlEvent) {}
53
54 mutable id<MTLEvent> fMtlEvent SK_API_AVAILABLE(macos(10.14), ios(12.0), tvos(12.0));
55 };
56
57 class GrMtlSemaphore : public GrSemaphore {
58 public:
59 static std::unique_ptr<GrMtlSemaphore> Make(GrMtlGpu* gpu) {
60 sk_sp<GrMtlEvent> event = GrMtlEvent::Make(gpu);
61 if (!event) {
62 return nullptr;
63 }
64 return std::unique_ptr<GrMtlSemaphore>(new GrMtlSemaphore(std::move(event), 1));
65 }
66
67 static std::unique_ptr<GrMtlSemaphore> MakeWrapped(GrMTLHandle mtlEvent, uint64_t value) {
68 sk_sp<GrMtlEvent> event = GrMtlEvent::MakeWrapped(mtlEvent);
69 if (!event) {
70 return nullptr;
71 }
72 return std::unique_ptr<GrMtlSemaphore>(new GrMtlSemaphore(std::move(event), value));
73 }
74
75 ~GrMtlSemaphore() override {}
76
77 sk_sp<GrMtlEvent> event() { return fEvent; }
78 uint64_t value() const { return fValue; }
79
80 GrBackendSemaphore backendSemaphore() const override;
81
82 private:
83 GrMtlSemaphore(sk_sp<GrMtlEvent> event, uint64_t value)
84 : fEvent(std::move(event))
85 , fValue(value) {}
86
87 void setIsOwned() override {}
88
89 sk_sp<GrMtlEvent> fEvent;
90 uint64_t fValue;
91
92 using INHERITED = GrSemaphore;
93 };
94
95 #endif