Skip to content
Open
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
- Bump MSRV to Rust 1.71.
- Make `Context` cloneable.
- Added `Buffer::width()` and `Buffer::height()` getters.
- `Context`, `Surface` and `Buffer` now implement `Debug`.

# 0.4.6

Expand Down
34 changes: 34 additions & 0 deletions src/backend_dispatch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -56,6 +57,17 @@ macro_rules! make_dispatch {
}
}

impl<D: fmt::Debug> fmt::Debug for ContextDispatch<D> {
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> {
$(
Expand Down Expand Up @@ -117,6 +129,17 @@ macro_rules! make_dispatch {
}
}

impl<D: fmt::Debug, W: fmt::Debug> fmt::Debug for SurfaceDispatch<D, W> {
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])*
Expand Down Expand Up @@ -192,6 +215,17 @@ macro_rules! make_dispatch {
}
}
}

impl<D: fmt::Debug, W: fmt::Debug> fmt::Debug for BufferDispatch<'_, D, W> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
$(
$(#[$attr])*
Self::$name(inner) => inner.fmt(f),
)*
}
}
}
};
}

Expand Down
8 changes: 5 additions & 3 deletions src/backends/android.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ use raw_window_handle::AndroidNdkWindowHandle;
use raw_window_handle::{HasDisplayHandle, HasWindowHandle, RawWindowHandle};

use crate::error::InitError;
use crate::{BufferInterface, Rect, SoftBufferError, SurfaceInterface};
use crate::{util, BufferInterface, Rect, SoftBufferError, SurfaceInterface};

/// The handle to a window for software buffering.
#[derive(Debug)]
pub struct AndroidImpl<D, W> {
native_window: NativeWindow,
window: W,
Expand Down Expand Up @@ -102,7 +103,7 @@ impl<D: HasDisplayHandle, W: HasWindowHandle> SurfaceInterface<D, W> for Android

Ok(BufferImpl {
native_window_buffer,
buffer,
buffer: util::PixelBuffer(buffer),
marker: PhantomData,
})
}
Expand All @@ -113,9 +114,10 @@ impl<D: HasDisplayHandle, W: HasWindowHandle> SurfaceInterface<D, W> for Android
}
}

#[derive(Debug)]
pub struct BufferImpl<'a, D: ?Sized, W> {
native_window_buffer: NativeWindowBufferLockGuard<'a>,
buffer: Vec<u32>,
buffer: util::PixelBuffer,
marker: PhantomData<(&'a D, &'a W)>,
}

Expand Down
12 changes: 8 additions & 4 deletions src/backends/cg.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Softbuffer implementation using CoreGraphics.
use crate::backend_interface::*;
use crate::error::InitError;
use crate::{Rect, SoftBufferError};
use crate::{util, Rect, SoftBufferError};
use objc2::rc::Retained;
use objc2::runtime::{AnyObject, Bool};
use objc2::{define_class, msg_send, AllocAnyThread, DefinedClass, MainThreadMarker, Message};
Expand Down Expand Up @@ -29,6 +29,7 @@ define_class!(
#[unsafe(super(NSObject))]
#[name = "SoftbufferObserver"]
#[ivars = SendCALayer]
#[derive(Debug)]
struct Observer;

/// NSKeyValueObserving
Expand Down Expand Up @@ -93,6 +94,7 @@ impl Observer {
}
}

#[derive(Debug)]
pub struct CGImpl<D, W> {
/// Our layer.
layer: SendCALayer,
Expand Down Expand Up @@ -258,15 +260,16 @@ impl<D: HasDisplayHandle, W: HasWindowHandle> SurfaceInterface<D, W> for CGImpl<

fn buffer_mut(&mut self) -> Result<BufferImpl<'_, D, W>, SoftBufferError> {
Ok(BufferImpl {
buffer: vec![0; self.width * self.height].into(),
buffer: util::PixelBuffer(vec![0; self.width * self.height]),
imp: self,
})
}
}

