use crate::Client;
pub struct Frame(Client, FrameName);
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord)]
pub struct FrameName(pub(crate) &'static str);
impl FrameName {
#[must_use]
pub fn new_leak(name: String) -> Self {
#[cfg(feature = "enable")]
{
let mut name = name;
name.push('\0');
let name = Box::leak(name.into_boxed_str());
Self(name)
}
#[cfg(not(feature = "enable"))]
{
drop(name);
Self("\0")
}
}
}
impl Client {
pub fn frame_mark(&self) {
#[cfg(feature = "enable")]
unsafe {
let () = sys::___tracy_emit_frame_mark(std::ptr::null());
}
}
pub fn secondary_frame_mark(&self, name: FrameName) {
#[cfg(feature = "enable")]
unsafe {
let () = sys::___tracy_emit_frame_mark(name.0.as_ptr().cast());
}
}
#[must_use]
pub fn non_continuous_frame(&self, name: FrameName) -> Frame {
#[cfg(feature = "enable")]
unsafe {
let () = sys::___tracy_emit_frame_mark_start(name.0.as_ptr().cast());
}
Frame(self.clone(), name)
}
pub fn frame_image(&self, image: &[u8], width: u16, height: u16, offset: u8, flip: bool) {
#[cfg(feature = "enable")]
unsafe {
let ptr = image.as_ptr();
let () = sys::___tracy_emit_frame_image(ptr.cast(), width, height, offset, flip as i32);
}
}
}
#[macro_export]
macro_rules! frame_name {
($name: literal) => {{
unsafe { $crate::internal::create_frame_name(concat!($name, "\0")) }
}};
}
impl Drop for Frame {
fn drop(&mut self) {
#[cfg(feature = "enable")]
unsafe {
let () = sys::___tracy_emit_frame_mark_end(self.1 .0.as_ptr().cast());
std::convert::identity(&self.0);
}
}
}
pub fn frame_mark() {
Client::running()
.expect("frame_mark! without a running Client")
.frame_mark();
}
pub fn frame_image(image: &[u8], width: u16, height: u16, offset: u8, flip: bool) {
Client::running()
.expect("frame_image without a running Client")
.frame_image(image, width, height, offset, flip);
}
#[macro_export]
macro_rules! secondary_frame_mark {
($name: literal) => {{
$crate::Client::running()
.expect("secondary_frame_mark! without a running Client")
.secondary_frame_mark($crate::frame_name!($name))
}};
}
#[macro_export]
macro_rules! non_continuous_frame {
($name: literal) => {{
$crate::Client::running()
.expect("non_continuous_frame! without a running Client")
.non_continuous_frame($crate::frame_name!($name))
}};
}