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
|
|
|
|
2025-05-25 17:37:40 +02:00
|
|
|
macro_rules! os_error {
|
|
|
|
|
($error:expr) => {{
|
|
|
|
|
winit_core::error::OsError::new(line!(), file!(), $error)
|
|
|
|
|
}};
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-23 21:35:26 +01:00
|
|
|
macro_rules! trace_scope {
|
|
|
|
|
($s:literal) => {
|
2025-05-25 17:37:40 +02:00
|
|
|
let _crate = $crate::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:?}")))
|
|
|
|
|
}
|
|
|
|
|
}
|