Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add frame_image, for emitting low-res frame screenshots #97

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading