2025-01-28 21:31:14 +01:00
|
|
|
use objc2_core_graphics::CGError;
|
2024-02-25 19:20:39 -08:00
|
|
|
use tracing::trace;
|
2025-05-17 04:26:09 +02:00
|
|
|
use winit_core::error::OsError;
|
2025-01-28 21:31:14 +01:00
|
|
|
|
2022-01-23 21:35:26 +01:00
|
|
|
macro_rules! trace_scope {
|
|
|
|
|
($s:literal) => {
|
2024-06-24 13:26:49 +02:00
|
|
|
let _crate =
|
|
|
|
|
$crate::platform_impl::platform::appkit::util::TraceGuard::new(module_path!(), $s);
|
2022-01-23 21:35:26 +01:00
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub(crate) struct TraceGuard {
|
|
|
|
|
module_path: &'static str,
|
|
|
|
|
called_from_fn: &'static str,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl TraceGuard {
|
|
|
|
|
#[inline]
|
|
|
|
|
pub(crate) fn new(module_path: &'static str, called_from_fn: &'static str) -> Self {
|
2024-02-25 19:20:39 -08:00
|
|
|
trace!(target = module_path, "Triggered `{}`", called_from_fn);
|
2022-01-23 21:35:26 +01:00
|
|
|
Self { module_path, called_from_fn }
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl Drop for TraceGuard {
|
|
|
|
|
#[inline]
|
|
|
|
|
fn drop(&mut self) {
|
2024-02-25 19:20:39 -08:00
|
|
|
trace!(target = self.module_path, "Completed `{}`", self.called_from_fn);
|
2022-01-23 21:35:26 +01:00
|
|
|
}
|
|
|
|
|
}
|
2025-01-28 21:31:14 +01:00
|
|
|
|
|
|
|
|
#[track_caller]
|
|
|
|
|
pub(crate) fn cgerr(err: CGError) -> Result<(), OsError> {
|
|
|
|
|
if err == CGError::Success {
|
|
|
|
|
Ok(())
|
|
|
|
|
} else {
|
|
|
|
|
Err(os_error!(format!("CGError {err:?}")))
|
|
|
|
|
}
|
|
|
|
|
}
|