#[derive(Debug)]
pub struct BufferImpl<'a, D, W> {
imp: &'a mut CGImpl<D, W>,
buffer: Box<[u32]>,
buffer: util::PixelBuffer,
}

impl<D: HasDisplayHandle, W: HasWindowHandle> BufferInterface for BufferImpl<'_, D, W> {
Expand Down Expand Up @@ -306,7 +309,7 @@ impl<D: HasDisplayHandle, W: HasWindowHandle> BufferInterface for BufferImpl<'_,

let data_provider = {
let len = self.buffer.len() * size_of::<u32>();
let buffer: *mut [u32] = Box::into_raw(self.buffer);
let buffer: *mut [u32] = Box::into_raw(self.buffer.0.into_boxed_slice());
// Convert slice pointer to thin pointer.
let data_ptr = buffer.cast::<c_void>();

Expand Down Expand Up @@ -363,6 +366,7 @@ impl<D: HasDisplayHandle, W: HasWindowHandle> BufferInterface for BufferImpl<'_,
}
}

#[derive(Debug)]
struct SendCALayer(Retained<CALayer>);

// SAFETY: CALayer is dubiously thread safe, like most things in Core Animation.
Expand Down
8 changes: 8 additions & 0 deletions src/backends/kms.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -118,6 +119,13 @@ pub(crate) struct BufferImpl<'a, D: ?Sized, W: ?Sized> {
_window: PhantomData<&'a mut W>,
}

impl<D: ?Sized + fmt::Debug, W: ?Sized + fmt::Debug> 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 {
Expand Down
15 changes: 12 additions & 3 deletions src/backends/orbital.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ use raw_window_handle::{HasDisplayHandle, HasWindowHandle, OrbitalWindowHandle,
use std::{cmp, marker::PhantomData, num::NonZeroU32, slice, str};

use crate::backend_interface::*;
use crate::{Rect, SoftBufferError};
use crate::{util, Rect, SoftBufferError};

#[derive(Debug)]
struct OrbitalMap {
address: usize,
size: usize,
Expand Down Expand Up @@ -55,6 +56,7 @@ impl Drop for OrbitalMap {
}
}

#[derive(Debug)]
pub struct OrbitalImpl<D, W> {
handle: ThreadSafeWindowHandle,
width: u32,
Expand All @@ -64,6 +66,7 @@ pub struct OrbitalImpl<D, W> {
_display: PhantomData<D>,
}

#[derive(Debug)]
struct ThreadSafeWindowHandle(OrbitalWindowHandle);
unsafe impl Send for ThreadSafeWindowHandle {}
unsafe impl Sync for ThreadSafeWindowHandle {}
Expand Down Expand Up @@ -174,17 +177,23 @@ impl<D: HasDisplayHandle, W: HasWindowHandle> SurfaceInterface<D, W> for Orbital
.expect("failed to map orbital window"),
)
} else {
Pixels::Buffer(vec![0; self.width as usize * self.height as usize])
Pixels::Buffer(util::PixelBuffer(vec![
0;
self.width as usize
* self.height as usize
]))
};
Ok(BufferImpl { imp: self, pixels })
}
}

#[derive(Debug)]
enum Pixels {
Mapping(OrbitalMap),
Buffer(Vec<u32>),
Buffer(util::PixelBuffer),
}

#[derive(Debug)]
pub struct BufferImpl<'a, D, W> {
imp: &'a mut OrbitalImpl<D, W>,
pixels: Pixels,
Expand Down
1 change: 1 addition & 0 deletions src/backends/wayland/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<State>,
tempfile: File,
Expand Down
3 changes: 3 additions & 0 deletions src/backends/wayland/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use buffer::WaylandBuffer;

struct State;

#[derive(Debug)]
pub struct WaylandDisplayImpl<D: ?Sized> {
conn: Option<Connection>,
event_queue: Mutex<EventQueue<State>>,
Expand Down Expand Up @@ -74,6 +75,7 @@ impl<D: ?Sized> Drop for WaylandDisplayImpl<D> {
}
}

