Skip to content

Commit a800ca4

Browse files
authored
Merge pull request #53 from ids1024/update
Update to stable wayland-rs 0.30, specify `rust-version`, rename `SwBufError` back to `SoftBufferError`
2 parents 3eeafad + fc1bba6 commit a800ca4

File tree

9 files changed

+40
-36
lines changed

9 files changed

+40
-36
lines changed

Cargo.toml

+3-2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ repository = "https://github.com/rust-windowing/softbuffer"
1010
keywords = ["framebuffer", "windowing"]
1111
categories = ["game-development", "graphics", "gui", "multimedia", "rendering"]
1212
exclude = ["examples"]
13+
rust-version = "1.60.0"
1314

1415
[features]
1516
default = ["x11", "wayland", "wayland-dlopen"]
@@ -24,8 +25,8 @@ log = "0.4.17"
2425

2526
[target.'cfg(any(target_os = "linux", target_os = "freebsd"))'.dependencies]
2627
nix = { version = "0.26.1", optional = true }
27-
wayland-backend = { version = "0.1.0-beta.14", features = ["client_system"], optional = true }
28-
wayland-client = { version = "0.30.0-beta.14", optional = true }
28+
wayland-backend = { version = "0.1.0", features = ["client_system"], optional = true }
29+
wayland-client = { version = "0.30.0", optional = true }
2930
wayland-sys = "0.30.0"
3031
bytemuck = { version = "1.12.3", optional = true }
3132
x11-dl = { version = "2.19.1", optional = true }

src/cg.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::SwBufError;
1+
use crate::SoftBufferError;
22
use core_graphics::base::{
33
kCGBitmapByteOrder32Little, kCGImageAlphaNoneSkipFirst, kCGRenderingIntentDefault,
44
};
@@ -19,7 +19,7 @@ pub struct CGImpl {
1919
}
2020

