MTLEvent.hpp
1 //------------------------------------------------------------------------------------------------------------------------------------------------------------- 2 // 3 // Metal/MTLEvent.hpp 4 // 5 // Copyright 2020-2024 Apple Inc. 6 // 7 // Licensed under the Apache License, Version 2.0 (the "License"); 8 // you may not use this file except in compliance with the License. 9 // You may obtain a copy of the License at 10 // 11 // http://www.apache.org/licenses/LICENSE-2.0 12 // 13 // Unless required by applicable law or agreed to in writing, software 14 // distributed under the License is distributed on an "AS IS" BASIS, 15 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 // See the License for the specific language governing permissions and 17 // limitations under the License. 18 // 19 //------------------------------------------------------------------------------------------------------------------------------------------------------------- 20 21 #pragma once 22 23 #include "MTLDefines.hpp" 24 #include "MTLHeaderBridge.hpp" 25 #include "MTLPrivate.hpp" 26 27 #include <Foundation/Foundation.hpp> 28 29 #include "MTLEvent.hpp" 30 31 namespace MTL 32 { 33 class Event : public NS::Referencing<Event> 34 { 35 public: 36 class Device* device() const; 37 38 NS::String* label() const; 39 void setLabel(const NS::String* label); 40 }; 41 42 class SharedEventListener : public NS::Referencing<SharedEventListener> 43 { 44 public: 45 static class SharedEventListener* alloc(); 46 47 MTL::SharedEventListener* init(); 48 49 MTL::SharedEventListener* init(const dispatch_queue_t dispatchQueue); 50 51 dispatch_queue_t dispatchQueue() const; 52 }; 53 54 using SharedEventNotificationBlock = void (^)(SharedEvent* pEvent, std::uint64_t value); 55 56 class SharedEvent : public NS::Referencing<SharedEvent, Event> 57 { 58 public: 59 void notifyListener(const class SharedEventListener* listener, uint64_t value, const MTL::SharedEventNotificationBlock block); 60 61 class SharedEventHandle* newSharedEventHandle(); 62 63 bool waitUntilSignaledValue(uint64_t value, uint64_t milliseconds); 64 65 uint64_t signaledValue() const; 66 void setSignaledValue(uint64_t signaledValue); 67 }; 68 69 class SharedEventHandle : public NS::SecureCoding<SharedEventHandle> 70 { 71 public: 72 static class SharedEventHandle* alloc(); 73 74 class SharedEventHandle* init(); 75 76 NS::String* label() const; 77 }; 78 79 } 80 81 // property: device 82 _MTL_INLINE MTL::Device* MTL::Event::device() const 83 { 84 return Object::sendMessage<MTL::Device*>(this, _MTL_PRIVATE_SEL(device)); 85 } 86 87 // property: label 88 _MTL_INLINE NS::String* MTL::Event::label() const 89 { 90 return Object::sendMessage<NS::String*>(this, _MTL_PRIVATE_SEL(label)); 91 } 92 93 _MTL_INLINE void MTL::Event::setLabel(const NS::String* label) 94 { 95 Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(setLabel_), label); 96 } 97 98 // static method: alloc 99 _MTL_INLINE MTL::SharedEventListener* MTL::SharedEventListener::alloc() 100 { 101 return NS::Object::alloc<MTL::SharedEventListener>(_MTL_PRIVATE_CLS(MTLSharedEventListener)); 102 } 103 104 // method: init 105 _MTL_INLINE MTL::SharedEventListener* MTL::SharedEventListener::init() 106 { 107 return NS::Object::init<MTL::SharedEventListener>(); 108 } 109 110 // method: initWithDispatchQueue: 111 _MTL_INLINE MTL::SharedEventListener* MTL::SharedEventListener::init(const dispatch_queue_t dispatchQueue) 112 { 113 return Object::sendMessage<MTL::SharedEventListener*>(this, _MTL_PRIVATE_SEL(initWithDispatchQueue_), dispatchQueue); 114 } 115 116 // property: dispatchQueue 117 _MTL_INLINE dispatch_queue_t MTL::SharedEventListener::dispatchQueue() const 118 { 119 return Object::sendMessage<dispatch_queue_t>(this, _MTL_PRIVATE_SEL(dispatchQueue)); 120 } 121 122 // method: notifyListener:atValue:block: 123 _MTL_INLINE void MTL::SharedEvent::notifyListener(const MTL::SharedEventListener* listener, uint64_t value, const MTL::SharedEventNotificationBlock block) 124 { 125 Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(notifyListener_atValue_block_), listener, value, block); 126 } 127 128 // method: newSharedEventHandle 129 _MTL_INLINE MTL::SharedEventHandle* MTL::SharedEvent::newSharedEventHandle() 130 { 131 return Object::sendMessage<MTL::SharedEventHandle*>(this, _MTL_PRIVATE_SEL(newSharedEventHandle)); 132 } 133 134 // method: waitUntilSignaledValue:timeoutMS: 135 _MTL_INLINE bool MTL::SharedEvent::waitUntilSignaledValue(uint64_t value, uint64_t milliseconds) 136 { 137 return Object::sendMessage<bool>(this, _MTL_PRIVATE_SEL(waitUntilSignaledValue_timeoutMS_), value, milliseconds); 138 } 139 140 // property: signaledValue 141 _MTL_INLINE uint64_t MTL::SharedEvent::signaledValue() const 142 { 143 return Object::sendMessage<uint64_t>(this, _MTL_PRIVATE_SEL(signaledValue)); 144 } 145 146 _MTL_INLINE void MTL::SharedEvent::setSignaledValue(uint64_t signaledValue) 147 { 148 Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(setSignaledValue_), signaledValue); 149 } 150 151 // static method: alloc 152 _MTL_INLINE MTL::SharedEventHandle* MTL::SharedEventHandle::alloc() 153 { 154 return NS::Object::alloc<MTL::SharedEventHandle>(_MTL_PRIVATE_CLS(MTLSharedEventHandle)); 155 } 156 157 // method: init 158 _MTL_INLINE MTL::SharedEventHandle* MTL::SharedEventHandle::init() 159 { 160 return NS::Object::init<MTL::SharedEventHandle>(); 161 } 162 163 // property: label 164 _MTL_INLINE NS::String* MTL::SharedEventHandle::label() const 165 { 166 return Object::sendMessage<NS::String*>(this, _MTL_PRIVATE_SEL(label)); 167 }