#[derive(Debug)]
pub struct WaylandImpl<D: ?Sized, W: ?Sized> {
display: Arc<WaylandDisplayImpl<D>>,
surface: Option<wl_surface::WlSurface>,
Expand Down Expand Up @@ -261,6 +263,7 @@ impl<D: ?Sized, W: ?Sized> Drop for WaylandImpl<D, W> {
}
}

#[derive(Debug)]
pub struct BufferImpl<'a, D: ?Sized, W> {
stack: util::BorrowStack<'a, WaylandImpl<D, W>, [u32]>,
width: i32,
Expand Down
11 changes: 7 additions & 4 deletions src/backends/web.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<D> {
document: web_sys::Document,
_display: D,
Expand All @@ -43,12 +43,13 @@ impl<D: HasDisplayHandle> ContextInterface<D> for WebDisplayImpl<D> {
}
}

#[derive(Debug)]
pub struct WebImpl<D, W> {
/// The handle and context to the canvas that we're drawing to.
canvas: Canvas,

/// The buffer that we're drawing to.
buffer: Vec<u32>,
buffer: util::PixelBuffer,

/// Buffer has been presented.
buffer_presented: bool,
Expand All @@ -65,6 +66,7 @@ pub struct WebImpl<D, W> {

/// Holding canvas and context for [`HtmlCanvasElement`] or [`OffscreenCanvas`],
/// since they have different types.
#[derive(Debug)]
enum Canvas {
Canvas {
canvas: HtmlCanvasElement,
Expand All @@ -82,7 +84,7 @@ impl<D: HasDisplayHandle, W: HasWindowHandle> WebImpl<D, W> {

Ok(Self {
canvas: Canvas::Canvas { canvas, ctx },
buffer: Vec::new(),
buffer: util::PixelBuffer(Vec::new()),
buffer_presented: false,
size: None,
window_handle: window,
Expand All @@ -98,7 +100,7 @@ impl<D: HasDisplayHandle, W: HasWindowHandle> WebImpl<D, W> {

Ok(Self {
canvas: Canvas::OffscreenCanvas { canvas, ctx },
buffer: Vec::new(),
buffer: util::PixelBuffer(Vec::new()),
buffer_presented: false,
size: None,
window_handle: window,
Expand Down Expand Up @@ -373,6 +375,7 @@ impl Canvas {
}
}

#[derive(Debug)]
pub struct BufferImpl<'a, D, W> {
imp: &'a mut WebImpl<D, W>,
}
Expand Down
4 changes: 4 additions & 0 deletions src/backends/win32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const ZERO_QUAD: Gdi::RGBQUAD = Gdi::RGBQUAD {
rgbReserved: 0,
};

#[derive(Debug)]
struct Buffer {
dc: Gdi::HDC,
bitmap: Gdi::HBITMAP,
Expand Down Expand Up @@ -135,6 +136,7 @@ impl Buffer {
}

/// The handle to a window for software buffering.
#[derive(Debug)]
pub struct Win32Impl<D: ?Sized, W> {
/// The window handle.
window: OnlyUsedFromOrigin<HWND>,
Expand Down Expand Up @@ -281,6 +283,7 @@ impl<D: HasDisplayHandle, W: HasWindowHandle> SurfaceInterface<D, W> for Win32Im
}
}

#[derive(Debug)]
pub struct BufferImpl<'a, D, W>(&'a mut Win32Impl<D, W>);

impl<D: HasDisplayHandle, W: HasWindowHandle> BufferInterface for BufferImpl<'_, D, W> {
Expand Down Expand Up @@ -468,6 +471,7 @@ impl Command {
}
}

#[derive(Debug)]
struct OnlyUsedFromOrigin<T>(T);
unsafe impl<T> Send for OnlyUsedFromOrigin<T> {}

Expand Down
Loading