diff --git a/CHANGELOG.md b/CHANGELOG.md index c93804e..ca5d486 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ - Update to `objc2` 0.6.0. - Bump MSRV to Rust 1.71. - Make `Context` cloneable. +- `Context`, `Surface` and `Buffer` now implement `Debug`. # 0.4.6 diff --git a/src/backend_dispatch.rs b/src/backend_dispatch.rs index 3b5d269..3a10e27 100644 --- a/src/backend_dispatch.rs +++ b/src/backend_dispatch.rs @@ -3,6 +3,7 @@ use crate::{backend_interface::*, backends, InitError, Rect, SoftBufferError}; use raw_window_handle::{HasDisplayHandle, HasWindowHandle}; +use std::fmt; use std::num::NonZeroU32; #[cfg(any(wayland_platform, x11_platform, kms_platform))] use std::sync::Arc; @@ -56,6 +57,17 @@ macro_rules! make_dispatch { } } + impl fmt::Debug for ContextDispatch { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + match self { + $( + $(#[$attr])* + Self::$name(inner) => inner.fmt(f), + )* + } + } + } + #[allow(clippy::large_enum_variant)] // it's boxed anyways pub(crate) enum SurfaceDispatch<$dgen, $wgen> { $( @@ -117,6 +129,17 @@ macro_rules! make_dispatch { } } + impl fmt::Debug for SurfaceDispatch { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + match self { + $( + $(#[$attr])* + Self::$name(inner) => inner.fmt(f), + )* + } + } + } + pub(crate) enum BufferDispatch<'a, $dgen, $wgen> { $( $(#[$attr])* @@ -172,6 +195,17 @@ macro_rules! make_dispatch { } } } + + impl fmt::Debug for BufferDispatch<'_, D, W> { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + match self { + $( + $(#[$attr])* + Self::$name(inner) => inner.fmt(f), + )* + } + } + } }; } diff --git a/src/backends/android.rs b/src/backends/android.rs index a14aaef..311ce9a 100644 --- a/src/backends/android.rs +++ b/src/backends/android.rs @@ -15,6 +15,7 @@ use crate::error::InitError; use crate::{BufferInterface, Rect, SoftBufferError, SurfaceInterface}; /// The handle to a window for software buffering. +#[derive(Debug)] pub struct AndroidImpl { native_window: NativeWindow, window: W, @@ -113,6 +114,7 @@ impl SurfaceInterface for Android } } +#[derive(Debug)] pub struct BufferImpl<'a, D: ?Sized, W> { native_window_buffer: NativeWindowBufferLockGuard<'a>, buffer: Vec, diff --git a/src/backends/cg.rs b/src/backends/cg.rs index ba6c17a..5be1373 100644 --- a/src/backends/cg.rs +++ b/src/backends/cg.rs @@ -28,6 +28,7 @@ define_class!( #[unsafe(super(NSObject))] #[name = "SoftbufferObserver"] #[ivars = SendCALayer] + #[derive(Debug)] struct Observer; /// NSKeyValueObserving @@ -92,6 +93,7 @@ impl Observer { } } +#[derive(Debug)] pub struct CGImpl { /// Our layer. layer: SendCALayer, @@ -263,6 +265,7 @@ impl SurfaceInterface for CGImpl< } } +#[derive(Debug)] pub struct BufferImpl<'a, D, W> { imp: &'a mut CGImpl, buffer: Box<[u32]>, @@ -344,6 +347,7 @@ impl BufferInterface for BufferImpl<'_, } } +#[derive(Debug)] struct SendCALayer(Retained); // SAFETY: CALayer is dubiously thread safe, like most things in Core Animation. diff --git a/src/backends/kms.rs b/src/backends/kms.rs index 35ed5b8..f2456e5 100644 --- a/src/backends/kms.rs +++ b/src/backends/kms.rs @@ -12,6 +12,7 @@ use drm::Device; use raw_window_handle::{HasDisplayHandle, HasWindowHandle, RawDisplayHandle, RawWindowHandle}; use std::collections::HashSet; +use std::fmt; use std::marker::PhantomData; use std::num::NonZeroU32; use std::os::unix::io::{AsFd, BorrowedFd}; @@ -118,6 +119,13 @@ pub(crate) struct BufferImpl<'a, D: ?Sized, W: ?Sized> { _window: PhantomData<&'a mut W>, } +impl fmt::Debug for BufferImpl<'_, D, W> { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + // FIXME: Derive instead once `DumbMapping` impls `Debug`. + f.debug_struct("BufferImpl").finish_non_exhaustive() + } +} + /// The combined frame buffer and dumb buffer. #[derive(Debug)] struct SharedBuffer { diff --git a/src/backends/orbital.rs b/src/backends/orbital.rs index d54683f..482d9c4 100644 --- a/src/backends/orbital.rs +++ b/src/backends/orbital.rs @@ -5,6 +5,7 @@ use std::{cmp, marker::PhantomData, num::NonZeroU32, slice, str}; use crate::backend_interface::*; use crate::{Rect, SoftBufferError}; +#[derive(Debug)] struct OrbitalMap { address: usize, size: usize, @@ -55,6 +56,7 @@ impl Drop for OrbitalMap { } } +#[derive(Debug)] pub struct OrbitalImpl { handle: ThreadSafeWindowHandle, width: u32, @@ -64,6 +66,7 @@ pub struct OrbitalImpl { _display: PhantomData, } +#[derive(Debug)] struct ThreadSafeWindowHandle(OrbitalWindowHandle); unsafe impl Send for ThreadSafeWindowHandle {} unsafe impl Sync for ThreadSafeWindowHandle {} @@ -180,11 +183,13 @@ impl SurfaceInterface for Orbital } } +#[derive(Debug)] enum Pixels { Mapping(OrbitalMap), Buffer(Vec), } +#[derive(Debug)] pub struct BufferImpl<'a, D, W> { imp: &'a mut OrbitalImpl, pixels: Pixels, diff --git a/src/backends/wayland/buffer.rs b/src/backends/wayland/buffer.rs index c4ebef0..9348090 100644 --- a/src/backends/wayland/buffer.rs +++ b/src/backends/wayland/buffer.rs @@ -67,6 +67,7 @@ unsafe fn map_file(file: &File) -> MmapMut { unsafe { MmapMut::map_mut(file.as_raw_fd()).expect("Failed to map shared memory") } } +#[derive(Debug)] pub(super) struct WaylandBuffer { qh: QueueHandle, tempfile: File, diff --git a/src/backends/wayland/mod.rs b/src/backends/wayland/mod.rs index 000e553..2256b80 100644 --- a/src/backends/wayland/mod.rs +++ b/src/backends/wayland/mod.rs @@ -20,6 +20,7 @@ use buffer::WaylandBuffer; struct State; +#[derive(Debug)] pub struct WaylandDisplayImpl { conn: Option, event_queue: Mutex>, @@ -74,6 +75,7 @@ impl Drop for WaylandDisplayImpl { } } +#[derive(Debug)] pub struct WaylandImpl { display: Arc>, surface: Option, @@ -257,6 +259,7 @@ impl Drop for WaylandImpl { } } +#[derive(Debug)] pub struct BufferImpl<'a, D: ?Sized, W> { stack: util::BorrowStack<'a, WaylandImpl, [u32]>, age: u8, diff --git a/src/backends/web.rs b/src/backends/web.rs index 6ebc70d..ae9da67 100644 --- a/src/backends/web.rs +++ b/src/backends/web.rs @@ -18,7 +18,7 @@ use std::num::NonZeroU32; /// Display implementation for the web platform. /// /// This just caches the document to prevent having to query it every time. -#[derive(Clone)] +#[derive(Clone, Debug)] pub struct WebDisplayImpl { document: web_sys::Document, _display: D, @@ -43,6 +43,7 @@ impl ContextInterface for WebDisplayImpl { } } +#[derive(Debug)] pub struct WebImpl { /// The handle and context to the canvas that we're drawing to. canvas: Canvas, @@ -65,6 +66,7 @@ pub struct WebImpl { /// Holding canvas and context for [`HtmlCanvasElement`] or [`OffscreenCanvas`], /// since they have different types. +#[derive(Debug)] enum Canvas { Canvas { canvas: HtmlCanvasElement, @@ -373,6 +375,7 @@ impl Canvas { } } +#[derive(Debug)] pub struct BufferImpl<'a, D, W> { imp: &'a mut WebImpl, } diff --git a/src/backends/win32.rs b/src/backends/win32.rs index 72dc6d0..ca26647 100644 --- a/src/backends/win32.rs +++ b/src/backends/win32.rs @@ -25,6 +25,7 @@ const ZERO_QUAD: Gdi::RGBQUAD = Gdi::RGBQUAD { rgbReserved: 0, }; +#[derive(Debug)] struct Buffer { dc: Gdi::HDC, bitmap: Gdi::HBITMAP, @@ -135,6 +136,7 @@ impl Buffer { } /// The handle to a window for software buffering. +#[derive(Debug)] pub struct Win32Impl { /// The window handle. window: OnlyUsedFromOrigin, @@ -281,6 +283,7 @@ impl SurfaceInterface for Win32Im } } +#[derive(Debug)] pub struct BufferImpl<'a, D, W>(&'a mut Win32Impl); impl BufferInterface for BufferImpl<'_, D, W> { @@ -460,6 +463,7 @@ impl Command { } } +#[derive(Debug)] struct OnlyUsedFromOrigin(T); unsafe impl Send for OnlyUsedFromOrigin {} diff --git a/src/backends/x11.rs b/src/backends/x11.rs index b4271f5..18c4be5 100644 --- a/src/backends/x11.rs +++ b/src/backends/x11.rs @@ -36,6 +36,7 @@ use x11rb::protocol::shm::{self, ConnectionExt as _}; use x11rb::protocol::xproto::{self, ConnectionExt as _, ImageOrder, VisualClass, Visualid}; use x11rb::xcb_ffi::XCBConnection; +#[derive(Debug)] pub struct X11DisplayImpl { /// The handle to the XCB connection. connection: Option, @@ -125,6 +126,7 @@ impl X11DisplayImpl { } /// The handle to an X11 drawing context. +#[derive(Debug)] pub struct X11Impl { /// X display this window belongs to. display: Arc>, @@ -155,6 +157,7 @@ pub struct X11Impl { } /// The buffer that is being drawn to. +#[derive(Debug)] enum Buffer { /// A buffer implemented using shared memory to prevent unnecessary copying. Shm(ShmBuffer), @@ -163,6 +166,7 @@ enum Buffer { Wire(Vec), } +#[derive(Debug)] struct ShmBuffer { /// The shared memory segment, paired with its ID. seg: Option<(ShmSegment, shm::Seg)>, @@ -383,6 +387,7 @@ impl SurfaceInterface fo } } +#[derive(Debug)] pub struct BufferImpl<'a, D: ?Sized, W: ?Sized>(&'a mut X11Impl); impl BufferInterface @@ -681,6 +686,7 @@ impl ShmBuffer { } } +#[derive(Debug)] struct ShmSegment { id: File, ptr: NonNull, diff --git a/src/lib.rs b/src/lib.rs index ec3f1e9..a733110 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -30,7 +30,7 @@ pub use backends::web::SurfaceExtWeb; /// An instance of this struct contains the platform-specific data that must be managed in order to /// write to a window on that platform. -#[derive(Clone)] +#[derive(Clone, Debug)] pub struct Context { /// The inner static dispatch object. context_impl: ContextDispatch, @@ -73,6 +73,7 @@ pub struct Rect { } /// A surface for drawing to a window with software buffers. +#[derive(Debug)] pub struct Surface { /// This is boxed so that `Surface` is the same size on every platform. surface_impl: Box>, @@ -200,6 +201,7 @@ impl HasWindowHandle for Surface /// /// Buffer copies an channel swizzling happen on: /// - Android +#[derive(Debug)] pub struct Buffer<'a, D, W> { buffer_impl: BufferDispatch<'a, D, W>, _marker: PhantomData<(Arc, Cell<()>)>, diff --git a/src/util.rs b/src/util.rs index de46e3f..bffeca8 100644 --- a/src/util.rs +++ b/src/util.rs @@ -2,6 +2,7 @@ #![allow(dead_code)] use std::cmp; +use std::fmt; use std::num::NonZeroU32; use crate::Rect; @@ -50,6 +51,12 @@ impl<'a, T: 'a + ?Sized, U: 'a + ?Sized> BorrowStack<'a, T, U> { } } +impl<'a, T: 'a + ?Sized, U: 'a + ?Sized + fmt::Debug> fmt::Debug for BorrowStack<'a, T, U> { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + self.member().fmt(f) + } +} + /// Calculates the smallest `Rect` necessary to represent all damaged `Rect`s. pub(crate) fn union_damage(damage: &[Rect]) -> Option { struct Region {