use std::{ffi::CStr, marker::PhantomData};
#[macro_export]
macro_rules! frame {
() => {
$crate::frame::frame();
};
($name:literal $(,)?) => {
$crate::frame::named_frame($crate::c_str!($name));
};
(discontinuous $name:literal $(,)?) => {
let _frame = $crate::frame::discontinuous_frame($crate::c_str!($name));
};
}
#[inline(always)]
pub fn frame() {
#[cfg(feature = "enable")]
unsafe {
sys::___tracy_emit_frame_mark(std::ptr::null());
}
}
#[inline(always)]
pub fn named_frame(name: &'static CStr) {
#[cfg(feature = "enable")]
unsafe {
sys::___tracy_emit_frame_mark(name.as_ptr());
}
}
#[inline(always)]
pub fn discontinuous_frame(name: &'static CStr) -> DiscontinuousFrame {
#[cfg(feature = "enable")]
unsafe {
sys::___tracy_emit_frame_mark_start(name.as_ptr());
DiscontinuousFrame {
unsend: PhantomData,
name,
}
}
#[cfg(not(feature = "enable"))]
DiscontinuousFrame {
unsend: PhantomData,
name: (),
}
}
pub struct DiscontinuousFrame {
unsend: PhantomData<*mut ()>,
#[cfg(feature = "enable")]
name: &'static CStr,
#[cfg(not(feature = "enable"))]
name: (),
}
impl Drop for DiscontinuousFrame {
#[inline(always)]
fn drop(&mut self) {
#[cfg(feature = "enable")]
unsafe {
sys::___tracy_emit_frame_mark_end(self.name.as_ptr());
}
}
}
#[repr(C)]
pub struct Pixel {
pub r: u8,
pub g: u8,
pub b: u8,
pub a: u8,
}
pub struct Image<'a> {
pub data: &'a [Pixel],
pub width: u16,
pub height: u16,
pub lag: u8,
pub flip: bool,
}
#[inline(always)]
pub fn frame_image(image: Image) {
#[cfg(feature = "enable")]
unsafe {
sys::___tracy_emit_frame_image(
image.data.as_ptr() as *const _,
image.width,
image.height,
image.lag,
image.flip as _,
);
}
}