Skip to main content

metal/
counters.rs

1use crate::{MTLStorageMode, NSUInteger};
2
3/// See <https://developer.apple.com/documentation/metal/mtlcountersamplebufferdescriptor>
4pub enum MTLCounterSampleBufferDescriptor {}
5
6foreign_obj_type! {
7    type CType = MTLCounterSampleBufferDescriptor;
8    pub struct CounterSampleBufferDescriptor;
9}
10
11impl CounterSampleBufferDescriptor {
12    pub fn new() -> Self {
13        let class = class!(MTLCounterSampleBufferDescriptor);
14        unsafe { msg_send![class, new] }
15    }
16}
17
18impl CounterSampleBufferDescriptorRef {
19    pub fn counter_set(&self) -> &CounterSetRef {
20        unsafe { msg_send![self, counterSet] }
21    }
22
23    pub fn set_counter_set(&self, counter_set: &CounterSetRef) {
24        unsafe { msg_send![self, setCounterSet: counter_set] }
25    }
26
27    pub fn label(&self) -> &str {
28        unsafe {
29            let label = msg_send![self, label];
30            crate::nsstring_as_str(label)
31        }
32    }
33
34    pub fn set_label(&self, label: &str) {
35        unsafe {
36            let nslabel = crate::nsstring_from_str(label);
37            let () = msg_send![self, setLabel: nslabel];
38        }
39    }
40
41    pub fn sample_count(&self) -> u64 {
42        unsafe { msg_send![self, sampleCount] }
43    }
44
45    pub fn set_sample_count(&self, sample_count: u64) {
46        unsafe { msg_send![self, setSampleCount: sample_count] }
47    }
48
49    pub fn storage_mode(&self) -> MTLStorageMode {
50        unsafe { msg_send![self, storageMode] }
51    }
52
53    pub fn set_storage_mode(&self, storage_mode: MTLStorageMode) {
54        unsafe { msg_send![self, setStorageMode: storage_mode] }
55    }
56}
57
58/// See <https://developer.apple.com/documentation/metal/mtlcountersamplebuffer>
59pub enum MTLCounterSampleBuffer {}
60
61foreign_obj_type! {
62    type CType = MTLCounterSampleBuffer;
63    pub struct CounterSampleBuffer;
64}
65
66impl CounterSampleBufferRef {
67    pub fn sample_count(&self) -> u64 {
68        unsafe { msg_send![self, sampleCount] }
69    }
70
71    pub fn resolve_counter_range(&self, range: crate::NSRange) -> Vec<NSUInteger> {
72        let mut data = Vec::with_capacity(range.length as usize);
73        let total_bytes = size_of_val(data.as_slice()) as u64;
74        unsafe {
75            let ns_data: *mut crate::Object = msg_send![self, resolveCounterRange: range];
76            let () = msg_send![ns_data, getBytes: data.as_mut_ptr() length: total_bytes];
77            data.set_len(range.length as usize);
78        }
79        data
80    }
81}
82
83/// See <https://developer.apple.com/documentation/metal/mtlcounter>
84pub enum MTLCounter {}
85
86foreign_obj_type! {
87    type CType = MTLCounter;
88    pub struct Counter;
89}
90
91impl CounterRef {}
92
93/// See <https://developer.apple.com/documentation/metal/mtlcounterset>
94pub enum MTLCounterSet {}
95
96foreign_obj_type! {
97    type CType = MTLCounterSet;
98    pub struct CounterSet;
99}
100
101impl CounterSetRef {
102    pub fn name(&self) -> &str {
103        unsafe {
104            let name = msg_send![self, name];
105            crate::nsstring_as_str(name)
106        }
107    }
108}
109
110/// See <https://developer.apple.com/documentation/metal/mtlcommoncounterset>
111pub enum MTLCommonCounterSet {}
112
113/// See <https://developer.apple.com/documentation/metal/mtlcommoncounter>
114pub enum MTLCommonCounter {}
115
116foreign_obj_type! {
117    type CType = MTLCommonCounter;
118    pub struct CommonCounter;
119}