Skip to content

Commit

Permalink
feat: add frame_image, for emitting low-res frame screenshots
Browse files Browse the repository at this point in the history
Refs: nagisa#96
  • Loading branch information
colinmarc committed Mar 14, 2024
1 parent d380940 commit 674b52f
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
31 changes: 31 additions & 0 deletions tracy-client/src/frame.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,30 @@ impl Client {
}
Frame(self.clone(), name)
}

/// Emits an image of a frame.
///
/// The following restrictions apply:
/// - The image must be in RGBA format.
/// - The image width and height must be divisible by four.
/// - The image data must be less than 256 KB, and should be as small as
/// possible.
///
/// The offset indicates how many frames in the past the image was captured.
/// For example, an offset of 1 would associate the image with the previous
/// call to [`frame_mark`](Client::frame_mark).
///
/// The `flip` parameter indicates that the image should be flipped before
/// displaying, for example if the image is an OpenGL texture.
pub fn frame_image(&self, image: &[u8], width: u16, height: u16, offset: u8, flip: bool) {
#[cfg(feature = "enable")]
unsafe {
// SAFE: Tracy copies the data before returning.
let ptr = image.as_ptr();

let () = sys::___tracy_emit_frame_image(ptr.cast(), width, height, offset, flip as i32);
}
}
}

/// Construct a [`FrameName`].
Expand Down Expand Up @@ -150,6 +174,13 @@ pub fn frame_mark() {
.frame_mark();
}

/// Convenience shortcut for [`Client::frame_image`] on the current client.
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);
}

/// Convenience macro for [`Client::secondary_frame_mark`] on the current client.
///
/// # Panics
Expand Down
2 changes: 1 addition & 1 deletion tracy-client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#![doc = include_str!("../FEATURES.mkd")]
#![cfg_attr(tracy_client_docs, feature(doc_auto_cfg))]

pub use crate::frame::{frame_mark, Frame, FrameName};
pub use crate::frame::{frame_image, frame_mark, Frame, FrameName};
pub use crate::gpu::{
GpuContext, GpuContextCreationError, GpuContextType, GpuSpan, GpuSpanCreationError,
};
Expand Down

0 comments on commit 674b52f

Please sign in to comment.