From 7da8c53c6de1fa8127ae5ae3805747b808326761 Mon Sep 17 00:00:00 2001 From: Dzmitry Malyshau Date: Tue, 24 Sep 2024 23:11:01 -0700 Subject: [PATCH] Add CounterSampleBuffer::resolve_counter_range --- src/counters.rs | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/counters.rs b/src/counters.rs index 0a39752..b02fbb9 100644 --- a/src/counters.rs +++ b/src/counters.rs @@ -1,4 +1,5 @@ -use crate::MTLStorageMode; +use crate::{MTLStorageMode, NSUInteger}; +use std::mem; /// See pub enum MTLCounterSampleBufferDescriptor {} @@ -63,6 +64,22 @@ foreign_obj_type! { pub struct CounterSampleBuffer; } +impl CounterSampleBufferRef { + pub fn sample_count(&self) -> u64 { + unsafe { msg_send![self, sampleCount] } + } + + pub fn resolve_counter_range(&self, range: crate::NSRange) -> Vec { + let mut data = vec![0 as NSUInteger; range.length as usize]; + let total_bytes = range.length * mem::size_of::() as u64; + unsafe { + let ns_data: *mut crate::Object = msg_send![self, resolveCounterRange: range]; + let () = msg_send![ns_data, getBytes: data.as_mut_ptr() length: total_bytes]; + } + data + } +} + /// See pub enum MTLCounter {}