Skip to content

Commit

Permalink
Merge pull request #53 from ids1024/update
Browse files Browse the repository at this point in the history
Update to stable wayland-rs 0.30, specify `rust-version`, rename `SwBufError` back to `SoftBufferError`
  • Loading branch information
ids1024 authored Dec 27, 2022
2 parents 3eeafad + fc1bba6 commit a800ca4
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 36 deletions.
5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ repository = "https://github.com/rust-windowing/softbuffer"
keywords = ["framebuffer", "windowing"]
categories = ["game-development", "graphics", "gui", "multimedia", "rendering"]
exclude = ["examples"]
rust-version = "1.60.0"

[features]
default = ["x11", "wayland", "wayland-dlopen"]
Expand All @@ -24,8 +25,8 @@ log = "0.4.17"

[target.'cfg(any(target_os = "linux", target_os = "freebsd"))'.dependencies]
nix = { version = "0.26.1", optional = true }
wayland-backend = { version = "0.1.0-beta.14", features = ["client_system"], optional = true }
wayland-client = { version = "0.30.0-beta.14", optional = true }
wayland-backend = { version = "0.1.0", features = ["client_system"], optional = true }
wayland-client = { version = "0.30.0", optional = true }
wayland-sys = "0.30.0"
bytemuck = { version = "1.12.3", optional = true }
x11-dl = { version = "2.19.1", optional = true }
Expand Down
4 changes: 2 additions & 2 deletions src/cg.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::SwBufError;
use crate::SoftBufferError;
use core_graphics::base::{
kCGBitmapByteOrder32Little, kCGImageAlphaNoneSkipFirst, kCGRenderingIntentDefault,
};
Expand All @@ -19,7 +19,7 @@ pub struct CGImpl {
}