2121
impl CGImpl {
22-
pub unsafe fn new(handle: AppKitWindowHandle) -> Result<Self, SwBufError> {
22+
pub unsafe fn new(handle: AppKitWindowHandle) -> Result<Self, SoftBufferError> {
2323
let window = handle.ns_window as id;
2424
let view = handle.ns_view as id;
2525
let layer = CALayer::new();

src/error.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use thiserror::Error;
44

55
#[derive(Error, Debug)]
66
#[non_exhaustive]
7-
pub enum SwBufError {
7+
pub enum SoftBufferError {
88
#[error(
99
"The provided window returned an unsupported platform: {human_readable_window_platform_name}, {human_readable_display_platform_name}."
1010
)]
@@ -29,10 +29,10 @@ pub enum SwBufError {
2929
pub(crate) fn unwrap<T, E: std::error::Error + 'static>(
3030
res: Result<T, E>,
3131
str: &str,
32-
) -> Result<T, SwBufError> {
32+
) -> Result<T, SoftBufferError> {
3333
match res {
3434
Ok(t) => Ok(t),
35-
Err(e) => Err(SwBufError::PlatformError(
35+
Err(e) => Err(SoftBufferError::PlatformError(
3636
Some(str.into()),
3737
Some(Box::new(e)),
3838
)),

src/lib.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ mod x11;
2121

2222
mod error;
2323

24-
pub use error::SwBufError;
24+
pub use error::SoftBufferError;
2525

2626
use raw_window_handle::{
2727
HasRawDisplayHandle, HasRawWindowHandle, RawDisplayHandle, RawWindowHandle,
@@ -90,7 +90,7 @@ impl GraphicsContext {
9090
pub unsafe fn new<W: HasRawWindowHandle, D: HasRawDisplayHandle>(
9191
window: &W,
9292
display: &D,
93-
) -> Result<Self, SwBufError> {
93+
) -> Result<Self, SoftBufferError> {
9494
unsafe { Self::from_raw(window.raw_window_handle(), display.raw_display_handle()) }
9595
}
9696

@@ -103,7 +103,7 @@ impl GraphicsContext {
103103
pub unsafe fn from_raw(
104104
raw_window_handle: RawWindowHandle,
105105
raw_display_handle: RawDisplayHandle,
106-
) -> Result<Self, SwBufError> {
106+
) -> Result<Self, SoftBufferError> {
107107
let imple: Dispatch = match (raw_window_handle, raw_display_handle) {
108108
#[cfg(all(feature = "x11", any(target_os = "linux", target_os = "freebsd")))]
109109
(
@@ -141,7 +141,7 @@ impl GraphicsContext {
141141
Dispatch::Orbital(orbital::OrbitalImpl::new(orbital_handle)?)
142142
}
143143
(unimplemented_window_handle, unimplemented_display_handle) => {
144-
return Err(SwBufError::UnsupportedPlatform {
144+
return Err(SoftBufferError::UnsupportedPlatform {
145145
human_readable_window_platform_name: window_handle_type_name(
146146
&unimplemented_window_handle,
147147
),

src/orbital.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use raw_window_handle::OrbitalWindowHandle;
22
use std::{cmp, slice, str};
33

4-
use crate::SwBufError;
4+
use crate::SoftBufferError;
55

66
struct OrbitalMap {
77
address: usize,
@@ -45,7 +45,7 @@ pub struct OrbitalImpl {
4545
}
4646

4747
impl OrbitalImpl {
48-
pub fn new(handle: OrbitalWindowHandle) -> Result<Self, SwBufError> {
48+
pub fn new(handle: OrbitalWindowHandle) -> Result<Self, SoftBufferError> {
4949
Ok(Self { handle })
5050
}
5151

src/wayland/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::{error::unwrap, SwBufError};
1+
use crate::{error::unwrap, SoftBufferError};
22
use raw_window_handle::{WaylandDisplayHandle, WaylandWindowHandle};
33
use std::collections::VecDeque;
44
use wayland_client::{
@@ -26,7 +26,7 @@ impl WaylandImpl {
2626
pub unsafe fn new(
2727
window_handle: WaylandWindowHandle,
2828
display_handle: WaylandDisplayHandle,
29-
) -> Result<Self, SwBufError> {
29+
) -> Result<Self, SoftBufferError> {
3030
// SAFETY: Ensured by user
3131
let backend = unsafe { Backend::from_foreign_display(display_handle.display as *mut _) };
3232
let conn = Connection::from_backend(backend);

src/web.rs

+10-7
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,25 @@ use web_sys::CanvasRenderingContext2d;
55
use web_sys::HtmlCanvasElement;
66
use web_sys::ImageData;
77

8-
use crate::SwBufError;
8+
use crate::SoftBufferError;
99

1010
pub struct WebImpl {
1111
canvas: HtmlCanvasElement,
1212
ctx: CanvasRenderingContext2d,
1313
}
1414

1515
impl WebImpl {
16-
pub fn new(handle: WebWindowHandle) -> Result<Self, SwBufError> {
16+
pub fn new(handle: WebWindowHandle) -> Result<Self, SoftBufferError> {
1717
let canvas: HtmlCanvasElement = web_sys::window()
1818
.ok_or_else(|| {
19-
SwBufError::PlatformError(
19+
SoftBufferError::PlatformError(
2020
Some("`window` is not present in this runtime".into()),
2121
None,
2222
)
2323
})?
2424
.document()
2525
.ok_or_else(|| {
26-
SwBufError::PlatformError(
26+
SoftBufferError::PlatformError(
2727
Some("`document` is not present in this runtime".into()),
2828
None,
2929
)
@@ -32,21 +32,24 @@ impl WebImpl {
3232
// `querySelector` only throws an error if the selector is invalid.
3333
.unwrap()
3434
.ok_or_else(|| {
35-
SwBufError::PlatformError(Some("No canvas found with the given id".into()), None)
35+
SoftBufferError::PlatformError(
36+
Some("No canvas found with the given id".into()),
37+
None,
38+
)
3639
})?
3740
// We already made sure this was a canvas in `querySelector`.
3841
.unchecked_into();
3942

4043
let ctx = canvas
4144
.get_context("2d")
4245
.map_err(|_| {
43-
SwBufError::PlatformError(
46+
SoftBufferError::PlatformError(
4447
Some("Canvas already controlled using `OffscreenCanvas`".into()),
4548
None,
4649
)
4750
})?
4851
.ok_or_else(|| {
49-
SwBufError::PlatformError(
52+
SoftBufferError::PlatformError(
5053
Some("A canvas context other than `CanvasRenderingContext2d` was already created".into()),
5154
None,
5255
)

src/win32.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//!
33
//! This module converts the input buffer into a bitmap and then stretches it to the window.
44
5-
use crate::SwBufError;
5+
use crate::SoftBufferError;
66
use raw_window_handle::Win32WindowHandle;
77

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

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

5151
// GetDC returns null if there is a platform error.
5252
if dc == 0 {
53-
return Err(SwBufError::PlatformError(
53+
return Err(SoftBufferError::PlatformError(
5454
Some("Device Context is null".into()),
5555
Some(Box::new(io::Error::last_os_error())),
5656
));

src/x11.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
//! drawn. A more effective implementation would use shared memory instead of the wire. In
55
//! addition, we may also want to blit to a pixmap instead of a window.
66
7-
use crate::SwBufError;
7+
use crate::SoftBufferError;
88
use raw_window_handle::{XcbDisplayHandle, XcbWindowHandle, XlibDisplayHandle, XlibWindowHandle};
99
use std::fmt;
1010

@@ -39,15 +39,15 @@ impl X11Impl {
3939
pub unsafe fn from_xlib(
4040
window_handle: XlibWindowHandle,
4141
display_handle: XlibDisplayHandle,
42-
) -> Result<Self, SwBufError> {
42+
) -> Result<Self, SoftBufferError> {
4343
// TODO: We should cache the shared libraries.
4444

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

4848
// Validate the display handle to ensure we can use it.
4949
if display_handle.display.is_null() {
50-
return Err(SwBufError::IncompleteDisplayHandle);
50+
return Err(SoftBufferError::IncompleteDisplayHandle);
5151
}
5252

5353
// Get the underlying XCB connection.
@@ -76,14 +76,14 @@ impl X11Impl {
7676
pub(crate) unsafe fn from_xcb(
7777
window_handle: XcbWindowHandle,
7878
display_handle: XcbDisplayHandle,
79-
) -> Result<Self, SwBufError> {
79+
) -> Result<Self, SoftBufferError> {
8080
// Check that the handles are valid.
8181
if display_handle.connection.is_null() {
82-
return Err(SwBufError::IncompleteDisplayHandle);
82+
return Err(SoftBufferError::IncompleteDisplayHandle);
8383
}
8484

8585
if window_handle.window == 0 {
86-
return Err(SwBufError::IncompleteWindowHandle);
86+
return Err(SoftBufferError::IncompleteWindowHandle);
8787
}
8888

8989
// Wrap the display handle in an x11rb connection.
@@ -160,15 +160,15 @@ impl Drop for X11Impl {
160160
}
161161
}
162162

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

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

0 commit comments

Comments
 (0)