impl CGImpl {
pub unsafe fn new(handle: AppKitWindowHandle) -> Result<Self, SwBufError> {
pub unsafe fn new(handle: AppKitWindowHandle) -> Result<Self, SoftBufferError> {
let window = handle.ns_window as id;
let view = handle.ns_view as id;
let layer = CALayer::new();
Expand Down
6 changes: 3 additions & 3 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use thiserror::Error;

#[derive(Error, Debug)]
#[non_exhaustive]
pub enum SwBufError {
pub enum SoftBufferError {
#[error(
"The provided window returned an unsupported platform: {human_readable_window_platform_name}, {human_readable_display_platform_name}."
)]
Expand All @@ -29,10 +29,10 @@ pub enum SwBufError {
pub(crate) fn unwrap<T, E: std::error::Error + 'static>(
res: Result<T, E>,
str: &str,
) -> Result<T, SwBufError> {
) -> Result<T, SoftBufferError> {
match res {
Ok(t) => Ok(t),
Err(e) => Err(SwBufError::PlatformError(
Err(e) => Err(SoftBufferError::PlatformError(
Some(str.into()),
Some(Box::new(e)),
)),
Expand Down
8 changes: 4 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ mod x11;

mod error;

pub use error::SwBufError;
pub use error::SoftBufferError;

use raw_window_handle::{
HasRawDisplayHandle, HasRawWindowHandle, RawDisplayHandle, RawWindowHandle,
Expand Down Expand Up @@ -90,7 +90,7 @@ impl GraphicsContext {
pub unsafe fn new<W: HasRawWindowHandle, D: HasRawDisplayHandle>(
window: &W,
display: &D,
) -> Result<Self, SwBufError> {
) -> Result<Self, SoftBufferError> {
unsafe { Self::from_raw(window.raw_window_handle(), display.raw_display_handle()) }
}

Expand All @@ -103,7 +103,7 @@ impl GraphicsContext {
pub unsafe fn from_raw(
raw_window_handle: RawWindowHandle,
raw_display_handle: RawDisplayHandle,
) -> Result<Self, SwBufError> {
) -> Result<Self, SoftBufferError> {
let imple: Dispatch = match (raw_window_handle, raw_display_handle) {
#[cfg(all(feature = "x11", any(target_os = "linux", target_os = "freebsd")))]
(
Expand Down Expand Up @@ -141,7 +141,7 @@ impl GraphicsContext {
Dispatch::Orbital(orbital::OrbitalImpl::new(orbital_handle)?)
}
(unimplemented_window_handle, unimplemented_display_handle) => {
return Err(SwBufError::UnsupportedPlatform {
return Err(SoftBufferError::UnsupportedPlatform {
human_readable_window_platform_name: window_handle_type_name(
&unimplemented_window_handle,
),
Expand Down
4 changes: 2 additions & 2 deletions src/orbital.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use raw_window_handle::OrbitalWindowHandle;
use std::{cmp, slice, str};

use crate::SwBufError;
use crate::SoftBufferError;

struct OrbitalMap {
address: usize,
Expand Down Expand Up @@ -45,7 +45,7 @@ pub struct OrbitalImpl {
}

impl OrbitalImpl {
pub fn new(handle: OrbitalWindowHandle) -> Result<Self, SwBufError> {
pub fn new(handle: OrbitalWindowHandle) -> Result<Self, SoftBufferError> {
Ok(Self { handle })
}

Expand Down
4 changes: 2 additions & 2 deletions src/wayland/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{error::unwrap, SwBufError};
use crate::{error::unwrap, SoftBufferError};
use raw_window_handle::{WaylandDisplayHandle, WaylandWindowHandle};
use std::collections::VecDeque;
use wayland_client::{
Expand Down Expand Up @@ -26,7 +26,7 @@ impl WaylandImpl {
pub unsafe fn new(
window_handle: WaylandWindowHandle,
display_handle: WaylandDisplayHandle,
) -> Result<Self, SwBufError> {
) -> Result<Self, SoftBufferError> {
// SAFETY: Ensured by user
let backend = unsafe { Backend::from_foreign_display(display_handle.display as *mut _) };
let conn = Connection::from_backend(backend);
Expand Down
17 changes: 10 additions & 7 deletions src/web.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,25 @@ use web_sys::CanvasRenderingContext2d;
use web_sys::HtmlCanvasElement;
use web_sys::ImageData;

use crate::SwBufError;
use crate::SoftBufferError;

pub struct WebImpl {
canvas: HtmlCanvasElement,
ctx: CanvasRenderingContext2d,
}

impl WebImpl {
pub fn new(handle: WebWindowHandle) -> Result<Self, SwBufError> {
pub fn new(handle: WebWindowHandle) -> Result<Self, SoftBufferError> {
let canvas: HtmlCanvasElement = web_sys::window()
.ok_or_else(|| {
SwBufError::PlatformError(
SoftBufferError::PlatformError(
Some("`window` is not present in this runtime".into()),
None,
)
})?
.document()
.ok_or_else(|| {
SwBufError::PlatformError(
SoftBufferError::PlatformError(
Some("`document` is not present in this runtime".into()),
None,
)
Expand All @@ -32,21 +32,24 @@ impl WebImpl {
// `querySelector` only throws an error if the selector is invalid.
.unwrap()
.ok_or_else(|| {
SwBufError::PlatformError(Some("No canvas found with the given id".into()), None)
SoftBufferError::PlatformError(
Some("No canvas found with the given id".into()),
None,
)
})?
// We already made sure this was a canvas in `querySelector`.
.unchecked_into();

let ctx = canvas
.get_context("2d")
.map_err(|_| {
SwBufError::PlatformError(
SoftBufferError::PlatformError(
Some("Canvas already controlled using `OffscreenCanvas`".into()),
None,
)
})?
.ok_or_else(|| {
SwBufError::PlatformError(
SoftBufferError::PlatformError(
Some("A canvas context other than `CanvasRenderingContext2d` was already created".into()),
None,
)
Expand Down
8 changes: 4 additions & 4 deletions src/win32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//!
//! This module converts the input buffer into a bitmap and then stretches it to the window.
use crate::SwBufError;
use crate::SoftBufferError;
use raw_window_handle::Win32WindowHandle;

use std::io;
Expand Down Expand Up @@ -37,10 +37,10 @@ impl Win32Impl {
/// # Safety
///
/// The `Win32WindowHandle` must be a valid window handle.
pub unsafe fn new(handle: &Win32WindowHandle) -> Result<Self, crate::SwBufError> {
pub unsafe fn new(handle: &Win32WindowHandle) -> Result<Self, crate::SoftBufferError> {
// It is valid for the window handle to be null here. Error out if it is.
if handle.hwnd.is_null() {
return Err(SwBufError::IncompleteWindowHandle);
return Err(SoftBufferError::IncompleteWindowHandle);
}

// Get the handle to the device context.
Expand All @@ -50,7 +50,7 @@ impl Win32Impl {

// GetDC returns null if there is a platform error.
if dc == 0 {
return Err(SwBufError::PlatformError(
return Err(SoftBufferError::PlatformError(
Some("Device Context is null".into()),
Some(Box::new(io::Error::last_os_error())),
));
Expand Down
20 changes: 10 additions & 10 deletions src/x11.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
//! drawn. A more effective implementation would use shared memory instead of the wire. In
//! addition, we may also want to blit to a pixmap instead of a window.
use crate::SwBufError;
use crate::SoftBufferError;
use raw_window_handle::{XcbDisplayHandle, XcbWindowHandle, XlibDisplayHandle, XlibWindowHandle};
use std::fmt;

Expand Down Expand Up @@ -39,15 +39,15 @@ impl X11Impl {
pub unsafe fn from_xlib(
window_handle: XlibWindowHandle,
display_handle: XlibDisplayHandle,
) -> Result<Self, SwBufError> {
) -> Result<Self, SoftBufferError> {
// TODO: We should cache the shared libraries.

// Try to open the XlibXCB shared library.
let lib_xcb = Xlib_xcb::open().swbuf_err("Failed to open XlibXCB shared library")?;

// Validate the display handle to ensure we can use it.
if display_handle.display.is_null() {
return Err(SwBufError::IncompleteDisplayHandle);
return Err(SoftBufferError::IncompleteDisplayHandle);
}

// Get the underlying XCB connection.
Expand Down Expand Up @@ -76,14 +76,14 @@ impl X11Impl {
pub(crate) unsafe fn from_xcb(
window_handle: XcbWindowHandle,
display_handle: XcbDisplayHandle,
) -> Result<Self, SwBufError> {
) -> Result<Self, SoftBufferError> {
// Check that the handles are valid.
if display_handle.connection.is_null() {
return Err(SwBufError::IncompleteDisplayHandle);
return Err(SoftBufferError::IncompleteDisplayHandle);
}

if window_handle.window == 0 {
return Err(SwBufError::IncompleteWindowHandle);
return Err(SoftBufferError::IncompleteWindowHandle);
}

// Wrap the display handle in an x11rb connection.
Expand Down Expand Up @@ -160,15 +160,15 @@ impl Drop for X11Impl {
}
}

/// Convenient wrapper to cast errors into SwBufError.
/// Convenient wrapper to cast errors into SoftBufferError.
trait ResultExt<T, E> {
fn swbuf_err(self, msg: impl Into<String>) -> Result<T, SwBufError>;
fn swbuf_err(self, msg: impl Into<String>) -> Result<T, SoftBufferError>;
}

impl<T, E: fmt::Debug + fmt::Display + 'static> ResultExt<T, E> for Result<T, E> {
fn swbuf_err(self, msg: impl Into<String>) -> Result<T, SwBufError> {
fn swbuf_err(self, msg: impl Into<String>) -> Result<T, SoftBufferError> {
self.map_err(|e| {
SwBufError::PlatformError(Some(msg.into()), Some(Box::new(LibraryError(e))))
SoftBufferError::PlatformError(Some(msg.into()), Some(Box::new(LibraryError(e))))
})
}
}
Expand Down

0 comments on commit a800ca4

Please sign in to comment.